git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org
Cc: don@goodman-wilson.com, stolee@gmail.com, peff@peff.net,
	sandals@crustytoothpaste.net, Matt Rogers <mattr94@gmail.com>,
	Eric Sunshine <sunshine@sunshineco.com>,
	Taylor Blau <me@ttaylorr.com>,
	Alban Gruin <alban.gruin@gmail.com>, Johannes Sixt <j6t@kdbg.org>,
	Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main branch name
Date: Mon, 15 Jun 2020 16:00:02 +0100	[thread overview]
Message-ID: <b530fe66-9cf6-ea63-e9e6-123448e2d978@gmail.com> (raw)
In-Reply-To: <f4d547391537e5c3b0b4a07adb41b6aa56541fc3.1592225416.git.gitgitgadget@gmail.com>

Hi dscho

On 15/06/2020 13:50, Johannes Schindelin via GitGitGadget wrote:
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
> 
> There is a growing number of projects and companies desiring to change
> the main branch name of their repositories (see e.g.
> https://twitter.com/mislav/status/1270388510684598272 for background on
> this).

I think this is a good way of phrasing the rationale for the change

> However, there are a couple of hard-coded spots in Git's source code
> that make this endeavor harder than necessary. For example, when
> formatting the commit message for merge commits, Git appends "into
> <branch-name>" unless the current branch is the `master` branch.
> 
> Clearly, this is not what one wants when already having gone through all
> the steps to manually rename the main branch

This didn't quite scan for me maybe s/already having/one has already/ ?

