Skip to content

Commit 728350b

Browse files
peffgitster
authored andcommitted
revision.c: propagate tag names from pending array
When we unwrap a tag to find its commit for a traversal, we do not propagate the "name" field of the tag in the pending array (i.e., the ref name the user gave us in the first place) to the commit (instead, we use an empty string). This means that "git log --source" will never show the tag-name for commits we reach through it. This was broken in 2073949 (traverse_commit_list: support pending blobs/trees with paths, 2014-10-15). That commit tried to be careful and avoid propagating the path information for a tag (which would be nonsensical) to trees and blobs. But it should not have cut off the "name" field, which should carry forward to children. Note that this does mean that the "name" field will carry forward to blobs and trees, too. Whereas prior to 2073949, we always gave them an empty string. This is the right thing to do, but in practice no callers probably use it (since now we have an explicit separate "path" field, which was the point of 2073949). We add tests here not only for the broken case, but also a basic sanity test of "log --source" in general, which did not have any coverage in the test suite. Reported-by: Raymundo <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2073949 commit 728350b

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

revision.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,8 @@ static struct commit *handle_commit(struct rev_info *revs,
300300
/*
301301
* We'll handle the tagged object by looping or dropping
302302
* through to the non-tag handlers below. Do not
303-
* propagate data from the tag's pending entry.
303+
* propagate path data from the tag's pending entry.
304304
*/
305-
name = "";
306305
path = NULL;
307306
mode = 0;
308307
}

t/t4202-log.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,4 +872,33 @@ test_expect_success GPG 'log --graph --show-signature for merged tag' '
872872
grep "^| | gpg: Good signature" actual
873873
'
874874

875+
test_expect_success 'set up --source tests' '
876+
git checkout --orphan source-a &&
877+
test_commit one &&
878+
test_commit two &&
879+
git checkout -b source-b HEAD^ &&
880+
test_commit three
881+
'
882+
883+
test_expect_success 'log --source paints branch names' '
884+
cat >expect <<-\EOF &&
885+
09e12a9 source-b three
886+
8e393e1 source-a two
887+
1ac6c77 source-b one
888+
EOF
889+
git log --oneline --source source-a source-b >actual &&
890+
test_cmp expect actual
891+
'
892+
893+
test_expect_success 'log --source paints tag names' '
894+
git tag -m tagged source-tag &&
895+
cat >expect <<-\EOF &&
896+
09e12a9 source-tag three
897+
8e393e1 source-a two
898+
1ac6c77 source-tag one
899+
EOF
900+
git log --oneline --source source-tag source-a >actual &&
901+
test_cmp expect actual
902+
'
903+
875904
test_done

0 commit comments

Comments
 (0)