Skip to content

Commit cb93c19

Browse files
author
Junio C Hamano
committed
merge-one-file: use common as base, instead of emptiness.
Unlike the previous round that merged the path added differently in each branches using emptiness as the base, compute a common version and use it as input to 'merge' program. This would show the resulting (still conflicting) file left in the working tree as: common file contents... <<<<<< FILENAME version from our branch... ====== version from their branch... >>>>>> .merge_file_XXXXXX more common file contents... when both sides added similar contents. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent f7d24bb commit cb93c19

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

apply.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static int numstat = 0;
2323
static int summary = 0;
2424
static int check = 0;
2525
static int apply = 1;
26+
static int no_add = 0;
2627
static int show_index_info = 0;
2728
static int line_termination = '\n';
2829
static const char apply_usage[] =
@@ -1112,8 +1113,10 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag)
11121113
break;
11131114
/* Fall-through for ' ' */
11141115
case '+':
1115-
memcpy(new + newsize, patch + 1, plen);
1116-
newsize += plen;
1116+
if (*patch != '+' || !no_add) {
1117+
memcpy(new + newsize, patch + 1, plen);
1118+
newsize += plen;
1119+
}
11171120
break;
11181121
case '@': case '\\':
11191122
/* Ignore it, we already handled it */
@@ -1710,6 +1713,10 @@ int main(int argc, char **argv)
17101713
excludes = x;
17111714
continue;
17121715
}
1716+
if (!strcmp(arg, "--no-add")) {
1717+
no_add = 1;
1718+
continue;
1719+
}
17131720
if (!strcmp(arg, "--stat")) {
17141721
apply = 0;
17151722
diffstat = 1;

git-merge-one-file.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,20 @@ case "${1:-.}${2:-.}${3:-.}" in
5757
# Modified in both, but differently.
5858
#
5959
"$1$2$3" | ".$2$3")
60+
src2=`git-unpack-file $3`
6061
case "$1" in
6162
'')
6263
echo "Added $4 in both, but differently."
64+
# This extracts OUR file in $orig, and uses git-apply to
65+
# remove lines that are unique to ours.
6366
orig=`git-unpack-file $2`
64-
: >$orig
67+
diff -u -La/$orig -Lb/$orig $orig $src2 | git-apply --no-add
6568
;;
6669
*)
6770
echo "Auto-merging $4."
6871
orig=`git-unpack-file $1`
6972
;;
7073
esac
71-
src2=`git-unpack-file $3`
7274

7375
# We reset the index to the first branch, making
7476
# git-diff-file useful

0 commit comments

Comments
 (0)