git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Wink Saville <wink@saville.com>
To: git@vger.kernel.org
Cc: Wink Saville <wink@saville.com>, gitster@pobox.com
Subject: [RFC PATCH v4 1/3] Teach remote add the --remote-tags option
Date: Tue,  1 May 2018 09:59:29 -0700	[thread overview]
Message-ID: <20180501165931.25515-2-wink@saville.com> (raw)
In-Reply-To: <20180501165931.25515-1-wink@saville.com>
In-Reply-To: <xmqqbme51rgn.fsf@gitster-ct.c.googlers.com>

When --remote-tags is passed to `git remote add` the tagopt is set to
--remote-tags and a second fetch line is added so tags are placed in
a separate hierarchy per remote.

For example:
  $ git remote add -f --remote-tags gbenchmark git@github.com:google/benchmark
  Updating gbenchmark
  warning: no common commits
  remote: Counting objects: 4406, done.
  remote: Compressing objects: 100% (18/18), done.
  remote: Total 4406 (delta 7), reused 13 (delta 6), pack-reused 4382
  Receiving objects: 100% (4406/4406), 1.34 MiB | 7.58 MiB/s, done.
  Resolving deltas: 100% (2865/2865), done.
  From github.com:google/benchmark
   * [new branch]      clangtidy       -> gbenchmark/clangtidy
   * [new branch]      iter_report     -> gbenchmark/iter_report
   * [new branch]      master          -> gbenchmark/master
   * [new branch]      releasing       -> gbenchmark/releasing
   * [new branch]      reportercleanup -> gbenchmark/reportercleanup
   * [new branch]      rmheaders       -> gbenchmark/rmheaders
   * [new branch]      v2              -> gbenchmark/v2
   * [new tag]         v0.0.9          -> gbenchmark/v0.0.9
   * [new tag]         v0.1.0          -> gbenchmark/v0.1.0
   * [new tag]         v1.0.0          -> gbenchmark/v1.0.0
   * [new tag]         v1.1.0          -> gbenchmark/v1.1.0
   * [new tag]         v1.2.0          -> gbenchmark/v1.2.0
   * [new tag]         v1.3.0          -> gbenchmark/v1.3.0
   * [new tag]         v1.4.0          -> gbenchmark/v1.4.0

