All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
@ 2015-10-08 20:35 Johannes Schindelin
  2015-10-08 20:35 ` [PATCH 1/2] merge_recursive_options: introduce the "gentle" flag Johannes Schindelin
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Johannes Schindelin @ 2015-10-08 20:35 UTC (permalink / raw)
  To: gitster; +Cc: Brendan Forster, git

Brendan Forster noticed that we no longer see the helpful message after
a failed `git pull --rebase`. It turns out that the builtin `am` calls
the recursive merge function directly, not via a separate process. But
that function was not really safe to be called that way, as it die()s
pretty liberally.

As a consequence, the code that wanted to see whether the merge failed
is not even executed, and the helpful message advising how to fix the
mess is not displayed.

This topic branch fixes this.

Please note that there are a couple of unhandled die() calls in
merge-recursive.c, most of which indicate code paths that should
never be reached (except in the case of a bug).

But there are two other functions that can die(): `update_file_flags()`
(which returns void) and `merge_file_1()`.

The latter function is already nested quite deeply so that the code
would have to be made much uglier to handle the `gentle` flag. It is
also not quite clear to me whether those error cases can be hit in a
regular `git pull --rebase` (which is what I really care about most).

As `update_file_flags()` is called by functions returning void and
that are again called in turn by other functions that also return void,
fixing this part is more involved, so I would like to avoid it, unless
it is deemed absolutely necessary to address in this patch series.


Johannes Schindelin (2):
  merge_recursive_options: introduce the "gentle" flag
  pull --rebase: reinstate helpful message on abort

 builtin/am.c      |  1 +
 merge-recursive.c | 44 +++++++++++++++++++++++++++++++++++---------
 merge-recursive.h |  1 +
 3 files changed, 37 insertions(+), 9 deletions(-)

-- 
2.6.1.windows.1

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

* [PATCH 1/2] merge_recursive_options: introduce the "gentle" flag
  2015-10-08 20:35 [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails Johannes Schindelin
@ 2015-10-08 20:35 ` Johannes Schindelin
  2015-10-08 20:35 ` [PATCH 2/2] pull --rebase: reinstate helpful message on abort Johannes Schindelin
  2015-10-09  0:52 ` [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails Junio C Hamano
  2 siblings, 0 replies; 22+ messages in thread
From: Johannes Schindelin @ 2015-10-08 20:35 UTC (permalink / raw)
  To: gitster; +Cc: Brendan Forster, git

Traditionally, all of Git's operations were intended as single
executables to be run once and exit, not as library functions with
careful error code paths. Therefore, it was okay for those operations
to simply die() with an error.

However, this assumption no longer holds true: builtin `am` calls
merge_recursive_generic() as a regular library function whose return
value indicates whether there was a problem.

Throughout Git's source code, that paradigm (to return an error instead
of die()ing) is called "gentle".

Let's introduce this flag and heed it in as many places as is easily
done.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 merge-recursive.c | 44 +++++++++++++++++++++++++++++++++++---------
 merge-recursive.h |  1 +
 2 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index 44d85be..37528c9 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -266,8 +266,12 @@ struct tree *write_tree_from_memory(struct merge_options *o)
 		active_cache_tree = cache_tree();
 
 	if (!cache_tree_fully_valid(active_cache_tree) &&
-	    cache_tree_update(&the_index, 0) < 0)
-		die(_("error building trees"));
+	    cache_tree_update(&the_index, 0) < 0) {
+		if (!o->gentle)
+			die(_("error building trees"));
+		error(_("error building trees"));
+		return NULL;
+	}
 
 	result = lookup_tree(active_cache_tree->sha1);
 
@@ -712,6 +716,8 @@ static int make_room_for_path(struct merge_options *o, const char *path)
 			error(msg, path, _(": perhaps a D/F conflict?"));
 			return -1;
 		}
+		if (o->gentle)
+			return error(msg, path, "");
 		die(msg, path, "");
 	}
 
@@ -1340,8 +1346,11 @@ static int process_renames(struct merge_options *o,
 			const char *ren2_src = ren2->pair->one->path;
 			const char *ren2_dst = ren2->pair->two->path;
 			enum rename_type rename_type;
-			if (strcmp(ren1_src, ren2_src) != 0)
+			if (strcmp(ren1_src, ren2_src) != 0) {
+				if (o->gentle)
+					return error("ren1_src != ren2_src");
 				die("ren1_src != ren2_src");
+			}
 			ren2->dst_entry->processed = 1;
 			ren2->processed = 1;
 			if (strcmp(ren1_dst, ren2_dst) != 0) {
@@ -1374,8 +1383,11 @@ static int process_renames(struct merge_options *o,
 			char *ren2_dst;
 			ren2 = lookup->util;
 			ren2_dst = ren2->pair->two->path;
-			if (strcmp(ren1_dst, ren2_dst) != 0)
+			if (strcmp(ren1_dst, ren2_dst) != 0) {
+				if (o->gentle)
+					return error("ren1_dst != ren2_dst");
 				die("ren1_dst != ren2_dst");
+			}
 
 			clean_merge = 0;
 			ren2->processed = 1;
@@ -1818,6 +1830,11 @@ int merge_trees(struct merge_options *o,
 	code = git_merge_trees(o->call_depth, common, head, merge);
 
 	if (code != 0) {
+		if (o->gentle)
+			return error(_("merging of trees %s and %s failed"),
+			    sha1_to_hex(head->object.sha1),
+			    sha1_to_hex(merge->object.sha1));
+
 		if (show(o, 4) || o->call_depth)
 			die(_("merging of trees %s and %s failed"),
 			    sha1_to_hex(head->object.sha1),
@@ -1864,8 +1881,8 @@ int merge_trees(struct merge_options *o,
 	else
 		clean = 1;
 
-	if (o->call_depth)
-		*result = write_tree_from_memory(o);
+	if (o->call_depth && !(*result = write_tree_from_memory(o)))
+		return -1;
 
 	return clean;
 }
@@ -1940,14 +1957,18 @@ int merge_recursive(struct merge_options *o,
 		saved_b2 = o->branch2;
 		o->branch1 = "Temporary merge branch 1";
 		o->branch2 = "Temporary merge branch 2";
-		merge_recursive(o, merged_common_ancestors, iter->item,
-				NULL, &merged_common_ancestors);
+		if (merge_recursive(o, merged_common_ancestors, iter->item,
+				NULL, &merged_common_ancestors) < 0)
+			return -1;
 		o->branch1 = saved_b1;
 		o->branch2 = saved_b2;
 		o->call_depth--;
 
-		if (!merged_common_ancestors)
+		if (!merged_common_ancestors) {
+			if (o->gentle)
+				return error(_("merge returned no commit"));
 			die(_("merge returned no commit"));
+		}
 	}
 
 	discard_cache();
@@ -1957,6 +1978,8 @@ int merge_recursive(struct merge_options *o,
 	o->ancestor = "merged common ancestors";
 	clean = merge_trees(o, h1->tree, h2->tree, merged_common_ancestors->tree,
 			    &mrtree);
+	if (clean < 0)
+		return clean;
 
 	if (o->call_depth) {
 		*result = make_virtual_commit(mrtree, "merged tree");
@@ -2013,6 +2036,9 @@ int merge_recursive_generic(struct merge_options *o,
 	hold_locked_index(lock, 1);
 	clean = merge_recursive(o, head_commit, next_commit, ca,
 			result);
+	if (clean < 0)
+		return clean;
+
 	if (active_cache_changed &&
 	    write_locked_index(&the_index, lock, COMMIT_LOCK))
 		return error(_("Unable to write index."));
diff --git a/merge-recursive.h b/merge-recursive.h
index 9e090a3..06f9b7e 100644
--- a/merge-recursive.h
+++ b/merge-recursive.h
@@ -15,6 +15,7 @@ struct merge_options {
 	const char *subtree_shift;
 	unsigned buffer_output : 1;
 	unsigned renormalize : 1;
+	unsigned gentle : 1;
 	long xdl_opts;
 	int verbosity;
 	int diff_rename_limit;
-- 
2.6.1.windows.1

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

* [PATCH 2/2] pull --rebase: reinstate helpful message on abort
  2015-10-08 20:35 [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails Johannes Schindelin
  2015-10-08 20:35 ` [PATCH 1/2] merge_recursive_options: introduce the "gentle" flag Johannes Schindelin
@ 2015-10-08 20:35 ` Johannes Schindelin
  2015-10-09 18:36   ` Junio C Hamano
  2015-10-09  0:52 ` [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails Junio C Hamano
  2 siblings, 1 reply; 22+ messages in thread
From: Johannes Schindelin @ 2015-10-08 20:35 UTC (permalink / raw)
  To: gitster; +Cc: Brendan Forster, git

When calling `git pull --rebase`, things can go wrong. In such a case,
we want to tell the user about the most common ways out of this fix:

	Patch failed at [...]
	[...]

	When you have resolved this problem, run "git rebase
	--continue". If you prefer to skip this patch, run "git rebase
	--skip" instead. To check out the original branch and stop
	rebasing, run "git rebase --abort".

However, with the switch to the builtin `git-am` we call the merge
recursive function directly, which usually die()s in case of an
error. Not what we want.

So let's set the newly-introduced `gentle` flag to get a chance to
print the helpful advice.

Reported by Brendan Forster.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/am.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/builtin/am.c b/builtin/am.c
index 4f77e07..c472937 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1653,6 +1653,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
 
 	init_merge_options(&o);
 
+	o.gentle = 1;
 	o.branch1 = "HEAD";
 	his_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg);
 	o.branch2 = his_tree_name;
-- 
2.6.1.windows.1

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-08 20:35 [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails Johannes Schindelin
  2015-10-08 20:35 ` [PATCH 1/2] merge_recursive_options: introduce the "gentle" flag Johannes Schindelin
  2015-10-08 20:35 ` [PATCH 2/2] pull --rebase: reinstate helpful message on abort Johannes Schindelin
@ 2015-10-09  0:52 ` Junio C Hamano
  2015-10-09  1:40   ` Paul Tan
  2 siblings, 1 reply; 22+ messages in thread
From: Junio C Hamano @ 2015-10-09  0:52 UTC (permalink / raw)
  To: Paul Tan; +Cc: Johannes Schindelin, Brendan Forster, git

Johannes Schindelin <johannes.schindelin@gmx.de> writes:

> Brendan Forster noticed that we no longer see the helpful message after
> a failed `git pull --rebase`. It turns out that the builtin `am` calls
> the recursive merge function directly, not via a separate process.
>
> But that function was not really safe to be called that way, as it
> die()s pretty liberally.

If that is the case, I'd thinkg that we'd prefer, as a regression
fix to correct "that", i.e., let recursive-merge die and let the
caller catch its exit status.

Paul, what do you think?

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-09  0:52 ` [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails Junio C Hamano
@ 2015-10-09  1:40   ` Paul Tan
  2015-10-09  9:50     ` Johannes Schindelin
  2015-10-09 18:15     ` Junio C Hamano
  0 siblings, 2 replies; 22+ messages in thread
From: Paul Tan @ 2015-10-09  1:40 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes Schindelin, Brendan Forster, Git List

On Fri, Oct 9, 2015 at 8:52 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>
>> Brendan Forster noticed that we no longer see the helpful message after
>> a failed `git pull --rebase`. It turns out that the builtin `am` calls
>> the recursive merge function directly, not via a separate process.
>>
>> But that function was not really safe to be called that way, as it
>> die()s pretty liberally.

I'm not too familiar with the merge-recursive.c code, but I was under
the impression that it only called die() under fatal conditions. In
common use cases, such as merge conflicts, it just errors out and the
helpful error message does get printed. Is there a reproduction recipe
for this?

That said, I do agree that even if we die(), we could try to be more
helpful by printing additional helpful instructions.

> If that is the case, I'd thinkg that we'd prefer, as a regression
> fix to correct "that", i.e., let recursive-merge die and let the
> caller catch its exit status.

We could do that, but I don't think it would be worth the overhead to
spawn an additional process for every patch just to print an
additional message should merge_recursive() call die().

Instead, stepping back a bit, I wonder if we can extend coverage of
the helpful message to all die() calls when running git-am. We could
just install a die routine with set_die_routine() in builtin/am.c.
Then, should die() be called anywhere, the helpful error message will
be printed as well. fast-import.c and http-backend.c seem to do this.

Regards,
Paul

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-09  1:40   ` Paul Tan
@ 2015-10-09  9:50     ` Johannes Schindelin
  2015-10-09 10:11       ` Johannes Schindelin
  2015-10-09 18:15     ` Junio C Hamano
  1 sibling, 1 reply; 22+ messages in thread
From: Johannes Schindelin @ 2015-10-09  9:50 UTC (permalink / raw)
  To: Paul Tan; +Cc: Junio C Hamano, Brendan Forster, Git List

Hi Junio & Paul,

On 2015-10-09 03:40, Paul Tan wrote:
> On Fri, Oct 9, 2015 at 8:52 AM, Junio C Hamano <gitster@pobox.com> wrote:
>> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>>
>>> Brendan Forster noticed that we no longer see the helpful message after
>>> a failed `git pull --rebase`. It turns out that the builtin `am` calls
>>> the recursive merge function directly, not via a separate process.
>>>
>>> But that function was not really safe to be called that way, as it
>>> die()s pretty liberally.
> 
> I'm not too familiar with the merge-recursive.c code, but I was under
> the impression that it only called die() under fatal conditions. In
> common use cases, such as merge conflicts, it just errors out and the
> helpful error message does get printed. Is there a reproduction recipe
> for this?

Yes. Sorry, I should have added that as part of the patch series. Actually, I should have written it *before* making those patches. Because it revealed that the underlying problem is completely different: *Normally* you are correct, if `pull --rebase` fails with a merge conflict, the advice is shown.

The problem occurs with CR/LF.

I have a reproducer and will wiggle it down to a proper test case.

>> If that is the case, I'd thinkg that we'd prefer, as a regression
>> fix to correct "that", i.e., let recursive-merge die and let the
>> caller catch its exit status.
> 
> We could do that, but I don't think it would be worth the overhead to
> spawn an additional process for every patch just to print an
> additional message should merge_recursive() call die().

I would hope that we do not go that direction! The benefit of making `am` a builtin was to *avoid* spawning, after all. Let's not make the experience for Windows users *worse* again.

> Instead, stepping back a bit, I wonder if we can extend coverage of
> the helpful message to all die() calls when running git-am. We could
> just install a die routine with set_die_routine() in builtin/am.c.
> Then, should die() be called anywhere, the helpful error message will
> be printed as well. fast-import.c and http-backend.c seem to do this.

This looks more like a work-around to me. In general, I think it is not really a good idea to treat each and every code path as if it is safe to die(). That would just preclude the code from being used as a library function.

But it looks more and more as if the problem lies with the CR/LF handling of Git. Will keep you posted.

Ciao,
Dscho

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-09  9:50     ` Johannes Schindelin
@ 2015-10-09 10:11       ` Johannes Schindelin
  2015-10-09 20:49         ` Junio C Hamano
                           ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Johannes Schindelin @ 2015-10-09 10:11 UTC (permalink / raw)
  To: Paul Tan; +Cc: Junio C Hamano, Brendan Forster, Git List

Me again,

On 2015-10-09 11:50, Johannes Schindelin wrote:
> 
> On 2015-10-09 03:40, Paul Tan wrote:
>> On Fri, Oct 9, 2015 at 8:52 AM, Junio C Hamano <gitster@pobox.com> wrote:
>>> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>>>
>>>> Brendan Forster noticed that we no longer see the helpful message after
>>>> a failed `git pull --rebase`. It turns out that the builtin `am` calls
>>>> the recursive merge function directly, not via a separate process.
>>>>
>>>> But that function was not really safe to be called that way, as it
>>>> die()s pretty liberally.
>>
>> I'm not too familiar with the merge-recursive.c code, but I was under
>> the impression that it only called die() under fatal conditions. In
>> common use cases, such as merge conflicts, it just errors out and the
>> helpful error message does get printed. Is there a reproduction recipe
>> for this?
> 
> Yes. Sorry, I should have added that as part of the patch series.
> Actually, I should have written it *before* making those patches.
> Because it revealed that the underlying problem is completely
> different: *Normally* you are correct, if `pull --rebase` fails with a
> merge conflict, the advice is shown.
> 
> The problem occurs with CR/LF.

I finally have that test case working, took way longer than I wanted to:

-- snip --
Subject: [PATCH 3/2] Verify that `git pull --rebase` shows the helpful advice when failing
Author: Johannes Schindelin <johannes.schindelin@gmx.de>
Date:   Fri Oct 9 11:15:30 2015 +0200
    
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index a0013ee..bce332f 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -237,6 +237,18 @@ test_expect_success '--rebase' '
 	test new = "$(git show HEAD:file2)"
 '
 
+test_expect_success 'failed --rebase shows advice' '
+	git checkout -b diverging &&
+	test_commit attributes .gitattributes "* text=auto" attrs &&
+	sha1="$(printf "1\\r\\n" | git hash-object -w --stdin)" &&
+	git update-index --cacheinfo 0644 $sha1 file &&
+	git commit -m v1-with-cr &&
+	git checkout -f -b fails-to-rebase HEAD^ &&
+	test_commit v2-without-cr file "2" file2-lf &&
+	test_must_fail git pull --rebase . diverging 2>err >out &&
+	grep "When you have resolved this problem" out
+'
+
 test_expect_success '--rebase fails with multiple branches' '
 	git reset --hard before-rebase &&
 	test_must_fail git pull --rebase . copy master 2>err &&
--

So the reason is that `unpack_trees()` fails with

    error: Your local changes to the following files would be overwritten by merge:
	file
    Please, commit your changes or stash them before you can merge.

then returns -1 to its caller, `git_merge_trees()`, which still returns -1 in turn to *its* caller, `merge_trees()`, which then gives up by die()ing:

    Aborting

I think there is more than one fix necessary to truly address the issue: the underlying problem is that Git handles *committed* CR/LF really badly when the corresponding `.gitattributes` label the file as `text=auto`. In fact, those files are labeled as modified in `git status`. If you change the line endings of them, they are labeled as modified in `git status`. And after a `git reset --hard`, they are *still* labeled as modified in `git status`.

I will try to make some time to continue to work on this later today, but in the meantime I would be relatively happy if we could introduce that gentle flag. It is really a very gentle patch, after all, much gentler than reverting to the heavy-handed spawning of `merge-recursive`.

Ciao,
Dscho

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-09  1:40   ` Paul Tan
  2015-10-09  9:50     ` Johannes Schindelin
@ 2015-10-09 18:15     ` Junio C Hamano
  2015-10-09 18:40       ` Junio C Hamano
  1 sibling, 1 reply; 22+ messages in thread
From: Junio C Hamano @ 2015-10-09 18:15 UTC (permalink / raw)
  To: Paul Tan; +Cc: Johannes Schindelin, Brendan Forster, Git List

Paul Tan <pyokagan@gmail.com> writes:

> That said, I do agree that even if we die(), we could try to be more
> helpful by printing additional helpful instructions.
>
>> If that is the case, I'd thinkg that we'd prefer, as a regression
>> fix to correct "that", i.e., let recursive-merge die and let the
>> caller catch its exit status.
>
> We could do that, but I don't think it would be worth the overhead to
> spawn an additional process for every patch just to print an
> additional message should merge_recursive() call die().

For a thing that (1) has to be run every time in the whole operation
and (2) is a very small operation itself whose runtime cost can be
dwarfed by cost of spawning on some platforms, it is clearly better
to run it internally instead of running it via run_command()
interface.  This is especially so if it (3) wants to just kill the
whole operation when it finds a problem anyway.  For example, it
would be crazy to run "update-ref" via run_command() in the "am"
that is rewritten in C.

But does the same reasoning apply to the use of merge-recursive in
"am -3" codepath, where it (1) runs only as a fallback when straight
application of the patch fails, (2) runs a heavy-weight recursive
merge machinery, and (3) now a regression is pointed out that it
wants to do more than just calling die() when there is a problem?

You seem to be viewing the world in black-and-white and thinking
that run_command() is unconditionally bad.  You need to stop doing
that.  Instead, view it as another tool that gives a much better
isolation from the main flow of logic (hence flexiblity) that comes
with a bigger cost.  I am not convinced with your "I don't think it
would be worth".

> Instead, stepping back a bit, I wonder if we can extend coverage of
> the helpful message to all die() calls when running git-am. We could
> just install a die routine with set_die_routine() in builtin/am.c.
> Then, should die() be called anywhere, the helpful error message will
> be printed as well.

That could certainly be a valid approach and may give us a better
end result.  If it works, it could be a change that is localized
with a lot less impact.

Thanks.

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

* Re: [PATCH 2/2] pull --rebase: reinstate helpful message on abort
  2015-10-08 20:35 ` [PATCH 2/2] pull --rebase: reinstate helpful message on abort Johannes Schindelin
@ 2015-10-09 18:36   ` Junio C Hamano
  2015-10-12  9:16     ` Johannes Schindelin
  0 siblings, 1 reply; 22+ messages in thread
From: Junio C Hamano @ 2015-10-09 18:36 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Brendan Forster, git

Johannes Schindelin <johannes.schindelin@gmx.de> writes:

> When calling `git pull --rebase`, things can go wrong. In such a case,
> we want to tell the user about the most common ways out of this fix:
> ...
>  builtin/am.c | 1 +
>  1 file changed, 1 insertion(+)

It is strange to see a patch to am that does not talk anything about
it, though.  And looking at the codepath, the issue does not have
much to do with "pull --rebase".  It doesn't even have much to do
with "rebase".  This is purely about "am -3" fallback codepath.

Because fall-back-threeway wants to react to an error (i.e. calls
merge_recursive_generic() and wants to use its return value), but
merge_recursive_generic() can die, it fails to do so.  It would not
even run rerere(), for example.

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-09 18:15     ` Junio C Hamano
@ 2015-10-09 18:40       ` Junio C Hamano
  2015-10-09 18:55         ` Junio C Hamano
                           ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Junio C Hamano @ 2015-10-09 18:40 UTC (permalink / raw)
  To: Paul Tan; +Cc: Johannes Schindelin, Brendan Forster, Git List

Junio C Hamano <gitster@pobox.com> writes:

>> Instead, stepping back a bit, I wonder if we can extend coverage of
>> the helpful message to all die() calls when running git-am. We could
>> just install a die routine with set_die_routine() in builtin/am.c.
>> Then, should die() be called anywhere, the helpful error message will
>> be printed as well.
>
> That could certainly be a valid approach and may give us a better
> end result.  If it works, it could be a change that is localized
> with a lot less impact.

I looked at the codepath involved, and I do not think that is a
feasible way forward in this case.  It is not about a "helpful
message" at all.  You would have to do everything that is done in
the error codepath in your custom die routine, which does not make
much sense.

I think the most sensible regression fix as the first step at this
point is to call it as a separate process, just like the code calls
"apply" as a separate process for each patch.  Optimization can come
later when it is shown that it matters---we need to regain
correctness first.

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-09 18:40       ` Junio C Hamano
@ 2015-10-09 18:55         ` Junio C Hamano
  2015-10-12  9:46           ` Johannes Schindelin
  2015-10-09 20:46         ` Junio C Hamano
  2015-10-12  9:40         ` Johannes Schindelin
  2 siblings, 1 reply; 22+ messages in thread
From: Junio C Hamano @ 2015-10-09 18:55 UTC (permalink / raw)
  To: Paul Tan; +Cc: Johannes Schindelin, Brendan Forster, Git List

Junio C Hamano <gitster@pobox.com> writes:

> I looked at the codepath involved, and I do not think that is a
> feasible way forward in this case.  It is not about a "helpful
> message" at all.  You would have to do everything that is done in
> the error codepath in your custom die routine, which does not make
> much sense.
>
> I think the most sensible regression fix as the first step at this
> point is to call it as a separate process, just like the code calls
> "apply" as a separate process for each patch.  Optimization can come
> later when it is shown that it matters---we need to regain
> correctness first.

Don't get me wrong by the above, though.

I would prefer the endgame to be an efficient implementation of
merge_recursive_generic(), a function that you can call without you
having to worry about it dying.

But the patch in this thread is not that, if I am reading Johannes's
description correctly.  

And by calling merge_recursive_generic() instead of spawning
merge-recursive via run_command(), your GSoC series introduced a
regression to "am -3".  I'd like to see the regression fixed, and
spawning merge-recursive is an obviously correct way to do so.

That is how "am -3" did it before builtin/am.c after all.

Once that is done, the users will not have to worry about this
regression, and merge_recursive_generic() implementation can be
improved separately.  The patch in this thread may serve as a good
starting point for that.

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-09 18:40       ` Junio C Hamano
  2015-10-09 18:55         ` Junio C Hamano
@ 2015-10-09 20:46         ` Junio C Hamano
  2015-10-12  9:40         ` Johannes Schindelin
  2 siblings, 0 replies; 22+ messages in thread
From: Junio C Hamano @ 2015-10-09 20:46 UTC (permalink / raw)
  To: Paul Tan; +Cc: Johannes Schindelin, Brendan Forster, Git List

Junio C Hamano <gitster@pobox.com> writes:

> I think the most sensible regression fix as the first step at this
> point is to call it as a separate process, just like the code calls
> "apply" as a separate process for each patch.  Optimization can come
> later when it is shown that it matters---we need to regain
> correctness first.

And the fix would look like this, I think.

It passes the test Dscho's 3/2 adds to t5520 ;-) but that is not
surprising.

---
Subject: [PATCH] am -3: do not let failed merge abort the error codepath

When "am" was rewritten in C, the codepath for falling back to
three-way merge was mistakenly made to make an internal call to
merge-recursive, disabling the error reporting code for certain
types of errors merge-recursive detects and reports by calling
die().

This is a quick-fix for correctness.  The ideal endgame would be to
replace run_command() in run_fallback_merge_recursive() with a
direct call after making sure that internal call to merge-recursive
does not die().

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/am.c | 49 +++++++++++++++++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 16 deletions(-)

diff --git a/builtin/am.c b/builtin/am.c
index 4f77e07..c869796 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1590,16 +1590,44 @@ static int build_fake_ancestor(const struct am_state *state, const char *index_f
 }
 
 /**
+ * Do the three-way merge using fake ancestor, his tree constructed
+ * from the fake ancestor and the postimage of the patch, and our
+ * state.
+ */
+static int run_fallback_merge_recursive(const struct am_state *state,
+					unsigned char *orig_tree,
+					unsigned char *our_tree,
+					unsigned char *his_tree)
+{
+	struct child_process cp = CHILD_PROCESS_INIT;
+	int status;
+
+	cp.git_cmd = 1;
+
+	argv_array_pushf(&cp.env_array, "GITHEAD_%s=%.*s",
+			 sha1_to_hex(his_tree), linelen(state->msg), state->msg);
+	if (state->quiet)
+		argv_array_push(&cp.env_array, "GIT_MERGE_VERBOSITY=0");
+
+	argv_array_push(&cp.args, "merge-recursive");
+	argv_array_push(&cp.args, sha1_to_hex(orig_tree));
+	argv_array_push(&cp.args, "--");
+	argv_array_push(&cp.args, sha1_to_hex(our_tree));
+	argv_array_push(&cp.args, sha1_to_hex(his_tree));
+
+	status = run_command(&cp) ? (-1) : 0;
+	discard_cache();
+	read_cache();
+	return status;
+}
+
+/**
  * Attempt a threeway merge, using index_path as the temporary index.
  */
 static int fall_back_threeway(const struct am_state *state, const char *index_path)
 {
 	unsigned char orig_tree[GIT_SHA1_RAWSZ], his_tree[GIT_SHA1_RAWSZ],
 		      our_tree[GIT_SHA1_RAWSZ];
-	const unsigned char *bases[1] = {orig_tree};
-	struct merge_options o;
-	struct commit *result;
-	char *his_tree_name;
 
 	if (get_sha1("HEAD", our_tree) < 0)
 		hashcpy(our_tree, EMPTY_TREE_SHA1_BIN);
@@ -1651,22 +1679,11 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
 	 * changes.
 	 */
 
-	init_merge_options(&o);
-
-	o.branch1 = "HEAD";
-	his_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg);
-	o.branch2 = his_tree_name;
-
-	if (state->quiet)
-		o.verbosity = 0;
-
-	if (merge_recursive_generic(&o, our_tree, his_tree, 1, bases, &result)) {
+	if (run_fallback_merge_recursive(state, orig_tree, our_tree, his_tree)) {
 		rerere(state->allow_rerere_autoupdate);
-		free(his_tree_name);
 		return error(_("Failed to merge in the changes."));
 	}
 
-	free(his_tree_name);
 	return 0;
 }
 
-- 
2.6.1-296-ge15092e

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-09 10:11       ` Johannes Schindelin
@ 2015-10-09 20:49         ` Junio C Hamano
  2015-10-10  4:58         ` Torsten Bögershausen
  2015-10-10 16:05         ` Torsten Bögershausen
  2 siblings, 0 replies; 22+ messages in thread
From: Junio C Hamano @ 2015-10-09 20:49 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Paul Tan, Brendan Forster, Git List

Johannes Schindelin <johannes.schindelin@gmx.de> writes:

> I finally have that test case working, took way longer than I wanted to:

This certainly fails without any fix and passes either with your
two-patch or a more conservative run_command() fix that I sent
separately.

However, this new test (becomes 5520.20) seems to break the
precondition of some later tests---I didn't dig but 5520.22 (which
used to be .21) fails after letting this new test run and succeed.

> I think there is more than one fix necessary to truly address the
> issue: the underlying problem is that Git handles *committed*
> CR/LF really badly when the corresponding `.gitattributes` label
> the file as `text=auto`.

Yeah, that certainly is the right thing to tackle.

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-09 10:11       ` Johannes Schindelin
  2015-10-09 20:49         ` Junio C Hamano
@ 2015-10-10  4:58         ` Torsten Bögershausen
  2015-10-10 16:05         ` Torsten Bögershausen
  2 siblings, 0 replies; 22+ messages in thread
From: Torsten Bögershausen @ 2015-10-10  4:58 UTC (permalink / raw)
  To: Johannes Schindelin, Paul Tan; +Cc: Junio C Hamano, Brendan Forster, Git List

On 2015-10-09 12.11, Johannes Schindelin wrote:
> Me again,
> 
> On 2015-10-09 11:50, Johannes Schindelin wrote:
>>
>> On 2015-10-09 03:40, Paul Tan wrote:
>>> On Fri, Oct 9, 2015 at 8:52 AM, Junio C Hamano <gitster@pobox.com> wrote:
>>>> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>>>>
>>>>> Brendan Forster noticed that we no longer see the helpful message after
>>>>> a failed `git pull --rebase`. It turns out that the builtin `am` calls
>>>>> the recursive merge function directly, not via a separate process.
>>>>>
>>>>> But that function was not really safe to be called that way, as it
>>>>> die()s pretty liberally.
>>>
>>> I'm not too familiar with the merge-recursive.c code, but I was under
>>> the impression that it only called die() under fatal conditions. In
>>> common use cases, such as merge conflicts, it just errors out and the
>>> helpful error message does get printed. Is there a reproduction recipe
>>> for this?
>>
>> Yes. Sorry, I should have added that as part of the patch series.
>> Actually, I should have written it *before* making those patches.
>> Because it revealed that the underlying problem is completely
>> different: *Normally* you are correct, if `pull --rebase` fails with a
>> merge conflict, the advice is shown.
>>
>> The problem occurs with CR/LF.
> 
> I finally have that test case working, took way longer than I wanted to:
> 
> -- snip --
> Subject: [PATCH 3/2] Verify that `git pull --rebase` shows the helpful advice when failing
> Author: Johannes Schindelin <johannes.schindelin@gmx.de>
> Date:   Fri Oct 9 11:15:30 2015 +0200
>     
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> 
> diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
> index a0013ee..bce332f 100755
> --- a/t/t5520-pull.sh
> +++ b/t/t5520-pull.sh
> @@ -237,6 +237,18 @@ test_expect_success '--rebase' '
>  	test new = "$(git show HEAD:file2)"
>  '
>  
> +test_expect_success 'failed --rebase shows advice' '
> +	git checkout -b diverging &&
> +	test_commit attributes .gitattributes "* text=auto" attrs &&
> +	sha1="$(printf "1\\r\\n" | git hash-object -w --stdin)" &&
> +	git update-index --cacheinfo 0644 $sha1 file &&
> +	git commit -m v1-with-cr &&
> +	git checkout -f -b fails-to-rebase HEAD^ &&
> +	test_commit v2-without-cr file "2" file2-lf &&
> +	test_must_fail git pull --rebase . diverging 2>err >out &&
> +	grep "When you have resolved this problem" out
> +'
> +
>  test_expect_success '--rebase fails with multiple branches' '
>  	git reset --hard before-rebase &&
>  	test_must_fail git pull --rebase . copy master 2>err &&
> --
> 
> So the reason is that `unpack_trees()` fails with
> 
>     error: Your local changes to the following files would be overwritten by merge:
> 	file
>     Please, commit your changes or stash them before you can merge.
> 
> then returns -1 to its caller, `git_merge_trees()`, which still returns -1 in turn to *its* caller, `merge_trees()`, which then gives up by die()ing:
> 
>     Aborting
> 
> I think there is more than one fix necessary to truly address the issue: the underlying problem is that Git handles *committed* CR/LF really badly when the corresponding `.gitattributes` label the file as `text=auto`. In fact, those files are labeled as modified in `git status`. If you change the line endings of them, they are labeled as modified in `git status`. And after a `git reset --hard`, they are *still* labeled as modified in `git status`.
This is related to the normalization feature of Git:
https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
  *       text=auto
This ensures that all files that Git considers to be text will have normalized
(LF) line endings in the repository.

The normalization feature has 2 consequences:
a) - Files will get normalized at the next commit,
     Line endings of the changed lines are normalized
     Line endings of unchanged lines are normalized
b) - Not normalized files will get normalized (at the next commit),
    even if they are unchanged otherwise.


As Git knows (* text=auto), that files are normalized at the next commit,
they will change in the repo, and they are marked as changed already now.
This is by design.

The normalization has been disabled for core.autocrlf = true in commit
fd6cce9e (Eyvind Bernhardsen   2010-05-19 22:43:10 +0200  207) 			 * This is the
new safer autocrlf handling.
(See convert.c)

I'm in the mood to propose a patch that disables/suppresses the normalization
even for "* text=auto", if a file has CRLF in the repo.
This would make core.autocrlf = true do the same as "* text=auto".

I'm nearly sure, that this change would break things for some users,
and improve for others.

Currently t0027 tests this behavior, and as soon as we have the new
NNO tests establish, I will propose some cleanups in convert.c
(without change of behavour), and later to make
core.autocrlf = true
to do the same as
* text=auto











> 
> I will try to make some time to continue to work on this later today, but in the meantime I would be relatively happy if we could introduce that gentle flag. It is really a very gentle patch, after all, much gentler than reverting to the heavy-handed spawning of `merge-recursive`.
> 
> Ciao,
> Dscho

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-09 10:11       ` Johannes Schindelin
  2015-10-09 20:49         ` Junio C Hamano
  2015-10-10  4:58         ` Torsten Bögershausen
@ 2015-10-10 16:05         ` Torsten Bögershausen
  2015-10-12 10:45           ` Johannes Schindelin
  2 siblings, 1 reply; 22+ messages in thread
From: Torsten Bögershausen @ 2015-10-10 16:05 UTC (permalink / raw)
  To: Johannes Schindelin, Paul Tan; +Cc: Junio C Hamano, Brendan Forster, Git List

On 09.10.15 12:11, Johannes Schindelin wrote:
> Me again,
> 
> On 2015-10-09 11:50, Johannes Schindelin wrote:
>>
>> On 2015-10-09 03:40, Paul Tan wrote:
>>> On Fri, Oct 9, 2015 at 8:52 AM, Junio C Hamano <gitster@pobox.com> wrote:
>>>> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>>>>
>>>>> Brendan Forster noticed that we no longer see the helpful message after
>>>>> a failed `git pull --rebase`. It turns out that the builtin `am` calls
>>>>> the recursive merge function directly, not via a separate process.
>>>>>
>>>>> But that function was not really safe to be called that way, as it
>>>>> die()s pretty liberally.
>>>
>>> I'm not too familiar with the merge-recursive.c code, but I was under
>>> the impression that it only called die() under fatal conditions. In
>>> common use cases, such as merge conflicts, it just errors out and the
>>> helpful error message does get printed. Is there a reproduction recipe
>>> for this?
>>
>> Yes. Sorry, I should have added that as part of the patch series.
>> Actually, I should have written it *before* making those patches.
>> Because it revealed that the underlying problem is completely
>> different: *Normally* you are correct, if `pull --rebase` fails with a
>> merge conflict, the advice is shown.
>>
>> The problem occurs with CR/LF.
> 
> I finally have that test case working, took way longer than I wanted to:
> 
> -- snip --
> Subject: [PATCH 3/2] Verify that `git pull --rebase` shows the helpful advice when failing
> Author: Johannes Schindelin <johannes.schindelin@gmx.de>
> Date:   Fri Oct 9 11:15:30 2015 +0200
>     
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> 
> diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
> index a0013ee..bce332f 100755
> --- a/t/t5520-pull.sh
> +++ b/t/t5520-pull.sh
> @@ -237,6 +237,18 @@ test_expect_success '--rebase' '
>  	test new = "$(git show HEAD:file2)"
>  '
>  
> +test_expect_success 'failed --rebase shows advice' '
> +	git checkout -b diverging &&
> +	test_commit attributes .gitattributes "* text=auto" attrs &&
> +	sha1="$(printf "1\\r\\n" | git hash-object -w --stdin)" &&
> +	git update-index --cacheinfo 0644 $sha1 file &&
> +	git commit -m v1-with-cr &&
> +	git checkout -f -b fails-to-rebase HEAD^ &&
> +	test_commit v2-without-cr file "2" file2-lf &&
> +	test_must_fail git pull --rebase . diverging 2>err >out &&
> +	grep "When you have resolved this problem" out
> +'
> +

One other question:
Is it good to mix 2 different things in one test case ?
"shows the helpful advice when failing" is one thing,
and the problematic CRLF handling another.

Does it make sense to simply create "really-modified" file to test the helpful advice ?

And may be another one witch test the CRLF handling, (may be)

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

* Re: [PATCH 2/2] pull --rebase: reinstate helpful message on abort
  2015-10-09 18:36   ` Junio C Hamano
@ 2015-10-12  9:16     ` Johannes Schindelin
  2015-10-12 20:33       ` Junio C Hamano
  0 siblings, 1 reply; 22+ messages in thread
From: Johannes Schindelin @ 2015-10-12  9:16 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Brendan Forster, git

Hi Junio,

On 2015-10-09 20:36, Junio C Hamano wrote:
> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> 
>> When calling `git pull --rebase`, things can go wrong. In such a case,
>> we want to tell the user about the most common ways out of this fix:
>> ...
>>  builtin/am.c | 1 +
>>  1 file changed, 1 insertion(+)
> 
> It is strange to see a patch to am that does not talk anything about
> it, though.  And looking at the codepath, the issue does not have
> much to do with "pull --rebase".  It doesn't even have much to do
> with "rebase".  This is purely about "am -3" fallback codepath.

I made it a habit of describing the big picture in commit messages, including the original motivation for the patch. Naturally, it is purely an implementation detail that the bug displayed by `git pull --rebase` is fixed by modifying `am.c`.

> Because fall-back-threeway wants to react to an error (i.e. calls
> merge_recursive_generic() and wants to use its return value), but
> merge_recursive_generic() can die, it fails to do so.  It would not
> even run rerere(), for example.

Precisely, So the symptom triggering the bug fix was seemingly unrelated to the patch, hence the need for the comprehensive commit message.

Since our tastes seem to differ a bit, maybe we can have the best of both worlds by appending the following paragraph to the commit message?

-- snipsnap --
This patch actually fixes a deeper-seated bug where the non-gentle death of the recursive merge would prevent not only the message from being shown but *any* code to run after the failed merge, including rerere.

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-09 18:40       ` Junio C Hamano
  2015-10-09 18:55         ` Junio C Hamano
  2015-10-09 20:46         ` Junio C Hamano
@ 2015-10-12  9:40         ` Johannes Schindelin
  2015-10-12 20:28           ` Junio C Hamano
  2 siblings, 1 reply; 22+ messages in thread
From: Johannes Schindelin @ 2015-10-12  9:40 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Paul Tan, Brendan Forster, Git List

Hi Junio,

On 2015-10-09 20:40, Junio C Hamano wrote:
> Junio C Hamano <gitster@pobox.com> writes:
> 
>>> Instead, stepping back a bit, I wonder if we can extend coverage of
>>> the helpful message to all die() calls when running git-am. We could
>>> just install a die routine with set_die_routine() in builtin/am.c.
>>> Then, should die() be called anywhere, the helpful error message will
>>> be printed as well.
>>
>> That could certainly be a valid approach and may give us a better
>> end result.  If it works, it could be a change that is localized
>> with a lot less impact.
> 
> I looked at the codepath involved, and I do not think that is a
> feasible way forward in this case.  It is not about a "helpful
> message" at all.  You would have to do everything that is done in
> the error codepath in your custom die routine, which does not make
> much sense.
> 
> I think the most sensible regression fix as the first step at this
> point is to call it as a separate process, just like the code calls
> "apply" as a separate process for each patch.  Optimization can come
> later when it is shown that it matters---we need to regain
> correctness first.

I fear that you might underestimate the finality of this "first step". If you reintroduce that separate process, not only is it a performance regression, but could we really realistically expect any further steps to happen after that? I do not think so.

Also, please let me clarify why I called reintroducing the separate process "heavy-handed" in an earlier message. As pointed out by Paul, the dying code paths indicate non-recoverable problems, i.e. serious problems that not even a rerere could fix. Modulo bugs, of course, but those bugs need to be fixed and not papered over. The real bug, after all, is that a non-recoverable code path is taken when it should just return with an error code.

Reintroducing the separate process would not help the endeavor to fix those code paths. Indeed, if we still had the separate process, I would never have discovered that bug!

And we should also keep in mind that this whole story demonstrates the rather serious shortcomings of the mindset we display throughout libgit.a where it does not behave like a library at all. Of course, hindsight is 20/20, so it is all too easy, and not exactly fair, to criticise the short-sightedness of writing code that does not clean up after itself "because it is a short-running process anyway". I certainly have contributed to these problems myself! All the more eager am I to help *increase* the number of functions in libgit.a that are reentrant, eventually making libgit.a behave like a true library. And in that light, what you called "the first step" appears like it would be a huge step backwards.

In contrast, introducing the "gentle" flag would be a step in the right direction. It is a much lighter stop-gap solution, too.

For the above reasons, I respectfully remain convinced that reintroducing the separate process would be a mistake.

Ciao,
Dscho

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-09 18:55         ` Junio C Hamano
@ 2015-10-12  9:46           ` Johannes Schindelin
  0 siblings, 0 replies; 22+ messages in thread
From: Johannes Schindelin @ 2015-10-12  9:46 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Paul Tan, Brendan Forster, Git List

Hi Junio,

On 2015-10-09 20:55, Junio C Hamano wrote:
> Junio C Hamano <gitster@pobox.com> writes:
> 
> I would prefer the endgame to be an efficient implementation of
> merge_recursive_generic(), a function that you can call without you
> having to worry about it dying.
> 
> But the patch in this thread is not that, if I am reading Johannes's
> description correctly.  

As pointed out by Paul, the recursive merge should only die() in case of a non-recoverable error so serious that not even rerere can do anything (such as a read error).

The bug is that a code path for a non-recoverable error is taken.

Spawning the recursive merge would be a work-around making the need to fix that bug less urgent, nothing more. (So would introducing the 'gentle' flag, of course, albeit without the performance regression of spawning a new process.)

Ciao,
Dscho

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-10 16:05         ` Torsten Bögershausen
@ 2015-10-12 10:45           ` Johannes Schindelin
  0 siblings, 0 replies; 22+ messages in thread
From: Johannes Schindelin @ 2015-10-12 10:45 UTC (permalink / raw)
  To: Torsten Bögershausen
  Cc: Paul Tan, Junio C Hamano, Brendan Forster, Git List

Hi Torsten,

On 2015-10-10 18:05, Torsten Bögershausen wrote:
> On 09.10.15 12:11, Johannes Schindelin wrote:
>> Me again,
>>
>> On 2015-10-09 11:50, Johannes Schindelin wrote:
>>>
>>> On 2015-10-09 03:40, Paul Tan wrote:
>>>> On Fri, Oct 9, 2015 at 8:52 AM, Junio C Hamano <gitster@pobox.com> wrote:
>>>>> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>>>>>
>>>>>> Brendan Forster noticed that we no longer see the helpful message after
>>>>>> a failed `git pull --rebase`. It turns out that the builtin `am` calls
>>>>>> the recursive merge function directly, not via a separate process.
>>
>> [... cut lots of unnecessary text ...]
>>
>> +test_expect_success 'failed --rebase shows advice' '
>> +	git checkout -b diverging &&
>> +	test_commit attributes .gitattributes "* text=auto" attrs &&
>> +	sha1="$(printf "1\\r\\n" | git hash-object -w --stdin)" &&
>> +	git update-index --cacheinfo 0644 $sha1 file &&
>> +	git commit -m v1-with-cr &&
>> +	git checkout -f -b fails-to-rebase HEAD^ &&
>> +	test_commit v2-without-cr file "2" file2-lf &&
>> +	test_must_fail git pull --rebase . diverging 2>err >out &&
>> +	grep "When you have resolved this problem" out
>> +'
>> +
> 
> One other question:
> Is it good to mix 2 different things in one test case ?
> "shows the helpful advice when failing" is one thing,
> and the problematic CRLF handling another.

I do not necessarily test things that work, and have been working for a long time, so no, I do not want to split that into two.

I could trigger the regression only via CR/LF, that is the only reason why CR/LF are used here. I do *not* want to test for anything CR/LF specific.

Ciao,
Dscho

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-12  9:40         ` Johannes Schindelin
@ 2015-10-12 20:28           ` Junio C Hamano
  2015-10-13 11:48             ` Johannes Schindelin
  0 siblings, 1 reply; 22+ messages in thread
From: Junio C Hamano @ 2015-10-12 20:28 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Paul Tan, Brendan Forster, Git List

Johannes Schindelin <johannes.schindelin@gmx.de> writes:

>> I think the most sensible regression fix as the first step at this
>> point is to call it as a separate process, just like the code calls
>> "apply" as a separate process for each patch.  Optimization can come
>> later when it is shown that it matters---we need to regain
>> correctness first.
>
> I fear that you might underestimate the finality of this "first
> step". If you reintroduce that separate process, not only is it a
> performance regression, but could we really realistically expect any
> further steps to happen after that? I do not think so.
> ...
> For the above reasons, I respectfully remain convinced that
> reintroducing the separate process would be a mistake.

I am not saying we should forever do run_command() going forward.

But I do not want to keep the direct call to merge_recursive() in
'maint'.  The topic was supposed to be "rewrite in C".  I do not
recall (and do not feel the need to read "git log" output to find
out) exactly how the series progressed, but a logical progression
would have been to run merge-recursive via run_command() like I
showed in the quick-fix in an early part of the series, followed by
a patch to turn it into a direct call to merge_recursive() as an
optimization change.

And the latter step turned out to be a regression caused by a
premature optimization.  If something introduces a regression, it
gets reverted.  As the scripted version certainly did not make an
internal call, we should just run_command().  And that is what we
want to have in the stable version people use every day.

The only thing I am saying is that the change to make a direct call
should come on top of the run_command() version with its own
justification as an optimization patch.

Going that route may require you to redo your patch, measure
performance improvements, ensure there is no unintended fallout in
other callers and longer term maintainability of the codebaths
involved, write a good log message, etc.  And such a fix to
merge_recursive() needs to be cooked sufficiently in 'pu' and
'next'.  And I view all that as a good thing.  I really hate to see
that this premature optimization to come back and bite us again---we
didn't see it while reviewing because "builtin-am: implement --3way"
was done in a single step with premature optimization from the
beginning.

Now, there are many reasons why the "first step" might turn out to
be the permanent optimal solution.

I did an unscientific experiment to rebase each of the 25 topics
that are cooking in 'next' on top of 'master'.  Only 3 of them will
fall back to the three-way merge machinery.  One possible reason why
the "first step" could stay a good-enough solution is that people
would not care and/or notice, because it is not like you are paying
unnecessary cost to spawn merge-recursive for each and every change.
It only kicks in when the patch does not apply.

Then I randomly picked one (jc/merge-drop-old-syntax) of the three
topics that does fall back, made it into a patch and ran "am -3" on
top of 'master' with and without the "first step".  The numbers from
5 runs of each look like this:

    real    0m0.109s                      real    0m0.109s
    user    0m0.080s                      user    0m0.079s
    sys     0m0.034s                      sys     0m0.035s

    real    0m0.109s                      real    0m0.105s
    user    0m0.095s                      user    0m0.087s
    sys     0m0.018s                      sys     0m0.022s

    real    0m0.109s                      real    0m0.110s
    user    0m0.075s                      user    0m0.086s
    sys     0m0.038s                      sys     0m0.028s

    real    0m0.107s                      real    0m0.108s
    user    0m0.083s                      user    0m0.075s
    sys     0m0.029s                      sys     0m0.038s

    real    0m0.106s                      real    0m0.108s
    user    0m0.086s                      user    0m0.090s
    sys     0m0.025s                      sys     0m0.023s

I am curious to see a similar number on platforms with slower
run_command().  From the above numbers alone, I cannot even see
which ones are with run_command(), even though I know the numbers on
the right hand side column were taken with run_command() and the
numbers on the left hand side column were taken with internal call.

Another possible reason why the "first step" could stay a
good-enough solution is that merge_recursive() in itself is a
heavy-weight operation that the cost of spawning a process is not
even felt [*1*].  After all, it's not like we are talking about
spawning the cost of "update-ref HEAD" dominating the cost of the
actual operation.

By the way, in order to make sure that I am running the correct
binary, I did "strace -f -e execve" on "am -3".  "mailsplit" and
"mailinfo", both of which are a lot more likely to be affected by
the cost of spawning because they are mostly dumb and straight
text-to-text filters, are spawned via run_command() interface.  And
then we do "apply --index" (which is always done), and after seeing
that fail, we do "apply --build-fake-ancestor" and "apply --cached"
before finally spawning merge-recursive (or making a direct call
internally before the "quick-fix") when we fall back to threeway.

Among the run_commands() invocations in the "am -3", I do not think
the one that spawns "merge-recursive" is the most profitable one to
turn into an internal call.  Libifying mailsplit and/or mailinfo and
making them directly callable may be a lot more useful thing to do
if you want to avoid run_command().


[Footnote]

*1* That is what I am seeing here, but this _is_ platform dependent
and that is why I said I am curious.

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

* Re: [PATCH 2/2] pull --rebase: reinstate helpful message on abort
  2015-10-12  9:16     ` Johannes Schindelin
@ 2015-10-12 20:33       ` Junio C Hamano
  0 siblings, 0 replies; 22+ messages in thread
From: Junio C Hamano @ 2015-10-12 20:33 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Brendan Forster, git

Johannes Schindelin <johannes.schindelin@gmx.de> writes:

> Hi Junio,
>
> On 2015-10-09 20:36, Junio C Hamano wrote:
>> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>> 
>>> When calling `git pull --rebase`, things can go wrong. In such a case,
>>> we want to tell the user about the most common ways out of this fix:
>>> ...
>>>  builtin/am.c | 1 +
>>>  1 file changed, 1 insertion(+)
>> 
>> It is strange to see a patch to am that does not talk anything about
>> it, though.  And looking at the codepath, the issue does not have
>> much to do with "pull --rebase".  It doesn't even have much to do
>> with "rebase".  This is purely about "am -3" fallback codepath.
>
> I made it a habit of describing the big picture in commit messages,
> including the original motivation for the patch. Naturally, it is
> purely an implementation detail that the bug displayed by `git pull
> --rebase` is fixed by modifying `am.c`.

Yup, but that is "I happened to notice that bug first in a command
that uses another command that happens to use this buggy one".  That
may be interesting in the "peeing in the snow" sense, but not very
interesting in the big picture of ensuring the health of the entire
codebase.

The "common ways out of this" helpful message is not even coming
from "pull --rebase" or even "rebase" in the first place.  What you
are reinstating helpful message on abort is "am -3".

"This fixes am -3, hence incidentally fixes rebase and hence fixes
pull --rebase, too" would be the most useful way to describe this
change.  The initial report being about "pull --rebase" is of much
lessor importance, I would think.

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

* Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails
  2015-10-12 20:28           ` Junio C Hamano
@ 2015-10-13 11:48             ` Johannes Schindelin
  0 siblings, 0 replies; 22+ messages in thread
From: Johannes Schindelin @ 2015-10-13 11:48 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Paul Tan, Brendan Forster, Git List

Hi Junio,

On 2015-10-12 22:28, Junio C Hamano wrote:
> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> 
>>> I think the most sensible regression fix as the first step at this
>>> point is to call it as a separate process, just like the code calls
>>> "apply" as a separate process for each patch.  Optimization can come
>>> later when it is shown that it matters---we need to regain
>>> correctness first.
>>
>> I fear that you might underestimate the finality of this "first
>> step". If you reintroduce that separate process, not only is it a
>> performance regression, but could we really realistically expect any
>> further steps to happen after that? I do not think so.
>> ...
>> For the above reasons, I respectfully remain convinced that
>> reintroducing the separate process would be a mistake.
> 
> I am not saying we should forever do run_command() going forward.

Fine, I will stop arguing about this and go back grumble in my corner.

Ciao,
Dscho

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

end of thread, other threads:[~2015-10-13 11:48 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-08 20:35 [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails Johannes Schindelin
2015-10-08 20:35 ` [PATCH 1/2] merge_recursive_options: introduce the "gentle" flag Johannes Schindelin
2015-10-08 20:35 ` [PATCH 2/2] pull --rebase: reinstate helpful message on abort Johannes Schindelin
2015-10-09 18:36   ` Junio C Hamano
2015-10-12  9:16     ` Johannes Schindelin
2015-10-12 20:33       ` Junio C Hamano
2015-10-09  0:52 ` [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails Junio C Hamano
2015-10-09  1:40   ` Paul Tan
2015-10-09  9:50     ` Johannes Schindelin
2015-10-09 10:11       ` Johannes Schindelin
2015-10-09 20:49         ` Junio C Hamano
2015-10-10  4:58         ` Torsten Bögershausen
2015-10-10 16:05         ` Torsten Bögershausen
2015-10-12 10:45           ` Johannes Schindelin
2015-10-09 18:15     ` Junio C Hamano
2015-10-09 18:40       ` Junio C Hamano
2015-10-09 18:55         ` Junio C Hamano
2015-10-12  9:46           ` Johannes Schindelin
2015-10-09 20:46         ` Junio C Hamano
2015-10-12  9:40         ` Johannes Schindelin
2015-10-12 20:28           ` Junio C Hamano
2015-10-13 11:48             ` Johannes Schindelin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.