* 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
| 126 | * but then handle conflicting entries together when possible. |
| 127 | */ |
| 128 | int 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 | |
| 154 | int name_compare(const char *name1, size_t len1, const char *name2, size_t len2) |
| 155 | { |
no outgoing calls
no test coverage detected