git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Rohit Ashiwal <rohit.ashiwal265@gmail.com>
Cc: git@vger.kernel.org, newren@gmail.com, t.gummerer@gmail.com,
	phillip.wood123@gmail.com
Subject: Re: [GSoC][PATCH v3 2/3] cherry-pick/revert: add --skip option
Date: Thu, 13 Jun 2019 10:56:26 -0700	[thread overview]
Message-ID: <xmqqa7elwer9.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20190613040504.32317-3-rohit.ashiwal265@gmail.com> (Rohit Ashiwal's message of "Thu, 13 Jun 2019 09:35:03 +0530")

Rohit Ashiwal <rohit.ashiwal265@gmail.com> writes:

> diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt
> index 754b16ce0c..955880ab88 100644
> --- a/Documentation/git-cherry-pick.txt
> +++ b/Documentation/git-cherry-pick.txt
> @@ -10,9 +10,7 @@ SYNOPSIS
>  [verse]
>  'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff]
>  		  [-S[<keyid>]] <commit>...
> -'git cherry-pick' --continue
> -'git cherry-pick' --quit
> -'git cherry-pick' --abort
> +'git cherry-pick' --continue | --skip | --abort | --quit

Is this correct, or do we need to enclose these choices inside (),
i.e.

	'git cherry-pick' ( --continue | --skip | --abort | --quit )

?  

> -static int rollback_single_pick(struct repository *r)
> +static int rollback_single_pick(struct repository *r, unsigned int is_skip)
>  {
>  	struct object_id head_oid;
>  
>  	if (!file_exists(git_path_cherry_pick_head(r)) &&
> -	    !file_exists(git_path_revert_head(r)))
> +	    !file_exists(git_path_revert_head(r)) && !is_skip)
>  		return error(_("no cherry-pick or revert in progress"));
>  	if (read_ref_full("HEAD", 0, &head_oid, NULL))
>  		return error(_("cannot resolve HEAD"));
> -	if (is_null_oid(&head_oid))
> +	if (is_null_oid(&head_oid) && !is_skip)
>  		return error(_("cannot abort from a branch yet to be born"));
>  	return reset_for_rollback(&head_oid);
>  }

It is unclear *why* the function (and more importantly, its callers)
would want to omit two sanity checks when is_skip is in effect.

Before this patch introduced such conditional behaviour, the name
was descriptive enough for this single-purpose function that is a
file-local helper, but it is no longer a case.  The function needs a
bit of commentary before it.

When &&-chaining error checks that are optional, check the condition
that makes the error checks optional first, i.e.

	if (!is_skip &&
		!file_exists(...) && !file_exists(...))
		return error(...);

The same comment applies to the "do not barf by checking is-null-oid
under is-skip mode, as that is a sign that we are on an unborn
branch and reset-for-rollback knows how to handle it now".

It may even be a good idea to group the checks that are guarded by
the condition for readability, i.e.

	if (!is_skip &&
		(!file_exists(...) && !file_exists(...)))
		return error(...);

> +int sequencer_skip(struct repository *r, struct replay_opts *opts)
> +{
> +	enum replay_action action = -1;
> +	sequencer_get_last_command(r, &action);
> +
> +	switch (opts->action) {
> +	case REPLAY_REVERT:
> +		if (!file_exists(git_path_revert_head(r))) {
> +			if (action == REPLAY_REVERT) {
> +				if (!rollback_is_safe())
> +					goto give_advice;
> +				else
> +					break;
> +			}
> +			return error(_("no revert in progress"));
> +		}

This part probably deserves a bit of in-code comment.  

    The Git subcommand (i.e. opts->action) tells us that we are
    asked to "git revert --skip".  When REVERT_HEAD is not there, we
    look at the last command of the sequencer state and make sure it
    is 'revert'; all other cases we barf.

That much we can read from the code.  But what are "all other cases"?
Do we cover a single-revert case (i.e. "git revert <commit>" got
conflict and the user is saying "git revert --skip")?  Was the user
in the middle of "git rebase -i" and the last command before we gave
the control back was 'pick'?

> +		break;
> +	case REPLAY_PICK:
> +		if (!file_exists(git_path_cherry_pick_head(r))) {
> +			if (action == REPLAY_PICK) {
> +				if (!rollback_is_safe())
> +					goto give_advice;
> +				else
> +					break;
> +			}
> +			return error(_("no cherry-pick in progress"));
> +		}
> +		break;
> +	default:
> +		BUG("the control must not reach here");
> +	}
> +
> +	if (rollback_single_pick(r, 1))
> +		return error(_("failed to skip the commit"));

And this takes us back to the previous comment.  By passing '1'
here, this caller is asking the callee to omit certain sanity check
the original version of the callee used to do.  What makes it an
appropriate thing to do so here?  "Because we reach at this point
under such and such condition, we would never have CHERRY_PICK_HEAD
or REVERT_HEAD---we do not want it to barf" is a good answer (and
no, do not merely give answer to me in your response---write the
answer as in-code comment to help future readers of the code).

