@matheusbsbs / matheus-bagliano / commits / 6ea23343ce
Fork 0

git-merge knows some strategies want to skip trivial merges

Most notably "ours". Also this makes sure we do not record duplicated parents on the parent list of the resulting commit. This is based on Mark Wooding's work, but does not change the UI nor introduce new flags. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Mar 18, 2006 at 14:50 UTC 6ea23343ce2962a5c76ed62a29fd17cb30954de2
1 file changed +40 -27
git-merge.sh
+40 -27
@@ -11,11 +11,15 @@ LF='
11 '
12
13 all_strategies='recursive octopus resolve stupid ours'
14 -default_strategies='recursive'
14 +default_twohead_strategies='recursive'
15 +default_octopus_strategies='octopus'
16 +no_trivial_merge_strategies='ours'
17 use_strategies=
18 +
19 +index_merge=t
20 if test "@@NO_PYTHON@@"; then
21 all_strategies='resolve octopus stupid ours'
18 - default_strategies='resolve'
22 + default_twohead_strategies='resolve'
23 fi
24
25 dropsave() {
@@ -90,8 +94,6 @@ do
94 shift
95 done
96
93 -test "$#" -le 2 && usage ;# we need at least two heads.
94 -
97 merge_msg="$1"
98 shift
99 head_arg="$1"
@@ -99,6 +101,8 @@ head=$(git-rev-parse --verify "$1"^0) || usage
101 shift
102
103 # All the rest are remote heads
104 +test "$#" = 0 && usage ;# we need at least one remote head.
105 +
106 remoteheads=
107 for remote
108 do
@@ -108,6 +112,27 @@ do
112 done
113 set x $remoteheads ; shift
114
115 +case "$use_strategies" in
116 +'')
117 + case "$#" in
118 + 1)
119 + use_strategies="$default_twohead_strategies" ;;
120 + *)
121 + use_strategies="$default_octopus_strategies" ;;
122 + esac
123 + ;;
124 +esac
125 +
126 +for s in $use_strategies
127 +do
128 + case " $s " in
129 + *" $no_trivial_merge_strategies "*)
130 + index_merge=f
131 + break
132 + ;;
133 + esac
134 +done
135 +
136 case "$#" in
137 1)
138 common=$(git-merge-base --all $head "$@")
@@ -118,18 +143,21 @@ case "$#" in
143 esac
144 echo "$head" >"$GIT_DIR/ORIG_HEAD"
145
121 -case "$#,$common,$no_commit" in
122 -*,'',*)
146 +case "$index_merge,$#,$common,$no_commit" in
147 +f,*)
148 + # We've been told not to try anything clever. Skip to real merge.
149 + ;;
150 +?,*,'',*)
151 # No common ancestors found. We need a real merge.
152 ;;
125 -1,"$1",*)
153 +?,1,"$1",*)
154 # If head can reach all the merge then we are up to date.
127 - # but first the most common case of merging one remote
155 + # but first the most common case of merging one remote.
156 echo "Already up-to-date."
157 dropsave
158 exit 0
159 ;;
132 -1,"$head",*)
160 +?,1,"$head",*)
161 # Again the most common case of merging one remote.
162 echo "Updating from $head to $1"
163 git-update-index --refresh 2>/dev/null
@@ -139,11 +167,11 @@ case "$#,$common,$no_commit" in
167 dropsave
168 exit 0
169 ;;
142 -1,?*"$LF"?*,*)
170 +?,1,?*"$LF"?*,*)
171 # We are not doing octopus and not fast forward. Need a
172 # real merge.
173 ;;
146 -1,*,)
174 +?,1,*,)
175 # We are not doing octopus, not fast forward, and have only
176 # one common. See if it is really trivial.
177 git var GIT_COMMITTER_IDENT >/dev/null || exit
@@ -188,17 +216,6 @@ esac
216 # We are going to make a new commit.
217 git var GIT_COMMITTER_IDENT >/dev/null || exit
218
191 -case "$use_strategies" in
192 -'')
193 - case "$#" in
194 - 1)
195 - use_strategies="$default_strategies" ;;
196 - *)
197 - use_strategies=octopus ;;
198 - esac
199 - ;;
200 -esac
201 -
219 # At this point, we need a real merge. No matter what strategy
220 # we use, it would operate on the index, possibly affecting the
221 # working tree, and when resolved cleanly, have the desired tree
@@ -270,11 +287,7 @@ done
287 # auto resolved the merge cleanly.
288 if test '' != "$result_tree"
289 then
273 - parents="-p $head"
274 - for remote
275 - do
276 - parents="$parents -p $remote"
277 - done
290 + parents=$(git-show-branch --independent "$head" "$@" | sed -e 's/^/-p /')
291 result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree $parents) || exit
292 finish "$result_commit" "Merge $result_commit, made by $wt_strategy."
293 dropsave