* [PATCH] style: indent multiline "if" conditions by 4 spaces
@ 2020-12-03 8:00 Jeff King
2020-12-03 18:22 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Jeff King @ 2020-12-03 8:00 UTC (permalink / raw)
To: git
Commit 6dc905d974 (config: split repo scope to local and worktree,
2020-02-10) made some "if" statements multiline, but didn't indent the
second lines in our usual way.
Signed-off-by: Jeff King <peff@peff.net>
---
I just happened to be reading nearby code and saw this.
remote.c | 2 +-
upload-pack.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/remote.c b/remote.c
index 8a6dbbb903..8b9d090ae5 100644
--- a/remote.c
+++ b/remote.c
@@ -355,7 +355,7 @@ static int handle_config(const char *key, const char *value, void *cb)
remote = make_remote(name, namelen);
remote->origin = REMOTE_CONFIG;
if (current_config_scope() == CONFIG_SCOPE_LOCAL ||
- current_config_scope() == CONFIG_SCOPE_WORKTREE)
+ current_config_scope() == CONFIG_SCOPE_WORKTREE)
remote->configured_in_repo = 1;
if (!strcmp(subkey, "mirror"))
remote->mirror = git_config_bool(key, value);
diff --git a/upload-pack.c b/upload-pack.c
index 5dc8e1f844..a85d4ec502 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1302,7 +1302,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
}
if (current_config_scope() != CONFIG_SCOPE_LOCAL &&
- current_config_scope() != CONFIG_SCOPE_WORKTREE) {
+ current_config_scope() != CONFIG_SCOPE_WORKTREE) {
if (!strcmp("uploadpack.packobjectshook", var))
return git_config_string(&data->pack_objects_hook, var, value);
}
--
2.29.2.896.g080220a959
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] style: indent multiline "if" conditions by 4 spaces
2020-12-03 8:00 [PATCH] style: indent multiline "if" conditions by 4 spaces Jeff King
@ 2020-12-03 18:22 ` Junio C Hamano
2020-12-03 18:32 ` Jeff King
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2020-12-03 18:22 UTC (permalink / raw)
To: Jeff King; +Cc: git
Jeff King <peff@peff.net> writes:
> Commit 6dc905d974 (config: split repo scope to local and worktree,
> 2020-02-10) made some "if" statements multiline, but didn't indent the
> second lines in our usual way.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> I just happened to be reading nearby code and saw this.
Can we rephrase "by 4 spaces" to avoid misleading new developers,
though? It's not like our rule is to indent continued expression by
4 spaces---it happens to be 4 in this case only because the second
line is aligned with the column inside "if (".
If the expression were
if ((A == X && B == Y &&
boolean_expression_on_the_second_line()) ||
C == Z)
we would have indented the second line to align with the inside of
the opening parenthesis, which may end up with "by 5 spaces", but
four vs five is not the important part of the equation.
Thanks.
> diff --git a/remote.c b/remote.c
> index 8a6dbbb903..8b9d090ae5 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -355,7 +355,7 @@ static int handle_config(const char *key, const char *value, void *cb)
> remote = make_remote(name, namelen);
> remote->origin = REMOTE_CONFIG;
> if (current_config_scope() == CONFIG_SCOPE_LOCAL ||
> - current_config_scope() == CONFIG_SCOPE_WORKTREE)
> + current_config_scope() == CONFIG_SCOPE_WORKTREE)
> remote->configured_in_repo = 1;
> if (!strcmp(subkey, "mirror"))
> remote->mirror = git_config_bool(key, value);
> diff --git a/upload-pack.c b/upload-pack.c
> index 5dc8e1f844..a85d4ec502 100644
> --- a/upload-pack.c
> +++ b/upload-pack.c
> @@ -1302,7 +1302,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
> }
>
> if (current_config_scope() != CONFIG_SCOPE_LOCAL &&
> - current_config_scope() != CONFIG_SCOPE_WORKTREE) {
> + current_config_scope() != CONFIG_SCOPE_WORKTREE) {
> if (!strcmp("uploadpack.packobjectshook", var))
> return git_config_string(&data->pack_objects_hook, var, value);
> }
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] style: indent multiline "if" conditions by 4 spaces
2020-12-03 18:22 ` Junio C Hamano
@ 2020-12-03 18:32 ` Jeff King
2020-12-03 18:38 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Jeff King @ 2020-12-03 18:32 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Thu, Dec 03, 2020 at 10:22:35AM -0800, Junio C Hamano wrote:
> Jeff King <peff@peff.net> writes:
>
> > Commit 6dc905d974 (config: split repo scope to local and worktree,
> > 2020-02-10) made some "if" statements multiline, but didn't indent the
> > second lines in our usual way.
> >
> > Signed-off-by: Jeff King <peff@peff.net>
> > ---
> > I just happened to be reading nearby code and saw this.
>
> Can we rephrase "by 4 spaces" to avoid misleading new developers,
> though? It's not like our rule is to indent continued expression by
> 4 spaces---it happens to be 4 in this case only because the second
> line is aligned with the column inside "if (".
>
> If the expression were
>
> if ((A == X && B == Y &&
> boolean_expression_on_the_second_line()) ||
> C == Z)
>
> we would have indented the second line to align with the inside of
> the opening parenthesis, which may end up with "by 5 spaces", but
> four vs five is not the important part of the equation.
Yeah, the goal is to align it, but I had trouble thinking of a succinct
way to say that. Maybe just:
style: align indent of multiline "if" conditions
?
-Peff
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] style: indent multiline "if" conditions by 4 spaces
2020-12-03 18:32 ` Jeff King
@ 2020-12-03 18:38 ` Junio C Hamano
2020-12-03 18:51 ` Jeff King
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2020-12-03 18:38 UTC (permalink / raw)
To: Jeff King; +Cc: git
Jeff King <peff@peff.net> writes:
> Yeah, the goal is to align it, but I had trouble thinking of a succinct
> way to say that. Maybe just:
>
> style: align indent of multiline "if" conditions
I couldn't come up with a good description, and
just did s/by 4 spaces/to align/, i.e.
style: indent multiline "if" conditions to align
while queuing. I dunno.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] style: indent multiline "if" conditions by 4 spaces
2020-12-03 18:38 ` Junio C Hamano
@ 2020-12-03 18:51 ` Jeff King
0 siblings, 0 replies; 5+ messages in thread
From: Jeff King @ 2020-12-03 18:51 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Thu, Dec 03, 2020 at 10:38:30AM -0800, Junio C Hamano wrote:
> Jeff King <peff@peff.net> writes:
>
> > Yeah, the goal is to align it, but I had trouble thinking of a succinct
> > way to say that. Maybe just:
> >
> > style: align indent of multiline "if" conditions
>
> I couldn't come up with a good description, and
> just did s/by 4 spaces/to align/, i.e.
>
> style: indent multiline "if" conditions to align
>
> while queuing. I dunno.
That sounds perfectly reasonable to me.
-Peff
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-12-03 18:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-03 8:00 [PATCH] style: indent multiline "if" conditions by 4 spaces Jeff King
2020-12-03 18:22 ` Junio C Hamano
2020-12-03 18:32 ` Jeff King
2020-12-03 18:38 ` Junio C Hamano
2020-12-03 18:51 ` Jeff King
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).