Skip to content

Commit

Permalink
refs outside refs/{heads,tags} match less strongly.
Browse files Browse the repository at this point in the history
This changes the refname matching logic used to decide which ref
is updated with git-send-pack.  We used to error out when
pushing 'master' when the other end has both 'master' branch and
a tracking branch 'remotes/$name/master' but with this, 'master'
matches only 'refs/heads/master' when both and no other 'master'
exist.

Pushing 'foo' when both heads/foo and tags/foo exist at the
remote end is still considered an error and you would need to
disambiguate between them by being more explicit.

When neither heads/foo nor tags/foo exists at the remote,
pushing 'foo' when there is only remotes/origin/foo is not
ambiguous, while it still is ambiguous when there are more than
one such weaker match (remotes/origin/foo and remotes/alt/foo,
for example).

Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Junio C Hamano committed Nov 24, 2006
1 parent f73da29 commit 29561ad
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,58 @@ static int count_refspec_match(const char *pattern,
struct ref *refs,
struct ref **matched_ref)
{
int match;
int patlen = strlen(pattern);
struct ref *matched_weak = NULL;
struct ref *matched = NULL;
int weak_match = 0;
int match = 0;

for (match = 0; refs; refs = refs->next) {
for (weak_match = match = 0; refs; refs = refs->next) {
char *name = refs->name;
int namelen = strlen(name);
int weak_match;

if (namelen < patlen ||
memcmp(name + namelen - patlen, pattern, patlen))
continue;
if (namelen != patlen && name[namelen - patlen - 1] != '/')
continue;
match++;
*matched_ref = refs;

/* A match is "weak" if it is with refs outside
* heads or tags, and did not specify the pattern
* in full (e.g. "refs/remotes/origin/master") or at
* least from the toplevel (e.g. "remotes/origin/master");
* otherwise "git push $URL master" would result in
* ambiguity between remotes/origin/master and heads/master
* at the remote site.
*/
if (namelen != patlen &&
patlen != namelen - 5 &&
strncmp(name, "refs/heads/", 11) &&
strncmp(name, "refs/tags/", 10)) {
/* We want to catch the case where only weak
* matches are found and there are multiple
* matches, and where more than one strong
* matches are found, as ambiguous. One
* strong match with zero or more weak matches
* are acceptable as a unique match.
*/
matched_weak = refs;
weak_match++;
}
else {
matched = refs;
match++;
}
}
if (!matched) {
*matched_ref = matched_weak;
return weak_match;
}
else {
*matched_ref = matched;
return match;
}
return match;
}

static void link_dst_tail(struct ref *ref, struct ref ***tail)
Expand Down

0 comments on commit 29561ad

Please sign in to comment.