git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Riesen <raa.lkml@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <junkio@cox.net>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH] Fix push with refspecs containing wildcards
Date: Fri, 8 Jun 2007 01:43:05 +0200	[thread overview]
Message-ID: <20070607234305.GB10633@steel.home> (raw)
In-Reply-To: <20070607225302.GA10633@steel.home>

Otherwise

    git push 'remote-name' 'refs/heads/*:refs/remotes/other/*'

will consider references in "refs/heads" of the remote repository
"remote-name", instead of the ones in "refs/remotes/other", which
the given refspec clearly means.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
Alex Riesen, Fri, Jun 08, 2007 00:53:02 +0200:
> Try something like this:
> 
>     git-send-pack --remote=origin --thin /some/other/repo \
>     'refs/heads/*:refs/remotes/child/*'
> 
> The result looks broken: the sent reference are created not in
> refs/remotes/child/ but just in refs/heads/ of /some/other/repo.
> 

And as usual, I'm not sure if it is the right fix. Johannes has a
point: why the hell does send-pack parse the wildcards at all?!

 remote.c |   39 +++++++++++++++++++++++++++------------
 1 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/remote.c b/remote.c
index d904616..33c8e50 100644
--- a/remote.c
+++ b/remote.c
@@ -501,16 +501,16 @@ static struct ref *find_ref_by_name(struct ref *list, const char *name)
 	return NULL;
 }
 
-static int check_pattern_match(struct refspec *rs, int rs_nr, struct ref *src)
+static const struct refspec *check_pattern_match(const struct refspec *rs,
+						 int rs_nr,
+						 const struct ref *src)
 {
 	int i;
-	if (!rs_nr)
-		return 1;
 	for (i = 0; i < rs_nr; i++) {
 		if (rs[i].pattern && !prefixcmp(src->name, rs[i].src))
-			return 1;
+			return rs + i;
 	}
-	return 0;
+	return NULL;
 }
 
 int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
@@ -525,29 +525,44 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
 	/* pick the remainder */
 	for ( ; src; src = src->next) {
 		struct ref *dst_peer;
+		const struct refspec *pat = NULL;
+		char *dst_name;
 		if (src->peer_ref)
 			continue;
-		if (!check_pattern_match(rs, nr_refspec, src))
-			continue;
+		if (nr_refspec) {
+			pat = check_pattern_match(rs, nr_refspec, src);
+			if (!pat)
+				continue;
+		}
 
-		dst_peer = find_ref_by_name(dst, src->name);
+		if (pat) {
+			dst_name = xmalloc(strlen(pat->dst) +
+					   strlen(src->name) -
+					   strlen(pat->src) + 2);
+			strcpy(dst_name, pat->dst);
+			strcat(dst_name, src->name + strlen(pat->src));
+		} else
+			dst_name = strdup(src->name);
+		dst_peer = find_ref_by_name(dst, dst_name);
 		if (dst_peer && dst_peer->peer_ref)
 			/* We're already sending something to this ref. */
-			continue;
+			goto free_name;
 		if (!dst_peer && !nr_refspec && !all)
 			/* Remote doesn't have it, and we have no
 			 * explicit pattern, and we don't have
 			 * --all. */
-			continue;
+			goto free_name;
 		if (!dst_peer) {
 			/* Create a new one and link it */
-			int len = strlen(src->name) + 1;
+			int len = strlen(dst_name) + 1;
 			dst_peer = xcalloc(1, sizeof(*dst_peer) + len);
-			memcpy(dst_peer->name, src->name, len);
+			memcpy(dst_peer->name, dst_name, len);
 			hashcpy(dst_peer->new_sha1, src->new_sha1);
 			link_dst_tail(dst_peer, dst_tail);
 		}
 		dst_peer->peer_ref = src;
+	free_name:
+		free(dst_name);
 	}
 	return 0;
 }
-- 
1.5.2.1.147.g7c82d

  parent reply	other threads:[~2007-06-07 23:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-07 22:53 git-send-pack: broken handling of ref specs with wildcards Alex Riesen
2007-06-07 22:56 ` Johannes Schindelin
2007-06-08  6:33   ` Junio C Hamano
2007-06-08 18:47     ` Daniel Barkalow
2007-06-07 23:43 ` Alex Riesen [this message]
2007-06-08  6:38   ` [PATCH] Fix push with refspecs containing wildcards Junio C Hamano
2007-06-08  7:42     ` Junio C Hamano
2007-06-08  9:13       ` Alex Riesen

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=20070607234305.GB10633@steel.home \
    --to=raa.lkml@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --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).