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 <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Oct 25, 2017 at 11:49 UTC
5ec8274b8424f76bf998059e66facff1b241337e
2 files changed
+28
xdiff-interface.c
+12
@@ -5,6 +5,7 @@
5
#include "xdiff/xdiffi.h"
6
#include "xdiff/xemit.h"
7
#include "xdiff/xmacros.h"
8
+#include "xdiff/xutils.h"
9
10
struct xdiff_emit_state {
11
xdiff_emit_consume_fn consume;
@@ -296,6 +297,17 @@ void xdiff_clear_find_func(xdemitconf_t *xecfg)
297
}
298
}
299
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
+
311
int git_xmerge_style = -1;
312
313
int git_xmerge_config(const char *var, const char *value, void *cb)
xdiff-interface.h
+16
@@ -29,4 +29,20 @@ extern void xdiff_clear_find_func(xdemitconf_t *xecfg);
29
extern int git_xmerge_config(const char *var, const char *value, void *cb);
30
extern int git_xmerge_style;
31
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
+
48
#endif