Skip to content

Commit 661b671

Browse files
zivarahgitster
authored andcommitted
sequencer: do not require allow_empty for redundant commit options
A consumer of the sequencer that wishes to take advantage of either the `keep_redundant_commits` or `drop_redundant_commits` feature must also specify `allow_empty`. However, these refer to two distinct types of empty commits: - `allow_empty` refers specifically to commits which start empty - `keep_redundant_commits` refers specifically to commits that do not start empty, but become empty due to the content already existing in the target history Conceptually, there is no reason that the behavior for handling one of these should be entangled with the other. It is particularly unintuitive to require `allow_empty` in order for `drop_redundant_commits` to have an effect: in order to prevent redundant commits automatically, initially-empty commits would need to be kept automatically as well. Instead, rewrite the `allow_empty()` logic to remove the over-arching requirement that `allow_empty` be specified in order to reach any of the keep/drop behaviors. Only if the commit was originally empty will `allow_empty` have an effect. Note that no behavioral changes should result from this commit -- it merely sets the stage for future commits. In one such future commit, an `--empty` option will be added to git-cherry-pick(1), meaning that `drop_redundant_commits` will be used by that command. Signed-off-by: Brian Lyles <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1b90588 commit 661b671

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

sequencer.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,34 +1734,25 @@ static int allow_empty(struct repository *r,
17341734
int index_unchanged, originally_empty;
17351735

17361736
/*
1737-
* Four cases:
1737+
* For a commit that is initially empty, allow_empty determines if it
1738+
* should be kept or not
17381739
*
1739-
* (1) we do not allow empty at all and error out.
1740-
*
1741-
* (2) we allow ones that were initially empty, and
1742-
* just drop the ones that become empty
1743-
*
1744-
* (3) we allow ones that were initially empty, but
1745-
* halt for the ones that become empty;
1746-
*
1747-
* (4) we allow both.
1740+
* For a commit that becomes empty, keep_redundant_commits and
1741+
* drop_redundant_commits determine whether the commit should be kept or
1742+
* dropped. If neither is specified, halt.
17481743
*/
1749-
if (!opts->allow_empty)
1750-
return 0; /* let "git commit" barf as necessary */
1751-
17521744
index_unchanged = is_index_unchanged(r);
17531745
if (index_unchanged < 0)
17541746
return index_unchanged;
17551747
if (!index_unchanged)
17561748
return 0; /* we do not have to say --allow-empty */
17571749

1758-
if (opts->keep_redundant_commits)
1759-
return 1;
1760-
17611750
originally_empty = is_original_commit_empty(commit);
17621751
if (originally_empty < 0)
17631752
return originally_empty;
17641753
if (originally_empty)
1754+
return opts->allow_empty;
1755+
else if (opts->keep_redundant_commits)
17651756
return 1;
17661757
else if (opts->drop_redundant_commits)
17671758
return 2;

0 commit comments

Comments
 (0)