git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] merge-recursive: do not report the resulting tree object name

From
Junio C Hamano <junkio@cox.net>
Date
Jan 13, 2007, 07:03 UTC
Message-ID
<7vk5zrmmqx.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20070113051447.GA22063@spearce.org>
"Shawn O. Pearce" <spearce@spearce.org> writes:
Show 6 quoted lines
>> Among these, I think lines 2..3 are somewhat confusing but I am
>> used to seeing them and do not mind them too much.
>
> In my experience these lines scare new users.  And then they start
> to ignore other "fatal:" messages from Git because they can safely
> ignore this particular one.
I tend to agree; we could do something like the attached.
Show 5 quoted lines
>> Lines 10..16 are useful, but I think we probably should show
>> them only for outermost merges.
>
> Actually I think that only 13 is useful.  10-12,14-17 are
> pretty useless messages in my mind.

I am not sure. It is nice to view which paths have content-level merges as it is more significant than path-level merges.

I think the output from merge-recursive can be categorized into 5 verbosity levels:

 1. "CONFLICT", "Rename", "Adding here instead due to D/F conflict" (outermost)
 2. "Auto-merged successfully" (outermost)
 3. The first "Merging X with Y".
 4. outermost "Merging:\ntitle1\ntitle2".
 5. outermost "found N common ancestors\nancestor1\nancestor2\n..."
    and anything from inner merge.

I would prefer the default verbosity level to be 2 (that is, show both 1 and 2); your "quieter" option would show only level 1, and somebody who is debugging reursive would ask for all levels.

-- >8 -- [PATCH] Make 'trivial merge' attempt less verbose.

This replaces die() calls in unpack-trees with simple and quiet exit(1) when we are trying trivial merges only and die() is about the case that cannot trivially be merged (i.e. not a serious corruption error but expected). Also it makes the nontrivial merges exit early.

And then this updates git-merge so that we do not have to say "trying..." followed by "wonderful" or "nope".

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 git-merge.sh   |   36 ++++++++++++++++++++++--------------
 unpack-trees.c |   29 ++++++++++++++++++-----------
 2 files changed, 40 insertions(+), 25 deletions(-)
diff --git a/git-merge.sh b/git-merge.sh
index 3eef048..6240a73 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -302,21 +302,29 @@ f,*)
 	# one common.  See if it is really trivial.
 	git var GIT_COMMITTER_IDENT >/dev/null || exit
 
-	echo "Trying really trivial in-index merge..."
 	git-update-index --refresh 2>/dev/null
-	if git-read-tree --trivial -m -u -v $common $head "$1" &&
-	   result_tree=$(git-write-tree)
-	then
-	    echo "Wonderful."
-	    result_commit=$(
-	        echo "$merge_msg" |
-	        git-commit-tree $result_tree -p HEAD -p "$1"
-	    ) || exit
-	    finish "$result_commit" "In-index merge"
-	    dropsave
-	    exit 0
-	fi
-	echo "Nope."
+	git-read-tree --trivial -m -u -v $common $head "$1"
+	case "$?" in
+	1)	: expected failure from non-trivial merge
+		;;
+	0)
+		if result_tree=$(git-write-tree)
+		then
+			echo "Trivially merged in index."
+			result_commit=$(
+				echo "$merge_msg" |
+				git-commit-tree $result_tree -p HEAD -p "$1"
+			) || exit
+			finish "$result_commit" "In-index merge"
+			dropsave
+			exit 0
+		fi
+		;;
+	*)
+		: This could be serious failure.
+		echo >&2 "Tried trivial merge but did not work; don't worry..."
+		;;
+	esac
 	;;
 *)
 	# An octopus.  If we can reach all the remote we are up to date.
diff --git a/unpack-trees.c b/unpack-trees.c
index 2e2232c..0fca83b 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -409,17 +409,17 @@ int unpack_trees(struct object_list *trees, struct unpack_trees_options *o)
 			return -1;
 	}
 
-	if (o->trivial_merges_only && o->nontrivial_merge)
-		die("Merge requires file-level merging");
-
 	check_updates(active_cache, active_nr, o);
 	return 0;
 }
 
 /* Here come the merge functions */
 
-static void reject_merge(struct cache_entry *ce)
+static void reject_merge(struct cache_entry *ce,
+			 struct unpack_trees_options *o)
 {
+	if (o->trivial_merges_only)
+		exit(1);
 	die("Entry '%s' would be overwritten by merge. Cannot merge.",
 	    ce->name);
 }
@@ -459,6 +459,8 @@ static void verify_uptodate(struct cache_entry *ce,
 	}
 	if (errno == ENOENT)
 		return;
+	if (o->trivial_merges_only)
+		exit(1);
 	die("Entry '%s' not uptodate. Cannot merge.", ce->name);
 }
 
@@ -473,15 +475,18 @@ static void invalidate_ce_path(struct cache_entry *ce)
  * is not tracked, unless it is ignored.
  */
 static void verify_absent(const char *path, const char *action,
-		struct unpack_trees_options *o)
+			  struct unpack_trees_options *o)
 {
 	struct stat st;
 
 	if (o->index_only || o->reset || !o->update)
 		return;
-	if (!lstat(path, &st) && !(o->dir && excluded(o->dir, path)))
+	if (!lstat(path, &st) && !(o->dir && excluded(o->dir, path))) {
+		if (o->trivial_merges_only)
+			exit(1);
 		die("Untracked working tree file '%s' "
 		    "would be %s by merge.", path, action);
+	}
 }
 
 static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
@@ -617,7 +622,7 @@ int threeway_merge(struct cache_entry **stages,
 	/* #14, #14ALT, #2ALT */
 	if (remote && !df_conflict_head && head_match && !remote_match) {
 		if (index && !same(index, remote) && !same(index, head))
-			reject_merge(index);
+			reject_merge(index, o);
 		return merged_entry(remote, index, o);
 	}
 	/*
@@ -625,7 +630,7 @@ int threeway_merge(struct cache_entry **stages,
 	 * make sure that it matches head.
 	 */
 	if (index && !same(index, head)) {
-		reject_merge(index);
+		reject_merge(index, o);
 	}
 
 	if (head) {
@@ -677,6 +682,8 @@ int threeway_merge(struct cache_entry **stages,
 	}
 
 	o->nontrivial_merge = 1;
+	if (o->trivial_merges_only)
+		exit(1);
 
 	/* #2, #3, #4, #6, #7, #9, #11. */
 	count = 0;
@@ -743,11 +750,11 @@ int twoway_merge(struct cache_entry **src,
 		else {
 			/* all other failures */
 			if (oldtree)
-				reject_merge(oldtree);
+				reject_merge(oldtree, o);
 			if (current)
-				reject_merge(current);
+				reject_merge(current, o);
 			if (newtree)
-				reject_merge(newtree);
+				reject_merge(newtree, o);
 			return -1;
 		}
 	}
-- 
1.5.0.rc1.g120b
Previous: Shawn O. PearceNext: Alex Riesen
Message 38 of 40 in “Speedup recursive by flushing index only once for all entries”
  1. Speedup recursive by flushing index only once for all entriesAlex Riesen, Jan 4, 2007
  2. Johannes SchindelinJan 4, 2007
  3. Alex RiesenJan 4, 2007
  4. Junio C HamanoJan 4, 2007
  5. Alex RiesenJan 5, 2007
  6. Alex RiesenJan 7, 2007
  7. Junio C HamanoJan 10, 2007
  8. Junio C HamanoJan 10, 2007
  9. Junio C HamanoJan 10, 2007
  10. Alex RiesenJan 10, 2007
  11. Linus TorvaldsJan 10, 2007
  12. Johannes SchindelinJan 11, 2007
  13. Alex RiesenJan 11, 2007
  14. Alex RiesenJan 11, 2007
  15. Junio C HamanoJan 11, 2007
  16. Alex RiesenJan 11, 2007
  17. Linus TorvaldsJan 11, 2007
  18. Alex RiesenJan 11, 2007
  19. Linus TorvaldsJan 11, 2007
  20. Alex RiesenJan 11, 2007
  21. Junio C HamanoJan 11, 2007
  22. Alex RiesenJan 11, 2007
  23. Linus TorvaldsJan 11, 2007
  24. Junio C HamanoJan 11, 2007
  25. Alex RiesenJan 12, 2007
  26. Junio C HamanoJan 11, 2007
  27. Johannes SchindelinJan 11, 2007
  28. Sergey VlasovJan 12, 2007
  29. Alex RiesenJan 12, 2007
  30. Sergey VlasovJan 12, 2007
  31. Junio C HamanoJan 12, 2007
  32. merge-recursive: do not report the resulting tree object nameJunio C Hamano, Jan 12, 2007
  33. Johannes SchindelinJan 12, 2007
  34. Junio C HamanoJan 13, 2007
  35. Jakub NarebskiJan 13, 2007
  36. Johannes SchindelinJan 13, 2007
  37. Shawn O. PearceJan 13, 2007
  38. Junio C HamanoJan 13, 2007
  39. Alex RiesenJan 12, 2007
  40. Sergey VlasovJan 12, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.