Skip to content

Commit 6ea2334

Browse files
author
Junio C Hamano
committed
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>
1 parent fd662dd commit 6ea2334

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

git-merge.sh

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ LF='
1111
'
1212

1313
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'
1517
use_strategies=
18+
19+
index_merge=t
1620
if test "@@NO_PYTHON@@"; then
1721
all_strategies='resolve octopus stupid ours'
18-
default_strategies='resolve'
22+
default_twohead_strategies='resolve'
1923
fi
2024

2125
dropsave() {
@@ -90,15 +94,15 @@ do
9094
shift
9195
done
9296

93-
test "$#" -le 2 && usage ;# we need at least two heads.
94-
9597
merge_msg="$1"
9698
shift
9799
head_arg="$1"
98100
head=$(git-rev-parse --verify "$1"^0) || usage
99101
shift
100102

101103
# All the rest are remote heads
104+
test "$#" = 0 && usage ;# we need at least one remote head.
105+
102106
remoteheads=
103107
for remote
104108
do
@@ -108,6 +112,27 @@ do
108112
done
109113
set x $remoteheads ; shift
110114

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+
111136
case "$#" in
112137
1)
113138
common=$(git-merge-base --all $head "$@")
@@ -118,18 +143,21 @@ case "$#" in
118143
esac
119144
echo "$head" >"$GIT_DIR/ORIG_HEAD"
120145

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+
?,*,'',*)
123151
# No common ancestors found. We need a real merge.
124152
;;
125-
1,"$1",*)
153+
?,1,"$1",*)
126154
# 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.
128156
echo "Already up-to-date."
129157
dropsave
130158
exit 0
131159
;;
132-
1,"$head",*)
160+
?,1,"$head",*)
133161
# Again the most common case of merging one remote.
134162
echo "Updating from $head to $1"
135163
git-update-index --refresh 2>/dev/null
@@ -139,11 +167,11 @@ case "$#,$common,$no_commit" in
139167
dropsave
140168
exit 0
141169
;;
142-
1,?*"$LF"?*,*)
170+
?,1,?*"$LF"?*,*)
143171
# We are not doing octopus and not fast forward. Need a
144172
# real merge.
145173
;;
146-
1,*,)
174+
?,1,*,)
147175
# We are not doing octopus, not fast forward, and have only
148176
# one common. See if it is really trivial.
149177
git var GIT_COMMITTER_IDENT >/dev/null || exit
@@ -188,17 +216,6 @@ esac
188216
# We are going to make a new commit.
189217
git var GIT_COMMITTER_IDENT >/dev/null || exit
190218

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-
202219
# At this point, we need a real merge. No matter what strategy
203220
# we use, it would operate on the index, possibly affecting the
204221
# working tree, and when resolved cleanly, have the desired tree
@@ -270,11 +287,7 @@ done
270287
# auto resolved the merge cleanly.
271288
if test '' != "$result_tree"
272289
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 /')
278291
result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree $parents) || exit
279292
finish "$result_commit" "Merge $result_commit, made by $wt_strategy."
280293
dropsave

0 commit comments

Comments
 (0)