git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/3] Some small fixes to merge-recursive and tests
@ 2018-01-05 20:19 Elijah Newren
  2018-01-05 20:19 ` [PATCH 1/3] Tighten and correct a few testcases for merging and cherry-picking Elijah Newren
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Elijah Newren @ 2018-01-05 20:19 UTC (permalink / raw)
  To: gitster; +Cc: git, sbeller, Elijah Newren

These three patches were the first three from
en/rename-directory-detection[1], but as Stefan suggested[2], I'm submitting
them separately as they are independent fixes.

Change from PATCHv5-rename-directory-detection:
  * Split from the rest of the series.
  * Added Stefan's Reviewed-By.

[1] https://public-inbox.org/git/20171228041352.27880-1-newren@gmail.com/
[2] https://public-inbox.org/git/CAGZ79kapuEKLO4RUUPVS6_-aeBERDhjpBAtmK=gycT8GaK2bFg@mail.gmail.com/

Elijah Newren (3):
  Tighten and correct a few testcases for merging and cherry-picking
  merge-recursive: fix logic ordering issue
  merge-recursive: add explanation for src_entry and dst_entry

 merge-recursive.c             | 21 ++++++++++++++++++++-
 t/t3501-revert-cherry-pick.sh |  7 +++++--
 t/t7607-merge-overwrite.sh    |  5 ++++-
 3 files changed, 29 insertions(+), 4 deletions(-)

-- 
2.14.2

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] Tighten and correct a few testcases for merging and cherry-picking
  2018-01-05 20:19 [PATCH 0/3] Some small fixes to merge-recursive and tests Elijah Newren
@ 2018-01-05 20:19 ` Elijah Newren
  2018-01-05 21:24   ` Johannes Schindelin
  2018-01-05 20:20 ` [PATCH 2/3] merge-recursive: fix logic ordering issue Elijah Newren
  2018-01-05 20:20 ` [PATCH 3/3] merge-recursive: add explanation for src_entry and dst_entry Elijah Newren
  2 siblings, 1 reply; 7+ messages in thread
From: Elijah Newren @ 2018-01-05 20:19 UTC (permalink / raw)
  To: gitster; +Cc: git, sbeller, Elijah Newren

t3501 had a testcase originally added in 05f2dfb965 (cherry-pick:
demonstrate a segmentation fault, 2016-11-26) to ensure cherry-pick
wouldn't segfault when working with a dirty file involved in a rename.
While the segfault was fixed, there was another problem this test
demonstrated: namely, that git would overwrite a dirty file involved in a
rename.  Further, the test encoded a "successful merge" and overwriting of
this file as correct behavior.  Modify the test so that it would still
catch the segfault, but to require the correct behavior.  Mark it as
test_expect_failure for now too, since this second bug is not yet fixed.

t7607 had a test added in 30fd3a5425 (merge overwrites unstaged changes in
renamed file, 2012-04-15) specific to looking for a merge overwriting a
dirty file involved in a rename, but it too actually encoded what I would
term incorrect behavior: it expected the merge to succeed.  Fix that, and
add a few more checks to make sure that the merge really does produce the
expected results.

Reviewed-By: Stefan Beller <sbeller@google.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
---
 t/t3501-revert-cherry-pick.sh | 7 +++++--
 t/t7607-merge-overwrite.sh    | 5 ++++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh
index 4f2a263b6..783bdbf59 100755
--- a/t/t3501-revert-cherry-pick.sh
+++ b/t/t3501-revert-cherry-pick.sh
@@ -141,7 +141,7 @@ test_expect_success 'cherry-pick "-" works with arguments' '
 	test_cmp expect actual
 '
 
-test_expect_success 'cherry-pick works with dirty renamed file' '
+test_expect_failure 'cherry-pick works with dirty renamed file' '
 	test_commit to-rename &&
 	git checkout -b unrelated &&
 	test_commit unrelated &&
@@ -150,7 +150,10 @@ test_expect_success 'cherry-pick works with dirty renamed file' '
 	test_tick &&
 	git commit -m renamed &&
 	echo modified >renamed &&
-	git cherry-pick refs/heads/unrelated
+	test_must_fail git cherry-pick refs/heads/unrelated >out &&
+	test_i18ngrep "Refusing to lose dirty file at renamed" out &&
+	test $(git rev-parse :0:renamed) = $(git rev-parse HEAD^:to-rename.t) &&
+	grep -q "^modified$" renamed
 '
 
 test_done
diff --git a/t/t7607-merge-overwrite.sh b/t/t7607-merge-overwrite.sh
index 9444d6a9b..9c422bcd7 100755
--- a/t/t7607-merge-overwrite.sh
+++ b/t/t7607-merge-overwrite.sh
@@ -97,7 +97,10 @@ test_expect_failure 'will not overwrite unstaged changes in renamed file' '
 	git mv c1.c other.c &&
 	git commit -m rename &&
 	cp important other.c &&
-	git merge c1a &&
+	test_must_fail git merge c1a >out &&
+	test_i18ngrep "Refusing to lose dirty file at other.c" out &&
+	test_path_is_file other.c~HEAD &&
+	test $(git hash-object other.c~HEAD) = $(git rev-parse c1a:c1.c) &&
 	test_cmp important other.c
 '
 
-- 
2.14.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] merge-recursive: fix logic ordering issue
  2018-01-05 20:19 [PATCH 0/3] Some small fixes to merge-recursive and tests Elijah Newren
  2018-01-05 20:19 ` [PATCH 1/3] Tighten and correct a few testcases for merging and cherry-picking Elijah Newren
@ 2018-01-05 20:20 ` Elijah Newren
  2018-01-05 21:22   ` Johannes Schindelin
  2018-01-05 20:20 ` [PATCH 3/3] merge-recursive: add explanation for src_entry and dst_entry Elijah Newren
  2 siblings, 1 reply; 7+ messages in thread
From: Elijah Newren @ 2018-01-05 20:20 UTC (permalink / raw)
  To: gitster; +Cc: git, sbeller, Elijah Newren

merge_trees() did a variety of work, including:
  * Calling get_unmerged() to get unmerged entries
  * Calling record_df_conflict_files() with all unmerged entries to
    do some work to ensure we could handle D/F conflicts correctly
  * Calling get_renames() to check for renames.

An easily overlooked issue is that get_renames() can create more
unmerged entries and add them to the list, which have the possibility of
being involved in D/F conflicts.  So the call to
record_df_conflict_files() should really be moved after all the rename
detection.  I didn't come up with any testcases demonstrating any bugs
with the old ordering, but I suspect there were some for both normal
renames and for directory renames.  Fix the ordering.

Reviewed-By: Stefan Beller <sbeller@google.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
---
 merge-recursive.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index d00b27438..98c84e73d 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1982,10 +1982,10 @@ int merge_trees(struct merge_options *o,
 		get_files_dirs(o, merge);
 
 		entries = get_unmerged();
-		record_df_conflict_files(o, entries);
 		re_head  = get_renames(o, head, common, head, merge, entries);
 		re_merge = get_renames(o, merge, common, head, merge, entries);
 		clean = process_renames(o, re_head, re_merge);
+		record_df_conflict_files(o, entries);
 		if (clean < 0)
 			goto cleanup;
 		for (i = entries->nr-1; 0 <= i; i--) {
-- 
2.14.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] merge-recursive: add explanation for src_entry and dst_entry
  2018-01-05 20:19 [PATCH 0/3] Some small fixes to merge-recursive and tests Elijah Newren
  2018-01-05 20:19 ` [PATCH 1/3] Tighten and correct a few testcases for merging and cherry-picking Elijah Newren
  2018-01-05 20:20 ` [PATCH 2/3] merge-recursive: fix logic ordering issue Elijah Newren
@ 2018-01-05 20:20 ` Elijah Newren
  2018-01-05 21:26   ` Johannes Schindelin
  2 siblings, 1 reply; 7+ messages in thread
From: Elijah Newren @ 2018-01-05 20:20 UTC (permalink / raw)
  To: gitster; +Cc: git, sbeller, Elijah Newren

If I have to walk through the debugger and inspect the values found in
here in order to figure out their meaning, despite having known these
things inside and out some years back, then they probably need a comment
for the casual reader to explain their purpose.

Reviewed-By: Stefan Beller <sbeller@google.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
---
 merge-recursive.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/merge-recursive.c b/merge-recursive.c
index 98c84e73d..d78853d5e 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -513,6 +513,25 @@ static void record_df_conflict_files(struct merge_options *o,
 
 struct rename {
 	struct diff_filepair *pair;
+	/*
+	 * Purpose of src_entry and dst_entry:
+	 *
+	 * If 'before' is renamed to 'after' then src_entry will contain
+	 * the versions of 'before' from the merge_base, HEAD, and MERGE in
+	 * stages 1, 2, and 3; dst_entry will contain the respective
+	 * versions of 'after' in corresponding locations.  Thus, we have a
+	 * total of six modes and oids, though some will be null.  (Stage 0
+	 * is ignored; we're interested in handling conflicts.)
+	 *
+	 * Since we don't turn on break-rewrites by default, neither
+	 * src_entry nor dst_entry can have all three of their stages have
+	 * non-null oids, meaning at most four of the six will be non-null.
+	 * Also, since this is a rename, both src_entry and dst_entry will
+	 * have at least one non-null oid, meaning at least two will be
+	 * non-null.  Of the six oids, a typical rename will have three be
+	 * non-null.  Only two implies a rename/delete, and four implies a
+	 * rename/add.
+	 */
 	struct stage_data *src_entry;
 	struct stage_data *dst_entry;
 	unsigned processed:1;
-- 
2.14.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] merge-recursive: fix logic ordering issue
  2018-01-05 20:20 ` [PATCH 2/3] merge-recursive: fix logic ordering issue Elijah Newren
