Artifact 027ea34f790294e5d02ba159cdffb190463f0201:
File
tools/cvs2fossil/lib/c2f_state.tcl
part of check-in
[b679ca3356]
- Code cleanup. Removed trailing whitespace across the board.
by
aku on
2007-11-25 07:54:09.
0000: 23 23 20 2d 2a 2d 20 74 63 6c 20 2d 2a 2d 0a 23 ## -*- tcl -*-.#
0010: 20 23 20 23 23 20 23 23 23 20 23 23 23 23 23 20 # ## ### #####
0020: 23 23 23 23 23 23 23 23 20 23 23 23 23 23 23 23 ######## #######
0030: 23 23 23 23 23 23 20 23 23 23 23 23 23 23 23 23 ###### #########
0040: 23 23 23 23 23 23 23 23 23 23 23 23 0a 23 23 20 ############.##
0050: 43 6f 70 79 72 69 67 68 74 20 28 63 29 20 32 30 Copyright (c) 20
0060: 30 37 20 41 6e 64 72 65 61 73 20 4b 75 70 72 69 07 Andreas Kupri
0070: 65 73 2e 0a 23 0a 23 20 54 68 69 73 20 73 6f 66 es..#.# This sof
0080: 74 77 61 72 65 20 69 73 20 6c 69 63 65 6e 73 65 tware is license
0090: 64 20 61 73 20 64 65 73 63 72 69 62 65 64 20 69 d as described i
00a0: 6e 20 74 68 65 20 66 69 6c 65 20 4c 49 43 45 4e n the file LICEN
00b0: 53 45 2c 20 77 68 69 63 68 0a 23 20 79 6f 75 20 SE, which.# you
00c0: 73 68 6f 75 6c 64 20 68 61 76 65 20 72 65 63 65 should have rece
00d0: 69 76 65 64 20 61 73 20 70 61 72 74 20 6f 66 20 ived as part of
00e0: 74 68 69 73 20 64 69 73 74 72 69 62 75 74 69 6f this distributio
00f0: 6e 2e 0a 23 0a 23 20 54 68 69 73 20 73 6f 66 74 n..#.# This soft
0100: 77 61 72 65 20 63 6f 6e 73 69 73 74 73 20 6f 66 ware consists of
0110: 20 76 6f 6c 75 6e 74 61 72 79 20 63 6f 6e 74 72 voluntary contr
0120: 69 62 75 74 69 6f 6e 73 20 6d 61 64 65 20 62 79 ibutions made by
0130: 20 6d 61 6e 79 0a 23 20 69 6e 64 69 76 69 64 75 many.# individu
0140: 61 6c 73 2e 20 20 46 6f 72 20 65 78 61 63 74 20 als. For exact
0150: 63 6f 6e 74 72 69 62 75 74 69 6f 6e 20 68 69 73 contribution his
0160: 74 6f 72 79 2c 20 73 65 65 20 74 68 65 20 72 65 tory, see the re
0170: 76 69 73 69 6f 6e 0a 23 20 68 69 73 74 6f 72 79 vision.# history
0180: 20 61 6e 64 20 6c 6f 67 73 2c 20 61 76 61 69 6c and logs, avail
0190: 61 62 6c 65 20 61 74 20 68 74 74 70 3a 2f 2f 66 able at http://f
01a0: 6f 73 73 69 6c 2d 73 63 6d 2e 68 77 61 63 69 2e ossil-scm.hwaci.
01b0: 63 6f 6d 2f 66 6f 73 73 69 6c 0a 23 20 23 20 23 com/fossil.# # #
01c0: 23 20 23 23 23 20 23 23 23 23 23 20 23 23 23 23 # ### ##### ####
01d0: 23 23 23 23 20 23 23 23 23 23 23 23 23 23 23 23 #### ###########
01e0: 23 23 20 23 23 23 23 23 23 23 23 23 23 23 23 23 ## #############
01f0: 23 23 23 23 23 23 23 23 0a 0a 23 23 20 53 74 61 ########..## Sta
0200: 74 65 20 6d 61 6e 61 67 65 72 2e 20 4d 61 69 6e te manager. Main
0210: 74 61 69 6e 73 20 74 68 65 20 73 71 6c 69 74 65 tains the sqlite
0220: 20 64 61 74 61 62 61 73 65 20 75 73 65 64 20 62 database used b
0230: 79 20 61 6c 6c 20 74 68 65 20 6f 74 68 65 72 0a y all the other.
0240: 23 23 20 70 61 72 74 73 20 6f 66 20 74 68 65 20 ## parts of the
0250: 73 79 73 74 65 6d 2c 20 65 73 70 65 63 69 61 6c system, especial
0260: 6c 79 20 74 68 65 20 70 61 73 73 65 73 20 61 6e ly the passes an
0270: 64 20 74 68 65 69 72 20 73 75 70 70 6f 72 74 20 d their support
0280: 63 6f 64 65 2c 0a 23 23 20 74 6f 20 70 65 72 73 code,.## to pers
0290: 69 73 74 20 61 6e 64 20 72 65 73 74 6f 72 65 20 ist and restore
02a0: 74 68 65 69 72 20 73 74 61 74 65 20 61 63 72 6f their state acro
02b0: 73 73 20 69 6e 76 6f 6b 61 74 69 6f 6e 73 2e 0a ss invokations..
02c0: 0a 23 20 23 20 23 23 20 23 23 23 20 23 23 23 23 .# # ## ### ####
02d0: 23 20 23 23 23 23 23 23 23 23 20 23 23 23 23 23 # ######## #####
02e0: 23 23 23 23 23 23 23 23 20 23 23 23 23 23 23 23 ######## #######
02f0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 0a 23 ##############.#
0300: 23 20 52 65 71 75 69 72 65 6d 65 6e 74 73 0a 0a # Requirements..
0310: 70 61 63 6b 61 67 65 20 72 65 71 75 69 72 65 20 package require
0320: 54 63 6c 20 38 2e 34 20 20 20 20 20 20 20 20 20 Tcl 8.4
0330: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0340: 20 3b 20 23 20 52 65 71 75 69 72 65 64 20 72 75 ; # Required ru
0350: 6e 74 69 6d 65 2e 0a 70 61 63 6b 61 67 65 20 72 ntime..package r
0360: 65 71 75 69 72 65 20 73 6e 69 74 20 20 20 20 20 equire snit
0370: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0380: 20 20 20 20 20 20 20 20 3b 20 23 20 4f 4f 20 73 ; # OO s
0390: 79 73 74 65 6d 2e 0a 70 61 63 6b 61 67 65 20 72 ystem..package r
03a0: 65 71 75 69 72 65 20 66 69 6c 65 75 74 69 6c 20 equire fileutil
03b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
03c0: 20 20 20 20 20 20 20 20 3b 20 23 20 46 69 6c 65 ; # File
03d0: 20 6f 70 65 72 61 74 69 6f 6e 73 2e 0a 70 61 63 operations..pac
03e0: 6b 61 67 65 20 72 65 71 75 69 72 65 20 73 71 6c kage require sql
03f0: 69 74 65 33 20 20 20 20 20 20 20 20 20 20 20 20 ite3
0400: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 3b 20 ;
0410: 23 20 44 61 74 61 62 61 73 65 20 61 63 63 65 73 # Database acces
0420: 73 2e 0a 70 61 63 6b 61 67 65 20 72 65 71 75 69 s..package requi
0430: 72 65 20 76 63 3a 3a 74 6f 6f 6c 73 3a 3a 74 72 re vc::tools::tr
0440: 6f 75 62 6c 65 20 20 20 20 20 20 20 20 20 20 20 ouble
0450: 20 20 20 20 3b 20 23 20 45 72 72 6f 72 20 72 65 ; # Error re
0460: 70 6f 72 74 69 6e 67 2e 0a 70 61 63 6b 61 67 65 porting..package
0470: 20 72 65 71 75 69 72 65 20 76 63 3a 3a 74 6f 6f require vc::too
0480: 6c 73 3a 3a 6c 6f 67 20 20 20 20 20 20 20 20 20 ls::log
0490: 20 20 20 20 20 20 20 20 20 20 3b 20 23 20 55 73 ; # Us
04a0: 65 72 20 66 65 65 64 62 61 63 6b 2e 0a 0a 23 20 er feedback...#
04b0: 23 20 23 23 20 23 23 23 20 23 23 23 23 23 20 23 # ## ### ##### #
04c0: 23 23 23 23 23 23 23 20 23 23 23 23 23 23 23 23 ####### ########
04d0: 23 23 23 23 23 20 23 23 23 23 23 23 23 23 23 23 ##### ##########
04e0: 23 23 23 23 23 23 23 23 23 23 23 0a 23 23 0a 0a ###########.##..
04f0: 73 6e 69 74 3a 3a 74 79 70 65 20 3a 3a 76 63 3a snit::type ::vc:
0500: 3a 66 6f 73 73 69 6c 3a 3a 69 6d 70 6f 72 74 3a :fossil::import:
0510: 3a 63 76 73 3a 3a 73 74 61 74 65 20 7b 0a 20 20 :cvs::state {.
0520: 20 20 23 20 23 20 23 23 20 23 23 23 20 23 23 23 # # ## ### ###
0530: 23 23 20 23 23 23 23 23 23 23 23 20 23 23 23 23 ## ######## ####
0540: 23 23 23 23 23 23 23 23 23 0a 20 20 20 20 23 23 #########. ##
0550: 20 50 75 62 6c 69 63 20 41 50 49 0a 0a 20 20 20 Public API..
0560: 20 74 79 70 65 6d 65 74 68 6f 64 20 75 73 65 20 typemethod use
0570: 7b 70 61 74 68 7d 20 7b 0a 09 23 20 49 6d 6d 65 {path} {..# Imme
0580: 64 69 61 74 65 20 76 61 6c 69 64 61 74 69 6f 6e diate validation
0590: 2e 20 54 68 65 72 65 20 61 72 65 20 61 72 65 20 . There are are
05a0: 74 77 6f 20 70 6f 73 73 69 62 69 6c 69 74 69 65 two possibilitie
05b0: 73 20 74 6f 0a 09 23 20 63 6f 6e 73 69 64 65 72 s to..# consider
05c0: 2e 20 54 68 65 20 70 61 74 68 20 65 78 69 73 74 . The path exist
05d0: 73 20 6f 72 20 69 74 20 64 6f 65 73 6e 27 74 2e s or it doesn't.
05e0: 0a 0a 09 23 20 49 6e 20 74 68 65 20 66 69 72 73 ...# In the firs
05f0: 74 20 63 61 73 65 20 69 74 20 68 61 73 20 74 6f t case it has to
0600: 20 62 65 20 61 20 72 65 61 64 61 62 6c 65 20 61 be a readable a
0610: 6e 64 20 77 72 69 74 61 62 6c 65 20 66 69 6c 65 nd writable file
0620: 2c 0a 09 23 20 61 6e 64 20 69 74 20 68 61 73 20 ,..# and it has
0630: 74 6f 20 62 65 20 61 20 70 72 6f 70 65 72 20 73 to be a proper s
0640: 71 6c 69 74 65 20 64 61 74 61 62 61 73 65 2e 20 qlite database.
0650: 46 75 72 74 68 65 72 20 63 68 65 63 6b 73 0a 09 Further checks..
0660: 23 20 72 65 67 61 72 64 69 6e 67 20 74 68 65 20 # regarding the
0670: 72 65 71 75 69 72 65 64 20 74 61 62 6c 65 73 20 required tables
0680: 77 69 6c 6c 20 62 65 20 64 6f 6e 65 20 6c 61 74 will be done lat
0690: 65 72 2c 20 62 79 20 74 68 65 0a 09 23 20 70 61 er, by the..# pa
06a0: 73 73 65 73 2c 20 64 75 72 69 6e 67 20 74 68 65 sses, during the
06b0: 69 72 20 73 65 74 75 70 2e 0a 0a 09 23 20 49 6e ir setup....# In
06c0: 20 74 68 65 20 73 65 63 6f 6e 64 20 63 61 73 65 the second case
06d0: 20 77 65 20 68 61 76 65 20 74 6f 20 62 65 20 61 we have to be a
06e0: 62 6c 65 20 74 6f 20 63 72 65 61 74 65 20 74 68 ble to create th
06f0: 65 20 66 69 6c 65 2c 0a 09 23 20 61 6e 64 20 63 e file,..# and c
0700: 68 65 63 6b 20 74 68 61 74 2e 20 54 68 69 73 20 heck that. This
0710: 69 73 20 64 6f 6e 65 20 62 79 20 6f 70 65 6e 69 is done by openi
0720: 6e 67 20 69 74 2c 20 73 71 6c 69 74 65 20 77 69 ng it, sqlite wi
0730: 6c 6c 20 74 68 65 6e 0a 09 23 20 74 72 79 20 74 ll then..# try t
0740: 6f 20 63 72 65 61 74 65 20 69 74 2c 20 61 6e 64 o create it, and
0750: 20 6d 61 79 20 66 61 69 6c 2e 0a 0a 09 69 66 20 may fail....if
0760: 7b 5b 66 69 6c 65 20 65 78 69 73 74 73 20 24 70 {[file exists $p
0770: 61 74 68 5d 7d 20 7b 0a 09 20 20 20 20 69 66 20 ath]} {.. if
0780: 7b 21 5b 66 69 6c 65 75 74 69 6c 3a 3a 74 65 73 {![fileutil::tes
0790: 74 20 24 70 61 74 68 20 66 72 77 20 6d 73 67 20 t $path frw msg
07a0: 7b 63 76 73 32 66 6f 73 73 69 6c 20 73 74 61 74 {cvs2fossil stat
07b0: 65 7d 5d 7d 20 7b 0a 09 09 74 72 6f 75 62 6c 65 e}]} {...trouble
07c0: 20 66 61 74 61 6c 20 24 6d 73 67 0a 09 09 72 65 fatal $msg...re
07d0: 74 75 72 6e 0a 09 20 20 20 20 7d 0a 09 7d 0a 0a turn.. }..}..
07e0: 09 69 66 20 7b 5b 63 61 74 63 68 20 7b 0a 09 20 .if {[catch {..
07f0: 20 20 20 73 71 6c 69 74 65 33 20 24 7b 74 79 70 sqlite3 ${typ
0800: 65 7d 3a 3a 54 45 4d 50 20 24 70 61 74 68 0a 09 e}::TEMP $path..
0810: 7d 20 72 65 73 5d 7d 20 7b 0a 09 20 20 20 20 74 } res]} {.. t
0820: 72 6f 75 62 6c 65 20 66 61 74 61 6c 20 24 72 65 rouble fatal $re
0830: 73 0a 09 20 20 20 20 72 65 74 75 72 6e 0a 09 7d s.. return..}
0840: 0a 0a 09 23 20 41 20 70 72 65 76 69 6f 75 73 6c ...# A previousl
0850: 79 20 64 65 66 69 6e 65 64 20 73 74 61 74 65 20 y defined state
0860: 64 61 74 61 62 61 73 65 20 69 73 20 63 6c 6f 73 database is clos
0870: 65 64 20 62 65 66 6f 72 65 0a 09 23 20 63 6f 6d ed before..# com
0880: 6d 69 74 74 69 6e 67 20 74 6f 20 74 68 65 20 6e mitting to the n
0890: 65 77 20 64 65 66 69 6e 69 74 69 6f 6e 2e 20 57 ew definition. W
08a0: 65 20 64 6f 20 6e 6f 74 20 73 74 6f 72 65 20 74 e do not store t
08b0: 68 65 20 70 61 74 68 0a 09 23 20 69 74 73 65 6c he path..# itsel
08c0: 66 2c 20 74 68 69 73 20 65 6e 73 75 72 65 73 20 f, this ensures
08d0: 74 68 61 74 20 74 68 65 20 66 69 6c 65 20 69 73 that the file is
08e0: 20 5f 6e 6f 74 5f 20 63 6c 65 61 6e 65 64 20 75 _not_ cleaned u
08f0: 70 20 61 66 74 65 72 0a 09 23 20 61 20 72 75 6e p after..# a run
0900: 2e 0a 0a 09 73 65 74 20 6d 79 73 74 61 74 65 20 ....set mystate
0910: 24 7b 74 79 70 65 7d 3a 3a 53 54 41 54 45 0a 09 ${type}::STATE..
0920: 73 65 74 20 6d 79 70 61 74 68 20 20 7b 7d 0a 0a set mypath {}..
0930: 09 63 61 74 63 68 20 7b 20 24 6d 79 73 74 61 74 .catch { $mystat
0940: 65 20 63 6c 6f 73 65 20 7d 0a 09 72 65 6e 61 6d e close }..renam
0950: 65 20 20 24 7b 74 79 70 65 7d 3a 3a 54 45 4d 50 e ${type}::TEMP
0960: 20 24 6d 79 73 74 61 74 65 0a 0a 09 6c 6f 67 20 $mystate...log
0970: 77 72 69 74 65 20 32 20 73 74 61 74 65 20 22 69 write 2 state "i
0980: 73 20 24 70 61 74 68 22 0a 09 72 65 74 75 72 6e s $path"..return
0990: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 74 79 70 65 . }.. type
09a0: 6d 65 74 68 6f 64 20 73 65 74 75 70 20 7b 7d 20 method setup {}
09b0: 7b 0a 09 23 20 49 66 2c 20 61 6e 64 20 6f 6e 6c {..# If, and onl
09c0: 79 20 69 66 20 6e 6f 20 73 74 61 74 65 20 64 61 y if no state da
09d0: 74 61 62 61 73 65 20 77 61 73 20 64 65 66 69 6e tabase was defin
09e0: 65 64 20 62 79 20 74 68 65 20 75 73 65 72 0a 09 ed by the user..
09f0: 23 20 74 68 65 6e 20 69 74 20 69 73 20 6e 6f 77 # then it is now
0a00: 20 74 68 65 20 74 69 6d 65 20 74 6f 20 63 72 65 the time to cre
0a10: 61 74 65 20 6f 75 72 20 6f 77 6e 20 75 73 69 6e ate our own usin
0a20: 67 20 61 20 74 65 6d 70 66 69 6c 65 2e 0a 0a 09 g a tempfile....
0a30: 69 66 20 7b 24 6d 79 73 74 61 74 65 20 6e 65 20 if {$mystate ne
0a40: 22 22 7d 20 72 65 74 75 72 6e 0a 0a 09 73 65 74 ""} return...set
0a50: 20 6d 79 70 61 74 68 20 20 5b 66 69 6c 65 75 74 mypath [fileut
0a60: 69 6c 3a 3a 74 65 6d 70 66 69 6c 65 20 63 76 73 il::tempfile cvs
0a70: 32 66 6f 73 73 69 6c 5f 73 74 61 74 65 5f 5d 0a 2fossil_state_].
0a80: 09 73 65 74 20 6d 79 73 74 61 74 65 20 24 7b 74 .set mystate ${t
0a90: 79 70 65 7d 3a 3a 53 54 41 54 45 0a 09 73 71 6c ype}::STATE..sql
0aa0: 69 74 65 33 20 24 6d 79 73 74 61 74 65 20 24 6d ite3 $mystate $m
0ab0: 79 70 61 74 68 0a 0a 09 6c 6f 67 20 77 72 69 74 ypath...log writ
0ac0: 65 20 32 20 73 74 61 74 65 20 22 75 73 69 6e 67 e 2 state "using
0ad0: 20 24 6d 79 70 61 74 68 22 0a 09 72 65 74 75 72 $mypath"..retur
0ae0: 6e 0a 20 20 20 20 7d 0a 0a 20 20 20 20 74 79 70 n. }.. typ
0af0: 65 6d 65 74 68 6f 64 20 72 65 6c 65 61 73 65 20 emethod release
0b00: 7b 7d 20 7b 0a 09 6c 6f 67 20 77 72 69 74 65 20 {} {..log write
0b10: 32 20 73 74 61 74 65 20 72 65 6c 65 61 73 65 0a 2 state release.
0b20: 09 24 7b 74 79 70 65 7d 3a 3a 53 54 41 54 45 20 .${type}::STATE
0b30: 63 6c 6f 73 65 0a 09 69 66 20 7b 24 6d 79 70 61 close..if {$mypa
0b40: 74 68 20 65 71 20 22 22 7d 20 72 65 74 75 72 6e th eq ""} return
0b50: 0a 09 66 69 6c 65 20 64 65 6c 65 74 65 20 24 6d ..file delete $m
0b60: 79 70 61 74 68 0a 09 72 65 74 75 72 6e 0a 20 20 ypath..return.
0b70: 20 20 7d 0a 0a 20 20 20 20 74 79 70 65 6d 65 74 }.. typemet
0b80: 68 6f 64 20 77 72 69 74 69 6e 67 20 7b 6e 61 6d hod writing {nam
0b90: 65 20 64 65 66 69 6e 69 74 69 6f 6e 7d 20 7b 0a e definition} {.
0ba0: 09 23 20 4d 65 74 68 6f 64 20 66 6f 72 20 61 20 .# Method for a
0bb0: 75 73 65 72 20 74 6f 20 64 65 63 6c 61 72 65 20 user to declare
0bc0: 61 20 74 61 62 6c 65 20 69 74 73 20 6e 65 65 64 a table its need
0bd0: 73 20 66 6f 72 20 73 74 6f 72 69 6e 67 0a 09 23 s for storing..#
0be0: 20 70 65 72 73 69 73 74 65 6e 74 20 73 74 61 74 persistent stat
0bf0: 65 2c 20 61 6e 64 20 74 68 65 20 65 78 70 65 63 e, and the expec
0c00: 74 65 64 20 73 74 72 75 63 74 75 72 65 2e 20 41 ted structure. A
0c10: 20 70 6f 73 73 69 62 6c 79 0a 09 23 20 70 72 65 possibly..# pre
0c20: 76 69 6f 75 73 6c 79 20 65 78 69 73 74 69 6e 67 viously existing
0c30: 20 64 65 66 69 6e 69 74 69 6f 6e 20 69 73 20 64 definition is d
0c40: 72 6f 70 70 65 64 2e 0a 0a 09 6c 6f 67 20 77 72 ropped....log wr
0c50: 69 74 65 20 31 20 73 74 61 74 65 20 22 77 72 69 ite 1 state "wri
0c60: 74 69 6e 67 20 24 6e 61 6d 65 22 20 3b 20 23 20 ting $name" ; #
0c70: 54 4f 44 4f 20 6d 6f 76 65 20 74 6f 20 6c 65 76 TODO move to lev
0c80: 65 6c 20 35 20 6f 72 20 73 6f 0a 0a 09 24 6d 79 el 5 or so...$my
0c90: 73 74 61 74 65 20 74 72 61 6e 73 61 63 74 69 6f state transactio
0ca0: 6e 20 7b 0a 09 20 20 20 20 63 61 74 63 68 20 7b n {.. catch {
0cb0: 20 24 6d 79 73 74 61 74 65 20 65 76 61 6c 20 22 $mystate eval "
0cc0: 44 52 4f 50 20 54 41 42 4c 45 20 24 6e 61 6d 65 DROP TABLE $name
0cd0: 22 20 7d 0a 09 20 20 20 20 24 6d 79 73 74 61 74 " }.. $mystat
0ce0: 65 20 65 76 61 6c 20 22 43 52 45 41 54 45 20 54 e eval "CREATE T
0cf0: 41 42 4c 45 20 24 6e 61 6d 65 20 28 20 24 64 65 ABLE $name ( $de
0d00: 66 69 6e 69 74 69 6f 6e 20 29 22 0a 09 7d 0a 09 finition )"..}..
0d10: 72 65 74 75 72 6e 0a 20 20 20 20 7d 0a 0a 20 20 return. }..
0d20: 20 20 74 79 70 65 6d 65 74 68 6f 64 20 72 65 61 typemethod rea
0d30: 64 69 6e 67 20 7b 6e 61 6d 65 7d 20 7b 0a 09 6c ding {name} {..l
0d40: 6f 67 20 77 72 69 74 65 20 31 20 73 74 61 74 65 og write 1 state
0d50: 20 22 72 65 61 64 69 6e 67 20 24 6e 61 6d 65 22 "reading $name"
0d60: 20 3b 20 23 20 54 4f 44 4f 20 6d 6f 76 65 20 74 ; # TODO move t
0d70: 6f 20 6c 65 76 65 6c 20 35 20 6f 72 20 73 6f 0a o level 5 or so.
0d80: 0a 09 23 20 4d 65 74 68 6f 64 20 66 6f 72 20 61 ..# Method for a
0d90: 20 75 73 65 72 20 74 6f 20 64 65 63 6c 61 72 65 user to declare
0da0: 20 61 20 74 61 62 6c 65 20 69 74 20 77 69 73 68 a table it wish
0db0: 65 73 20 74 6f 20 72 65 61 64 0a 09 23 20 66 72 es to read..# fr
0dc0: 6f 6d 2e 20 41 20 6d 69 73 73 69 6e 67 20 74 61 om. A missing ta
0dd0: 62 6c 65 20 69 73 20 61 6e 20 69 6e 74 65 72 6e ble is an intern
0de0: 61 6c 20 65 72 72 6f 72 20 63 61 75 73 69 6e 67 al error causing
0df0: 20 61 6e 0a 09 23 20 69 6d 6d 65 64 69 61 74 65 an..# immediate
0e00: 20 65 78 69 74 2e 0a 0a 09 73 65 74 20 66 6f 75 exit....set fou
0e10: 6e 64 20 5b 6c 6c 65 6e 67 74 68 20 5b 24 6d 79 nd [llength [$my
0e20: 73 74 61 74 65 20 65 76 61 6c 20 7b 0a 09 20 20 state eval {..
0e30: 20 20 53 45 4c 45 43 54 20 6e 61 6d 65 0a 09 20 SELECT name..
0e40: 20 20 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d FROM sqlite_m
0e50: 61 73 74 65 72 0a 09 20 20 20 20 57 48 45 52 45 aster.. WHERE
0e60: 20 74 79 70 65 20 3d 20 27 74 61 62 6c 65 27 0a type = 'table'.
0e70: 09 20 20 20 20 41 4e 44 20 20 20 6e 61 6d 65 20 . AND name
0e80: 3d 20 24 6e 61 6d 65 0a 09 20 20 20 20 3b 0a 09 = $name.. ;..
0e90: 7d 5d 5d 0a 0a 09 69 66 20 7b 24 66 6f 75 6e 64 }]]...if {$found
0ea0: 7d 20 72 65 74 75 72 6e 0a 0a 09 74 72 6f 75 62 } return...troub
0eb0: 6c 65 20 69 6e 74 65 72 6e 61 6c 20 22 54 68 65 le internal "The
0ec0: 20 72 65 71 75 69 72 65 64 20 74 61 62 6c 65 20 required table
0ed0: 5c 22 24 6e 61 6d 65 5c 22 20 69 73 20 6e 6f 74 \"$name\" is not
0ee0: 20 64 65 66 69 6e 65 64 2e 22 0a 09 23 20 4e 6f defined."..# No
0ef0: 74 20 72 65 61 63 68 65 64 0a 09 72 65 74 75 72 t reached..retur
0f00: 6e 0a 20 20 20 20 7d 0a 0a 20 20 20 20 74 79 70 n. }.. typ
0f10: 65 6d 65 74 68 6f 64 20 64 69 73 63 61 72 64 20 emethod discard
0f20: 7b 6e 61 6d 65 7d 20 7b 0a 09 23 20 4d 65 74 68 {name} {..# Meth
0f30: 6f 64 20 66 6f 72 20 61 20 75 73 65 72 20 74 6f od for a user to
0f40: 20 72 65 6d 6f 76 65 20 6f 75 74 64 61 74 65 64 remove outdated
0f50: 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 66 72 6f information fro
0f60: 6d 20 74 68 65 0a 09 23 20 70 65 72 73 69 73 74 m the..# persist
0f70: 65 6e 74 20 73 74 61 74 65 2c 20 74 61 62 6c 65 ent state, table
0f80: 20 62 79 20 74 61 62 6c 65 2e 0a 0a 09 6c 6f 67 by table....log
0f90: 20 77 72 69 74 65 20 31 20 73 74 61 74 65 20 22 write 1 state "
0fa0: 64 69 73 63 61 72 64 20 24 6e 61 6d 65 22 20 3b discard $name" ;
0fb0: 20 23 20 54 4f 44 4f 20 6d 6f 76 65 20 74 6f 20 # TODO move to
0fc0: 6c 65 76 65 6c 20 35 20 6f 72 20 73 6f 0a 0a 09 level 5 or so...
0fd0: 24 6d 79 73 74 61 74 65 20 74 72 61 6e 73 61 63 $mystate transac
0fe0: 74 69 6f 6e 20 7b 0a 09 20 20 20 20 63 61 74 63 tion {.. catc
0ff0: 68 20 7b 20 24 6d 79 73 74 61 74 65 20 65 76 61 h { $mystate eva
1000: 6c 20 22 44 52 4f 50 20 54 41 42 4c 45 20 24 6e l "DROP TABLE $n
1010: 61 6d 65 22 20 7d 0a 09 7d 0a 09 72 65 74 75 72 ame" }..}..retur
1020: 6e 0a 20 20 20 20 7d 0a 0a 20 20 20 20 74 79 70 n. }.. typ
1030: 65 6d 65 74 68 6f 64 20 72 75 6e 20 7b 61 72 67 emethod run {arg
1040: 73 7d 20 7b 0a 09 72 65 74 75 72 6e 20 5b 75 70 s} {..return [up
1050: 6c 65 76 65 6c 20 31 20 5b 6c 69 6e 73 65 72 74 level 1 [linsert
1060: 20 24 61 72 67 73 20 30 20 24 6d 79 73 74 61 74 $args 0 $mystat
1070: 65 20 65 76 61 6c 5d 5d 0a 20 20 20 20 7d 0a 0a e eval]]. }..
1080: 20 20 20 20 74 79 70 65 6d 65 74 68 6f 64 20 6f typemethod o
1090: 6e 65 20 7b 61 72 67 73 7d 20 7b 0a 09 72 65 74 ne {args} {..ret
10a0: 75 72 6e 20 5b 6c 69 6e 64 65 78 20 5b 75 70 6c urn [lindex [upl
10b0: 65 76 65 6c 20 31 20 5b 6c 69 6e 73 65 72 74 20 evel 1 [linsert
10c0: 24 61 72 67 73 20 30 20 24 6d 79 73 74 61 74 65 $args 0 $mystate
10d0: 20 65 76 61 6c 5d 5d 20 30 5d 0a 20 20 20 20 7d eval]] 0]. }
10e0: 0a 0a 20 20 20 20 74 79 70 65 6d 65 74 68 6f 64 .. typemethod
10f0: 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 7b 73 63 transaction {sc
1100: 72 69 70 74 7d 20 7b 0a 09 72 65 74 75 72 6e 20 ript} {..return
1110: 5b 75 70 6c 65 76 65 6c 20 31 20 5b 6c 69 73 74 [uplevel 1 [list
1120: 20 24 6d 79 73 74 61 74 65 20 74 72 61 6e 73 61 $mystate transa
1130: 63 74 69 6f 6e 20 24 73 63 72 69 70 74 5d 5d 0a ction $script]].
1140: 20 20 20 20 7d 0a 0a 20 20 20 20 74 79 70 65 6d }.. typem
1150: 65 74 68 6f 64 20 69 64 20 7b 7d 20 7b 0a 09 72 ethod id {} {..r
1160: 65 74 75 72 6e 20 5b 24 6d 79 73 74 61 74 65 20 eturn [$mystate
1170: 6c 61 73 74 5f 69 6e 73 65 72 74 5f 72 6f 77 69 last_insert_rowi
1180: 64 5d 0a 20 20 20 20 7d 0a 0a 20 20 20 20 23 20 d]. }.. #
1190: 23 20 23 23 20 23 23 23 20 23 23 23 23 23 20 23 # ## ### ##### #
11a0: 23 23 23 23 23 23 23 20 23 23 23 23 23 23 23 23 ####### ########
11b0: 23 23 23 23 23 0a 20 20 20 20 23 23 20 53 74 61 #####. ## Sta
11c0: 74 65 0a 0a 20 20 20 20 74 79 70 65 76 61 72 69 te.. typevari
11d0: 61 62 6c 65 20 6d 79 73 74 61 74 65 20 7b 7d 20 able mystate {}
11e0: 3b 20 23 20 53 71 6c 69 74 65 20 64 61 74 61 62 ; # Sqlite datab
11f0: 61 73 65 20 28 63 6f 6d 6d 61 6e 64 29 20 68 6f ase (command) ho
1200: 6c 64 69 6e 67 20 74 68 65 20 63 6f 6e 76 65 72 lding the conver
1210: 74 65 72 20 73 74 61 74 65 2e 0a 20 20 20 20 74 ter state.. t
1220: 79 70 65 76 61 72 69 61 62 6c 65 20 6d 79 70 61 ypevariable mypa
1230: 74 68 20 20 7b 7d 20 3b 20 23 20 50 61 74 68 20 th {} ; # Path
1240: 74 6f 20 74 68 65 20 64 61 74 61 62 61 73 65 2c to the database,
1250: 20 66 6f 72 20 63 6c 65 61 6e 75 70 20 6f 66 20 for cleanup of
1260: 61 20 74 65 6d 70 20 64 61 74 61 62 61 73 65 2e a temp database.
1270: 0a 0a 20 20 20 20 23 20 23 20 23 23 20 23 23 23 .. # # ## ###
1280: 20 23 23 23 23 23 20 23 23 23 23 23 23 23 23 20 ##### ########
1290: 23 23 23 23 23 23 23 23 23 23 23 23 23 0a 20 20 #############.
12a0: 20 20 23 23 20 49 6e 74 65 72 6e 61 6c 20 6d 65 ## Internal me
12b0: 74 68 6f 64 73 0a 0a 0a 20 20 20 20 23 20 23 20 thods... # #
12c0: 23 23 20 23 23 23 20 23 23 23 23 23 20 23 23 23 ## ### ##### ###
12d0: 23 23 23 23 23 20 23 23 23 23 23 23 23 23 23 23 ##### ##########
12e0: 23 23 23 0a 20 20 20 20 23 23 20 43 6f 6e 66 69 ###. ## Confi
12f0: 67 75 72 61 74 69 6f 6e 0a 0a 20 20 20 20 70 72 guration.. pr
1300: 61 67 6d 61 20 2d 68 61 73 69 6e 73 74 61 6e 63 agma -hasinstanc
1310: 65 73 20 20 20 6e 6f 20 3b 20 23 20 73 69 6e 67 es no ; # sing
1320: 6c 65 74 6f 6e 0a 20 20 20 20 70 72 61 67 6d 61 leton. pragma
1330: 20 2d 68 61 73 74 79 70 65 69 6e 66 6f 20 20 20 -hastypeinfo
1340: 20 6e 6f 20 3b 20 23 20 6e 6f 20 69 6e 74 72 6f no ; # no intro
1350: 73 70 65 63 74 69 6f 6e 0a 20 20 20 20 70 72 61 spection. pra
1360: 67 6d 61 20 2d 68 61 73 74 79 70 65 64 65 73 74 gma -hastypedest
1370: 72 6f 79 20 6e 6f 20 3b 20 23 20 69 6d 6d 6f 72 roy no ; # immor
1380: 74 61 6c 0a 0a 20 20 20 20 23 20 23 20 23 23 20 tal.. # # ##
1390: 23 23 23 20 23 23 23 23 23 20 23 23 23 23 23 23 ### ##### ######
13a0: 23 23 20 23 23 23 23 23 23 23 23 23 23 23 23 23 ## #############
13b0: 0a 7d 0a 0a 6e 61 6d 65 73 70 61 63 65 20 65 76 .}..namespace ev
13c0: 61 6c 20 3a 3a 76 63 3a 3a 66 6f 73 73 69 6c 3a al ::vc::fossil:
13d0: 3a 69 6d 70 6f 72 74 3a 3a 63 76 73 20 7b 0a 20 :import::cvs {.
13e0: 20 20 20 6e 61 6d 65 73 70 61 63 65 20 65 78 70 namespace exp
13f0: 6f 72 74 20 73 74 61 74 65 0a 20 20 20 20 6e 61 ort state. na
1400: 6d 65 73 70 61 63 65 20 65 76 61 6c 20 73 74 61 mespace eval sta
1410: 74 65 20 7b 0a 09 6e 61 6d 65 73 70 61 63 65 20 te {..namespace
1420: 69 6d 70 6f 72 74 20 3a 3a 76 63 3a 3a 74 6f 6f import ::vc::too
1430: 6c 73 3a 3a 74 72 6f 75 62 6c 65 0a 09 6e 61 6d ls::trouble..nam
1440: 65 73 70 61 63 65 20 69 6d 70 6f 72 74 20 3a 3a espace import ::
1450: 76 63 3a 3a 74 6f 6f 6c 73 3a 3a 6c 6f 67 0a 09 vc::tools::log..
1460: 6c 6f 67 20 72 65 67 69 73 74 65 72 20 73 74 61 log register sta
1470: 74 65 0a 20 20 20 20 7d 0a 7d 0a 0a 23 20 23 20 te. }.}..# #
1480: 23 23 20 23 23 23 20 23 23 23 23 23 20 23 23 23 ## ### ##### ###
1490: 23 23 23 23 23 20 23 23 23 23 23 23 23 23 23 23 ##### ##########
14a0: 23 23 23 20 23 23 23 23 23 23 23 23 23 23 23 23 ### ############
14b0: 23 23 23 23 23 23 23 23 23 0a 23 23 20 52 65 61 #########.## Rea
14c0: 64 79 0a 0a 70 61 63 6b 61 67 65 20 70 72 6f 76 dy..package prov
14d0: 69 64 65 20 76 63 3a 3a 66 6f 73 73 69 6c 3a 3a ide vc::fossil::
14e0: 69 6d 70 6f 72 74 3a 3a 63 76 73 3a 3a 73 74 61 import::cvs::sta
14f0: 74 65 20 31 2e 30 0a 72 65 74 75 72 6e 0a te 1.0.return.