Skip to content

Commit bf975d3

Browse files
jrngitster
authored andcommitted
cherry-pick, revert: add a label for ancestor
When writing conflict hunks in ‘diff3 -m’ format, also add a label to the common ancestor. Especially in a cherry-pick, it is not immediately obvious without such a label what the common ancestor represents. git rerere does not have trouble parsing the new output and its preimage ids are unchanged since it includes its own code for recreating conflict hunks. No other code in git parses conflict hunks. Requested-by: Stefan Monnier <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d685654 commit bf975d3

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

builtin/revert.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
281281
{
282282
unsigned char head[20];
283283
struct commit *base, *next, *parent;
284-
const char *next_label;
284+
const char *base_label, *next_label;
285285
int i, index_fd, clean;
286286
struct commit_message msg = { NULL, NULL, NULL, NULL, NULL };
287287

@@ -368,6 +368,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
368368

369369
if (action == REVERT) {
370370
base = commit;
371+
base_label = msg.label;
371372
next = parent;
372373
next_label = msg.parent_label;
373374
add_to_msg("Revert \"");
@@ -382,6 +383,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
382383
add_to_msg(".\n");
383384
} else {
384385
base = parent;
386+
base_label = msg.parent_label;
385387
next = commit;
386388
next_label = msg.label;
387389
set_author_ident_env(msg.message);
@@ -395,6 +397,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
395397

396398
read_cache();
397399
init_merge_options(&o);
400+
o.ancestor = base ? base_label : "(empty tree)";
398401
o.branch1 = "HEAD";
399402
o.branch2 = next ? next_label : "(empty tree)";
400403

t/t3507-cherry-pick-conflict.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ test_expect_success 'diff3 -m style' '
112112
cat <<-EOF > expected &&
113113
<<<<<<< HEAD
114114
a
115-
|||||||
115+
||||||| parent of objid picked
116116
b
117117
=======
118118
c
@@ -179,7 +179,7 @@ test_expect_success 'revert conflict, diff3 -m style' '
179179
cat <<-EOF > expected &&
180180
<<<<<<< HEAD
181181
a
182-
|||||||
182+
||||||| objid picked
183183
c
184184
=======
185185
b

0 commit comments

Comments
 (0)