git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Phillip Wood via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, "Stefan Haller" <lists@haller-berlin.de>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"Rubén Justo" <rjusto@gmail.com>,
	"Phillip Wood" <phillip.wood@dunelm.org.uk>
Subject: Re: [PATCH v2 1/2] rebase -i: pass struct replay_opts to parse_insn_line()
Date: Tue, 9 Apr 2024 06:03:54 +0200	[thread overview]
Message-ID: <ZhS-KktVxRH-Xl3V@tanuki> (raw)
In-Reply-To: <1bcf92c6105e6e7ac2b2981575e112072fec383e.1712585787.git.gitgitgadget@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 11005 bytes --]

On Mon, Apr 08, 2024 at 02:16:26PM +0000, Phillip Wood via GitGitGadget wrote:
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
> 
> This new parameter will be used in the next commit.

Nit: we don't typically write commit messages as a continuation of their
subject. Other than that this commit looks good to me.

Patrick

> As adding the
> parameter requires quite a few changes to plumb it through the call
> chain these are separated into their own commit to avoid cluttering up
> the next commit with incidental changes.
> 
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  builtin/rebase.c     | 17 +++++++++++------
>  rebase-interactive.c | 21 +++++++++++++--------
>  rebase-interactive.h |  9 ++++++---
>  sequencer.c          | 22 ++++++++++++----------
>  sequencer.h          |  4 ++--
>  5 files changed, 44 insertions(+), 29 deletions(-)
> 
> diff --git a/builtin/rebase.c b/builtin/rebase.c
> index 891f28468e8..a33a2ed413a 100644
> --- a/builtin/rebase.c
> +++ b/builtin/rebase.c
> @@ -194,7 +194,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
>  	return replay;
>  }
>  
> -static int edit_todo_file(unsigned flags)
> +static int edit_todo_file(unsigned flags, struct replay_opts *opts)
>  {
>  	const char *todo_file = rebase_path_todo();
>  	struct todo_list todo_list = TODO_LIST_INIT,
> @@ -205,7 +205,8 @@ static int edit_todo_file(unsigned flags)
>  		return error_errno(_("could not read '%s'."), todo_file);
>  
>  	strbuf_stripspace(&todo_list.buf, comment_line_str);
> -	res = edit_todo_list(the_repository, &todo_list, &new_todo, NULL, NULL, flags);
> +	res = edit_todo_list(the_repository, opts, &todo_list, &new_todo,
> +			     NULL, NULL, flags);
>  	if (!res && todo_list_write_to_file(the_repository, &new_todo, todo_file,
>  					    NULL, NULL, -1, flags & ~(TODO_LIST_SHORTEN_IDS)))
>  		res = error_errno(_("could not write '%s'"), todo_file);
> @@ -296,8 +297,8 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
>  		error(_("could not generate todo list"));
>  	else {
>  		discard_index(&the_index);
> -		if (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf,
> -						&todo_list))
> +		if (todo_list_parse_insn_buffer(the_repository, &replay,
> +						todo_list.buf.buf, &todo_list))
>  			BUG("unusable todo list");
>  
>  		ret = complete_action(the_repository, &replay, flags,
> @@ -352,9 +353,13 @@ static int run_sequencer_rebase(struct rebase_options *opts)
>  		replay_opts_release(&replay_opts);
>  		break;
>  	}
> -	case ACTION_EDIT_TODO:
> -		ret = edit_todo_file(flags);
> +	case ACTION_EDIT_TODO: {
> +		struct replay_opts replay_opts = get_replay_opts(opts);
> +
> +		ret = edit_todo_file(flags, &replay_opts);
> +		replay_opts_release(&replay_opts);
>  		break;
> +	}
>  	case ACTION_SHOW_CURRENT_PATCH: {
>  		struct child_process cmd = CHILD_PROCESS_INIT;
>  
> diff --git a/rebase-interactive.c b/rebase-interactive.c
> index c343e16fcdd..56fd7206a95 100644
> --- a/rebase-interactive.c
> +++ b/rebase-interactive.c
> @@ -101,9 +101,10 @@ void append_todo_help(int command_count,
>  	strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str);
>  }
>  
> -int edit_todo_list(struct repository *r, struct todo_list *todo_list,
> -		   struct todo_list *new_todo, const char *shortrevisions,
> -		   const char *shortonto, unsigned flags)
> +int edit_todo_list(struct repository *r, struct replay_opts *opts,
> +		   struct todo_list *todo_list, struct todo_list *new_todo,
> +		   const char *shortrevisions, const char *shortonto,
> +		   unsigned flags)
>  {
>  	const char *todo_file = rebase_path_todo(),
>  		*todo_backup = rebase_path_todo_backup();
> @@ -114,7 +115,9 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
>  	 * it.  If there is an error, we do not return, because the user
>  	 * might want to fix it in the first place. */
>  	if (!initial)
> -		incorrect = todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list) |
> +		incorrect = todo_list_parse_insn_buffer(r, opts,
> +							todo_list->buf.buf,
> +							todo_list) |
>  			file_exists(rebase_path_dropped());
>  
>  	if (todo_list_write_to_file(r, todo_list, todo_file, shortrevisions, shortonto,
> @@ -134,13 +137,13 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
>  	if (initial && new_todo->buf.len == 0)
>  		return -3;
>  
> -	if (todo_list_parse_insn_buffer(r, new_todo->buf.buf, new_todo)) {
> +	if (todo_list_parse_insn_buffer(r, opts, new_todo->buf.buf, new_todo)) {
>  		fprintf(stderr, _(edit_todo_list_advice));
>  		return -4;
>  	}
>  
>  	if (incorrect) {
> -		if (todo_list_check_against_backup(r, new_todo)) {
> +		if (todo_list_check_against_backup(r, opts, new_todo)) {
>  			write_file(rebase_path_dropped(), "%s", "");
>  			return -4;
>  		}
> @@ -228,13 +231,15 @@ int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo)
>  	return res;
>  }
>  
> -int todo_list_check_against_backup(struct repository *r, struct todo_list *todo_list)
> +int todo_list_check_against_backup(struct repository *r,
> +				   struct replay_opts *opts,
> +				   struct todo_list *todo_list)
>  {
>  	struct todo_list backup = TODO_LIST_INIT;
>  	int res = 0;
>  
>  	if (strbuf_read_file(&backup.buf, rebase_path_todo_backup(), 0) > 0) {
> -		todo_list_parse_insn_buffer(r, backup.buf.buf, &backup);
> +		todo_list_parse_insn_buffer(r, opts, backup.buf.buf, &backup);
>  		res = todo_list_check(&backup, todo_list);
>  	}
>  
> diff --git a/rebase-interactive.h b/rebase-interactive.h
> index 7239c60f791..8e5b181b334 100644
> --- a/rebase-interactive.h
> +++ b/rebase-interactive.h
> @@ -3,17 +3,20 @@
>  
>  struct strbuf;
>  struct repository;
> +struct replay_opts;
>  struct todo_list;
>  
>  void append_todo_help(int command_count,
>  		      const char *shortrevisions, const char *shortonto,
>  		      struct strbuf *buf);
> -int edit_todo_list(struct repository *r, struct todo_list *todo_list,
> -		   struct todo_list *new_todo, const char *shortrevisions,
> -		   const char *shortonto, unsigned flags);
> +int edit_todo_list(struct repository *r, struct replay_opts *opts,
> +		   struct todo_list *todo_list, struct todo_list *new_todo,
> +		   const char *shortrevisions, const char *shortonto,
> +		   unsigned flags);
>  
>  int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo);
>  int todo_list_check_against_backup(struct repository *r,
> +				   struct replay_opts *opts,
>  				   struct todo_list *todo_list);
>  
>  #endif
> diff --git a/sequencer.c b/sequencer.c
> index 2c19846385b..a3154ba3347 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -2573,8 +2573,9 @@ static int check_label_or_ref_arg(enum todo_command command, const char *arg)
>  	return 0;
>  }
>  
> -static int parse_insn_line(struct repository *r, struct todo_item *item,
> -			   const char *buf, const char *bol, char *eol)
> +static int parse_insn_line(struct repository *r, struct replay_opts *opts UNUSED,
> +			   struct todo_item *item, const char *buf,
> +			   const char *bol, char *eol)
>  {
>  	struct object_id commit_oid;
>  	char *end_of_object_name;
> @@ -2708,8 +2709,8 @@ int sequencer_get_last_command(struct repository *r UNUSED, enum replay_action *
>  	return ret;
>  }
>  
> -int todo_list_parse_insn_buffer(struct repository *r, char *buf,
> -				struct todo_list *todo_list)
> +int todo_list_parse_insn_buffer(struct repository *r, struct replay_opts *opts,
> +				char *buf, struct todo_list *todo_list)
>  {
>  	struct todo_item *item;
>  	char *p = buf, *next_p;
> @@ -2727,7 +2728,7 @@ int todo_list_parse_insn_buffer(struct repository *r, char *buf,
>  
>  		item = append_new_todo(todo_list);
>  		item->offset_in_buf = p - todo_list->buf.buf;
> -		if (parse_insn_line(r, item, buf, p, eol)) {
> +		if (parse_insn_line(r, opts, item, buf, p, eol)) {
>  			res = error(_("invalid line %d: %.*s"),
>  				i, (int)(eol - p), p);
>  			item->command = TODO_COMMENT + 1;
> @@ -2875,7 +2876,7 @@ static int read_populate_todo(struct repository *r,
>  	if (strbuf_read_file_or_whine(&todo_list->buf, todo_file) < 0)
>  		return -1;
>  
> -	res = todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list);
> +	res = todo_list_parse_insn_buffer(r, opts, todo_list->buf.buf, todo_list);
>  	if (res) {
>  		if (is_rebase_i(opts))
>  			return error(_("please fix this using "
> @@ -2905,7 +2906,7 @@ static int read_populate_todo(struct repository *r,
>  		struct todo_list done = TODO_LIST_INIT;
>  
>  		if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 &&
> -		    !todo_list_parse_insn_buffer(r, done.buf.buf, &done))
> +		    !todo_list_parse_insn_buffer(r, opts, done.buf.buf, &done))
>  			todo_list->done_nr = count_commands(&done);
>  		else
>  			todo_list->done_nr = 0;
> @@ -5251,7 +5252,8 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
>  			goto release_todo_list;
>  
>  		if (file_exists(rebase_path_dropped())) {
> -			if ((res = todo_list_check_against_backup(r, &todo_list)))
> +			if ((res = todo_list_check_against_backup(r, opts,
> +								  &todo_list)))
>  				goto release_todo_list;
>  
>  			unlink(rebase_path_dropped());
> @@ -6294,7 +6296,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
>  		return error(_("nothing to do"));
>  	}
>  
> -	res = edit_todo_list(r, todo_list, &new_todo, shortrevisions,
> +	res = edit_todo_list(r, opts, todo_list, &new_todo, shortrevisions,
>  			     shortonto, flags);
>  	if (res == -1)
>  		return -1;
> @@ -6322,7 +6324,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
>  	strbuf_release(&buf2);
>  	/* Nothing is done yet, and we're reparsing, so let's reset the count */
>  	new_todo.total_nr = 0;
> -	if (todo_list_parse_insn_buffer(r, new_todo.buf.buf, &new_todo) < 0)
> +	if (todo_list_parse_insn_buffer(r, opts, new_todo.buf.buf, &new_todo) < 0)
>  		BUG("invalid todo list after expanding IDs:\n%s",
>  		    new_todo.buf.buf);
>  
> diff --git a/sequencer.h b/sequencer.h
> index 437eabd38af..33943e5ed28 100644
> --- a/sequencer.h
> +++ b/sequencer.h
> @@ -137,8 +137,8 @@ struct todo_list {
>  	.buf = STRBUF_INIT, \
>  }
>  
> -int todo_list_parse_insn_buffer(struct repository *r, char *buf,
> -				struct todo_list *todo_list);
> +int todo_list_parse_insn_buffer(struct repository *r, struct replay_opts *opts,
> +				char *buf, struct todo_list *todo_list);
>  int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list,
>  			    const char *file, const char *shortrevisions,
>  			    const char *shortonto, int num, unsigned flags);
> -- 
> gitgitgadget
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2024-04-09  4:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-26 10:58 [PATCH] rebase -i: improve error message when picking merge Phillip Wood via GitGitGadget
2024-04-03 13:42 ` phillip.wood123
2024-04-04  6:08   ` Patrick Steinhardt
2024-04-04  6:08 ` Patrick Steinhardt
2024-04-04 15:29   ` phillip.wood123
2024-04-04 19:44 ` Rubén Justo
2024-04-05  9:30   ` phillip.wood123
2024-04-06 14:24     ` Rubén Justo
2024-04-07 13:55       ` phillip.wood123
2024-04-08 14:16 ` [PATCH v2 0/2] " Phillip Wood via GitGitGadget
2024-04-08 14:16   ` [PATCH v2 1/2] rebase -i: pass struct replay_opts to parse_insn_line() Phillip Wood via GitGitGadget
2024-04-09  4:03     ` Patrick Steinhardt [this message]
2024-04-08 14:16   ` [PATCH v2 2/2] rebase -i: improve error message when picking merge Phillip Wood via GitGitGadget
2024-04-08 22:29     ` Junio C Hamano
2024-04-09  4:03       ` Patrick Steinhardt
2024-04-09  5:08         ` Junio C Hamano
2024-04-09  6:04           ` Patrick Steinhardt
2024-04-09 15:04       ` Phillip Wood
2024-04-09 19:56         ` Junio C Hamano
2024-04-12 13:24           ` Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZhS-KktVxRH-Xl3V@tanuki \
    --to=ps@pks.im \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=lists@haller-berlin.de \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=rjusto@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).