[PATCH v5 10/10] diff-merges: avoid history simplifications when diffing merges

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

 



From: Elijah Newren <newren@xxxxxxxxx>

Doing diffs for merges are special; they should typically avoid history
simplification.  For example, with

    git log --diff-merges=first-parent -- path

the default history simplification would remove merge commits from
consideration if the file "path" matched the second parent.  That is
counter to what the user wants when looking for first-parent diffs.
Similar comments can be made for --diff-merges=separate (which diffs
against both parents) and --diff-merges=remerge (which diffs against a
remerge of the merge commit).

However, history simplification still makes sense if not doing diffing
merges, and it also makes sense for the combined and dense-combined
forms of diffing merges (because both of those are defined to only show
a diff when the merge result at the relevant paths differs from *both*
parents).

So, for separate, first-parent, and remerge styles of diff-merges, turn
off history simplification.

Signed-off-by: Elijah Newren <newren@xxxxxxxxx>
---
 diff-merges.c           |  2 ++
 t/t4069-remerge-diff.sh | 58 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/diff-merges.c b/diff-merges.c
index 0af4b3f9191..a833fd747ad 100644
--- a/diff-merges.c
+++ b/diff-merges.c
@@ -24,6 +24,7 @@ static void set_separate(struct rev_info *revs)
 {
 	suppress(revs);
 	revs->separate_merges = 1;
+	revs->simplify_history = 0;
 }
 
 static void set_first_parent(struct rev_info *revs)
@@ -50,6 +51,7 @@ static void set_remerge_diff(struct rev_info *revs)
 {
 	suppress(revs);
 	revs->remerge_diff = 1;
+	revs->simplify_history = 0;
 }
 
 static diff_merges_setup_func_t func_by_opt(const char *optarg)
diff --git a/t/t4069-remerge-diff.sh b/t/t4069-remerge-diff.sh
index fd6bce64781..35f94957fce 100755
--- a/t/t4069-remerge-diff.sh
+++ b/t/t4069-remerge-diff.sh
@@ -227,7 +227,63 @@ test_expect_success 'remerge-diff w/ pathspec: limits to relevant file including
 	# with sha256
 	sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
 
-	git show --oneline --remerge-diff --full-history resolution -- "letters*" >tmp &&
+	git show --oneline --remerge-diff resolution -- "letters*" >tmp &&
+	sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'setup non-content conflicts' '
+	git switch --orphan newbase &&
+
+	test_write_lines 1 2 3 4 5 6 7 8 9 >numbers &&
+	git add numbers &&
+	git commit -m base &&
+
+	git branch newside1 &&
+	git branch newside2 &&
+
+	git checkout newside1 &&
+	test_write_lines 1 2 three 4 5 6 7 8 9 >numbers &&
+	git add numbers &&
+	git commit -m side1 &&
+
+	git checkout newside2 &&
+	test_write_lines 1 2 drei 4 5 6 7 8 9 >numbers &&
+	git add numbers &&
+	git commit -m side2 &&
+
+	git checkout -b newresolution newside1 &&
+	test_must_fail git merge newside2 &&
+	git checkout --theirs numbers &&
+	git add -u numbers &&
+	git commit -m resolved
+'
+
+test_expect_success 'remerge-diff turns off history simplification' '
+	git log -1 --oneline newresolution >tmp &&
+	cat <<-EOF >>tmp &&
+	diff --git a/numbers b/numbers
+	remerge CONFLICT (content): Merge conflict in numbers
+	index 070e9e7..5335e78 100644
+	--- a/numbers
+	+++ b/numbers
+	@@ -1,10 +1,6 @@
+	 1
+	 2
+	-<<<<<<< 96f1e45 (side1)
+	-three
+	-=======
+	 drei
+	->>>>>>> 4fd522f (side2)
+	 4
+	 5
+	 6
+	EOF
+	# We still have some sha1 hashes above; rip them out so test works
+	# with sha256
+	sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
+
+	git show --oneline --remerge-diff newresolution -- numbers >tmp &&
 	sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
 	test_cmp expect actual
 '
-- 
gitgitgadget



[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