improve refspec handling in push, refactor matching in fetch
cover improve refspec handling in push, refactor matching in fetch
This is a replacement for sp/push-refspec. It is rebased to the current master.
Documentation/git-push.txt | 4 ++-- Documentation/git-send-pack.txt | 4 +++- builtin-push.c | 11 +++++++++++ cache.h | 4 ++++ refs.c | 31 +++++++++++++++++++++++++++++++ remote.c | 28 +++------------------------- sha1_name.c | 14 ++------------ t/t5510-fetch.sh | 25 +++++++++++++++++++++++++ t/t5516-fetch-push.sh | 29 ++++++++++++++++++++++++++++- transport.c | 8 ++++++-- transport.h | 1 + 11 files changed, 116 insertions(+), 43 deletions(-)
[PATCH 1/6] push: mention --verbose option in documentation
Push uses parseopts, which supports '--verbose'.
[PATCH 2/6] push: teach push to pass --verbose option to transport layer
Adapted to paresopts changes.
[PATCH 3/6] push: support pushing HEAD to real branch name
Same as before.
[PATCH 4/6] add ref_abbrev_matches_full_with_rules()
[PATCH 5/6] push: use same rules as git-rev-parse to resolve refspecs [PATCH 6/6] refactor fetch's ref matching to use ref_abbrev_matches_full_with_rules()
Start unification of refspec matching rules.
PATCH 1/6 push: mention --verbose option in documentation
From: Steffen Prohaska <[email protected]>
Before this commit, only '-v' was documented.
--- Documentation/git-push.txt | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
Documentation/git-push.txt +2 -2
@@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git-push' [--all] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>] - [--repo=all] [-f | --force] [-v] [<repository> <refspec>...] + [--repo=all] [-f | --force] [-v | --verbose] [<repository> <refspec>...] DESCRIPTION -----------
@@ -95,7 +95,7 @@ the remote repository. transfer spends extra cycles to minimize the number of objects to be sent and meant to be used on slower connection. --v:: +-v, \--verbose:: Run verbosely. include::urls-remotes.txt[]
Signature · 1 line
1.5.3.5.578.g886d
PATCH 2/6 push: teach push to pass --verbose option to transport layer
From: Steffen Prohaska <[email protected]>
A --verbose option to push should also be passed to the transport layer, i.e. git-send-pack, git-http-push.
git push is modified to do so.
--- builtin-push.c | 2 ++ transport.c | 8 ++++++-- transport.h | 1 + 3 files changed, 9 insertions(+), 2 deletions(-)
builtin-push.c +2 -0
@@ -115,6 +115,8 @@ int cmd_push(int argc, const char **argv, const char *prefix) flags |=TRANSPORT_PUSH_FORCE ;if (dry_run) flags |=TRANSPORT_PUSH_DRY_RUN ; +if (verbose) + flags |=TRANSPORT_PUSH_VERBOSE ;if (tags)add_refspec ("refs/tags/*" );if (all)
transport.c +6 -2
@@ -386,7 +386,7 @@ static int curl_transport_push(struct transport *transport, int refspec_nr, consint argc;int err; - argv =xmalloc ((refspec_nr +11 ) *sizeof (char *)); + argv =xmalloc ((refspec_nr +12 ) *sizeof (char *)); argv[0 ] ="http-push" ; argc =1 ;if (flags &TRANSPORT_PUSH_ALL )
@@ -395,6 +395,8 @@ static int curl_transport_push(struct transport *transport, int refspec_nr, cons argv[argc++] ="--force" ;if (flags &TRANSPORT_PUSH_DRY_RUN ) argv[argc++] ="--dry-run" ; +if (flags &TRANSPORT_PUSH_VERBOSE ) + argv[argc++] ="--verbose" ; argv[argc++] = transport->url;while (refspec_nr--) argv[argc++] = *refspec++;
@@ -655,7 +657,7 @@ static int git_transport_push(struct transport *transport, int refspec_nr, constint argc;int err; - argv =xmalloc ((refspec_nr +11 ) *sizeof (char *)); + argv =xmalloc ((refspec_nr +12 ) *sizeof (char *)); argv[0 ] ="send-pack" ; argc =1 ;if (flags &TRANSPORT_PUSH_ALL )
@@ -664,6 +666,8 @@ static int git_transport_push(struct transport *transport, int refspec_nr, const argv[argc++] ="--force" ;if (flags &TRANSPORT_PUSH_DRY_RUN ) argv[argc++] ="--dry-run" ; +if (flags &TRANSPORT_PUSH_VERBOSE ) + argv[argc++] ="--verbose" ;if (data->receivepack) {char *rp =xmalloc (strlen (data->receivepack) +16 );sprintf (rp,"--receive-pack=%s" , data->receivepack);
transport.h +1 -0
@@ -30,6 +30,7 @@ struct transport {#define TRANSPORT_PUSH_ALL 1#define TRANSPORT_PUSH_FORCE 2#define TRANSPORT_PUSH_DRY_RUN 4 +#define TRANSPORT_PUSH_VERBOSE 8/* Returns a transport suitable for the url */ struct transport *transport_get (struct remote *,const char *);
Signature · 1 line
1.5.3.5.578.g886d
PATCH 3/6 push: support pushing HEAD to real branch name
From: Steffen Prohaska <[email protected]>
This teaches "push <remote> HEAD" to resolve HEAD on the local side to its real branch name, e.g. master, and then act as if the real branch name was specified. So we have a shorthand for pushing the current branch. Besides HEAD, no other symbolic ref is resolved.
Thanks to Daniel Barkalow <[email protected]> for suggesting this implementation, which is much simpler than the implementation proposed before.
--- builtin-push.c | 9 +++++++++ t/t5516-fetch-push.sh | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-)
builtin-push.c +9 -0
@@ -44,6 +44,15 @@ static void set_refspecs(const char **refs, int nr)strcat (tag, refs[i]); ref = tag; } +if (!strcmp ("HEAD" , ref)) { +unsigned char sha1_dummy[20 ]; + ref =resolve_ref (ref, sha1_dummy,1 ,NULL ); +if (!ref) +die ("HEAD cannot be resolved." ); +if (strncmp (ref,"refs/heads/" ,11 )) +die ("HEAD cannot be resolved to branch." ); + ref =xstrdup (ref +11 ); + }add_refspec (ref); } }
t/t5516-fetch-push.sh +17 -0
@@ -244,6 +244,23 @@ test_expect_success 'push with colon-less refspec (4)' ' ' +test_expect_success 'push with HEAD' ' + + mk_test heads/master && + git checkout master && + git push testrepo HEAD && + check_push_result $the_commit heads/master + +' + +test_expect_success 'push with HEAD nonexisting at remote' ' + + mk_test heads/master && + git checkout -b local master && + git push testrepo HEAD && + check_push_result $the_commit heads/local +' + test_expect_success 'push with dry-run' ' mk_test heads/master &&
Signature · 1 line
1.5.3.5.578.g886d
PATCH 4/6 add ref_abbrev_matches_full_with_rules()
We use at least two rulesets for matching abbreviated refnames with full refnames (starting with 'refs/'). git-rev-parse and git-fetch use slightly different rules.
This commit introduces a new function ref_abbrev_matches_full_with_rules(
const char *abbrev_name, const char *full_name, const char **rules).abbrev_name is expanded using the rules and matched against full_name. If a match is found the function returns true. rules is a NULL-terminate list of format patterns with "%.*s", for example
const char *ref_rev_parse_rules[] = {
"%.*s",
"refs/%.*s",
"refs/tags/%.*s",
"refs/heads/%.*s",
"refs/remotes/%.*s",
"refs/remotes/%.*s/HEAD",
NULL
};Asterisks are included in the format strings because this is the form required in sha1_name.c. Sharing the list with the functions there is a good idea to avoid duplicating the rules. Hopefully this facilitates unified matching rules in the future.
This commit makes the rules used by rev-parse for resolving refs to sha1s available for string comparison. Before this change, the rules were buried in get_sha1*() and dwim_ref().
A follow-up commit will refactor the rules used by fetch.
ref_abbrev_matches_full_with_rules() will be used for matching refspecs in git-send-pack.
Thanks to Daniel Barkalow <[email protected]> for pointing out that ref_matches_abbrev in remote.c solves a similar problem and care should be taken to avoid confusion.
--- cache.h | 3 +++ refs.c | 24 ++++++++++++++++++++++++ sha1_name.c | 14 ++------------ 3 files changed, 29 insertions(+), 12 deletions(-)
cache.h +3 -0
@@ -409,6 +409,9 @@ extern const char *resolve_ref(const char *path, unsigned char *sha1, int, int *extern int dwim_ref (const char *str,int len,unsigned char *sha1,char **ref);extern int dwim_log (const char *str,int len,unsigned char *sha1,char **ref); +extern int ref_abbrev_matches_full_with_rules (const char *abbrev_name,const char *full_name,const char **rules); +extern const char *ref_rev_parse_rules[]; +extern int create_symref (const char *ref,const char *refs_heads_master,const char *logmsg);extern int validate_headref (const char *ref);
refs.c +24 -0
@@ -655,6 +655,30 @@ int check_ref_format(const char *ref) } } +const char *ref_rev_parse_rules[] = { +"%.*s" , +"refs/%.*s" , +"refs/tags/%.*s" , +"refs/heads/%.*s" , +"refs/remotes/%.*s" , +"refs/remotes/%.*s/HEAD" , +NULL +}; + +int ref_abbrev_matches_full_with_rules (const char *abbrev_name,const char *full_name,const char **rules) +{ +const char **p; +const int abbrev_name_len =strlen (abbrev_name); + +for (p = rules; *p; p++) { +if (!strcmp (full_name,mkpath (*p, abbrev_name_len, abbrev_name))) { +return 1 ; + } + } + +return 0 ; +} +static struct ref_lock *verify_lock (struct ref_lock *lock,const unsigned char *old_sha1,int mustexist) {
sha1_name.c +2 -12
@@ -239,23 +239,13 @@ static int ambiguous_path(const char *path, int len)return slash; } -static const char *ref_fmt[] = { -"%.*s" , -"refs/%.*s" , -"refs/tags/%.*s" , -"refs/heads/%.*s" , -"refs/remotes/%.*s" , -"refs/remotes/%.*s/HEAD" , -NULL -}; -int dwim_ref (const char *str,int len,unsigned char *sha1,char **ref) {const char **p, *r;int refs_found =0 ; *ref =NULL ; -for (p = ref_fmt; *p; p++) { +for (p = ref_rev_parse_rules; *p; p++) {unsigned char sha1_from_ref[20 ];unsigned char *this_result;
@@ -277,7 +267,7 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)int logs_found =0 ; *log =NULL ; -for (p = ref_fmt; *p; p++) { +for (p = ref_rev_parse_rules; *p; p++) {struct stat st;unsigned char hash[20 ];char path[PATH_MAX ];
Signature · 1 line
1.5.3.5.578.g886d
PATCH 5/6 push: use same rules as git-rev-parse to resolve refspecs
This commit changes the rules for resolving refspecs to match the rules for resolving refs in rev-parse. git-rev-parse uses clear rules to resolve a short ref to its full name, which are well documented. The rules for resolving refspecs documented in git-send-pack were less strict and harder to understand. This commit replaces them by the rules of git-rev-parse.
The unified rules are easier to understand and better resolve ambiguous cases. You can now push from a repository containing several branches ending on the same short name.
Note, this may break existing setups. For example "master" will no longer resolve to "origin/master".
--- Documentation/git-send-pack.txt | 4 +++- remote.c | 5 +---- t/t5516-fetch-push.sh | 12 +++++++++++- 3 files changed, 15 insertions(+), 6 deletions(-)
Documentation/git-send-pack.txt +3 -1
@@ -85,7 +85,9 @@ Each pattern pair consists of the source side (before the colon) and the destination side (after the colon). The ref to be pushed is determined by finding a match that matches the source side, and where it is pushed is determined by using the -destination side. +destination side. The rules used to match a ref are the same +rules used by gitlink:git-rev-parse[1] to resolve a symbolic ref +name. - It is an error if <src> does not match exactly one of the local refs.
remote.c +1 -4
@@ -519,10 +519,7 @@ static int count_refspec_match(const char *pattern,char *name = refs->name;int namelen =strlen (name); -if (namelen < patlen || -memcmp (name + namelen - patlen, pattern, patlen)) -continue ; -if (namelen != patlen && name[namelen - patlen -1 ] !='/' ) +if (!ref_abbrev_matches_full_with_rules (pattern, name, ref_rev_parse_rules))continue ;/* A match is "weak" if it is with refs outside
t/t5516-fetch-push.sh +11 -1
@@ -145,11 +145,21 @@ test_expect_success 'push with no ambiguity (1)' ' test_expect_success 'push with no ambiguity (2)' ' mk_test remotes/origin/master && - git push testrepo master:master && + git push testrepo master:origin/master && check_push_result $the_commit remotes/origin/master ' +test_expect_success 'push with colon-less refspec, no ambiguity' ' + + mk_test heads/master heads/t/master && + git branch -f t/master master && + git push testrepo master && + check_push_result $the_commit heads/master && + check_push_result $the_first_commit heads/t/master + +' + test_expect_success 'push with weak ambiguity (1)' ' mk_test heads/master remotes/origin/master &&
Signature · 1 line
1.5.3.5.578.g886d
PATCH 6/6 refactor fetch's ref matching to use ref_abbrev_matches_full_with_rules()
The old rules used by fetch were coded as a series of ifs. The old rules are:
1) match full refname if it starts with "refs/" or matches "HEAD"
2) verify that full refname starts with "refs/"
3) match abbreviated name in "refs/" if it starts with "heads/",
"tags/", or "remotes/".
4) match abbreviated name in "refs/heads/"
This is replaced by the new rules
a) match full refname
b) match abbreviated name prefixed with "refs/"
c) match abbreviated name prefixed with "refs/heads/"
The details of the new rules are different from the old rules. We no longer verify that the full refname starts with "refs/". The new rule
(a) matches any full string. The old rules (1) and (2) were stricter. Now, the caller is responsible for using sensible full refnames. This should be the case for the current code. The new rule (b) is less strict than old rule (3). The new rule accepts abbreviated names that start with a non-standard prefix below "refs/".
Despite this modifications the new rules should handle all cases as expected. Two tests are added to verify that fetch does not resolve short tags or HEAD in remotes.
We may even think about loosening the rules a bit more and unify them with the rev-parse rules. This would be done by replacing ref_ref_fetch_rules with ref_ref_parse_rules. Note, the two new test would break.
--- cache.h | 1 + refs.c | 7 +++++++ remote.c | 23 ++--------------------- t/t5510-fetch.sh | 25 +++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 21 deletions(-)
cache.h +1 -0
@@ -411,6 +411,7 @@ extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);extern int ref_abbrev_matches_full_with_rules (const char *abbrev_name,const char *full_name,const char **rules);extern const char *ref_rev_parse_rules[]; +extern const char *ref_fetch_rules[];extern int create_symref (const char *ref,const char *refs_heads_master,const char *logmsg);extern int validate_headref (const char *ref);
refs.c +7 -0
@@ -665,6 +665,13 @@ const char *ref_rev_parse_rules[] = { NULL }; +const char *ref_fetch_rules[] = { +"%.*s" , +"refs/%.*s" , +"refs/heads/%.*s" , +NULL +}; +int ref_abbrev_matches_full_with_rules (const char *abbrev_name,const char *full_name,const char **rules) {const char **p;
remote.c +2 -21
@@ -417,25 +417,6 @@ int remote_has_url(struct remote *remote, const char *url)return 0 ; } -/* -* Returns true if, under the matching rules for fetching, name is the -* same as the given full name. -*/ -static int ref_matches_abbrev (const char *name,const char *full) -{ -if (!prefixcmp (name,"refs/" ) || !strcmp (name,"HEAD" )) -return !strcmp (name, full); -if (prefixcmp (full,"refs/" )) -return 0 ; -if (!prefixcmp (name,"heads/" ) || - !prefixcmp (name,"tags/" ) || - !prefixcmp (name,"remotes/" )) -return !strcmp (name, full +5 ); -if (prefixcmp (full +5 ,"heads/" )) -return 0 ; -return !strcmp (full +11 , name); -} -int remote_find_tracking (struct remote *remote,struct refspec *refspec) {int find_src = refspec->src ==NULL ;
@@ -804,7 +785,7 @@ int branch_merge_matches(struct branch *branch, {if (!branch || i <0 || i >= branch->merge_nr)return 0 ; -return ref_matches_abbrev (branch->merge[i]->src, refname); +return ref_abbrev_matches_full_with_rules (branch->merge[i]->src, refname, ref_fetch_rules); } static struct ref *get_expanded_map(struct ref *remote_refs,
@@ -843,7 +824,7 @@ static struct ref *find_ref_by_name_abbrev(struct ref *refs, const char *name) {struct ref *ref;for (ref = refs; ref; ref = ref->next) { -if (ref_matches_abbrev (name, ref->name)) +if (ref_abbrev_matches_full_with_rules (name, ref->name, ref_fetch_rules))return ref; }return NULL ;
t/t5510-fetch.sh +25 -0
@@ -95,6 +95,31 @@ test_expect_success 'fetch following tags' ' ' +test_expect_failure 'fetch must not resolve short tag name' ' + + cd "$D" && + + mkdir five && + cd five && + git init && + + git fetch .. anno:five + +' + +test_expect_failure 'fetch must not resolve short remote name' ' + + cd "$D" && + git-update-ref refs/remotes/six/HEAD HEAD + + mkdir six && + cd six && + git init && + + git fetch .. six:six + +' + test_expect_success 'create bundle 1' ' cd "$D" && echo >file updated again by origin &&
Signature · 1 line
1.5.3.5.578.g886d
Re: [PATCH 6/6] refactor fetch's ref matching to use ref_abbrev_matches_full_with_rules()
Quoted 21 lines · Steffen Prohaska
The old rules used by fetch were coded as a series of ifs. The old rules are:
1) match full refname if it starts with "refs/" or matches "HEAD"
2) verify that full refname starts with "refs/"
3) match abbreviated name in "refs/" if it starts with "heads/", "tags/", or "remotes/".
4) match abbreviated name in "refs/heads/"This is replaced by the new rules
a) match full refname
b) match abbreviated name prefixed with "refs/"
c) match abbreviated name prefixed with "refs/heads/"The details of the new rules are different from the old rules. We no longer verify that the full refname starts with "refs/". The new rule
(a) matches any full string. The old rules (1) and (2) were stricter. Now, the caller is responsible for using sensible full refnames. This should be the case for the current code. The new rule (b) is less strict than old rule (3). The new rule accepts abbreviated names that start with a non-standard prefix below "refs/".
Quoted 8 lines
Despite this modifications the new rules should handle all cases as expected. Two tests are added to verify that fetch does not resolve short tags or HEAD in remotes.
We may even think about loosening the rules a bit more and unify them with the rev-parse rules. This would be done by replacing
ref_ref_fetch_ruleswithref_ref_parse_rules. Note, the two new test would break.
Does still "origin" matches "origin/HEAD" if we have emote "origin"?
Signature · 3 lines
Jakub Narebski Warsaw, Poland ShadeHawk on #git
Re: [PATCH 6/6] refactor fetch's ref matching to use ref_abbrev_matches_full_with_rules()
Quoted 27 lines · Jakub Narebski
Quoted 25 lines · Steffen Prohaska
The old rules used by fetch were coded as a series of ifs. The old rules are:
1) match full refname if it starts with "refs/" or matches "HEAD"
2) verify that full refname starts with "refs/"
3) match abbreviated name in "refs/" if it starts with "heads/","tags/", or "remotes/".4) match abbreviated name in "refs/heads/"
This is replaced by the new rules
a) match full refname
b) match abbreviated name prefixed with "refs/"
c) match abbreviated name prefixed with "refs/heads/"The details of the new rules are different from the old rules. We no longer verify that the full refname starts with "refs/". The new rule
(a) matches any full string. The old rules (1) and (2) were stricter. Now, the caller is responsible for using sensible full refnames. This should be the case for the current code. The new rule (b) is less strict than old rule (3). The new rule accepts abbreviated names that start with a non-standard prefix below "refs/".Despite this modifications the new rules should handle all cases as expected. Two tests are added to verify that fetch does not resolve short tags or HEAD in remotes.
Quoted 6 lines
Quoted 4 lines
We may even think about loosening the rules a bit more and unify them with the rev-parse rules. This would be done by replacing
ref_ref_fetch_ruleswithref_ref_parse_rules. Note, the two new test would break.Does still "origin" matches "origin/HEAD" if we have emote "origin"?
No, and it did not before. fetch does _not_ match origin as refs/remotes/origin/HEAD. I added a test to confirm the old behaviour. Only the git-rev-parse rules match origin as refs/remotes/origin/HEAD.
Steffen
Re: [PATCH 5/6] push: use same rules as git-rev-parse to resolve refspecs
In reply to Steffen ProhaskaQuoted 5 lines · Steffen Prohaska
remote.c +0
-0
remote.c static int count_refspec_match(const char *pattern, · line 523
Quoted 9 lines
remote.c +1
-4@@ -519,10 +519,7 @@ static int count_refspec_match(const char *pattern,char *name = refs->name;int namelen =strlen (name); -if (namelen < patlen || -memcmp (name + namelen - patlen, pattern, patlen)) -continue ; -if (namelen != patlen && name[namelen - patlen -1 ] !='/' ) +if (!ref_abbrev_matches_full_with_rules (pattern, name, ref_rev_parse_rules))continue ;
I vaguely recall that in the old round this check used to be without negation '!' in the front. I think this version is correct.
Re: [PATCH 5/6] push: use same rules as git-rev-parse to resolve refspecs
Quoted 11 lines · Junio C Hamano
Quoted 9 lines · Steffen Prohaska
remote.c +0
-0@@ -519,10 +519,7 @@ static int count_refspec_match(const char *pattern, char *name = refs->name;int namelen =strlen (name);
Quoted 11 lines
remote.c static int count_refspec_match(const char *pattern, · line 523
Quoted 7 lines
remote.c +1
-4-if (namelen < patlen || -memcmp (name + namelen - patlen, pattern, patlen)) -continue ; -if (namelen != patlen && name[namelen - patlen -1 ] !='/' ) +if (!ref_abbrev_matches_full_with_rules (pattern, name, ref_rev_parse_rules))continue ;I vaguely recall that in the old round this check used to be without negation '!' in the front. I think this version is correct.
Yes. I started with a syntax inspired by strcmp. But later the function got match in its name. I think returning a match with 'true' is more natural; and reserving '-1, 0, 1' for compare (as in strcmp). Therefore I changed the return value.
With '!' is correct now. Without '!' was correct before.
Steffen
Re: [PATCH 4/6] add ref_abbrev_matches_full_with_rules()
In reply to Steffen ProhaskaQuoted 4 lines · Steffen Prohaska
refs.c +4
-0+int ref_abbrev_matches_full_with_rules (const char *abbrev_name,const char *full_name,const char **rules) +{ +const char **p; +const int abbrev_name_len =strlen (abbrev_name);
refs.c int check_ref_format(const char *ref) · line 681
Quoted 10 lines
refs.c +10
-0+ +for (p = rules; *p; p++) { +if (!strcmp (full_name,mkpath (*p, abbrev_name_len, abbrev_name))) { +return 1 ; + } + } + +return 0 ; +} +
How about calling this simply "ref_abbrev_matches()" or "refname_match()" which is even shorter?
Re: [PATCH 4/6] add ref_abbrev_matches_full_with_rules()
Quoted 13 lines · Junio C Hamano
Quoted 11 lines · Steffen Prohaska
+int
ref_abbrev_matches_full_with_rules(const char *abbrev_name, const char *full_name, const char **rules)refs.c +6
-0+{ + const char **p; + const int abbrev_name_len = strlen(abbrev_name); + + for (p = rules; *p; p++) { + if (!strcmp(full_name, mkpath(*p, abbrev_name_len,
abbrev_name))) {(quoted diff) +2
-0+ return 1; + }
Quoted 8 lines
refs.c int check_ref_format(const char *ref) · line 681
Quoted 5 lines
refs.c +5
-0+ } + +return 0 ; +} +How about calling this simply "
ref_abbrev_matches()" or "refname_match()" which is even shorter?
Yes. As you already did on pu. Thanks for cleaning up.
Steffen
Re: [PATCH 3/6] push: support pushing HEAD to real branch name
In reply to Steffen ProhaskaQuoted 5 lines · Steffen Prohaska
builtin-push.c +0
-0
builtin-push.c static void set_refspecs(const char **refs, int nr) · line 52
Quoted 9 lines
builtin-push.c +6
-0@@ -44,6 +44,15 @@ static void set_refspecs(const char **refs, int nr)strcat (tag, refs[i]); ref = tag; } +if (!strcmp ("HEAD" , ref)) { +unsigned char sha1_dummy[20 ]; + ref =resolve_ref (ref, sha1_dummy,1 ,NULL ); +if (!ref) +die ("HEAD cannot be resolved." ); +if (strncmp (ref,"refs/heads/" ,11 ))
Why not prefixcmp(ref, "refs/heads/")?
Signature · 3 lines
Andreas Ericsson [email protected] OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231
PATCH 3/6 push: support pushing HEAD to real branch name
This teaches "push <remote> HEAD" to resolve HEAD on the local side to its real branch name, e.g. master, and then act as if the real branch name was specified. So we have a shorthand for pushing the current branch. Besides HEAD, no other symbolic ref is resolved.
Thanks to Daniel Barkalow <[email protected]> for suggesting this implementation, which is much simpler than the implementation proposed before.
--- builtin-push.c | 9 +++++++++ t/t5516-fetch-push.sh | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-)
prefixcmp() is simpler.
Steffen
builtin-push.c +9 -0
@@ -44,6 +44,15 @@ static void set_refspecs(const char **refs, int nr)strcat (tag, refs[i]); ref = tag; } +if (!strcmp ("HEAD" , ref)) { +unsigned char sha1_dummy[20 ]; + ref =resolve_ref (ref, sha1_dummy,1 ,NULL ); +if (!ref) +die ("HEAD cannot be resolved." ); +if (prefixcmp (ref,"refs/heads/" )) +die ("HEAD cannot be resolved to branch." ); + ref =xstrdup (ref +11 ); + }add_refspec (ref); } }
t/t5516-fetch-push.sh +17 -0
@@ -244,6 +244,23 @@ test_expect_success 'push with colon-less refspec (4)' ' ' +test_expect_success 'push with HEAD' ' + + mk_test heads/master && + git checkout master && + git push testrepo HEAD && + check_push_result $the_commit heads/master + +' + +test_expect_success 'push with HEAD nonexisting at remote' ' + + mk_test heads/master && + git checkout -b local master && + git push testrepo HEAD && + check_push_result $the_commit heads/local +' + test_expect_success 'push with dry-run' ' mk_test heads/master &&
Signature · 1 line
1.5.3.5.643.g20245
Re: [PATCH 1/6] push: mention --verbose option in documentation
In reply to Steffen ProhaskaQuoted 1 line · Steffen Prohaska
From: Steffen Prohaska <[email protected]>
This is obviously wrong. I have no clear idea how this happend. I remember I took the topic branch sp/push-refspec from pu and started to refactor. I used 'rebase' and 'rebase -i' a couple of times and now I have my name with Junios email address.
I'll investigate how this could happen.
Steffen
Re: [PATCH 1/6] push: mention --verbose option in documentation
Quoted 11 lines · Steffen Prohaska
Quoted 1 line · Steffen Prohaska
From: Steffen Prohaska <[email protected]>
This is obviously wrong. I have no clear idea how this happend. I remember I took the topic branch sp/push-refspec from pu and started to refactor. I used 'rebase' and 'rebase -i' a couple of times and now I have my name with Junios email address.
I'll investigate how this could happen.
The Author line was already wrong in Junio's pu branch, commit f31447f5f06200305393ca16e2eb9485e65dcccc, and I carried this over without noticing.
Steffen
Re: [PATCH 1/6] push: mention --verbose option in documentation
Quoted 3 lines · Steffen Prohaska
The Author line was already wrong in Junio's pu branch, commit
f31447f5f06200305393ca16e2eb9485e65dcccc, and I carried this over without noticing.
Yes, I know I pushed out a faulty one on 'pu' in the past. I am suspecting that it probably was a misuse of "git commit --author" after _not_ applying a WS mangled patch and instead of typing, or something like that.