gitk: Add menu item for reverting commits

Sometimes it's helpful (at least psychologically) to have this feature easily accessible. Code borrows heavily from cherrypick. Signed-off-by: Knut Franke <Knut.Franke@gmx.de> Signed-off-by: Paul Mackerras <paulus@samba.org>

Knut Franke committed Apr 27, 2013 at 16:36 UTC 8f3ff9339fd0bdb797e072a1843bc5e9f766e4c6
1 file changed +62
gitk
+62
@@ -2567,6 +2567,7 @@ proc makewindow {} {
2567 {mc "Compare with marked commit" command compare_commits}
2568 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2569 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2570 + {mc "Revert this commit" command revert}
2571 }
2572 $rowctxmenu configure -tearoff 0
2573
@@ -9346,6 +9347,67 @@ proc cherrypick {} {
9347 notbusy cherrypick
9348 }
9349
9350 +proc revert {} {
9351 + global rowmenuid curview
9352 + global mainhead mainheadid
9353 + global gitdir
9354 +
9355 + set oldhead [exec git rev-parse HEAD]
9356 + set dheads [descheads $rowmenuid]
9357 + if { $dheads eq {} || [lsearch -exact $dheads $oldhead] == -1 } {
9358 + set ok [confirm_popup [mc "Commit %s is not\
9359 + included in branch %s -- really revert it?" \
9360 + [string range $rowmenuid 0 7] $mainhead]]
9361 + if {!$ok} return
9362 + }
9363 + nowbusy revert [mc "Reverting"]
9364 + update
9365 +
9366 + if [catch {exec git revert --no-edit $rowmenuid} err] {
9367 + notbusy revert
9368 + if [regexp {files would be overwritten by merge:(\n(( |\t)+[^\n]+\n)+)}\
9369 + $err match files] {
9370 + regsub {\n( |\t)+} $files "\n" files
9371 + error_popup [mc "Revert failed because of local changes to\
9372 + the following files:%s Please commit, reset or stash \
9373 + your changes and try again." $files]
9374 + } elseif [regexp {error: could not revert} $err] {
9375 + if [confirm_popup [mc "Revert failed because of merge conflict.\n\
9376 + Do you wish to run git citool to resolve it?"]] {
9377 + # Force citool to read MERGE_MSG
9378 + file delete [file join $gitdir "GITGUI_MSG"]
9379 + exec_citool {} $rowmenuid
9380 + }
9381 + } else { error_popup $err }
9382 + run updatecommits
9383 + return
9384 + }
9385 +
9386 + set newhead [exec git rev-parse HEAD]
9387 + if { $newhead eq $oldhead } {
9388 + notbusy revert
9389 + error_popup [mc "No changes committed"]
9390 + return
9391 + }
9392 +
9393 + addnewchild $newhead $oldhead
9394 +
9395 + if [commitinview $oldhead $curview] {
9396 + # XXX this isn't right if we have a path limit...
9397 + insertrow $newhead $oldhead $curview
9398 + if {$mainhead ne {}} {
9399 + movehead $newhead $mainhead
9400 + movedhead $newhead $mainhead
9401 + }
9402 + set mainheadid $newhead
9403 + redrawtags $oldhead
9404 + redrawtags $newhead
9405 + selbyid $newhead
9406 + }
9407 +
9408 + notbusy revert
9409 +}
9410 +
9411 proc resethead {} {
9412 global mainhead rowmenuid confirm_ok resettype NS
9413