Skip to content

Commit 13e7ed6

Browse files
bk2204gitster
authored andcommitted
builtin/checkout: compute checkout metadata for checkouts
Provide commit metadata for checkout code paths that use unpack_trees and friends. When we're checking out a commit, use the commit information, but don't provide commit information if we're checking out from the index, since there need not be any particular commit associated with the index, and even if there is one, we can't know what it is. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c397aac commit 13e7ed6

File tree

6 files changed

+68
-33
lines changed

6 files changed

+68
-33
lines changed

builtin/checkout.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,8 @@ static void describe_detached_head(const char *msg, struct commit *commit)
604604
}
605605

606606
static int reset_tree(struct tree *tree, const struct checkout_opts *o,
607-
int worktree, int *writeout_error)
607+
int worktree, int *writeout_error,
608+
struct branch_info *info)
608609
{
609610
struct unpack_trees_options opts;
610611
struct tree_desc tree_desc;
@@ -619,6 +620,11 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
619620
opts.verbose_update = o->show_progress;
620621
opts.src_index = &the_index;
621622
opts.dst_index = &the_index;
623+
init_checkout_metadata(&opts.meta, info->refname,
624+
info->commit ? &info->commit->object.oid :
625+
is_null_oid(&info->oid) ? &tree->object.oid :
626+
&info->oid,
627+
NULL);
622628
parse_tree(tree);
623629
init_tree_desc(&tree_desc, tree->buffer, tree->size);
624630
switch (unpack_trees(1, &tree_desc, &opts)) {
@@ -677,7 +683,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
677683
} else
678684
new_tree = get_commit_tree(new_branch_info->commit);
679685
if (opts->discard_changes) {
680-
ret = reset_tree(new_tree, opts, 1, writeout_error);
686+
ret = reset_tree(new_tree, opts, 1, writeout_error, new_branch_info);
681687
if (ret)
682688
return ret;
683689
} else {
@@ -706,6 +712,10 @@ static int merge_working_tree(const struct checkout_opts *opts,
706712
topts.quiet = opts->merge && old_branch_info->commit;
707713
topts.verbose_update = opts->show_progress;
708714
topts.fn = twoway_merge;
715+
init_checkout_metadata(&topts.meta, new_branch_info->refname,
716+
new_branch_info->commit ?
717+
&new_branch_info->commit->object.oid :
718+
&new_branch_info->oid, NULL);
709719
if (opts->overwrite_ignore) {
710720
topts.dir = xcalloc(1, sizeof(*topts.dir));
711721
topts.dir->flags |= DIR_SHOW_IGNORED;
@@ -776,7 +786,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
776786

777787
ret = reset_tree(new_tree,
778788
opts, 1,
779-
writeout_error);
789+
writeout_error, new_branch_info);
780790
if (ret)
781791
return ret;
782792
o.ancestor = old_branch_info->name;
@@ -796,7 +806,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
796806
exit(128);
797807
ret = reset_tree(new_tree,
798808
opts, 0,
799-
writeout_error);
809+
writeout_error, new_branch_info);
800810
strbuf_release(&o.obuf);
801811
strbuf_release(&old_commit_shortname);
802812
if (ret)

merge.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ int checkout_fast_forward(struct repository *r,
9494
opts.verbose_update = 1;
9595
opts.merge = 1;
9696
opts.fn = twoway_merge;
97+
init_checkout_metadata(&opts.meta, NULL, remote, NULL);
9798
setup_unpack_trees_porcelain(&opts, "merge");
9899

99100
if (unpack_trees(nr_trees, t, &opts)) {

t/t0021-conversion.sh

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,10 @@ test_expect_success PERL 'required process filter should filter data' '
364364
S=$(file_size test.r) &&
365365
S2=$(file_size test2.r) &&
366366
S3=$(file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
367+
M=$(git hash-object test.r) &&
368+
M2=$(git hash-object test2.r) &&
369+
M3=$(git hash-object "testsubdir/test3 '\''sq'\'',\$x=.r") &&
370+
EMPTY=$(git hash-object /dev/null) &&
367371
368372
filter_git add . &&
369373
cat >expected.log <<-EOF &&
@@ -378,14 +382,15 @@ test_expect_success PERL 'required process filter should filter data' '
378382
test_cmp_count expected.log debug.log &&
379383
380384
git commit -m "test commit 2" &&
385+
META="ref=refs/heads/master treeish=$(git rev-parse --verify master)" &&
381386
rm -f test2.r "testsubdir/test3 '\''sq'\'',\$x=.r" &&
382387
383388
filter_git checkout --quiet --no-progress . &&
384389
cat >expected.log <<-EOF &&
385390
START
386391
init handshake complete
387-
IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
388-
IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK]
392+
IN: smudge test2.r blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
393+
IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
389394
STOP
390395
EOF
391396
test_cmp_exclude_clean expected.log debug.log &&
@@ -406,10 +411,10 @@ test_expect_success PERL 'required process filter should filter data' '
406411
cat >expected.log <<-EOF &&
407412
START
408413
init handshake complete
409-
IN: smudge test.r $S [OK] -- OUT: $S . [OK]
410-
IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
411-
IN: smudge test4-empty.r 0 [OK] -- OUT: 0 [OK]
412-
IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK]
414+
IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
415+
IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
416+
IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
417+
IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
413418
STOP
414419
EOF
415420
test_cmp_exclude_clean expected.log debug.log &&
@@ -519,17 +524,22 @@ test_expect_success PERL 'required process filter should process multiple packet
519524
EOF
520525
test_cmp_count expected.log debug.log &&
521526
522-
rm -f *.file &&
527+
M1="blob=$(git hash-object 1pkt_1__.file)" &&
528+
M2="blob=$(git hash-object 2pkt_1+1.file)" &&
529+
M3="blob=$(git hash-object 2pkt_2-1.file)" &&
530+
M4="blob=$(git hash-object 2pkt_2__.file)" &&
531+
M5="blob=$(git hash-object 3pkt_2+1.file)" &&
532+
rm -f *.file debug.log &&
523533
524534
filter_git checkout --quiet --no-progress -- *.file &&
525535
cat >expected.log <<-EOF &&
526536
START
527537
init handshake complete
528-
IN: smudge 1pkt_1__.file $(($S )) [OK] -- OUT: $(($S )) . [OK]
529-
IN: smudge 2pkt_1+1.file $(($S +1)) [OK] -- OUT: $(($S +1)) .. [OK]
530-
IN: smudge 2pkt_2-1.file $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK]
531-
IN: smudge 2pkt_2__.file $(($S*2 )) [OK] -- OUT: $(($S*2 )) .. [OK]
532-
IN: smudge 3pkt_2+1.file $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK]
538+
IN: smudge 1pkt_1__.file $M1 $(($S )) [OK] -- OUT: $(($S )) . [OK]
539+
IN: smudge 2pkt_1+1.file $M2 $(($S +1)) [OK] -- OUT: $(($S +1)) .. [OK]
540+
IN: smudge 2pkt_2-1.file $M3 $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK]
541+
IN: smudge 2pkt_2__.file $M4 $(($S*2 )) [OK] -- OUT: $(($S*2 )) .. [OK]
542+
IN: smudge 3pkt_2+1.file $M5 $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK]
533543
STOP
534544
EOF
535545
test_cmp_exclude_clean expected.log debug.log &&
@@ -578,6 +588,10 @@ test_expect_success PERL 'process filter should restart after unexpected write f
578588
S=$(file_size test.r) &&
579589
S2=$(file_size test2.r) &&
580590
SF=$(file_size smudge-write-fail.r) &&
591+
M=$(git hash-object test.r) &&
592+
M2=$(git hash-object test2.r) &&
593+
MF=$(git hash-object smudge-write-fail.r) &&
594+
rm -f debug.log &&
581595
582596
git add . &&
583597
rm -f *.r &&
@@ -591,11 +605,11 @@ test_expect_success PERL 'process filter should restart after unexpected write f
591605
cat >expected.log <<-EOF &&
592606
START
593607
init handshake complete
594-
IN: smudge smudge-write-fail.r $SF [OK] -- [WRITE FAIL]
608+
IN: smudge smudge-write-fail.r blob=$MF $SF [OK] -- [WRITE FAIL]
595609
START
596610
init handshake complete
597-
IN: smudge test.r $S [OK] -- OUT: $S . [OK]
598-
IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
611+
IN: smudge test.r blob=$M $S [OK] -- OUT: $S . [OK]
612+
IN: smudge test2.r blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
599613
STOP
600614
EOF
601615
test_cmp_exclude_clean expected.log debug.log &&
@@ -629,6 +643,10 @@ test_expect_success PERL 'process filter should not be restarted if it signals a
629643
S=$(file_size test.r) &&
630644
S2=$(file_size test2.r) &&
631645
SE=$(file_size error.r) &&
646+
M=$(git hash-object test.r) &&
647+
M2=$(git hash-object test2.r) &&
648+
ME=$(git hash-object error.r) &&
649+
rm -f debug.log &&
632650
633651
git add . &&
634652
rm -f *.r &&
@@ -637,9 +655,9 @@ test_expect_success PERL 'process filter should not be restarted if it signals a
637655
cat >expected.log <<-EOF &&
638656
START
639657
init handshake complete
640-
IN: smudge error.r $SE [OK] -- [ERROR]
641-
IN: smudge test.r $S [OK] -- OUT: $S . [OK]
642-
IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
658+
IN: smudge error.r blob=$ME $SE [OK] -- [ERROR]
659+
IN: smudge test.r blob=$M $S [OK] -- OUT: $S . [OK]
660+
IN: smudge test2.r blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
643661
STOP
644662
EOF
645663
test_cmp_exclude_clean expected.log debug.log &&
@@ -665,18 +683,21 @@ test_expect_success PERL 'process filter abort stops processing of all further f
665683
echo "error this blob and all future blobs" >abort.o &&
666684
cp abort.o abort.r &&
667685
686+
M="blob=$(git hash-object abort.r)" &&
687+
rm -f debug.log &&
668688
SA=$(file_size abort.r) &&
669689
670690
git add . &&
671691
rm -f *.r &&
672692
693+
673694
# Note: This test assumes that Git filters files in alphabetical
674695
# order ("abort.r" before "test.r").
675696
filter_git checkout --quiet --no-progress . &&
676697
cat >expected.log <<-EOF &&
677698
START
678699
init handshake complete
679-
IN: smudge abort.r $SA [OK] -- [ABORT]
700+
IN: smudge abort.r $M $SA [OK] -- [ABORT]
680701
STOP
681702
EOF
682703
test_cmp_exclude_clean expected.log debug.log &&
@@ -727,27 +748,28 @@ test_expect_success PERL 'delayed checkout in process filter' '
727748
) &&
728749
729750
S=$(file_size "$TEST_ROOT/test.o") &&
751+
M="blob=$(git -C repo rev-parse --verify master:test.a)" &&
730752
cat >a.exp <<-EOF &&
731753
START
732754
init handshake complete
733-
IN: smudge test.a $S [OK] -- OUT: $S . [OK]
734-
IN: smudge test-delay10.a $S [OK] -- [DELAYED]
735-
IN: smudge test-delay11.a $S [OK] -- [DELAYED]
736-
IN: smudge test-delay20.a $S [OK] -- [DELAYED]
755+
IN: smudge test.a $M $S [OK] -- OUT: $S . [OK]
756+
IN: smudge test-delay10.a $M $S [OK] -- [DELAYED]
757+
IN: smudge test-delay11.a $M $S [OK] -- [DELAYED]
758+
IN: smudge test-delay20.a $M $S [OK] -- [DELAYED]
737759
IN: list_available_blobs test-delay10.a test-delay11.a [OK]
738-
IN: smudge test-delay10.a 0 [OK] -- OUT: $S . [OK]
739-
IN: smudge test-delay11.a 0 [OK] -- OUT: $S . [OK]
760+
IN: smudge test-delay10.a $M 0 [OK] -- OUT: $S . [OK]
761+
IN: smudge test-delay11.a $M 0 [OK] -- OUT: $S . [OK]
740762
IN: list_available_blobs test-delay20.a [OK]
741-
IN: smudge test-delay20.a 0 [OK] -- OUT: $S . [OK]
763+
IN: smudge test-delay20.a $M 0 [OK] -- OUT: $S . [OK]
742764
IN: list_available_blobs [OK]
743765
STOP
744766
EOF
745767
cat >b.exp <<-EOF &&
746768
START
747769
init handshake complete
748-
IN: smudge test-delay10.b $S [OK] -- [DELAYED]
770+
IN: smudge test-delay10.b $M $S [OK] -- [DELAYED]
749771
IN: list_available_blobs test-delay10.b [OK]
750-
IN: smudge test-delay10.b 0 [OK] -- OUT: $S . [OK]
772+
IN: smudge test-delay10.b $M 0 [OK] -- OUT: $S . [OK]
751773
IN: list_available_blobs [OK]
752774
STOP
753775
EOF

t/t0021/rot13-filter.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ sub rot13 {
136136
$DELAY{$pathname}{"requested"} = 1;
137137
}
138138
} elsif ($buffer =~ /^(ref|treeish|blob)=/) {
139-
# Do nothing.
139+
print $debug " $buffer";
140140
} else {
141141
# In general, filters need to be graceful about
142142
# new metadata, since it's documented that we

unpack-trees.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ static int check_updates(struct unpack_trees_options *o)
371371
state.quiet = 1;
372372
state.refresh_cache = 1;
373373
state.istate = index;
374+
clone_checkout_metadata(&state.meta, &o->meta, NULL);
374375

375376
if (!o->update || o->dry_run) {
376377
remove_marked_cache_entries(index, 0);

unpack-trees.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct unpack_trees_options {
8585
struct index_state result;
8686

8787
struct pattern_list *pl; /* for internal use */
88+
struct checkout_metadata meta;
8889
};
8990

9091
int unpack_trees(unsigned n, struct tree_desc *t,

0 commit comments

Comments
 (0)