Fix builtin-push to honor Push: lines in remotes file.
[jc: originally from Johannes Schindelin, but reworked to lift a hard limit of Push: lines] Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Apr 30, 2006 at 16:03 UTC
7aaf83dafbde7aaa60a1e220e967faaeb28a46f6
1 file changed
+18
-16
builtin-push.c
+18
-16
@@ -68,14 +68,11 @@ static void set_refspecs(const char **refs, int nr)
68
expand_refspecs();
69
}
70
71
-#define MAX_REFSPECS 10
72
-static int current_refspec = 0;
73
-static char *refspecs_[MAX_REFSPECS];
74
-
71
static int get_remotes_uri(const char *repo, const char *uri[MAX_URI])
72
{
73
int n = 0;
74
FILE *f = fopen(git_path("remotes/%s", repo), "r");
75
+ int has_explicit_refspec = refspec_nr;
76
77
if (!f)
78
return -1;
@@ -103,10 +100,14 @@ static int get_remotes_uri(const char *repo, const char *uri[MAX_URI])
100
while (isspace(p[-1]))
101
*--p = 0;
102
106
- if (!is_refspec && n < MAX_URI)
107
- uri[n++] = strdup(s);
108
- else if (is_refspec && current_refspec < MAX_REFSPECS)
109
- refspecs_[current_refspec++] = strdup(s);
103
+ if (!is_refspec) {
104
+ if (n < MAX_URI)
105
+ uri[n++] = strdup(s);
106
+ else
107
+ error("more than %d URL's specified, ignoreing the rest", MAX_URI);
108
+ }
109
+ else if (is_refspec && !has_explicit_refspec)
110
+ add_refspec(strdup(s));
111
}
112
fclose(f);
113
if (!n)
@@ -146,13 +147,17 @@ static int get_branches_uri(const char *repo, const char *uri[MAX_URI])
147
return 1;
148
}
149
149
-static int get_uri(const char *repo, const char *uri[MAX_URI])
150
+/*
151
+ * Read remotes and branches file, fill the push target URI
152
+ * list. If there is no command line refspecs, read Push: lines
153
+ * to set up the *refspec list as well.
154
+ * return the number of push target URIs
155
+ */
156
+static int read_config(const char *repo, const char *uri[MAX_URI])
157
{
158
int n;
159
160
if (*repo != '/') {
154
- current_refspec = 0;
155
-
161
n = get_remotes_uri(repo, uri);
162
if (n > 0)
163
return n;
@@ -169,18 +174,15 @@ static int get_uri(const char *repo, const char *uri[MAX_URI])
174
static int do_push(const char *repo)
175
{
176
const char *uri[MAX_URI];
172
- int i, n = get_uri(repo, uri);
177
+ int i, n;
178
int remote;
179
const char **argv;
180
int argc;
181
177
- n = get_uri(repo, uri);
182
+ n = read_config(repo, uri);
183
if (n <= 0)
184
die("bad repository '%s'", repo);
185
181
- if (refspec_nr == 0)
182
- set_refspecs((const char**)refspecs_, current_refspec);
183
-
186
argv = xmalloc((refspec_nr + 10) * sizeof(char *));
187
argv[0] = "dummy-send-pack";
188
argc = 1;