Skip to content

Commit a082e28

Browse files
Linus Arvergitster
authored andcommitted
shortlog: add test for de-duplicating folded trailers
The shortlog builtin was taught to use the trailer iterator interface in 47beb37 (shortlog: match commit trailers with --group, 2020-09-27). The iterator always unfolds values and this has always been the case since the time the iterator was first introduced in f0939a0 (trailer: add interface for iterating over commit trailers, 2020-09-27). Add a comment line to remind readers of this behavior. The fact that the iterator always unfolds values is important (at least for shortlog) because unfolding allows it to recognize both folded and unfolded versions of the same trailer for de-duplication. Capture the existing behavior in a new test case to guard against regressions in this area. This test case is based off of the existing "shortlog de-duplicates trailers in a single commit" just above it. Now if we were to remove the call to unfold_value(&iter->val); inside the iterator, this new test case will break. Signed-off-by: Linus Arver <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0f3a461 commit a082e28

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

t/t4201-shortlog.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,38 @@ test_expect_success 'shortlog de-duplicates trailers in a single commit' '
312312
test_cmp expect actual
313313
'
314314

315+
# Trailers that have unfolded (single line) and folded (multiline) values which
316+
# are otherwise identical are treated as the same trailer for de-duplication.
317+
test_expect_success 'shortlog de-duplicates trailers in a single commit (folded/unfolded values)' '
318+
git commit --allow-empty -F - <<-\EOF &&
319+
subject one
320+
321+
this message has two distinct values, plus a repeat (folded)
322+
323+
Repeated-trailer: Foo foo foo
324+
Repeated-trailer: Bar
325+
Repeated-trailer: Foo
326+
foo foo
327+
EOF
328+
329+
git commit --allow-empty -F - <<-\EOF &&
330+
subject two
331+
332+
similar to the previous, but without the second distinct value
333+
334+
Repeated-trailer: Foo foo foo
335+
Repeated-trailer: Foo
336+
foo foo
337+
EOF
338+
339+
cat >expect <<-\EOF &&
340+
2 Foo foo foo
341+
1 Bar
342+
EOF
343+
git shortlog -ns --group=trailer:repeated-trailer -2 HEAD >actual &&
344+
test_cmp expect actual
345+
'
346+
315347
test_expect_success 'shortlog can match multiple groups' '
316348
git commit --allow-empty -F - <<-\EOF &&
317349
subject one

trailer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,7 @@ int trailer_iterator_advance(struct trailer_iterator *iter)
12701270
strbuf_reset(&iter->val);
12711271
parse_trailer(&iter->key, &iter->val, NULL,
12721272
trailer, separator_pos);
1273+
/* Always unfold values during iteration. */
12731274
unfold_value(&iter->val);
12741275
return 1;
12751276
}

0 commit comments

Comments
 (0)