And the .git/config remote "gbenchmark" section looks like:
  [remote "gbenchmark"]
    url = git@github.com:google/benchmark
    fetch = +refs/heads/*:refs/remotes/gbenchmark/*
    fetch = +refs/tags/*:refs/remote-tags/gbenchmark/*
    tagopt = --remote-tags

Based on a solution proposed by Junio on the email list [1]

[1]: https://public-inbox.org/git/xmqqbme51rgn.fsf@gitster-ct.c.googlers.com/T/#me7f7f153b8ba742c0dc48d8ec79c280c9682d32e

Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Jacob Keller <jacob.keller@gmail.com>
Helped-by: Bryan Turner <bturner@atlassian.com>
Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Wink Saville <wink@saville.com>
---
 Documentation/git-remote.txt |  8 +++++--
 builtin/remote.c             | 44 ++++++++++++++++++++++++++++++++----
 refs.c                       |  1 +
 remote.c                     |  2 ++
 4 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
index 4feddc0293..fc983c2ff1 100644
--- a/Documentation/git-remote.txt
+++ b/Documentation/git-remote.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git remote' [-v | --verbose]
-'git remote add' [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>] <name> <url>
+'git remote add' [-t <branch>] [-m <master>] [-f] [--tags | --remote-tags | --no-tags] [--mirror=<fetch|push>] <name> <url>
 'git remote rename' <old> <new>
 'git remote remove' <name>
 'git remote set-head' <name> (-a | --auto | -d | --delete | <branch>)
@@ -54,7 +54,11 @@ With `-f` option, `git fetch <name>` is run immediately after
 the remote information is set up.
 +
 With `--tags` option, `git fetch <name>` imports every tag from the
-remote repository.
+remote repository to refs/tags, use --remote-tags to import them
+to refs/remote-tags/<name>/<tag>.
++
+With `--remote-tags` option, `git fetch <name>` imports every tag from the
+remote repository to refs/remote-tags/<name>/<tag>.
 +
 With `--no-tags` option, `git fetch <name>` does not import tags from
 the remote repository.
diff --git a/builtin/remote.c b/builtin/remote.c
index 805ffc05cd..07832113e9 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -11,7 +11,7 @@
 
 static const char * const builtin_remote_usage[] = {
 	N_("git remote [-v | --verbose]"),
-	N_("git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url>"),
+	N_("git remote add [-t <branch>] [-m <master>] [-f] [--tags | --remote-tags | --no-tags] [--mirror=<fetch|push>] <name> <url>"),
 	N_("git remote rename <old> <new>"),
 	N_("git remote remove <name>"),
 	N_("git remote set-head <name> (-a | --auto | -d | --delete | <branch>)"),
@@ -101,7 +101,8 @@ static int fetch_remote(const char *name)
 enum {
 	TAGS_UNSET = 0,
 	TAGS_DEFAULT = 1,
-	TAGS_SET = 2
+	TAGS_SET = 2,
+	TAGS_SET_REMOTE = 3
 };
 
 #define MIRROR_NONE 0
@@ -123,6 +124,14 @@ static void add_branch(const char *key, const char *branchname,
 	git_config_set_multivar(key, tmp->buf, "^$", 0);
 }
 
+static void add_remote_tags(const char *key, const char *remotename,
+			    struct strbuf *tmp)
+{
+	strbuf_reset(tmp);
+	strbuf_addf(tmp, "+refs/tags/*:refs/remote-tags/%s/*", remotename);
+	git_config_set_multivar(key, tmp->buf, "^$", 0);
+}
+
 static const char mirror_advice[] =
 N_("--mirror is dangerous and deprecated; please\n"
    "\t use --mirror=fetch or --mirror=push instead");
@@ -161,6 +170,9 @@ static int add(int argc, const char **argv)
 		OPT_SET_INT(0, "tags", &fetch_tags,
 			    N_("import all tags and associated objects when fetching"),
 			    TAGS_SET),
+		OPT_SET_INT(0, "remote-tags", &fetch_tags,
+			    N_("import all tags and associated objects when fetching to refs/remote-tags/<name>/<tag>"),
+			    TAGS_SET_REMOTE),
 		OPT_SET_INT(0, NULL, &fetch_tags,
 			    N_("or do not fetch any tag at all (--no-tags)"), TAGS_UNSET),
 		OPT_STRING_LIST('t', "track", &track, N_("branch"),
@@ -182,6 +194,10 @@ static int add(int argc, const char **argv)
 		die(_("specifying a master branch makes no sense with --mirror"));
 	if (mirror && !(mirror & MIRROR_FETCH) && track.nr)
 		die(_("specifying branches to track makes sense only with fetch mirrors"));
+	if ((fetch_tags == TAGS_SET_REMOTE) && mirror)
+		die(_("specifying --remote-tags makes no sense with --mirror"));
+	if ((fetch_tags == TAGS_SET_REMOTE) && track.nr)
+		die(_("specifying --remote-tags makes no sense with -t or --track"));
 
 	name = argv[0];
 	url = argv[1];
@@ -215,10 +231,30 @@ static int add(int argc, const char **argv)
 	}
 
 	if (fetch_tags != TAGS_DEFAULT) {
+		if (fetch_tags == TAGS_SET_REMOTE) {
+			strbuf_reset(&buf);
+			strbuf_addf(&buf, "remote.%s.fetch", name);
+			add_remote_tags(buf.buf, name, &buf2);
+		}
+
 		strbuf_reset(&buf);
 		strbuf_addf(&buf, "remote.%s.tagopt", name);
-		git_config_set(buf.buf,
-			       fetch_tags == TAGS_SET ? "--tags" : "--no-tags");
+		char *config_val = NULL;
+		switch (fetch_tags) {
+		case TAGS_UNSET:
+			config_val = "--no-tags";
+			break;
+		case TAGS_SET:
+			config_val = "--tags";
+			break;
+		case TAGS_SET_REMOTE:
+			config_val = "--remote-tags";
+			break;
+		default:
+			die(_("Unexpected TAGS enum %d"), fetch_tags);
+			break;
+		}
+		git_config_set(buf.buf, config_val);
 	}
 
 	if (fetch && fetch_remote(name))
diff --git a/refs.c b/refs.c
index 8b7a77fe5e..4075150e26 100644
--- a/refs.c
+++ b/refs.c
@@ -472,6 +472,7 @@ const char *prettify_refname(const char *name)
 {
 	if (skip_prefix(name, "refs/heads/", &name) ||
 	    skip_prefix(name, "refs/tags/", &name) ||
+	    skip_prefix(name, "refs/remote-tags/", &name) ||
 	    skip_prefix(name, "refs/remotes/", &name))
 		; /* nothing */
 	return name;
