@matheusbsbs / matheus-bagliano / commits / cb93c19365
Fork 0

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>

Junio C Hamano committed Nov 9, 2005 at 20:38 UTC cb93c19365760d939f05d9a3c2ef4499f0d5ce16
2 files changed +13 -4
apply.c
+9 -2
@@ -23,6 +23,7 @@ static int numstat = 0;
23 static int summary = 0;
24 static int check = 0;
25 static int apply = 1;
26 +static int no_add = 0;
27 static int show_index_info = 0;
28 static int line_termination = '\n';
29 static const char apply_usage[] =
@@ -1112,8 +1113,10 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag)
1113 break;
1114 /* Fall-through for ' ' */
1115 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 + }
1120 break;
1121 case '@': case '\\':
1122 /* Ignore it, we already handled it */
@@ -1710,6 +1713,10 @@ int main(int argc, char **argv)
1713 excludes = x;
1714 continue;
1715 }
1716 + if (!strcmp(arg, "--no-add")) {
1717 + no_add = 1;
1718 + continue;
1719 + }
1720 if (!strcmp(arg, "--stat")) {
1721 apply = 0;
1722 diffstat = 1;
git-merge-one-file.sh
+4 -2
@@ -57,18 +57,20 @@ case "${1:-.}${2:-.}${3:-.}" in
57 # Modified in both, but differently.
58 #
59 "$1$2$3" | ".$2$3")
60 + src2=`git-unpack-file $3`
61 case "$1" in
62 '')
63 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.
66 orig=`git-unpack-file $2`
64 - : >$orig
67 + diff -u -La/$orig -Lb/$orig $orig $src2 | git-apply --no-add
68 ;;
69 *)
70 echo "Auto-merging $4."
71 orig=`git-unpack-file $1`
72 ;;
73 esac
71 - src2=`git-unpack-file $3`
74
75 # We reset the index to the first branch, making
76 # git-diff-file useful