diff mbox series

[05/15] push: only get the branch when needed

Message ID 20210529074458.1916817-6-felipe.contreras@gmail.com (mailing list archive)
State New, archived
Headers show
Series None | expand

Commit Message

Felipe Contreras May 29, 2021, 7:44 a.m. UTC
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 builtin/push.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Junio C Hamano May 31, 2021, 6:44 a.m. UTC | #1
Felipe Contreras <felipe.contreras@gmail.com> writes:

> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  builtin/push.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

> diff --git a/builtin/push.c b/builtin/push.c
> index a2abacf64d..4b3a14278a 100644
> --- a/builtin/push.c
> +++ b/builtin/push.c
> @@ -243,7 +243,7 @@ static int is_workflow_triangular(struct remote *remote)
>  
>  static void setup_default_push_refspecs(struct remote *remote)
>  {
> -	struct branch *branch = branch_get(NULL);
> +	struct branch *branch;
>  	int triangular = is_workflow_triangular(remote);
>  
>  	switch (push_default) {
> @@ -258,6 +258,7 @@ static void setup_default_push_refspecs(struct remote *remote)
>  	default:

Not a fault of this step, but please make it a habit to have
"break;" here.  case label with absolutely no body just looks
strange and is distracting to the eyes.

>  	}
>  
> +	branch = branch_get(NULL);
>  	if (!branch)
>  		die(_(message_detached_head_die), remote->name);

This step is the true justification for the splitting of a single
switch into two switches done in [03/15].  Makes quite a lot of
sense.
Felipe Contreras May 31, 2021, 8:16 a.m. UTC | #2
Junio C Hamano wrote:
> Felipe Contreras <felipe.contreras@gmail.com> writes:
> 
> > Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> > ---
> >  builtin/push.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> > diff --git a/builtin/push.c b/builtin/push.c
> > index a2abacf64d..4b3a14278a 100644
> > --- a/builtin/push.c
> > +++ b/builtin/push.c
> > @@ -243,7 +243,7 @@ static int is_workflow_triangular(struct remote *remote)
> >  
> >  static void setup_default_push_refspecs(struct remote *remote)
> >  {
> > -	struct branch *branch = branch_get(NULL);
> > +	struct branch *branch;
> >  	int triangular = is_workflow_triangular(remote);
> >  
> >  	switch (push_default) {
> > @@ -258,6 +258,7 @@ static void setup_default_push_refspecs(struct remote *remote)
> >  	default:
> 
> Not a fault of this step, but please make it a habit to have
> "break;" here.  case label with absolutely no body just looks
> strange and is distracting to the eyes.

All right.

> >  	}
> >  
> > +	branch = branch_get(NULL);
> >  	if (!branch)
> >  		die(_(message_detached_head_die), remote->name);
> 
> This step is the true justification for the splitting of a single
> switch into two switches done in [03/15].  Makes quite a lot of
> sense.

It is one, not the only one. But yeah, the most readily apparent.
diff mbox series

Patch

diff --git a/builtin/push.c b/builtin/push.c
index a2abacf64d..4b3a14278a 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -243,7 +243,7 @@  static int is_workflow_triangular(struct remote *remote)
 
 static void setup_default_push_refspecs(struct remote *remote)
 {
-	struct branch *branch = branch_get(NULL);
+	struct branch *branch;
 	int triangular = is_workflow_triangular(remote);
 
 	switch (push_default) {
@@ -258,6 +258,7 @@  static void setup_default_push_refspecs(struct remote *remote)
 	default:
 	}
 
+	branch = branch_get(NULL);
 	if (!branch)
 		die(_(message_detached_head_die), remote->name);