"Because when we come here, sometimes the XXX_HEAD must exist but
some other times XXX_HEAD may not exist, so insisting that either
exists would make the function fail" is *NOT* a good answer, on the
other hand.  Somebody must still check that the necessary file
exists when it must exist.

Thanks.

  reply	other threads:[~2019-06-13 17:56 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-08 19:19 [GSoC][PATCH 0/3] Teach cherry-pick/revert to skip commits Rohit Ashiwal
2019-06-08 19:19 ` [GSoC][PATCH 1/3] sequencer: add advice for revert Rohit Ashiwal
2019-06-09 17:52   ` Phillip Wood
2019-06-10  5:13     ` Rohit Ashiwal
2019-06-10 10:39       ` Phillip Wood
2019-06-10 13:25         ` Rohit Ashiwal
2019-06-10 17:46           ` Phillip Wood
2019-06-10 16:34         ` Junio C Hamano
2019-06-08 19:19 ` [GSoC][PATCH 2/3] cherry-pick/revert: add --skip option Rohit Ashiwal
2019-06-09  8:37   ` Thomas Gummerer
2019-06-09 18:01   ` Phillip Wood
2019-06-10  5:57     ` Rohit Ashiwal
2019-06-10 10:40       ` Phillip Wood
2019-06-10 13:43         ` Rohit Ashiwal
2019-06-10 17:47           ` Phillip Wood
2019-06-08 19:19 ` [GSoC][PATCH 3/3] cherry-pick/revert: update hints Rohit Ashiwal
2019-06-09  8:42   ` Thomas Gummerer
2019-06-09 18:03   ` Phillip Wood
2019-06-10  5:28     ` Rohit Ashiwal
2019-06-10 10:40       ` Phillip Wood
2019-06-10 13:33         ` Rohit Ashiwal
2019-06-10 17:47           ` Phillip Wood
2019-06-09  9:02 ` [GSoC][PATCH 0/3] Teach cherry-pick/revert to skip commits Thomas Gummerer
2019-06-09 10:06   ` Rohit Ashiwal
2019-06-09 20:00     ` Thomas Gummerer
2019-06-11  7:31 ` [GSoC][PATCH v2 " Rohit Ashiwal
2019-06-11  7:31   ` [GSoC][PATCH v2 1/3] sequencer: add advice for revert Rohit Ashiwal
2019-06-11 21:25     ` Junio C Hamano
2019-06-11  7:31   ` [GSoC][PATCH v2 2/3] cherry-pick/revert: add --skip option Rohit Ashiwal
2019-06-12 13:31     ` Phillip Wood
2019-06-12 18:11       ` Junio C Hamano
2019-06-12 18:57         ` Phillip Wood
2019-06-11  7:31   ` [GSoC][PATCH v2 3/3] cherry-pick/revert: advise using --skip Rohit Ashiwal
2019-06-12 15:16     ` Phillip Wood
2019-06-13  4:05 ` [GSoC][PATCH v3 0/3] Teach cherry-pick/revert to skip commits Rohit Ashiwal
2019-06-13  4:05   ` [GSoC][PATCH v3 1/3] sequencer: add advice for revert Rohit Ashiwal
2019-06-13 17:45     ` Phillip Wood
2019-06-13 19:21       ` Martin Ågren
2019-06-13 20:59         ` Junio C Hamano
2019-06-14  3:44         ` Rohit Ashiwal
2019-06-14  3:43       ` Rohit Ashiwal
2019-06-13  4:05   ` [GSoC][PATCH v3 2/3] cherry-pick/revert: add --skip option Rohit Ashiwal
2019-06-13 17:56     ` Junio C Hamano [this message]
2019-06-13 19:57       ` Junio C Hamano
2019-06-14  3:48         ` Rohit Ashiwal
2019-06-14  3:45       ` Rohit Ashiwal
2019-06-14 15:58         ` Junio C Hamano
2019-06-16  7:03       ` Rohit Ashiwal
2019-06-13 17:59     ` Phillip Wood
2019-06-13  4:05   ` [GSoC][PATCH v3 3/3] cherry-pick/revert: advise using --skip Rohit Ashiwal
2019-06-16  8:20 ` [GSoC][PATCH v4 0/4] [GSoC][PATCH 0/3] Teach cherry-pick/revert to skip commits Rohit Ashiwal
2019-06-16  8:20   ` [GSoC][PATCH v4 1/4] sequencer: add advice for revert Rohit Ashiwal
2019-06-17  5:51     ` Thomas Gummerer
2019-06-16  8:20   ` [GSoC][PATCH v4 2/4] sequencer: rename reset_for_rollback to reset_merge Rohit Ashiwal
2019-06-16  8:20   ` [GSoC][PATCH v4 3/4] cherry-pick/revert: add --skip option Rohit Ashiwal
2019-06-17  8:30     ` Thomas Gummerer
2019-06-16  8:20   ` [GSoC][PATCH v4 4/4] cherry-pick/revert: advise using --skip Rohit Ashiwal
2019-06-17  8:39   ` [GSoC][PATCH v4 0/4] [GSoC][PATCH 0/3] Teach cherry-pick/revert to skip commits Thomas Gummerer
2019-06-18 17:06 ` [GSoC][PATCH v5 0/5] " Rohit Ashiwal
2019-06-18 17:06   ` [GSoC][PATCH v5 1/5] sequencer: add advice for revert Rohit Ashiwal
2019-06-18 17:06   ` [GSoC][PATCH v5 2/5] sequencer: rename reset_for_rollback to reset_merge Rohit Ashiwal
2019-06-18 17:06   ` [GSoC][PATCH v5 3/5] sequencer: use argv_array in reset_merge Rohit Ashiwal
2019-06-18 17:06   ` [GSoC][PATCH v5 4/5] cherry-pick/revert: add --skip option Rohit Ashiwal
2019-06-20  3:40     ` Junio C Hamano
2019-06-20  9:46       ` Rohit Ashiwal
2019-06-20  9:57       ` Phillip Wood
2019-06-20 20:09         ` Junio C Hamano
2019-06-20 10:02     ` Phillip Wood
2019-06-20 10:34       ` Rohit Ashiwal
2019-06-20 11:42         ` Phillip Wood
2019-06-21  7:47           ` Rohit Ashiwal
2019-06-18 17:06   ` [GSoC][PATCH v5 5/5] cherry-pick/revert: advise using --skip Rohit Ashiwal
2019-06-21  9:17 ` [GSoC][PATCH v6 0/5] Teach cherry-pick/revert to skip commits Rohit Ashiwal
2019-06-21  9:17   ` [GSoC][PATCH v6 1/5] sequencer: add advice for revert Rohit Ashiwal
2019-06-21  9:17   ` [GSoC][PATCH v6 2/5] sequencer: rename reset_for_rollback to reset_merge Rohit Ashiwal
2019-06-21  9:17   ` [GSoC][PATCH v6 3/5] sequencer: use argv_array in reset_merge Rohit Ashiwal
2019-06-21  9:17   ` [GSoC][PATCH v6 4/5] cherry-pick/revert: add --skip option Rohit Ashiwal
2019-06-21  9:18   ` [GSoC][PATCH v6 5/5] cherry-pick/revert: advise using --skip Rohit Ashiwal
2019-06-21 19:09   ` [GSoC][PATCH v6 0/5] Teach cherry-pick/revert to skip commits Junio C Hamano
2019-06-23 20:03 ` [GSoC][PATCH v7 0/6] " Rohit Ashiwal
2019-06-23 20:03   ` [GSoC][PATCH v7 1/6] advice: add sequencerInUse config variable Rohit Ashiwal
2019-06-25  9:18     ` Thomas Gummerer
2019-06-23 20:03   ` [GSoC][PATCH v7 2/6] sequencer: add advice for revert Rohit Ashiwal
2019-06-29 14:05     ` Phillip Wood
2019-06-23 20:03   ` [GSoC][PATCH v7 3/6] sequencer: rename reset_for_rollback to reset_merge Rohit Ashiwal
2019-06-23 20:03   ` [GSoC][PATCH v7 4/6] sequencer: use argv_array in reset_merge Rohit Ashiwal
2019-06-23 20:03   ` [GSoC][PATCH v7 5/6] cherry-pick/revert: add --skip option Rohit Ashiwal
2019-06-23 20:03   ` [GSoC][PATCH v7 6/6] cherry-pick/revert: advise using --skip Rohit Ashiwal
2019-07-02  9:11 ` [GSoC][PATCH v8 0/5] Teach cherry-pick/revert to skip commits Rohit Ashiwal
2019-07-02  9:11   ` [GSoC][PATCH v8 1/5] sequencer: add advice for revert Rohit Ashiwal
2019-07-02  9:11   ` [GSoC][PATCH v8 2/5] sequencer: rename reset_for_rollback to reset_merge Rohit Ashiwal
2019-07-02  9:11   ` [GSoC][PATCH v8 3/5] sequencer: use argv_array in reset_merge Rohit Ashiwal
2019-07-02  9:11   ` [GSoC][PATCH v8 4/5] cherry-pick/revert: add --skip option Rohit Ashiwal
2019-07-02  9:11   ` [GSoC][PATCH v8 5/5] cherry-pick/revert: advise using --skip Rohit Ashiwal
2019-07-02 15:26   ` [GSoC][PATCH v8 0/5] Teach cherry-pick/revert to skip commits 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=xmqqa7elwer9.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=newren@gmail.com \
    --cc=phillip.wood123@gmail.com \
    --cc=rohit.ashiwal265@gmail.com \
    --cc=t.gummerer@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).