Re: [PATCH v2 05/12] fast-export: handle overridden main branch names correctly
Hi dscho
On 15/06/2020 13:50, Johannes Schindelin via GitGitGadget wrote:
Show 41 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> When anonymizing commit history, we are careful to translate the main
> branch name to `ref0`.
>
> When the main branch name is overridden via the config, we will want
> `git fast-export` to use that overridden name instead.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> builtin/fast-export.c | 11 ++++++++++-
> t/t9351-fast-export-anonymize.sh | 6 ++++++
> 2 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/fast-export.c b/builtin/fast-export.c
> index 1072bbf041f..deeb01b6937 100644
> --- a/builtin/fast-export.c
> +++ b/builtin/fast-export.c
> @@ -515,14 +515,23 @@ static const char *anonymize_refname(const char *refname)
> };
> static struct hashmap refs;
> static struct strbuf anon = STRBUF_INIT;
> + static char *main_branch;
> int i;
>
> /*
> * In certain circumstances, it might be interesting to be able to
> * identify the main branch. For that reason, let's force its name to
> * be anonymized to `ref0`.
> + *
> + * While the main branch name might often be `main` for new
> + * repositories (and `master` for aged ones), and such well-known names
> + * may not necessarily need anonymizing, it could be configured to use
> + * a secret word that the user may not want to reveal.
> */
> - if (!strcmp(refname, "refs/heads/master"))
> + if (!main_branch)
> + main_branch = git_main_branch_name(MAIN_BRANCH_FULL_NAME);
> +
> + if (!strcmp(refname, main_branch))
> return "refs/heads/ref0";
This leaks main_branch if it came from git_main_branch_name()
Best Wishes
Phillip
Show 19 quoted lines
> strbuf_reset(&anon);
> diff --git a/t/t9351-fast-export-anonymize.sh b/t/t9351-fast-export-anonymize.sh
> index 2415f0ec213..f42be635c2f 100755
> --- a/t/t9351-fast-export-anonymize.sh
> +++ b/t/t9351-fast-export-anonymize.sh
> @@ -31,6 +31,12 @@ test_expect_success 'stream translates master to ref0' '
> ! grep master stream
> '
>
> +test_expect_success 'respects configured main branch' '
> + git -c core.mainBranch=does-not-exist \
> + fast-export --anonymize --all >stream-without-ref0 &&
> + ! grep ref0 stream-without-ref0
> +'
> +
> test_expect_success 'stream omits other refnames' '
> ! grep other stream &&
> ! grep mytag stream
>