{"thread":{"id":"32692","subject":"gitk show branch in commit overview","startedAt":"2013-01-22T13:45:54Z","lastAt":"2013-01-22T13:45:54Z","messageCount":1,"participants":["Teun Grinwis"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"207509","messageId":"50FE9812.2020405@adesys.nl","threadId":"32692","inReplyTo":"50FE70F0.8020600@adesys.nl","subject":"gitk show branch in commit overview","fromName":"Teun Grinwis","fromEmail":"teun@adesys.nl","sentAt":"2013-01-22T13:45:54Z","receivedAt":"2013-01-22T13:45:54Z","isPatch":false,"sender":{"key":"teun@adesys.nl","avatar":null},"body":"\n> Hello,\n> We recently changed from using CVS to GIT, previous company I worked \n> we used clearcase.\n>\n> We do feature development / bug fixing (complex) on branches, trivial \n> changes commit direct on Develop branch.\n>\n> What I am missing in all the gui tools is the relation on what \n> specific branch did one do a commit.\n>\n> I searched on the internet and read that  there is need to see on \n> which branch a specific commit is done.\n>\n> From the link below,\n> https://github.com/pajp/git/compare/master...x-working-branch\n> I tried this version, but could not see the branches when I started \n> gitk in a git repository,\n> so I looked into his changes, and adapted his code with use of the git \n> commands\n> git show-branch --all and git show-branch --all --sha1name.\n> And see the result below:\n>\n\n\n-- \nMet vriendelijke groeten / With kind regards,\n\nTeun Grinwis\nSoftware engineer\n\nAdesys B.V.\nMolenweer 4, 2291 NR, Wateringen, NL.\nP.O. Box 60, 2290 AB, Wateringen, NL.\n\nTfn         : +31 174 296389\nFax         : +31 174 293807\ne-mail      : teun@adesys.nl\ninternet    : www.adesys.nl\n\n\n\n>From 15427e2dc35c58ab2ad7e9466aa280f5c70e9eda Mon Sep 17 00:00:00 2001\nFrom: Teun Grinwis <teun@adesys.nl>\nDate: Tue, 22 Jan 2013 11:43:39 +0100\nSubject: [PATCH] show branch canvas in commit overview\n\n---\n gitk | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------\n 1 file changed, 79 insertions(+), 12 deletions(-)\n\ndiff --git a/gitk b/gitk\nindex b3706fc..cdde3b2 100755\n--- a/gitk\n+++ b/gitk\n@@ -496,7 +496,9 @@ proc updatecommits {} {\n     global hasworktree\n     global varcid vposids vnegids vflags vrevs\n     global show_notes\n+    global workbranches_set\n \n+    set workbranches_set false\n     set hasworktree [hasworktree]\n     rereadrefs\n     set view $curview\n@@ -577,7 +579,9 @@ proc reloadcommits {} {\n     global curview viewcomplete selectedline currentid thickerline\n     global showneartags treediffs commitinterest cached_commitrow\n     global targetid\n+    global workbranches_set\n \n+    set workbranches_set false\n     set selid {}\n     if {$selectedline ne {}} {\n \tset selid $currentid\n@@ -1652,6 +1656,50 @@ proc readcommit {id} {\n     parsecommit $id $contents 1\n }\n \n+set workbranches_set false\n+\n+proc set_workbranches { } {\n+    global workbranches\n+\n+    catch {set allbranches [exec git show-branch --all]}\n+    catch {set allsha1names [exec git show-branch --all --sha1-name]}\n+\n+    set allbranches [split $allbranches \\n\\n]\n+    set allsha1names [split $allsha1names \\n\\n]\n+\n+    foreach br $allbranches sha1 $allsha1names {\n+\n+        set branch [lindex [split $br \"\\[\"] 1 ]\n+        set branch [lindex [split $branch \"]\"] 0 ]\n+        set branch [lindex [split $branch \"~\"] 0 ]\n+        set branch [lindex [split $branch \"^\"] 0 ]\n+\n+        set sha1Id [lindex [split $sha1 \"\\[\"] 1 ]\n+        set sha1Id [lindex [split $sha1Id \"]\"] 0 ]\n+        set workbranches($sha1Id) $branch\n+    }\n+}\n+\n+proc get_workbranch { shaid } {\n+\n+    global workbranches workbranches_set\n+    set workbranch \"\"\n+\n+#   use 1st 7 digits of shaid\n+    set shaid [string range $shaid 0 6]\n+\n+    if { $workbranches_set == false } {\n+        set_workbranches\n+        set workbranches_set true\n+    }\n+\n+    if { [ info exist workbranches($shaid) ] } {\n+        return $workbranches($shaid)\n+    } else {\n+        return \"unknown\"\n+    }\n+}\n+\n proc parsecommit {id contents listed} {\n     global commitinfo\n \n@@ -1662,6 +1710,7 @@ proc parsecommit {id contents listed} {\n     set audate {}\n     set comname {}\n     set comdate {}\n+    set workbranch {}\n     set hdrend [string first \"\\n\\n\" $contents]\n     if {$hdrend < 0} {\n \t# should never happen...\n@@ -1703,9 +1752,11 @@ proc parsecommit {id contents listed} {\n \t}\n \tset comment $newcomment\n     }\n+    set workbranch [get_workbranch $id]\n     set hasnote [string first \"\\nNotes:\\n\" $contents]\n     set commitinfo($id) [list $headline $auname $audate \\\n-\t\t\t     $comname $comdate $comment $hasnote]\n+                 $comname $comdate $comment $hasnote $workbranch]\n+\n }\n \n proc getcommit {id} {\n@@ -2015,7 +2066,7 @@ proc makedroplist {w varname args} {\n }\n \n proc makewindow {} {\n-    global canv canv2 canv3 linespc charspc ctext cflist cscroll\n+    global canv canv2 canv3 canv4 linespc charspc ctext cflist cscroll\n     global tabstop\n     global findtype findtypemenu findloc findstring fstring geometry\n     global entries sha1entry sha1string sha1but\n@@ -2109,7 +2160,7 @@ proc makewindow {} {\n \t.tf.histframe.pwclist configure -sashpad 0 -handlesize 4\n     }\n \n-    # create three canvases\n+    # create four canvases\n     set cscroll .tf.histframe.csb\n     set canv .tf.histframe.pwclist.canv\n     canvas $canv \\\n@@ -2127,6 +2178,11 @@ proc makewindow {} {\n \t-selectbackground $selectbgcolor \\\n \t-background $bgcolor -bd 0 -yscrollincr $linespc\n     .tf.histframe.pwclist add $canv3\n+    set canv4 .tf.histframe.pwclist.canv4\n+    canvas $canv4 \\\n+    -selectbackground $selectbgcolor \\\n+    -background $bgcolor -bd 0 -yscrollincr $linespc\n+    .tf.histframe.pwclist add $canv4\n     if {$use_ttk} {\n \tbind .tf.histframe.pwclist <Map> {\n \t    bind %W <Map> {}\n@@ -2602,11 +2658,11 @@ proc makewindow {} {\n # the one where the mouse hovers, so bind those events here and redirect\n # to the correct window\n proc windows_mousewheel_redirector {W X Y D} {\n-    global canv canv2 canv3\n+    global canv canv2 canv3 canv4\n     set w [winfo containing -displayof $W $X $Y]\n     if {$w ne \"\"} {\n \tset u [expr {$D < 0 ? 5 : -5}]\n-\tif {$w == $canv || $w == $canv2 || $w == $canv3} {\n+    if {$w == $canv || $w == $canv2 || $w == $canv3 || $w == $canv4} {\n \t    allcanvs yview scroll $u units\n \t} else {\n \t    catch {\n@@ -2715,7 +2771,7 @@ proc doprogupdate {} {\n }\n \n proc savestuff {w} {\n-    global canv canv2 canv3 mainfont textfont uifont tabstop\n+    global canv canv2 canv3 canv4 mainfont textfont uifont tabstop\n     global stuffsaved findmergefiles maxgraphpct\n     global maxwidth showneartags showlocalchanges\n     global viewname viewfiles viewargs viewargscmd viewperm nextviewnum\n@@ -2859,17 +2915,19 @@ proc resizecdetpanes {win w} {\n }\n \n proc allcanvs args {\n-    global canv canv2 canv3\n+    global canv canv2 canv3 canv4\n     eval $canv $args\n     eval $canv2 $args\n     eval $canv3 $args\n+    eval $canv4 $args\n }\n \n proc bindall {event action} {\n-    global canv canv2 canv3\n+    global canv canv2 canv3 canv4\n     bind $canv $event $action\n     bind $canv2 $event $action\n     bind $canv3 $event $action\n+    bind $canv4 $event $action\n }\n \n proc about {} {\n@@ -4997,13 +5055,14 @@ proc initlayout {} {\n }\n \n proc setcanvscroll {} {\n-    global canv canv2 canv3 numcommits linespc canvxmax canvy0\n+    global canv canv2 canv3 canv4 numcommits linespc canvxmax canvy0\n     global lastscrollset lastscrollrows\n \n     set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]\n     $canv conf -scrollregion [list 0 0 $canvxmax $ymax]\n     $canv2 conf -scrollregion [list 0 0 0 $ymax]\n     $canv3 conf -scrollregion [list 0 0 0 $ymax]\n+    $canv4 conf -scrollregion [list 0 0 0 $ymax]\n     set lastscrollset [clock clicks -milliseconds]\n     set lastscrollrows $numcommits\n }\n@@ -5919,7 +5978,7 @@ proc drawlines {id} {\n }\n \n proc drawcmittext {id row col} {\n-    global linespc canv canv2 canv3 fgcolor curview\n+    global linespc canv canv2 canv3 canv4 fgcolor curview\n     global cmitlisted commitinfo rowidlist parentlist\n     global rowtextx idpos idtags idheads idotherrefs\n     global linehtag linentag linedtag selectedline\n@@ -5986,6 +6045,7 @@ proc drawcmittext {id row col} {\n     set headline [lindex $commitinfo($id) 0]\n     set name [lindex $commitinfo($id) 1]\n     set date [lindex $commitinfo($id) 2]\n+    set workbranch [lindex $commitinfo($id) 7]\n     set date [formatdate $date]\n     set font mainfont\n     set nfont mainfont\n@@ -6001,9 +6061,12 @@ proc drawcmittext {id row col} {\n     set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \\\n \t\t\t   -text $headline -font $font -tags text]\n     $canv bind $linehtag($id) $ctxbut \"rowmenu %X %Y $id\"\n+# set workbranch before the name\n     set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \\\n-\t\t\t   -text $name -font $nfont -tags text]\n+               -text $workbranch -font $nfont -tags text]\n     set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \\\n+               -text $name -font mainfont -tags text]\n+    set linedtag($id) [$canv4 create text 3 $y -anchor w -fill $fgcolor \\\n \t\t\t   -text $date -font mainfont -tags text]\n     if {$selectedline == $row} {\n \tmake_secsel $id\n@@ -6993,7 +7056,7 @@ proc dispnexttag {} {\n }\n \n proc make_secsel {id} {\n-    global linehtag linentag linedtag canv canv2 canv3\n+    global linehtag linentag linedtag canv canv2 canv3 canv4\n \n     if {![info exists linehtag($id)]} return\n     $canv delete secsel\n@@ -7008,6 +7071,10 @@ proc make_secsel {id} {\n     set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \\\n \t       -tags secsel -fill [$canv3 cget -selectbackground]]\n     $canv3 lower $t\n+    $canv4 delete secsel\n+    set t [eval $canv4 create rect [$canv4 bbox $linedtag($id)] -outline {{}} \\\n+            -tags secsel -fill [$canv4 cget -selectbackground]]\n+    $canv4 lower $t\n }\n \n proc make_idmark {id} {\n-- \n1.7.11.msysgit.1\n\n"}]}