File: lodtree

package info (click to toggle)
fossil 1%3A1.22.1%2Bdfsg-0.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 10,588 kB
  • sloc: ansic: 151,799; tcl: 10,291; sh: 4,413; makefile: 1,822; sql: 376
file content (88 lines) | stat: -rw-r--r-- 3,001 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
## -*- tcl -*- \
exec tclsh "$0" ${1+"$@"}

# # ## ### ##### ######## ############# #####################
## Copyright (c) 2007 Andreas Kupries.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
#
# This software consists of voluntary contributions made by many
# individuals.  For exact contribution history, see the revision
# history and logs, available at http://fossil-scm.hwaci.com/fossil
# # ## ### ##### ######## ############# #####################

## Command line application to extract the tree of branches (lines of
## development) from a state database and show it graphically. The
## code uses GraphViz's 'dot' to do the layouting and conversion into
## an image.

# # ## ### ##### ######## ############# #####################
## Requirements, extended package management for local packages.

lappend auto_path [file join [file dirname [info script]] lib]

package require Tcl 8.4                               ; # Required runtime.
package require struct::graph                         ; # Graph handling.
package require struct::list                          ; # Higher order list ops.
package require vc::fossil::import::cvs::state        ; # State storage.
package require vc::tools::dot                        ; # Graph export to DOT.

namespace import ::vc::fossil::import::cvs::state
namespace import ::vc::tools::dot

# Process the command line. Get the database to access.

state use [lindex $argv 0]
state reading symbol
state reading parent

# Get the data of all symbols in the state as a list for iteration,
# and as array for random access of neighbouring symbols.

foreach {sid name} [set symbols [state run { SELECT sid, name FROM symbol }]] {
    set sym($sid) [list $name]
}
foreach {sid lod} [state run { SELECT sid, lod FROM tag }] {
    catch {unset sym($sid)}
}
foreach {sid lod} [state run { SELECT sid, lod FROM branch }] {
    lappend sym($sid) $lod $sym($lod) diamond Branch
}

# Start the graph

struct::graph dg

# Convert the symbols into nodes of the graph, and use node attributes
# to highlight various pieces of interest for the dot conversion.
# Label => Symbol name.

foreach sid [array names sym] {
    dg node insert $sid
    struct::list assign $sym($sid) name lod lodname shape what
    if {$shape eq ""} { set shape circle }
    if {$what ne ""} { append what " " }
    dg node set $sid label "$what$name"
    dg node set $sid shape $shape
}

# Go through the symbols a second time, now set up the arcs based on
# their parent choices. Use arc attributes to highlight interesting
# things (...).

foreach sid [array names sym] {
    struct::list assign $sym($sid) name lod lodname shape
    if {$lod eq ""} continue ; # Root has no parent.
    dg arc insert $sid $lod
}

# Convert the graph to dot, then run the layouter and convert to png,
# at last show the image.

vc::tools::dot layout png dg SymbolTree st.png
exec display st.png
file delete st.png
exit