fast-export: fix anonymized tag using original length

Commit 7f4075949686 (fast-export: tighten anonymize_mem() interface to handle only strings, 2020-06-23) changed the interface used in anonymizing strings, but failed to update the size of annotated tag messages to match the new anonymized string. As a result, exporting tags having messages longer than 13 characters would create output that couldn't be parsed by fast-import, as the data length indicated was larger than the data output. Reset the message size when anonymizing, and add a tag with a "long" message to the test. Signed-off-by: Tal Kelrich <hasturkun@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tal Kelrich committed Aug 31, 2021 at 15:55 UTC 2f040a96711aaa576ce983b962b4e92abfa238b4
2 files changed +7 -4
builtin/fast-export.c
+1
@@ -821,6 +821,7 @@ static void handle_tag(const char *name, struct tag *tag)
821 static struct hashmap tags;
822 message = anonymize_str(&tags, anonymize_tag,
823 message, message_size, NULL);
824 + message_size = strlen(message);
825 }
826 }
827
t/t9351-fast-export-anonymize.sh
+6 -4
@@ -18,7 +18,8 @@ test_expect_success 'setup simple repo' '
18 git update-index --add --cacheinfo 160000,$fake_commit,link1 &&
19 git update-index --add --cacheinfo 160000,$fake_commit,link2 &&
20 git commit -m "add gitlink" &&
21 - git tag -m "annotated tag" mytag
21 + git tag -m "annotated tag" mytag &&
22 + git tag -m "annotated tag with long message" longtag
23 '
24
25 test_expect_success 'export anonymized stream' '
@@ -55,7 +56,8 @@ test_expect_success 'stream retains other as refname' '
56
57 test_expect_success 'stream omits other refnames' '
58 ! grep main stream &&
58 - ! grep mytag stream
59 + ! grep mytag stream &&
60 + ! grep longtag stream
61 '
62
63 test_expect_success 'stream omits identities' '
@@ -118,9 +120,9 @@ test_expect_success 'identical gitlinks got identical oid' '
120 test_line_count = 1 commits
121 '
122
121 -test_expect_success 'tag points to branch tip' '
123 +test_expect_success 'all tags point to branch tip' '
124 git rev-parse $other_branch >expect &&
123 - git for-each-ref --format="%(*objectname)" | grep . >actual &&
125 + git for-each-ref --format="%(*objectname)" | grep . | uniq >actual &&
126 test_cmp expect actual
127 '
128