shortlog: add test for de-duplicating folded trailers

The shortlog builtin was taught to use the trailer iterator interface in 47beb37bc6 (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 f0939a0eb1 (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 <linusa@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Arver committed Mar 1, 2024 at 00:14 UTC a082e2893868be819b5486e9af3e390a7c948ee2
2 files changed +33
t/t4201-shortlog.sh
+32
@@ -312,6 +312,38 @@ test_expect_success 'shortlog de-duplicates trailers in a single commit' '
312 test_cmp expect actual
313 '
314
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 +
347 test_expect_success 'shortlog can match multiple groups' '
348 git commit --allow-empty -F - <<-\EOF &&
349 subject one
trailer.c
+1
@@ -1270,6 +1270,7 @@ int trailer_iterator_advance(struct trailer_iterator *iter)
1270 strbuf_reset(&iter->val);
1271 parse_trailer(&iter->key, &iter->val, NULL,
1272 trailer, separator_pos);
1273 + /* Always unfold values during iteration. */
1274 unfold_value(&iter->val);
1275 return 1;
1276 }