]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sequencer: avoid garbled merge machinery messages due to commit labels
authorElijah Newren <newren@gmail.com>
Wed, 12 Aug 2020 14:40:04 +0000 (14:40 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Aug 2020 17:48:58 +0000 (10:48 -0700)
sequencer's get_message() exists to provide good labels on conflict
hunks; see commits
  d68565402a ("revert: clarify label on conflict hunks", 2010-03-20)
  bf975d379d ("cherry-pick, revert: add a label for ancestor", 2010-03-20)
  043a4492b3 ("sequencer: factor code out of revert builtin", 2012-01-11).
for background on this function.  These labels are of the form
  <commitID>... <commit summary>
or
  parent of <commitID>... <commit summary>
These labels are then passed as branch names to the merge machinery.
However, these labels, as formatted, often also serve to confuse.  For
example, if we have a rename involved in a content merge, then it
results in text such as the following:

    <<<<<<<< HEAD:foo.c
      int j;
    ========
      int counter;
    >>>>>>>> b01dface... Removed unnecessary stuff:bar.c

Or in various conflict messages, it can make it very difficult to read:

    CONFLICT (rename/delete): foo.c deleted in b01dface... Removed
    unnecessary stuff and renamed in HEAD.  Version HEAD of foo.c left
    in tree.

    CONFLICT (file location): dir1/foo.c added in b01dface... Removed
    unnecessary stuff inside a directory that was renamed in HEAD,
    suggesting it should perhaps be moved to dir2/foo.c.

Make a minor change to remove the ellipses and add parentheses around
the commit summary; this makes all three examples much easier to read:

    <<<<<<<< HEAD:foo.c
      int j;
    ========
      int counter;
    >>>>>>>> b01dface (Removed unnecessary stuff):bar.c

    CONFLICT (rename/delete): foo.c deleted in b01dface (Removed
    unnecessary stuff) and renamed in HEAD.  Version HEAD of foo.c left
    in tree.

    CONFLICT (file location): dir1/foo.c added in b01dface (Removed
    unnecessary stuff) inside a directory that was renamed in HEAD,
    suggesting it should perhaps be moved to dir2/foo.c.

Signed-off-by: Elijah Newren <newren@gmail.com>
Reviewed-by: Taylor Blau <me@ttaylorr.com>
Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c
t/t3404-rebase-interactive.sh
t/t3507-cherry-pick-conflict.sh

index fd7701c88a8643c424d4f61fd0cc86fde3097d7d..e988c12ad2b66f0d24678820ba1dd42f44014f1e 100644 (file)
@@ -355,7 +355,7 @@ static int get_message(struct commit *commit, struct commit_message *out)
        subject_len = find_commit_subject(out->message, &subject);
 
        out->subject = xmemdupz(subject, subject_len);
-       out->label = xstrfmt("%s... %s", abbrev, out->subject);
+       out->label = xstrfmt("%s (%s)", abbrev, out->subject);
        out->parent_label = xstrfmt("parent of %s", out->label);
 
        return 0;
index 4a7d21f898f7361ffcdf988b2458e52089b758ba..1d0a656ebdcaf2ef5075a6181ba6be2ba0cfbdb4 100755 (executable)
@@ -256,7 +256,7 @@ test_expect_success 'stop on conflicting pick' '
        D
        =======
        G
-       >>>>>>> $commit... G
+       >>>>>>> $commit (G)
        EOF
        git tag new-branch1 &&
        test_must_fail git rebase -i master &&
index 752bc43487196a4be33ff7df770384f331a68315..152ea11dc9278978acf78e425785949be74d3ae8 100755 (executable)
@@ -283,12 +283,12 @@ test_expect_success 'failed cherry-pick describes conflict in work tree' '
        a
        =======
        c
-       >>>>>>> objid picked
+       >>>>>>> objid (picked)
        EOF
 
        test_must_fail git cherry-pick picked &&
 
-       sed "s/[a-f0-9]*\.\.\./objid/" foo >actual &&
+       sed "s/[a-f0-9]* (/objid (/" foo >actual &&
        test_cmp expected actual
 '
 
@@ -298,16 +298,16 @@ test_expect_success 'diff3 -m style' '
        cat <<-EOF >expected &&
        <<<<<<< HEAD
        a
-       ||||||| parent of objid picked
+       ||||||| parent of objid (picked)
        b
        =======
        c
-       >>>>>>> objid picked
+       >>>>>>> objid (picked)
        EOF
 
        test_must_fail git cherry-pick picked &&
 
-       sed "s/[a-f0-9]*\.\.\./objid/" foo >actual &&
+       sed "s/[a-f0-9]* (/objid (/" foo >actual &&
        test_cmp expected actual
 '
 
@@ -319,7 +319,7 @@ test_expect_success 'revert also handles conflicts sanely' '
        a
        =======
        b
-       >>>>>>> parent of objid picked
+       >>>>>>> parent of objid (picked)
        EOF
        {
                git checkout picked -- foo &&
@@ -345,7 +345,7 @@ test_expect_success 'revert also handles conflicts sanely' '
        test_must_fail git update-index --refresh -q &&
        test_must_fail git diff-index --exit-code HEAD &&
        test_cmp expected-stages actual-stages &&
-       sed "s/[a-f0-9]*\.\.\./objid/" foo >actual &&
+       sed "s/[a-f0-9]* (/objid (/" foo >actual &&
        test_cmp expected actual
 '
 
@@ -429,16 +429,16 @@ test_expect_success 'revert conflict, diff3 -m style' '
        cat <<-EOF >expected &&
        <<<<<<< HEAD
        a
-       ||||||| objid picked
+       ||||||| objid (picked)
        c
        =======
        b
-       >>>>>>> parent of objid picked
+       >>>>>>> parent of objid (picked)
        EOF
 
        test_must_fail git revert picked &&
 
-       sed "s/[a-f0-9]*\.\.\./objid/" foo >actual &&
+       sed "s/[a-f0-9]* (/objid (/" foo >actual &&
        test_cmp expected actual
 '