Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'xdiff/xutils.c')
-rw-r--r--xdiff/xutils.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index 1b899f32c4..bf91c0f73c 100644
--- a/xdiff/xutils.c
+++ b/xdiff/xutils.c
@@ -215,18 +215,35 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)
return 0;
}
return (i1 >= s1 && i2 >= s2);
+ } else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL) {
+ for (i1 = i2 = 0; i1 < s1 && i2 < s2; ) {
+ if (l1[i1] != l2[i2]) {
+ while (i1 < s1 && isspace(l1[i1]))
+ i1++;
+ while (i2 < s2 && isspace(l2[i2]))
+ i2++;
+ if (i1 < s1 || i2 < s2)
+ return 0;
+ return 1;
+ }
+ i1++;
+ i2++;
+ }
+ return i1 >= s1 && i2 >= s2;
} else
return s1 == s2 && !memcmp(l1, l2, s1);
return 0;
}
-unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
+static unsigned long xdl_hash_record_with_whitespace(char const **data,
+ char const *top, long flags) {
unsigned long ha = 5381;
char const *ptr = *data;
for (; ptr < top && *ptr != '\n'; ptr++) {
- if (isspace(*ptr) && (flags & XDF_WHITESPACE_FLAGS)) {
+ if (isspace(*ptr)) {
+ const char *ptr2 = ptr;
while (ptr + 1 < top && isspace(ptr[1])
&& ptr[1] != '\n')
ptr++;
@@ -235,6 +252,14 @@ unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
ha += (ha << 5);
ha ^= (unsigned long) ' ';
}
+ if (flags & XDF_IGNORE_WHITESPACE_AT_EOL
+ && ptr[1] != '\n') {
+ while (ptr2 != ptr + 1) {
+ ha += (ha << 5);
+ ha ^= (unsigned long) *ptr2;
+ ptr2++;
+ }
+ }
continue;
}
ha += (ha << 5);
@@ -246,6 +271,23 @@ unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
}
+unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
+ unsigned long ha = 5381;
+ char const *ptr = *data;
+
+ if (flags & XDF_WHITESPACE_FLAGS)
+ return xdl_hash_record_with_whitespace(data, top, flags);
+
+ for (; ptr < top && *ptr != '\n'; ptr++) {
+ ha += (ha << 5);
+ ha ^= (unsigned long) *ptr;
+ }
+ *data = ptr < top ? ptr + 1: ptr;
+
+ return ha;
+}
+
+
unsigned int xdl_hashbits(unsigned int size) {
unsigned int val = 1, bits = 0;