has_dir_name(): make code more obvious
One thing that might be non-obvious to readers (or to analyzers like CodeQL) is that the function essentially does nothing when the Git index is empty, and in particular that it does not look at the value of `len_eq_last` (which would be uninitialized at that point). Let's make this much easier to understand, by returning early if the Git index is empty, and by avoiding empty `else` blocks. This commit changes indentation and is hence best viewed using `--ignore-space-change`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
bf0468e2ba
commit
655268452c
55
read-cache.c
55
read-cache.c
@@ -1117,48 +1117,19 @@ static int has_dir_name(struct index_state *istate,
|
|||||||
*
|
*
|
||||||
* Compare the entry's full path with the last path in the index.
|
* Compare the entry's full path with the last path in the index.
|
||||||
*/
|
*/
|
||||||
if (istate->cache_nr > 0) {
|
if (!istate->cache_nr)
|
||||||
cmp_last = strcmp_offset(name,
|
return 0;
|
||||||
istate->cache[istate->cache_nr - 1]->name,
|
|
||||||
&len_eq_last);
|
cmp_last = strcmp_offset(name,
|
||||||
if (cmp_last > 0) {
|
istate->cache[istate->cache_nr - 1]->name,
|
||||||
if (name[len_eq_last] != '/') {
|
&len_eq_last);
|
||||||
/*
|
if (cmp_last > 0 && name[len_eq_last] != '/')
|
||||||
* The entry sorts AFTER the last one in the
|
/*
|
||||||
* index.
|
* The entry sorts AFTER the last one in the
|
||||||
*
|
* index and their paths have no common prefix,
|
||||||
* If there were a conflict with "file", then our
|
* so there cannot be a F/D conflict.
|
||||||
* name would start with "file/" and the last index
|
*/
|
||||||
* entry would start with "file" but not "file/".
|
return 0;
|
||||||
*
|
|
||||||
* The next character after common prefix is
|
|
||||||
* not '/', so there can be no conflict.
|
|
||||||
*/
|
|
||||||
return retval;
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* The entry sorts AFTER the last one in the
|
|
||||||
* index, and the next character after common
|
|
||||||
* prefix is '/'.
|
|
||||||
*
|
|
||||||
* Either the last index entry is a file in
|
|
||||||
* conflict with this entry, or it has a name
|
|
||||||
* which sorts between this entry and the
|
|
||||||
* potential conflicting file.
|
|
||||||
*
|
|
||||||
* In both cases, we fall through to the loop
|
|
||||||
* below and let the regular search code handle it.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
} else if (cmp_last == 0) {
|
|
||||||
/*
|
|
||||||
* The entry exactly matches the last one in the
|
|
||||||
* index, but because of multiple stage and CE_REMOVE
|
|
||||||
* items, we fall through and let the regular search
|
|
||||||
* code handle it.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|||||||
Reference in New Issue
Block a user