All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Schindelin <johannes.schindelin@gmx.de>,
	Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH 2/3] get_default_branch_name(): prepare for showing some advice
Date: Sun, 22 Nov 2020 23:23:25 +0000	[thread overview]
Message-ID: <42f694004322361b5495f2ce1a2eba638644f754.1606087406.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.921.git.git.1606087406.gitgitgadget@gmail.com>

From: Johannes Schindelin <johannes.schindelin@gmx.de>

We are about to introduce a message giving users running `git init` some
advice about `init.defaultBranch`. This will necessarily be done in
`repo_default_branch_name()`.

Not all code paths want to show that advice, though. In particular, the
`git clone` codepath _specifically_ asks for `init_db()` to be quiet,
via the `INIT_DB_QUIET` flag.

In preparation for showing users above-mentioned advice, let's change
the function signature of `get_default_branch_name()` to accept the
parameter `quiet`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/clone.c   | 2 +-
 builtin/init-db.c | 8 +++++---
 refs.c            | 6 +++---
 refs.h            | 4 ++--
 remote.c          | 5 +++--
 5 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index a0841923cf..64b1784011 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -1323,7 +1323,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		remote_head = NULL;
 		option_no_checkout = 1;
 		if (!option_bare) {
-			const char *branch = git_default_branch_name();
+			const char *branch = git_default_branch_name(0);
 			char *ref = xstrfmt("refs/heads/%s", branch);
 
 			install_branch_config(0, branch, remote_name, ref);
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 01bc648d41..dcc45bef51 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -202,7 +202,8 @@ void initialize_repository_version(int hash_algo, int reinit)
 static int create_default_files(const char *template_path,
 				const char *original_git_dir,
 				const char *initial_branch,
-				const struct repository_format *fmt)
+				const struct repository_format *fmt,
+				int quiet)
 {
 	struct stat st1;
 	struct strbuf buf = STRBUF_INIT;
@@ -267,7 +268,7 @@ static int create_default_files(const char *template_path,
 		char *ref;
 
 		if (!initial_branch)
-			initial_branch = git_default_branch_name();
+			initial_branch = git_default_branch_name(quiet);
 
 		ref = xstrfmt("refs/heads/%s", initial_branch);
 		if (check_refname_format(ref, 0) < 0)
@@ -438,7 +439,8 @@ int init_db(const char *git_dir, const char *real_git_dir,
 	validate_hash_algorithm(&repo_fmt, hash);
 
 	reinit = create_default_files(template_dir, original_git_dir,
-				      initial_branch, &repo_fmt);
+				      initial_branch, &repo_fmt,
+				      flags & INIT_DB_QUIET);
 	if (reinit && initial_branch)
 		warning(_("re-init: ignored --initial-branch=%s"),
 			initial_branch);
diff --git a/refs.c b/refs.c
index 392f0bbf68..8df03122d6 100644
--- a/refs.c
+++ b/refs.c
@@ -562,7 +562,7 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix)
 		strvec_pushf(prefixes, *p, len, prefix);
 }
 
-char *repo_default_branch_name(struct repository *r)
+char *repo_default_branch_name(struct repository *r, int quiet)
 {
 	const char *config_key = "init.defaultbranch";
 	const char *config_display_key = "init.defaultBranch";
@@ -585,12 +585,12 @@ char *repo_default_branch_name(struct repository *r)
 	return ret;
 }
 
-const char *git_default_branch_name(void)
+const char *git_default_branch_name(int quiet)
 {
 	static char *ret;
 
 	if (!ret)
-		ret = repo_default_branch_name(the_repository);
+		ret = repo_default_branch_name(the_repository, quiet);
 
 	return ret;
 }
diff --git a/refs.h b/refs.h
index 6695518156..ff05d2e9fe 100644
--- a/refs.h
+++ b/refs.h
@@ -170,8 +170,8 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
  * The return value of `repo_default_branch_name()` is an allocated string. The
  * return value of `git_default_branch_name()` is a singleton.
  */
