push: make setup_push_* return the dst

All of the setup_push_* functions are appending a refspec. Do this only once on the parent function. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed May 31, 2021 at 14:51 UTC 00458dc5f191f52ef965ca7185b739e8c800b7cb
1 file changed +16 -14
builtin/push.c
+16 -14
@@ -202,8 +202,8 @@ static const char *get_upstream_ref(struct branch *branch, const char *remote_na
202 return branch->merge[0]->src;
203 }
204
205 -static void setup_push_upstream(struct remote *remote, struct branch *branch,
206 - int same_remote)
205 +static const char *setup_push_upstream(struct remote *remote, struct branch *branch,
206 + int same_remote)
207 {
208 const char *upstream_ref;
209 upstream_ref = get_upstream_ref(branch, remote->name);
@@ -212,16 +212,15 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,
212 "your current branch '%s', without telling me what to push\n"
213 "to update which remote branch."),
214 remote->name, branch->name);
215 -
216 - refspec_appendf(&rs, "%s:%s", branch->refname, upstream_ref);
215 + return upstream_ref;
216 }
217
219 -static void setup_push_current(struct remote *remote, struct branch *branch)
218 +static const char *setup_push_current(struct remote *remote, struct branch *branch)
219 {
221 - refspec_appendf(&rs, "%s:%s", branch->refname, branch->refname);
220 + return branch->refname;
221 }
222
224 -static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)
223 +static const char *setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)
224 {
225 if (same_remote) {
226 const char *upstream_ref;
@@ -232,7 +231,7 @@ static void setup_push_simple(struct remote *remote, struct branch *branch, int
231 if (strcmp(branch->refname, upstream_ref))
232 die_push_simple(branch, remote);
233 }
235 - refspec_appendf(&rs, "%s:%s", branch->refname, branch->refname);
234 + return branch->refname;
235 }
236
237 static int is_same_remote(struct remote *remote)
@@ -245,6 +244,7 @@ static void setup_default_push_refspecs(struct remote *remote)
244 {
245 struct branch *branch;
246 int same_remote = is_same_remote(remote);
247 + const char *dst;
248
249 switch (push_default) {
250 case PUSH_DEFAULT_MATCHING:
@@ -267,17 +267,19 @@ static void setup_default_push_refspecs(struct remote *remote)
267 default:
268 case PUSH_DEFAULT_UNSPECIFIED:
269 case PUSH_DEFAULT_SIMPLE:
270 - setup_push_simple(remote, branch, same_remote);
271 - return;
270 + dst = setup_push_simple(remote, branch, same_remote);
271 + break;
272
273 case PUSH_DEFAULT_UPSTREAM:
274 - setup_push_upstream(remote, branch, same_remote);
275 - return;
274 + dst = setup_push_upstream(remote, branch, same_remote);
275 + break;
276
277 case PUSH_DEFAULT_CURRENT:
278 - setup_push_current(remote, branch);
279 - return;
278 + dst = setup_push_current(remote, branch);
279 + break;
280 }
281 +
282 + refspec_appendf(&rs, "%s:%s", branch->refname, dst);
283 }
284
285 static const char message_advice_pull_before_push[] =