Skip to content

Commit 8a49495

Browse files
peffgitster
authored andcommitted
fast-export: anonymize "master" refname
Running "fast-export --anonymize" will leave "refs/heads/master" untouched in the output, for two reasons: - it helped to have some known reference point between the original and anonymized repository - since it's historically the default branch name, it doesn't leak any information Now that we can ask fast-export to retain particular tokens, we have a much better tool for the first one (because it works for any ref, not just master). For the second, the notion of "default branch name" is likely to become configurable soon, at which point the name _does_ leak information. Let's drop this special case in preparation. Note that we have to adjust the test a bit, since it relied on using the name "master" in the anonymized repos. We could just use --anonymize-map=master to keep the same output, but then we wouldn't know if it works because of our hard-coded master or because of the explicit map. So let's flip the test a bit, and confirm that we anonymize "master", but keep "other" in the output. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 65b5d9f commit 8a49495

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

builtin/fast-export.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,6 @@ static const char *anonymize_refname(const char *refname)
538538
static struct strbuf anon = STRBUF_INIT;
539539
int i;
540540

541-
/*
542-
* We also leave "master" as a special case, since it does not reveal
543-
* anything interesting.
544-
*/
545-
if (!strcmp(refname, "refs/heads/master"))
546-
return refname;
547-
548541
strbuf_reset(&anon);
549542
for (i = 0; i < ARRAY_SIZE(prefixes); i++) {
550543
if (skip_prefix(refname, prefixes[i], &refname)) {

t/t9351-fast-export-anonymize.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ test_expect_success 'export anonymized stream' '
2222
git fast-export --anonymize --all \
2323
--anonymize-map=retain-me \
2424
--anonymize-map=xyzzy:custom-name \
25+
--anonymize-map=other \
2526
>stream
2627
'
2728

@@ -45,12 +46,12 @@ test_expect_success 'stream omits gitlink oids' '
4546
! grep a000000000000000000 stream
4647
'
4748

48-
test_expect_success 'stream allows master as refname' '
49-
grep master stream
49+
test_expect_success 'stream retains other as refname' '
50+
grep other stream
5051
'
5152

5253
test_expect_success 'stream omits other refnames' '
53-
! grep other stream &&
54+
! grep master stream &&
5455
! grep mytag stream
5556
'
5657

@@ -76,15 +77,16 @@ test_expect_success 'import stream to new repository' '
7677
test_expect_success 'result has two branches' '
7778
git for-each-ref --format="%(refname)" refs/heads >branches &&
7879
test_line_count = 2 branches &&
79-
other_branch=$(grep -v refs/heads/master branches)
80+
other_branch=refs/heads/other &&
81+
main_branch=$(grep -v $other_branch branches)
8082
'
8183

8284
test_expect_success 'repo has original shape and timestamps' '
8385
shape () {
8486
git log --format="%m %ct" --left-right --boundary "$@"
8587
} &&
8688
(cd .. && shape master...other) >expect &&
87-
shape master...$other_branch >actual &&
89+
shape $main_branch...$other_branch >actual &&
8890
test_cmp expect actual
8991
'
9092

0 commit comments

Comments
 (0)