Skip to content

Commit

Permalink
[PATCH] Add an --argscmd flag to get the list of refs to show
Browse files Browse the repository at this point in the history
This allows gitk to be used to display a different set of refs each
the display is refreshed.  This is useful when gitk is called from
other porcelain suites, for doing such things as displaying the set of
patches in a patch stack.

The user specifies a command as the argument to the --argscmd option.
The command is run initially and each time the display is refreshed,
and is expected to generate a list of commit IDs, one per line.  Those
commits are appended to the commits passed on the command-line when
constructing the git log command to be executed.

The command is considered to be an attribute of a view, and has its
own field in the saved view, and an edit field in the view editor.

Signed-off-by: Yann Dirson <ydirson@altern.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
  • Loading branch information
Yann Dirson authored and Paul Mackerras committed Mar 10, 2008
1 parent b9bee11 commit 2d48085
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions gitk
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,31 @@ proc dorunq {} {
proc start_rev_list {view} {
global startmsecs
global commfd leftover tclencoding datemode
global viewargs viewfiles commitidx viewcomplete vnextroot
global viewargs viewargscmd viewfiles commitidx viewcomplete vnextroot
global showlocalchanges commitinterest mainheadid
global progressdirn progresscoords proglastnc curview

set startmsecs [clock clicks -milliseconds]
set commitidx($view) 0
set viewcomplete($view) 0
set vnextroot($view) 0
set args $viewargs($view)
if {$viewargscmd($view) ne {}} {
if {[catch {
set str [exec sh -c $viewargscmd($view)]
} err]} {
error_popup "Error executing --argscmd command: $err"
exit 1
}
set args [concat $args [split $str "\n"]]
}
set order "--topo-order"
if {$datemode} {
set order "--date-order"
}
if {[catch {
set fd [open [concat | git log --no-color -z --pretty=raw $order --parents \
--boundary $viewargs($view) "--" $viewfiles($view)] r]
--boundary $args "--" $viewfiles($view)] r]
} err]} {
error_popup "[mc "Error executing git rev-list:"] $err"
exit 1
Expand Down Expand Up @@ -1168,7 +1178,7 @@ proc savestuff {w} {
global canv canv2 canv3 mainfont textfont uifont tabstop
global stuffsaved findmergefiles maxgraphpct
global maxwidth showneartags showlocalchanges
global viewname viewfiles viewargs viewperm nextviewnum
global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
global cmitmode wrapcomment datetimeformat limitdiffs
global colors bgcolor fgcolor diffcolors diffcontext selectbgcolor

Expand Down Expand Up @@ -1207,7 +1217,7 @@ proc savestuff {w} {
puts -nonewline $f "set permviews {"
for {set v 0} {$v < $nextviewnum} {incr v} {
if {$viewperm($v)} {
puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v)]}"
puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
}
}
puts $f "}"
Expand Down Expand Up @@ -1858,7 +1868,7 @@ proc shellsplit {str} {

proc newview {ishighlight} {
global nextviewnum newviewname newviewperm newishighlight
global newviewargs revtreeargs
global newviewargs revtreeargs viewargscmd newviewargscmd curview

set newishighlight $ishighlight
set top .gitkview
Expand All @@ -1869,13 +1879,14 @@ proc newview {ishighlight} {
set newviewname($nextviewnum) "View $nextviewnum"
set newviewperm($nextviewnum) 0
set newviewargs($nextviewnum) [shellarglist $revtreeargs]
set newviewargscmd($nextviewnum) $viewargscmd($curview)
vieweditor $top $nextviewnum [mc "Gitk view definition"]
}

proc editview {} {
global curview
global viewname viewperm newviewname newviewperm
global viewargs newviewargs
global viewargs newviewargs viewargscmd newviewargscmd

set top .gitkvedit-$curview
if {[winfo exists $top]} {
Expand All @@ -1885,6 +1896,7 @@ proc editview {} {
set newviewname($curview) $viewname($curview)
set newviewperm($curview) $viewperm($curview)
set newviewargs($curview) [shellarglist $viewargs($curview)]
set newviewargscmd($curview) $viewargscmd($curview)
vieweditor $top $curview "Gitk: edit view $viewname($curview)"
}

Expand All @@ -1905,6 +1917,14 @@ proc vieweditor {top n title} {
entry $top.args -width 50 -textvariable newviewargs($n) \
-background $bgcolor
grid $top.args - -sticky ew -padx 5

message $top.ac -aspect 1000 \
-text [mc "Command to generate more commits to include:"]
grid $top.ac - -sticky w -pady 5
entry $top.argscmd -width 50 -textvariable newviewargscmd($n) \
-background white
grid $top.argscmd - -sticky ew -padx 5

message $top.l -aspect 1000 \
-text [mc "Enter files and directories to include, one per line:"]
grid $top.l - -sticky w
Expand Down Expand Up @@ -1948,7 +1968,7 @@ proc allviewmenus {n op args} {
proc newviewok {top n} {
global nextviewnum newviewperm newviewname newishighlight
global viewname viewfiles viewperm selectedview curview
global viewargs newviewargs viewhlmenu
global viewargs newviewargs viewargscmd newviewargscmd viewhlmenu

if {[catch {
set newargs [shellsplit $newviewargs($n)]
Expand All @@ -1972,6 +1992,7 @@ proc newviewok {top n} {
set viewperm($n) $newviewperm($n)
set viewfiles($n) $files
set viewargs($n) $newargs
set viewargscmd($n) $newviewargscmd($n)
addviewmenu $n
if {!$newishighlight} {
run showview $n
Expand All @@ -1988,9 +2009,11 @@ proc newviewok {top n} {
# doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
# entryconf [list -label $viewname($n) -value $viewname($n)]
}
if {$files ne $viewfiles($n) || $newargs ne $viewargs($n)} {
if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
$newviewargscmd($n) ne $viewargscmd($n)} {
set viewfiles($n) $files
set viewargs($n) $newargs
set viewargscmd($n) $newviewargscmd($n)
if {$curview == $n} {
run updatecommits
}
Expand Down Expand Up @@ -8530,8 +8553,9 @@ set mergeonly 0
set revtreeargs {}
set cmdline_files {}
set i 0
set revtreeargscmd {}
foreach arg $argv {
switch -- $arg {
switch -glob -- $arg {
"" { }
"-d" { set datemode 1 }
"--merge" {
Expand All @@ -8542,6 +8566,9 @@ foreach arg $argv {
set cmdline_files [lrange $argv [expr {$i + 1}] end]
break
}
"--argscmd=*" {
set revtreeargscmd [string range $arg 10 end]
}
default {
lappend revtreeargs $arg
}
Expand Down Expand Up @@ -8643,6 +8670,7 @@ set highlight_files {}
set viewfiles(0) {}
set viewperm(0) 0
set viewargs(0) {}
set viewargscmd(0) {}

set cmdlineok 0
set stopped 0
Expand All @@ -8658,14 +8686,15 @@ tkwait visibility .
wm title . "[file tail $argv0]: [file tail [pwd]]"
readrefs

if {$cmdline_files ne {} || $revtreeargs ne {}} {
if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
# create a view for the files/dirs specified on the command line
set curview 1
set selectedview 1
set nextviewnum 2
set viewname(1) [mc "Command line"]
set viewfiles(1) $cmdline_files
set viewargs(1) $revtreeargs
set viewargscmd(1) $revtreeargscmd
set viewperm(1) 0
addviewmenu 1
.bar.view entryconf [mc "Edit view..."] -state normal
Expand All @@ -8679,6 +8708,7 @@ if {[info exists permviews]} {
set viewname($n) [lindex $v 0]
set viewfiles($n) [lindex $v 1]
set viewargs($n) [lindex $v 2]
set viewargscmd($n) [lindex $v 3]
set viewperm($n) 1
addviewmenu $n
}
Expand Down

0 comments on commit 2d48085

Please sign in to comment.