MCPcopy Create free account
hub / github.com/git/git / df_name_compare

Function df_name_compare

tree.c:128–152  ·  view source on GitHub ↗

* df_name_compare() is identical to base_name_compare(), except it * compares conflicting directory/file entries as equal. Note that * while a directory name compares as equal to a regular file, they * then individually compare _differently_ to a filename that has * a dot after the basename (because '\0' < '.' < '/'). * * This is used by routines that want to traverse the git namespace * bu

Source from the content-addressed store, hash-verified

126 * but then handle conflicting entries together when possible.
127 */
128int df_name_compare(const char *name1, size_t len1, int mode1,
129 const char *name2, size_t len2, int mode2)
130{
131 unsigned char c1, c2;
132 size_t len = len1 < len2 ? len1 : len2;
133 int cmp;
134
135 cmp = memcmp(name1, name2, len);
136 if (cmp)
137 return cmp;
138 /* Directories and files compare equal (same length, same name) */
139 if (len1 == len2)
140 return 0;
141 c1 = name1[len];
142 if (!c1 && S_ISDIR(mode1))
143 c1 = '/';
144 c2 = name2[len];
145 if (!c2 && S_ISDIR(mode2))
146 c2 = '/';
147 if (c1 == '/' && !c2)
148 return 0;
149 if (c2 == '/' && !c1)
150 return 0;
151 return c1 - c2;
152}
153
154int name_compare(const char *name1, size_t len1, const char *name2, size_t len2)
155{

Callers 2

do_compare_entryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected