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

git-gui: Factor out common fast-forward merge case

In both the ff and reset merge_types supported by checkout_op the result is the same if the merge base of our target commit and the existing commit is the existing commit: its a fast-forward as the existing commit is fully contained in the target commit. This minor cleanup in logic will make it easier to implement a new kind of merge_type that actually merges the two trees with a real merge strategy, such as git-merge-recursive. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jul 20, 2007 at 03:34 UTC f66b8a68f21d7dba6b80ba213315974476001b93
1 file changed +21 -25
lib/checkout_op.tcl
+21 -25
@@ -182,27 +182,23 @@ method _update_ref {} {
182 #
183 } else {
184 catch {set merge_base [git merge-base $new $cur]}
185 - switch -- $merge_type {
186 - ff {
187 - if {$merge_base eq $new} {
188 - # The current branch is actually newer.
189 - #
190 - set new $cur
191 - } elseif {$merge_base eq $cur} {
192 - # The current branch is older.
193 - #
194 - set reflog_msg "merge $new_expr: Fast-forward"
195 - } else {
196 - _error $this "Branch '$newbranch' already exists.\n\nIt cannot fast-forward to $new_expr.\nA merge is required."
197 - return 0
185 + if {$merge_base eq $cur} {
186 + # The current branch is older.
187 + #
188 + set reflog_msg "merge $new_expr: Fast-forward"
189 + } else {
190 + switch -- $merge_type {
191 + ff {
192 + if {$merge_base eq $new} {
193 + # The current branch is actually newer.
194 + #
195 + set new $cur
196 + } else {
197 + _error $this "Branch '$newbranch' already exists.\n\nIt cannot fast-forward to $new_expr.\nA merge is required."
198 + return 0
199 + }
200 }
199 - }
200 - reset {
201 - if {$merge_base eq $cur} {
202 - # The current branch is older.
203 - #
204 - set reflog_msg "merge $new_expr: Fast-forward"
205 - } else {
201 + reset {
202 # The current branch will lose things.
203 #
204 if {[_confirm_reset $this $cur]} {
@@ -211,11 +207,11 @@ method _update_ref {} {
207 return 0
208 }
209 }
214 - }
215 - default {
216 - _error $this "Only 'ff' and 'reset' merge is currently supported."
217 - return 0
218 - }
210 + default {
211 + _error $this "Only 'ff' and 'reset' merge is currently supported."
212 + return 0
213 + }
214 + }
215 }
216 }
217