[PATCH v7 06/15] merge-index: add a new way to invoke `git-merge-one-file'

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

 



Since `git-merge-one-file' will be rewritten and libified, there may be
cases where there is no executable named this way (ie. when git is
compiled with `SKIP_DASHED_BUILT_INS' enabled).  This adds a new way to
invoke this particular program even if it does not exist, by passing
`--use=merge-one-file' to merge-index.  For now, it still forks.

The test suite and shell scripts (git-merge-octopus.sh and
git-merge-resolve.sh) are updated to use this new convention.

Signed-off-by: Alban Gruin <alban.gruin@xxxxxxxxx>
---
 Documentation/git-merge-index.txt |  7 ++++---
 builtin/merge-index.c             | 25 ++++++++++++++++++++++---
 git-merge-octopus.sh              |  2 +-
 git-merge-resolve.sh              |  2 +-
 t/t6060-merge-index.sh            |  8 ++++----
 5 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/Documentation/git-merge-index.txt b/Documentation/git-merge-index.txt
index 2ab84a91e5..57e7e03b4c 100644
--- a/Documentation/git-merge-index.txt
+++ b/Documentation/git-merge-index.txt
@@ -9,7 +9,7 @@ git-merge-index - Run a merge for files needing merging
 SYNOPSIS
 --------
 [verse]
-'git merge-index' [-o] [-q] <merge-program> (-a | [--] <file>*)
+'git merge-index' [-o] [-q] (<merge-program> | --use=merge-one-file) (-a | [--] <file>*)
 
 DESCRIPTION
 -----------
@@ -44,8 +44,9 @@ code.
 Typically this is run with a script calling Git's imitation of
 the 'merge' command from the RCS package.
 
-A sample script called 'git merge-one-file' is included in the
-distribution.
+A sample script called 'git merge-one-file' used to be included in the
+distribution. This program must now be called with
+'--use=merge-one-file'.
 
 ALERT ALERT ALERT! The Git "merge object order" is different from the
 RCS 'merge' program merge object order. In the above ordering, the
diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index 49ddf3f9cd..fd5b1a5a92 100644
--- a/builtin/merge-index.c
+++ b/builtin/merge-index.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "lockfile.h"
 #include "merge-strategies.h"
 #include "run-command.h"
 
@@ -37,7 +38,10 @@ static int merge_one_file_spawn(struct index_state *istate,
 int cmd_merge_index(int argc, const char **argv, const char *prefix)
 {
 	int i, force_file = 0, err = 0, one_shot = 0, quiet = 0;
+	merge_fn merge_action = merge_one_file_spawn;
+	struct lock_file lock = LOCK_INIT;
 	struct repository *r = the_repository;
+	const char *use_internal = NULL;
 
 	/* Without this we cannot rely on waitpid() to tell
 	 * what happened to our children.
@@ -45,7 +49,7 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix)
 	signal(SIGCHLD, SIG_DFL);
 
 	if (argc < 3)
-		usage("git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])");
+		usage("git merge-index [-o] [-q] (<merge-program> | --use=merge-one-file) (-a | [--] [<filename>...])");
 
 	if (repo_read_index(r) < 0)
 		die("invalid index");
@@ -61,6 +65,14 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix)
 	}
 
 	pgm = argv[i++];
+	setup_work_tree();
+
+	if (skip_prefix(pgm, "--use=", &use_internal)) {
+		if (!strcmp(use_internal, "merge-one-file"))
+			pgm = "git-merge-one-file";
+		else
+			die(_("git merge-index: unknown internal program %s"), use_internal);
+	}
 
 	for (; i < argc; i++) {
 		const char *arg = argv[i];
@@ -71,13 +83,20 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix)
 			}
 			if (!strcmp(arg, "-a")) {
 				err |= merge_all_index(r->index, one_shot, quiet,
-						       merge_one_file_spawn, NULL);
+						       merge_action, NULL);
 				continue;
 			}
 			die("git merge-index: unknown option %s", arg);
 		}
 		err |= merge_index_path(r->index, one_shot, quiet, arg,
-					merge_one_file_spawn, NULL);
+					merge_action, NULL);
+	}
+
+	if (is_lock_file_locked(&lock)) {
+		if (err)
+			rollback_lock_file(&lock);
+		else
+			return write_locked_index(r->index, &lock, COMMIT_LOCK);
 	}
 
 	return err;
diff --git a/git-merge-octopus.sh b/git-merge-octopus.sh
index 7d19d37951..2770891960 100755
--- a/git-merge-octopus.sh
+++ b/git-merge-octopus.sh
@@ -100,7 +100,7 @@ do
 	if test $? -ne 0
 	then
 		gettextln "Simple merge did not work, trying automatic merge."
-		git merge-index -o git-merge-one-file -a ||
+		git merge-index -o --use=merge-one-file -a ||
 		OCTOPUS_FAILURE=1
 		next=$(git write-tree 2>/dev/null)
 	fi
diff --git a/git-merge-resolve.sh b/git-merge-resolve.sh
index 343fe7bccd..0b4fc88b61 100755
--- a/git-merge-resolve.sh
+++ b/git-merge-resolve.sh
@@ -45,7 +45,7 @@ then
 	exit 0
 else
 	echo "Simple merge failed, trying Automatic merge."
-	if git merge-index -o git-merge-one-file -a
+	if git merge-index -o --use=merge-one-file -a
 	then
 		exit 0
 	else
diff --git a/t/t6060-merge-index.sh b/t/t6060-merge-index.sh
index 0cbd8a1f7f..d0cdfeddc1 100755
--- a/t/t6060-merge-index.sh
+++ b/t/t6060-merge-index.sh
@@ -50,8 +50,8 @@ test_expect_success 'read-tree does not resolve content merge' '
 	test_cmp expect unmerged
 '
 
-test_expect_success 'git merge-index git-merge-one-file resolves' '
-	git merge-index git-merge-one-file -a &&
+test_expect_success 'git merge-index --use=merge-one-file resolves' '
+	git merge-index --use=merge-one-file -a &&
 	git diff-files --name-only --diff-filter=U >unmerged &&
 	test_must_be_empty unmerged &&
 	test_cmp expect-merged file &&
@@ -83,7 +83,7 @@ test_expect_success 'merge-one-file respects GIT_WORK_TREE' '
 	 export GIT_WORK_TREE &&
 	 GIT_INDEX_FILE=$PWD/merge.index &&
 	 export GIT_INDEX_FILE &&
-	 git merge-index git-merge-one-file -a &&
+	 git merge-index --use=merge-one-file -a &&
 	 git cat-file blob :file >work/file-index
 	) &&
 	test_cmp expect-merged bare.git/work/file &&
@@ -98,7 +98,7 @@ test_expect_success 'merge-one-file respects core.worktree' '
 	 export GIT_DIR &&
 	 git config core.worktree "$PWD/child" &&
 	 git read-tree -i -m base ten two &&
-	 git merge-index git-merge-one-file -a &&
+	 git merge-index --use=merge-one-file -a &&
 	 git cat-file blob :file >file-index
 	) &&
 	test_cmp expect-merged subdir/child/file &&
-- 
2.31.0




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux