aboutsummaryrefslogtreecommitdiffstats
path: root/read-cache.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-05-27 13:59:10 -0700
committerJunio C Hamano <gitster@pobox.com>2025-05-27 13:59:11 -0700
commitf9cdaa2860e20f3f36595646b7a82082aa772df8 (patch)
tree40513df8eb4aec40cc4ec28e0ba4855d532be476 /read-cache.c
parentMerge branch 'sj/use-mmap-to-check-packed-refs' (diff)
parentsequencer: stop pretending that an assignment is a condition (diff)
downloadgit-f9cdaa2860e20f3f36595646b7a82082aa772df8.tar.gz
git-f9cdaa2860e20f3f36595646b7a82082aa772df8.zip
Merge branch 'js/misc-fixes'
Assorted fixes for issues found with CodeQL. * js/misc-fixes: sequencer: stop pretending that an assignment is a condition bundle-uri: avoid using undefined output of `sscanf()` commit-graph: avoid using stale stack addresses trace2: avoid "futile conditional" Avoid redundant conditions fetch: avoid unnecessary work when there is no current branch has_dir_name(): make code more obvious upload-pack: rename `enum` to reflect the operation commit-graph: avoid malloc'ing a local variable fetch: carefully clear local variable's address after use commit: simplify code
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c55
1 files changed, 13 insertions, 42 deletions
diff --git a/read-cache.c b/read-cache.c
index 73f83a7e7a..c0bb760ad4 100644
--- a/read-cache.c
+++ b/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.
*/
- if (istate->cache_nr > 0) {
- cmp_last = strcmp_offset(name,
- istate->cache[istate->cache_nr - 1]->name,
- &len_eq_last);
- if (cmp_last > 0) {
- if (name[len_eq_last] != '/') {
- /*
- * The entry sorts AFTER the last one in the
- * index.
- *
- * If there were a conflict with "file", then our
- * name would start with "file/" and the last index
- * entry would start with "file" but not "file/".
- *
- * 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.
- */
- }
- }
+ if (!istate->cache_nr)
+ return 0;
+
+ cmp_last = strcmp_offset(name,
+ istate->cache[istate->cache_nr - 1]->name,
+ &len_eq_last);
+ if (cmp_last > 0 && name[len_eq_last] != '/')
+ /*
+ * The entry sorts AFTER the last one in the
+ * index and their paths have no common prefix,
+ * so there cannot be a F/D conflict.
+ */
+ return 0;
for (;;) {
size_t len;