git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] User-friendly error messages for merge failure on fast-forward.
@ 2009-11-29 12:18 Matthieu Moy
  2009-11-29 12:18 ` [PATCH 1/2] merge-recursive: make the error-message generation an extern function Matthieu Moy
  2009-11-29 12:18 ` [RFC/PATCH 2/2] builtin-merge: show user-friendly error messages for fast-forward too Matthieu Moy
  0 siblings, 2 replies; 5+ messages in thread
From: Matthieu Moy @ 2009-11-29 12:18 UTC (permalink / raw)
  To: git; +Cc: Matthieu Moy

I noticed that failures of fast-forward merges were still using the
plumbing error message:

$ git merge master
Updating 1fdeef9..e248dad
error: Entry 'foo.txt' not uptodate. Cannot merge.

I'm not 100% sure that my patch doesn't trigger the porcelain behavior
for plumbing. Someone more familiar than me with the codebase should
confirm/infirm this.

Matthieu Moy (2):
  merge-recursive: make the error-message generation an extern function
  builtin-merge: show user-friendly error messages for fast-forward
    too.

 builtin-merge.c   |    1 +
 merge-recursive.c |   41 +++++++++++++++++++++++------------------
 merge-recursive.h |    3 +++
 3 files changed, 27 insertions(+), 18 deletions(-)

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

* [PATCH 1/2] merge-recursive: make the error-message generation an extern function
  2009-11-29 12:18 [PATCH 0/2] User-friendly error messages for merge failure on fast-forward Matthieu Moy
@ 2009-11-29 12:18 ` Matthieu Moy
  2009-11-29 12:18 ` [RFC/PATCH 2/2] builtin-merge: show user-friendly error messages for fast-forward too Matthieu Moy
  1 sibling, 0 replies; 5+ messages in thread
From: Matthieu Moy @ 2009-11-29 12:18 UTC (permalink / raw)
  To: git; +Cc: Matthieu Moy

The construction of the struct unpack_trees_error_msgs was done within
git_merge_trees(), which prevented using the same messages easily from
another function.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 merge-recursive.c |   41 +++++++++++++++++++++++------------------
 merge-recursive.h |    3 +++
 2 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index a91208f..70cd6cc 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -172,23 +172,6 @@ static int git_merge_trees(int index_only,
 	int rc;
 	struct tree_desc t[3];
 	struct unpack_trees_options opts;
-	struct unpack_trees_error_msgs msgs = {
-		/* would_overwrite */
-		"Your local changes to '%s' would be overwritten by merge.  Aborting.",
-		/* not_uptodate_file */
-		"Your local changes to '%s' would be overwritten by merge.  Aborting.",
-		/* not_uptodate_dir */
-		"Updating '%s' would lose untracked files in it.  Aborting.",
-		/* would_lose_untracked */
-		"Untracked working tree file '%s' would be %s by merge.  Aborting",
-		/* bind_overlap -- will not happen here */
-		NULL,
-	};
-	if (advice_commit_before_merge) {
-		msgs.would_overwrite = msgs.not_uptodate_file =
-			"Your local changes to '%s' would be overwritten by merge.  Aborting.\n"
-			"Please, commit your changes or stash them before you can merge.";
-	}
 
 	memset(&opts, 0, sizeof(opts));
 	if (index_only)
@@ -200,7 +183,7 @@ static int git_merge_trees(int index_only,
 	opts.fn = threeway_merge;
 	opts.src_index = &the_index;
 	opts.dst_index = &the_index;
-	opts.msgs = msgs;
+	opts.msgs = get_porcelain_error_msgs();
 
 	init_tree_desc_from_tree(t+0, common);
 	init_tree_desc_from_tree(t+1, head);
@@ -1188,6 +1171,28 @@ static int process_entry(struct merge_options *o,
 	return clean_merge;
 }
 
+struct unpack_trees_error_msgs get_porcelain_error_msgs()
+{
+	struct unpack_trees_error_msgs msgs = {
+		/* would_overwrite */
+		"Your local changes to '%s' would be overwritten by merge.  Aborting.",
+		/* not_uptodate_file */
+		"Your local changes to '%s' would be overwritten by merge.  Aborting.",
+		/* not_uptodate_dir */
+		"Updating '%s' would lose untracked files in it.  Aborting.",
+		/* would_lose_untracked */
+		"Untracked working tree file '%s' would be %s by merge.  Aborting",
+		/* bind_overlap -- will not happen here */
+		NULL,
+	};
+	if (advice_commit_before_merge) {
+		msgs.would_overwrite = msgs.not_uptodate_file =
+			"Your local changes to '%s' would be overwritten by merge.  Aborting.\n"
+			"Please, commit your changes or stash them before you can merge.";
+	}
+	return msgs;
+}
+
 int merge_trees(struct merge_options *o,
 		struct tree *head,
 		struct tree *merge,
diff --git a/merge-recursive.h b/merge-recursive.h
index fd138ca..f4b7f57 100644
--- a/merge-recursive.h
+++ b/merge-recursive.h
@@ -17,6 +17,9 @@ struct merge_options {
 	struct string_list current_directory_set;
 };
 
+/* Return a list of user-friendly error messages to be used by merge */
+struct unpack_trees_error_msgs get_porcelain_error_msgs();
+
 /* merge_trees() but with recursive ancestor consolidation */
 int merge_recursive(struct merge_options *o,
 		    struct commit *h1,
-- 
1.6.5.3.435.g5f2e3.dirty

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

* [RFC/PATCH 2/2] builtin-merge: show user-friendly error messages for fast-forward too.
  2009-11-29 12:18 [PATCH 0/2] User-friendly error messages for merge failure on fast-forward Matthieu Moy
  2009-11-29 12:18 ` [PATCH 1/2] merge-recursive: make the error-message generation an extern function Matthieu Moy
@ 2009-11-29 12:18 ` Matthieu Moy
  2009-11-30  2:23   ` Junio C Hamano
  1 sibling, 1 reply; 5+ messages in thread
From: Matthieu Moy @ 2009-11-29 12:18 UTC (permalink / raw)
  To: git; +Cc: Matthieu Moy

fadd069d03 (merge-recursive: give less scary messages when merge did not
start, Sep 7 2009) introduced some friendlier error message for merge
failure, but the messages were shown only for non-fast forward merges.
This patch uses the same for fast-forward.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
This is where I'm not 100% sure I'm not breaking some plumbing.

 builtin-merge.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/builtin-merge.c b/builtin-merge.c
index 57eedd4..0dd363f 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -656,6 +656,7 @@ static int checkout_fast_forward(unsigned char *head, unsigned char *remote)
 	opts.verbose_update = 1;
 	opts.merge = 1;
 	opts.fn = twoway_merge;
+	opts.msgs = get_porcelain_error_msgs();
 
 	trees[nr_trees] = parse_tree_indirect(head);
 	if (!trees[nr_trees++])
-- 
1.6.5.3.435.g5f2e3.dirty

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

* Re: [RFC/PATCH 2/2] builtin-merge: show user-friendly error messages for fast-forward too.
  2009-11-29 12:18 ` [RFC/PATCH 2/2] builtin-merge: show user-friendly error messages for fast-forward too Matthieu Moy
@ 2009-11-30  2:23   ` Junio C Hamano
  2009-11-30  8:42     ` Matthieu Moy
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2009-11-30  2:23 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git

Matthieu Moy <Matthieu.Moy@imag.fr> writes:

> This is where I'm not 100% sure I'm not breaking some plumbing.

I think this change is safe for the current codebase, as the only caller
of checkout_fast_forward() is cmd_merge(), which is an implementation of
"git merge".  Even if there were a plumbing implementation that internally
runs "git merge", either by calling cmd_merge() or via run_command()
interface (there isn't as far as I know), or if somebody adds such a thing
in the future, such a "plumbing" will get Porcelain messages from other
codepaths in cmd_merge() anyway.  You are not introducing a new problem.

Or did you have something a lot more subtle in mind?

Side note. checkout_fast_forward() switches between two commits (the one
that matches HEAD) to another (given as remote), which is the same as what
"git checkout other-branch" and "git checkout -b new-branch" do.  We might
want to replace it with the main part of merge_working_tree() from
builtin-checkout.c eventually, which would teach the "checkout -m" logic
that carries the local changes forward to fast-forward of "git merge".

>  builtin-merge.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/builtin-merge.c b/builtin-merge.c
> index 57eedd4..0dd363f 100644
> --- a/builtin-merge.c
> +++ b/builtin-merge.c
> @@ -656,6 +656,7 @@ static int checkout_fast_forward(unsigned char *head, unsigned char *remote)
>  	opts.verbose_update = 1;
>  	opts.merge = 1;
>  	opts.fn = twoway_merge;
> +	opts.msgs = get_porcelain_error_msgs();
>  
>  	trees[nr_trees] = parse_tree_indirect(head);
>  	if (!trees[nr_trees++])

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

* Re: [RFC/PATCH 2/2] builtin-merge: show user-friendly error messages for fast-forward too.
  2009-11-30  2:23   ` Junio C Hamano
@ 2009-11-30  8:42     ` Matthieu Moy
  0 siblings, 0 replies; 5+ messages in thread
From: Matthieu Moy @ 2009-11-30  8:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

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

> Matthieu Moy <Matthieu.Moy@imag.fr> writes:
>
>> This is where I'm not 100% sure I'm not breaking some plumbing.
>
> I think this change is safe [...]
>
> Or did you have something a lot more subtle in mind?

Not at all. But since I found the place to add my code more or less
randomly with gdb, I feel safer with your comment ;-).

Thanks,

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

end of thread, other threads:[~2009-11-30  8:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-29 12:18 [PATCH 0/2] User-friendly error messages for merge failure on fast-forward Matthieu Moy
2009-11-29 12:18 ` [PATCH 1/2] merge-recursive: make the error-message generation an extern function Matthieu Moy
2009-11-29 12:18 ` [RFC/PATCH 2/2] builtin-merge: show user-friendly error messages for fast-forward too Matthieu Moy
2009-11-30  2:23   ` Junio C Hamano
2009-11-30  8:42     ` Matthieu Moy

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 NNTP newsgroup(s).