diff --git a/remote.c b/remote.c
index 91eb010ca9..86cccc0b6e 100644
--- a/remote.c
+++ b/remote.c
@@ -447,6 +447,8 @@ static int handle_config(const char *key, const char *value, void *cb)
 			remote->fetch_tags = -1;
 		else if (!strcmp(value, "--tags"))
 			remote->fetch_tags = 2;
+		else if (!strcmp(value, "--remote-tags"))
+			remote->fetch_tags = -1;
 	} else if (!strcmp(subkey, "proxy")) {
 		return git_config_string((const char **)&remote->http_proxy,
 					 key, value);
-- 
2.17.0.393.g4573f5e134


  parent reply	other threads:[~2018-05-01 16:59 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-24 19:57 Fetching tags overwrites existing tags Wink Saville
2018-04-24 23:48 ` Jacob Keller
2018-04-25  0:52 ` Junio C Hamano
2018-04-25  1:29   ` Jacob Keller
2018-04-25  1:31   ` Wink Saville
2018-04-26 19:39     ` Wink Saville
2018-04-26 22:50       ` Junio C Hamano
2018-04-26 23:24         ` Junio C Hamano
2018-04-27 18:50           ` [RFC PATCH v2] Teach remote add the --prefix-tags option Wink Saville
2018-04-27 19:08           ` Fetching tags overwrites existing tags Wink Saville
2018-04-27 19:13             ` Bryan Turner
2018-05-04 15:56               ` Jacob Keller
2018-04-28  7:26             ` Jacob Keller
2018-04-28 18:27           ` [RFC PATCH v3] Teach remote add the --remote-tags option Wink Saville
2018-04-28 19:00             ` Wink Saville
2018-04-28 21:27               ` Wink Saville
2018-05-01 16:59           ` [RFC PATCH v4 0/3] Optional sub hierarchy for remote tags Wink Saville
2018-05-01 19:24             ` Ævar Arnfjörð Bjarmason
2018-05-01 19:45               ` Jacob Keller
2018-05-01 20:34                 ` Wink Saville
2018-05-01 23:24                 ` Junio C Hamano
2018-05-02  0:08                   ` Jacob Keller
2018-05-01 23:28               ` Junio C Hamano
2018-05-01 16:59           ` Wink Saville [this message]
2018-05-01 18:50             ` [RFC PATCH v4 1/3] Teach remote add the --remote-tags option Ævar Arnfjörð Bjarmason
2018-05-08 10:26             ` Kaartic Sivaraam
2018-05-01 16:59           ` [RFC PATCH v4 2/3] Teach tag to list remote-tags Wink Saville
2018-05-01 16:59           ` [RFC PATCH v4 3/3] Test git remote add -f --remote-tags Wink Saville
2018-04-27 19:46 ` Fetching tags overwrites existing tags Ævar Arnfjörð Bjarmason
2018-04-29 20:20   ` [PATCH 0/8] "git fetch" should not clobber existing tags without --force Ævar Arnfjörð Bjarmason
2018-07-31 13:07     ` [PATCH v2 00/10] " Ævar Arnfjörð Bjarmason
2018-08-13 19:22       ` [PATCH v3 0/7] Prep for " Ævar Arnfjörð Bjarmason
2018-08-13 20:29         ` Junio C Hamano
2018-08-13 20:37           ` Ævar Arnfjörð Bjarmason
2018-08-30 20:12         ` [PATCH v4 0/6] " Ævar Arnfjörð Bjarmason
2018-08-31 20:09           ` [PATCH v5 0/9] git " Ævar Arnfjörð Bjarmason
2018-08-31 20:09           ` [PATCH v5 1/9] fetch: change "branch" to "reference" in --force -h output Ævar Arnfjörð Bjarmason
2018-08-31 20:09           ` [PATCH v5 2/9] push tests: make use of unused $1 in test description Ævar Arnfjörð Bjarmason
2018-08-31 21:07             ` Junio C Hamano
2018-08-31 22:02               ` Ævar Arnfjörð Bjarmason
2018-08-31 20:09           ` [PATCH v5 3/9] push tests: use spaces in interpolated string Ævar Arnfjörð Bjarmason
2018-08-31 20:09           ` [PATCH v5 4/9] fetch tests: add a test for clobbering tag behavior Ævar Arnfjörð Bjarmason
2018-08-31 20:10           ` [PATCH v5 5/9] push doc: remove confusing mention of remote merger Ævar Arnfjörð Bjarmason
2018-08-31 20:10           ` [PATCH v5 6/9] push doc: move mention of "tag <tag>" later in the prose Ævar Arnfjörð Bjarmason
2018-08-31 20:10           ` [PATCH v5 7/9] push doc: correct lies about how push refspecs work Ævar Arnfjörð Bjarmason
2018-08-31 20:10           ` [PATCH v5 8/9] fetch: document local ref updates with/without --force Ævar Arnfjörð Bjarmason
2018-08-31 20:10           ` [PATCH v5 9/9] fetch: stop clobbering existing tags without --force Ævar Arnfjörð Bjarmason
2018-08-30 20:12         ` [PATCH v4 1/6] fetch: change "branch" to "reference" in --force -h output Ævar Arnfjörð Bjarmason
2018-08-30 20:12         ` [PATCH v4 2/6] push tests: correct quoting in interpolated string Ævar Arnfjörð Bjarmason
2018-08-30 21:20           ` Junio C Hamano
2018-08-30 20:12         ` [PATCH v4 3/6] fetch tests: add a test for clobbering tag behavior Ævar Arnfjörð Bjarmason
2018-08-30 21:22           ` Junio C Hamano
2018-08-30 20:12         ` [PATCH v4 4/6] push doc: correct lies about how push refspecs work Ævar Arnfjörð Bjarmason
2018-08-30 21:31           ` Junio C Hamano
2018-08-30 22:34           ` Ævar Arnfjörð Bjarmason
2018-08-31 16:24             ` Junio C Hamano
2018-08-31 16:35               ` Ævar Arnfjörð Bjarmason
2018-08-30 20:12         ` [PATCH v4 5/6] fetch: document local ref updates with/without --force Ævar Arnfjörð Bjarmason
2018-08-30 20:12         ` [PATCH v4 6/6] fetch: stop clobbering existing tags without --force Ævar Arnfjörð Bjarmason
2018-08-30 21:43           ` Junio C Hamano
2018-08-13 19:22       ` [PATCH v3 1/7] fetch tests: change "Tag" test tag to "testTag" Ævar Arnfjörð Bjarmason
2018-08-13 19:22       ` [PATCH v3 2/7] push tests: remove redundant 'git push' invocation Ævar Arnfjörð Bjarmason
2018-08-13 19:22       ` [PATCH v3 3/7] push tests: fix logic error in "push" test assertion Ævar Arnfjörð Bjarmason
2018-08-13 19:22       ` [PATCH v3 4/7] push tests: add more testing for forced tag pushing Ævar Arnfjörð Bjarmason
2018-08-13 19:22       ` [PATCH v3 5/7] push tests: assert re-pushing annotated tags Ævar Arnfjörð Bjarmason
2018-08-13 19:22       ` [PATCH v3 6/7] fetch tests: correct a comment "remove it" -> "remove them" Ævar Arnfjörð Bjarmason
2018-08-13 19:22       ` [PATCH v3 7/7] pull doc: fix a long-standing grammar error Ævar Arnfjörð Bjarmason
2018-07-31 13:07     ` [PATCH v2 01/10] fetch tests: change "Tag" test tag to "testTag" Ævar Arnfjörð Bjarmason
2018-07-31 13:07     ` [PATCH v2 02/10] push tests: remove redundant 'git push' invocation Ævar Arnfjörð Bjarmason
2018-07-31 13:07     ` [PATCH v2 03/10] push tests: fix logic error in "push" test assertion Ævar Arnfjörð Bjarmason
2018-07-31 13:07     ` [PATCH v2 04/10] push tests: add more testing for forced tag pushing Ævar Arnfjörð Bjarmason
2018-07-31 13:07     ` [PATCH v2 05/10] push tests: assert re-pushing annotated tags Ævar Arnfjörð Bjarmason
2018-07-31 13:07     ` [PATCH v2 06/10] push doc: correct lies about how push refspecs work Ævar Arnfjörð Bjarmason
2018-07-31 17:40       ` Junio C Hamano
2018-08-30 14:52         ` Ævar Arnfjörð Bjarmason
2018-08-30 15:23           ` Junio C Hamano
2018-08-30 16:59             ` Ævar Arnfjörð Bjarmason
2018-07-31 13:07     ` [PATCH v2 07/10] fetch tests: correct a comment "remove it" -> "remove them" Ævar Arnfjörð Bjarmason
2018-07-31 13:07     ` [PATCH v2 08/10] fetch tests: add a test clobbering tag behavior Ævar Arnfjörð Bjarmason
2018-07-31 17:48       ` Junio C Hamano
2018-07-31 13:07     ` [PATCH v2 09/10] pull doc: fix a long-standing grammar error Ævar Arnfjörð Bjarmason
2018-07-31 13:07     ` [PATCH v2 10/10] fetch: stop clobbering existing tags without --force Ævar Arnfjörð Bjarmason
2018-07-31 18:03       ` Junio C Hamano
2018-04-29 20:20   ` [PATCH 1/8] push tests: remove redundant 'git push' invocation Ævar Arnfjörð Bjarmason
2018-04-29 20:20   ` [PATCH 2/8] push tests: fix logic error in "push" test assertion Ævar Arnfjörð Bjarmason
2018-04-29 20:20   ` [PATCH 3/8] push tests: add more testing for forced tag pushing Ævar Arnfjörð Bjarmason
2018-05-07 10:09     ` Kaartic Sivaraam
2018-05-08  2:35     ` Junio C Hamano
2018-05-08  3:19       ` Junio C Hamano
2018-05-08  9:52         ` Kaartic Sivaraam
2018-05-08 10:19     ` Kaartic Sivaraam
2018-04-29 20:20   ` [PATCH 4/8] push tests: assert re-pushing annotated tags Ævar Arnfjörð Bjarmason
2018-05-08  4:30     ` Junio C Hamano
2018-05-08 14:05     ` SZEDER Gábor
2018-04-29 20:20   ` [PATCH 5/8] push doc: correct lies about how push refspecs work Ævar Arnfjörð Bjarmason
2018-05-08  5:14     ` Junio C Hamano
2018-04-29 20:20   ` [PATCH 6/8] fetch tests: correct a comment "remove it" -> "remove them" Ævar Arnfjörð Bjarmason
2018-04-29 20:20   ` [PATCH 7/8] fetch tests: add a test clobbering tag behavior Ævar Arnfjörð Bjarmason
2018-04-29 20:21   ` [PATCH 8/8] fetch: stop clobbering existing tags without --force Ævar Arnfjörð Bjarmason
2018-05-08  5:37     ` Junio C Hamano
2018-05-01 17:11 ` Fetching tags overwrites existing tags Wink Saville

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=20180501165931.25515-2-wink@saville.com \
    --to=wink@saville.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).