Artifact eadeb78341c0c59f1dec0f0db0383bf797f5ca8f:
File
tools/cvs2fossil/lodtree
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 62 72 61 6e 63 68 65 73 20 28 6c 69 of branches (li
0260: 6e 65 73 20 6f 66 0a 23 23 20 64 65 76 65 6c 6f nes of.## develo
0270: 70 6d 65 6e 74 29 20 66 72 6f 6d 20 61 20 73 74 pment) from a st
0280: 61 74 65 20 64 61 74 61 62 61 73 65 20 61 6e 64 ate database and
0290: 20 73 68 6f 77 20 69 74 20 67 72 61 70 68 69 63 show it graphic
02a0: 61 6c 6c 79 2e 20 54 68 65 0a 23 23 20 63 6f 64 ally. The.## cod
02b0: 65 20 75 73 65 73 20 47 72 61 70 68 56 69 7a 27 e uses GraphViz'
02c0: 73 20 27 64 6f 74 27 20 74 6f 20 64 6f 20 74 68 s 'dot' to do th
02d0: 65 20 6c 61 79 6f 75 74 69 6e 67 20 61 6e 64 20 e layouting and
02e0: 63 6f 6e 76 65 72 73 69 6f 6e 20 69 6e 74 6f 0a conversion into.
02f0: 23 23 20 61 6e 20 69 6d 61 67 65 2e 0a 0a 23 20 ## an image...#
0300: 23 20 23 23 20 23 23 23 20 23 23 23 23 23 20 23 # ## ### ##### #
0310: 23 23 23 23 23 23 23 20 23 23 23 23 23 23 23 23 ####### ########
0320: 23 23 23 23 23 20 23 23 23 23 23 23 23 23 23 23 ##### ##########
0330: 23 23 23 23 23 23 23 23 23 23 23 0a 23 23 20 52 ###########.## R
0340: 65 71 75 69 72 65 6d 65 6e 74 73 2c 20 65 78 74 equirements, ext
0350: 65 6e 64 65 64 20 70 61 63 6b 61 67 65 20 6d 61 ended package ma
0360: 6e 61 67 65 6d 65 6e 74 20 66 6f 72 20 6c 6f 63 nagement for loc
0370: 61 6c 20 70 61 63 6b 61 67 65 73 2e 0a 0a 6c 61 al packages...la
0380: 70 70 65 6e 64 20 61 75 74 6f 5f 70 61 74 68 20 ppend auto_path
0390: 5b 66 69 6c 65 20 6a 6f 69 6e 20 5b 66 69 6c 65 [file join [file
03a0: 20 64 69 72 6e 61 6d 65 20 5b 69 6e 66 6f 20 73 dirname [info s
03b0: 63 72 69 70 74 5d 5d 20 6c 69 62 5d 0a 0a 70 61 cript]] lib]..pa
03c0: 63 6b 61 67 65 20 72 65 71 75 69 72 65 20 54 63 ckage require Tc
03d0: 6c 20 38 2e 34 20 20 20 20 20 20 20 20 20 20 20 l 8.4
03e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
03f0: 20 20 20 20 3b 20 23 20 52 65 71 75 69 72 65 64 ; # Required
0400: 20 72 75 6e 74 69 6d 65 2e 0a 70 61 63 6b 61 67 runtime..packag
0410: 65 20 72 65 71 75 69 72 65 20 73 74 72 75 63 74 e require struct
0420: 3a 3a 67 72 61 70 68 20 20 20 20 20 20 20 20 20 ::graph
0430: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0440: 3b 20 23 20 47 72 61 70 68 20 68 61 6e 64 6c 69 ; # Graph handli
0450: 6e 67 2e 0a 70 61 63 6b 61 67 65 20 72 65 71 75 ng..package requ
0460: 69 72 65 20 73 74 72 75 63 74 3a 3a 6c 69 73 74 ire 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 20 20 20 20 3b 20 23 20 48 69 ; # Hi
0490: 67 68 65 72 20 6f 72 64 65 72 20 6c 69 73 74 20 gher order list
04a0: 6f 70 73 2e 0a 70 61 63 6b 61 67 65 20 72 65 71 ops..package req
04b0: 75 69 72 65 20 76 63 3a 3a 66 6f 73 73 69 6c 3a uire vc::fossil:
04c0: 3a 69 6d 70 6f 72 74 3a 3a 63 76 73 3a 3a 73 74 :import::cvs::st
04d0: 61 74 65 20 20 20 20 20 20 20 20 3b 20 23 20 53 ate ; # S
04e0: 74 61 74 65 20 73 74 6f 72 61 67 65 2e 0a 70 61 tate storage..pa
04f0: 63 6b 61 67 65 20 72 65 71 75 69 72 65 20 76 63 ckage require vc
0500: 3a 3a 74 6f 6f 6c 73 3a 3a 64 6f 74 20 20 20 20 ::tools::dot
0510: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0520: 20 20 20 20 3b 20 23 20 47 72 61 70 68 20 65 78 ; # Graph ex
0530: 70 6f 72 74 20 74 6f 20 44 4f 54 2e 0a 0a 6e 61 port to DOT...na
0540: 6d 65 73 70 61 63 65 20 69 6d 70 6f 72 74 20 3a mespace import :
0550: 3a 76 63 3a 3a 66 6f 73 73 69 6c 3a 3a 69 6d 70 :vc::fossil::imp
0560: 6f 72 74 3a 3a 63 76 73 3a 3a 73 74 61 74 65 0a ort::cvs::state.
0570: 6e 61 6d 65 73 70 61 63 65 20 69 6d 70 6f 72 74 namespace import
0580: 20 3a 3a 76 63 3a 3a 74 6f 6f 6c 73 3a 3a 64 6f ::vc::tools::do
0590: 74 0a 0a 23 20 50 72 6f 63 65 73 73 20 74 68 65 t..# Process the
05a0: 20 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65 2e 20 47 command line. G
05b0: 65 74 20 74 68 65 20 64 61 74 61 62 61 73 65 20 et the database
05c0: 74 6f 20 61 63 63 65 73 73 2e 0a 0a 73 74 61 74 to access...stat
05d0: 65 20 75 73 65 20 5b 6c 69 6e 64 65 78 20 24 61 e use [lindex $a
05e0: 72 67 76 20 30 5d 0a 73 74 61 74 65 20 72 65 61 rgv 0].state rea
05f0: 64 69 6e 67 20 73 79 6d 62 6f 6c 0a 73 74 61 74 ding symbol.stat
0600: 65 20 72 65 61 64 69 6e 67 20 70 61 72 65 6e 74 e reading parent
0610: 0a 0a 23 20 47 65 74 20 74 68 65 20 64 61 74 61 ..# Get the data
0620: 20 6f 66 20 61 6c 6c 20 73 79 6d 62 6f 6c 73 20 of all symbols
0630: 69 6e 20 74 68 65 20 73 74 61 74 65 20 61 73 20 in the state as
0640: 61 20 6c 69 73 74 20 66 6f 72 20 69 74 65 72 61 a list for itera
0650: 74 69 6f 6e 2c 0a 23 20 61 6e 64 20 61 73 20 61 tion,.# and as a
0660: 72 72 61 79 20 66 6f 72 20 72 61 6e 64 6f 6d 20 rray for random
0670: 61 63 63 65 73 73 20 6f 66 20 6e 65 69 67 68 62 access of neighb
0680: 6f 75 72 69 6e 67 20 73 79 6d 62 6f 6c 73 2e 0a ouring symbols..
0690: 0a 66 6f 72 65 61 63 68 20 7b 73 69 64 20 6e 61 .foreach {sid na
06a0: 6d 65 7d 20 5b 73 65 74 20 73 79 6d 62 6f 6c 73 me} [set symbols
06b0: 20 5b 73 74 61 74 65 20 72 75 6e 20 7b 20 53 45 [state run { SE
06c0: 4c 45 43 54 20 73 69 64 2c 20 6e 61 6d 65 20 46 LECT sid, name F
06d0: 52 4f 4d 20 73 79 6d 62 6f 6c 20 7d 5d 5d 20 7b ROM symbol }]] {
06e0: 0a 20 20 20 20 73 65 74 20 73 79 6d 28 24 73 69 . set sym($si
06f0: 64 29 20 5b 6c 69 73 74 20 24 6e 61 6d 65 5d 0a d) [list $name].
0700: 7d 0a 66 6f 72 65 61 63 68 20 7b 73 69 64 20 6c }.foreach {sid l
0710: 6f 64 7d 20 5b 73 74 61 74 65 20 72 75 6e 20 7b od} [state run {
0720: 20 53 45 4c 45 43 54 20 73 69 64 2c 20 6c 6f 64 SELECT sid, lod
0730: 20 46 52 4f 4d 20 74 61 67 20 7d 5d 20 7b 0a 20 FROM tag }] {.
0740: 20 20 20 63 61 74 63 68 20 7b 75 6e 73 65 74 20 catch {unset
0750: 73 79 6d 28 24 73 69 64 29 7d 0a 7d 0a 66 6f 72 sym($sid)}.}.for
0760: 65 61 63 68 20 7b 73 69 64 20 6c 6f 64 7d 20 5b each {sid lod} [
0770: 73 74 61 74 65 20 72 75 6e 20 7b 20 53 45 4c 45 state run { SELE
0780: 43 54 20 73 69 64 2c 20 6c 6f 64 20 46 52 4f 4d CT sid, lod FROM
0790: 20 62 72 61 6e 63 68 20 7d 5d 20 7b 0a 20 20 20 branch }] {.
07a0: 20 6c 61 70 70 65 6e 64 20 73 79 6d 28 24 73 69 lappend sym($si
07b0: 64 29 20 24 6c 6f 64 20 24 73 79 6d 28 24 6c 6f d) $lod $sym($lo
07c0: 64 29 20 64 69 61 6d 6f 6e 64 20 42 72 61 6e 63 d) diamond Branc
07d0: 68 0a 7d 0a 0a 23 20 53 74 61 72 74 20 74 68 65 h.}..# Start the
07e0: 20 67 72 61 70 68 0a 0a 73 74 72 75 63 74 3a 3a graph..struct::
07f0: 67 72 61 70 68 20 64 67 0a 0a 23 20 43 6f 6e 76 graph dg..# Conv
0800: 65 72 74 20 74 68 65 20 73 79 6d 62 6f 6c 73 20 ert the symbols
0810: 69 6e 74 6f 20 6e 6f 64 65 73 20 6f 66 20 74 68 into nodes of th
0820: 65 20 67 72 61 70 68 2c 20 61 6e 64 20 75 73 65 e graph, and use
0830: 20 6e 6f 64 65 20 61 74 74 72 69 62 75 74 65 73 node attributes
0840: 0a 23 20 74 6f 20 68 69 67 68 6c 69 67 68 74 20 .# to highlight
0850: 76 61 72 69 6f 75 73 20 70 69 65 63 65 73 20 6f various pieces o
0860: 66 20 69 6e 74 65 72 65 73 74 20 66 6f 72 20 74 f interest for t
0870: 68 65 20 64 6f 74 20 63 6f 6e 76 65 72 73 69 6f he dot conversio
0880: 6e 2e 0a 23 20 4c 61 62 65 6c 20 3d 3e 20 53 79 n..# Label => Sy
0890: 6d 62 6f 6c 20 6e 61 6d 65 2e 0a 0a 66 6f 72 65 mbol name...fore
08a0: 61 63 68 20 73 69 64 20 5b 61 72 72 61 79 20 6e ach sid [array n
08b0: 61 6d 65 73 20 73 79 6d 5d 20 7b 0a 20 20 20 20 ames sym] {.
08c0: 64 67 20 6e 6f 64 65 20 69 6e 73 65 72 74 20 24 dg node insert $
08d0: 73 69 64 0a 20 20 20 20 73 74 72 75 63 74 3a 3a sid. struct::
08e0: 6c 69 73 74 20 61 73 73 69 67 6e 20 24 73 79 6d list assign $sym
08f0: 28 24 73 69 64 29 20 6e 61 6d 65 20 6c 6f 64 20 ($sid) name lod
0900: 6c 6f 64 6e 61 6d 65 20 73 68 61 70 65 20 77 68 lodname shape wh
0910: 61 74 0a 20 20 20 20 69 66 20 7b 24 73 68 61 70 at. if {$shap
0920: 65 20 65 71 20 22 22 7d 20 7b 20 73 65 74 20 73 e eq ""} { set s
0930: 68 61 70 65 20 63 69 72 63 6c 65 20 7d 0a 20 20 hape circle }.
0940: 20 20 69 66 20 7b 24 77 68 61 74 20 6e 65 20 22 if {$what ne "
0950: 22 7d 20 7b 20 61 70 70 65 6e 64 20 77 68 61 74 "} { append what
0960: 20 22 20 22 20 7d 0a 20 20 20 20 64 67 20 6e 6f " " }. dg no
0970: 64 65 20 73 65 74 20 24 73 69 64 20 6c 61 62 65 de set $sid labe
0980: 6c 20 22 24 77 68 61 74 24 6e 61 6d 65 22 0a 20 l "$what$name".
0990: 20 20 20 64 67 20 6e 6f 64 65 20 73 65 74 20 24 dg node set $
09a0: 73 69 64 20 73 68 61 70 65 20 24 73 68 61 70 65 sid shape $shape
09b0: 0a 7d 0a 0a 23 20 47 6f 20 74 68 72 6f 75 67 68 .}..# Go through
09c0: 20 74 68 65 20 73 79 6d 62 6f 6c 73 20 61 20 73 the symbols a s
09d0: 65 63 6f 6e 64 20 74 69 6d 65 2c 20 6e 6f 77 20 econd time, now
09e0: 73 65 74 20 75 70 20 74 68 65 20 61 72 63 73 20 set up the arcs
09f0: 62 61 73 65 64 20 6f 6e 0a 23 20 74 68 65 69 72 based on.# their
0a00: 20 70 61 72 65 6e 74 20 63 68 6f 69 63 65 73 2e parent choices.
0a10: 20 55 73 65 20 61 72 63 20 61 74 74 72 69 62 75 Use arc attribu
0a20: 74 65 73 20 74 6f 20 68 69 67 68 6c 69 67 68 74 tes to highlight
0a30: 20 69 6e 74 65 72 65 73 74 69 6e 67 0a 23 20 74 interesting.# t
0a40: 68 69 6e 67 73 20 28 2e 2e 2e 29 2e 0a 0a 66 6f hings (...)...fo
0a50: 72 65 61 63 68 20 73 69 64 20 5b 61 72 72 61 79 reach sid [array
0a60: 20 6e 61 6d 65 73 20 73 79 6d 5d 20 7b 0a 20 20 names sym] {.
0a70: 20 20 73 74 72 75 63 74 3a 3a 6c 69 73 74 20 61 struct::list a
0a80: 73 73 69 67 6e 20 24 73 79 6d 28 24 73 69 64 29 ssign $sym($sid)
0a90: 20 6e 61 6d 65 20 6c 6f 64 20 6c 6f 64 6e 61 6d name lod lodnam
0aa0: 65 20 73 68 61 70 65 0a 20 20 20 20 69 66 20 7b e shape. if {
0ab0: 24 6c 6f 64 20 65 71 20 22 22 7d 20 63 6f 6e 74 $lod eq ""} cont
0ac0: 69 6e 75 65 20 3b 20 23 20 52 6f 6f 74 20 68 61 inue ; # Root ha
0ad0: 73 20 6e 6f 20 70 61 72 65 6e 74 2e 0a 20 20 20 s no parent..
0ae0: 20 64 67 20 61 72 63 20 69 6e 73 65 72 74 20 24 dg arc insert $
0af0: 73 69 64 20 24 6c 6f 64 0a 7d 0a 0a 23 20 43 6f sid $lod.}..# Co
0b00: 6e 76 65 72 74 20 74 68 65 20 67 72 61 70 68 20 nvert the graph
0b10: 74 6f 20 64 6f 74 2c 20 74 68 65 6e 20 72 75 6e to dot, then run
0b20: 20 74 68 65 20 6c 61 79 6f 75 74 65 72 20 61 6e the layouter an
0b30: 64 20 63 6f 6e 76 65 72 74 20 74 6f 20 70 6e 67 d convert to png
0b40: 2c 0a 23 20 61 74 20 6c 61 73 74 20 73 68 6f 77 ,.# at last show
0b50: 20 74 68 65 20 69 6d 61 67 65 2e 0a 0a 76 63 3a the image...vc:
0b60: 3a 74 6f 6f 6c 73 3a 3a 64 6f 74 20 6c 61 79 6f :tools::dot layo
0b70: 75 74 20 70 6e 67 20 64 67 20 53 79 6d 62 6f 6c ut png dg Symbol
0b80: 54 72 65 65 20 73 74 2e 70 6e 67 0a 65 78 65 63 Tree st.png.exec
0b90: 20 64 69 73 70 6c 61 79 20 73 74 2e 70 6e 67 0a display st.png.
0ba0: 66 69 6c 65 20 64 65 6c 65 74 65 20 73 74 2e 70 file delete st.p
0bb0: 6e 67 0a 65 78 69 74 0a 0a ng.exit..