|
1
|
#!/bin/sh |
|
2
|
## -*- tcl -*- \ |
|
3
|
exec tclsh "$0" ${1+"$@"} |
|
4
|
|
|
5
|
# # ## ### ##### ######## ############# ##################### |
|
6
|
## Copyright (c) 2007 Andreas Kupries. |
|
7
|
# |
|
8
|
# This software is licensed as described in the file LICENSE, which |
|
9
|
# you should have received as part of this distribution. |
|
10
|
# |
|
11
|
# This software consists of voluntary contributions made by many |
|
12
|
# individuals. For exact contribution history, see the revision |
|
13
|
# history and logs, available at http://fossil-scm.hwaci.com/fossil |
|
14
|
# # ## ### ##### ######## ############# ##################### |
|
15
|
|
|
16
|
## Command line application to extract the tree of branches (lines of |
|
17
|
## development) from a state database and show it graphically. The |
|
18
|
## code uses GraphViz's 'dot' to do the layouting and conversion into |
|
19
|
## an image. |
|
20
|
|
|
21
|
# # ## ### ##### ######## ############# ##################### |
|
22
|
## Requirements, extended package management for local packages. |
|
23
|
|
|
24
|
lappend auto_path [file join [file dirname [info script]] lib] |
|
25
|
|
|
26
|
package require Tcl 8.4 ; # Required runtime. |
|
27
|
package require struct::graph ; # Graph handling. |
|
28
|
package require struct::list ; # Higher order list ops. |
|
29
|
package require vc::fossil::import::cvs::state ; # State storage. |
|
30
|
package require vc::tools::dot ; # Graph export to DOT. |
|
31
|
|
|
32
|
namespace import ::vc::fossil::import::cvs::state |
|
33
|
namespace import ::vc::tools::dot |
|
34
|
|
|
35
|
# Process the command line. Get the database to access. |
|
36
|
|
|
37
|
state use [lindex $argv 0] |
|
38
|
state reading symbol |
|
39
|
state reading parent |
|
40
|
|
|
41
|
# Get the data of all symbols in the state as a list for iteration, |
|
42
|
# and as array for random access of neighbouring symbols. |
|
43
|
|
|
44
|
foreach {sid name} [set symbols [state run { SELECT sid, name FROM symbol }]] { |
|
45
|
set sym($sid) [list $name] |
|
46
|
} |
|
47
|
foreach {sid lod} [state run { SELECT sid, lod FROM tag }] { |
|
48
|
catch {unset sym($sid)} |
|
49
|
} |
|
50
|
foreach {sid lod} [state run { SELECT sid, lod FROM branch }] { |
|
51
|
lappend sym($sid) $lod $sym($lod) diamond Branch |
|
52
|
} |
|
53
|
|
|
54
|
# Start the graph |
|
55
|
|
|
56
|
struct::graph dg |
|
57
|
|
|
58
|
# Convert the symbols into nodes of the graph, and use node attributes |
|
59
|
# to highlight various pieces of interest for the dot conversion. |
|
60
|
# Label => Symbol name. |
|
61
|
|
|
62
|
foreach sid [array names sym] { |
|
63
|
dg node insert $sid |
|
64
|
struct::list assign $sym($sid) name lod lodname shape what |
|
65
|
if {$shape eq ""} { set shape circle } |
|
66
|
if {$what ne ""} { append what " " } |
|
67
|
dg node set $sid label "$what$name" |
|
68
|
dg node set $sid shape $shape |
|
69
|
} |
|
70
|
|
|
71
|
# Go through the symbols a second time, now set up the arcs based on |
|
72
|
# their parent choices. Use arc attributes to highlight interesting |
|
73
|
# things (...). |
|
74
|
|
|
75
|
foreach sid [array names sym] { |
|
76
|
struct::list assign $sym($sid) name lod lodname shape |
|
77
|
if {$lod eq ""} continue ; # Root has no parent. |
|
78
|
dg arc insert $sid $lod |
|
79
|
} |
|
80
|
|
|
81
|
# Convert the graph to dot, then run the layouter and convert to png, |
|
82
|
# at last show the image. |
|
83
|
|
|
84
|
vc::tools::dot layout png dg SymbolTree st.png |
|
85
|
exec display st.png |
|
86
|
file delete st.png |
|
87
|
exit |
|
88
|
|
|
89
|
|