Skip to content

Commit 692be9f

Browse files
committed
Merge branch 'cb/maint-unpack-trees-absense' into maint
* cb/maint-unpack-trees-absense: unpack-trees: remove redundant path search in verify_absent unpack-trees: fix path search bug in verify_absent unpack-trees: handle failure in verify_absent
2 parents f630171 + 7b9e3ce commit 692be9f

File tree

2 files changed

+67
-18
lines changed

2 files changed

+67
-18
lines changed

t/t1001-read-tree-m-2way.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,55 @@ test_expect_success \
341341
check_cache_at DF/DF dirty &&
342342
:'
343343

344+
test_expect_success \
345+
'a/b (untracked) vs a case setup.' \
346+
'rm -f .git/index &&
347+
: >a &&
348+
git update-index --add a &&
349+
treeM=`git write-tree` &&
350+
echo treeM $treeM &&
351+
git ls-tree $treeM &&
352+
git ls-files --stage >treeM.out &&
353+
354+
rm -f a &&
355+
git update-index --remove a &&
356+
mkdir a &&
357+
: >a/b &&
358+
treeH=`git write-tree` &&
359+
echo treeH $treeH &&
360+
git ls-tree $treeH'
361+
362+
test_expect_success \
363+
'a/b (untracked) vs a, plus c/d case test.' \
364+
'! git read-tree -u -m "$treeH" "$treeM" &&
365+
git ls-files --stage &&
366+
test -f a/b'
367+
368+
test_expect_success \
369+
'a/b vs a, plus c/d case setup.' \
370+
'rm -f .git/index &&
371+
rm -fr a &&
372+
: >a &&
373+
mkdir c &&
374+
: >c/d &&
375+
git update-index --add a c/d &&
376+
treeM=`git write-tree` &&
377+
echo treeM $treeM &&
378+
git ls-tree $treeM &&
379+
git ls-files --stage >treeM.out &&
380+
381+
rm -f a &&
382+
mkdir a
383+
: >a/b &&
384+
git update-index --add --remove a a/b &&
385+
treeH=`git write-tree` &&
386+
echo treeH $treeH &&
387+
git ls-tree $treeH'
388+
389+
test_expect_success \
390+
'a/b vs a, plus c/d case test.' \
391+
'git read-tree -u -m "$treeH" "$treeM" &&
392+
git ls-files --stage | tee >treeMcheck.out &&
393+
test_cmp treeM.out treeMcheck.out'
394+
344395
test_done

unpack-trees.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
494494
* anything in the existing directory there.
495495
*/
496496
int namelen;
497-
int pos, i;
497+
int i;
498498
struct dir_struct d;
499499
char *pathbuf;
500500
int cnt = 0;
@@ -515,24 +515,20 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
515515
* in that directory.
516516
*/
517517
namelen = strlen(ce->name);
518-
pos = index_name_pos(o->src_index, ce->name, namelen);
519-
if (0 <= pos)
520-
return cnt; /* we have it as nondirectory */
521-
pos = -pos - 1;
522-
for (i = pos; i < o->src_index->cache_nr; i++) {
523-
struct cache_entry *ce = o->src_index->cache[i];
524-
int len = ce_namelen(ce);
518+
for (i = o->pos; i < o->src_index->cache_nr; i++) {
519+
struct cache_entry *ce2 = o->src_index->cache[i];
520+
int len = ce_namelen(ce2);
525521
if (len < namelen ||
526-
strncmp(ce->name, ce->name, namelen) ||
527-
ce->name[namelen] != '/')
522+
strncmp(ce->name, ce2->name, namelen) ||
523+
ce2->name[namelen] != '/')
528524
break;
529525
/*
530-
* ce->name is an entry in the subdirectory.
526+
* ce2->name is an entry in the subdirectory.
531527
*/
532-
if (!ce_stage(ce)) {
533-
if (verify_uptodate(ce, o))
528+
if (!ce_stage(ce2)) {
529+
if (verify_uptodate(ce2, o))
534530
return -1;
535-
add_entry(o, ce, CE_REMOVE, 0);
531+
add_entry(o, ce2, CE_REMOVE, 0);
536532
}
537533
cnt++;
538534
}
@@ -588,7 +584,7 @@ static int verify_absent(struct cache_entry *ce, const char *action,
588584
return 0;
589585

590586
if (!lstat(ce->name, &st)) {
591-
int cnt;
587+
int ret;
592588
int dtype = ce_to_dtype(ce);
593589
struct cache_entry *result;
594590

@@ -616,13 +612,15 @@ static int verify_absent(struct cache_entry *ce, const char *action,
616612
* files that are in "foo/" we would lose
617613
* it.
618614
*/
619-
cnt = verify_clean_subdirectory(ce, action, o);
615+
ret = verify_clean_subdirectory(ce, action, o);
616+
if (ret < 0)
617+
return ret;
620618

621619
/*
622620
* If this removed entries from the index,
623621
* what that means is:
624622
*
625-
* (1) the caller unpack_trees_rec() saw path/foo
623+
* (1) the caller unpack_callback() saw path/foo
626624
* in the index, and it has not removed it because
627625
* it thinks it is handling 'path' as blob with
628626
* D/F conflict;
@@ -635,7 +633,7 @@ static int verify_absent(struct cache_entry *ce, const char *action,
635633
* We need to increment it by the number of
636634
* deleted entries here.
637635
*/
638-
o->pos += cnt;
636+
o->pos += ret;
639637
return 0;
640638
}
641639

0 commit comments

Comments
 (0)