Skip to contentSkip to conversation

style: indent multiline "if" conditions by 4 spaces

PATCH In review Jeff King 2 participants 5 messages Dec 3, 2020

lore
Share & tools
lore

Jeff King

author
#0 lore raw

PATCH 1/1 style: indent multiline "if" conditions by 4 spaces

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.

---
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(-)
remote.c +1 -1
index 8a6dbbb903..8b9d090ae5 100644
@@ -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);
upload-pack.c +1 -1
index 5dc8e1f844..a85d4ec502 100644
@@ -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);
 	}
Signature · 1 line
2.29.2.896.g080220a959
#1 lore raw
Quoted 7 lines · Jeff King

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.

---
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.

Quoted 26 lines
remote.c +1 -1
index 8a6dbbb903..8b9d090ae5 100644
@@ -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);
upload-pack.c +1 -1
index 5dc8e1f844..a85d4ec502 100644
@@ -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);
 	}
author
#2 lore raw
Quoted 17 lines · Junio C Hamano
Quoted 7 lines · Jeff King

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.

---
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

Quoted 7 lines
	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

#3 lore raw
Quoted 4 lines · Jeff King

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.

author
#4 lore raw
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Jeff King

Yeah, the goal is to align it, but I had trouble thinking of a succinct way to say that. Maybe just:

Quoted 8 lines
Quoted 1 line

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