summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorJeff Hostetler <jeffhost@microsoft.com>2017-04-14 19:12:28 +0000
committerJunio C Hamano <gitster@pobox.com>2017-04-15 02:21:12 -0700
commita6db3fbb6e4ec11695e2a3af8bc2cb9119cb1941 (patch)
tree6eeb1de45587403bee39e7579585c57409d1346c /read-cache.c
parentcf11a67975b057a144618badf16dc4e3d25b9407 (diff)
downloadgit-a6db3fbb6e4ec11695e2a3af8bc2cb9119cb1941.tar.gz
read-cache: add strcmp_offset function
Add strcmp_offset() function to also return the offset of the first change. Add unit test and helper to verify. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/read-cache.c b/read-cache.c
index e447751823..11823f5dbc 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -887,6 +887,26 @@ static int has_file_name(struct index_state *istate,
return retval;
}
+
+/*
+ * Like strcmp(), but also return the offset of the first change.
+ * If strings are equal, return the length.
+ */
+int strcmp_offset(const char *s1, const char *s2, size_t *first_change)
+{
+ size_t k;
+
+ if (!first_change)
+ return strcmp(s1, s2);
+
+ for (k = 0; s1[k] == s2[k]; k++)
+ if (s1[k] == '\0')
+ break;
+
+ *first_change = k;
+ return (unsigned char)s1[k] - (unsigned char)s2[k];
+}
+
/*
* Do we have another file with a pathname that is a proper
* subset of the name we're trying to add?