Re: [PATCH v4 0/7] cherry-pick: add `--empty` for more robust redundant commit handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Brian

On 20/03/2024 23:36, Brian Lyles wrote:
This re-roll contains only minor changes from v3.

Here is the range diff with a couple of comments

1:  5a503a7026 = 1:  5aa3f7cec2 docs: address inaccurate `--empty` default with `--exec`
2:  36278e0d40 = 2:  abb7d7233a docs: clean up `--empty` formatting in git-rebase(1) and git-am(1)
3:  a2f603da50 = 3:  ef8224d286 rebase: update `--empty=ask` to `--empty=stop`
4:  0701f9f9fc ! 4:  21ed2dfb65 sequencer: treat error reading HEAD as unborn branch
    @@ Metadata
     Author: Brian Lyles <brianmlyles@xxxxxxxxx>
## Commit message ##
    -    sequencer: treat error reading HEAD as unborn branch
    +    sequencer: handle unborn branch with `--allow-empty`
When using git-cherry-pick(1) with `--allow-empty` while on an unborn
         branch, an error is thrown. This is inconsistent with the same
         cherry-pick when `--allow-empty` is not specified.
- Treat a failure reading HEAD as an unborn branch in
    -    `is_index_unchanged`. This is consistent with other sequencer logic such
    -    as `do_pick_commit`. When on an unborn branch, use the `empty_tree` as
    -    the tree to compare against.
    +    Detect unborn branches in `is_index_unchanged`. When on an unborn
    +    branch, use the `empty_tree` as the tree to compare against.
Add a new test to cover this scenario. While modelled off of the
         existing 'cherry-pick on unborn branch' test, some improvements can be
    @@ Commit message
         - Use `git switch --orphan unborn` instead of `git checkout --orphan
           unborn` to avoid the need for a separate `rm -rf *` call
         - Avoid using `--quiet` in the `git diff` call to make debugging easier
    -      in the event of a failure
    +      in the event of a failure. Use simply `--exit-code` instead.
Make these improvements to the existing test as well as the new test. Helped-by: Phillip Wood <phillip.wood@xxxxxxxxxxxxx>
    +    Helped-by: Junio C Hamano <gitster@xxxxxxxxx>
         Signed-off-by: Brian Lyles <brianmlyles@xxxxxxxxx>
## sequencer.c ##
    @@ sequencer.c: static struct object_id *get_cache_tree_oid(struct index_state *ist
     +	const struct object_id *head_tree_oid;
      	struct commit *head_commit;
      	struct index_state *istate = r->index;
    -
    +-
     -	if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
     -		return error(_("could not resolve HEAD commit"));
     -
    @@ sequencer.c: static struct object_id *get_cache_tree_oid(struct index_state *ist
     -	 */
     -	if (repo_parse_commit(r, head_commit))
     -		return -1;
    ++	const char *head_name;
    ++
     +	if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL)) {
     +		/*
    -+		 * Treat an error reading HEAD as an unborn branch.
    ++		 * Check to see if this is an unborn branch
     +		 */

You are only editing an existing comment here and it is not worth a
re-roll on its own, but for one line comments we prefer

	/* Check to see if this is an unborn branch */

    ++		head_name = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE, &head_oid, NULL);
    ++		if (!head_name || !starts_with(head_name, "refs/heads/") || !is_null_oid(&head_oid))

While we don't mind the occasional line that is a little over 80
characters these really are rather long.

    ++			return error(_("could not resolve HEAD commit"));
     +		head_tree_oid = the_hash_algo->empty_tree;
     +	} else {
     +		head_commit = lookup_commit(r, &head_oid);
    @@ t/t3501-revert-cherry-pick.sh: test_expect_success 'revert forbidden on dirty wo
     -	rm -rf * &&
      	git cherry-pick initial &&
     -	git diff --quiet initial &&
    -+	git diff initial &&
    ++	git diff --exit-code initial &&
     +	test_cmp_rev ! initial HEAD
     +'
     +
    @@ t/t3501-revert-cherry-pick.sh: test_expect_success 'revert forbidden on dirty wo
     +	git branch -D unborn &&
     +	git switch --orphan unborn &&
     +	git cherry-pick initial --allow-empty &&
    -+	git diff initial &&
    ++	git diff --exit-code initial &&
      	test_cmp_rev ! initial HEAD
      '

Thanks for updating these tests
5: 3634da0f70 = 5: 5c16a01056 sequencer: do not require `allow_empty` for redundant commit options
6:  e98b414697 = 6:  3ee057e485 cherry-pick: enforce `--keep-redundant-commits` incompatibility
7:  cc4030d8ec ! 7:  0cd4620ef7 cherry-pick: add `--empty` for more robust redundant commit handling
    @@ Documentation/git-cherry-pick.txt: effect to your index in a row.
     +	you to examine the commit. This is the default behavior.
     +--
     ++
    -+Note that this option specifies how to handle a commit that was not initially
    -+empty, but rather became empty due to a previous commit. Commits that were
    -+initially empty will cause the cherry-pick to fail. To force the inclusion of
    -+those commits, use `--allow-empty`.
    ++Note that `--empty=drop` and `--empty=stop` only specify how to handle a
    ++commit that was not initially empty, but rather became empty due to a previous
    ++commit. Commits that were initially empty will still cause the cherry-pick to
    ++fail unless one of `--empty=keep` or `--allow-empty` are specified.
     ++
     +
      --keep-redundant-commits::

The new wording here looks good

Apart from the minor style issues this all looks good to me, thanks
for working on it, it will be a useful addition to be able to drop
cherry-picks that become empty.

Best Wishes

Phillip




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux