Option to allow cherry-pick to skip empty commits
RFC PATCH 1/1 Option to allow cherry-pick to skip empty commits
This allows cherry-picking a set of commits, some of which may be redundant, without stopping to ask for the user intervention.
--- Documentation/git-cherry-pick.txt | 4 ++++ builtin/revert.c | 1 + sequencer.c | 45 +++++++++++++++++++++++++++++++-------- sequencer.h | 1 + 4 files changed, 42 insertions(+), 9 deletions(-)
I would like to add to cherry-pick the ability to skip patches. To this end, I'm working on two options: a general --skip-empty option to handle redundant and empty commits by simply skipping them (no user intervention), and a --skip option as an alternative form to --continue to skip the ongoing (conflicting or empty) commit.
The patch here presents my implementation of the --skip-empty option, including documentation. Comments welcome.
However, it has been some time since I dwelved into git internals and I'm having issues with the --skip option. My idea was to rely on the existing implementation for --continue, and have it run the rollback instead of the commit. However, I'm finding that after the rollback is done (I'm using the existing rollback function in sequencer, which calls git reset --merge, but I've also tried a reset --hard) the sequencer does not continue because e.g. if the cherry-pick had stopped due to a conflict, it still finds unmerged paths, and I can't find a way to tell the sequencer to just re-read the index from scratch. Opinions welcome (I can provide my WIP patch to make discussion easier).
On the same note, I've noticed that git reset clears CHERRY_PICK_HEAD. I find this a little confusing, both for humans for the code itself (since it doesn't really abort an ongoing cherry-pick, yet the sequencer will think there is no running cherry-pick). This is particularly bad because git reset is one of the strategies proposed to solve conflicts in cherry-picking. So I was wondering if this was intentional or a side effect of something else that I might look into cleaning up during this patch series.
Documentation/git-cherry-pick.txt +4 -0
@@ -138,6 +138,10 @@ effect to your index in a row. examine the commit. This option overrides that behavior and creates an empty commit object. Implies `--allow-empty`. +--skip-empty:: + This option causes empty and redundant cherry-picked commits to + be skipped without requesting the user intervention. + --strategy=<strategy>:: Use the given merge strategy. Should only be used once. See the MERGE STRATEGIES section in linkgit:git-merge[1]
builtin/revert.c +1 -0
@@ -102,6 +102,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)OPT_BOOL (0 ,"allow-empty" , &opts->allow_empty,N_ ("preserve initially empty commits" )),OPT_BOOL (0 ,"allow-empty-message" , &opts->allow_empty_message,N_ ("allow commits with empty messages" )),OPT_BOOL (0 ,"keep-redundant-commits" , &opts->keep_redundant_commits,N_ ("keep redundant, empty commits" )), +OPT_BOOL (0 ,"skip-empty" , &opts->skip_empty,N_ ("skip redundant, empty commits" )),OPT_END (), }; options =parse_options_concat (options, cp_extra);
sequencer.c +36 -9
107 lines not on this page · raw message
sequencer.h +1 -0
@@ -23,6 +23,7 @@ struct replay_opts {int allow_empty;int allow_empty_message;int keep_redundant_commits; +int skip_empty;int mainline;
Signature · 1 line
2.11.0.585.g56041942c3.dirty
Quoted 12 lines · Giuseppe Bilotta
This allows cherry-picking a set of commits, some of which may be redundant, without stopping to ask for the user intervention.
Signed-off-by Giuseppe Bilotta <[email protected]>--- Documentation/git-cherry-pick.txt | 4 ++++ builtin/revert.c | 1 + sequencer.c | 45 +++++++++++++++++++++++++++++++-------- sequencer.h | 1 + 4 files changed, 42 insertions(+), 9 deletions(-)
Quoted 8 lines
I would like to add to cherry-pick the ability to skip patches. To this end, I'm working on two options: a general
--skip-emptyoption to handle redundant and empty commits by simply skipping them (no user intervention), and a--skipoption as an alternative form to--continueto skip the ongoing (conflicting or empty) commit.The patch here presents my implementation of the
--skip-emptyoption, including documentation. Comments welcome.
Sounds like a useful thing to do.
Quoted 10 lines
sequencer.c +3
-2+static int allow_or_skip_empty (struct replay_opts *opts,struct commit *commit) {int index_unchanged, empty_commit;/* -* Three cases: +* Four cases: * -* (1) we do not allow empty at all and error out. +* (1) we do not allow empty at all and error out;
sequencer.c static int is_original_commit_empty(struct commit *commit) · line 577
Quoted 10 lines
sequencer.c +4
-2* -* (2) we allow ones that were initially empty, but +* (2) we skip empty commits altogether; +* +* (3) we allow ones that were initially empty, but * forbid the ones that become empty; * -* (3) we allow both. +* (4) we allow both. */
The original gave callers the choice to tell two cases (a commit was empty in the original history, and a commit that was not empty in the original history turns out to be redundant) apart and handle them differently. I tend to agree that skipping the former should be the norm, and also I think it is sensible to drop the latter, and that is what your updated (2) gives us, I think.
But I would suspect that it would rather be common to have a deliberately empty commit in the original as a marker in a history and want to keep that across cherry-picking a series, while wanting to discard/skip patches that are already applied in an updated base. Shouldn't that be supported as the fifth case?
Quoted 30 lines · Junio C Hamano
Quoted 10 lines · Giuseppe Bilotta
sequencer.c +3
-2+static int allow_or_skip_empty (struct replay_opts *opts,struct commit *commit) {int index_unchanged, empty_commit;/* -* Three cases: +* Four cases: * -* (1) we do not allow empty at all and error out. +* (1) we do not allow empty at all and error out; sequencer.c static int is_original_commit_empty(struct commit *commit) · line 577
Quoted 10 lines
sequencer.c +4
-2* -* (2) we allow ones that were initially empty, but +* (2) we skip empty commits altogether; +* +* (3) we allow ones that were initially empty, but * forbid the ones that become empty; * -* (3) we allow both. +* (4) we allow both. */ The original gave callers the choice to tell two cases (a commit was empty in the original history, and a commit that was not empty in the original history turns out to be redundant) apart and handle them differently. I tend to agree that skipping the former should be the norm, and also I think it is sensible to drop the latter, and that is what your updated (2) gives us, I think.
Quoted 5 lines
But I would suspect that it would rather be common to have a deliberately empty commit in the original as a marker in a history and want to keep that across cherry-picking a series, while wanting to discard/skip patches that are already applied in an updated base. Shouldn't that be supported as the fifth case?
I was actually wondering about that. I guess the best approach (symmetric wrt to the --allow) would be to intro introduce --skip-empty _and_ --skip-redundant, with the former implying the latter.
By the way, I noticed going over the code that the -allow options are not stored, so that in case of interruption they will be reset, is this intentional or a bug?
Signature · 1 line
Giuseppe "Oblomov" Bilotta
Quoted 3 lines · Giuseppe Bilotta
By the way, I noticed going over the code that the -allow options are not stored, so that in case of interruption they will be reset, is this intentional or a bug?
I do not know offhand, but given the history of the two commands, I would guess it was a bug simply overlooked when people bolted "a series of commits" mode onto these commands that originally worked only on a single commit.
Quoted 10 lines · Junio C Hamano
Quoted 3 lines · Giuseppe Bilotta
By the way, I noticed going over the code that the -allow options are not stored, so that in case of interruption they will be reset, is this intentional or a bug?
I do not know offhand, but given the history of the two commands, I would guess it was a bug simply overlooked when people bolted "a series of commits" mode onto these commands that originally worked only on a single commit.
It seems like a bug to me. I'll prepare a new series that also fixes this. I still don't see how to force a complete reread of the index after running a git reset (which I need for the --skip command), but maybe I'll add a WIP of what I have for --skip so far and people can comment on that.
Signature · 1 line
Giuseppe "Oblomov" Bilotta
Quoted 2 lines · Giuseppe Bilotta
... I still don't see how to force a complete reread of the index after running a git reset (which I need for the --skip command), ...
Do you mean discard_index() or discard_cache() followed by read_index() or read_cache(), or do you mean something more elaborate?
Quoted 8 lines · Junio C Hamano
Quoted 2 lines · Giuseppe Bilotta
... I still don't see how to force a complete reread of the index after running a git reset (which I need for the --skip command), ...
Do you mean
discard_index()ordiscard_cache()followed byread_index()orread_cache(), or do you mean something more elaborate?
Apparently discard_cache() followed by read_cache() is exactly what I needed. New patchset incoming 8-)
Signature · 1 line
Giuseppe "Oblomov" Bilotta