git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
From: Duy Nguyen <pclouds@gmail.com>
To: Phillip Wood <phillip.wood@dunelm.org.uk>
Cc: Git Mailing List <git@vger.kernel.org>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Junio C Hamano <gitster@pobox.com>,
	Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH 1/2] commit/reset: try to clean up sequencer state
Date: Mon, 1 Apr 2019 17:09:21 +0700
Message-ID: <CACsJy8D3tH0K8wNLighuNtjUtv3K3TGNMGgx3T5j5sCxok8hbQ@mail.gmail.com> (raw)
In-Reply-To: <20190329163009.493-2-phillip.wood123@gmail.com>

On Fri, Mar 29, 2019 at 11:32 PM Phillip Wood <phillip.wood123@gmail.com> wrote:
>
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> When cherry-picking or reverting a sequence of commits and if the final
> pick/revert has conflicts and the user uses `git commit` to commit the
> conflict resolution and does not run `git cherry-pick --continue` then
> the sequencer state is left behind. This can cause problems later. In my
> case I cherry-picked a sequence of commits the last one of which I
> committed with `git commit` after resolving some conflicts, then a while
> later, on a different branch I aborted a revert which rewound my HEAD to
> the end of the cherry-pick sequence on the previous branch. Avoid this
> potential problem by removing the sequencer state if we're committing or
> resetting the final pick in a sequence.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  branch.c                        |  7 +++++--
>  builtin/commit.c                |  7 +++++--
>  sequencer.c                     | 23 +++++++++++++++++++++++
>  sequencer.h                     |  1 +
>  t/t3507-cherry-pick-conflict.sh | 19 +++++++++++++++++++
>  5 files changed, 53 insertions(+), 4 deletions(-)
>
> diff --git a/branch.c b/branch.c
> index 28b81a7e02..9ed60081c1 100644
> --- a/branch.c
> +++ b/branch.c
> @@ -5,6 +5,7 @@
>  #include "refs.h"
>  #include "refspec.h"
>  #include "remote.h"
> +#include "sequencer.h"
>  #include "commit.h"
>  #include "worktree.h"
>
> @@ -339,8 +340,10 @@ void create_branch(struct repository *r,
>
>  void remove_branch_state(struct repository *r)

This function is also called in git-am, git-rebase and git-checkout.
While the first two should not be affected, git-checkout can be
executed while we're in the middle of a cherry-pick or revert. I guess
that's ok because git-checkout is basically the same as git-reset in
this case?

>  {
> -       unlink(git_path_cherry_pick_head(r));
> -       unlink(git_path_revert_head(r));
> +       if (!unlink(git_path_cherry_pick_head(r)))
> +               sequencer_post_commit_cleanup();
> +       if (!unlink(git_path_revert_head(r)))
> +               sequencer_post_commit_cleanup();
>         unlink(git_path_merge_head(r));
>         unlink(git_path_merge_rr(r));
>         unlink(git_path_merge_msg(r));
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 2986553d5f..422b7d62a5 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1657,8 +1657,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>                 die("%s", err.buf);
>         }
>
> -       unlink(git_path_cherry_pick_head(the_repository));
> -       unlink(git_path_revert_head(the_repository));
> +       if (!unlink(git_path_cherry_pick_head(the_repository)))
> +               sequencer_post_commit_cleanup();
> +       if (!unlink(git_path_revert_head(the_repository)))
> +               sequencer_post_commit_cleanup();
>         unlink(git_path_merge_head(the_repository));
>         unlink(git_path_merge_msg(the_repository));
>         unlink(git_path_merge_mode(the_repository));
> @@ -1678,6 +1680,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>         if (amend && !no_post_rewrite) {
>                 commit_post_rewrite(the_repository, current_head, &oid);
>         }
> +
>         if (!quiet) {
>                 unsigned int flags = 0;
>
> diff --git a/sequencer.c b/sequencer.c
> index 0db410d590..028699209f 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -2220,6 +2220,29 @@ static ssize_t strbuf_read_file_or_whine(struct strbuf *sb, const char *path)
>         return len;
>  }
>
> +void sequencer_post_commit_cleanup(void)
> +{
> +       struct replay_opts opts = REPLAY_OPTS_INIT;
> +       struct strbuf buf = STRBUF_INIT;
> +       const char *eol;
> +       const char *todo_path = git_path_todo_file();
> +
> +       if (strbuf_read_file(&buf, todo_path, 0) < 0) {
> +               if (errno == ENOENT) {
> +                       return;
> +               } else {
> +                       error_errno("unable to open '%s'", todo_path);

_() the string to make it translatable.

> +                       return;
> +               }
> +       }
> +       /* If there is only one line then we are done */
> +       eol = strchr(buf.buf, '\n');
> +       if (!eol || !eol[1])
> +               sequencer_remove_state(&opts);

Should we say something to let the user know cherry-pick/revert is
finished? (unless --quiet is specified)

> +
> +       strbuf_release(&buf);
> +}
> +
>  static int read_populate_todo(struct repository *r,
>                               struct todo_list *todo_list,
>                               struct replay_opts *opts)
-- 
Duy

  parent reply index

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-29 16:30 [PATCH 0/2] A couple of cherry-pick related fixes Phillip Wood
2019-03-29 16:30 ` [PATCH 1/2] commit/reset: try to clean up sequencer state Phillip Wood
2019-04-01  8:28   ` Junio C Hamano
2019-04-08 14:15     ` Phillip Wood
2019-04-01 10:09   ` Duy Nguyen [this message]
2019-04-08 15:47     ` Phillip Wood
2019-03-29 16:30 ` [PATCH 2/2] fix cherry-pick/revert status after commit Phillip Wood
2019-04-01  8:34   ` Junio C Hamano
2019-04-08 14:17     ` Phillip Wood
2019-04-16 10:18 ` [PATCH v2 0/2] A couple of cherry-pick related fixes Phillip Wood
2019-04-16 10:18   ` [PATCH v2 1/2] commit/reset: try to clean up sequencer state Phillip Wood
2019-04-17  7:04     ` Junio C Hamano
2019-04-17 12:26       ` Johannes Schindelin
2019-04-17 15:04         ` Phillip Wood
2019-04-16 10:18   ` [PATCH v2 2/2] fix cherry-pick/revert status after commit Phillip Wood

Reply instructions:

You may reply publically 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=CACsJy8D3tH0K8wNLighuNtjUtv3K3TGNMGgx3T5j5sCxok8hbQ@mail.gmail.com \
    --to=pclouds@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=newren@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    /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

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox