{"thread":{"id":"2538","subject":"[PATCH] Re: Make \"gitk\" work better with dense revlists","startedAt":"2005-11-15T22:57:40Z","lastAt":"2005-11-19T22:48:20Z","messageCount":2,"participants":["Yann Dirson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"11950","messageId":"20051115225740.GB28173@nowhere.earth","threadId":"2538","inReplyTo":null,"subject":"[PATCH] Re: Make \"gitk\" work better with dense revlists","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2005-11-15T22:57:40Z","receivedAt":"2005-11-15T22:57:40Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"Linus wrote:\n>To generate the diff for a commit, gitk used to do\n>\n>\tgit-diff-tree -p -C $p $id\n\nAlthough the \"$p\" reference is harmful to --dense mode, and redundant\nwhen we just want to look at a single commit, removing it breaks the\n\"Diff this -> selected\" and \"Diff selected -> this\" features.\n\nA minimal fix would be at least make your change dependant on being in\ndense mode, and disable those extra features then (better than keeping\nthem broken) if noone takes the lead to fix it.\n\nSigned-off-by: Yann Dirson <ydirson@altern.org>\n\ndiff --git a/gitk b/gitk\nindex a9d37d9..f73ab41 100755\n--- a/gitk\n+++ b/gitk\n@@ -2801,12 +2801,17 @@ proc addtocflist {ids} {\n }\n \n proc gettreediffs {ids} {\n-    global treediff parents treepending\n+    global treediff parents treepending isdense\n     set treepending $ids\n     set treediff {}\n     set id [lindex $ids 0]\n     set p [lindex $ids 1]\n-    if [catch {set gdtf [open \"|git-diff-tree -r $id\" r]}] return\n+    if {$isdense == 1} {\n+       set range \"$id\"\n+    } else {\n+       set range \"$p $id\"\n+    }\n+    if [catch {set gdtf [open \"|git-diff-tree -r $range\" r]}] return\n     fconfigure $gdtf -blocking 0\n     fileevent $gdtf readable [list gettreediffline $gdtf $ids]\n }\n@@ -2837,12 +2842,16 @@ proc gettreediffline {gdtf ids} {\n \n proc getblobdiffs {ids} {\n     global diffopts blobdifffd diffids env curdifftag curtagstart\n-    global difffilestart nextupdate diffinhdr treediffs\n+    global difffilestart nextupdate diffinhdr treediffs isdense\n \n     set id [lindex $ids 0]\n     set p [lindex $ids 1]\n     set env(GIT_DIFF_OPTS) $diffopts\n-    set cmd [list | git-diff-tree -r -p -C $id]\n+    if {$isdense == 1} {\n+       set cmd [list | git-diff-tree -r -p -C $id]\n+    } else {\n+       set cmd [list | git-diff-tree -r -p -C $p $id]\n+    }\n     if {[catch {set bdf [open $cmd r]} err]} {\n        puts \"error getting diffs: $err\"\n        return\n@@ -3299,16 +3308,21 @@ proc mstime {} {\n }\n \n proc rowmenu {x y id} {\n-    global rowctxmenu idline selectedline rowmenuid\n+    global rowctxmenu idline selectedline rowmenuid isdense\n \n     if {![info exists selectedline] || $idline($id) eq $selectedline} {\n-       set state disabled\n+       set patchstate disabled\n     } else {\n-       set state normal\n+       set patchstate normal\n+    }\n+    if {$isdense || $patchstate eq \"disabled\"} {\n+       set diffstate disabled\n+    } else {\n+       set diffstate normal\n     }\n-    $rowctxmenu entryconfigure 0 -state $state\n-    $rowctxmenu entryconfigure 1 -state $state\n-    $rowctxmenu entryconfigure 2 -state $state\n+    $rowctxmenu entryconfigure 0 -state $diffstate\n+    $rowctxmenu entryconfigure 1 -state $diffstate\n+    $rowctxmenu entryconfigure 2 -state $patchstate\n     set rowmenuid $id\n     tk_popup $rowctxmenu $x $y\n }\n@@ -3653,6 +3667,7 @@ proc doquit {} {\n # defaults...\n set datemode 0\n set boldnames 0\n+set isdense 0\n set diffopts \"-U 5 -p\"\n set wrcomcmd \"git-diff-tree --stdin -p --pretty\"\n \n@@ -3678,6 +3693,10 @@ foreach arg $argv {\n        \"^$\" { }\n        \"^-b\" { set boldnames 1 }\n        \"^-d\" { set datemode 1 }\n+       \"^--dense$\" {\n+           set isdense 1\n+           lappend revtreeargs $arg\n+       }\n        default {\n            lappend revtreeargs $arg\n        }\n\n-- \nYann Dirson    <ydirson@altern.org> |\nDebian-related: <dirson@debian.org> |   Support Debian GNU/Linux:\n                                    |  Freedom, Power, Stability, Gratis\n     http://ydirson.free.fr/        | Check <http://www.debian.org/>\n"},{"id":"12345","messageId":"20051119224819.GG3393@nowhere.earth","threadId":"2538","inReplyTo":"20051115225740.GB28173@nowhere.earth","subject":"[PATCH, take 2] Re: Make \"gitk\" work better with dense revlists","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2005-11-19T22:48:20Z","receivedAt":"2005-11-19T22:48:20Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"On Tue, Nov 15, 2005 at 11:57:40PM +0100, Yann Dirson wrote:\n> Linus wrote:\n> >To generate the diff for a commit, gitk used to do\n> >\n> >\tgit-diff-tree -p -C $p $id\n> \n> Although the \"$p\" reference is harmful to --dense mode, and redundant\n> when we just want to look at a single commit, removing it breaks the\n> \"Diff this -> selected\" and \"Diff selected -> this\" features.\n\nAs noted by Junio off-list, this original fix was not good.  Here is\nanother try, which should be more robust, and, unlike the 1st try,\nhandle all cases.  Also pullable from\nhttp://ydirson.free.fr/soft/git/git.git/\n\n\ncommit 6483475ddd1af24fc138d36cfec986335685663e\ntree 421f408703235272f7b4d86f77a451f4e6606ec3\nparent 6ed64058e1241f9939c4abf5d6a9eaed6a2cc795\nauthor Yann Dirson <ydirson@altern.org> Sat, 19 Nov 2005 23:36:16 +0100\ncommitter Yann Dirson <dwitch@gandelf.nowhere.earth> Sat, 19 Nov 2005 23:36:16 +0100\n\n    Fix gitk this->selected diffs\n    \n    The change made to accomodate dense revlists in single-commit diffs\n    had broken computing of diffs between arbitrary trees, which does need\n    to pass two commit ids, whether sparse or dense.\n    \n    This patch changes the two git-diff-tree calls to get the necessary\n    two ids in this case.  It does so by propagating a \"singlecommit\" flag\n    through all functions involved via an additionnal argument.\n    \n    Signed-off-by: Yann Dirson <ydirson@altern.org>\n\n6483475ddd1af24fc138d36cfec986335685663e\ndiff --git a/gitk b/gitk\nindex 95b05c0..e3389e2 100755\n--- a/gitk\n+++ b/gitk\n@@ -2197,9 +2197,9 @@ proc selectline {l isnew} {\n     $cflist delete 0 end\n     $cflist insert end \"Comments\"\n     if {$nparents($id) == 1} {\n-       startdiff [concat $id $parents($id)]\n+       startdiff [concat $id $parents($id)] 1\n     } elseif {$nparents($id) > 1} {\n-       mergediff $id\n+       mergediff $id 1\n     }\n }\n \n@@ -2268,7 +2268,7 @@ proc goforw {} {\n     }\n }\n \n-proc mergediff {id} {\n+proc mergediff {id singlecommit} {\n     global parents diffmergeid diffmergegca mergefilelist diffpindex\n \n     set diffmergeid $id\n@@ -2279,7 +2279,7 @@ proc mergediff {id} {\n            showmergediff\n        }\n     } else {\n-       contmergediff {}\n+       contmergediff {} $singlecommit\n     }\n }\n \n@@ -2299,7 +2299,7 @@ proc findgca {ids} {\n     return $gca\n }\n \n-proc contmergediff {ids} {\n+proc contmergediff {ids singlecommit} {\n     global diffmergeid diffpindex parents nparents diffmergegca\n     global treediffs mergefilelist diffids treepending\n \n@@ -2316,7 +2316,7 @@ proc contmergediff {ids} {\n        if {![info exists treediffs($ids)]} {\n            set diffids $ids\n            if {![info exists treepending]} {\n-               gettreediffs $ids\n+               gettreediffs $ids $singlecommit\n            }\n            return\n        }\n@@ -2794,40 +2794,45 @@ proc similarity {pnum l nlc f events} {\n     return [expr {200 * $same / (2 * $same + $diff)}]\n }\n \n-proc startdiff {ids} {\n+proc startdiff {ids singlecommit} {\n     global treediffs diffids treepending diffmergeid\n \n     set diffids $ids\n     catch {unset diffmergeid}\n     if {![info exists treediffs($ids)]} {\n        if {![info exists treepending]} {\n-           gettreediffs $ids\n+           gettreediffs $ids $singlecommit\n        }\n     } else {\n-       addtocflist $ids\n+       addtocflist $ids $singlecommit\n     }\n }\n \n-proc addtocflist {ids} {\n+proc addtocflist {ids singlecommit} {\n     global treediffs cflist\n     foreach f $treediffs($ids) {\n        $cflist insert end $f\n     }\n-    getblobdiffs $ids\n+    getblobdiffs $ids $singlecommit\n }\n \n-proc gettreediffs {ids} {\n+proc gettreediffs {ids singlecommit} {\n     global treediff parents treepending\n     set treepending $ids\n     set treediff {}\n     set id [lindex $ids 0]\n     set p [lindex $ids 1]\n-    if [catch {set gdtf [open \"|git-diff-tree -r $id\" r]}] return\n+    if {$singlecommit == 1} {\n+       set range \"$id\"\n+    } else {\n+       set range \"$p $id\"\n+    }\n+    if [catch {set gdtf [open \"|git-diff-tree -r $range\" r]}] return\n     fconfigure $gdtf -blocking 0\n-    fileevent $gdtf readable [list gettreediffline $gdtf $ids]\n+    fileevent $gdtf readable [list gettreediffline $gdtf $ids $singlecommit]\n }\n \n-proc gettreediffline {gdtf ids} {\n+proc gettreediffline {gdtf ids singlecommit} {\n     global treediff treediffs treepending diffids diffmergeid\n \n     set n [gets $gdtf line]\n@@ -2837,12 +2842,12 @@ proc gettreediffline {gdtf ids} {\n        set treediffs($ids) $treediff\n        unset treepending\n        if {$ids != $diffids} {\n-           gettreediffs $diffids\n+           gettreediffs $diffids $singlecommit\n        } else {\n            if {[info exists diffmergeid]} {\n-               contmergediff $ids\n+               contmergediff $ids $singlecommit\n            } else {\n-               addtocflist $ids\n+               addtocflist $ids $singlecommit\n            }\n        }\n        return\n@@ -2851,14 +2856,18 @@ proc gettreediffline {gdtf ids} {\n     lappend treediff $file\n }\n \n-proc getblobdiffs {ids} {\n+proc getblobdiffs {ids singlecommit} {\n     global diffopts blobdifffd diffids env curdifftag curtagstart\n     global difffilestart nextupdate diffinhdr treediffs\n \n     set id [lindex $ids 0]\n     set p [lindex $ids 1]\n     set env(GIT_DIFF_OPTS) $diffopts\n-    set cmd [list | git-diff-tree -r -p -C $id]\n+    if {$singlecommit == 1} {\n+       set cmd [list | git-diff-tree -r -p -C $id]\n+    } else {\n+       set cmd [list | git-diff-tree -r -p -C $p $id]\n+    }\n     if {[catch {set bdf [open $cmd r]} err]} {\n        puts \"error getting diffs: $err\"\n        return\n@@ -3373,7 +3382,7 @@ proc doseldiff {oldid newid} {\n     $ctext conf -state disabled\n     $ctext tag delete Comments\n     $ctext tag remove found 1.0 end\n-    startdiff [list $newid $oldid]\n+    startdiff [list $newid $oldid] 0\n }\n \n proc mkpatch {} {\n\n-- \nYann Dirson    <ydirson@altern.org> |\nDebian-related: <dirson@debian.org> |   Support Debian GNU/Linux:\n                                    |  Freedom, Power, Stability, Gratis\n     http://ydirson.free.fr/        | Check <http://www.debian.org/>\n"}]}