git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Barkalow <barkalow@iabervon.org>
To: Andy Whitcroft <apw@shadowen.org>
Cc: git@vger.kernel.org, Junio C Hamano <junkio@cox.net>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH] Remove duplicate ref matches in fetch
Date: Mon, 8 Oct 2007 00:25:07 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0710080014000.23070@iabervon.org> (raw)

If multiple refspecs matched the same ref, the update would be
processed multiple times. Now having the same destination for the same
source has no additional effect, and having the same destination for
different sources is an error.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
I tested this with the usual tests, but (a) they don't include this case 
(yet), and (b) they passed before I fixed a bug. So this should get some 
good testing, and probably by somebody with valgrind --leak-check to make 
sure I'm deallocating things correctly.

 builtin-fetch.c |    1 +
 remote.c        |   27 +++++++++++++++++++++++++++
 remote.h        |    5 +++++
 3 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/builtin-fetch.c b/builtin-fetch.c
index cf7498b..caaca63 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -112,6 +112,7 @@ static struct ref *get_ref_map(struct transport *transport,
 			ref_map->merge = 1;
 		}
 	}
+	ref_remove_duplicates(ref_map);
 
 	return ref_map;
 }
diff --git a/remote.c b/remote.c
index e7d735b..e2ca4d3 100644
--- a/remote.c
+++ b/remote.c
@@ -380,6 +380,33 @@ int for_each_remote(each_remote_fn fn, void *priv)
 	return result;
 }
 
+void ref_remove_duplicates(struct ref *ref_map)
+{
+	struct ref **posn;
+	struct ref *next;
+	for (; ref_map; ref_map = ref_map->next) {
+		if (!ref_map->peer_ref)
+			continue;
+		posn = &ref_map->next;
+		while (*posn) {
+			if ((*posn)->peer_ref &&
+			    !strcmp((*posn)->peer_ref->name,
+				    ref_map->peer_ref->name)) {
+				if (strcmp((*posn)->name, ref_map->name))
+					die("%s tracks both %s and %s",
+					    ref_map->peer_ref->name,
+					    (*posn)->name, ref_map->name);
+				next = (*posn)->next;
+				free((*posn)->peer_ref);
+				free(*posn);
+				*posn = next;
+			} else {
+				posn = &(*posn)->next;
+			}
+		}
+	}
+}
+
 int remote_has_url(struct remote *remote, const char *url)
 {
 	int i;
diff --git a/remote.h b/remote.h
index 05add06..c62636d 100644
--- a/remote.h
+++ b/remote.h
@@ -49,6 +49,11 @@ struct ref *alloc_ref(unsigned namelen);
  */
 void free_refs(struct ref *ref);
 
+/*
+ * Removes and frees any duplicate refs in the map.
+ */
+void ref_remove_duplicates(struct ref *ref_map);
+
 struct refspec *parse_ref_spec(int nr_refspec, const char **refspec);
 
 int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
-- 
1.5.3.4.1155.gfe96ee

                 reply	other threads:[~2007-10-08  4:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=Pine.LNX.4.64.0710080014000.23070@iabervon.org \
    --to=barkalow@iabervon.org \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=apw@shadowen.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /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 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 NNTP newsgroup(s).