Artifact 6c405827269eda1089a1ffe58e03b4657a7bdfa6:
File
tools/cvs2fossil/symboltree
part of check-in
[b8c3542172]
- Added two helper applications which peek into a conversion state and generate graphs from it. Both helpers look at the tree of symbols and show it in toto (symbol tree), or restrict themselves to the branches, aka lines of development (lodtree).
by
aku on
2007-11-22 07:24:06.
0000: 23 21 2f 62 69 6e 2f 73 68 0a 23 23 20 2d 2a 2d #!/bin/sh.## -*-
0010: 20 74 63 6c 20 2d 2a 2d 20 5c 0a 65 78 65 63 20 tcl -*- \.exec
0020: 74 63 6c 73 68 20 22 24 30 22 20 24 7b 31 2b 22 tclsh "$0" ${1+"
0030: 24 40 22 7d 0a 0a 23 20 23 20 23 23 20 23 23 23 $@"}..# # ## ###
0040: 20 23 23 23 23 23 20 23 23 23 23 23 23 23 23 20 ##### ########
0050: 23 23 23 23 23 23 23 23 23 23 23 23 23 20 23 23 ############# ##
0060: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
0070: 23 23 23 0a 23 23 20 43 6f 70 79 72 69 67 68 74 ###.## Copyright
0080: 20 28 63 29 20 32 30 30 37 20 41 6e 64 72 65 61 (c) 2007 Andrea
0090: 73 20 4b 75 70 72 69 65 73 2e 0a 23 0a 23 20 54 s Kupries..#.# T
00a0: 68 69 73 20 73 6f 66 74 77 61 72 65 20 69 73 20 his software is
00b0: 6c 69 63 65 6e 73 65 64 20 61 73 20 64 65 73 63 licensed as desc
00c0: 72 69 62 65 64 20 69 6e 20 74 68 65 20 66 69 6c ribed in the fil
00d0: 65 20 4c 49 43 45 4e 53 45 2c 20 77 68 69 63 68 e LICENSE, which
00e0: 0a 23 20 79 6f 75 20 73 68 6f 75 6c 64 20 68 61 .# you should ha
00f0: 76 65 20 72 65 63 65 69 76 65 64 20 61 73 20 70 ve received as p
0100: 61 72 74 20 6f 66 20 74 68 69 73 20 64 69 73 74 art of this dist
0110: 72 69 62 75 74 69 6f 6e 2e 0a 23 0a 23 20 54 68 ribution..#.# Th
0120: 69 73 20 73 6f 66 74 77 61 72 65 20 63 6f 6e 73 is software cons
0130: 69 73 74 73 20 6f 66 20 76 6f 6c 75 6e 74 61 72 ists of voluntar
0140: 79 20 63 6f 6e 74 72 69 62 75 74 69 6f 6e 73 20 y contributions
0150: 6d 61 64 65 20 62 79 20 6d 61 6e 79 0a 23 20 69 made by many.# i
0160: 6e 64 69 76 69 64 75 61 6c 73 2e 20 20 46 6f 72 ndividuals. For
0170: 20 65 78 61 63 74 20 63 6f 6e 74 72 69 62 75 74 exact contribut
0180: 69 6f 6e 20 68 69 73 74 6f 72 79 2c 20 73 65 65 ion history, see
0190: 20 74 68 65 20 72 65 76 69 73 69 6f 6e 0a 23 20 the revision.#
01a0: 68 69 73 74 6f 72 79 20 61 6e 64 20 6c 6f 67 73 history and logs
01b0: 2c 20 61 76 61 69 6c 61 62 6c 65 20 61 74 20 68 , available at h
01c0: 74 74 70 3a 2f 2f 66 6f 73 73 69 6c 2d 73 63 6d ttp://fossil-scm
01d0: 2e 68 77 61 63 69 2e 63 6f 6d 2f 66 6f 73 73 69 .hwaci.com/fossi
01e0: 6c 0a 23 20 23 20 23 23 20 23 23 23 20 23 23 23 l.# # ## ### ###
01f0: 23 23 20 23 23 23 23 23 23 23 23 20 23 23 23 23 ## ######## ####
0200: 23 23 23 23 23 23 23 23 23 20 23 23 23 23 23 23 ######### ######
0210: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 0a ###############.
0220: 0a 23 23 20 43 6f 6d 6d 61 6e 64 20 6c 69 6e 65 .## Command line
0230: 20 61 70 70 6c 69 63 61 74 69 6f 6e 20 74 6f 20 application to
0240: 65 78 74 72 61 63 74 20 74 68 65 20 74 72 65 65 extract the tree
0250: 20 6f 66 20 73 79 6d 62 6f 6c 73 20 28 74 61 67 of symbols (tag
0260: 73 20 61 6e 64 0a 23 23 20 62 72 61 6e 63 68 65 s and.## branche
0270: 73 29 20 66 72 6f 6d 20 61 20 73 74 61 74 65 20 s) from a state
0280: 64 61 74 61 62 61 73 65 20 61 6e 64 20 73 68 6f database and sho
0290: 77 20 69 74 20 67 72 61 70 68 69 63 61 6c 6c 79 w it graphically
02a0: 2e 20 54 68 65 20 63 6f 64 65 0a 23 23 20 75 73 . The code.## us
02b0: 65 73 20 47 72 61 70 68 56 69 7a 27 73 20 27 64 es GraphViz's 'd
02c0: 6f 74 27 20 74 6f 20 64 6f 20 74 68 65 20 6c 61 ot' to do the la
02d0: 79 6f 75 74 69 6e 67 20 61 6e 64 20 63 6f 6e 76 youting and conv
02e0: 65 72 73 69 6f 6e 20 69 6e 74 6f 20 61 6e 0a 23 ersion into an.#
02f0: 23 20 69 6d 61 67 65 2e 0a 0a 23 20 23 20 23 23 # image...# # ##
0300: 20 23 23 23 20 23 23 23 23 23 20 23 23 23 23 23 ### ##### #####
0310: 23 23 23 20 23 23 23 23 23 23 23 23 23 23 23 23 ### ############
0320: 23 20 23 23 23 23 23 23 23 23 23 23 23 23 23 23 # ##############
0330: 23 23 23 23 23 23 23 0a 23 23 20 52 65 71 75 69 #######.## Requi
0340: 72 65 6d 65 6e 74 73 2c 20 65 78 74 65 6e 64 65 rements, extende
0350: 64 20 70 61 63 6b 61 67 65 20 6d 61 6e 61 67 65 d package manage
0360: 6d 65 6e 74 20 66 6f 72 20 6c 6f 63 61 6c 20 70 ment for local p
0370: 61 63 6b 61 67 65 73 2e 0a 0a 6c 61 70 70 65 6e ackages...lappen
0380: 64 20 61 75 74 6f 5f 70 61 74 68 20 5b 66 69 6c d auto_path [fil
0390: 65 20 6a 6f 69 6e 20 5b 66 69 6c 65 20 64 69 72 e join [file dir
03a0: 6e 61 6d 65 20 5b 69 6e 66 6f 20 73 63 72 69 70 name [info scrip
03b0: 74 5d 5d 20 6c 69 62 5d 0a 0a 70 61 63 6b 61 67 t]] lib]..packag
03c0: 65 20 72 65 71 75 69 72 65 20 54 63 6c 20 38 2e e require Tcl 8.
03d0: 34 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 4
03e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
03f0: 3b 20 23 20 52 65 71 75 69 72 65 64 20 72 75 6e ; # Required run
0400: 74 69 6d 65 2e 0a 70 61 63 6b 61 67 65 20 72 65 time..package re
0410: 71 75 69 72 65 20 73 74 72 75 63 74 3a 3a 67 72 quire struct::gr
0420: 61 70 68 20 20 20 20 20 20 20 20 20 20 20 20 20 aph
0430: 20 20 20 20 20 20 20 20 20 20 20 20 3b 20 23 20 ; #
0440: 47 72 61 70 68 20 68 61 6e 64 6c 69 6e 67 2e 0a Graph handling..
0450: 70 61 63 6b 61 67 65 20 72 65 71 75 69 72 65 20 package require
0460: 73 74 72 75 63 74 3a 3a 6c 69 73 74 20 20 20 20 struct::list
0470: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0480: 20 20 20 20 20 20 3b 20 23 20 48 69 67 68 65 72 ; # Higher
0490: 20 6f 72 64 65 72 20 6c 69 73 74 20 6f 70 73 2e order list ops.
04a0: 0a 70 61 63 6b 61 67 65 20 72 65 71 75 69 72 65 .package require
04b0: 20 76 63 3a 3a 66 6f 73 73 69 6c 3a 3a 69 6d 70 vc::fossil::imp
04c0: 6f 72 74 3a 3a 63 76 73 3a 3a 73 74 61 74 65 20 ort::cvs::state
04d0: 20 20 20 20 20 20 20 3b 20 23 20 53 74 61 74 65 ; # State
04e0: 20 73 74 6f 72 61 67 65 2e 0a 70 61 63 6b 61 67 storage..packag
04f0: 65 20 72 65 71 75 69 72 65 20 76 63 3a 3a 74 6f e require vc::to
0500: 6f 6c 73 3a 3a 64 6f 74 20 20 20 20 20 20 20 20 ols::dot
0510: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0520: 3b 20 23 20 47 72 61 70 68 20 65 78 70 6f 72 74 ; # Graph export
0530: 20 74 6f 20 44 4f 54 2e 0a 0a 6e 61 6d 65 73 70 to DOT...namesp
0540: 61 63 65 20 69 6d 70 6f 72 74 20 3a 3a 76 63 3a ace import ::vc:
0550: 3a 66 6f 73 73 69 6c 3a 3a 69 6d 70 6f 72 74 3a :fossil::import:
0560: 3a 63 76 73 3a 3a 73 74 61 74 65 0a 6e 61 6d 65 :cvs::state.name
0570: 73 70 61 63 65 20 69 6d 70 6f 72 74 20 3a 3a 76 space import ::v
0580: 63 3a 3a 74 6f 6f 6c 73 3a 3a 64 6f 74 0a 0a 23 c::tools::dot..#
0590: 20 50 72 6f 63 65 73 73 20 74 68 65 20 63 6f 6d Process the com
05a0: 6d 61 6e 64 20 6c 69 6e 65 2e 20 47 65 74 20 74 mand line. Get t
05b0: 68 65 20 64 61 74 61 62 61 73 65 20 74 6f 20 61 he database to a
05c0: 63 63 65 73 73 2e 0a 0a 73 74 61 74 65 20 75 73 ccess...state us
05d0: 65 20 5b 6c 69 6e 64 65 78 20 24 61 72 67 76 20 e [lindex $argv
05e0: 30 5d 0a 73 74 61 74 65 20 72 65 61 64 69 6e 67 0].state reading
05f0: 20 73 79 6d 62 6f 6c 0a 73 74 61 74 65 20 72 65 symbol.state re
0600: 61 64 69 6e 67 20 70 61 72 65 6e 74 0a 0a 23 20 ading parent..#
0610: 47 65 74 20 74 68 65 20 64 61 74 61 20 6f 66 20 Get the data of
0620: 61 6c 6c 20 73 79 6d 62 6f 6c 73 20 69 6e 20 74 all symbols in t
0630: 68 65 20 73 74 61 74 65 20 61 73 20 61 20 6c 69 he state as a li
0640: 73 74 20 66 6f 72 20 69 74 65 72 61 74 69 6f 6e st for iteration
0650: 2c 0a 23 20 61 6e 64 20 61 73 20 61 72 72 61 79 ,.# and as array
0660: 20 66 6f 72 20 72 61 6e 64 6f 6d 20 61 63 63 65 for random acce
0670: 73 73 20 6f 66 20 6e 65 69 67 68 62 6f 75 72 69 ss of neighbouri
0680: 6e 67 20 73 79 6d 62 6f 6c 73 2e 0a 0a 66 6f 72 ng symbols...for
0690: 65 61 63 68 20 7b 73 69 64 20 6e 61 6d 65 7d 20 each {sid name}
06a0: 5b 73 65 74 20 73 79 6d 62 6f 6c 73 20 5b 73 74 [set symbols [st
06b0: 61 74 65 20 72 75 6e 20 7b 20 53 45 4c 45 43 54 ate run { SELECT
06c0: 20 73 69 64 2c 20 6e 61 6d 65 20 46 52 4f 4d 20 sid, name FROM
06d0: 73 79 6d 62 6f 6c 20 7d 5d 5d 20 7b 0a 20 20 20 symbol }]] {.
06e0: 20 73 65 74 20 73 79 6d 28 24 73 69 64 29 20 5b set sym($sid) [
06f0: 6c 69 73 74 20 24 6e 61 6d 65 5d 0a 7d 0a 66 6f list $name].}.fo
0700: 72 65 61 63 68 20 7b 73 69 64 20 6c 6f 64 7d 20 reach {sid lod}
0710: 5b 73 74 61 74 65 20 72 75 6e 20 7b 20 53 45 4c [state run { SEL
0720: 45 43 54 20 73 69 64 2c 20 6c 6f 64 20 46 52 4f ECT sid, lod FRO
0730: 4d 20 74 61 67 20 7d 5d 20 7b 0a 20 20 20 20 6c M tag }] {. l
0740: 61 70 70 65 6e 64 20 73 79 6d 28 24 73 69 64 29 append sym($sid)
0750: 20 24 6c 6f 64 20 24 73 79 6d 28 24 6c 6f 64 29 $lod $sym($lod)
0760: 20 62 6f 78 20 54 61 67 0a 7d 0a 66 6f 72 65 61 box Tag.}.forea
0770: 63 68 20 7b 73 69 64 20 6c 6f 64 7d 20 5b 73 74 ch {sid lod} [st
0780: 61 74 65 20 72 75 6e 20 7b 20 53 45 4c 45 43 54 ate run { SELECT
0790: 20 73 69 64 2c 20 6c 6f 64 20 46 52 4f 4d 20 62 sid, lod FROM b
07a0: 72 61 6e 63 68 20 7d 5d 20 7b 0a 20 20 20 20 6c ranch }] {. l
07b0: 61 70 70 65 6e 64 20 73 79 6d 28 24 73 69 64 29 append sym($sid)
07c0: 20 24 6c 6f 64 20 24 73 79 6d 28 24 6c 6f 64 29 $lod $sym($lod)
07d0: 20 64 69 61 6d 6f 6e 64 20 42 72 61 6e 63 68 0a diamond Branch.
07e0: 7d 0a 0a 23 20 53 74 61 72 74 20 74 68 65 20 67 }..# Start the g
07f0: 72 61 70 68 0a 0a 73 74 72 75 63 74 3a 3a 67 72 raph..struct::gr
0800: 61 70 68 20 64 67 0a 0a 23 20 43 6f 6e 76 65 72 aph dg..# Conver
0810: 74 20 74 68 65 20 73 79 6d 62 6f 6c 73 20 69 6e t the symbols in
0820: 74 6f 20 6e 6f 64 65 73 20 6f 66 20 74 68 65 20 to nodes of the
0830: 67 72 61 70 68 2c 20 61 6e 64 20 75 73 65 20 6e graph, and use n
0840: 6f 64 65 20 61 74 74 72 69 62 75 74 65 73 0a 23 ode attributes.#
0850: 20 74 6f 20 68 69 67 68 6c 69 67 68 74 20 76 61 to highlight va
0860: 72 69 6f 75 73 20 70 69 65 63 65 73 20 6f 66 20 rious pieces of
0870: 69 6e 74 65 72 65 73 74 20 66 6f 72 20 74 68 65 interest for the
0880: 20 64 6f 74 20 63 6f 6e 76 65 72 73 69 6f 6e 2e dot conversion.
0890: 0a 23 20 4c 61 62 65 6c 20 3d 3e 20 53 79 6d 62 .# Label => Symb
08a0: 6f 6c 20 6e 61 6d 65 2e 0a 0a 66 6f 72 65 61 63 ol name...foreac
08b0: 68 20 73 69 64 20 5b 61 72 72 61 79 20 6e 61 6d h sid [array nam
08c0: 65 73 20 73 79 6d 5d 20 7b 0a 20 20 20 20 64 67 es sym] {. dg
08d0: 20 6e 6f 64 65 20 69 6e 73 65 72 74 20 24 73 69 node insert $si
08e0: 64 0a 20 20 20 20 73 74 72 75 63 74 3a 3a 6c 69 d. struct::li
08f0: 73 74 20 61 73 73 69 67 6e 20 24 73 79 6d 28 24 st assign $sym($
0900: 73 69 64 29 20 6e 61 6d 65 20 6c 6f 64 20 6c 6f sid) name lod lo
0910: 64 6e 61 6d 65 20 73 68 61 70 65 20 77 68 61 74 dname shape what
0920: 0a 20 20 20 20 69 66 20 7b 24 73 68 61 70 65 20 . if {$shape
0930: 65 71 20 22 22 7d 20 7b 20 73 65 74 20 73 68 61 eq ""} { set sha
0940: 70 65 20 63 69 72 63 6c 65 20 7d 0a 20 20 20 20 pe circle }.
0950: 69 66 20 7b 24 77 68 61 74 20 6e 65 20 22 22 7d if {$what ne ""}
0960: 20 7b 20 61 70 70 65 6e 64 20 77 68 61 74 20 22 { append what "
0970: 20 22 20 7d 0a 20 20 20 20 64 67 20 6e 6f 64 65 " }. dg node
0980: 20 73 65 74 20 24 73 69 64 20 6c 61 62 65 6c 20 set $sid label
0990: 22 24 77 68 61 74 24 6e 61 6d 65 22 0a 20 20 20 "$what$name".
09a0: 20 64 67 20 6e 6f 64 65 20 73 65 74 20 24 73 69 dg node set $si
09b0: 64 20 73 68 61 70 65 20 24 73 68 61 70 65 0a 7d d shape $shape.}
09c0: 0a 0a 23 20 47 6f 20 74 68 72 6f 75 67 68 20 74 ..# Go through t
09d0: 68 65 20 73 79 6d 62 6f 6c 73 20 61 20 73 65 63 he symbols a sec
09e0: 6f 6e 64 20 74 69 6d 65 2c 20 6e 6f 77 20 73 65 ond time, now se
09f0: 74 20 75 70 20 74 68 65 20 61 72 63 73 20 62 61 t up the arcs ba
0a00: 73 65 64 20 6f 6e 0a 23 20 74 68 65 69 72 20 70 sed on.# their p
0a10: 61 72 65 6e 74 20 63 68 6f 69 63 65 73 2e 20 55 arent choices. U
0a20: 73 65 20 61 72 63 20 61 74 74 72 69 62 75 74 65 se arc attribute
0a30: 73 20 74 6f 20 68 69 67 68 6c 69 67 68 74 20 69 s to highlight i
0a40: 6e 74 65 72 65 73 74 69 6e 67 0a 23 20 74 68 69 nteresting.# thi
0a50: 6e 67 73 20 28 2e 2e 2e 29 2e 0a 0a 66 6f 72 65 ngs (...)...fore
0a60: 61 63 68 20 73 69 64 20 5b 61 72 72 61 79 20 6e ach sid [array n
0a70: 61 6d 65 73 20 73 79 6d 5d 20 7b 0a 20 20 20 20 ames sym] {.
0a80: 73 74 72 75 63 74 3a 3a 6c 69 73 74 20 61 73 73 struct::list ass
0a90: 69 67 6e 20 24 73 79 6d 28 24 73 69 64 29 20 6e ign $sym($sid) n
0aa0: 61 6d 65 20 6c 6f 64 20 6c 6f 64 6e 61 6d 65 20 ame lod lodname
0ab0: 73 68 61 70 65 0a 20 20 20 20 69 66 20 7b 24 6c shape. if {$l
0ac0: 6f 64 20 65 71 20 22 22 7d 20 63 6f 6e 74 69 6e od eq ""} contin
0ad0: 75 65 20 3b 20 23 20 52 6f 6f 74 20 68 61 73 20 ue ; # Root has
0ae0: 6e 6f 20 70 61 72 65 6e 74 2e 0a 20 20 20 20 64 no parent.. d
0af0: 67 20 61 72 63 20 69 6e 73 65 72 74 20 24 73 69 g arc insert $si
0b00: 64 20 24 6c 6f 64 0a 7d 0a 0a 23 20 43 6f 6e 76 d $lod.}..# Conv
0b10: 65 72 74 20 74 68 65 20 67 72 61 70 68 20 74 6f ert the graph to
0b20: 20 64 6f 74 2c 20 74 68 65 6e 20 72 75 6e 20 74 dot, then run t
0b30: 68 65 20 6c 61 79 6f 75 74 65 72 20 61 6e 64 20 he layouter and
0b40: 63 6f 6e 76 65 72 74 20 74 6f 20 70 6e 67 2c 0a convert to png,.
0b50: 23 20 61 74 20 6c 61 73 74 20 73 68 6f 77 20 74 # at last show t
0b60: 68 65 20 69 6d 61 67 65 2e 0a 0a 76 63 3a 3a 74 he image...vc::t
0b70: 6f 6f 6c 73 3a 3a 64 6f 74 20 6c 61 79 6f 75 74 ools::dot layout
0b80: 20 70 6e 67 20 64 67 20 53 79 6d 62 6f 6c 54 72 png dg SymbolTr
0b90: 65 65 20 73 74 2e 70 6e 67 0a 65 78 65 63 20 64 ee st.png.exec d
0ba0: 69 73 70 6c 61 79 20 73 74 2e 70 6e 67 0a 66 69 isplay st.png.fi
0bb0: 6c 65 20 64 65 6c 65 74 65 20 73 74 2e 70 6e 67 le delete st.png
0bc0: 0a 65 78 69 74 0a 0a .exit..