git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/5] sequencer.c: factor out a function

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Sep 9, 2021, 10:44 UTC
Message-ID
<nycvar.QRO.7.76.6.2109091241270.59@tvgsbejvaqbjf.bet>
In-Reply-To
<53cde4825b408e5fb893bbd9a222e7387d69a408.1631108472.git.gitgitgadget@gmail.com>
Hi Phillip,
On Wed, 8 Sep 2021, Phillip Wood via GitGitGadget wrote:
Show 64 quoted lines
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> This code is heavily indented and obscures the high level logic within
> the loop. Lets move it to its own function before modifying it in the
> next commit.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  sequencer.c | 38 ++++++++++++++++++++++++--------------
>  1 file changed, 24 insertions(+), 14 deletions(-)
>
> diff --git a/sequencer.c b/sequencer.c
> index 7f07cd00f3f..a248c886c27 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -4254,6 +4254,27 @@ static int stopped_at_head(struct repository *r)
>
>  }
>
> +static int reread_todo_if_changed(struct repository *r,
> +				  struct todo_list *todo_list,
> +				  struct replay_opts *opts)
> +{
> +	struct stat st;
> +
> +	if (stat(get_todo_path(opts), &st)) {
> +		return error_errno(_("could not stat '%s'"),
> +				   get_todo_path(opts));
> +	} else if (match_stat_data(&todo_list->stat, &st)) {
> +		/* Reread the todo file if it has changed. */
> +		todo_list_release(todo_list);
> +		if (read_populate_todo(r, todo_list, opts))
> +			return -1; /* message was printed */
> +		/* `current` will be incremented on return */
> +		todo_list->current = -1;
> +	}
> +
> +	return 0;
> +}
> +
>  static const char rescheduled_advice[] =
>  N_("Could not execute the todo command\n"
>  "\n"
> @@ -4433,20 +4454,9 @@ static int pick_commits(struct repository *r,
>  							item->commit,
>  							arg, item->arg_len,
>  							opts, res, 0);
> -		} else if (is_rebase_i(opts) && check_todo && !res) {
> -			struct stat st;
> -
> -			if (stat(get_todo_path(opts), &st)) {
> -				res = error_errno(_("could not stat '%s'"),
> -						  get_todo_path(opts));
> -			} else if (match_stat_data(&todo_list->stat, &st)) {
> -				/* Reread the todo file if it has changed. */
> -				todo_list_release(todo_list);
> -				if (read_populate_todo(r, todo_list, opts))
> -					res = -1; /* message was printed */
> -				/* `current` will be incremented below */
> -				todo_list->current = -1;
> -			}
> +		} else if (is_rebase_i(opts) && check_todo && !res &&
> +			   reread_todo_if_changed(r, todo_list, opts)) {
> +			return -1;

It definitely looks like a good refactoring, but it does subtly change the behavior. If the `todo` file could not be found, we previously continued after printing out an error, but now we return with an error.

Likewise, if the `todo` file existed but had a parse error, we would print that error _but continue_. This is definitely a bug, if you ask me.

Now, this might be a desirable change in the first place: if an `exec` command removed the `todo` file, changes are that the user wanted to abort, right? And the bug needs to be fixed, too.

It does need to be called out in the commit message, though.

Thank you, Dscho

Show 7 quoted lines
>  		}
>
>  		todo_list->current++;
> --
> gitgitgadget
>
>
Previous: Phillip WoodNext: Phillip Wood via GitGitGadget
Message 5 of 31 in “rebase -i: a couple of small improvements”
  1. 0/5 rebase -i: a couple of small improvementsPhillip Wood via GitGitGadget, Sep 8, 2021
  2. 1/5 sequencer.c: factor out a functionPhillip Wood via GitGitGadget, Sep 8, 2021
  3. Eric SunshineSep 8, 2021
  4. Phillip WoodSep 9, 2021
  5. Johannes SchindelinSep 9, 2021
  6. 2/5 rebase: fix todo-list rereadingPhillip Wood via GitGitGadget, Sep 8, 2021
  7. Johannes SchindelinSep 9, 2021
  8. 3/5 reset_head(): mark oid parameter as constPhillip Wood via GitGitGadget, Sep 8, 2021
  9. 4/5 rebase -i: don't fork git checkoutPhillip Wood via GitGitGadget, Sep 8, 2021
  10. Philippe BlainSep 8, 2021
  11. Phillip WoodSep 9, 2021
  12. Philippe BlainSep 9, 2021
  13. Phillip WoodSep 9, 2021
  14. Elijah NewrenSep 9, 2021
  15. Philippe BlainSep 10, 2021
  16. Phillip WoodSep 15, 2021
  17. Johannes SchindelinSep 9, 2021
  18. Philippe BlainSep 9, 2021
  19. Johannes SchindelinSep 9, 2021
  20. Johannes SchindelinSep 10, 2021
  21. Philippe BlainSep 10, 2021
  22. Elijah NewrenSep 9, 2021
  23. 5/5 rebase: remove unused parameterPhillip Wood via GitGitGadget, Sep 8, 2021
  24. Johannes SchindelinSep 9, 2021
  25. Phillip WoodSep 9, 2021
  26. 0/2 rebase -i: a couple of small improvementsPhillip Wood via GitGitGadget, Sep 23, 2021
  27. 2/2 rebase: fix todo-list rereadingPhillip Wood via GitGitGadget, Sep 23, 2021
  28. Junio C HamanoSep 24, 2021
  29. Phillip WoodSep 28, 2021
  30. 1/2 sequencer.c: factor out a functionPhillip Wood via GitGitGadget, Sep 23, 2021
  31. Junio C HamanoSep 24, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.