-const char *git_default_branch_name(void);
-char *repo_default_branch_name(struct repository *r);
+const char *git_default_branch_name(int quiet);
+char *repo_default_branch_name(struct repository *r, int quiet);
 
 /*
  * A ref_transaction represents a collection of reference updates that
diff --git a/remote.c b/remote.c
index 8a6dbbb903..bdb88d4b7d 100644
--- a/remote.c
+++ b/remote.c
@@ -284,7 +284,7 @@ static void read_branches_file(struct remote *remote)
 	if (frag)
 		*(frag++) = '\0';
 	else
-		frag = (char *)git_default_branch_name();
+		frag = (char *)git_default_branch_name(0);
 
 	add_url_alias(remote, strbuf_detach(&buf, NULL));
 	refspec_appendf(&remote->fetch, "refs/heads/%s:refs/heads/%s",
@@ -2206,7 +2206,8 @@ struct ref *guess_remote_head(const struct ref *head,
 
 	/* If a remote branch exists with the default branch name, let's use it. */
 	if (!all) {
-		char *ref = xstrfmt("refs/heads/%s", git_default_branch_name());
+		char *ref = xstrfmt("refs/heads/%s",
+				    git_default_branch_name(0));
 
 		r = find_ref_by_name(refs, ref);
 		free(ref);
-- 
gitgitgadget


  parent reply	other threads:[~2020-11-22 23:23 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-22 23:23 [PATCH 0/3] Add helpful advice about init.defaultBranch Johannes Schindelin via GitGitGadget
2020-11-22 23:23 ` [PATCH 1/3] init: document `init.defaultBranch` better Johannes Schindelin via GitGitGadget
2020-11-22 23:40   ` Junio C Hamano
2020-11-23 12:07     ` Johannes Schindelin
2020-11-22 23:23 ` Johannes Schindelin via GitGitGadget [this message]
2020-11-22 23:23 ` [PATCH 3/3] init: provide useful advice about init.defaultBranch Johannes Schindelin via GitGitGadget
2020-11-22 23:53   ` Junio C Hamano
2020-11-23  2:07     ` Junio C Hamano
2020-11-23 12:28       ` Johannes Schindelin
2020-11-23 18:40         ` Junio C Hamano
2020-11-23 20:46           ` Johannes Schindelin
2020-11-23 21:28             ` Junio C Hamano
2020-11-23 12:26     ` Johannes Schindelin
2020-11-23 12:49   ` Philip Oakley
2020-11-23 20:47     ` Johannes Schindelin
2020-11-23 23:20 ` [PATCH v2 0/4] Add helpful " Johannes Schindelin via GitGitGadget
2020-11-23 23:20   ` [PATCH v2 1/4] init: document `init.defaultBranch` better Johannes Schindelin via GitGitGadget
2020-11-23 23:20   ` [PATCH v2 2/4] branch -m: allow renaming a yet-unborn branch Johannes Schindelin via GitGitGadget
2020-11-23 23:45     ` Junio C Hamano
2020-11-24  5:47       ` Johannes Schindelin
2020-11-24 20:14         ` Junio C Hamano
2020-11-23 23:20   ` [PATCH v2 3/4] get_default_branch_name(): prepare for showing some advice Johannes Schindelin via GitGitGadget
2020-11-23 23:20   ` [PATCH v2 4/4] init: provide useful advice about init.defaultBranch Johannes Schindelin via GitGitGadget
2020-11-23 23:53     ` Junio C Hamano
2020-11-24  5:57       ` Johannes Schindelin
2020-11-24 20:53         ` Junio C Hamano
2020-12-09 14:47           ` Johannes Schindelin
2020-12-09 22:15             ` Junio C Hamano
2020-12-10 12:12               ` Johannes Schindelin
2020-12-10 23:32                 ` Junio C Hamano
2020-12-10  0:40             ` Felipe Contreras
2020-11-24 15:07   ` [PATCH v3 0/4] Add helpful " Johannes Schindelin via GitGitGadget
2020-11-24 15:07     ` [PATCH v3 1/4] init: document `init.defaultBranch` better Johannes Schindelin via GitGitGadget
2020-11-24 15:07     ` [PATCH v3 2/4] branch -m: allow renaming a yet-unborn branch Johannes Schindelin via GitGitGadget
2020-11-24 15:07     ` [PATCH v3 3/4] get_default_branch_name(): prepare for showing some advice Johannes Schindelin via GitGitGadget
2020-11-24 15:07     ` [PATCH v3 4/4] init: provide useful advice about init.defaultBranch Johannes Schindelin via GitGitGadget
2020-12-10 21:58     ` [PATCH v4 0/4] Add helpful " Johannes Schindelin via GitGitGadget
2020-12-10 21:58       ` [PATCH v4 1/4] init: document `init.defaultBranch` better Johannes Schindelin via GitGitGadget
2020-12-11  0:24         ` Felipe Contreras
2020-12-11  5:47           ` Junio C Hamano
2020-12-11  6:26             ` Felipe Contreras
2020-12-11  5:59           ` Junio C Hamano
2020-12-10 21:58       ` [PATCH v4 2/4] branch -m: allow renaming a yet-unborn branch Johannes Schindelin via GitGitGadget
2020-12-10 21:58       ` [PATCH v4 3/4] get_default_branch_name(): prepare for showing some advice Johannes Schindelin via GitGitGadget
2020-12-10 21:58       ` [PATCH v4 4/4] init: provide useful advice about init.defaultBranch Johannes Schindelin via GitGitGadget
2020-12-11  0:15         ` Felipe Contreras
2020-12-11  1:22           ` Junio C Hamano
2020-12-11  0:47             ` Johannes Schindelin
2020-12-11  2:00             ` Felipe Contreras
2020-12-11 11:36       ` [PATCH v5 0/4] Add helpful " Johannes Schindelin via GitGitGadget
2020-12-11 11:36         ` [PATCH v5 1/4] init: document `init.defaultBranch` better Johannes Schindelin via GitGitGadget
2020-12-11 11:36         ` [PATCH v5 2/4] branch -m: allow renaming a yet-unborn branch Johannes Schindelin via GitGitGadget
2020-12-11 11:36         ` [PATCH v5 3/4] get_default_branch_name(): prepare for showing some advice Johannes Schindelin via GitGitGadget
2020-12-11 11:36         ` [PATCH v5 4/4] init: provide useful advice about init.defaultBranch Johannes Schindelin via GitGitGadget
2021-02-02 21:24           ` SZEDER Gábor
2021-02-02 22:25             ` Junio C Hamano
2021-02-03  5:20               ` SZEDER Gábor

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

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

  git send-email \
    --in-reply-to=42f694004322361b5495f2ce1a2eba638644f754.1606087406.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=johannes.schindelin@gmx.de \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.