Skip to contentSkip to conversation

rebase: simplify an assignment of options.type in cmd_rebase

PATCH Superseded Edmundo Carmona Antoranz 2 participants 2 messages Apr 18, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rebase: simplify an assignment of options.type in cmd_rebase

There is an if statement where both if and else have the same assignment of options.type to REBASE_MERGE. Simplify it by getting that assigmnent out of the if.

---
 builtin/rebase.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
builtin/rebase.c +2 -4
index 27fde7bf28..d2d63bdef1 100644
@@ -1187,11 +1187,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		} else {
 			strbuf_reset(&buf);
 			strbuf_addf(&buf, "%s/interactive", merge_dir());
-			if(file_exists(buf.buf)) {
-				options.type = REBASE_MERGE;
+			options.type = REBASE_MERGE;
+			if(file_exists(buf.buf))
 				options.flags |= REBASE_INTERACTIVE_EXPLICIT;
-			} else
-				options.type = REBASE_MERGE;
 		}
 		options.state_dir = merge_dir();
 	}
Signature · 1 line
2.35.1
#1 lore raw
Quoted 14 lines · Edmundo Carmona Antoranz

There is an if statement where both if and else have the same assignment of options.type to REBASE_MERGE. Simplify it by getting that assigmnent out of the if.

---
 builtin/rebase.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
builtin/rebase.c +0 -0
index 27fde7bf28..d2d63bdef1 100644

builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1191

Quoted 7 lines
builtin/rebase.c +2 -2
@@ -1187,11 +1187,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		} else {
 			strbuf_reset(&buf);
 			strbuf_addf(&buf, "%s/interactive", merge_dir());
-			if(file_exists(buf.buf)) {
-				options.type = REBASE_MERGE;
+			options.type = REBASE_MERGE;
+			if(file_exists(buf.buf))

Perhaps fix the style as we are changing the line anyway by losing {}? i.e.

if (file_exists(buf.buf))

builtin/rebase.c int cmd_rebase(int argc, const char **argv, const char *prefix) · line 1195

Quoted 6 lines
builtin/rebase.c +0 -2
 				options.flags |= REBASE_INTERACTIVE_EXPLICIT;
-			} else
-				options.type = REBASE_MERGE;
 		}
 		options.state_dir = merge_dir();
 	}

Other than that, good finding!