]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fast-export: anonymize "master" refname
authorJeff King <peff@peff.net>
Thu, 25 Jun 2020 19:48:35 +0000 (15:48 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 Jun 2020 21:19:23 +0000 (14:19 -0700)
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fast-export.c
t/t9351-fast-export-anonymize.sh

index b0b09bca30e1ec1a329e183a5e8531fe62b4b209..c6ecf404d700295c424fb6fca7d6d057f7e4fc41 100644 (file)
@@ -538,13 +538,6 @@ static const char *anonymize_refname(const char *refname)
        static struct strbuf anon = STRBUF_INIT;
        int i;
 
-       /*
-        * We also leave "master" as a special case, since it does not reveal
-        * anything interesting.
-        */
-       if (!strcmp(refname, "refs/heads/master"))
-               return refname;
-
        strbuf_reset(&anon);
        for (i = 0; i < ARRAY_SIZE(prefixes); i++) {
                if (skip_prefix(refname, prefixes[i], &refname)) {
index 5a21c7156870a74ca278aea6527f05a716bff201..5ac2c3b5eef0657e25418b4a6656b7e63edd8821 100755 (executable)
@@ -22,6 +22,7 @@ test_expect_success 'export anonymized stream' '
        git fast-export --anonymize --all \
                --anonymize-map=retain-me \
                --anonymize-map=xyzzy:custom-name \
+               --anonymize-map=other \
                >stream
 '
 
@@ -45,12 +46,12 @@ test_expect_success 'stream omits gitlink oids' '
        ! grep a000000000000000000 stream
 '
 
-test_expect_success 'stream allows master as refname' '
-       grep master stream
+test_expect_success 'stream retains other as refname' '
+       grep other stream
 '
 
 test_expect_success 'stream omits other refnames' '
-       ! grep other stream &&
+       ! grep master stream &&
        ! grep mytag stream
 '
 
@@ -76,7 +77,8 @@ test_expect_success 'import stream to new repository' '
 test_expect_success 'result has two branches' '
        git for-each-ref --format="%(refname)" refs/heads >branches &&
        test_line_count = 2 branches &&
-       other_branch=$(grep -v refs/heads/master branches)
+       other_branch=refs/heads/other &&
+       main_branch=$(grep -v $other_branch branches)
 '
 
 test_expect_success 'repo has original shape and timestamps' '
@@ -84,7 +86,7 @@ test_expect_success 'repo has original shape and timestamps' '
                git log --format="%m %ct" --left-right --boundary "$@"
        } &&
        (cd .. && shape master...other) >expect &&
-       shape master...$other_branch >actual &&
+       shape $main_branch...$other_branch >actual &&
        test_cmp expect actual
 '