For those who like to spawn interactive merge tools on a merge failure
or otherwise run some kind of script, allow a "merge.tool" repo-config
option that will take arguments as merge(1) does.
---
merge-recursive.c | 23 ++++++++++++++++++++++-
1 files changed, 22 insertions(+), 1 deletions(-)
Here's the script I use:
#!/bin/sh
output=`mktemp -p . .merge_file_XXXXXX`
branch1="$7"
branch2="$9"
ancestor="$8"
cp $branch1 $output
if merge -L $2 -L $4 -L $6 $output $ancestor $branch2
then
mv $output $branch1
exit 0
else
rm $output
emacs --eval "(ediff-merge-files-with-ancestor \"${branch1}\"
\"${branch2}\" \"${ancestor}\" nil \"${output}\")"
if [ -s "$output" ]
then
mv $output $branch1
exit 0
else
exit 1
fi
fi
diff --git a/merge-recursive.c b/merge-recursive.c
index 5a70a5c..0e2da57 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -627,6 +627,8 @@ static char *git_unpack_file(const unsigned char *sha1, char *path)
return path;
}
+static char* merge_tool = "merge";
+
static struct merge_file_info merge_file(struct diff_filespec *o,
struct diff_filespec *a, struct diff_filespec *b,
const char *branch1, const char *branch2)
@@ -661,12 +663,14 @@ static struct merge_file_info merge_file(struct diff_filespec *o,
char src1[PATH_MAX];
char src2[PATH_MAX];
const char *argv[] = {
- "merge", "-L", NULL, "-L", NULL, "-L", NULL,
+ NULL, "-L", NULL, "-L", NULL, "-L", NULL,
NULL, NULL, NULL,
NULL
};
char *la, *lb, *lo;
+ argv[0] = merge_tool;
+
git_unpack_file(o->sha1, orig);
git_unpack_file(a->sha1, src1);
git_unpack_file(b->sha1, src2);
@@ -1134,6 +1138,21 @@ static int process_entry(const char *path, struct stage_data *entry,
return clean_merge;
}
+static int
+git_merge_config(const char *key, const char *val)
+{
+ char merge_key[] = "merge.";
+ if (strncmp( key, merge_key, sizeof merge_key - 1 ))
+ return 0;
+ key += sizeof merge_key - 1;
+
+ if (!strcmp( "tool", key )) {
+ merge_tool = xstrdup(val);
+ }
+
+ return 0;
+}
+
static int merge_trees(struct tree *head,
struct tree *merge,
struct tree *common,
@@ -1148,6 +1167,8 @@ static int merge_trees(struct tree *head,
return 1;
}
+ git_config( git_merge_config );
+
code = git_merge_trees(index_only, common, head, merge);
if (code != 0)
--
1.4.4.1.ge918e-dirty
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html