@ 2018-01-05 21:22   ` Johannes Schindelin
  0 siblings, 0 replies; 7+ messages in thread
From: Johannes Schindelin @ 2018-01-05 21:22 UTC (permalink / raw)
  To: Elijah Newren; +Cc: gitster, git, sbeller

Hi Elijah,

On Fri, 5 Jan 2018, Elijah Newren wrote:

> merge_trees() did a variety of work, including:
>   * Calling get_unmerged() to get unmerged entries
>   * Calling record_df_conflict_files() with all unmerged entries to
>     do some work to ensure we could handle D/F conflicts correctly
>   * Calling get_renames() to check for renames.
> 
> An easily overlooked issue is that get_renames() can create more
> unmerged entries and add them to the list, which have the possibility of
> being involved in D/F conflicts.  So the call to
> record_df_conflict_files() should really be moved after all the rename
> detection.

I cannot actually see how the *current* rename detection would result in
D/F conflicts, as it is really only about detecting the renames, the
conflicts should have happened earlier.

But I could imagine that your "detect directory renames" patch series
changes this behavior.

In any case, the reordering does not hurt.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] Tighten and correct a few testcases for merging and cherry-picking
  2018-01-05 20:19 ` [PATCH 1/3] Tighten and correct a few testcases for merging and cherry-picking Elijah Newren
@ 2018-01-05 21:24   ` Johannes Schindelin
  0 siblings, 0 replies; 7+ messages in thread
From: Johannes Schindelin @ 2018-01-05 21:24 UTC (permalink / raw)
  To: Elijah Newren; +Cc: gitster, git, sbeller

Hi Elijah,

On Fri, 5 Jan 2018, Elijah Newren wrote:

> t3501 had a testcase originally added in 05f2dfb965 (cherry-pick:
> demonstrate a segmentation fault, 2016-11-26) to ensure cherry-pick
> wouldn't segfault when working with a dirty file involved in a rename.
>
> While the segfault was fixed, there was another problem this test
> demonstrated: namely, that git would overwrite a dirty file involved in a
> rename.  Further, the test encoded a "successful merge" and overwriting of
> this file as correct behavior.

Whoops. Sorry about that. Thanks for the patch, looks obviously good (I
haven't read 3/3 yet, but figure that the error message stems from the
changes introduced in that patch).

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] merge-recursive: add explanation for src_entry and dst_entry
  2018-01-05 20:20 ` [PATCH 3/3] merge-recursive: add explanation for src_entry and dst_entry Elijah Newren
@ 2018-01-05 21:26   ` Johannes Schindelin
  0 siblings, 0 replies; 7+ messages in thread
From: Johannes Schindelin @ 2018-01-05 21:26 UTC (permalink / raw)
  To: Elijah Newren; +Cc: gitster, git, sbeller

Hi Elijah,

On Fri, 5 Jan 2018, Elijah Newren wrote:

> If I have to walk through the debugger and inspect the values found in
> here in order to figure out their meaning, despite having known these
> things inside and out some years back, then they probably need a comment
> for the casual reader to explain their purpose.

Makes sense.

Thanks,
Dscho

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-01-05 21:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-05 20:19 [PATCH 0/3] Some small fixes to merge-recursive and tests Elijah Newren
2018-01-05 20:19 ` [PATCH 1/3] Tighten and correct a few testcases for merging and cherry-picking Elijah Newren
2018-01-05 21:24   ` Johannes Schindelin
2018-01-05 20:20 ` [PATCH 2/3] merge-recursive: fix logic ordering issue Elijah Newren
2018-01-05 21:22   ` Johannes Schindelin
2018-01-05 20:20 ` [PATCH 3/3] merge-recursive: add explanation for src_entry and dst_entry Elijah Newren
2018-01-05 21:26   ` Johannes Schindelin

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).