git-push: accept tag <tag> as advertised.
The documentation talked about "git push $URL tag <tag>" as a short-hand for refs/tags/<tag>:refs/tags/<tag> for a long time but that was never the case (the short-hand was for "git fetch"). Instead of fixing the documentation, just add a bit of code to match it since it is easy to do and would make it more consistent. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Dec 13, 2006 at 10:03 UTC
411fb8baa6862b76f7bdd9fc0d5844855a4db589
1 file changed
+30
-5
builtin-push.c
+30
-5
@@ -57,11 +57,36 @@ static void expand_refspecs(void)
57
static void set_refspecs(const char **refs, int nr)
58
{
59
if (nr) {
60
- size_t bytes = nr * sizeof(char *);
61
-
62
- refspec = xrealloc(refspec, bytes);
63
- memcpy(refspec, refs, bytes);
64
- refspec_nr = nr;
60
+ int pass;
61
+ for (pass = 0; pass < 2; pass++) {
62
+ /* pass 0 counts and allocates, pass 1 fills */
63
+ int i, cnt;
64
+ for (i = cnt = 0; i < nr; i++) {
65
+ if (!strcmp("tag", refs[i])) {
66
+ int len;
67
+ char *tag;
68
+ if (nr <= ++i)
69
+ die("tag <tag> shorthand without <tag>");
70
+ if (pass) {
71
+ len = strlen(refs[i]) + 11;
72
+ tag = xmalloc(len);
73
+ strcpy(tag, "refs/tags/");
74
+ strcat(tag, refs[i]);
75
+ refspec[cnt] = tag;
76
+ }
77
+ cnt++;
78
+ continue;
79
+ }
80
+ if (pass)
81
+ refspec[cnt] = refs[i];
82
+ cnt++;
83
+ }
84
+ if (!pass) {
85
+ size_t bytes = cnt * sizeof(char *);
86
+ refspec_nr = cnt;
87
+ refspec = xrealloc(refspec, bytes);
88
+ }
89
+ }
90
}
91
expand_refspecs();
92
}