* [PATCH 0/1] revert/cherry-pick: add --show-current-patch option
@ 2023-12-18 12:10 Michael Lohmann
2023-12-18 12:10 ` [PATCH 1/1] " Michael Lohmann
2023-12-18 16:42 ` [PATCH 0/1] " Phillip Wood
0 siblings, 2 replies; 5+ messages in thread
From: Michael Lohmann @ 2023-12-18 12:10 UTC (permalink / raw)
To: git; +Cc: Michael Lohmann, Elijah Newren
Hi,
I am a lead developer of a small team and quite often I have to
cherry-pick commits (and sometimes also revert them). When
cherry-picking multiple commits at once and there is a merge conflict it
sometimes can be hard to understand what the current patch is trying to
do in order to resolve the conflict properly. With `rebase` there is
`--show-current-patch` and since that is quite helpful I would suggest
to also add this flag also to `cherry-pick` and `revert`.
Since this is my first contribution to git I am not exactly sure where
the best place for this functionality is. From my initial understanding
there are two places where to put the actual invocation of the `show`:
- Duplicate the code (with the needed adaptations) of builtin/rebase.c
in builtin/revert.c
- Create a central function that shows the respective `*_HEAD` depending
on the current `action`.
In this first draft I went with the second option, since I felt that it
reduces code duplication and the sequencer already has the action enum
with exactly those three cases. On the other hand I don’t really have a
good understanding of the role that this `sequencer` should play and if
this adds additional coupling that is unwanted. My current impression
is, that this would be the right place, since this looks to be the core
of the commands where a user can apply a sequence of commits and in my
opinion even if additional actions would be added, they could also fail
and so it would be good to add the `--show-current-patch` option to that
one as well.
Side note: my only C(++) experience was ~10 years ago and only for a
single university course, so my perspective is much more from a general
architecture point of view than based on any C experience, let alone in
this code base and so I would be very grateful for criticism!
Side note: The check for the `REBASE_HEAD` would not be necessary, since
that is already taken care of in the builtin/rebase.c before.
Nevertheless I opted for this check, because I would much rather require
the same preconditions no matter from where I call this function. The
whole argument parsing / option struct are very different between rebase
and revert. Maybe it would make sense to align them a bit further?
Initial observations: `rebase_options->type` is functionally similar to
`replay_opts->action` (as in "what general action am I performing? -
interactive rebase / cherry-pick / revert / ...") whereas
`rebase_options->action` is not part of the `replay_opts` struct at all.
Instead the role is taken over in builtin/revert.c by `int cmd = 0;`.
I am preparing a patch converting this to an enum, so that there are
no random chars that have to be kept in sync manually in different
places, or is that a design decision?
I looked through the mailing list archive and did not find anything
related on this topic. The only slightly related thread I could find was
in [1] by Elijah Newren and that one was talking about a separate
possible feature and how to get certain information if CHERRY_PICK_HEAD
and REVERT_HEAD were to be replaced by a different construct. I hope I
did not miss something...
Cheers
Michael
[1]:
https://lore.kernel.org/git/CABPp-BGd-W8T7EsvKYyjdi3=mfSTJ8zM-uzVsFnh1AWyV2wEzQ@mail.gmail.com
Michael Lohmann (1):
revert/cherry-pick: add --show-current-patch option
Documentation/git-cherry-pick.txt | 2 +-
Documentation/git-revert.txt | 2 +-
Documentation/sequencer.txt | 5 +++++
builtin/rebase.c | 7 ++----
builtin/revert.c | 9 ++++++--
contrib/completion/git-completion.bash | 2 +-
sequencer.c | 24 +++++++++++++++++++++
sequencer.h | 2 ++
t/t3507-cherry-pick-conflict.sh | 30 ++++++++++++++++++++++++++
9 files changed, 73 insertions(+), 10 deletions(-)
--
2.43.0.77.gff6ea8bb74
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/1] revert/cherry-pick: add --show-current-patch option
2023-12-18 12:10 [PATCH 0/1] revert/cherry-pick: add --show-current-patch option Michael Lohmann
@ 2023-12-18 12:10 ` Michael Lohmann
2023-12-18 16:42 ` [PATCH 0/1] " Phillip Wood
1 sibling, 0 replies; 5+ messages in thread
From: Michael Lohmann @ 2023-12-18 12:10 UTC (permalink / raw)
To: git; +Cc: Michael Lohmann, Elijah Newren
This aligns the interface to the rebase one and allows for an easier way
of figuring out how to resolve conflicts if commits fail to apply
(especially when reverting/cherry-picking multiple commits at the same
time)
Signed-off-by: Michael Lohmann <mi.al.lohmann@gmail.com>
---
Documentation/git-cherry-pick.txt | 2 +-
Documentation/git-revert.txt | 2 +-
Documentation/sequencer.txt | 5 +++++
builtin/rebase.c | 7 ++----
builtin/revert.c | 9 ++++++--
contrib/completion/git-completion.bash | 2 +-
sequencer.c | 24 +++++++++++++++++++++
sequencer.h | 2 ++
t/t3507-cherry-pick-conflict.sh | 30 ++++++++++++++++++++++++++
9 files changed, 73 insertions(+), 10 deletions(-)
diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt
index fdcad3d200..af41903fe7 100644
--- a/Documentation/git-cherry-pick.txt
+++ b/Documentation/git-cherry-pick.txt
@@ -10,7 +10,7 @@ SYNOPSIS
[verse]
'git cherry-pick' [--edit] [-n] [-m <parent-number>] [-s] [-x] [--ff]
[-S[<keyid>]] <commit>...
-'git cherry-pick' (--continue | --skip | --abort | --quit)
+'git cherry-pick' (--continue | --skip | --abort | --quit | --show-current-patch)
DESCRIPTION
-----------
diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt
index cbe0208834..5bd2ecf35a 100644
--- a/Documentation/git-revert.txt
+++ b/Documentation/git-revert.txt
@@ -9,7 +9,7 @@ SYNOPSIS
--------
[verse]
'git revert' [--[no-]edit] [-n] [-m <parent-number>] [-s] [-S[<keyid>]] <commit>...
-'git revert' (--continue | --skip | --abort | --quit)
+'git revert' (--continue | --skip | --abort | --quit | --show-current-patch)
DESCRIPTION
-----------
diff --git a/Documentation/sequencer.txt b/Documentation/sequencer.txt
index 3bceb56474..e9394761bc 100644
--- a/Documentation/sequencer.txt
+++ b/Documentation/sequencer.txt
@@ -12,5 +12,10 @@
to clear the sequencer state after a failed cherry-pick or
revert.
+--show-current-patch::
+ Show the current patch when a revert or cherry-pick is
+ stopped because of conflicts. This is the equivalent of
+ `git show REVERT_HEAD` or `git show CHERRY_PICK_HEAD`.
+
--abort::
Cancel the operation and return to the pre-sequence state.
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 9f8192e0a5..8ad3cf3e90 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -360,12 +360,9 @@ static int run_sequencer_rebase(struct rebase_options *opts)
ret = edit_todo_file(flags);
break;
case ACTION_SHOW_CURRENT_PATCH: {
- struct child_process cmd = CHILD_PROCESS_INIT;
-
- cmd.git_cmd = 1;
- strvec_pushl(&cmd.args, "show", "REBASE_HEAD", "--", NULL);
- ret = run_command(&cmd);
+ struct replay_opts replay_opts = get_replay_opts(opts);
+ ret = sequencer_show_current_patch(the_repository, &replay_opts);
break;
}
default:
diff --git a/builtin/revert.c b/builtin/revert.c
index e6f9a1ad26..cbcd9fdc23 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -24,14 +24,14 @@
static const char * const revert_usage[] = {
N_("git revert [--[no-]edit] [-n] [-m <parent-number>] [-s] [-S[<keyid>]] <commit>..."),
- N_("git revert (--continue | --skip | --abort | --quit)"),
+ N_("git revert (--continue | --skip | --abort | --quit | --show-current-patch)"),
NULL
};
static const char * const cherry_pick_usage[] = {
N_("git cherry-pick [--edit] [-n] [-m <parent-number>] [-s] [-x] [--ff]\n"
" [-S[<keyid>]] <commit>..."),
- N_("git cherry-pick (--continue | --skip | --abort | --quit)"),
+ N_("git cherry-pick (--continue | --skip | --abort | --quit | --show-current-patch)"),
NULL
};
@@ -93,6 +93,7 @@ static int run_sequencer(int argc, const char **argv, const char *prefix,
OPT_CMDMODE(0, "continue", &cmd, N_("resume revert or cherry-pick sequence"), 'c'),
OPT_CMDMODE(0, "abort", &cmd, N_("cancel revert or cherry-pick sequence"), 'a'),
OPT_CMDMODE(0, "skip", &cmd, N_("skip current commit and continue"), 's'),
+ OPT_CMDMODE(0, "show-current-patch", &cmd, N_("show the patch file being reverted or cherry-picked"), 'p'),
OPT_CLEANUP(&cleanup_arg),
OPT_BOOL('n', "no-commit", &opts->no_commit, N_("don't automatically commit")),
OPT_BOOL('e', "edit", &opts->edit, N_("edit the commit message")),
@@ -154,6 +155,8 @@ static int run_sequencer(int argc, const char **argv, const char *prefix,
this_operation = "--continue";
else if (cmd == 's')
this_operation = "--skip";
+ else if (cmd == 'p')
+ this_operation = "--show-current-patch";
else {
assert(cmd == 'a');
this_operation = "--abort";
@@ -224,6 +227,8 @@ static int run_sequencer(int argc, const char **argv, const char *prefix,
return sequencer_rollback(the_repository, opts);
if (cmd == 's')
return sequencer_skip(the_repository, opts);
+ if (cmd == 'p')
+ return sequencer_show_current_patch(the_repository, opts);
return sequencer_pick_revisions(the_repository, opts);
}
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 13a39ebd2e..b740b7d48c 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1618,7 +1618,7 @@ _git_checkout ()
esac
}
-__git_sequencer_inprogress_options="--continue --quit --abort --skip"
+__git_sequencer_inprogress_options="--continue --quit --abort --skip --show-current-patch"
__git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
diff --git a/sequencer.c b/sequencer.c
index d584cac8ed..3f6f9ad75c 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3417,6 +3417,30 @@ int sequencer_skip(struct repository *r, struct replay_opts *opts)
return -1;
}
+int sequencer_show_current_patch(struct repository *r, struct replay_opts *opts)
+{
+ struct child_process cmd = CHILD_PROCESS_INIT;
+ cmd.git_cmd = 1;
+ switch (opts->action) {
+ case REPLAY_REVERT:
+ if (!refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD"))
+ die(_("No revert in progress?"));
+ strvec_pushl(&cmd.args, "show", "REVERT_HEAD", "--", NULL);
+ break;
+ case REPLAY_PICK:
+ if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD"))
+ die(_("No cherry-pick in progress?"));
+ strvec_pushl(&cmd.args, "show", "CHERRY_PICK_HEAD", "--", NULL);
+ break;
+ case REPLAY_INTERACTIVE_REBASE:
+ if (!refs_ref_exists(get_main_ref_store(r), "REBASE_HEAD"))
+ die(_("No rebase in progress?"));
+ strvec_pushl(&cmd.args, "show", "REBASE_HEAD", "--", NULL);
+ break;
+ }
+ return run_command(&cmd);
+}
+
static int save_todo(struct todo_list *todo_list, struct replay_opts *opts,
int reschedule)
{
diff --git a/sequencer.h b/sequencer.h
index 913a0f652d..e20cb8bc56 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -162,6 +162,8 @@ int sequencer_pick_revisions(struct repository *repo,
struct replay_opts *opts);
int sequencer_continue(struct repository *repo, struct replay_opts *opts);
int sequencer_rollback(struct repository *repo, struct replay_opts *opts);
+int sequencer_show_current_patch(struct repository *repo,
+ struct replay_opts *opts);
int sequencer_skip(struct repository *repo, struct replay_opts *opts);
void replay_opts_release(struct replay_opts *opts);
int sequencer_remove_state(struct replay_opts *opts);
diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh
index c88d597b12..4f50d287a6 100755
--- a/t/t3507-cherry-pick-conflict.sh
+++ b/t/t3507-cherry-pick-conflict.sh
@@ -566,6 +566,36 @@ test_expect_success 'cherry-pick preserves sparse-checkout' '
test_grep ! "Changes not staged for commit:" actual
'
+test_expect_success 'cherry-pick --show-current-patch fails if no cherry-pick in progress' '
+ pristine_detach initial &&
+ test_must_fail git cherry-pick --show-current-patch
+'
+
+test_expect_success 'cherry-pick --show-current-patch describes patch that failed to apply' '
+ test_when_finished "git cherry-pick --abort || :" &&
+ pristine_detach initial &&
+ git show picked >expected &&
+
+ test_must_fail git cherry-pick picked &&
+
+ git cherry-pick --show-current-patch >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'revert --show-current-patch fails if no revert in progress' '
+ pristine_detach initial &&
+ test_must_fail git revert --show-current-patch
+'
+
+test_expect_success 'revert --show-current-patch describes patch that failed to apply' '
+ test_when_finished "git revert --abort || :" &&
+ pristine_detach initial &&
+ git show picked >expected &&
+ test_must_fail git revert picked &&
+ git revert --show-current-patch >actual &&
+ test_cmp expected actual
+'
+
test_expect_success 'cherry-pick --continue remembers --keep-redundant-commits' '
test_when_finished "git cherry-pick --abort || :" &&
pristine_detach initial &&
--
2.43.0.77.gff6ea8bb74
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/1] revert/cherry-pick: add --show-current-patch option
2023-12-18 12:10 [PATCH 0/1] revert/cherry-pick: add --show-current-patch option Michael Lohmann
2023-12-18 12:10 ` [PATCH 1/1] " Michael Lohmann
@ 2023-12-18 16:42 ` Phillip Wood
2023-12-20 6:51 ` Michael Lohmann
1 sibling, 1 reply; 5+ messages in thread
From: Phillip Wood @ 2023-12-18 16:42 UTC (permalink / raw)
To: Michael Lohmann, git; +Cc: Michael Lohmann, Elijah Newren
Hi Michael
On 18/12/2023 12:10, Michael Lohmann wrote:
> Hi,
> I am a lead developer of a small team and quite often I have to
> cherry-pick commits (and sometimes also revert them). When
> cherry-picking multiple commits at once and there is a merge conflict it
> sometimes can be hard to understand what the current patch is trying to
> do in order to resolve the conflict properly. With `rebase` there is
> `--show-current-patch` and since that is quite helpful I would suggest
> to also add this flag also to `cherry-pick` and `revert`.
Thanks for bringing this up I agree it can be very helpful to look at
the original commit when resolving cherry-pick and revert conflicts. I'm
in two minds about this change though - I wonder if it'd be better to
improve the documentation for CHERRY_PICK_HEAD and REVERT_HEAD and tell
users to run "git show CHERRY_PICK_HEAD" instead. I think the main
reason we have a "--show-current-patch" option for "rebase" is that
there are two different implementations of that command and the
patched-based one of them does not support REBASE_HEAD. That reasoning
does not apply to "cherry-pick" and "revert" and "--show-current-patch"
suggests a patch-based implementation which is also not the case for
these commands.
Best Wishes
Phillip
> Since this is my first contribution to git I am not exactly sure where
> the best place for this functionality is. From my initial understanding
> there are two places where to put the actual invocation of the `show`:
> - Duplicate the code (with the needed adaptations) of builtin/rebase.c
> in builtin/revert.c
> - Create a central function that shows the respective `*_HEAD` depending
> on the current `action`.
>
> In this first draft I went with the second option, since I felt that it
> reduces code duplication and the sequencer already has the action enum
> with exactly those three cases. On the other hand I don’t really have a
> good understanding of the role that this `sequencer` should play and if
> this adds additional coupling that is unwanted. My current impression
> is, that this would be the right place, since this looks to be the core
> of the commands where a user can apply a sequence of commits and in my
> opinion even if additional actions would be added, they could also fail
> and so it would be good to add the `--show-current-patch` option to that
> one as well.
>
> Side note: my only C(++) experience was ~10 years ago and only for a
> single university course, so my perspective is much more from a general
> architecture point of view than based on any C experience, let alone in
> this code base and so I would be very grateful for criticism!
>
>
> Side note: The check for the `REBASE_HEAD` would not be necessary, since
> that is already taken care of in the builtin/rebase.c before.
> Nevertheless I opted for this check, because I would much rather require
> the same preconditions no matter from where I call this function. The
> whole argument parsing / option struct are very different between rebase
> and revert. Maybe it would make sense to align them a bit further?
> Initial observations: `rebase_options->type` is functionally similar to
> `replay_opts->action` (as in "what general action am I performing? -
> interactive rebase / cherry-pick / revert / ...") whereas
> `rebase_options->action` is not part of the `replay_opts` struct at all.
> Instead the role is taken over in builtin/revert.c by `int cmd = 0;`.
> I am preparing a patch converting this to an enum, so that there are
> no random chars that have to be kept in sync manually in different
> places, or is that a design decision?
>
> I looked through the mailing list archive and did not find anything
> related on this topic. The only slightly related thread I could find was
> in [1] by Elijah Newren and that one was talking about a separate
> possible feature and how to get certain information if CHERRY_PICK_HEAD
> and REVERT_HEAD were to be replaced by a different construct. I hope I
> did not miss something...
>
> Cheers
> Michael
>
> [1]:
> https://lore.kernel.org/git/CABPp-BGd-W8T7EsvKYyjdi3=mfSTJ8zM-uzVsFnh1AWyV2wEzQ@mail.gmail.com
>
> Michael Lohmann (1):
> revert/cherry-pick: add --show-current-patch option
>
> Documentation/git-cherry-pick.txt | 2 +-
> Documentation/git-revert.txt | 2 +-
> Documentation/sequencer.txt | 5 +++++
> builtin/rebase.c | 7 ++----
> builtin/revert.c | 9 ++++++--
> contrib/completion/git-completion.bash | 2 +-
> sequencer.c | 24 +++++++++++++++++++++
> sequencer.h | 2 ++
> t/t3507-cherry-pick-conflict.sh | 30 ++++++++++++++++++++++++++
> 9 files changed, 73 insertions(+), 10 deletions(-)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Re: [PATCH 0/1] revert/cherry-pick: add --show-current-patch option
2023-12-18 16:42 ` [PATCH 0/1] " Phillip Wood
@ 2023-12-20 6:51 ` Michael Lohmann
2023-12-21 16:32 ` phillip.wood123
0 siblings, 1 reply; 5+ messages in thread
From: Michael Lohmann @ 2023-12-20 6:51 UTC (permalink / raw)
To: phillip.wood123; +Cc: git, mi.al.lohmann, mial.lohmann, newren, phillip.wood
Hi Phillip
On 18/12/2023 16:42, Phillip Wood wrote:
> Thanks for bringing this up I agree it can be very helpful to look at
> the original commit when resolving cherry-pick and revert conflicts.
> I'm in two minds about this change though - I wonder if it'd be better
> to improve the documentation for CHERRY_PICK_HEAD and REVERT_HEAD and
> tell users to run "git show CHERRY_PICK_HEAD" instead. I think the
> main reason we have a "--show-current-patch" option for "rebase" is
> that there are two different implementations of that command and the
> patched-based one of them does not support REBASE_HEAD. That reasoning
> does not apply to "cherry-pick" and "revert" and
> "--show-current-patch" suggests a patch-based implementation which is
> also not the case for these commands.
I appreciate the urge of limiting the interface to the minimum needed
and not to duplicate functionality that already exists. On the other
hand, this would
a) grant the user the same experience, not having to wonder about
implementation details such as different backends for rebase, but not
for revert/cherry-pick and
b) (I know it is more indicative of me, but:) when I am looking for a
feature in software and I look into the respective man page I tend to
focus first on the synopsis instead of reading the whole page (or
sometimes I even just rely on the shell autocompletion for
discoverability).
So yes, mentioning REVERT_HEAD and CHERRY_PICK_HEAD in the respective
docs would technically be sufficient, but I don't think it is as
discoverable to an average user (who does not know about the details of
all the existing pseudo refs) as a toplevel action would be. But an
assessment of the pros and cons is not on me to decide.
I have to be honest: I have troubles distinguishing a "patch" and a
"diff", the latter of which `git show <commit>` shows according to the
documentation ("For commits it shows the log message and textual
diff."), though my understanding was that a patch is a diff + context
lines, which is what `git show` actually shows... I think this is
probably why I don't feel so strong about the potential loose usage of
the word here.
Also the documentation of cherry-pick already uses the word "patch" in a
(according to my understanding from a technical perspective) sloppy (but
from a layman's point of view probably nevertheless helpful) way:
> The following sequence attempts to backport a patch, bails out because
> the code the patch applies to has changed too much, and then tries
> again, this time exercising more care about matching up context lines.
>
> ------------
> $ git cherry-pick topic^ <1>
> $ git diff <2>
> $ git cherry-pick --abort <3>
> $ git cherry-pick -Xpatience topic^ <4>
> ------------
> <1> apply the change that would be shown by `git show topic^`.
> In this example, the patch does not apply cleanly, so
> information about the conflict is written to the index and
> working tree and no new commit results.
Should that also be rephrased?
Out of curiosity: The following from the rebase docs seems to imply that
the apply backend will probably be removed in the future:
> --apply
> Use applying strategies to rebase (calling git-am
> internally). This option may become a no-op in the future
> once the merge backend handles everything the apply one
> does.
But I would expect the `rebase --show-current-patch` still to be
working. Would that only be a legacy compatibility flag and instead also
for rebases the recommended option would be to run
`git show REBASE_HEAD`?
Best Wishes
Michael
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/1] revert/cherry-pick: add --show-current-patch option
2023-12-20 6:51 ` Michael Lohmann
@ 2023-12-21 16:32 ` phillip.wood123
0 siblings, 0 replies; 5+ messages in thread
From: phillip.wood123 @ 2023-12-21 16:32 UTC (permalink / raw)
To: Michael Lohmann; +Cc: git, mi.al.lohmann, newren, phillip.wood
Hi Michael
On 20/12/2023 06:51, Michael Lohmann wrote:
> Hi Phillip
>
> On 18/12/2023 16:42, Phillip Wood wrote:
>> Thanks for bringing this up I agree it can be very helpful to look at
>> the original commit when resolving cherry-pick and revert conflicts.
As an aside I find it useful is to do a kind of range-diff before
committing the conflict resolution. Unfortunately one cannot use "git
range-diff" because the conflict resolution is not yet committed.
Instead I use
diff <(git diff CHERRY_PICK_HEAD^-) <(git diff HEAD)
in practice it is helpful to pipe the diffs through sed to delete the
"index" lines and normalize the hunk headers.
>> I'm in two minds about this change though - I wonder if it'd be better
>> to improve the documentation for CHERRY_PICK_HEAD and REVERT_HEAD and
>> tell users to run "git show CHERRY_PICK_HEAD" instead. I think the
>> main reason we have a "--show-current-patch" option for "rebase" is
>> that there are two different implementations of that command and the
>> patched-based one of them does not support REBASE_HEAD. That reasoning
>> does not apply to "cherry-pick" and "revert" and
>> "--show-current-patch" suggests a patch-based implementation which is
>> also not the case for these commands.
>
> I appreciate the urge of limiting the interface to the minimum needed
> and not to duplicate functionality that already exists. On the other
> hand, this would
> a) grant the user the same experience, not having to wonder about
> implementation details such as different backends for rebase, but not
> for revert/cherry-pick and
> b) (I know it is more indicative of me, but:) when I am looking for a
> feature in software and I look into the respective man page I tend to
> focus first on the synopsis instead of reading the whole page (or
> sometimes I even just rely on the shell autocompletion for
> discoverability).
>
> So yes, mentioning REVERT_HEAD and CHERRY_PICK_HEAD in the respective
> docs would technically be sufficient, but I don't think it is as
> discoverable to an average user (who does not know about the details of
> all the existing pseudo refs) as a toplevel action would be. But an
> assessment of the pros and cons is not on me to decide.
To make the psuedo refs discoverable we should certainly be mentioning
them in the section about resolving conflicts. I haven't checked what
the docs say at the moment but a worked example showing how to inspect
the conflicts and the original changes would be helpful I think. That
does assume that the user actually reads the section about resolving
conflicts rather than just scanning the available command line options
though.
> I have to be honest: I have troubles distinguishing a "patch" and a
> "diff", the latter of which `git show <commit>` shows according to the
> documentation ("For commits it shows the log message and textual
> diff."), though my understanding was that a patch is a diff + context
> lines, which is what `git show` actually shows... I think this is
> probably why I don't feel so strong about the potential loose usage of
> the word here.
I think for the purposes of this discussion "patch" and "diff" are
largely interchangeable (a "patch" is essentially a "diff" with a commit
message). Maybe I'm overthinking it but the reason I'm not very keen on
"--show-current-patch" (in addition to the "duplicate functionality"
argument you mention above) is that cherry-pick and revert do not work
by applying patches (or diffs) but use a 3-way merge instead. I think
--show-current-patch first appeared as an option to "git am" which makes
sense as that command is all about applying patches.
I'd be interested to hear what other people think about whether it makes
"--show-current-patch" make sense for other commands.
> Also the documentation of cherry-pick already uses the word "patch" in a
> (according to my understanding from a technical perspective) sloppy (but
> from a layman's point of view probably nevertheless helpful) way:
>
>> The following sequence attempts to backport a patch, bails out because
>> the code the patch applies to has changed too much, and then tries
>> again, this time exercising more care about matching up context lines.
>>
>> ------------
>> $ git cherry-pick topic^ <1>
>> $ git diff <2>
>> $ git cherry-pick --abort <3>
>> $ git cherry-pick -Xpatience topic^ <4>
>> ------------
>> <1> apply the change that would be shown by `git show topic^`.
>> In this example, the patch does not apply cleanly, so
>> information about the conflict is written to the index and
>> working tree and no new commit results.
>
> Should that also be rephrased?
It would certainly be more accurate for the first paragraph to say
something like
The following sequence tries to backport a commit. It bails out
because the code modified by the commit has conflicting changes in
the current branch.
The bit about exercising more care about matching up context lines is
moot these days as the default merge strategy is "ort" which uses the
histogram diff algorithm to do just that so commands <3> & <4> should
not be needed.
>
> Out of curiosity: The following from the rebase docs seems to imply that
> the apply backend will probably be removed in the future:
>> --apply
>> Use applying strategies to rebase (calling git-am
>> internally). This option may become a no-op in the future
>> once the merge backend handles everything the apply one
>> does.
>
> But I would expect the `rebase --show-current-patch` still to be
> working. Would that only be a legacy compatibility flag and instead also
> for rebases the recommended option would be to run
> `git show REBASE_HEAD`?
The long term goal is to remove the apply backend but I don't think
anyone is actively working on it at the moment. We'd certainly need to
keep the --show-current-patch option for backwards compatibility.
I'll be off the list for the next couple of weeks but I'll be sure to
catch up with this thread in the New Year
Best Wishes
Phillip
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-12-21 16:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-18 12:10 [PATCH 0/1] revert/cherry-pick: add --show-current-patch option Michael Lohmann
2023-12-18 12:10 ` [PATCH 1/1] " Michael Lohmann
2023-12-18 16:42 ` [PATCH 0/1] " Phillip Wood
2023-12-20 6:51 ` Michael Lohmann
2023-12-21 16:32 ` phillip.wood123
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 NNTP newsgroup(s).