Skip to content

Commit 5ec8274

Browse files
stefanbellergitster
authored andcommitted
xdiff-interface: export comparing and hashing strings
This will turn out to be useful in a later patch. xdl_recmatch is exported in xdiff/xutils.h, to be used by various xdiff/*.c files, but not outside of xdiff/. This one makes it available to the outside, too. While at it, add documentation. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b66b507 commit 5ec8274

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

xdiff-interface.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "xdiff/xdiffi.h"
66
#include "xdiff/xemit.h"
77
#include "xdiff/xmacros.h"
8+
#include "xdiff/xutils.h"
89

910
struct xdiff_emit_state {
1011
xdiff_emit_consume_fn consume;
@@ -296,6 +297,17 @@ void xdiff_clear_find_func(xdemitconf_t *xecfg)
296297
}
297298
}
298299

300+
unsigned long xdiff_hash_string(const char *s, size_t len, long flags)
301+
{
302+
return xdl_hash_record(&s, s + len, flags);
303+
}
304+
305+
int xdiff_compare_lines(const char *l1, long s1,
306+
const char *l2, long s2, long flags)
307+
{
308+
return xdl_recmatch(l1, s1, l2, s2, flags);
309+
}
310+
299311
int git_xmerge_style = -1;
300312

301313
int git_xmerge_config(const char *var, const char *value, void *cb)

xdiff-interface.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,20 @@ extern void xdiff_clear_find_func(xdemitconf_t *xecfg);
2929
extern int git_xmerge_config(const char *var, const char *value, void *cb);
3030
extern int git_xmerge_style;
3131

32+
/*
33+
* Compare the strings l1 with l2 which are of size s1 and s2 respectively.
34+
* Returns 1 if the strings are deemed equal, 0 otherwise.
35+
* The `flags` given as XDF_WHITESPACE_FLAGS determine how white spaces
36+
* are treated for the comparision.
37+
*/
38+
extern int xdiff_compare_lines(const char *l1, long s1,
39+
const char *l2, long s2, long flags);
40+
41+
/*
42+
* Returns a hash of the string s of length len.
43+
* The `flags` given as XDF_WHITESPACE_FLAGS determine how white spaces
44+
* are treated for the hash.
45+
*/
46+
extern unsigned long xdiff_hash_string(const char *s, size_t len, long flags);
47+
3248
#endif

0 commit comments

Comments
 (0)