{"thread":{"id":"33634","subject":"[PATCH] gitk: Add menu item for reverting commits","startedAt":"2013-04-27T14:36:13Z","lastAt":"2013-05-11T09:43:56Z","messageCount":2,"participants":["Knut Franke","Paul Mackerras"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"215711","messageId":"1367073373.12513.3.camel@Vger","threadId":"33634","inReplyTo":null,"subject":"[PATCH] gitk: Add menu item for reverting commits","fromName":"Knut Franke","fromEmail":"knut.franke@gmx.de","sentAt":"2013-04-27T14:36:13Z","receivedAt":"2013-04-27T14:36:13Z","isPatch":true,"sender":{"key":"knut.franke@gmx.de","avatar":null},"body":"Sometimes it's helpful (at least psychologically) to have this feature\neasily accessible. Code borrows heavily from cherrypick.\n\nSigned-off-by: Knut Franke <Knut.Franke@gmx.de>\n---\n gitk |   62\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 62 insertions(+)\n\ndiff --git a/gitk b/gitk\nindex 572f73f..fb1a6ce 100755\n--- a/gitk\n+++ b/gitk\n@@ -2562,6 +2562,7 @@ proc makewindow {} {\n \t{mc \"Compare with marked commit\" command compare_commits}\n \t{mc \"Diff this -> marked commit\" command {diffvsmark 0}}\n \t{mc \"Diff marked commit -> this\" command {diffvsmark 1}}\n+\t{mc \"Revert this commit\" command revert}\n     }\n     $rowctxmenu configure -tearoff 0\n \n@@ -9347,6 +9348,67 @@ proc cherrypick {} {\n     notbusy cherrypick\n }\n \n+proc revert {} {\n+    global rowmenuid curview\n+    global mainhead mainheadid\n+    global gitdir\n+\n+    set oldhead [exec git rev-parse HEAD]\n+    set dheads [descheads $rowmenuid]\n+    if { $dheads eq {} || [lsearch -exact $dheads $oldhead] == -1 } {\n+       set ok [confirm_popup [mc \"Commit %s is not\\\n+           included in branch %s -- really revert it?\" \\\n+                      [string range $rowmenuid 0 7] $mainhead]]\n+       if {!$ok} return\n+    }\n+    nowbusy revert [mc \"Reverting\"]\n+    update\n+\n+    if [catch {exec git revert --no-edit $rowmenuid} err] {\n+        notbusy revert\n+        if [regexp {files would be overwritten by merge:(\\n(( |\\t)+[^\n\\n]+\\n)+)}\\\n+                $err match files] {\n+            regsub {\\n( |\\t)+} $files \"\\n\" files\n+            error_popup [mc \"Revert failed because of local changes to\n\\\n+                the following files:%s Please commit, reset or stash \\\n+                your changes and try again.\" $files]\n+        } elseif [regexp {error: could not revert} $err] {\n+            if [confirm_popup [mc \"Revert failed because of merge\nconflict.\\n\\\n+                Do you wish to run git citool to resolve it?\"]] {\n+                # Force citool to read MERGE_MSG\n+                file delete [file join $gitdir \"GITGUI_MSG\"]\n+                exec_citool {} $rowmenuid\n+            }\n+        } else { error_popup $err }\n+        run updatecommits\n+        return\n+    }\n+\n+    set newhead [exec git rev-parse HEAD]\n+    if { $newhead eq $oldhead } {\n+        notbusy revert\n+        error_popup [mc \"No changes committed\"]\n+        return\n+    }\n+\n+    addnewchild $newhead $oldhead\n+\n+    if [commitinview $oldhead $curview] {\n+        # XXX this isn't right if we have a path limit...\n+        insertrow $newhead $oldhead $curview\n+        if {$mainhead ne {}} {\n+            movehead $newhead $mainhead\n+            movedhead $newhead $mainhead\n+        }\n+        set mainheadid $newhead\n+        redrawtags $oldhead\n+        redrawtags $newhead\n+        selbyid $newhead\n+    }\n+\n+    notbusy revert\n+}\n+\n proc resethead {} {\n     global mainhead rowmenuid confirm_ok resettype NS\n \n-- \n1.7.9.5\n"},{"id":"216986","messageId":"20130511094356.GD6196@iris.ozlabs.ibm.com","threadId":"33634","inReplyTo":"1367073373.12513.3.camel@Vger","subject":"Re: [PATCH] gitk: Add menu item for reverting commits","fromName":"Paul Mackerras","fromEmail":"paulus@samba.org","sentAt":"2013-05-11T09:43:56Z","receivedAt":"2013-05-11T09:43:56Z","isPatch":true,"sender":{"key":"paulus@samba.org","avatar":"https://avatars.githubusercontent.com/u/1606439?v=4"},"body":"On Sat, Apr 27, 2013 at 04:36:13PM +0200, Knut Franke wrote:\n> Sometimes it's helpful (at least psychologically) to have this feature\n> easily accessible. Code borrows heavily from cherrypick.\n> \n> Signed-off-by: Knut Franke <Knut.Franke@gmx.de>\n\nThanks, applied, after undoing the linewrapping (done by your mailer?).\n\nPaul.\n"}]}