git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH 1/7] built-in add -p: prepare for patch modes other than "stage"
Date: Tue, 17 Dec 2019 11:37:36 -0800	[thread overview]
Message-ID: <xmqq36dihhfj.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <8f6139f94debb9b3bfb9c9e8b8e18e3c2fb46a06.1576579264.git.gitgitgadget@gmail.com> (Johannes Schindelin via GitGitGadget's message of "Tue, 17 Dec 2019 10:40:58 +0000")

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> +
> +enum add_p_mode {
> +	ADD_P_STAGE,
> +};

Nice to see a trailing comma here ;-)

> +int run_add_p(struct repository *r, enum add_p_mode mode,
> +	      const char *revision, const struct pathspec *ps);

This makes readers wonder if "const struct object_id *" is more
appropriate; "const char *revision" that holds human-readable name
is better when the internal machinery uses it for reporting, so that
may be what is going on here (so is the new field in add_p_state
structure).

>  #endif
> diff --git a/add-patch.c b/add-patch.c
> index 2c46fe5b33..8a691f07da 100644
> --- a/add-patch.c
> +++ b/add-patch.c
> @@ -11,10 +11,33 @@ enum prompt_mode_type {
>  	PROMPT_MODE_CHANGE = 0, PROMPT_DELETION, PROMPT_HUNK
>  };
>  
> -static const char *prompt_mode[] = {
> -	N_("Stage mode change [y,n,a,q,d%s,?]? "),
> -	N_("Stage deletion [y,n,a,q,d%s,?]? "),
> -	N_("Stage this hunk [y,n,a,q,d%s,?]? ")
> +struct patch_mode {
> +	const char *diff[4], *apply[4], *apply_check[4];

Hardcoded "4" and not-quite descriptive names puzzle readers at the
first glance.  Let's read on to see if they need any further
improvement.

> +	unsigned is_reverse:1, apply_for_checkout:1;
> +	const char *prompt_mode[PROMPT_HUNK + 1];

This relies on the enum value assignment (or listing) order to
ensure that PROMPT_HUNK always comes at the end.  Perhaps that
deserves a comment before "enum prompt_mode_type", e.g.

	+/* Keep PROMPT_HUNK at the end */
	 enum prompt_mode_type {
	 	PROMPT_MODE_CHANGE = 0, ...
	 };

> +	const char *edit_hunk_hint, *help_patch_text;
> +};
> +
> +static struct patch_mode patch_mode_stage = {
> +	.diff = { "diff-files", NULL },

Nice to see designated initializers used ;-)

Mental note: the "diff" field is (probably) for "the command line
to be used to generate the patch"

> +	.apply = { "--cached", NULL },
> +	.apply_check = { "--cached", NULL },

Mental note: these "apply" and "apply_check" fields are (probably)
not for the command line; unlike the "diff" field, these only have
arguments.

Mental note: if the three field names become confusing, perhaps we
can clarify them by either (1) calling diff as diff_cmd[], or (2)
calling the other as apply_args[] and apply_check_args[], or (3)
rename both.

> +	.is_reverse = 0,

Wouldn't it be sufficient to apply the default initialization, just
like it is done for apply_for_checkout bitfield?

> @@ -1310,6 +1345,9 @@ int run_add_p(struct repository *r, const struct pathspec *ps)
>  
>  	init_add_i_state(&s.s, r);
>  
> +	s.mode = &patch_mode_stage;
> +	s.revision = revision;

The phrase "mode_stage" may become problematic, as other modes that
will be introduced, like "reset", "checkout" all will stage
different contents to the index.  The only mode the machinery knows
at this point in the series is how "add" stages contents to the
index, so "patch_mode_add" might turn out to be a better choice of
the phrase as we read the series along.  We'll see.

> +		if (!strcmp(patch_mode, "--patch"))
> +			mode = ADD_P_STAGE;

The same comment applies to this enum token.

Thanks.

  reply	other threads:[~2019-12-17 19:37 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-17 10:40 [PATCH 0/7] stash/reset/checkout -p: optionally use the add --patch backend written in pure C Johannes Schindelin via GitGitGadget
2019-12-17 10:40 ` [PATCH 1/7] built-in add -p: prepare for patch modes other than "stage" Johannes Schindelin via GitGitGadget
2019-12-17 19:37   ` Junio C Hamano [this message]
2019-12-21 21:19     ` Johannes Schindelin
2019-12-17 10:40 ` [PATCH 2/7] built-in add -p: implement the "stash" and "reset" patch modes Johannes Schindelin via GitGitGadget
2019-12-17 20:12   ` Junio C Hamano
2019-12-21 21:23     ` Johannes Schindelin
2019-12-17 10:41 ` [PATCH 3/7] legacy stash -p: respect the add.interactive.usebuiltin setting Johannes Schindelin via GitGitGadget
2019-12-17 10:41 ` [PATCH 4/7] built-in stash: use the built-in `git add -p` if so configured Johannes Schindelin via GitGitGadget
2019-12-17 20:19   ` Junio C Hamano
2019-12-21 21:26     ` Johannes Schindelin
2019-12-17 10:41 ` [PATCH 5/7] built-in add -p: implement the "checkout" patch modes Johannes Schindelin via GitGitGadget
2019-12-17 10:41 ` [PATCH 6/7] built-in add -p: implement the "worktree" " Johannes Schindelin via GitGitGadget
2019-12-17 10:41 ` [PATCH 7/7] commit --interactive: make it work with the built-in `add -i` Johannes Schindelin via GitGitGadget
2019-12-17 20:23 ` [PATCH 0/7] stash/reset/checkout -p: optionally use the add --patch backend written in pure C Junio C Hamano
2019-12-21 21:57 ` [PATCH v2 " Johannes Schindelin via GitGitGadget
2019-12-21 21:57   ` [PATCH v2 1/7] built-in add -p: prepare for patch modes other than "stage" Johannes Schindelin via GitGitGadget
2019-12-21 21:57   ` [PATCH v2 2/7] built-in add -p: implement the "stash" and "reset" patch modes Johannes Schindelin via GitGitGadget
2019-12-21 21:57   ` [PATCH v2 3/7] legacy stash -p: respect the add.interactive.usebuiltin setting Johannes Schindelin via GitGitGadget
2019-12-21 21:57   ` [PATCH v2 4/7] built-in stash: use the built-in `git add -p` if so configured Johannes Schindelin via GitGitGadget
2019-12-21 21:57   ` [PATCH v2 5/7] built-in add -p: implement the "checkout" patch modes Johannes Schindelin via GitGitGadget
2019-12-21 21:57   ` [PATCH v2 6/7] built-in add -p: implement the "worktree" " Johannes Schindelin via GitGitGadget
2019-12-21 21:57   ` [PATCH v2 7/7] commit --interactive: make it work with the built-in `add -i` Johannes Schindelin via GitGitGadget

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=xmqq36dihhfj.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=johannes.schindelin@gmx.de \
    /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).