> (and taking care of all the
> fall-out such as re-targeting existing Pull Requests).
> 
> Let's introduce a way to override Git's hard-coded default:
> `core.mainBranch`.
> 
> We will start supporting this config option in the `git fmt-merge-msg`
> command and successively adjust all other places where the main branch
> name is hard-coded.
> 
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>   Documentation/config/core.txt |  5 +++++
>   fmt-merge-msg.c               |  6 ++++--
>   refs.c                        | 27 +++++++++++++++++++++++++++
>   refs.h                        |  7 +++++++
>   t/t6200-fmt-merge-msg.sh      |  7 +++++++
>   5 files changed, 50 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/config/core.txt b/Documentation/config/core.txt
> index 74619a9c03b..32bb5368ebb 100644
> --- a/Documentation/config/core.txt
> +++ b/Documentation/config/core.txt
> @@ -626,3 +626,8 @@ core.abbrev::
>   	in your repository, which hopefully is enough for
>   	abbreviated object names to stay unique for some time.
>   	The minimum length is 4.
> +
> +core.mainBranch::
> +	The name of the main (or: primary) branch in the current repository.
> +	For historical reasons, `master` is used as the fall-back for this
> +	setting.
> diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
> index 72d32bd73b1..43f4f829242 100644
> --- a/fmt-merge-msg.c
> +++ b/fmt-merge-msg.c
> @@ -407,7 +407,7 @@ static void fmt_merge_msg_title(struct strbuf *out,
>   				const char *current_branch)
>   {
>   	int i = 0;
> -	char *sep = "";
> +	char *sep = "", *main_branch;
>   
>   	strbuf_addstr(out, "Merge ");
>   	for (i = 0; i < srcs.nr; i++) {
> @@ -451,10 +451,12 @@ static void fmt_merge_msg_title(struct strbuf *out,
>   			strbuf_addf(out, " of %s", srcs.items[i].string);
>   	}
>   
> -	if (!strcmp("master", current_branch))
> +	main_branch = git_main_branch_name();
> +	if (!strcmp(main_branch, current_branch))
>   		strbuf_addch(out, '\n');
>   	else
>   		strbuf_addf(out, " into %s\n", current_branch);
> +	free(main_branch);
>   }
>   
>   static void fmt_tag_signature(struct strbuf *tagbuf,
> diff --git a/refs.c b/refs.c
> index 224ff66c7bb..f1854cffa2f 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -560,6 +560,33 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)
>   		argv_array_pushf(prefixes, *p, len, prefix);
>   }
>   
> +char *repo_main_branch_name(struct repository *r)
> +{
> +	const char *config_key = "core.mainbranch";
> +	const char *config_display_key = "core.mainBranch";
> +	const char *fall_back = "master";
> +	char *name = NULL, *ret;
> +
> +	if (repo_config_get_string(r, config_key, &name) < 0)
> +		die(_("could not retrieve `%s`"), config_display_key);
> +
> +	ret = name ? name : xstrdup(fall_back);
> +
> +	if (check_refname_format(ret, REFNAME_ALLOW_ONELEVEL))
> +		die(_("invalid branch name: %s = %s"),
> +		    config_display_key, name);
> +
> +	if (name != ret)
> +		free(name);

I'm struggling to come up with a scenario where name != NULL && name != 
ret here, however once we get to patch 4 that scenario definitely does 
exist.

> +
> +	return ret;
> +}
> +
> +char *git_main_branch_name(void)
> +{
> +	return repo_main_branch_name(the_repository);
> +}
> +
>   /*
>    * *string and *len will only be substituted, and *string returned (for
>    * later free()ing) if the string passed in is a magic short-hand form
> diff --git a/refs.h b/refs.h
> index a92d2c74c83..a207ef01348 100644
> --- a/refs.h
> +++ b/refs.h
> @@ -154,6 +154,13 @@ int repo_dwim_log(struct repository *r, const char *str, int len, struct object_
>   int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
>   int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
>   
> +/*
> + * Retrieves the name of the main (or: primary) branch of the given

nit pick, I'm confused by the ':'

Best Wishes

Phillip

> + * repository.
> + */
> +char *git_main_branch_name(void);
> +char *repo_main_branch_name(struct repository *r);
> +
>   /*
>    * A ref_transaction represents a collection of reference updates that
>    * should succeed or fail together.
> diff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh
> index e4c2a6eca43..7a873f4a05c 100755
> --- a/t/t6200-fmt-merge-msg.sh
> +++ b/t/t6200-fmt-merge-msg.sh
> @@ -158,6 +158,13 @@ test_expect_success 'setup FETCH_HEAD' '
>   	git fetch . left
>   '
>   
> +test_expect_success 'with overridden default branch name' '
> +	test_when_finished "git switch master" &&
> +	git switch -c default &&
> +	git -c core.mainBranch=default fmt-merge-msg <.git/FETCH_HEAD >actual &&
> +	! grep "into default" actual
> +'
> +
>   test_expect_success 'merge.log=3 limits shortlog length' '
>   	cat >expected <<-EOF &&
>   	Merge branch ${apos}left${apos}
> 

  reply	other threads:[~2020-06-15 15:00 UTC|newest]

Thread overview: 180+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-10 21:19 [PATCH 0/9] Allow overriding the default name of the default branch Johannes Schindelin via GitGitGadget
2020-06-10 21:19 ` [PATCH 1/9] init: allow overriding the default branch name for new repositories Don Goodman-Wilson via GitGitGadget
2020-06-10 23:22   ` brian m. carlson
2020-06-11  0:16   ` Eric Sunshine
2020-06-11 14:09     ` Johannes Schindelin
2020-06-11 15:28       ` Junio C Hamano
2020-06-16 12:45     ` Jeff King
2020-06-16 12:47       ` Jeff King
2020-06-18 13:08         ` Johannes Schindelin
2020-06-23 20:32       ` Johannes Schindelin
2020-06-11  9:35   ` Phillip Wood
2020-06-12 11:55     ` Johannes Schindelin
2020-06-12 16:51       ` Junio C Hamano
2020-06-14 22:00         ` Johannes Schindelin
2020-06-15 10:00         ` Phillip Wood
2020-06-11 10:23   ` Alban Gruin
2020-06-11 23:14     ` Junio C Hamano
2020-06-11 23:46       ` brian m. carlson
2020-06-12 12:45         ` Johannes Schindelin
2020-06-13 18:01       ` Alban Gruin
2020-06-14  8:57         ` Johannes Schindelin
2020-06-16 12:25           ` Jeff King
2020-06-18 10:17             ` Johannes Schindelin
2020-06-10 21:19 ` [PATCH 2/9] remote: respect `core.defaultBranchName` Johannes Schindelin via GitGitGadget
2020-06-16 12:35   ` Jeff King
2020-06-18 10:21     ` Johannes Schindelin
2020-06-18 11:50       ` Jeff King
2020-06-23 21:15         ` Johannes Schindelin
2020-06-10 21:19 ` [PATCH 3/9] send-pack/transport-helper: " Johannes Schindelin via GitGitGadget
2020-06-10 21:19 ` [PATCH 4/9] testsvn: " Johannes Schindelin via GitGitGadget
2020-06-10 21:19 ` [PATCH 5/9] submodule: use the (possibly overridden) default branch name Johannes Schindelin via GitGitGadget
2020-06-15 10:46   ` Denton Liu
2020-06-10 21:19 ` [PATCH 6/9] clone: learn about the possibly-configured " Johannes Schindelin via GitGitGadget
2020-06-10 22:58   ` Junio C Hamano
2020-06-10 21:19 ` [PATCH 7/9] fmt-merge-msg: " Johannes Schindelin via GitGitGadget
2020-06-10 22:59   ` Junio C Hamano
2020-06-10 21:19 ` [PATCH 8/9] fast-export: respect the possibly-overridden " Johannes Schindelin via GitGitGadget
2020-06-10 21:54   ` Matt Rogers
2020-06-10 23:25     ` Junio C Hamano
2020-06-10 23:39     ` brian m. carlson
2020-06-11  0:20       ` Matt Rogers
2020-06-11  5:26         ` Junio C Hamano
2020-06-11 14:05           ` Johannes Schindelin
2020-06-11 15:05             ` Re* " Junio C Hamano
2020-06-11 16:44               ` Junio C Hamano
2020-06-11 18:18                 ` Junio C Hamano
2020-06-12 12:07                   ` Johannes Schindelin
2020-06-12 12:32                     ` Junio C Hamano
2020-06-12 12:03               ` Johannes Schindelin
2020-06-12 12:50                 ` Junio C Hamano
2020-06-12 12:53               ` Johannes Schindelin
2020-06-12 13:18                 ` Johannes Schindelin
2020-06-12 15:19                   ` Junio C Hamano
2020-06-12 15:22                     ` Junio C Hamano
2020-06-13  5:00                       ` Johannes Schindelin
2020-06-12 15:14                 ` Junio C Hamano
2020-06-13 11:49                   ` Johannes Sixt
2020-06-13 16:25                     ` Junio C Hamano
2020-06-13 14:47                       ` Johannes Schindelin
2020-06-13 18:49                         ` Junio C Hamano
2020-06-14  8:55                           ` Johannes Schindelin
2020-06-17 20:06                             ` Junio C Hamano
2020-06-23 21:11                               ` Johannes Schindelin
2020-06-23 21:32                                 ` Junio C Hamano
2020-06-13 14:44                   ` Johannes Schindelin
2020-06-11 13:57     ` Johannes Schindelin
2020-06-11 18:19       ` Junio C Hamano
2020-06-12 12:07         ` Johannes Schindelin
2020-06-10 21:19 ` [PATCH 9/9] Document how the default branch name can be overridden Johannes Schindelin via GitGitGadget
2020-06-11  0:18   ` Junio C Hamano
2020-06-10 23:11 ` [PATCH 0/9] Allow overriding the default name of the default branch Junio C Hamano
2020-06-11  5:42   ` Junio C Hamano
2020-06-11 13:44   ` Johannes Schindelin
2020-06-11 14:44     ` Junio C Hamano
2020-06-10 23:41 ` brian m. carlson
2020-06-11  1:07 ` Taylor Blau
2020-06-11 14:33   ` Johannes Schindelin
2020-06-15 10:03 ` Pratyush Yadav
2020-06-14 22:26   ` Johannes Schindelin
2020-06-16  0:19     ` Denton Liu
2020-06-23 20:10       ` Johannes Schindelin
2020-06-15 23:10   ` brian m. carlson
2020-06-15 12:50 ` [PATCH v2 00/12] " Johannes Schindelin via GitGitGadget
2020-06-15 12:50   ` [PATCH v2 01/12] fast-export: do anonymize the primary branch name Junio C Hamano via GitGitGadget
2020-06-16 12:58     ` Jeff King
2020-06-17 18:16       ` Junio C Hamano
2020-06-17 21:23         ` Jeff King
2020-06-18  2:06           ` Elijah Newren
2020-06-18  6:30             ` Junio C Hamano
2020-06-18  7:13               ` Elijah Newren
2020-06-18 11:45             ` Jeff King
2020-06-15 12:50   ` [PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main " Johannes Schindelin via GitGitGadget
2020-06-15 15:00     ` Phillip Wood [this message]
2020-06-23 12:31       ` Johannes Schindelin
2020-06-15 17:05     ` Junio C Hamano
2020-06-23 19:19       ` Johannes Schindelin
2020-06-16  8:46     ` Ævar Arnfjörð Bjarmason
2020-06-17 18:21       ` Junio C Hamano
2020-06-16 13:04     ` Jeff King
2020-06-17 18:23       ` Junio C Hamano
2020-06-18 13:15         ` Johannes Schindelin
2020-06-17 20:56     ` Johannes Sixt
2020-06-17 21:16       ` Junio C Hamano
2020-06-23 21:12         ` Johannes Schindelin
2020-06-15 12:50   ` [PATCH v2 03/12] send-pack/transport-helper: respect `core.mainBranch` Johannes Schindelin via GitGitGadget
2020-06-15 12:50   ` [PATCH v2 04/12] git_main_branch_name(): optionally report the full ref name Johannes Schindelin via GitGitGadget
2020-06-15 15:04     ` Phillip Wood
2020-06-23 19:17       ` Johannes Schindelin
2020-06-15 12:50   ` [PATCH v2 05/12] fast-export: handle overridden main branch names correctly Johannes Schindelin via GitGitGadget
2020-06-15 15:05     ` Phillip Wood
2020-06-16 13:10       ` Jeff King
2020-06-16 15:49         ` Phillip Wood
2020-06-18 10:08         ` Johannes Schindelin
2020-06-15 17:09     ` Junio C Hamano
2020-06-23 19:22       ` Johannes Schindelin
2020-06-15 12:50   ` [PATCH v2 06/12] branch -m: adjust `core.mainBranch` if necessary Johannes Schindelin via GitGitGadget
2020-06-15 12:50   ` [PATCH v2 07/12] init: allow specifying the main branch name for the new repository Johannes Schindelin via GitGitGadget
2020-06-15 12:50   ` [PATCH v2 08/12] init: allow overriding the default main branch name via the config Don Goodman-Wilson via GitGitGadget
2020-06-15 12:50   ` [PATCH v2 09/12] clone: handle overridden main branch names Johannes Schindelin via GitGitGadget
2020-06-16 13:22     ` Jeff King
2020-06-23 20:58       ` Johannes Schindelin
2020-06-15 12:50   ` [PATCH v2 10/12] remote: learn about the possibly-overridden default main branch name Johannes Schindelin via GitGitGadget
2020-06-15 12:50   ` [PATCH v2 11/12] submodule: use the correct default for the " Johannes Schindelin via GitGitGadget
2020-06-16 13:46     ` Jeff King
2020-06-23 21:03       ` Johannes Schindelin
2020-06-23 21:14         ` Jeff King
2020-06-15 12:50   ` [PATCH v2 12/12] testsvn: respect `init.defaultBranch` Johannes Schindelin via GitGitGadget
2020-06-16 13:51     ` Jeff King
2020-06-23 21:07       ` Johannes Schindelin
2020-06-23 22:33   ` [PATCH v3 0/8] Allow overriding the default name of the default branch Johannes Schindelin via GitGitGadget
2020-06-23 22:33     ` [PATCH v3 1/8] fmt-merge-msg: stop treating `master` specially Johannes Schindelin via GitGitGadget
2020-06-24 16:16       ` Junio C Hamano
2020-06-25 13:07         ` Johannes Schindelin
2020-06-23 22:33     ` [PATCH v3 2/8] send-pack/transport-helper: avoid mentioning a particular branch Johannes Schindelin via GitGitGadget
2020-06-24  0:36       ` Junio C Hamano
2020-06-24 12:44         ` Johannes Schindelin
2020-06-24 15:44           ` Junio C Hamano
2020-06-25 13:05             ` Johannes Schindelin
2020-06-23 22:33     ` [PATCH v3 3/8] submodule: use a better fall-back for missing remote.<name>.branch Johannes Schindelin via GitGitGadget
2020-06-24  2:18       ` Philippe Blain
2020-06-24 12:51         ` Johannes Schindelin
2020-06-23 22:33     ` [PATCH v3 4/8] init: allow specifying the initial branch name for the new repository Johannes Schindelin via GitGitGadget
2020-06-24  0:58       ` Junio C Hamano
2020-06-24 12:55         ` Johannes Schindelin
2020-06-23 22:33     ` [PATCH v3 5/8] init: allow setting the default for the initial branch name via the config Don Goodman-Wilson via GitGitGadget
2020-06-24  1:05       ` Junio C Hamano
2020-06-24 12:56         ` Johannes Schindelin
2020-06-24 16:25           ` Junio C Hamano
2020-06-23 22:33     ` [PATCH v3 6/8] clone: use configured default branch name when appropriate Johannes Schindelin via GitGitGadget
2020-06-23 22:33     ` [PATCH v3 7/8] remote: use the " Johannes Schindelin via GitGitGadget
2020-06-24  1:10       ` Junio C Hamano
2020-06-24 13:00         ` Johannes Schindelin
2020-06-23 22:33     ` [PATCH v3 8/8] testsvn: respect `init.defaultBranch` Johannes Schindelin via GitGitGadget
2020-06-24 14:46     ` [PATCH v4 0/9] Allow overriding the default name of the default branch Johannes Schindelin via GitGitGadget
2020-06-24 14:46       ` [PATCH v4 1/9] fmt-merge-msg: stop treating `master` specially Johannes Schindelin via GitGitGadget
2020-06-29 16:20         ` Đoàn Trần Công Danh
2020-06-29 13:27           ` Johannes Schindelin
2020-06-30 15:05             ` Đoàn Trần Công Danh
2020-07-01 10:39               ` Johannes Schindelin
2020-07-01 19:54                 ` Junio C Hamano
2020-06-24 14:46       ` [PATCH v4 2/9] send-pack/transport-helper: avoid mentioning a particular branch Johannes Schindelin via GitGitGadget
2020-06-24 14:46       ` [PATCH v4 3/9] submodule: fall back to remote's HEAD for missing remote.<name>.branch Johannes Schindelin via GitGitGadget
2020-06-24 16:17         ` Junio C Hamano
2020-06-24 14:46       ` [PATCH v4 4/9] docs: add missing diamond brackets Johannes Schindelin via GitGitGadget
2020-06-24 14:46       ` [PATCH v4 5/9] init: allow specifying the initial branch name for the new repository Johannes Schindelin via GitGitGadget
2020-06-24 14:46       ` [PATCH v4 6/9] init: allow setting the default for the initial branch name via the config Don Goodman-Wilson via GitGitGadget
2020-06-24 14:46       ` [PATCH v4 7/9] clone: use configured default branch name when appropriate Johannes Schindelin via GitGitGadget
2020-06-24 14:46       ` [PATCH v4 8/9] remote: use the " Johannes Schindelin via GitGitGadget
2020-06-24 14:46       ` [PATCH v4 9/9] testsvn: respect `init.defaultBranch` Johannes Schindelin via GitGitGadget
2020-06-24 16:26       ` [PATCH v4 0/9] Allow overriding the default name of the default branch Junio C Hamano
2020-06-25 13:03         ` Johannes Schindelin
2020-06-29 22:41       ` brian m. carlson
2020-07-12 13:03         ` Edward Thomson
2020-07-12  8:19           ` Johannes Schindelin
     [not found]             ` <CA+WKDT1GMNTY5N862-7ui70D6-b1u6fuUkvctEYo+57aJGbjmw@mail.gmail.com>
2020-07-14 14:55               ` Johannes Schindelin
2020-06-16  9:47 ` [PATCH " Ævar Arnfjörð Bjarmason
2020-06-16 14:09   ` Jeff King
2020-06-16 14:24     ` Jeff King
2020-06-23 20:28       ` Johannes Schindelin
2020-06-17 20:28   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b530fe66-9cf6-ea63-e9e6-123448e2d978@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=alban.gruin@gmail.com \
    --cc=don@goodman-wilson.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=j6t@kdbg.org \
    --cc=johannes.schindelin@gmx.de \
    --cc=mattr94@gmail.com \
    --cc=me@ttaylorr.com \
    --cc=peff@peff.net \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=sandals@crustytoothpaste.net \
    --cc=stolee@gmail.com \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).