git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Fetching tags overwrites existing tags

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 26, 2018, 23:24 UTC
Message-ID
<xmqqbme51rgn.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<xmqqfu3h1t22.fsf@gitster-ct.c.googlers.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 22 quoted lines
> Wink Saville <wink@saville.com> writes:
>
>> I've tried to teach 'git remote add' the --prefix-tags option using the
>> technique Junio provided. At moment it is PR #486 on github [1]
>> and I'd love some comments on whether or not this the right direction
>> for fetching tags and putting them in the branches namespace.
>>
>> -- Wink
>>
>> [1] https://github.com/git/git/pull/486
>
> FWIW, here is how that pull/486/head looks like.
>
> -- >8 --
>
> From: Wink Saville <wink@saville.com>
> Date: Thu, 26 Apr 2018 09:56:11 -0700
> Subject: [PATCH] Teach remote add the --prefix-tags option
>
> When --prefix-tags is passed to `git remote add` the tagopt is set to
> --prefix-tags and a second fetch line is added so tags are placed in
> the branches namespace.

When I hear "branches namespace", what comes to my mind is refs/heads/ or perhaps refs/remotes/*/. "... are placed in a separate hierarchy per remote" or something, perhaps?

Show 9 quoted lines
>
> ...
> 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 = --prefix-tags
> ---
Missing sign-off ;-)
Show 7 quoted lines
> +static void add_remote_tags(const char *key, const char *branchname,
> +		       const char *remotename, struct strbuf *tmp)
> +{
> +	strbuf_reset(tmp);
> +	strbuf_addch(tmp, '+');
> +	strbuf_addf(tmp, "refs/tags/%s:refs/remote-tags/%s/%s",
> +				branchname, remotename, branchname);

With "+refs/tags/%s:refs/remote-tags/%s/%s", combine addch/addf into one, perhaps?

> +	git_config_set_multivar(key, tmp->buf, "^$", 0);
> +}

Calling the second parameter "branchname" makes little sense, I would think. Practically, you would call this at most once with its second parameter set to '*', and even if the second parameter is not a wildcard/asterisk, it would be a tagname.

Show 10 quoted lines
>  static const char mirror_advice[] =
>  N_("--mirror is dangerous and deprecated; please\n"
>     "\t use --mirror=fetch or --mirror=push instead");
> @@ -161,6 +172,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, "prefix-tags", &fetch_tags,
> +			    N_("import all tags and associated objects when fetching and prefix with <name>"),
> +          TAGS_SET_PREFIX),

Funny indent. Use monospaced font in your editor, set tab width to 8 and align, imitating how the above OPT_SET_INT() item does for TAGS_SET.

Show 13 quoted lines
> @@ -215,10 +229,35 @@ static int add(int argc, const char **argv)
>  	}
>  
>  	if (fetch_tags != TAGS_DEFAULT) {
> +		if (fetch_tags == TAGS_SET_PREFIX) {
> +			strbuf_reset(&buf);
> +			strbuf_addf(&buf, "remote.%s.fetch", name);
> +			if (track.nr == 0)
> +				string_list_append(&track, "*");
> +			for (i = 0; i < track.nr; i++) {
> +				add_remote_tags(buf.buf, track.items[i].string,
> +						name, &buf2);
> +			}

The "track" thing is made incompatible with anything but mirror in early part of this function (outside the precontext). I highly suspect that --prefix-tags does *not* make sense when mirroring.

Hence (1) we should detect and error out when --prefix-tags is used with mirror fetch near where we do the same for track used without mirror fetch already, (2) detect and error out when --prefix-tags is used with track, and (3) add "+refs/tags/*:refs/remote-tags/$name/*" just once without paying attention to track here. We may not even want add_remote_tags() helper function if we go that route.

Show 7 quoted lines
> +		}
> +
>  		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;
decl-after-statement.  Also "char *var", not "char* var".
Show 28 quoted lines
> +		switch (fetch_tags) {
> +		case TAGS_UNSET:
> +			config_val = "--no-tags";
> +			break;
> +		case TAGS_SET:
> +			config_val = "--tags";
> +			break;
> +		case TAGS_SET_PREFIX:
> +			config_val = "--prefix-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/remote.c b/remote.c
> index 91eb010ca9..f383ce3cdf 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, "--prefix-tags"))
> +			remote->fetch_tags = -1; // A fetch for refs/tags is present so tags are retrieved

We are old fashioned and do not use // comments, but more importantly it is not clear what this comment is trying to say, at least to me.

>  	} else if (!strcmp(subkey, "proxy")) {
>  		return git_config_string((const char **)&remote->http_proxy,
>  					 key, value);
Previous: Junio C HamanoNext: Wink Saville
Message 8 of 101 in “Fetching tags overwrites existing tags”
  1. Wink SavilleApr 24, 2018
  2. Jacob KellerApr 24, 2018
  3. Junio C HamanoApr 25, 2018
  4. Jacob KellerApr 25, 2018
  5. Wink SavilleApr 25, 2018
  6. Wink SavilleApr 26, 2018
  7. Junio C HamanoApr 26, 2018
  8. Junio C HamanoApr 26, 2018
  9. Teach remote add the --prefix-tags optionWink Saville, Apr 27, 2018
  10. Wink SavilleApr 27, 2018
  11. Bryan TurnerApr 27, 2018
  12. Jacob KellerMay 4, 2018
  13. Jacob KellerApr 28, 2018
  14. Teach remote add the --remote-tags optionWink Saville, Apr 28, 2018
  15. Wink SavilleApr 28, 2018
  16. Wink SavilleApr 28, 2018
  17. 0/3 Optional sub hierarchy for remote tagsWink Saville, May 1, 2018
  18. 1/3 Teach remote add the --remote-tags optionWink Saville, May 1, 2018
  19. Ævar Arnfjörð BjarmasonMay 1, 2018
  20. Kaartic SivaraamMay 8, 2018
  21. 2/3 Teach tag to list remote-tagsWink Saville, May 1, 2018
  22. 3/3 Test git remote add -f --remote-tagsWink Saville, May 1, 2018
  23. Ævar Arnfjörð BjarmasonMay 1, 2018
  24. Jacob KellerMay 1, 2018
  25. Wink SavilleMay 1, 2018
  26. Junio C HamanoMay 1, 2018
  27. Jacob KellerMay 2, 2018
  28. Junio C HamanoMay 1, 2018
  29. Ævar Arnfjörð BjarmasonApr 27, 2018
  30. 0/8 "git fetch" should not clobber existing tags without --forceÆvar Arnfjörð Bjarmason, Apr 29, 2018
  31. 1/8 push tests: remove redundant 'git push' invocationÆvar Arnfjörð Bjarmason, Apr 29, 2018
  32. 2/8 push tests: fix logic error in "push" test assertionÆvar Arnfjörð Bjarmason, Apr 29, 2018
  33. 3/8 push tests: add more testing for forced tag pushingÆvar Arnfjörð Bjarmason, Apr 29, 2018
  34. Kaartic SivaraamMay 7, 2018
  35. Junio C HamanoMay 8, 2018
  36. Junio C HamanoMay 8, 2018
  37. Kaartic SivaraamMay 8, 2018
  38. Kaartic SivaraamMay 8, 2018
  39. 4/8 push tests: assert re-pushing annotated tagsÆvar Arnfjörð Bjarmason, Apr 29, 2018
  40. Junio C HamanoMay 8, 2018
  41. SZEDER GáborMay 8, 2018
  42. 6/8 fetch tests: correct a comment "remove it" -> "remove them"Ævar Arnfjörð Bjarmason, Apr 29, 2018
  43. 5/8 push doc: correct lies about how push refspecs workÆvar Arnfjörð Bjarmason, Apr 29, 2018
  44. Junio C HamanoMay 8, 2018
  45. 8/8 fetch: stop clobbering existing tags without --forceÆvar Arnfjörð Bjarmason, Apr 29, 2018
  46. Junio C HamanoMay 8, 2018
  47. 7/8 fetch tests: add a test clobbering tag behaviorÆvar Arnfjörð Bjarmason, Apr 29, 2018
  48. 00/10 "git fetch" should not clobber existing tags without --forceÆvar Arnfjörð Bjarmason, Jul 31, 2018
  49. 0/7 Prep for "git fetch" should not clobber existing tags without --forceÆvar Arnfjörð Bjarmason, Aug 13, 2018
  50. Junio C HamanoAug 13, 2018
  51. Ævar Arnfjörð BjarmasonAug 13, 2018
  52. 0/6 "git fetch" should not clobber existing tags without --forceÆvar Arnfjörð Bjarmason, Aug 30, 2018
  53. 0/9 git fetch" should not clobber existing tags without --forceÆvar Arnfjörð Bjarmason, Aug 31, 2018
  54. 1/9 fetch: change "branch" to "reference" in --force -h outputÆvar Arnfjörð Bjarmason, Aug 31, 2018
  55. 2/9 push tests: make use of unused $1 in test descriptionÆvar Arnfjörð Bjarmason, Aug 31, 2018
  56. Junio C HamanoAug 31, 2018
  57. Ævar Arnfjörð BjarmasonAug 31, 2018
  58. 3/9 push tests: use spaces in interpolated stringÆvar Arnfjörð Bjarmason, Aug 31, 2018
  59. 4/9 fetch tests: add a test for clobbering tag behaviorÆvar Arnfjörð Bjarmason, Aug 31, 2018
  60. 5/9 push doc: remove confusing mention of remote mergerÆvar Arnfjörð Bjarmason, Aug 31, 2018
  61. 6/9 push doc: move mention of "tag <tag>" later in the proseÆvar Arnfjörð Bjarmason, Aug 31, 2018
  62. 7/9 push doc: correct lies about how push refspecs workÆvar Arnfjörð Bjarmason, Aug 31, 2018
  63. 8/9 fetch: document local ref updates with/without --forceÆvar Arnfjörð Bjarmason, Aug 31, 2018
  64. 9/9 fetch: stop clobbering existing tags without --forceÆvar Arnfjörð Bjarmason, Aug 31, 2018
  65. 1/6 fetch: change "branch" to "reference" in --force -h outputÆvar Arnfjörð Bjarmason, Aug 30, 2018
  66. 2/6 push tests: correct quoting in interpolated stringÆvar Arnfjörð Bjarmason, Aug 30, 2018
  67. Junio C HamanoAug 30, 2018
  68. 3/6 fetch tests: add a test for clobbering tag behaviorÆvar Arnfjörð Bjarmason, Aug 30, 2018
  69. Junio C HamanoAug 30, 2018
  70. 4/6 push doc: correct lies about how push refspecs workÆvar Arnfjörð Bjarmason, Aug 30, 2018
  71. Junio C HamanoAug 30, 2018
  72. Ævar Arnfjörð BjarmasonAug 30, 2018
  73. Junio C HamanoAug 31, 2018
  74. Ævar Arnfjörð BjarmasonAug 31, 2018
  75. 5/6 fetch: document local ref updates with/without --forceÆvar Arnfjörð Bjarmason, Aug 30, 2018
  76. 6/6 fetch: stop clobbering existing tags without --forceÆvar Arnfjörð Bjarmason, Aug 30, 2018
  77. Junio C HamanoAug 30, 2018
  78. 2/7 push tests: remove redundant 'git push' invocationÆvar Arnfjörð Bjarmason, Aug 13, 2018
  79. 3/7 push tests: fix logic error in "push" test assertionÆvar Arnfjörð Bjarmason, Aug 13, 2018
  80. 4/7 push tests: add more testing for forced tag pushingÆvar Arnfjörð Bjarmason, Aug 13, 2018
  81. 5/7 push tests: assert re-pushing annotated tagsÆvar Arnfjörð Bjarmason, Aug 13, 2018
  82. 6/7 fetch tests: correct a comment "remove it" -> "remove them"Ævar Arnfjörð Bjarmason, Aug 13, 2018
  83. 7/7 pull doc: fix a long-standing grammar errorÆvar Arnfjörð Bjarmason, Aug 13, 2018
  84. 1/7 fetch tests: change "Tag" test tag to "testTag"Ævar Arnfjörð Bjarmason, Aug 13, 2018
  85. 01/10 fetch tests: change "Tag" test tag to "testTag"Ævar Arnfjörð Bjarmason, Jul 31, 2018
  86. 02/10 push tests: remove redundant 'git push' invocationÆvar Arnfjörð Bjarmason, Jul 31, 2018
  87. 03/10 push tests: fix logic error in "push" test assertionÆvar Arnfjörð Bjarmason, Jul 31, 2018
  88. 04/10 push tests: add more testing for forced tag pushingÆvar Arnfjörð Bjarmason, Jul 31, 2018
  89. 05/10 push tests: assert re-pushing annotated tagsÆvar Arnfjörð Bjarmason, Jul 31, 2018
  90. 06/10 push doc: correct lies about how push refspecs workÆvar Arnfjörð Bjarmason, Jul 31, 2018
  91. Junio C HamanoJul 31, 2018
  92. Ævar Arnfjörð BjarmasonAug 30, 2018
  93. Junio C HamanoAug 30, 2018
  94. Ævar Arnfjörð BjarmasonAug 30, 2018
  95. 08/10 fetch tests: add a test clobbering tag behaviorÆvar Arnfjörð Bjarmason, Jul 31, 2018
  96. Junio C HamanoJul 31, 2018
  97. 07/10 fetch tests: correct a comment "remove it" -> "remove them"Ævar Arnfjörð Bjarmason, Jul 31, 2018
  98. 09/10 pull doc: fix a long-standing grammar errorÆvar Arnfjörð Bjarmason, Jul 31, 2018
  99. 10/10 fetch: stop clobbering existing tags without --forceÆvar Arnfjörð Bjarmason, Jul 31, 2018
  100. Junio C HamanoJul 31, 2018
  101. Wink SavilleMay 1, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.