Skip to contentSkip to conversation

sequencer: remove unreachable exit condition in pick_commits()

PATCH Superseded Oswald Buddenhagen 3 participants 5 messages Sep 3, 2023 – Sep 13, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sequencer: remove unreachable exit condition in pick_commits()

This was introduced by 56dc3ab04 ("sequencer (rebase -i): implement the 'edit' command", 2017-01-02), and was pointless from the get-go, as the command causes an early return.

---
this remains valid after phillip's pending series, through it becomes marginally harder to prove (c.f. "sequencer: factor out part of pick_commits()").

Cc Johannes Schindelin <[email protected]>
Cc Phillip Wood <[email protected]>
---
 sequencer.c | 4 ----
 1 file changed, 4 deletions(-)
sequencer.c +0 -4
index a66dcf8ab2..99e9c520ca 100644
@@ -4832,10 +4832,6 @@ static int pick_commits(struct repository *r,
 		struct strbuf head_ref = STRBUF_INIT, buf = STRBUF_INIT;
 		struct stat st;
 
-		/* Stopped in the middle, as planned? */
-		if (todo_list->current < todo_list->nr)
-			return 0;
-
 		if (read_oneliner(&head_ref, rebase_path_head_name(), 0) &&
 				starts_with(head_ref.buf, "refs/")) {
 			const char *msg;
Signature · 1 line
2.40.0.152.g15d061e6df
#1 lore raw

Hi Oswald

Quoted 3 lines · Oswald Buddenhagen

This was introduced by 56dc3ab04 ("sequencer (rebase -i): implement the 'edit' command", 2017-01-02), and was pointless from the get-go, as the command causes an early return.

While I agree this code is unreachable, just because it was unused when it was added does not mean it is unused now. It would be helpful for the commit message to explain that there are no "break" or "goto" statements in the loop body and therefore this code is only reachable when the loop terminates because todo_list->current == todo_list->nr

Best Wishes

Phillip

Quoted 28 lines

---
this remains valid after phillip's pending series, through it becomes marginally harder to prove (c.f. "sequencer: factor out part of pick_commits()").

Cc Johannes Schindelin <[email protected]>
Cc Phillip Wood <[email protected]>
---
  sequencer.c | 4 ----
  1 file changed, 4 deletions(-)
sequencer.c +0 -4
index a66dcf8ab2..99e9c520ca 100644
@@ -4832,10 +4832,6 @@ static int pick_commits(struct repository *r,
  		struct strbuf head_ref = STRBUF_INIT, buf = STRBUF_INIT;
  		struct stat st;
 
-		/* Stopped in the middle, as planned? */
-		if (todo_list->current < todo_list->nr)
-			return 0;
-
  		if (read_oneliner(&head_ref, rebase_path_head_name(), 0) &&
  				starts_with(head_ref.buf, "refs/")) {
  			const char *msg;
#2 lore raw

PATCH v2 1/1 sequencer: remove unreachable exit condition in pick_commits()

This was introduced by 56dc3ab04 ("sequencer (rebase -i): implement the 'edit' command", 2017-01-02), and was pointless from the get-go: all early exits from the loop above are returns, so todo_list->current == todo_list->nr is an invariant after the loop.

---
v2:
- improved commit message

Cc Johannes Schindelin <[email protected]>
Cc Phillip Wood <[email protected]>
Cc Junio C Hamano <[email protected]>
---
 sequencer.c | 4 ----
 1 file changed, 4 deletions(-)
sequencer.c +0 -4
index a66dcf8ab2..99e9c520ca 100644
@@ -4832,10 +4832,6 @@ static int pick_commits(struct repository *r,
 		struct strbuf head_ref = STRBUF_INIT, buf = STRBUF_INIT;
 		struct stat st;
 
-		/* Stopped in the middle, as planned? */
-		if (todo_list->current < todo_list->nr)
-			return 0;
-
 		if (read_oneliner(&head_ref, rebase_path_head_name(), 0) &&
 				starts_with(head_ref.buf, "refs/")) {
 			const char *msg;
Signature · 1 line
2.42.0.419.g70bf8a5751
#3 lore raw
Quoted 6 lines · Oswald Buddenhagen

This was introduced by 56dc3ab04 ("sequencer (rebase -i): implement the 'edit' command", 2017-01-02), and was pointless from the get-go: all early exits from the loop above are returns, so todo_list->current == todo_list->nr is an invariant after the loop.

Thanks for updating the commit message, I think it is clearer now

Best Wishes

Phillip

Quoted 26 lines

---
v2:
- improved commit message

Cc Johannes Schindelin <[email protected]>
Cc Phillip Wood <[email protected]>
Cc Junio C Hamano <[email protected]>
---
  sequencer.c | 4 ----
  1 file changed, 4 deletions(-)
sequencer.c +0 -4
index a66dcf8ab2..99e9c520ca 100644
@@ -4832,10 +4832,6 @@ static int pick_commits(struct repository *r,
  		struct strbuf head_ref = STRBUF_INIT, buf = STRBUF_INIT;
  		struct stat st;
 
-		/* Stopped in the middle, as planned? */
-		if (todo_list->current < todo_list->nr)
-			return 0;
-
  		if (read_oneliner(&head_ref, rebase_path_head_name(), 0) &&
  				starts_with(head_ref.buf, "refs/")) {
  			const char *msg;
#4 lore raw
Quoted 8 lines · Phillip Wood
Quoted 5 lines · Oswald Buddenhagen

This was introduced by 56dc3ab04 ("sequencer (rebase -i): implement the 'edit' command", 2017-01-02), and was pointless from the get-go: all early exits from the loop above are returns, so todo_list->current == todo_list->nr is an invariant after the loop.

Thanks for updating the commit message, I think it is clearer now

Thanks, both. Queued.