push: reorganize setup_push_simple()
Simply move the code around and remove dead code. In particular the '!same_remote' conditional is a no-op since that part of the code is the same_remote leg of the conditional beforehand. No functional changes. Suggestions-by: Elijah Newren <newren@gmail.com> 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:32 UTC
6b010c80a2596c75d562afa5ab098ffff21bab06
1 file changed
+12
-17
builtin/push.c
+12
-17
@@ -225,13 +225,14 @@ static void setup_push_current(struct remote *remote, struct branch *branch)
225
226
static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)
227
{
228
+ const char *dst;
229
+
230
+ if (!branch)
231
+ die(_(message_detached_head_die), remote->name);
232
+
233
if (!same_remote) {
229
- if (!branch)
230
- die(_(message_detached_head_die), remote->name);
231
- refspec_appendf(&rs, "%s:%s", branch->refname, branch->refname);
234
+ dst = branch->refname;
235
} else {
233
- if (!branch)
234
- die(_(message_detached_head_die), remote->name);
236
if (!branch->merge_nr || !branch->merge || !branch->remote_name)
237
die(_("The current branch %s has no upstream branch.\n"
238
"To push the current branch and set the remote as upstream, use\n"
@@ -243,20 +244,14 @@ static void setup_push_simple(struct remote *remote, struct branch *branch, int
244
if (branch->merge_nr != 1)
245
die(_("The current branch %s has multiple upstream branches, "
246
"refusing to push."), branch->name);
246
- if (!same_remote)
247
- die(_("You are pushing to remote '%s', which is not the upstream of\n"
248
- "your current branch '%s', without telling me what to push\n"
249
- "to update which remote branch."),
250
- remote->name, branch->name);
251
-
252
- if (1) {
253
- /* Additional safety */
254
- if (strcmp(branch->refname, branch->merge[0]->src))
255
- die_push_simple(branch, remote);
256
- }
247
258
- refspec_appendf(&rs, "%s:%s", branch->refname, branch->merge[0]->src);
248
+ /* Additional safety */
249
+ if (strcmp(branch->refname, branch->merge[0]->src))
250
+ die_push_simple(branch, remote);
251
+
252
+ dst = branch->merge[0]->src;
253
}
254
+ refspec_appendf(&rs, "%s:%s", branch->refname, dst);
255
}
256
257
static int is_same_remote(struct remote *remote)