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

[PATCH 9/9] fetch: Make automatic tag following work with arbitrary refspecs

From
AGAndreas Gruenbacher <agruen@suse.de>
Date
Mar 17, 2010, 23:59 UTC
Message-ID
<ff287641841582e06f6a145e9c697badb089b9d4.1268913163.git.agruen@suse.de>
In-Reply-To
<3f1d446c333b7eaabce513e846efe5313d2084fb.1268913163.git.agruen@suse.de>

Make automatic tag following and the --tags and --no-tags options work together with arbitrary refspecs: by default, tags will always be fetched automatically, the --tags option will fetch all tags (and only tags), and the --no-tags option will not fetch any tags. This allows to define how things are mapped and which things to fetch independently.

Signed-off-by: Andres Gruenbacher <agruen@suse.de>
---
 builtin/fetch.c |   37 ++++++++++++++++++++++++++-----------
 1 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 8c01876..9265d76 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -147,6 +147,7 @@ static void add_default_tags(const struct ref *remote_refs,
 			     struct string_list *existing_refs,
 			     struct string_list *peeled_map,
 			     struct ref *ref_map,
+			     int overwrite,
 			     struct ref ***tail)
 {
 	struct string_list mapped_refs = { NULL, 0, 0, 0 };
@@ -180,12 +181,8 @@ static void add_default_tags(const struct ref *remote_refs,
 	for (tag = &tags; *tag; ) {
 		ref = *tag;
 		peer_ref = ref->peer_ref;
-		if (!(string_list_has_string(existing_refs, peer_ref->name) ||
-		      string_list_has_string(&mapped_refs, ref->name))) {
-			struct string_list_item *item;
-
-			item = string_list_lookup(ref->name, peeled_map);
-			ref->automatic = !(item && will_fetch(ref_map, item->util));
+		if ((overwrite || !string_list_has_string(existing_refs, peer_ref->name)) &&
+		    !string_list_has_string(&mapped_refs, ref->name)) {
 			string_list_insert(peer_ref->name, existing_refs);
 			move_tag_to_tail(tag, tail);
 			continue;
@@ -218,6 +215,10 @@ int ref_is_automatic(const struct ref *ref) {
 	return ref->automatic;
 }
 
+int ref_is_tag(const struct ref *ref) {
+	return !prefixcmp(ref->name, "refs/tags/");
+}
+
 static struct ref *get_ref_map(struct transport *transport,
 			       struct refspec *refs, int ref_count, int tags,
 			       struct string_list *peeled_map,
@@ -231,7 +232,7 @@ static struct ref *get_ref_map(struct transport *transport,
 
 	const struct ref *remote_refs = transport_get_remote_refs(transport);
 
-	if (ref_count || tags == TAGS_SET) {
+	if (ref_count) {
 		for (i = 0; i < ref_count; i++) {
 			get_fetch_map(remote_refs, &refs[i], &tail, 0);
 			if (refs[i].dst && refs[i].dst[0])
@@ -240,8 +241,6 @@ static struct ref *get_ref_map(struct transport *transport,
 		/* Merge everything on the command line, but not --tags */
 		for (rm = ref_map; rm; rm = rm->next)
 			rm->merge = 1;
-		if (tags == TAGS_SET)
-			get_fetch_map(remote_refs, tag_refspec, &tail, 0);
 	} else {
 		/* Use the defaults */
 		struct remote *remote = transport->remote;
@@ -287,8 +286,24 @@ static struct ref *get_ref_map(struct transport *transport,
 		}
 	}
 
-	if (tags == TAGS_DEFAULT && *autotags)
-		add_default_tags(remote_refs, &existing_refs, peeled_map, ref_map, &tail);
+	if (tags == TAGS_SET) {
+		add_default_tags(remote_refs, &existing_refs, peeled_map, ref_map, 1, &tail);
+		discard_refs(&ref_map, 1, ref_is_tag);
+		free_refs(rm);
+	} else if (tags == TAGS_DEFAULT && *autotags) {
+		add_default_tags(remote_refs, &existing_refs, peeled_map, ref_map, 0, &tail);
+		for (rm = ref_map; rm; rm = rm->next) {
+			struct string_list_item *item;
+
+			if (prefixcmp(rm->name, "refs/tags/"))
+				continue;
+			item = string_list_lookup(rm->name, peeled_map);
+			rm->automatic = !(item && will_fetch(ref_map, item->util));
+		}
+	} else {
+		discard_refs(&ref_map, 0, ref_is_tag);
+		free_refs(rm);
+	}
 	string_list_clear(&existing_refs, 0);
 
 	ref_remove_duplicates(ref_map);
-- 
1.7.0.2.273.gc2413
Previous: Andreas GruenbacherNext: Shawn O. Pearce
Message 10 of 14 in “Multiple remotes without conflicts”
  1. 0/9 Multiple remotes without conflictsAndreas Gruenbacher, Mar 18, 2010
  2. 1/9 fetch: Check for a "^{}" suffix with suffixcmp()Andreas Gruenbacher, Mar 13, 2010
  3. 2/9 fetch: Properly initialize refspec on stackAndreas Gruenbacher, Mar 12, 2010
  4. 3/9 fetch: Fix minor memory leakAndreas Gruenbacher, Mar 15, 2010
  5. 4/9 fetch: Move deepening fetch check into builtin/fetch.cAndreas Gruenbacher, Mar 16, 2010
  6. 5/9 fetch: Move loop checking which refs we have alreadyAndreas Gruenbacher, Mar 16, 2010
  7. 6/9 fetch: Check if all objects exist after fetchingAndreas Gruenbacher, Mar 16, 2010
  8. 7/9 fetch: Use the same ref map for all branches and tagsAndreas Gruenbacher, Mar 17, 2010
  9. 8/9 fetch: Don't fetch tags twiceAndreas Gruenbacher, Mar 17, 2010
  10. 9/9 fetch: Make automatic tag following work with arbitrary refspecsAndreas Gruenbacher, Mar 17, 2010
  11. Shawn O. PearceMar 18, 2010
  12. Andreas GruenbacherMar 18, 2010
  13. Shawn O. PearceMar 18, 2010
  14. Andreas GruenbacherMar 18, 2010

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.