Hex Artifact Content
Not logged in

Artifact b562462581be29a9bb4ca692de48a78fb7123c6c:

File tools/cvs2fossil/lib/c2f_prev.tcl part of check-in [9214c11831] - Changeset handling, extended logging of how parent is determined. Fossil access, fixed importrev call to use correct workspace/repository. Fixed handling of output, stripping unwanted text, checking of output syntax. Extended logging. Added final 'rebuild'. NOTE: formation of the changesets/manifests is buggy, is not tracking unchanged files across changesets. Further not yet tracking when files have been removed. by aku on 2008-02-02 07:03:39.

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 52 65 76  ########..## Rev
0200: 69 73 69 6f 6e 73 20 70 65 72 20 70 72 6f 6a 65  isions per proje
0210: 63 74 2c 20 61 6b 61 20 43 68 61 6e 67 65 73 65  ct, aka Changese
0220: 74 73 2e 20 54 68 65 73 65 20 6f 62 6a 65 63 74  ts. These object
0230: 73 20 61 72 65 20 66 69 72 73 74 20 75 73 65 64  s are first used
0240: 0a 23 23 20 69 6e 20 70 61 73 73 20 35 2c 20 77  .## in pass 5, w
0250: 68 69 63 68 20 63 72 65 61 74 65 73 20 74 68 65  hich creates the
0260: 20 69 6e 69 74 69 61 6c 20 73 65 74 20 63 6f 76   initial set cov
0270: 65 72 69 6e 67 20 74 68 65 20 72 65 70 6f 73 69  ering the reposi
0280: 74 6f 72 79 2e 0a 0a 23 20 23 20 23 23 20 23 23  tory...# # ## ##
0290: 23 20 23 23 23 23 23 20 23 23 23 23 23 23 23 23  # ##### ########
02a0: 20 23 23 23 23 23 23 23 23 23 23 23 23 23 20 23   ############# #
02b0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
02c0: 23 23 23 23 0a 23 23 20 52 65 71 75 69 72 65 6d  ####.## Requirem
02d0: 65 6e 74 73 0a 0a 70 61 63 6b 61 67 65 20 72 65  ents..package re
02e0: 71 75 69 72 65 20 54 63 6c 20 38 2e 34 20 20 20  quire Tcl 8.4   
02f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0300: 20 20 20 20 20 20 20 20 20 20 20 20 3b 20 23 20              ; # 
0310: 52 65 71 75 69 72 65 64 20 72 75 6e 74 69 6d 65  Required runtime
0320: 2e 0a 70 61 63 6b 61 67 65 20 72 65 71 75 69 72  ..package requir
0330: 65 20 73 6e 69 74 20 20 20 20 20 20 20 20 20 20  e snit          
0340: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0350: 20 20 20 20 20 20 20 20 3b 20 23 20 4f 4f 20 73          ; # OO s
0360: 79 73 74 65 6d 2e 0a 70 61 63 6b 61 67 65 20 72  ystem..package r
0370: 65 71 75 69 72 65 20 73 74 72 75 63 74 3a 3a 73  equire struct::s
0380: 65 74 20 20 20 20 20 20 20 20 20 20 20 20 20 20  et              
0390: 20 20 20 20 20 20 20 20 20 20 20 20 20 3b 20 23               ; #
03a0: 20 53 65 74 20 6f 70 65 72 61 74 69 6f 6e 73 2e   Set operations.
03b0: 0a 70 61 63 6b 61 67 65 20 72 65 71 75 69 72 65  .package require
03c0: 20 76 63 3a 3a 74 6f 6f 6c 73 3a 3a 6d 69 73 63   vc::tools::misc
03d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
03e0: 20 20 20 20 20 20 20 3b 20 23 20 54 65 78 74 20         ; # Text 
03f0: 66 6f 72 6d 61 74 74 69 6e 67 0a 70 61 63 6b 61  formatting.packa
0400: 67 65 20 72 65 71 75 69 72 65 20 76 63 3a 3a 74  ge require vc::t
0410: 6f 6f 6c 73 3a 3a 74 72 6f 75 62 6c 65 20 20 20  ools::trouble   
0420: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0430: 20 3b 20 23 20 45 72 72 6f 72 20 72 65 70 6f 72   ; # Error repor
0440: 74 69 6e 67 2e 0a 70 61 63 6b 61 67 65 20 72 65  ting..package re
0450: 71 75 69 72 65 20 76 63 3a 3a 74 6f 6f 6c 73 3a  quire vc::tools:
0460: 3a 6c 6f 67 20 20 20 20 20 20 20 20 20 20 20 20  :log            
0470: 20 20 20 20 20 20 20 20 20 20 20 20 3b 20 23 20              ; # 
0480: 55 73 65 72 20 66 65 65 64 62 61 63 6b 2e 0a 70  User feedback..p
0490: 61 63 6b 61 67 65 20 72 65 71 75 69 72 65 20 76  ackage require v
04a0: 63 3a 3a 66 6f 73 73 69 6c 3a 3a 69 6d 70 6f 72  c::fossil::impor
04b0: 74 3a 3a 63 76 73 3a 3a 73 74 61 74 65 20 20 20  t::cvs::state   
04c0: 20 20 20 20 20 3b 20 23 20 53 74 61 74 65 20 73       ; # State s
04d0: 74 6f 72 61 67 65 2e 0a 70 61 63 6b 61 67 65 20  torage..package 
04e0: 72 65 71 75 69 72 65 20 76 63 3a 3a 66 6f 73 73  require vc::foss
04f0: 69 6c 3a 3a 69 6d 70 6f 72 74 3a 3a 63 76 73 3a  il::import::cvs:
0500: 3a 69 6e 74 65 67 72 69 74 79 20 20 20 20 3b 20  :integrity    ; 
0510: 23 20 53 74 61 74 65 20 69 6e 74 65 67 72 69 74  # State integrit
0520: 79 20 63 68 65 63 6b 73 2e 0a 0a 23 20 23 20 23  y checks...# # #
0530: 23 20 23 23 23 20 23 23 23 23 23 20 23 23 23 23  # ### ##### ####
0540: 23 23 23 23 20 23 23 23 23 23 23 23 23 23 23 23  #### ###########
0550: 23 23 20 23 23 23 23 23 23 23 23 23 23 23 23 23  ## #############
0560: 23 23 23 23 23 23 23 23 0a 23 23 0a 0a 73 6e 69  ########.##..sni
0570: 74 3a 3a 74 79 70 65 20 3a 3a 76 63 3a 3a 66 6f  t::type ::vc::fo
0580: 73 73 69 6c 3a 3a 69 6d 70 6f 72 74 3a 3a 63 76  ssil::import::cv
0590: 73 3a 3a 70 72 6f 6a 65 63 74 3a 3a 72 65 76 20  s::project::rev 
05a0: 7b 0a 20 20 20 20 23 20 23 20 23 23 20 23 23 23  {.    # # ## ###
05b0: 20 23 23 23 23 23 20 23 23 23 23 23 23 23 23 20   ##### ######## 
05c0: 23 23 23 23 23 23 23 23 23 23 23 23 23 0a 20 20  #############.  
05d0: 20 20 23 23 20 50 75 62 6c 69 63 20 41 50 49 0a    ## Public API.
05e0: 0a 20 20 20 20 63 6f 6e 73 74 72 75 63 74 6f 72  .    constructor
05f0: 20 7b 70 72 6f 6a 65 63 74 20 63 73 74 79 70 65   {project cstype
0600: 20 73 72 63 69 64 20 69 74 65 6d 73 20 7b 74 68   srcid items {th
0610: 65 69 64 20 7b 7d 7d 7d 20 7b 0a 09 69 66 20 7b  eid {}}} {..if {
0620: 24 74 68 65 69 64 20 6e 65 20 22 22 7d 20 7b 0a  $theid ne ""} {.
0630: 09 20 20 20 20 73 65 74 20 6d 79 69 64 20 24 74  .    set myid $t
0640: 68 65 69 64 0a 09 7d 20 65 6c 73 65 20 7b 0a 09  heid..} else {..
0650: 20 20 20 20 73 65 74 20 6d 79 69 64 20 5b 69 6e      set myid [in
0660: 63 72 20 6d 79 63 6f 75 6e 74 65 72 5d 0a 09 7d  cr mycounter]..}
0670: 0a 0a 09 69 6e 74 65 67 72 69 74 79 20 61 73 73  ...integrity ass
0680: 65 72 74 20 7b 0a 09 20 20 20 20 5b 69 6e 66 6f  ert {..    [info
0690: 20 65 78 69 73 74 73 20 6d 79 63 73 74 79 70 65   exists mycstype
06a0: 28 24 63 73 74 79 70 65 29 5d 0a 09 7d 20 7b 42  ($cstype)]..} {B
06b0: 61 64 20 63 68 61 6e 67 65 73 65 74 20 74 79 70  ad changeset typ
06c0: 65 20 27 24 63 73 74 79 70 65 27 2e 7d 0a 0a 09  e '$cstype'.}...
06d0: 73 65 74 20 6d 79 70 72 6f 6a 65 63 74 20 20 20  set myproject   
06e0: 24 70 72 6f 6a 65 63 74 0a 09 73 65 74 20 6d 79  $project..set my
06f0: 74 79 70 65 20 20 20 20 20 20 24 63 73 74 79 70  type      $cstyp
0700: 65 0a 09 73 65 74 20 6d 79 74 79 70 65 6f 62 6a  e..set mytypeobj
0710: 20 20 20 3a 3a 76 63 3a 3a 66 6f 73 73 69 6c 3a     ::vc::fossil:
0720: 3a 69 6d 70 6f 72 74 3a 3a 63 76 73 3a 3a 70 72  :import::cvs::pr
0730: 6f 6a 65 63 74 3a 3a 72 65 76 3a 3a 24 7b 63 73  oject::rev::${cs
0740: 74 79 70 65 7d 0a 09 73 65 74 20 6d 79 73 72 63  type}..set mysrc
0750: 69 64 09 24 73 72 63 69 64 0a 09 73 65 74 20 6d  id.$srcid..set m
0760: 79 69 74 65 6d 73 20 20 20 20 20 24 69 74 65 6d  yitems     $item
0770: 73 0a 09 73 65 74 20 6d 79 70 6f 73 20 20 20 20  s..set mypos    
0780: 20 20 20 7b 7d 20 3b 20 23 20 43 6f 6d 6d 69 74     {} ; # Commit
0790: 20 6c 6f 63 61 74 69 6f 6e 20 69 73 20 6e 6f 74   location is not
07a0: 20 6b 6e 6f 77 6e 20 79 65 74 2e 0a 0a 09 23 20   known yet....# 
07b0: 4b 65 65 70 20 74 72 61 63 6b 20 6f 66 20 74 68  Keep track of th
07c0: 65 20 67 65 6e 65 72 61 74 65 64 20 63 68 61 6e  e generated chan
07d0: 67 65 73 65 74 73 20 61 6e 64 20 6f 66 20 74 68  gesets and of th
07e0: 65 20 69 6e 76 65 72 73 65 0a 09 23 20 6d 61 70  e inverse..# map
07f0: 70 69 6e 67 20 66 72 6f 6d 20 69 74 65 6d 73 20  ping from items 
0800: 74 6f 20 74 68 65 6d 2e 0a 09 6c 61 70 70 65 6e  to them...lappen
0810: 64 20 6d 79 63 68 61 6e 67 65 73 65 74 73 20 20  d mychangesets  
0820: 20 24 73 65 6c 66 0a 09 6c 61 70 70 65 6e 64 20   $self..lappend 
0830: 6d 79 74 63 68 61 6e 67 65 73 65 74 73 28 24 63  mytchangesets($c
0840: 73 74 79 70 65 29 20 24 73 65 6c 66 0a 09 73 65  stype) $self..se
0850: 74 20 20 20 20 20 6d 79 69 64 6d 61 70 28 24 6d  t     myidmap($m
0860: 79 69 64 29 20 24 73 65 6c 66 0a 09 66 6f 72 65  yid) $self..fore
0870: 61 63 68 20 69 69 64 20 24 69 74 65 6d 73 20 7b  ach iid $items {
0880: 0a 09 20 20 20 20 73 65 74 20 6b 65 79 20 5b 6c  ..    set key [l
0890: 69 73 74 20 24 63 73 74 79 70 65 20 24 69 69 64  ist $cstype $iid
08a0: 5d 0a 09 20 20 20 20 73 65 74 20 6d 79 69 74 65  ]..    set myite
08b0: 6d 6d 61 70 28 24 6b 65 79 29 20 24 73 65 6c 66  mmap($key) $self
08c0: 0a 09 20 20 20 20 6c 61 70 70 65 6e 64 20 6d 79  ..    lappend my
08d0: 74 69 74 65 6d 73 20 24 6b 65 79 0a 09 20 20 20  titems $key..   
08e0: 20 6c 6f 67 20 77 72 69 74 65 20 38 20 63 73 65   log write 8 cse
08f0: 74 73 20 7b 4d 41 50 2b 20 69 74 65 6d 20 3c 24  ts {MAP+ item <$
0900: 6b 65 79 3e 20 24 73 65 6c 66 20 3d 20 5b 24 73  key> $self = [$s
0910: 65 6c 66 20 73 74 72 5d 7d 0a 09 7d 0a 09 72 65  elf str]}..}..re
0920: 74 75 72 6e 0a 20 20 20 20 7d 0a 0a 20 20 20 20  turn.    }..    
0930: 6d 65 74 68 6f 64 20 73 74 72 20 7b 7d 20 7b 0a  method str {} {.
0940: 09 73 65 74 20 73 74 72 20 20 20 20 22 3c 22 0a  .set str    "<".
0950: 09 73 65 74 20 64 65 74 61 69 6c 20 22 22 0a 09  .set detail ""..
0960: 69 66 20 7b 5b 24 6d 79 74 79 70 65 6f 62 6a 20  if {[$mytypeobj 
0970: 62 79 73 79 6d 62 6f 6c 5d 7d 20 7b 0a 09 20 20  bysymbol]} {..  
0980: 20 20 73 65 74 20 64 65 74 61 69 6c 20 22 20 27    set detail " '
0990: 5b 73 74 61 74 65 20 6f 6e 65 20 7b 0a 09 09 53  [state one {...S
09a0: 45 4c 45 43 54 20 53 2e 6e 61 6d 65 0a 09 09 46  ELECT S.name...F
09b0: 52 4f 4d 20 20 20 73 79 6d 62 6f 6c 20 53 0a 09  ROM   symbol S..
09c0: 09 57 48 45 52 45 20 20 53 2e 73 69 64 20 3d 20  .WHERE  S.sid = 
09d0: 24 6d 79 73 72 63 69 64 0a 09 20 20 20 20 7d 5d  $mysrcid..    }]
09e0: 27 22 0a 09 7d 0a 09 61 70 70 65 6e 64 20 73 74  '"..}..append st
09f0: 72 20 22 24 6d 79 74 79 70 65 20 24 7b 6d 79 69  r "$mytype ${myi
0a00: 64 7d 24 7b 64 65 74 61 69 6c 7d 3e 22 0a 09 72  d}${detail}>"..r
0a10: 65 74 75 72 6e 20 24 73 74 72 0a 20 20 20 20 7d  eturn $str.    }
0a20: 0a 0a 20 20 20 20 6d 65 74 68 6f 64 20 69 64 20  ..    method id 
0a30: 20 20 20 7b 7d 20 7b 20 72 65 74 75 72 6e 20 24     {} { return $
0a40: 6d 79 69 64 20 7d 0a 20 20 20 20 6d 65 74 68 6f  myid }.    metho
0a50: 64 20 69 74 65 6d 73 20 7b 7d 20 7b 20 72 65 74  d items {} { ret
0a60: 75 72 6e 20 24 6d 79 74 69 74 65 6d 73 20 7d 0a  urn $mytitems }.
0a70: 20 20 20 20 6d 65 74 68 6f 64 20 64 61 74 61 20      method data 
0a80: 20 7b 7d 20 7b 20 72 65 74 75 72 6e 20 5b 6c 69   {} { return [li
0a90: 73 74 20 24 6d 79 70 72 6f 6a 65 63 74 20 24 6d  st $myproject $m
0aa0: 79 74 79 70 65 20 24 6d 79 73 72 63 69 64 5d 20  ytype $mysrcid] 
0ab0: 7d 0a 0a 20 20 20 20 64 65 6c 65 67 61 74 65 20  }..    delegate 
0ac0: 6d 65 74 68 6f 64 20 62 79 73 79 6d 62 6f 6c 20  method bysymbol 
0ad0: 20 20 74 6f 20 6d 79 74 79 70 65 6f 62 6a 0a 20    to mytypeobj. 
0ae0: 20 20 20 64 65 6c 65 67 61 74 65 20 6d 65 74 68     delegate meth
0af0: 6f 64 20 62 79 72 65 76 69 73 69 6f 6e 20 74 6f  od byrevision to
0b00: 20 6d 79 74 79 70 65 6f 62 6a 0a 20 20 20 20 64   mytypeobj.    d
0b10: 65 6c 65 67 61 74 65 20 6d 65 74 68 6f 64 20 69  elegate method i
0b20: 73 62 72 61 6e 63 68 20 20 20 74 6f 20 6d 79 74  sbranch   to myt
0b30: 79 70 65 6f 62 6a 0a 20 20 20 20 64 65 6c 65 67  ypeobj.    deleg
0b40: 61 74 65 20 6d 65 74 68 6f 64 20 69 73 74 61 67  ate method istag
0b50: 20 20 20 20 20 20 74 6f 20 6d 79 74 79 70 65 6f        to mytypeo
0b60: 62 6a 0a 0a 20 20 20 20 6d 65 74 68 6f 64 20 73  bj..    method s
0b70: 65 74 70 6f 73 20 7b 70 7d 20 7b 20 73 65 74 20  etpos {p} { set 
0b80: 6d 79 70 6f 73 20 24 70 20 3b 20 72 65 74 75 72  mypos $p ; retur
0b90: 6e 20 7d 0a 20 20 20 20 6d 65 74 68 6f 64 20 70  n }.    method p
0ba0: 6f 73 20 20 20 20 7b 7d 20 20 7b 20 72 65 74 75  os    {}  { retu
0bb0: 72 6e 20 24 6d 79 70 6f 73 20 7d 0a 0a 20 20 20  rn $mypos }..   
0bc0: 20 6d 65 74 68 6f 64 20 64 65 74 65 72 6d 69 6e   method determin
0bd0: 65 73 75 63 63 65 73 73 6f 72 73 20 7b 7d 20 7b  esuccessors {} {
0be0: 0a 09 23 20 50 61 73 73 20 36 20 6f 70 65 72 61  ..# Pass 6 opera
0bf0: 74 69 6f 6e 2e 20 43 6f 6d 70 75 74 65 20 70 72  tion. Compute pr
0c00: 6f 6a 65 63 74 2d 6c 65 76 65 6c 20 64 65 70 65  oject-level depe
0c10: 6e 64 65 6e 63 69 65 73 20 66 72 6f 6d 0a 09 23  ndencies from..#
0c20: 20 74 68 65 20 66 69 6c 65 2d 6c 65 76 65 6c 20   the file-level 
0c30: 64 61 74 61 20 61 6e 64 20 73 61 76 65 20 69 74  data and save it
0c40: 20 62 61 63 6b 20 74 6f 20 74 68 65 20 73 74 61   back to the sta
0c50: 74 65 2e 20 54 68 69 73 20 6d 61 79 0a 09 23 20  te. This may..# 
0c60: 62 65 20 63 61 6c 6c 65 64 20 64 75 72 69 6e 67  be called during
0c70: 20 74 68 65 20 63 79 63 6c 65 20 62 72 65 61 6b   the cycle break
0c80: 65 72 20 70 61 73 73 65 73 20 61 73 20 77 65 6c  er passes as wel
0c90: 6c 2c 20 74 6f 20 61 64 6a 75 73 74 0a 09 23 20  l, to adjust..# 
0ca0: 74 68 65 20 73 75 63 63 65 73 73 6f 72 20 69 6e  the successor in
0cb0: 66 6f 72 6d 61 74 69 6f 6e 20 6f 66 20 63 68 61  formation of cha
0cc0: 6e 67 65 73 65 74 73 20 77 68 69 63 68 20 61 72  ngesets which ar
0cd0: 65 20 74 68 65 0a 09 23 20 70 72 65 64 65 63 65  e the..# predece
0ce0: 73 73 6f 72 73 20 6f 66 20 64 72 6f 70 70 65 64  ssors of dropped
0cf0: 20 63 68 61 6e 67 65 73 65 74 73 2e 20 46 6f 72   changesets. For
0d00: 20 74 68 65 6d 20 77 65 20 68 61 76 65 20 74 6f   them we have to
0d10: 0a 09 23 20 72 65 6d 6f 76 65 20 74 68 65 69 72  ..# remove their
0d20: 20 65 78 69 73 74 69 6e 67 20 69 6e 66 6f 72 6d   existing inform
0d30: 61 74 69 6f 6e 20 66 69 72 73 74 20 62 65 66 6f  ation first befo
0d40: 72 65 20 69 6e 73 65 72 74 69 6e 67 20 74 68 65  re inserting the
0d50: 0a 09 23 20 6e 65 77 20 64 61 74 61 2e 0a 09 73  ..# new data...s
0d60: 74 61 74 65 20 72 75 6e 20 7b 0a 09 20 20 20 20  tate run {..    
0d70: 44 45 4c 45 54 45 20 46 52 4f 4d 20 63 73 73 75  DELETE FROM cssu
0d80: 63 63 65 73 73 6f 72 20 57 48 45 52 45 20 63 69  ccessor WHERE ci
0d90: 64 20 3d 20 24 6d 79 69 64 3b 0a 09 7d 0a 09 73  d = $myid;..}..s
0da0: 65 74 20 6c 6f 6f 70 20 30 0a 09 66 6f 72 65 61  et loop 0..forea
0db0: 63 68 20 6e 69 64 20 5b 24 6d 79 74 79 70 65 6f  ch nid [$mytypeo
0dc0: 62 6a 20 63 73 5f 73 75 63 63 65 73 73 6f 72 73  bj cs_successors
0dd0: 20 24 6d 79 69 74 65 6d 73 5d 20 7b 0a 09 20 20   $myitems] {..  
0de0: 20 20 73 74 61 74 65 20 72 75 6e 20 7b 0a 09 09    state run {...
0df0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 63 73 73 75  INSERT INTO cssu
0e00: 63 63 65 73 73 6f 72 20 28 63 69 64 2c 20 20 6e  ccessor (cid,  n
0e10: 69 64 29 0a 09 09 56 41 4c 55 45 53 20 20 20 20  id)...VALUES    
0e20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 28 24                ($
0e30: 6d 79 69 64 2c 24 6e 69 64 29 0a 09 20 20 20 20  myid,$nid)..    
0e40: 7d 0a 09 20 20 20 20 69 66 20 7b 24 6e 69 64 20  }..    if {$nid 
0e50: 3d 3d 20 24 6d 79 69 64 7d 20 7b 20 73 65 74 20  == $myid} { set 
0e60: 6c 6f 6f 70 20 31 20 7d 0a 09 7d 0a 09 23 20 52  loop 1 }..}..# R
0e70: 65 70 6f 72 74 20 61 66 74 65 72 20 74 68 65 20  eport after the 
0e80: 63 6f 6d 70 6c 65 74 65 20 73 74 72 75 63 74 75  complete structu
0e90: 72 65 20 68 61 73 20 62 65 65 6e 20 73 61 76 65  re has been save
0ea0: 64 2e 0a 09 69 66 20 7b 24 6c 6f 6f 70 7d 20 7b  d...if {$loop} {
0eb0: 20 24 73 65 6c 66 20 72 65 70 6f 72 74 6c 6f 6f   $self reportloo
0ec0: 70 20 7d 0a 09 72 65 74 75 72 6e 0a 20 20 20 20  p }..return.    
0ed0: 7d 0a 0a 20 20 20 20 23 20 72 65 73 75 6c 74 20  }..    # result 
0ee0: 3d 20 6c 69 73 74 20 28 63 68 61 6e 67 65 73 65  = list (changese
0ef0: 74 29 0a 20 20 20 20 6d 65 74 68 6f 64 20 73 75  t).    method su
0f00: 63 63 65 73 73 6f 72 73 20 7b 7d 20 7b 0a 09 23  ccessors {} {..#
0f10: 20 55 73 65 20 74 68 65 20 64 61 74 61 20 73 61   Use the data sa
0f20: 76 65 64 20 62 79 20 70 61 73 73 20 36 2e 0a 09  ved by pass 6...
0f30: 72 65 74 75 72 6e 20 5b 73 74 72 75 63 74 3a 3a  return [struct::
0f40: 6c 69 73 74 20 6d 61 70 20 5b 73 74 61 74 65 20  list map [state 
0f50: 72 75 6e 20 7b 0a 09 20 20 20 20 53 45 4c 45 43  run {..    SELEC
0f60: 54 20 53 2e 6e 69 64 0a 09 20 20 20 20 46 52 4f  T S.nid..    FRO
0f70: 4d 20 20 20 63 73 73 75 63 63 65 73 73 6f 72 20  M   cssuccessor 
0f80: 53 0a 09 20 20 20 20 57 48 45 52 45 20 20 53 2e  S..    WHERE  S.
0f90: 63 69 64 20 3d 20 24 6d 79 69 64 0a 09 7d 5d 20  cid = $myid..}] 
0fa0: 5b 6d 79 74 79 70 65 6d 65 74 68 6f 64 20 6f 66  [mytypemethod of
0fb0: 5d 5d 0a 20 20 20 20 7d 0a 0a 20 20 20 20 23 20  ]].    }..    # 
0fc0: 69 74 65 6d 20 2d 3e 20 6c 69 73 74 20 28 69 74  item -> list (it
0fd0: 65 6d 29 0a 20 20 20 20 6d 65 74 68 6f 64 20 6e  em).    method n
0fe0: 65 78 74 6d 61 70 20 7b 7d 20 7b 0a 09 24 6d 79  extmap {} {..$my
0ff0: 74 79 70 65 6f 62 6a 20 73 75 63 63 65 73 73 6f  typeobj successo
1000: 72 73 20 74 6d 70 20 24 6d 79 69 74 65 6d 73 0a  rs tmp $myitems.
1010: 09 72 65 74 75 72 6e 20 5b 61 72 72 61 79 20 67  .return [array g
1020: 65 74 20 74 6d 70 5d 0a 20 20 20 20 7d 0a 0a 20  et tmp].    }.. 
1030: 20 20 20 6d 65 74 68 6f 64 20 62 72 65 61 6b 69     method breaki
1040: 6e 74 65 72 6e 61 6c 64 65 70 65 6e 64 65 6e 63  nternaldependenc
1050: 69 65 73 20 7b 7d 20 7b 0a 0a 09 23 23 0a 09 23  ies {} {...##..#
1060: 23 20 4e 4f 54 45 3a 20 54 68 69 73 20 6d 65 74  # NOTE: This met
1070: 68 6f 64 2c 20 6d 61 79 62 65 20 69 6e 20 63 6f  hod, maybe in co
1080: 6e 6a 75 6e 63 74 69 6f 6e 20 77 69 74 68 20 69  njunction with i
1090: 74 73 20 63 61 6c 6c 65 72 0a 09 23 23 20 20 20  ts caller..##   
10a0: 20 20 20 20 73 65 65 6d 73 20 74 6f 20 62 65 20      seems to be 
10b0: 61 20 6d 65 6d 6f 72 79 20 68 6f 67 2c 20 65 73  a memory hog, es
10c0: 70 65 63 69 61 6c 6c 79 20 66 6f 72 20 6c 61 72  pecially for lar
10d0: 67 65 0a 09 23 23 20 20 20 20 20 20 20 63 68 61  ge..##       cha
10e0: 6e 67 65 73 65 74 73 2c 20 77 69 74 68 20 27 6c  ngesets, with 'l
10f0: 61 72 67 65 27 20 6d 65 61 6e 69 6e 67 20 74 6f  arge' meaning to
1100: 20 68 61 76 65 20 61 20 27 6c 6f 6e 67 20 6c 69   have a 'long li
1110: 73 74 0a 09 23 23 20 20 20 20 20 20 20 6f 66 20  st..##       of 
1120: 69 74 65 6d 73 2c 20 73 65 76 65 72 61 6c 20 74  items, several t
1130: 68 6f 75 73 61 6e 64 27 2e 20 49 6e 76 65 73 74  housand'. Invest
1140: 69 67 61 74 65 20 77 68 65 72 65 20 74 68 65 0a  igate where the.
1150: 09 23 23 20 20 20 20 20 20 20 6d 65 6d 6f 72 79  .##       memory
1160: 20 69 73 20 73 70 65 6e 74 20 61 6e 64 20 74 68   is spent and th
1170: 65 6e 20 6c 6f 6f 6b 20 66 6f 72 20 77 61 79 73  en look for ways
1180: 20 6f 66 20 72 65 63 74 69 66 79 69 6e 67 0a 09   of rectifying..
1190: 23 23 20 20 20 20 20 20 20 74 68 65 20 70 72 6f  ##       the pro
11a0: 62 6c 65 6d 2e 0a 09 23 23 0a 0a 09 23 20 54 68  blem...##...# Th
11b0: 69 73 20 6d 65 74 68 6f 64 20 69 6e 73 70 65 63  is method inspec
11c0: 74 73 20 74 68 65 20 63 68 61 6e 67 65 73 65 74  ts the changeset
11d0: 73 20 66 6f 72 20 69 6e 74 65 72 6e 61 6c 0a 09  s for internal..
11e0: 23 20 64 65 70 65 6e 64 65 6e 63 69 65 73 2e 20  # dependencies. 
11f0: 4e 6f 74 68 69 6e 67 20 69 73 20 64 6f 6e 65 20  Nothing is done 
1200: 69 66 20 74 68 65 72 65 20 61 72 65 20 6e 6f 0a  if there are no.
1210: 09 23 20 73 75 63 68 2e 20 4f 74 68 65 72 77 69  .# such. Otherwi
1220: 73 65 20 74 68 65 20 63 68 61 6e 67 65 73 65 74  se the changeset
1230: 20 69 73 20 73 70 6c 69 74 20 69 6e 74 6f 20 61   is split into a
1240: 20 73 65 74 20 6f 66 0a 09 23 20 66 72 61 67 6d   set of..# fragm
1250: 65 6e 74 73 20 77 69 74 68 6f 75 74 20 69 6e 74  ents without int
1260: 65 72 6e 61 6c 20 64 65 70 65 6e 64 65 6e 63 69  ernal dependenci
1270: 65 73 2c 20 74 72 61 6e 73 66 6f 72 6d 69 6e 67  es, transforming
1280: 20 74 68 65 0a 09 23 20 69 6e 74 65 72 6e 61 6c   the..# internal
1290: 20 64 65 70 65 6e 64 65 6e 63 69 65 73 20 69 6e   dependencies in
12a0: 74 6f 20 65 78 74 65 72 6e 61 6c 20 6f 6e 65 73  to external ones
12b0: 2e 20 54 68 65 20 6e 65 77 20 63 68 61 6e 67 65  . The new change
12c0: 73 65 74 73 0a 09 23 20 61 72 65 20 61 64 64 65  sets..# are adde
12d0: 64 20 74 6f 20 74 68 65 20 6c 69 73 74 20 6f 66  d to the list of
12e0: 20 61 6c 6c 20 63 68 61 6e 67 65 73 65 74 73 2e   all changesets.
12f0: 0a 0a 09 23 20 57 65 20 70 65 72 66 6f 72 6d 20  ...# We perform 
1300: 61 6c 6c 20 6e 65 63 65 73 73 61 72 79 20 73 70  all necessary sp
1310: 6c 69 74 73 20 69 6e 20 6f 6e 65 20 67 6f 2c 20  lits in one go, 
1320: 69 6e 73 74 65 61 64 20 6f 66 20 6f 6e 6c 79 0a  instead of only.
1330: 09 23 20 6f 6e 65 2e 20 54 68 65 20 70 72 65 76  .# one. The prev
1340: 69 6f 75 73 20 61 6c 67 6f 72 69 74 68 6d 2c 20  ious algorithm, 
1350: 61 64 61 70 74 65 64 20 66 72 6f 6d 20 63 76 73  adapted from cvs
1360: 32 73 76 6e 2c 20 63 6f 6d 70 75 74 65 64 0a 09  2svn, computed..
1370: 23 20 61 20 6c 6f 74 20 6f 66 20 73 74 61 74 65  # a lot of state
1380: 20 77 68 69 63 68 20 77 61 73 20 74 68 72 6f 77   which was throw
1390: 6e 20 61 77 61 79 20 61 6e 64 20 74 68 65 6e 20  n away and then 
13a0: 63 6f 6d 70 75 74 65 64 20 61 67 61 69 6e 0a 09  computed again..
13b0: 23 20 66 6f 72 20 65 61 63 68 20 6f 66 20 74 68  # for each of th
13c0: 65 20 66 72 61 67 6d 65 6e 74 73 2e 20 49 74 20  e fragments. It 
13d0: 73 68 6f 75 6c 64 20 62 65 20 65 61 73 69 65 72  should be easier
13e0: 20 74 6f 20 75 70 64 61 74 65 20 61 6e 64 0a 09   to update and..
13f0: 23 20 72 65 75 73 65 20 74 68 61 74 20 73 74 61  # reuse that sta
1400: 74 65 2e 0a 0a 09 23 20 54 68 65 20 63 6f 64 65  te....# The code
1410: 20 63 68 65 63 6b 73 20 6f 6e 6c 79 20 73 75 63   checks only suc
1420: 63 65 73 73 6f 72 20 64 65 70 65 6e 64 65 6e 63  cessor dependenc
1430: 69 65 73 2c 20 61 73 20 74 68 69 73 0a 09 23 20  ies, as this..# 
1440: 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 20 63 6f  automatically co
1450: 76 65 72 73 20 74 68 65 20 70 72 65 64 65 63 65  vers the predece
1460: 73 73 6f 72 20 64 65 70 65 6e 64 65 6e 63 69 65  ssor dependencie
1470: 73 20 61 73 20 77 65 6c 6c 20 28 41 0a 09 23 20  s as well (A..# 
1480: 73 75 63 63 65 73 73 6f 72 20 64 65 70 65 6e 64  successor depend
1490: 65 6e 63 79 20 61 20 2d 3e 20 62 20 69 73 20 61  ency a -> b is a
14a0: 6c 73 6f 20 61 20 70 72 65 64 65 63 65 73 73 6f  lso a predecesso
14b0: 72 20 64 65 70 65 6e 64 65 6e 63 79 0a 09 23 20  r dependency..# 
14c0: 62 20 2d 3e 20 61 29 2e 0a 0a 09 23 20 41 72 72  b -> a)....# Arr
14d0: 61 79 20 6f 66 20 64 65 70 65 6e 64 65 6e 63 69  ay of dependenci
14e0: 65 73 20 28 70 61 72 65 6e 74 20 2d 3e 20 63 68  es (parent -> ch
14f0: 69 6c 64 29 2e 20 54 68 69 73 20 69 73 20 70 75  ild). This is pu
1500: 6c 6c 65 64 20 66 72 6f 6d 0a 09 23 20 74 68 65  lled from..# the
1510: 20 73 74 61 74 65 2c 20 61 6e 64 20 6c 69 6d 69   state, and limi
1520: 74 65 64 20 74 6f 20 73 75 63 63 65 73 73 6f 72  ted to successor
1530: 73 20 77 69 74 68 69 6e 20 74 68 65 20 63 68 61  s within the cha
1540: 6e 67 65 73 65 74 2e 0a 0a 09 61 72 72 61 79 20  ngeset....array 
1550: 73 65 74 20 64 65 70 65 6e 64 65 6e 63 69 65 73  set dependencies
1560: 20 7b 7d 0a 09 24 6d 79 74 79 70 65 6f 62 6a 20   {}..$mytypeobj 
1570: 69 6e 74 65 72 6e 61 6c 73 75 63 63 65 73 73 6f  internalsuccesso
1580: 72 73 20 64 65 70 65 6e 64 65 6e 63 69 65 73 20  rs dependencies 
1590: 24 6d 79 69 74 65 6d 73 0a 09 69 66 20 7b 21 5b  $myitems..if {![
15a0: 61 72 72 61 79 20 73 69 7a 65 20 64 65 70 65 6e  array size depen
15b0: 64 65 6e 63 69 65 73 5d 7d 20 7b 72 65 74 75 72  dencies]} {retur
15c0: 6e 20 30 7d 20 3b 20 23 20 4e 6f 74 68 69 6e 67  n 0} ; # Nothing
15d0: 20 74 6f 20 62 72 65 61 6b 2e 0a 0a 09 6c 6f 67   to break....log
15e0: 20 77 72 69 74 65 20 35 20 63 73 65 74 73 20 2e   write 5 csets .
15f0: 2e 2e 5b 24 73 65 6c 66 20 73 74 72 5d 2e 2e 2e  ..[$self str]...
1600: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e  ................
1610: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e  ................
1620: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e  ................
1630: 2e 2e 2e 2e 0a 0a 09 23 20 57 65 20 68 61 76 65  .......# We have
1640: 20 69 6e 74 65 72 6e 61 6c 20 64 65 70 65 6e 64   internal depend
1650: 65 6e 63 69 65 73 20 74 6f 20 62 72 65 61 6b 2e  encies to break.
1660: 20 57 65 20 6e 6f 77 20 69 74 65 72 61 74 65 20   We now iterate 
1670: 6f 76 65 72 0a 09 23 20 61 6c 6c 20 70 6f 73 69  over..# all posi
1680: 74 69 6f 6e 73 20 69 6e 20 74 68 65 20 6c 69 73  tions in the lis
1690: 74 20 28 77 68 69 63 68 20 69 73 20 63 68 72 6f  t (which is chro
16a0: 6e 6f 6c 6f 67 69 63 61 6c 2c 20 61 74 20 6c 65  nological, at le
16b0: 61 73 74 0a 09 23 20 61 73 20 66 61 72 20 61 73  ast..# as far as
16c0: 20 74 68 65 20 74 69 6d 65 73 74 61 6d 70 73 20   the timestamps 
16d0: 61 72 65 20 63 6f 72 72 65 63 74 20 61 6e 64 20  are correct and 
16e0: 75 6e 69 71 75 65 29 20 61 6e 64 0a 09 23 20 64  unique) and..# d
16f0: 65 74 65 72 6d 69 6e 65 20 74 68 65 20 62 65 73  etermine the bes
1700: 74 20 70 6f 73 69 74 69 6f 6e 20 66 6f 72 20 74  t position for t
1710: 68 65 20 62 72 65 61 6b 2c 20 62 79 20 74 72 79  he break, by try
1720: 69 6e 67 20 74 6f 0a 09 23 20 62 72 65 61 6b 20  ing to..# break 
1730: 61 73 20 6d 61 6e 79 20 64 65 70 65 6e 64 65 6e  as many dependen
1740: 63 69 65 73 20 61 73 20 70 6f 73 73 69 62 6c 65  cies as possible
1750: 20 69 6e 20 6f 6e 65 20 67 6f 2e 20 57 68 65 6e   in one go. When
1760: 20 61 0a 09 23 20 62 72 65 61 6b 20 77 61 73 20   a..# break was 
1770: 66 6f 75 6e 64 20 74 68 69 73 20 69 73 20 72 65  found this is re
1780: 64 6f 6e 65 20 66 6f 72 20 74 68 65 20 66 72 61  done for the fra
1790: 67 6d 65 6e 74 73 20 63 6f 6d 69 6e 67 20 61 6e  gments coming an
17a0: 64 0a 09 23 20 61 66 74 65 72 2c 20 61 66 74 65  d..# after, afte
17b0: 72 20 75 70 64 69 6e 67 20 74 68 65 20 63 72 6f  r upding the cro
17c0: 73 73 69 6e 67 20 69 6e 66 6f 72 6d 61 74 69 6f  ssing informatio
17d0: 6e 2e 0a 0a 09 23 20 44 61 74 61 20 73 74 72 75  n....# Data stru
17e0: 63 74 75 72 65 73 3a 0a 09 23 20 4d 61 70 3a 20  ctures:..# Map: 
17f0: 20 50 4f 53 20 20 20 72 65 76 69 73 69 6f 6e 20   POS   revision 
1800: 69 64 20 20 20 20 20 20 2d 3e 20 70 6f 73 69 74  id      -> posit
1810: 69 6f 6e 20 69 6e 20 6c 69 73 74 2e 0a 09 23 20  ion in list...# 
1820: 20 20 20 20 20 20 43 52 4f 53 53 20 70 6f 73 69        CROSS posi
1830: 74 69 6f 6e 20 69 6e 20 6c 69 73 74 20 2d 3e 20  tion in list -> 
1840: 6e 75 6d 62 65 72 20 6f 66 20 64 65 70 65 6e 64  number of depend
1850: 65 6e 63 69 65 73 20 63 72 6f 73 73 69 6e 67 20  encies crossing 
1860: 69 74 0a 09 23 20 20 20 20 20 20 20 44 45 50 43  it..#       DEPC
1870: 20 20 64 65 70 65 6e 64 65 6e 63 79 20 20 20 20    dependency    
1880: 20 20 20 2d 3e 20 70 6f 73 69 74 69 6f 6e 73 20     -> positions 
1890: 69 74 20 63 72 6f 73 73 65 73 0a 09 23 20 4c 69  it crosses..# Li
18a0: 73 74 3a 20 52 41 4e 47 45 20 4f 66 20 74 68 65  st: RANGE Of the
18b0: 20 70 6f 73 69 74 69 6f 6e 73 20 69 74 73 65 6c   positions itsel
18c0: 66 2e 0a 09 23 20 41 20 64 65 70 65 6e 64 65 6e  f...# A dependen
18d0: 63 79 20 69 73 20 61 20 73 69 6e 67 6c 65 2d 65  cy is a single-e
18e0: 6c 65 6d 65 6e 74 20 6d 61 70 20 70 61 72 65 6e  lement map paren
18f0: 74 20 2d 3e 20 63 68 69 6c 64 0a 0a 09 49 6e 69  t -> child...Ini
1900: 74 69 61 6c 69 7a 65 42 72 65 61 6b 53 74 61 74  tializeBreakStat
1910: 65 20 24 6d 79 69 74 65 6d 73 0a 0a 09 73 65 74  e $myitems...set
1920: 20 66 72 61 67 6d 65 6e 74 73 20 7b 7d 0a 09 73   fragments {}..s
1930: 65 74 20 6e 65 77 20 20 20 20 20 20 20 5b 6c 69  et new       [li
1940: 73 74 20 24 72 61 6e 67 65 5d 0a 09 61 72 72 61  st $range]..arra
1950: 79 20 73 65 74 20 62 72 65 61 6b 73 20 7b 7d 0a  y set breaks {}.
1960: 0a 09 23 20 49 6e 73 74 65 61 64 20 6f 66 20 6f  ..# Instead of o
1970: 6e 65 20 6c 69 73 74 20 68 6f 6c 64 69 6e 67 20  ne list holding 
1980: 62 6f 74 68 20 70 72 6f 63 65 73 73 65 64 20 61  both processed a
1990: 6e 64 20 70 65 6e 64 69 6e 67 0a 09 23 20 66 72  nd pending..# fr
19a0: 61 67 6d 65 6e 74 73 20 77 65 20 75 73 65 20 74  agments we use t
19b0: 77 6f 2c 20 6f 6e 65 20 66 6f 72 20 74 68 65 20  wo, one for the 
19c0: 66 72 61 6d 65 6e 74 73 20 74 6f 20 70 72 6f 63  framents to proc
19d0: 65 73 73 2c 20 6f 6e 65 0a 09 23 20 74 6f 20 68  ess, one..# to h
19e0: 6f 6c 64 20 74 68 65 20 6e 65 77 20 66 72 61 67  old the new frag
19f0: 6d 65 6e 74 73 2c 20 61 6e 64 20 74 68 65 20 6c  ments, and the l
1a00: 61 74 74 65 72 20 69 73 20 63 6f 70 69 65 64 20  atter is copied 
1a10: 74 6f 20 74 68 65 0a 09 23 20 66 6f 72 6d 65 72  to the..# former
1a20: 20 77 68 65 6e 20 74 68 65 79 20 72 75 6e 20 6f   when they run o
1a30: 75 74 2e 20 54 68 69 73 20 6b 65 65 70 73 20 74  ut. This keeps t
1a40: 68 65 20 6c 69 73 74 20 6f 66 20 70 65 6e 64 69  he list of pendi
1a50: 6e 67 0a 09 23 20 66 72 61 67 6d 65 6e 74 73 20  ng..# fragments 
1a60: 73 68 6f 72 74 20 77 69 74 68 6f 75 74 20 73 61  short without sa
1a70: 63 72 69 66 69 63 69 6e 67 20 73 70 65 65 64 20  crificing speed 
1a80: 62 79 20 73 68 69 66 74 69 6e 67 20 73 74 75 66  by shifting stuf
1a90: 66 0a 09 23 20 64 6f 77 6e 2e 20 57 65 20 65 73  f..# down. We es
1aa0: 70 65 63 69 61 6c 6c 79 20 64 72 6f 70 20 74 68  pecially drop th
1ab0: 65 20 6d 65 6d 6f 72 79 20 6f 66 20 66 72 61 67  e memory of frag
1ac0: 6d 65 6e 74 73 20 62 72 6f 6b 65 6e 0a 09 23 20  ments broken..# 
1ad0: 64 75 72 69 6e 67 20 70 72 6f 63 65 73 73 69 6e  during processin
1ae0: 67 20 61 66 74 65 72 20 61 20 73 68 6f 72 74 20  g after a short 
1af0: 74 69 6d 65 2c 20 69 6e 73 74 65 61 64 20 6f 66  time, instead of
1b00: 20 6c 65 74 74 69 6e 67 20 69 74 0a 09 23 20 63   letting it..# c
1b10: 6f 6e 73 75 6d 65 20 6d 65 6d 6f 72 79 2e 0a 0a  onsume memory...
1b20: 09 77 68 69 6c 65 20 7b 5b 6c 6c 65 6e 67 74 68  .while {[llength
1b30: 20 24 6e 65 77 5d 7d 20 7b 0a 0a 09 20 20 20 20   $new]} {...    
1b40: 73 65 74 20 70 65 6e 64 69 6e 67 20 24 6e 65 77  set pending $new
1b50: 0a 09 20 20 20 20 73 65 74 20 6e 65 77 20 20 20  ..    set new   
1b60: 20 20 7b 7d 0a 09 20 20 20 20 73 65 74 20 61 74    {}..    set at
1b70: 20 20 20 20 20 20 30 0a 0a 09 20 20 20 20 77 68        0...    wh
1b80: 69 6c 65 20 7b 24 61 74 20 3c 20 5b 6c 6c 65 6e  ile {$at < [llen
1b90: 67 74 68 20 24 70 65 6e 64 69 6e 67 5d 7d 20 7b  gth $pending]} {
1ba0: 0a 09 09 73 65 74 20 63 75 72 72 65 6e 74 20 5b  ...set current [
1bb0: 6c 69 6e 64 65 78 20 24 70 65 6e 64 69 6e 67 20  lindex $pending 
1bc0: 24 61 74 5d 0a 0a 09 09 6c 6f 67 20 77 72 69 74  $at]....log writ
1bd0: 65 20 36 20 63 73 65 74 73 20 7b 2e 20 2e 20 2e  e 6 csets {. . .
1be0: 2e 20 2e 2e 2e 20 2e 2e 2e 2e 2e 20 2e 2e 2e 2e  . ... ..... ....
1bf0: 2e 2e 2e 2e 20 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e  .... ...........
1c00: 2e 2e 7d 0a 09 09 6c 6f 67 20 77 72 69 74 65 20  ..}...log write 
1c10: 36 20 63 73 65 74 73 20 7b 53 63 68 65 64 75 6c  6 csets {Schedul
1c20: 65 64 20 20 20 5b 6a 6f 69 6e 20 5b 50 52 73 20  ed   [join [PRs 
1c30: 5b 6c 72 61 6e 67 65 20 24 70 65 6e 64 69 6e 67  [lrange $pending
1c40: 20 24 61 74 20 65 6e 64 5d 5d 20 7b 20 7d 5d 7d   $at end]] { }]}
1c50: 0a 09 09 6c 6f 67 20 77 72 69 74 65 20 36 20 63  ...log write 6 c
1c60: 73 65 74 73 20 7b 43 6f 6e 73 69 64 65 72 69 6e  sets {Considerin
1c70: 67 20 5b 50 52 20 24 63 75 72 72 65 6e 74 5d 20  g [PR $current] 
1c80: 5c 5b 24 61 74 2f 5b 6c 6c 65 6e 67 74 68 20 24  \[$at/[llength $
1c90: 70 65 6e 64 69 6e 67 5d 5c 5d 7d 0a 0a 09 09 73  pending]\]}....s
1ca0: 65 74 20 62 65 73 74 20 5b 46 69 6e 64 42 65 73  et best [FindBes
1cb0: 74 42 72 65 61 6b 20 24 63 75 72 72 65 6e 74 5d  tBreak $current]
1cc0: 0a 0a 09 09 69 66 20 7b 24 62 65 73 74 20 3c 20  ....if {$best < 
1cd0: 30 7d 20 7b 0a 09 09 20 20 20 20 23 20 54 68 65  0} {...    # The
1ce0: 20 69 6e 73 70 65 63 74 65 64 20 72 61 6e 67 65   inspected range
1cf0: 20 68 61 73 20 6e 6f 20 69 6e 74 65 72 6e 61 6c   has no internal
1d00: 0a 09 09 20 20 20 20 23 20 64 65 70 65 6e 64 65  ...    # depende
1d10: 6e 63 69 65 73 2e 20 54 68 69 73 20 69 73 20 61  ncies. This is a
1d20: 20 63 6f 6d 70 6c 65 74 65 20 66 72 61 67 6d 65   complete fragme
1d30: 6e 74 2e 0a 09 09 20 20 20 20 6c 61 70 70 65 6e  nt....    lappen
1d40: 64 20 66 72 61 67 6d 65 6e 74 73 20 24 63 75 72  d fragments $cur
1d50: 72 65 6e 74 0a 0a 09 09 20 20 20 20 6c 6f 67 20  rent....    log 
1d60: 77 72 69 74 65 20 36 20 63 73 65 74 73 20 22 4e  write 6 csets "N
1d70: 6f 20 62 72 65 61 6b 73 2c 20 66 69 6e 61 6c 22  o breaks, final"
1d80: 0a 09 09 7d 20 65 6c 73 65 20 7b 0a 09 09 20 20  ...} else {...  
1d90: 20 20 23 20 53 70 6c 69 74 20 74 68 65 20 72 61    # Split the ra
1da0: 6e 67 65 20 61 6e 64 20 73 63 68 65 64 75 6c 65  nge and schedule
1db0: 20 74 68 65 20 72 65 73 75 6c 74 69 6e 67 0a 09   the resulting..
1dc0: 09 20 20 20 20 23 20 66 72 61 67 6d 65 6e 74 73  .    # fragments
1dd0: 20 66 6f 72 20 66 75 72 74 68 65 72 20 69 6e 73   for further ins
1de0: 70 65 63 74 69 6f 6e 2e 20 52 65 6d 65 6d 62 65  pection. Remembe
1df0: 72 20 74 68 65 0a 09 09 20 20 20 20 23 20 6e 75  r the...    # nu
1e00: 6d 62 65 72 20 6f 66 20 64 65 70 65 6e 64 65 6e  mber of dependen
1e10: 63 69 65 73 20 63 75 74 20 62 65 66 6f 72 65 20  cies cut before 
1e20: 77 65 20 72 65 6d 6f 76 65 20 74 68 65 6d 0a 09  we remove them..
1e30: 09 20 20 20 20 23 20 66 72 6f 6d 20 63 6f 6e 73  .    # from cons
1e40: 69 64 65 72 61 74 69 6f 6e 2c 20 66 6f 72 20 64  ideration, for d
1e50: 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 6c 61 74  ocumentation lat
1e60: 65 72 2e 0a 0a 09 09 20 20 20 20 73 65 74 20 62  er.....    set b
1e70: 72 65 61 6b 73 28 24 62 65 73 74 29 20 24 63 72  reaks($best) $cr
1e80: 6f 73 73 28 24 62 65 73 74 29 0a 0a 09 09 20 20  oss($best)....  
1e90: 20 20 6c 6f 67 20 77 72 69 74 65 20 36 20 63 73    log write 6 cs
1ea0: 65 74 73 20 22 42 65 73 74 20 62 72 65 61 6b 20  ets "Best break 
1eb0: 40 20 24 62 65 73 74 2c 20 63 75 74 74 69 6e 67  @ $best, cutting
1ec0: 20 5b 6e 73 70 20 24 63 72 6f 73 73 28 24 62 65   [nsp $cross($be
1ed0: 73 74 29 20 64 65 70 65 6e 64 65 6e 63 79 20 64  st) dependency d
1ee0: 65 70 65 6e 64 65 6e 63 69 65 73 5d 22 0a 0a 09  ependencies]"...
1ef0: 09 20 20 20 20 23 20 4e 6f 74 65 3a 20 54 68 65  .    # Note: The
1f00: 20 76 61 6c 75 65 20 6f 66 20 62 65 73 74 20 69   value of best i
1f10: 73 20 61 6e 20 61 62 6f 6c 75 74 65 20 6c 6f 63  s an abolute loc
1f20: 61 74 69 6f 6e 0a 09 09 20 20 20 20 23 20 69 6e  ation...    # in
1f30: 20 6d 79 69 74 65 6d 73 2e 20 55 73 65 20 74 68   myitems. Use th
1f40: 65 20 73 74 61 72 74 20 6f 66 20 63 75 72 72 65  e start of curre
1f50: 6e 74 20 74 6f 20 6d 61 6b 65 20 69 74 0a 09 09  nt to make it...
1f60: 20 20 20 20 23 20 61 6e 20 69 6e 64 65 78 20 61      # an index a
1f70: 62 73 6f 6c 75 74 65 20 74 6f 20 63 75 72 72 65  bsolute to curre
1f80: 6e 74 2e 0a 0a 09 09 20 20 20 20 73 65 74 20 62  nt.....    set b
1f90: 72 65 6c 20 5b 65 78 70 72 20 7b 24 62 65 73 74  rel [expr {$best
1fa0: 20 2d 20 5b 6c 69 6e 64 65 78 20 24 63 75 72 72   - [lindex $curr
1fb0: 65 6e 74 20 30 5d 7d 5d 0a 09 09 20 20 20 20 73  ent 0]}]...    s
1fc0: 65 74 20 62 6e 65 78 74 20 24 62 72 65 6c 20 3b  et bnext $brel ;
1fd0: 20 69 6e 63 72 20 62 6e 65 78 74 0a 09 09 20 20   incr bnext...  
1fe0: 20 20 73 65 74 20 66 72 61 67 62 65 66 6f 72 65    set fragbefore
1ff0: 20 5b 6c 72 61 6e 67 65 20 24 63 75 72 72 65 6e   [lrange $curren
2000: 74 20 30 20 24 62 72 65 6c 5d 0a 09 09 20 20 20  t 0 $brel]...   
2010: 20 73 65 74 20 66 72 61 67 61 66 74 65 72 20 20   set fragafter  
2020: 5b 6c 72 61 6e 67 65 20 24 63 75 72 72 65 6e 74  [lrange $current
2030: 20 24 62 6e 65 78 74 20 65 6e 64 5d 0a 0a 09 09   $bnext end]....
2040: 20 20 20 20 6c 6f 67 20 77 72 69 74 65 20 36 20      log write 6 
2050: 63 73 65 74 73 20 22 4e 65 77 20 70 69 65 63 65  csets "New piece
2060: 73 20 20 5b 50 52 20 24 66 72 61 67 62 65 66 6f  s  [PR $fragbefo
2070: 72 65 5d 20 5b 50 52 20 24 66 72 61 67 61 66 74  re] [PR $fragaft
2080: 65 72 5d 22 0a 0a 09 09 20 20 20 20 69 6e 74 65  er]"....    inte
2090: 67 72 69 74 79 20 61 73 73 65 72 74 20 7b 5b 6c  grity assert {[l
20a0: 6c 65 6e 67 74 68 20 24 66 72 61 67 62 65 66 6f  length $fragbefo
20b0: 72 65 5d 7d 20 7b 46 6f 75 6e 64 20 7a 65 72 6f  re]} {Found zero
20c0: 2d 6c 65 6e 67 74 68 20 66 72 61 67 6d 65 6e 74  -length fragment
20d0: 20 61 74 20 74 68 65 20 62 65 67 69 6e 6e 69 6e   at the beginnin
20e0: 67 7d 0a 09 09 20 20 20 20 69 6e 74 65 67 72 69  g}...    integri
20f0: 74 79 20 61 73 73 65 72 74 20 7b 5b 6c 6c 65 6e  ty assert {[llen
2100: 67 74 68 20 24 66 72 61 67 61 66 74 65 72 5d 7d  gth $fragafter]}
2110: 20 20 7b 46 6f 75 6e 64 20 7a 65 72 6f 2d 6c 65    {Found zero-le
2120: 6e 67 74 68 20 66 72 61 67 6d 65 6e 74 20 61 74  ngth fragment at
2130: 20 74 68 65 20 65 6e 64 7d 0a 0a 09 09 20 20 20   the end}....   
2140: 20 6c 61 70 70 65 6e 64 20 6e 65 77 20 24 66 72   lappend new $fr
2150: 61 67 62 65 66 6f 72 65 20 24 66 72 61 67 61 66  agbefore $fragaf
2160: 74 65 72 0a 09 09 20 20 20 20 43 75 74 41 74 20  ter...    CutAt 
2170: 24 62 65 73 74 0a 09 09 7d 0a 0a 09 09 69 6e 63  $best...}....inc
2180: 72 20 61 74 0a 09 20 20 20 20 7d 0a 09 7d 0a 0a  r at..    }..}..
2190: 09 6c 6f 67 20 77 72 69 74 65 20 36 20 63 73 65  .log write 6 cse
21a0: 74 73 20 22 2e 20 2e 20 2e 2e 20 2e 2e 2e 20 2e  ts ". . .. ... .
21b0: 2e 2e 2e 2e 20 2e 2e 2e 2e 2e 2e 2e 2e 20 2e 2e  .... ........ ..
21c0: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 22 0a 0a 09 23  ..........."...#
21d0: 20 28 2a 29 20 57 65 20 63 6c 65 61 72 20 6f 75   (*) We clear ou
21e0: 74 20 74 68 65 20 61 73 73 6f 63 69 61 74 65 64  t the associated
21f0: 20 70 61 72 74 20 6f 66 20 74 68 65 20 6d 79 69   part of the myi
2200: 74 65 6d 6d 61 70 0a 09 23 20 69 6e 2d 6d 65 6d  temmap..# in-mem
2210: 6f 72 79 20 69 6e 64 65 78 20 69 6e 20 70 72 65  ory index in pre
2220: 70 61 72 61 74 69 6f 6e 20 66 6f 72 20 6e 65 77  paration for new
2230: 20 64 61 74 61 2e 20 41 20 73 69 6d 70 6c 65 20   data. A simple 
2240: 75 6e 73 65 74 0a 09 23 20 69 73 20 65 6e 6f 75  unset..# is enou
2250: 67 68 2c 20 77 65 20 68 61 76 65 20 6e 6f 20 73  gh, we have no s
2260: 79 6d 62 6f 6c 20 63 68 61 6e 67 65 73 65 74 73  ymbol changesets
2270: 20 61 74 20 74 68 69 73 20 74 69 6d 65 2c 20 61   at this time, a
2280: 6e 64 0a 09 23 20 74 68 75 73 20 6e 65 76 65 72  nd..# thus never
2290: 20 6d 6f 72 65 20 74 68 61 6e 20 6f 6e 65 20 72   more than one r
22a0: 65 66 65 72 65 6e 63 65 20 69 6e 20 74 68 65 20  eference in the 
22b0: 6c 69 73 74 2e 0a 0a 09 66 6f 72 65 61 63 68 20  list....foreach 
22c0: 69 69 64 20 24 6d 79 69 74 65 6d 73 20 7b 0a 09  iid $myitems {..
22d0: 20 20 20 20 73 65 74 20 6b 65 79 20 5b 6c 69 73      set key [lis
22e0: 74 20 24 6d 79 74 79 70 65 20 24 69 69 64 5d 0a  t $mytype $iid].
22f0: 09 20 20 20 20 75 6e 73 65 74 20 6d 79 69 74 65  .    unset myite
2300: 6d 6d 61 70 28 24 6b 65 79 29 0a 09 20 20 20 20  mmap($key)..    
2310: 6c 6f 67 20 77 72 69 74 65 20 38 20 63 73 65 74  log write 8 cset
2320: 73 20 7b 4d 41 50 2d 20 69 74 65 6d 20 3c 24 6b  s {MAP- item <$k
2330: 65 79 3e 20 24 73 65 6c 66 20 3d 20 5b 24 73 65  ey> $self = [$se
2340: 6c 66 20 73 74 72 5d 7d 0a 09 7d 0a 0a 09 23 20  lf str]}..}...# 
2350: 43 72 65 61 74 65 20 63 68 61 6e 67 65 73 65 74  Create changeset
2360: 73 20 66 6f 72 20 74 68 65 20 66 72 61 67 6d 65  s for the fragme
2370: 6e 74 73 2c 20 72 65 75 73 69 6e 67 20 74 68 65  nts, reusing the
2380: 20 63 75 72 72 65 6e 74 20 6f 6e 65 0a 09 23 20   current one..# 
2390: 66 6f 72 20 74 68 65 20 66 69 72 73 74 20 66 72  for the first fr
23a0: 61 67 6d 65 6e 74 2e 20 57 65 20 73 6f 72 74 20  agment. We sort 
23b0: 74 68 65 6d 20 69 6e 20 6f 72 64 65 72 20 74 6f  them in order to
23c0: 20 61 6c 6c 6f 77 0a 09 23 20 63 68 65 63 6b 69   allow..# checki
23d0: 6e 67 20 66 6f 72 20 67 61 70 73 20 61 6e 64 20  ng for gaps and 
23e0: 6e 69 63 65 20 6d 65 73 73 61 67 65 73 2e 0a 0a  nice messages...
23f0: 09 73 65 74 20 66 72 61 67 6d 65 6e 74 73 20 5b  .set fragments [
2400: 6c 73 6f 72 74 20 2d 69 6e 64 65 78 20 30 20 2d  lsort -index 0 -
2410: 69 6e 74 65 67 65 72 20 24 66 72 61 67 6d 65 6e  integer $fragmen
2420: 74 73 5d 0a 0a 09 23 70 75 74 73 20 5c 74 2e 5b  ts]...#puts \t.[
2430: 6a 6f 69 6e 20 5b 50 52 73 20 24 66 72 61 67 6d  join [PRs $fragm
2440: 65 6e 74 73 5d 20 2e 5c 6e 5c 74 2e 5d 2e 0a 0a  ents] .\n\t.]...
2450: 09 42 6f 72 64 65 72 20 5b 6c 69 6e 64 65 78 20  .Border [lindex 
2460: 24 66 72 61 67 6d 65 6e 74 73 20 30 5d 20 66 69  $fragments 0] fi
2470: 72 73 74 73 20 66 69 72 73 74 65 0a 0a 09 69 6e  rsts firste...in
2480: 74 65 67 72 69 74 79 20 61 73 73 65 72 74 20 7b  tegrity assert {
2490: 24 66 69 72 73 74 73 20 3d 3d 20 30 7d 20 7b 42  $firsts == 0} {B
24a0: 61 64 20 66 72 61 67 6d 65 6e 74 20 73 74 61 72  ad fragment star
24b0: 74 20 40 20 24 66 69 72 73 74 73 2c 20 67 61 70  t @ $firsts, gap
24c0: 2c 20 6f 72 20 62 65 66 6f 72 65 20 62 65 67 69  , or before begi
24d0: 6e 6e 69 6e 67 20 6f 66 20 74 68 65 20 72 61 6e  nning of the ran
24e0: 67 65 7d 0a 0a 09 73 65 74 20 6c 61 73 74 65 20  ge}...set laste 
24f0: 24 66 69 72 73 74 65 0a 09 66 6f 72 65 61 63 68  $firste..foreach
2500: 20 66 72 61 67 6d 65 6e 74 20 5b 6c 72 61 6e 67   fragment [lrang
2510: 65 20 24 66 72 61 67 6d 65 6e 74 73 20 31 20 65  e $fragments 1 e
2520: 6e 64 5d 20 7b 0a 09 20 20 20 20 42 6f 72 64 65  nd] {..    Borde
2530: 72 20 24 66 72 61 67 6d 65 6e 74 20 73 20 65 0a  r $fragment s e.
2540: 09 20 20 20 20 69 6e 74 65 67 72 69 74 79 20 61  .    integrity a
2550: 73 73 65 72 74 20 7b 24 6c 61 73 74 65 20 3d 3d  ssert {$laste ==
2560: 20 28 24 73 20 2d 20 31 29 7d 20 7b 42 61 64 20   ($s - 1)} {Bad 
2570: 66 72 61 67 6d 65 6e 74 20 62 6f 72 64 65 72 20  fragment border 
2580: 3c 24 6c 61 73 74 65 20 7c 20 24 73 3e 2c 20 67  <$laste | $s>, g
2590: 61 70 20 6f 72 20 6f 76 65 72 6c 61 70 7d 0a 0a  ap or overlap}..
25a0: 09 20 20 20 20 73 65 74 20 6e 65 77 20 5b 24 74  .    set new [$t
25b0: 79 70 65 20 25 41 55 54 4f 25 20 24 6d 79 70 72  ype %AUTO% $mypr
25c0: 6f 6a 65 63 74 20 24 6d 79 74 79 70 65 20 24 6d  oject $mytype $m
25d0: 79 73 72 63 69 64 20 5b 6c 72 61 6e 67 65 20 24  ysrcid [lrange $
25e0: 6d 79 69 74 65 6d 73 20 24 73 20 24 65 5d 5d 0a  myitems $s $e]].
25f0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 6c 6f 67  .            log
2600: 20 77 72 69 74 65 20 34 20 63 73 65 74 73 20 22   write 4 csets "
2610: 42 72 65 61 6b 69 6e 67 20 5b 24 73 65 6c 66 20  Breaking [$self 
2620: 73 74 72 20 5d 20 40 20 24 6c 61 73 74 65 2c 20  str ] @ $laste, 
2630: 6e 65 77 20 5b 24 6e 65 77 20 73 74 72 5d 2c 20  new [$new str], 
2640: 63 75 74 74 69 6e 67 20 24 62 72 65 61 6b 73 28  cutting $breaks(
2650: 24 6c 61 73 74 65 29 22 0a 0a 09 20 20 20 20 73  $laste)"...    s
2660: 65 74 20 6c 61 73 74 65 20 24 65 0a 09 7d 0a 0a  et laste $e..}..
2670: 09 69 6e 74 65 67 72 69 74 79 20 61 73 73 65 72  .integrity asser
2680: 74 20 7b 0a 09 20 20 20 20 24 6c 61 73 74 65 20  t {..    $laste 
2690: 3d 3d 20 28 5b 6c 6c 65 6e 67 74 68 20 24 6d 79  == ([llength $my
26a0: 69 74 65 6d 73 5d 2d 31 29 0a 09 7d 20 7b 42 61  items]-1)..} {Ba
26b0: 64 20 66 72 61 67 6d 65 6e 74 20 65 6e 64 20 40  d fragment end @
26c0: 20 24 6c 61 73 74 65 2c 20 67 61 70 2c 20 6f 72   $laste, gap, or
26d0: 20 62 65 79 6f 6e 64 20 65 6e 64 20 6f 66 20 74   beyond end of t
26e0: 68 65 20 72 61 6e 67 65 7d 0a 0a 09 23 20 50 75  he range}...# Pu
26f0: 74 20 74 68 65 20 66 69 72 73 74 20 66 72 61 67  t the first frag
2700: 6d 65 6e 74 20 69 6e 74 6f 20 74 68 65 20 63 75  ment into the cu
2710: 72 72 65 6e 74 20 63 68 61 6e 67 65 73 65 74 2c  rrent changeset,
2720: 20 61 6e 64 0a 09 23 20 75 70 64 61 74 65 20 74   and..# update t
2730: 68 65 20 69 6e 2d 6d 65 6d 6f 72 79 20 69 6e 64  he in-memory ind
2740: 65 78 2e 20 57 65 20 63 61 6e 20 73 69 6d 70 6c  ex. We can simpl
2750: 79 20 28 72 65 29 61 64 64 20 74 68 65 20 69 74  y (re)add the it
2760: 65 6d 73 0a 09 23 20 62 65 63 61 75 73 65 20 77  ems..# because w
2770: 65 20 63 6c 65 61 72 65 64 20 74 68 65 20 70 72  e cleared the pr
2780: 65 76 69 6f 75 73 6c 79 20 65 78 69 73 74 69 6e  eviously existin
2790: 67 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2c 20 73  g information, s
27a0: 65 65 0a 09 23 20 28 2a 29 20 61 62 6f 76 65 2e  ee..# (*) above.
27b0: 20 50 65 72 73 69 73 74 65 6e 63 65 20 64 6f 65   Persistence doe
27c0: 73 20 6e 6f 74 20 6d 61 74 74 65 72 20 68 65 72  s not matter her
27d0: 65 2c 20 6e 6f 6e 65 20 6f 66 20 74 68 65 0a 09  e, none of the..
27e0: 23 20 63 68 61 6e 67 65 73 65 74 73 20 68 61 73  # changesets has
27f0: 20 62 65 65 6e 20 73 61 76 65 64 20 74 6f 20 74   been saved to t
2800: 68 65 20 70 65 72 73 69 73 74 65 6e 74 20 73 74  he persistent st
2810: 61 74 65 20 79 65 74 2e 0a 0a 09 73 65 74 20 6d  ate yet....set m
2820: 79 69 74 65 6d 73 20 20 5b 6c 72 61 6e 67 65 20  yitems  [lrange 
2830: 24 6d 79 69 74 65 6d 73 20 20 30 20 24 66 69 72  $myitems  0 $fir
2840: 73 74 65 5d 0a 09 73 65 74 20 6d 79 74 69 74 65  ste]..set mytite
2850: 6d 73 20 5b 6c 72 61 6e 67 65 20 24 6d 79 74 69  ms [lrange $myti
2860: 74 65 6d 73 20 30 20 24 66 69 72 73 74 65 5d 0a  tems 0 $firste].
2870: 09 66 6f 72 65 61 63 68 20 69 69 64 20 24 6d 79  .foreach iid $my
2880: 69 74 65 6d 73 20 7b 0a 09 20 20 20 20 73 65 74  items {..    set
2890: 20 6b 65 79 20 5b 6c 69 73 74 20 24 6d 79 74 79   key [list $myty
28a0: 70 65 20 24 69 69 64 5d 0a 09 20 20 20 20 73 65  pe $iid]..    se
28b0: 74 20 6d 79 69 74 65 6d 6d 61 70 28 24 6b 65 79  t myitemmap($key
28c0: 29 20 24 73 65 6c 66 0a 09 20 20 20 20 6c 6f 67  ) $self..    log
28d0: 20 77 72 69 74 65 20 38 20 63 73 65 74 73 20 7b   write 8 csets {
28e0: 4d 41 50 2b 20 69 74 65 6d 20 3c 24 6b 65 79 3e  MAP+ item <$key>
28f0: 20 24 73 65 6c 66 20 3d 20 5b 24 73 65 6c 66 20   $self = [$self 
2900: 73 74 72 5d 7d 0a 09 7d 0a 0a 09 72 65 74 75 72  str]}..}...retur
2910: 6e 20 31 0a 20 20 20 20 7d 0a 0a 20 20 20 20 6d  n 1.    }..    m
2920: 65 74 68 6f 64 20 70 65 72 73 69 73 74 20 7b 7d  ethod persist {}
2930: 20 7b 0a 09 73 65 74 20 74 69 64 20 24 6d 79 63   {..set tid $myc
2940: 73 74 79 70 65 28 24 6d 79 74 79 70 65 29 0a 09  stype($mytype)..
2950: 73 65 74 20 70 69 64 20 5b 24 6d 79 70 72 6f 6a  set pid [$myproj
2960: 65 63 74 20 69 64 5d 0a 09 73 65 74 20 70 6f 73  ect id]..set pos
2970: 20 30 0a 0a 09 73 74 61 74 65 20 74 72 61 6e 73   0...state trans
2980: 61 63 74 69 6f 6e 20 7b 0a 09 20 20 20 20 73 74  action {..    st
2990: 61 74 65 20 72 75 6e 20 7b 0a 09 09 49 4e 53 45  ate run {...INSE
29a0: 52 54 20 49 4e 54 4f 20 63 68 61 6e 67 65 73 65  RT INTO changese
29b0: 74 20 28 63 69 64 2c 20 20 20 70 69 64 2c 20 20  t (cid,   pid,  
29c0: 74 79 70 65 2c 20 73 72 63 29 0a 09 09 56 41 4c  type, src)...VAL
29d0: 55 45 53 20 20 20 20 20 20 20 20 20 20 20 20 20  UES             
29e0: 20 20 20 28 24 6d 79 69 64 2c 20 24 70 69 64 2c     ($myid, $pid,
29f0: 20 24 74 69 64 2c 20 24 6d 79 73 72 63 69 64 29   $tid, $mysrcid)
2a00: 3b 0a 09 20 20 20 20 7d 0a 0a 09 20 20 20 20 66  ;..    }...    f
2a10: 6f 72 65 61 63 68 20 69 69 64 20 24 6d 79 69 74  oreach iid $myit
2a20: 65 6d 73 20 7b 0a 09 09 73 74 61 74 65 20 72 75  ems {...state ru
2a30: 6e 20 7b 0a 09 09 20 20 20 20 49 4e 53 45 52 54  n {...    INSERT
2a40: 20 49 4e 54 4f 20 63 73 69 74 65 6d 20 28 63 69   INTO csitem (ci
2a50: 64 2c 20 20 20 70 6f 73 2c 20 20 69 69 64 29 0a  d,   pos,  iid).
2a60: 09 09 20 20 20 20 56 41 4c 55 45 53 20 20 20 20  ..    VALUES    
2a70: 20 20 20 20 20 20 20 20 20 28 24 6d 79 69 64 2c           ($myid,
2a80: 20 24 70 6f 73 2c 20 24 69 69 64 29 3b 0a 09 09   $pos, $iid);...
2a90: 7d 0a 09 09 69 6e 63 72 20 70 6f 73 0a 09 20 20  }...incr pos..  
2aa0: 20 20 7d 0a 09 7d 0a 09 72 65 74 75 72 6e 0a 20    }..}..return. 
2ab0: 20 20 20 7d 0a 0a 20 20 20 20 6d 65 74 68 6f 64     }..    method
2ac0: 20 74 69 6d 65 72 61 6e 67 65 20 7b 7d 20 7b 20   timerange {} { 
2ad0: 72 65 74 75 72 6e 20 5b 24 6d 79 74 79 70 65 6f  return [$mytypeo
2ae0: 62 6a 20 74 69 6d 65 72 61 6e 67 65 20 24 6d 79  bj timerange $my
2af0: 69 74 65 6d 73 5d 20 7d 0a 0a 20 20 20 20 6d 65  items] }..    me
2b00: 74 68 6f 64 20 6c 69 6d 69 74 73 20 7b 7d 20 7b  thod limits {} {
2b10: 0a 09 73 74 72 75 63 74 3a 3a 6c 69 73 74 20 61  ..struct::list a
2b20: 73 73 69 67 6e 20 5b 24 6d 79 74 79 70 65 6f 62  ssign [$mytypeob
2b30: 6a 20 6c 69 6d 69 74 73 20 24 6d 79 69 74 65 6d  j limits $myitem
2b40: 73 5d 20 6d 61 78 70 20 6d 69 6e 73 0a 09 72 65  s] maxp mins..re
2b50: 74 75 72 6e 20 5b 6c 69 73 74 20 5b 54 61 67 49  turn [list [TagI
2b60: 74 65 6d 44 69 63 74 20 24 6d 61 78 70 20 24 6d  temDict $maxp $m
2b70: 79 74 79 70 65 5d 20 5b 54 61 67 49 74 65 6d 44  ytype] [TagItemD
2b80: 69 63 74 20 24 6d 69 6e 73 20 24 6d 79 74 79 70  ict $mins $mytyp
2b90: 65 5d 5d 0a 20 20 20 20 7d 0a 0a 20 20 20 20 6d  e]].    }..    m
2ba0: 65 74 68 6f 64 20 64 72 6f 70 20 7b 7d 20 7b 0a  ethod drop {} {.
2bb0: 09 6c 6f 67 20 77 72 69 74 65 20 38 20 63 73 65  .log write 8 cse
2bc0: 74 73 20 7b 44 72 6f 70 70 69 6e 67 20 24 73 65  ts {Dropping $se
2bd0: 6c 66 20 3d 20 5b 24 73 65 6c 66 20 73 74 72 5d  lf = [$self str]
2be0: 7d 0a 0a 09 73 74 61 74 65 20 74 72 61 6e 73 61  }...state transa
2bf0: 63 74 69 6f 6e 20 7b 0a 09 20 20 20 20 73 74 61  ction {..    sta
2c00: 74 65 20 72 75 6e 20 7b 0a 09 09 44 45 4c 45 54  te run {...DELET
2c10: 45 20 46 52 4f 4d 20 63 68 61 6e 67 65 73 65 74  E FROM changeset
2c20: 20 20 20 57 48 45 52 45 20 63 69 64 20 3d 20 24     WHERE cid = $
2c30: 6d 79 69 64 3b 0a 09 09 44 45 4c 45 54 45 20 46  myid;...DELETE F
2c40: 52 4f 4d 20 63 73 69 74 65 6d 20 20 20 20 20 20  ROM csitem      
2c50: 57 48 45 52 45 20 63 69 64 20 3d 20 24 6d 79 69  WHERE cid = $myi
2c60: 64 3b 0a 09 09 44 45 4c 45 54 45 20 46 52 4f 4d  d;...DELETE FROM
2c70: 20 63 73 73 75 63 63 65 73 73 6f 72 20 57 48 45   cssuccessor WHE
2c80: 52 45 20 63 69 64 20 3d 20 24 6d 79 69 64 3b 0a  RE cid = $myid;.
2c90: 09 20 20 20 20 7d 0a 09 7d 0a 09 66 6f 72 65 61  .    }..}..forea
2ca0: 63 68 20 69 69 64 20 24 6d 79 69 74 65 6d 73 20  ch iid $myitems 
2cb0: 7b 0a 09 20 20 20 20 73 65 74 20 6b 65 79 20 5b  {..    set key [
2cc0: 6c 69 73 74 20 24 6d 79 74 79 70 65 20 24 69 69  list $mytype $ii
2cd0: 64 5d 0a 09 20 20 20 20 75 6e 73 65 74 20 6d 79  d]..    unset my
2ce0: 69 74 65 6d 6d 61 70 28 24 6b 65 79 29 0a 09 20  itemmap($key).. 
2cf0: 20 20 20 6c 6f 67 20 77 72 69 74 65 20 38 20 63     log write 8 c
2d00: 73 65 74 73 20 7b 4d 41 50 2d 20 69 74 65 6d 20  sets {MAP- item 
2d10: 3c 24 6b 65 79 3e 20 24 73 65 6c 66 20 3d 20 5b  <$key> $self = [
2d20: 24 73 65 6c 66 20 73 74 72 5d 7d 0a 09 7d 0a 09  $self str]}..}..
2d30: 73 65 74 20 70 6f 73 20 20 20 20 20 20 20 20 20  set pos         
2d40: 20 5b 6c 73 65 61 72 63 68 20 2d 65 78 61 63 74   [lsearch -exact
2d50: 20 24 6d 79 63 68 61 6e 67 65 73 65 74 73 20 24   $mychangesets $
2d60: 73 65 6c 66 5d 0a 09 73 65 74 20 6d 79 63 68 61  self]..set mycha
2d70: 6e 67 65 73 65 74 73 20 5b 6c 72 65 70 6c 61 63  ngesets [lreplac
2d80: 65 20 24 6d 79 63 68 61 6e 67 65 73 65 74 73 20  e $mychangesets 
2d90: 24 70 6f 73 20 24 70 6f 73 5d 0a 09 73 65 74 20  $pos $pos]..set 
2da0: 70 6f 73 20 20 20 20 20 20 20 20 20 20 20 20 20  pos             
2db0: 20 20 20 20 20 20 20 5b 6c 73 65 61 72 63 68 20         [lsearch 
2dc0: 2d 65 78 61 63 74 20 24 6d 79 74 63 68 61 6e 67  -exact $mytchang
2dd0: 65 73 65 74 73 28 24 6d 79 74 79 70 65 29 20 24  esets($mytype) $
2de0: 73 65 6c 66 5d 0a 09 73 65 74 20 6d 79 74 63 68  self]..set mytch
2df0: 61 6e 67 65 73 65 74 73 28 24 6d 79 74 79 70 65  angesets($mytype
2e00: 29 20 5b 6c 72 65 70 6c 61 63 65 20 24 6d 79 74  ) [lreplace $myt
2e10: 63 68 61 6e 67 65 73 65 74 73 28 24 6d 79 74 79  changesets($myty
2e20: 70 65 29 20 24 70 6f 73 20 24 70 6f 73 5d 0a 0a  pe) $pos $pos]..
2e30: 09 23 20 52 65 74 75 72 6e 20 74 68 65 20 6c 69  .# Return the li
2e40: 73 74 20 6f 66 20 70 72 65 64 65 63 65 73 73 6f  st of predecesso
2e50: 72 73 20 73 6f 20 74 68 61 74 20 74 68 65 79 20  rs so that they 
2e60: 63 61 6e 20 62 65 20 61 64 6a 75 73 74 65 64 2e  can be adjusted.
2e70: 0a 09 72 65 74 75 72 6e 20 5b 73 74 72 75 63 74  ..return [struct
2e80: 3a 3a 6c 69 73 74 20 6d 61 70 20 5b 73 74 61 74  ::list map [stat
2e90: 65 20 72 75 6e 20 7b 0a 09 20 20 20 20 53 45 4c  e run {..    SEL
2ea0: 45 43 54 20 63 69 64 0a 09 20 20 20 20 46 52 4f  ECT cid..    FRO
2eb0: 4d 20 20 20 63 73 73 75 63 63 65 73 73 6f 72 0a  M   cssuccessor.
2ec0: 09 20 20 20 20 57 48 45 52 45 20 20 6e 69 64 20  .    WHERE  nid 
2ed0: 3d 20 24 6d 79 69 64 0a 09 7d 5d 20 5b 6d 79 74  = $myid..}] [myt
2ee0: 79 70 65 6d 65 74 68 6f 64 20 6f 66 5d 5d 0a 20  ypemethod of]]. 
2ef0: 20 20 20 7d 0a 0a 20 20 20 20 6d 65 74 68 6f 64     }..    method
2f00: 20 72 65 70 6f 72 74 6c 6f 6f 70 20 7b 7b 6b 69   reportloop {{ki
2f10: 6c 6c 20 31 7d 7d 20 7b 0a 09 23 20 57 65 20 70  ll 1}} {..# We p
2f20: 72 69 6e 74 20 74 68 65 20 69 74 65 6d 73 20 77  rint the items w
2f30: 68 69 63 68 20 61 72 65 20 70 72 6f 64 75 63 69  hich are produci
2f40: 6e 67 20 74 68 65 20 6c 6f 6f 70 2c 20 61 6e 64  ng the loop, and
2f50: 20 68 6f 77 2e 0a 0a 09 73 65 74 20 68 64 72 20   how....set hdr 
2f60: 22 53 65 6c 66 2d 72 65 66 65 72 65 6e 74 69 61  "Self-referentia
2f70: 6c 20 63 68 61 6e 67 65 73 65 74 20 5b 24 73 65  l changeset [$se
2f80: 6c 66 20 73 74 72 5d 20 5f 5f 5f 5f 5f 5f 5f 5f  lf str] ________
2f90: 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 22 0a 09 73 65 74  __________"..set
2fa0: 20 66 74 72 20 5b 72 65 67 73 75 62 20 2d 61 6c   ftr [regsub -al
2fb0: 6c 20 7b 5b 5e 20 09 5d 7d 20 24 68 64 72 20 7b  l {[^ .]} $hdr {
2fc0: 5f 7d 5d 0a 0a 09 6c 6f 67 20 77 72 69 74 65 20  _}]...log write 
2fd0: 30 20 63 73 65 74 73 20 24 68 64 72 0a 09 66 6f  0 csets $hdr..fo
2fe0: 72 65 61 63 68 20 7b 69 74 65 6d 20 6e 65 78 74  reach {item next
2ff0: 69 74 65 6d 7d 20 5b 24 6d 79 74 79 70 65 6f 62  item} [$mytypeob
3000: 6a 20 6c 6f 6f 70 73 20 24 6d 79 69 74 65 6d 73  j loops $myitems
3010: 5d 20 7b 0a 09 20 20 20 20 23 20 43 72 65 61 74  ] {..    # Creat
3020: 65 20 74 61 67 67 65 64 20 69 74 65 6d 73 20 66  e tagged items f
3030: 72 6f 6d 20 74 68 65 20 69 64 20 61 6e 64 20 6f  rom the id and o
3040: 75 72 20 74 79 70 65 2e 0a 09 20 20 20 20 73 65  ur type...    se
3050: 74 20 69 74 65 6d 20 20 20 20 20 5b 6c 69 73 74  t item     [list
3060: 20 24 6d 79 74 79 70 65 20 20 24 69 74 65 6d 5d   $mytype  $item]
3070: 0a 09 20 20 20 20 73 65 74 20 6e 65 78 74 69 74  ..    set nextit
3080: 65 6d 20 5b 6c 69 73 74 20 24 6d 79 74 79 70 65  em [list $mytype
3090: 20 24 6e 65 78 74 69 74 65 6d 5d 0a 09 20 20 20   $nextitem]..   
30a0: 20 23 20 50 72 69 6e 74 61 62 6c 65 20 6c 61 62   # Printable lab
30b0: 65 6c 73 2e 0a 09 20 20 20 20 73 65 74 20 69 20  els...    set i 
30c0: 20 22 3c 5b 24 74 79 70 65 20 69 74 65 6d 73 74   "<[$type itemst
30d0: 72 20 24 69 74 65 6d 5d 3e 22 0a 09 20 20 20 20  r $item]>"..    
30e0: 73 65 74 20 6e 20 20 22 3c 5b 24 74 79 70 65 20  set n  "<[$type 
30f0: 69 74 65 6d 73 74 72 20 24 6e 65 78 74 69 74 65  itemstr $nextite
3100: 6d 5d 3e 22 0a 09 20 20 20 20 73 65 74 20 6e 63  m]>"..    set nc
3110: 73 20 24 6d 79 69 74 65 6d 6d 61 70 28 24 6e 65  s $myitemmap($ne
3120: 78 74 69 74 65 6d 29 0a 09 20 20 20 20 23 20 50  xtitem)..    # P
3130: 72 69 6e 74 0a 09 20 20 20 20 6c 6f 67 20 77 72  rint..    log wr
3140: 69 74 65 20 30 20 63 73 65 74 73 20 7b 2a 20 24  ite 0 csets {* $
3150: 69 20 2d 2d 3e 20 24 6e 20 2d 2d 3e 20 63 73 20  i --> $n --> cs 
3160: 5b 24 6e 63 73 20 73 74 72 5d 7d 0a 09 7d 0a 09  [$ncs str]}..}..
3170: 6c 6f 67 20 77 72 69 74 65 20 30 20 63 73 65 74  log write 0 cset
3180: 73 20 24 66 74 72 0a 0a 09 69 66 20 7b 21 24 6b  s $ftr...if {!$k
3190: 69 6c 6c 7d 20 72 65 74 75 72 6e 0a 09 74 72 6f  ill} return..tro
31a0: 75 62 6c 65 20 69 6e 74 65 72 6e 61 6c 20 22 5b  uble internal "[
31b0: 24 73 65 6c 66 20 73 74 72 5d 20 64 65 70 65 6e  $self str] depen
31c0: 64 73 20 6f 6e 20 69 74 73 65 6c 66 22 0a 09 72  ds on itself"..r
31d0: 65 74 75 72 6e 0a 20 20 20 20 7d 0a 0a 20 20 20  eturn.    }..   
31e0: 20 6d 65 74 68 6f 64 20 70 75 73 68 74 6f 20 7b   method pushto {
31f0: 73 76 20 72 65 70 6f 73 69 74 6f 72 79 20 64 61  sv repository da
3200: 74 65 7d 20 7b 0a 09 75 70 76 61 72 20 31 20 24  te} {..upvar 1 $
3210: 73 76 20 73 74 61 74 65 0a 0a 09 23 20 47 65 6e  sv state...# Gen
3220: 65 72 61 74 65 20 61 6e 64 20 69 6d 70 6f 72 74  erate and import
3230: 20 74 68 65 20 6d 61 6e 69 66 65 73 74 20 66 6f   the manifest fo
3240: 72 20 74 68 69 73 20 63 68 61 6e 67 65 73 65 74  r this changeset
3250: 2e 0a 09 23 0a 09 23 20 44 61 74 61 20 6e 65 65  ...#..# Data nee
3260: 64 65 64 3a 0a 09 23 20 2d 20 43 6f 6d 6d 69 74  ded:..# - Commit
3270: 20 6d 65 73 73 61 67 65 20 20 20 20 20 20 20 20   message        
3280: 20 20 20 20 20 20 20 28 2d 2d 20 6d 79 73 72 63         (-- mysrc
3290: 69 64 20 2d 3e 20 72 65 70 6f 73 69 74 6f 72 79  id -> repository
32a0: 20 6d 65 74 61 29 0a 09 23 20 2d 20 55 73 65 72   meta)..# - User
32b0: 20 64 6f 69 6e 67 20 74 68 65 20 63 6f 6d 6d 69   doing the commi
32c0: 74 20 20 20 20 20 20 20 20 28 73 2e 61 2e 29 0a  t        (s.a.).
32d0: 09 23 0a 09 23 20 2d 20 54 69 6d 65 73 74 61 6d  .#..# - Timestam
32e0: 70 20 6f 66 20 77 68 65 6e 20 63 6f 6d 6d 69 74  p of when commit
32f0: 74 65 64 20 20 28 63 6f 6d 6d 61 6e 64 20 61 72  ted  (command ar
3300: 67 75 6d 65 6e 74 29 0a 09 23 0a 09 23 20 2d 20  gument)..#..# - 
3310: 54 68 65 20 70 61 72 65 6e 74 20 63 68 61 6e 67  The parent chang
3320: 65 73 65 74 2c 20 69 66 20 61 6e 79 2e 20 49 66  eset, if any. If
3330: 20 74 68 65 72 65 20 69 73 20 6e 6f 20 70 61 72   there is no par
3340: 65 6e 74 20 66 6f 73 73 69 6c 0a 09 23 20 20 20  ent fossil..#   
3350: 77 69 6c 6c 20 75 73 65 20 74 68 65 20 65 6d 70  will use the emp
3360: 74 79 20 62 61 73 65 20 72 65 76 69 73 69 6f 6e  ty base revision
3370: 20 61 73 20 70 61 72 65 6e 74 2e 0a 09 23 0a 09   as parent...#..
3380: 23 20 2d 20 4c 69 73 74 20 6f 66 20 74 68 65 20  # - List of the 
3390: 66 69 6c 65 20 72 65 76 69 73 69 6f 6e 73 20 69  file revisions i
33a0: 6e 20 74 68 65 20 63 68 61 6e 67 65 73 65 74 2e  n the changeset.
33b0: 0a 0a 09 73 74 72 75 63 74 3a 3a 6c 69 73 74 20  ...struct::list 
33c0: 61 73 73 69 67 6e 20 5b 24 6d 79 70 72 6f 6a 65  assign [$myproje
33d0: 63 74 20 67 65 74 6d 65 74 61 20 24 6d 79 73 72  ct getmeta $mysr
33e0: 63 69 64 5d 20 5f 5f 20 62 72 61 6e 63 68 20 75  cid] __ branch u
33f0: 73 65 72 20 6d 65 73 73 61 67 65 0a 09 73 74 72  ser message..str
3400: 75 63 74 3a 3a 6c 69 73 74 20 61 73 73 69 67 6e  uct::list assign
3410: 20 24 62 72 61 6e 63 68 20 5f 5f 20 6c 6f 64 6e   $branch __ lodn
3420: 61 6d 65 0a 0a 09 23 20 50 65 72 66 6f 72 6d 20  ame...# Perform 
3430: 74 68 65 20 69 6d 70 6f 72 74 2e 20 41 73 20 70  the import. As p
3440: 61 72 74 20 6f 66 20 74 68 61 74 20 77 65 20 64  art of that we d
3450: 65 74 65 72 6d 69 6e 65 20 74 68 65 20 70 61 72  etermine the par
3460: 65 6e 74 0a 09 23 20 77 65 20 6e 65 65 64 2c 20  ent..# we need, 
3470: 61 6e 64 20 63 6f 6e 76 65 72 74 20 74 68 65 20  and convert the 
3480: 6c 69 73 74 20 6f 66 20 69 74 65 6d 73 20 69 6e  list of items in
3490: 20 74 68 65 20 63 68 61 6e 67 65 73 65 74 20 69   the changeset i
34a0: 6e 74 6f 0a 09 23 20 75 75 69 64 73 20 61 6e 64  nto..# uuids and
34b0: 20 70 72 69 6e 74 61 62 6c 65 20 64 61 74 61 2e   printable data.
34c0: 0a 0a 09 73 65 74 20 75 75 69 64 20 5b 55 70 64  ...set uuid [Upd
34d0: 61 74 65 73 74 61 74 65 20 73 74 61 74 65 20 24  atestate state $
34e0: 6c 6f 64 6e 61 6d 65 20 5c 0a 09 09 20 20 20 20  lodname \...    
34f0: 20 20 5b 24 72 65 70 6f 73 69 74 6f 72 79 20 69    [$repository i
3500: 6d 70 6f 72 74 72 65 76 69 73 69 6f 6e 20 5b 24  mportrevision [$
3510: 73 65 6c 66 20 73 74 72 5d 20 5c 0a 09 09 09 20  self str] \.... 
3520: 20 20 24 75 73 65 72 20 24 6d 65 73 73 61 67 65    $user $message
3530: 20 24 64 61 74 65 20 5c 0a 09 09 09 20 20 20 5b   $date \....   [
3540: 47 65 74 70 61 72 65 6e 74 20 73 74 61 74 65 20  Getparent state 
3550: 24 6c 6f 64 6e 61 6d 65 20 24 6d 79 70 72 6f 6a  $lodname $myproj
3560: 65 63 74 20 24 6d 79 69 74 65 6d 73 5d 20 5c 0a  ect $myitems] \.
3570: 09 09 09 20 20 20 5b 47 65 74 72 65 76 69 73 69  ...   [Getrevisi
3580: 6f 6e 69 6e 66 6f 20 24 6d 79 69 74 65 6d 73 5d  oninfo $myitems]
3590: 5d 5d 0a 0a 09 23 20 52 65 6d 65 6d 62 65 72 20  ]]...# Remember 
35a0: 74 68 65 20 77 68 6f 6c 65 20 63 68 61 6e 67 65  the whole change
35b0: 73 65 74 20 2f 20 75 75 69 64 20 6d 61 70 70 69  set / uuid mappi
35c0: 6e 67 2c 20 66 6f 72 20 74 68 65 20 74 61 67 73  ng, for the tags
35d0: 2e 0a 0a 09 73 74 61 74 65 20 72 75 6e 20 7b 0a  ....state run {.
35e0: 09 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
35f0: 20 63 73 75 75 69 64 20 28 63 69 64 2c 20 20 20   csuuid (cid,   
3600: 75 75 69 64 29 0a 09 20 20 20 20 56 41 4c 55 45  uuid)..    VALUE
3610: 53 20 20 20 20 20 20 20 20 20 20 20 20 20 28 24  S             ($
3620: 6d 79 69 64 2c 20 24 75 75 69 64 29 0a 09 7d 0a  myid, $uuid)..}.
3630: 09 72 65 74 75 72 6e 0a 20 20 20 20 7d 0a 0a 20  .return.    }.. 
3640: 20 20 20 70 72 6f 63 20 47 65 74 72 65 76 69 73     proc Getrevis
3650: 69 6f 6e 69 6e 66 6f 20 7b 72 65 76 69 73 69 6f  ioninfo {revisio
3660: 6e 73 7d 20 7b 0a 09 73 65 74 20 74 68 65 73 65  ns} {..set these
3670: 74 20 28 27 5b 6a 6f 69 6e 20 24 72 65 76 69 73  t ('[join $revis
3680: 69 6f 6e 73 20 7b 27 2c 27 7d 5d 27 29 0a 09 73  ions {','}]')..s
3690: 65 74 20 72 65 76 69 73 69 6f 6e 73 20 7b 7d 0a  et revisions {}.
36a0: 09 66 6f 72 65 61 63 68 20 7b 66 72 69 64 20 70  .foreach {frid p
36b0: 61 74 68 20 66 6e 61 6d 65 20 72 65 76 6e 72 7d  ath fname revnr}
36c0: 20 5b 73 74 61 74 65 20 72 75 6e 20 5b 73 75 62   [state run [sub
36d0: 73 74 20 2d 6e 6f 63 6f 6d 6d 61 6e 64 73 20 2d  st -nocommands -
36e0: 6e 6f 62 61 63 6b 73 6c 61 73 68 65 73 20 7b 0a  nobackslashes {.
36f0: 09 20 20 20 20 53 45 4c 45 43 54 20 55 2e 75 75  .    SELECT U.uu
3700: 69 64 2c 20 46 2e 76 69 73 69 62 6c 65 2c 20 46  id, F.visible, F
3710: 2e 6e 61 6d 65 2c 20 52 2e 72 65 76 0a 09 20 20  .name, R.rev..  
3720: 20 20 46 52 4f 4d 20 20 20 72 65 76 69 73 69 6f    FROM   revisio
3730: 6e 20 52 2c 20 72 65 76 75 75 69 64 20 55 2c 20  n R, revuuid U, 
3740: 66 69 6c 65 20 46 0a 09 20 20 20 20 57 48 45 52  file F..    WHER
3750: 45 20 20 52 2e 72 69 64 20 49 4e 20 24 74 68 65  E  R.rid IN $the
3760: 73 65 74 20 20 2d 2d 20 41 6c 6c 20 73 70 65 63  set  -- All spec
3770: 69 66 69 65 64 20 72 65 76 69 73 69 6f 6e 73 0a  ified revisions.
3780: 09 20 20 20 20 41 4e 44 20 20 20 20 55 2e 72 69  .    AND    U.ri
3790: 64 20 3d 20 52 2e 72 69 64 20 20 20 20 20 2d 2d  d = R.rid     --
37a0: 20 67 65 74 20 66 6f 73 73 69 6c 20 75 75 69 64   get fossil uuid
37b0: 20 6f 66 20 72 65 76 69 73 69 6f 6e 0a 09 20 20   of revision..  
37c0: 20 20 41 4e 44 20 20 20 20 46 2e 66 69 64 20 3d    AND    F.fid =
37d0: 20 52 2e 66 69 64 20 20 20 20 20 2d 2d 20 67 65   R.fid     -- ge
37e0: 74 20 66 69 6c 65 20 6f 66 20 72 65 76 69 73 69  t file of revisi
37f0: 6f 6e 0a 09 7d 5d 5d 20 7b 0a 09 20 20 20 20 6c  on..}]] {..    l
3800: 61 70 70 65 6e 64 20 72 65 76 69 73 69 6f 6e 73  append revisions
3810: 20 24 66 72 69 64 20 24 70 61 74 68 20 24 66 6e   $frid $path $fn
3820: 61 6d 65 2f 24 72 65 76 6e 72 0a 09 7d 0a 09 72  ame/$revnr..}..r
3830: 65 74 75 72 6e 20 24 72 65 76 69 73 69 6f 6e 73  eturn $revisions
3840: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 70 72 6f 63  .    }..    proc
3850: 20 47 65 74 70 61 72 65 6e 74 20 7b 73 76 20 6c   Getparent {sv l
3860: 6f 64 6e 61 6d 65 20 70 72 6f 6a 65 63 74 20 69  odname project i
3870: 74 65 6d 73 7d 20 7b 0a 09 75 70 76 61 72 20 31  tems} {..upvar 1
3880: 20 24 73 76 20 73 74 61 74 65 0a 0a 09 73 74 72   $sv state...str
3890: 75 63 74 3a 3a 6c 69 73 74 20 61 73 73 69 67 6e  uct::list assign
38a0: 20 5b 47 65 74 69 73 64 65 66 61 75 6c 74 20 24   [Getisdefault $
38b0: 69 74 65 6d 73 5d 20 69 73 64 65 66 61 75 6c 74  items] isdefault
38c0: 20 6c 61 73 74 64 65 66 61 75 6c 74 6f 6e 74 72   lastdefaultontr
38d0: 75 6e 6b 0a 0a 09 6c 6f 67 20 77 72 69 74 65 20  unk...log write 
38e0: 38 20 63 73 65 74 73 20 7b 4c 4f 44 20 20 20 20  8 csets {LOD    
38f0: 27 24 6c 6f 64 6e 61 6d 65 27 7d 0a 09 6c 6f 67  '$lodname'}..log
3900: 20 77 72 69 74 65 20 38 20 63 73 65 74 73 20 7b   write 8 csets {
3910: 20 64 65 66 3f 20 20 24 69 73 64 65 66 61 75 6c   def?  $isdefaul
3920: 74 7d 0a 09 6c 6f 67 20 77 72 69 74 65 20 38 20  t}..log write 8 
3930: 63 73 65 74 73 20 7b 20 6c 61 73 74 3f 20 24 6c  csets { last? $l
3940: 61 73 74 64 65 66 61 75 6c 74 6f 6e 74 72 75 6e  astdefaultontrun
3950: 6b 7d 0a 0a 09 66 6f 72 65 61 63 68 20 6b 20 5b  k}...foreach k [
3960: 6c 73 6f 72 74 20 5b 61 72 72 61 79 20 6e 61 6d  lsort [array nam
3970: 65 73 20 73 74 61 74 65 5d 5d 20 7b 0a 09 20 20  es state]] {..  
3980: 20 20 6c 6f 67 20 77 72 69 74 65 20 38 20 63 73    log write 8 cs
3990: 65 74 73 20 7b 20 20 20 20 24 6b 20 3d 20 24 73  ets {    $k = $s
39a0: 74 61 74 65 28 24 6b 29 7d 0a 09 7d 0a 0a 09 23  tate($k)}..}...#
39b0: 20 53 65 65 20 28 61 29 20 62 65 6c 6f 77 2c 20   See (a) below, 
39c0: 77 65 20 68 61 76 65 20 74 6f 20 72 65 6d 65 6d  we have to remem
39d0: 62 65 72 20 69 66 20 74 68 65 20 63 68 61 6e 67  ber if the chang
39e0: 65 73 65 74 20 69 73 20 6c 61 73 74 0a 09 23 20  eset is last..# 
39f0: 6f 6e 20 76 65 6e 64 6f 72 20 62 72 61 6e 63 68  on vendor branch
3a00: 20 61 6c 73 6f 20 62 65 6c 6f 6e 67 69 6e 67 20   also belonging 
3a10: 74 6f 20 74 72 75 6e 6b 20 65 76 65 6e 20 69 66  to trunk even if
3a20: 20 77 65 20 66 69 6e 64 20 61 0a 09 23 20 70 61   we find a..# pa
3a30: 72 65 6e 74 20 69 6e 20 74 68 65 20 73 74 61 74  rent in the stat
3a40: 65 2e 20 54 68 65 20 63 61 6c 6c 65 72 20 77 69  e. The caller wi
3a50: 6c 6c 20 6c 61 74 65 72 20 28 61 66 74 65 72 20  ll later (after 
3a60: 69 6d 70 6f 72 74 29 0a 09 23 20 6d 61 6b 65 20  import)..# make 
3a70: 75 73 20 74 68 65 20 66 69 72 73 74 20 74 72 75  us the first tru
3a80: 6e 6b 20 63 68 61 6e 67 65 73 65 74 20 69 6e 20  nk changeset in 
3a90: 74 68 65 20 73 74 61 74 65 20 28 53 65 65 20 28  the state (See (
3aa0: 2a 2a 29 29 2e 0a 0a 09 69 66 20 7b 24 6c 61 73  **))....if {$las
3ab0: 74 64 65 66 61 75 6c 74 6f 6e 74 72 75 6e 6b 7d  tdefaultontrunk}
3ac0: 20 7b 0a 09 20 20 20 20 73 65 74 20 73 74 61 74   {..    set stat
3ad0: 65 28 3a 76 65 6e 64 6f 72 3a 6c 61 73 74 3a 29  e(:vendor:last:)
3ae0: 20 2e 0a 09 7d 0a 0a 09 23 20 54 68 65 20 73 74   ...}...# The st
3af0: 61 74 65 20 61 72 72 61 79 20 68 6f 6c 64 73 20  ate array holds 
3b00: 66 6f 72 20 65 61 63 68 20 6c 69 6e 65 2d 6f 66  for each line-of
3b10: 2d 64 65 76 65 6c 6f 70 6d 65 6e 74 20 28 4c 4f  -development (LO
3b20: 44 29 20 74 68 65 0a 09 23 20 6c 61 73 74 20 63  D) the..# last c
3b30: 6f 6d 6d 69 74 74 65 64 20 63 68 61 6e 67 65 73  ommitted changes
3b40: 65 74 20 62 65 6c 6f 6e 67 69 6e 67 20 74 6f 20  et belonging to 
3b50: 74 68 61 74 20 4c 4f 44 2e 0a 0a 09 23 20 28 2a  that LOD....# (*
3b60: 29 20 53 74 61 6e 64 61 72 64 20 68 61 6e 64 6c  ) Standard handl
3b70: 69 6e 67 20 69 66 20 69 6e 2d 4c 4f 44 20 63 68  ing if in-LOD ch
3b80: 61 6e 67 65 73 65 74 73 2e 20 49 66 20 74 68 65  angesets. If the
3b90: 20 4c 4f 44 20 6f 66 0a 09 23 20 20 20 20 20 74   LOD of..#     t
3ba0: 68 65 20 63 75 72 72 65 6e 74 20 63 68 61 6e 67  he current chang
3bb0: 65 73 65 74 20 65 78 69 73 74 73 20 69 6e 20 74  eset exists in t
3bc0: 68 65 20 73 74 61 74 65 20 28 3d 20 68 61 73 20  he state (= has 
3bd0: 62 65 65 6e 0a 09 23 20 20 20 20 20 63 6f 6d 6d  been..#     comm
3be0: 69 74 74 65 64 20 74 6f 29 20 74 68 65 6e 20 74  itted to) then t
3bf0: 68 65 20 73 74 6f 72 65 64 20 63 68 61 6e 67 65  he stored change
3c00: 73 65 74 20 69 73 20 74 68 65 20 70 61 72 65 6e  set is the paren
3c10: 74 20 77 65 0a 09 23 20 20 20 20 20 61 72 65 20  t we..#     are 
3c20: 6c 6f 6f 6b 69 6e 67 20 66 6f 72 2e 0a 0a 09 69  looking for....i
3c30: 66 20 7b 5b 69 6e 66 6f 20 65 78 69 73 74 73 20  f {[info exists 
3c40: 73 74 61 74 65 28 24 6c 6f 64 6e 61 6d 65 29 5d  state($lodname)]
3c50: 7d 20 7b 0a 09 20 20 20 20 72 65 74 75 72 6e 20  } {..    return 
3c60: 24 73 74 61 74 65 28 24 6c 6f 64 6e 61 6d 65 29  $state($lodname)
3c70: 0a 09 7d 0a 0a 09 23 20 49 66 20 74 68 65 20 4c  ..}...# If the L
3c80: 4f 44 20 69 73 20 6e 6f 74 20 79 65 74 20 6b 6e  OD is not yet kn
3c90: 6f 77 6e 20 74 68 65 20 63 75 72 72 65 6e 74 20  own the current 
3ca0: 63 68 61 6e 67 65 73 65 74 20 63 61 6e 20 65 69  changeset can ei
3cb0: 74 68 65 72 0a 09 23 20 62 65 0a 09 23 20 28 61  ther..# be..# (a
3cc0: 29 20 74 68 65 20 72 6f 6f 74 20 6f 66 20 61 20  ) the root of a 
3cd0: 76 65 6e 64 6f 72 20 62 72 61 6e 63 68 2c 0a 09  vendor branch,..
3ce0: 23 20 28 62 29 20 74 68 65 20 72 6f 6f 74 20 6f  # (b) the root o
3cf0: 66 20 74 68 65 20 74 72 75 6e 6b 20 4c 4f 44 2c  f the trunk LOD,
3d00: 20 6f 72 0a 09 23 20 28 63 29 20 74 68 65 20 66   or..# (c) the f
3d10: 69 72 73 74 20 63 68 61 6e 67 65 73 65 74 20 69  irst changeset i
3d20: 6e 20 61 20 6e 65 77 20 4c 4f 44 20 77 68 69 63  n a new LOD whic
3d30: 68 20 77 61 73 20 73 70 61 77 6e 65 64 20 66 72  h was spawned fr
3d40: 6f 6d 0a 09 23 20 20 20 20 20 61 6e 20 65 78 69  om..#     an exi
3d50: 73 74 69 6e 67 20 4c 4f 44 2e 0a 0a 09 69 66 20  sting LOD....if 
3d60: 7b 24 69 73 64 65 66 61 75 6c 74 7d 20 7b 0a 09  {$isdefault} {..
3d70: 20 20 20 20 23 20 49 6e 20 63 61 73 65 20 6f 66      # In case of
3d80: 20 28 61 29 20 74 68 65 20 63 68 61 6e 67 65 73   (a) the changes
3d90: 65 74 20 68 61 73 20 6e 6f 20 70 61 72 65 6e 74  et has no parent
3da0: 2c 20 73 69 67 6e 61 6c 65 64 20 62 79 0a 09 20  , signaled by.. 
3db0: 20 20 20 23 20 74 68 65 20 65 6d 70 74 79 20 73     # the empty s
3dc0: 74 72 69 6e 67 2e 20 57 65 20 64 6f 20 72 65 6d  tring. We do rem
3dd0: 65 6d 62 65 72 20 69 66 20 74 68 65 20 63 68 61  ember if the cha
3de0: 6e 67 65 73 65 74 20 69 73 0a 09 20 20 20 20 23  ngeset is..    #
3df0: 20 6c 61 73 74 20 6f 6e 20 74 68 65 20 76 65 6e   last on the ven
3e00: 64 6f 72 20 62 72 61 6e 63 68 20 73 74 69 6c 6c  dor branch still
3e10: 20 62 65 6c 6f 6e 67 69 6e 67 20 74 6f 20 74 72   belonging to tr
3e20: 75 6e 6b 2c 20 66 6f 72 0a 09 20 20 20 20 23 20  unk, for..    # 
3e30: 74 68 65 20 74 72 75 6e 6b 20 72 6f 6f 74 2e 0a  the trunk root..
3e40: 09 20 20 20 20 72 65 74 75 72 6e 20 7b 7d 0a 09  .    return {}..
3e50: 7d 0a 0a 09 69 66 20 7b 24 6c 6f 64 6e 61 6d 65  }...if {$lodname
3e60: 20 65 71 20 22 3a 74 72 75 6e 6b 3a 22 7d 20 7b   eq ":trunk:"} {
3e70: 0a 09 20 20 20 20 23 20 54 68 69 73 20 69 73 20  ..    # This is 
3e80: 63 61 73 65 20 28 62 29 2c 20 61 6e 64 20 77 65  case (b), and we
3e90: 20 61 6c 73 6f 20 63 61 6e 20 62 65 20 73 75 72   also can be sur
3ea0: 65 20 74 68 61 74 20 74 68 65 72 65 20 69 73 0a  e that there is.
3eb0: 09 20 20 20 20 23 20 6e 6f 20 76 65 6e 64 6f 72  .    # no vendor
3ec0: 20 62 72 61 6e 63 68 20 63 68 61 6e 67 65 73 65   branch changese
3ed0: 74 20 77 68 69 63 68 20 63 6f 75 6c 64 20 62 65  t which could be
3ee0: 20 6f 75 72 0a 09 20 20 20 20 23 20 70 61 72 65   our..    # pare
3ef0: 6e 74 2e 20 54 68 61 74 20 77 61 73 20 61 6c 72  nt. That was alr
3f00: 65 61 64 79 20 64 65 61 6c 74 20 77 69 74 68 20  eady dealt with 
3f10: 74 68 72 6f 75 67 68 20 74 68 65 0a 09 20 20 20  through the..   
3f20: 20 23 20 3a 76 65 6e 64 6f 72 3a 6c 61 73 74 3a   # :vendor:last:
3f30: 20 73 69 67 6e 61 6c 20 61 6e 64 20 63 6f 64 65   signal and code
3f40: 20 69 6e 20 74 68 65 20 63 61 6c 6c 65 72 20 28   in the caller (
3f50: 73 65 74 74 69 6e 67 0a 09 20 20 20 20 23 20 73  setting..    # s
3f60: 75 63 68 20 61 20 63 68 61 6e 67 65 73 65 74 20  uch a changeset 
3f70: 75 70 20 61 73 20 70 61 72 65 6e 74 20 69 6e 20  up as parent in 
3f80: 74 68 65 20 73 74 61 74 65 2c 20 63 61 75 73 69  the state, causi
3f90: 6e 67 20 74 68 65 0a 09 20 20 20 20 23 20 73 74  ng the..    # st
3fa0: 61 6e 64 61 72 64 20 4c 4f 44 20 68 61 6e 64 6c  andard LOD handl
3fb0: 65 72 20 61 74 20 28 2a 29 20 74 6f 20 6b 69 63  er at (*) to kic
3fc0: 6b 20 69 6e 2e 20 53 6f 2c 20 6e 6f 20 70 61 72  k in. So, no par
3fd0: 65 6e 74 0a 09 20 20 20 20 23 20 68 65 72 65 20  ent..    # here 
3fe0: 61 74 20 61 6c 6c 2e 0a 09 20 20 20 20 72 65 74  at all...    ret
3ff0: 75 72 6e 20 7b 7d 0a 09 7d 0a 0a 09 23 20 43 61  urn {}..}...# Ca
4000: 73 65 20 28 63 29 2e 20 57 65 20 66 69 6e 64 20  se (c). We find 
4010: 74 68 65 20 70 61 72 65 6e 74 20 4c 4f 44 20 6f  the parent LOD o
4020: 66 20 6f 75 72 20 4c 4f 44 20 61 6e 64 20 74 61  f our LOD and ta
4030: 6b 65 20 74 68 65 0a 09 23 20 6c 61 73 74 20 63  ke the..# last c
4040: 68 61 6e 67 65 73 65 74 20 63 6f 6d 6d 69 74 74  hangeset committ
4050: 65 64 20 74 6f 20 74 68 61 74 20 61 73 20 6f 75  ed to that as ou
4060: 72 20 70 61 72 65 6e 74 2e 20 49 66 20 74 68 61  r parent. If tha
4070: 74 0a 09 23 20 64 6f 65 73 6e 27 74 20 65 78 69  t..# doesn't exi
4080: 73 74 20 77 65 20 68 61 76 65 20 61 6e 20 65 72  st we have an er
4090: 72 6f 72 20 6f 6e 20 6f 75 72 20 68 61 6e 64 73  ror on our hands
40a0: 2e 0a 0a 09 73 65 74 20 70 6c 6f 64 6e 61 6d 65  ....set plodname
40b0: 20 5b 5b 5b 24 70 72 6f 6a 65 63 74 20 67 65 74   [[[$project get
40c0: 73 79 6d 62 6f 6c 20 24 6c 6f 64 6e 61 6d 65 5d  symbol $lodname]
40d0: 20 70 61 72 65 6e 74 5d 20 6e 61 6d 65 5d 0a 0a   parent] name]..
40e0: 09 6c 6f 67 20 77 72 69 74 65 20 38 20 63 73 65  .log write 8 cse
40f0: 74 73 20 7b 70 4c 4f 44 20 20 20 27 24 70 6c 6f  ts {pLOD   '$plo
4100: 64 6e 61 6d 65 27 7d 0a 0a 09 69 66 20 7b 5b 69  dname'}...if {[i
4110: 6e 66 6f 20 65 78 69 73 74 73 20 73 74 61 74 65  nfo exists state
4120: 28 24 70 6c 6f 64 6e 61 6d 65 29 5d 7d 20 7b 0a  ($plodname)]} {.
4130: 09 20 20 20 20 72 65 74 75 72 6e 20 24 73 74 61  .    return $sta
4140: 74 65 28 24 70 6c 6f 64 6e 61 6d 65 29 0a 09 7d  te($plodname)..}
4150: 0a 0a 09 74 72 6f 75 62 6c 65 20 69 6e 74 65 72  ...trouble inter
4160: 6e 61 6c 20 7b 55 6e 61 62 6c 65 20 74 6f 20 64  nal {Unable to d
4170: 65 74 65 72 6d 69 6e 65 20 63 68 61 6e 67 65 73  etermine changes
4180: 65 74 20 70 61 72 65 6e 74 7d 0a 09 72 65 74 75  et parent}..retu
4190: 72 6e 0a 20 20 20 20 7d 0a 0a 20 20 20 20 70 72  rn.    }..    pr
41a0: 6f 63 20 47 65 74 69 73 64 65 66 61 75 6c 74 20  oc Getisdefault 
41b0: 7b 72 65 76 69 73 69 6f 6e 73 7d 20 7b 0a 09 73  {revisions} {..s
41c0: 65 74 20 74 68 65 73 65 74 20 28 27 5b 6a 6f 69  et theset ('[joi
41d0: 6e 20 24 72 65 76 69 73 69 6f 6e 73 20 7b 27 2c  n $revisions {',
41e0: 27 7d 5d 27 29 0a 0a 09 73 74 72 75 63 74 3a 3a  '}]')...struct::
41f0: 6c 69 73 74 20 61 73 73 69 67 6e 20 5b 73 74 61  list assign [sta
4200: 74 65 20 72 75 6e 20 5b 73 75 62 73 74 20 2d 6e  te run [subst -n
4210: 6f 63 6f 6d 6d 61 6e 64 73 20 2d 6e 6f 62 61 63  ocommands -nobac
4220: 6b 73 6c 61 73 68 65 73 20 7b 0a 09 20 20 20 20  kslashes {..    
4230: 53 45 4c 45 43 54 20 52 2e 69 73 64 65 66 61 75  SELECT R.isdefau
4240: 6c 74 2c 20 52 2e 64 62 63 68 69 6c 64 0a 09 20  lt, R.dbchild.. 
4250: 20 20 20 46 52 4f 4d 20 20 20 72 65 76 69 73 69     FROM   revisi
4260: 6f 6e 20 52 0a 09 20 20 20 20 57 48 45 52 45 20  on R..    WHERE 
4270: 20 52 2e 72 69 64 20 49 4e 20 24 74 68 65 73 65   R.rid IN $these
4280: 74 20 20 2d 2d 20 41 6c 6c 20 73 70 65 63 69 66  t  -- All specif
4290: 69 65 64 20 72 65 76 69 73 69 6f 6e 73 0a 09 20  ied revisions.. 
42a0: 20 20 20 4c 49 4d 49 54 20 31 0a 09 7d 5d 5d 20     LIMIT 1..}]] 
42b0: 64 65 66 20 6c 61 73 74 0a 0a 09 23 20 54 4f 44  def last...# TOD
42c0: 4f 2f 43 48 45 43 4b 3a 20 6c 6f 6f 6b 20 66 6f  O/CHECK: look fo
42d0: 72 20 63 68 61 6e 67 65 73 65 74 73 20 77 68 65  r changesets whe
42e0: 72 65 20 69 73 64 65 66 61 75 6c 74 2f 64 62 63  re isdefault/dbc
42f0: 68 69 6c 64 20 69 73 0a 09 23 20 61 6d 62 69 67  hild is..# ambig
4300: 6f 75 73 2e 0a 0a 09 72 65 74 75 72 6e 20 5b 6c  ous....return [l
4310: 69 73 74 20 24 64 65 66 20 5b 65 78 70 72 20 7b  ist $def [expr {
4320: 24 6c 61 73 74 20 6e 65 20 22 22 7d 5d 5d 0a 20  $last ne ""}]]. 
4330: 20 20 20 7d 0a 0a 20 20 20 20 70 72 6f 63 20 55     }..    proc U
4340: 70 64 61 74 65 73 74 61 74 65 20 7b 73 76 20 6c  pdatestate {sv l
4350: 6f 64 6e 61 6d 65 20 75 75 69 64 7d 20 7b 0a 09  odname uuid} {..
4360: 75 70 76 61 72 20 31 20 24 73 76 20 73 74 61 74  upvar 1 $sv stat
4370: 65 0a 0a 09 23 20 52 65 6d 65 6d 62 65 72 20 74  e...# Remember t
4380: 68 65 20 69 6d 70 6f 72 74 65 64 20 63 68 61 6e  he imported chan
4390: 67 65 73 65 74 20 69 6e 20 74 68 65 20 73 74 61  geset in the sta
43a0: 74 65 2c 20 75 6e 64 65 72 20 6f 75 72 0a 09 23  te, under our..#
43b0: 20 4c 4f 44 2e 20 28 2a 2a 29 20 41 6e 64 20 69   LOD. (**) And i
43c0: 66 20 74 68 65 20 3a 76 65 6e 64 6f 72 3a 6c 61  f the :vendor:la
43d0: 73 74 3a 20 73 69 67 6e 61 6c 20 69 73 20 70 72  st: signal is pr
43e0: 65 73 65 6e 74 20 74 68 65 6e 0a 09 23 20 74 68  esent then..# th
43f0: 65 20 72 65 76 69 73 69 6f 6e 20 69 73 20 61 6c  e revision is al
4400: 73 6f 20 74 68 65 20 61 63 74 75 61 6c 20 72 6f  so the actual ro
4410: 6f 74 20 6f 66 20 74 68 65 20 3a 74 72 75 6e 6b  ot of the :trunk
4420: 3a 2c 20 73 6f 0a 09 23 20 72 65 6d 65 6d 62 65  :, so..# remembe
4430: 72 20 69 74 20 61 73 20 73 75 63 68 2e 0a 0a 09  r it as such....
4440: 73 65 74 20 73 74 61 74 65 28 24 6c 6f 64 6e 61  set state($lodna
4450: 6d 65 29 20 24 75 75 69 64 0a 09 69 66 20 7b 5b  me) $uuid..if {[
4460: 69 6e 66 6f 20 65 78 69 73 74 73 20 73 74 61 74  info exists stat
4470: 65 28 3a 76 65 6e 64 6f 72 3a 6c 61 73 74 3a 29  e(:vendor:last:)
4480: 5d 7d 20 7b 0a 09 20 20 20 20 75 6e 73 65 74 20  ]} {..    unset 
4490: 73 74 61 74 65 28 3a 76 65 6e 64 6f 72 3a 6c 61  state(:vendor:la
44a0: 73 74 3a 29 0a 09 20 20 20 20 73 65 74 20 73 74  st:)..    set st
44b0: 61 74 65 28 3a 74 72 75 6e 6b 3a 29 20 24 75 75  ate(:trunk:) $uu
44c0: 69 64 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 20 24  id..}...return $
44d0: 75 75 69 64 0a 20 20 20 20 7d 0a 0a 20 20 20 20  uuid.    }..    
44e0: 74 79 70 65 6d 65 74 68 6f 64 20 73 70 6c 69 74  typemethod split
44f0: 20 7b 63 73 65 74 20 61 72 67 73 7d 20 7b 0a 09   {cset args} {..
4500: 23 20 41 73 20 70 61 72 74 20 6f 66 20 74 68 65  # As part of the
4510: 20 63 72 65 61 74 69 6f 6e 20 6f 66 20 74 68 65   creation of the
4520: 20 6e 65 77 20 63 68 61 6e 67 65 73 65 74 73 20   new changesets 
4530: 73 70 65 63 69 66 69 65 64 20 69 6e 0a 09 23 20  specified in..# 
4540: 41 52 47 53 20 61 73 20 73 65 74 73 20 6f 66 20  ARGS as sets of 
4550: 69 74 65 6d 73 2c 20 61 6c 6c 20 73 75 62 73 65  items, all subse
4560: 74 73 20 6f 66 20 43 53 45 54 27 73 20 69 74 65  ts of CSET's ite
4570: 6d 20 73 65 74 2c 20 43 53 45 54 0a 09 23 20 77  m set, CSET..# w
4580: 69 6c 6c 20 62 65 20 64 72 6f 70 70 65 64 20 66  ill be dropped f
4590: 72 6f 6d 20 61 6c 6c 20 64 61 74 61 62 61 73 65  rom all database
45a0: 73 2c 20 69 6e 20 61 6e 64 20 6f 75 74 20 6f 66  s, in and out of
45b0: 20 6d 65 6d 6f 72 79 2c 0a 09 23 20 61 6e 64 20   memory,..# and 
45c0: 74 68 65 6e 20 64 65 73 74 72 6f 79 65 64 2e 0a  then destroyed..
45d0: 09 23 0a 09 23 20 4e 6f 74 65 3a 20 54 68 65 20  .#..# Note: The 
45e0: 69 74 65 6d 20 6c 69 73 74 73 20 66 6f 75 6e 64  item lists found
45f0: 20 69 6e 20 61 72 67 73 20 61 72 65 20 74 61 67   in args are tag
4600: 67 65 64 20 69 74 65 6d 73 2e 20 54 68 65 79 0a  ged items. They.
4610: 09 23 20 68 61 76 65 20 74 6f 20 68 61 76 65 20  .# have to have 
4620: 74 68 65 20 73 61 6d 65 20 74 79 70 65 20 61 73  the same type as
4630: 20 74 68 65 20 63 68 61 6e 67 65 73 65 74 2c 20   the changeset, 
4640: 62 65 69 6e 67 20 73 75 62 73 65 74 73 0a 09 23  being subsets..#
4650: 20 6f 66 20 69 74 73 20 69 74 65 6d 73 2e 20 54   of its items. T
4660: 68 69 73 20 69 73 20 63 68 65 63 6b 65 64 20 69  his is checked i
4670: 6e 20 55 6e 74 61 67 31 2e 0a 0a 09 6c 6f 67 20  n Untag1....log 
4680: 77 72 69 74 65 20 38 20 63 73 65 74 73 20 7b 4f  write 8 csets {O
4690: 4c 44 3a 20 5b 6c 73 6f 72 74 20 5b 24 63 73 65  LD: [lsort [$cse
46a0: 74 20 69 74 65 6d 73 5d 5d 7d 0a 09 56 61 6c 69  t items]]}..Vali
46b0: 64 61 74 65 46 72 61 67 6d 65 6e 74 73 20 24 63  dateFragments $c
46c0: 73 65 74 20 24 61 72 67 73 0a 0a 09 23 20 41 6c  set $args...# Al
46d0: 6c 20 63 68 65 63 6b 73 20 70 61 73 73 2c 20 61  l checks pass, a
46e0: 63 74 75 61 6c 6c 79 20 70 65 72 66 6f 72 6d 20  ctually perform 
46f0: 74 68 65 20 73 70 6c 69 74 2e 0a 0a 09 73 74 72  the split....str
4700: 75 63 74 3a 3a 6c 69 73 74 20 61 73 73 69 67 6e  uct::list assign
4710: 20 5b 24 63 73 65 74 20 64 61 74 61 5d 20 70 72   [$cset data] pr
4720: 6f 6a 65 63 74 20 63 73 74 79 70 65 20 63 73 73  oject cstype css
4730: 72 63 0a 0a 09 73 65 74 20 70 72 65 64 65 63 65  rc...set predece
4740: 73 73 6f 72 73 20 5b 24 63 73 65 74 20 64 72 6f  ssors [$cset dro
4750: 70 5d 0a 09 24 63 73 65 74 20 64 65 73 74 72 6f  p]..$cset destro
4760: 79 0a 0a 09 73 65 74 20 6e 65 77 63 73 65 74 73  y...set newcsets
4770: 20 7b 7d 0a 09 66 6f 72 65 61 63 68 20 66 72 61   {}..foreach fra
4780: 67 6d 65 6e 74 69 74 65 6d 73 20 24 61 72 67 73  gmentitems $args
4790: 20 7b 0a 09 20 20 20 20 6c 6f 67 20 77 72 69 74   {..    log writ
47a0: 65 20 38 20 63 73 65 74 73 20 7b 4d 41 4b 45 3a  e 8 csets {MAKE:
47b0: 20 5b 6c 73 6f 72 74 20 24 66 72 61 67 6d 65 6e   [lsort $fragmen
47c0: 74 69 74 65 6d 73 5d 7d 0a 0a 09 20 20 20 20 73  titems]}...    s
47d0: 65 74 20 66 72 61 67 6d 65 6e 74 20 5b 24 74 79  et fragment [$ty
47e0: 70 65 20 25 41 55 54 4f 25 20 24 70 72 6f 6a 65  pe %AUTO% $proje
47f0: 63 74 20 24 63 73 74 79 70 65 20 24 63 73 73 72  ct $cstype $cssr
4800: 63 20 5c 0a 09 09 09 20 20 20 20 20 20 5b 55 6e  c \....      [Un
4810: 74 61 67 20 24 66 72 61 67 6d 65 6e 74 69 74 65  tag $fragmentite
4820: 6d 73 20 24 63 73 74 79 70 65 5d 5d 0a 09 20 20  ms $cstype]]..  
4830: 20 20 6c 61 70 70 65 6e 64 20 6e 65 77 63 73 65    lappend newcse
4840: 74 73 20 24 66 72 61 67 6d 65 6e 74 0a 0a 09 20  ts $fragment... 
4850: 20 20 20 24 66 72 61 67 6d 65 6e 74 20 70 65 72     $fragment per
4860: 73 69 73 74 0a 09 20 20 20 20 24 66 72 61 67 6d  sist..    $fragm
4870: 65 6e 74 20 64 65 74 65 72 6d 69 6e 65 73 75 63  ent determinesuc
4880: 63 65 73 73 6f 72 73 0a 09 7d 0a 0a 09 23 20 54  cessors..}...# T
4890: 68 65 20 70 72 65 64 65 63 65 73 73 6f 72 73 20  he predecessors 
48a0: 68 61 76 65 20 74 6f 20 72 65 63 6f 6d 70 75 74  have to recomput
48b0: 65 20 74 68 65 69 72 20 73 75 63 63 65 73 73 6f  e their successo
48c0: 72 73 2c 20 69 2e 65 2e 0a 09 23 20 72 65 6d 6f  rs, i.e...# remo
48d0: 76 65 20 74 68 65 20 64 72 6f 70 70 65 64 20 63  ve the dropped c
48e0: 68 61 6e 67 65 73 65 74 20 61 6e 64 20 70 75 74  hangeset and put
48f0: 20 6f 6e 65 20 6f 66 20 74 68 65 20 66 72 61 67   one of the frag
4900: 6d 65 6e 74 73 0a 09 23 20 69 6e 74 6f 20 69 74  ments..# into it
4910: 73 20 70 6c 61 63 65 2e 0a 09 66 6f 72 65 61 63  s place...foreac
4920: 68 20 70 20 24 70 72 65 64 65 63 65 73 73 6f 72  h p $predecessor
4930: 73 20 7b 0a 09 20 20 20 20 24 70 20 64 65 74 65  s {..    $p dete
4940: 72 6d 69 6e 65 73 75 63 63 65 73 73 6f 72 73 0a  rminesuccessors.
4950: 09 7d 0a 0a 09 72 65 74 75 72 6e 20 24 6e 65 77  .}...return $new
4960: 63 73 65 74 73 0a 20 20 20 20 7d 0a 0a 20 20 20  csets.    }..   
4970: 20 74 79 70 65 6d 65 74 68 6f 64 20 69 74 65 6d   typemethod item
4980: 73 74 72 20 7b 69 74 65 6d 7d 20 7b 0a 09 73 74  str {item} {..st
4990: 72 75 63 74 3a 3a 6c 69 73 74 20 61 73 73 69 67  ruct::list assig
49a0: 6e 20 24 69 74 65 6d 20 69 74 79 70 65 20 69 69  n $item itype ii
49b0: 64 0a 09 72 65 74 75 72 6e 20 5b 24 69 74 79 70  d..return [$ityp
49c0: 65 20 73 74 72 20 24 69 69 64 5d 0a 20 20 20 20  e str $iid].    
49d0: 7d 0a 0a 20 20 20 20 74 79 70 65 6d 65 74 68 6f  }..    typemetho
49e0: 64 20 73 74 72 6c 69 73 74 20 7b 63 68 61 6e 67  d strlist {chang
49f0: 65 73 65 74 73 7d 20 7b 0a 09 72 65 74 75 72 6e  esets} {..return
4a00: 20 5b 6a 6f 69 6e 20 5b 73 74 72 75 63 74 3a 3a   [join [struct::
4a10: 6c 69 73 74 20 6d 61 70 20 24 63 68 61 6e 67 65  list map $change
4a20: 73 65 74 73 20 5b 6d 79 70 72 6f 63 20 49 44 5d  sets [myproc ID]
4a30: 5d 5d 0a 20 20 20 20 7d 0a 0a 20 20 20 20 70 72  ]].    }..    pr
4a40: 6f 63 20 49 44 20 7b 63 73 65 74 7d 20 7b 20 24  oc ID {cset} { $
4a50: 63 73 65 74 20 73 74 72 20 7d 0a 0a 20 20 20 20  cset str }..    
4a60: 70 72 6f 63 20 55 6e 74 61 67 20 7b 74 61 67 67  proc Untag {tagg
4a70: 65 64 69 74 65 6d 73 20 63 73 74 79 70 65 7d 20  editems cstype} 
4a80: 7b 0a 09 72 65 74 75 72 6e 20 5b 73 74 72 75 63  {..return [struc
4a90: 74 3a 3a 6c 69 73 74 20 6d 61 70 20 24 74 61 67  t::list map $tag
4aa0: 67 65 64 69 74 65 6d 73 20 5b 6d 79 70 72 6f 63  geditems [myproc
4ab0: 20 55 6e 74 61 67 31 20 24 63 73 74 79 70 65 5d   Untag1 $cstype]
4ac0: 5d 0a 20 20 20 20 7d 0a 0a 20 20 20 20 70 72 6f  ].    }..    pro
4ad0: 63 20 55 6e 74 61 67 31 20 7b 63 73 74 79 70 65  c Untag1 {cstype
4ae0: 20 74 68 65 69 74 65 6d 7d 20 7b 0a 09 73 74 72   theitem} {..str
4af0: 75 63 74 3a 3a 6c 69 73 74 20 61 73 73 69 67 6e  uct::list assign
4b00: 20 24 74 68 65 69 74 65 6d 20 74 20 69 0a 09 69   $theitem t i..i
4b10: 6e 74 65 67 72 69 74 79 20 61 73 73 65 72 74 20  ntegrity assert 
4b20: 7b 24 63 73 74 79 70 65 20 65 71 20 24 74 7d 20  {$cstype eq $t} 
4b30: 7b 49 74 65 6d 20 24 69 27 73 20 74 79 70 65 20  {Item $i's type 
4b40: 69 73 20 27 24 74 27 2c 20 65 78 70 65 63 74 65  is '$t', expecte
4b50: 64 20 27 24 63 73 74 79 70 65 27 7d 0a 09 72 65  d '$cstype'}..re
4b60: 74 75 72 6e 20 24 69 0a 20 20 20 20 7d 0a 0a 20  turn $i.    }.. 
4b70: 20 20 20 70 72 6f 63 20 54 61 67 49 74 65 6d 44     proc TagItemD
4b80: 69 63 74 20 7b 69 74 65 6d 64 69 63 74 20 63 73  ict {itemdict cs
4b90: 74 79 70 65 7d 20 7b 0a 09 73 65 74 20 72 65 73  type} {..set res
4ba0: 20 7b 7d 0a 09 66 6f 72 65 61 63 68 20 7b 69 20   {}..foreach {i 
4bb0: 76 7d 20 24 69 74 65 6d 64 69 63 74 20 7b 20 6c  v} $itemdict { l
4bc0: 61 70 70 65 6e 64 20 72 65 73 20 5b 6c 69 73 74  append res [list
4bd0: 20 24 63 73 74 79 70 65 20 24 69 5d 20 24 76 20   $cstype $i] $v 
4be0: 7d 0a 09 72 65 74 75 72 6e 20 24 72 65 73 0a 20  }..return $res. 
4bf0: 20 20 20 7d 0a 0a 20 20 20 20 70 72 6f 63 20 56     }..    proc V
4c00: 61 6c 69 64 61 74 65 46 72 61 67 6d 65 6e 74 73  alidateFragments
4c10: 20 7b 63 73 65 74 20 66 72 61 67 6d 65 6e 74 73   {cset fragments
4c20: 7d 20 7b 0a 09 23 20 43 68 65 63 6b 20 74 68 65  } {..# Check the
4c30: 20 76 61 72 69 6f 75 73 20 69 6e 74 65 67 72 69   various integri
4c40: 74 79 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 66  ty constraints f
4c50: 6f 72 20 74 68 65 20 66 72 61 67 6d 65 6e 74 73  or the fragments
4c60: 0a 09 23 20 73 70 65 63 69 66 79 69 6e 67 20 68  ..# specifying h
4c70: 6f 77 20 74 6f 20 73 70 6c 69 74 20 74 68 65 20  ow to split the 
4c80: 63 68 61 6e 67 65 73 65 74 3a 0a 09 23 0a 09 23  changeset:..#..#
4c90: 20 2a 20 57 65 20 6d 75 73 74 20 68 61 76 65 20   * We must have 
4ca0: 74 77 6f 20 6f 72 20 6d 6f 72 65 20 66 72 61 67  two or more frag
4cb0: 6d 65 6e 74 73 2c 20 61 73 20 73 70 6c 69 74 74  ments, as splitt
4cc0: 69 6e 67 20 61 0a 09 23 20 20 20 63 68 61 6e 67  ing a..#   chang
4cd0: 65 73 65 74 20 69 6e 74 6f 20 6f 6e 65 20 6d 61  eset into one ma
4ce0: 6b 65 73 20 6e 6f 20 73 65 6e 73 65 2e 0a 09 23  kes no sense...#
4cf0: 20 2a 20 4e 6f 20 66 72 61 67 6d 65 6e 74 20 6d   * No fragment m
4d00: 61 79 20 62 65 20 65 6d 70 74 79 2e 0a 09 23 20  ay be empty...# 
4d10: 2a 20 41 6c 6c 20 66 72 61 67 6d 65 6e 74 73 20  * All fragments 
4d20: 68 61 76 65 20 74 6f 20 62 65 20 74 72 75 65 20  have to be true 
4d30: 73 75 62 73 65 74 73 20 6f 66 20 74 68 65 20 69  subsets of the i
4d40: 74 65 6d 73 20 69 6e 20 74 68 65 0a 09 23 20 20  tems in the..#  
4d50: 20 63 68 61 6e 67 65 73 65 74 20 74 6f 20 73 70   changeset to sp
4d60: 6c 69 74 2e 20 54 68 65 20 27 74 72 75 65 27 20  lit. The 'true' 
4d70: 69 73 20 69 6d 70 6c 69 65 64 20 62 65 63 61 75  is implied becau
4d80: 73 65 20 6e 6f 6e 65 20 61 72 65 0a 09 23 20 20  se none are..#  
4d90: 20 61 6c 6c 6f 77 65 64 20 74 6f 20 62 65 20 65   allowed to be e
4da0: 6d 70 74 79 2c 20 73 6f 20 65 61 63 68 20 68 61  mpty, so each ha
4db0: 73 20 74 6f 20 62 65 20 73 6d 61 6c 6c 65 72 20  s to be smaller 
4dc0: 74 68 61 6e 20 74 68 65 0a 09 23 20 20 20 74 6f  than the..#   to
4dd0: 74 61 6c 2e 0a 09 23 20 2a 20 54 68 65 20 75 6e  tal...# * The un
4de0: 69 6f 6e 20 6f 66 20 74 68 65 20 66 72 61 67 6d  ion of the fragm
4df0: 65 6e 74 73 20 68 61 73 20 74 6f 20 62 65 20 74  ents has to be t
4e00: 68 65 20 69 74 65 6d 20 73 65 74 20 6f 66 20 74  he item set of t
4e10: 68 65 0a 09 23 20 20 20 63 68 61 6e 67 65 73 65  he..#   changese
4e20: 74 2e 0a 09 23 20 2a 20 54 68 65 20 66 72 61 67  t...# * The frag
4e30: 6d 65 6e 74 20 6d 75 73 74 20 6e 6f 74 20 6f 76  ment must not ov
4e40: 65 72 6c 61 70 2c 20 69 2e 65 2e 20 74 68 65 69  erlap, i.e. thei
4e50: 72 20 70 61 69 72 77 69 73 65 0a 09 23 20 20 20  r pairwise..#   
4e60: 69 6e 74 65 72 73 65 63 74 69 6f 6e 73 20 68 61  intersections ha
4e70: 76 65 20 74 6f 20 62 65 20 65 6d 70 74 79 2e 0a  ve to be empty..
4e80: 0a 09 73 65 74 20 63 6f 76 65 72 20 7b 7d 0a 09  ..set cover {}..
4e90: 66 6f 72 65 61 63 68 20 66 72 61 67 6d 65 6e 74  foreach fragment
4ea0: 69 74 65 6d 73 20 24 66 72 61 67 6d 65 6e 74 73  items $fragments
4eb0: 20 7b 0a 09 20 20 20 20 6c 6f 67 20 77 72 69 74   {..    log writ
4ec0: 65 20 38 20 63 73 65 74 73 20 7b 4e 45 57 3a 20  e 8 csets {NEW: 
4ed0: 5b 6c 73 6f 72 74 20 24 66 72 61 67 6d 65 6e 74  [lsort $fragment
4ee0: 69 74 65 6d 73 5d 7d 0a 0a 09 20 20 20 20 69 6e  items]}...    in
4ef0: 74 65 67 72 69 74 79 20 61 73 73 65 72 74 20 7b  tegrity assert {
4f00: 0a 09 09 21 5b 73 74 72 75 63 74 3a 3a 73 65 74  ...![struct::set
4f10: 20 65 6d 70 74 79 20 24 66 72 61 67 6d 65 6e 74   empty $fragment
4f20: 69 74 65 6d 73 5d 0a 09 20 20 20 20 7d 20 7b 63  items]..    } {c
4f30: 68 61 6e 67 65 73 65 74 20 66 72 61 67 6d 65 6e  hangeset fragmen
4f40: 74 20 69 73 20 65 6d 70 74 79 7d 0a 0a 09 20 20  t is empty}...  
4f50: 20 20 69 6e 74 65 67 72 69 74 79 20 61 73 73 65    integrity asse
4f60: 72 74 20 7b 0a 09 09 5b 73 74 72 75 63 74 3a 3a  rt {...[struct::
4f70: 73 65 74 20 73 75 62 73 65 74 6f 66 20 24 66 72  set subsetof $fr
4f80: 61 67 6d 65 6e 74 69 74 65 6d 73 20 5b 24 63 73  agmentitems [$cs
4f90: 65 74 20 69 74 65 6d 73 5d 5d 0a 09 20 20 20 20  et items]]..    
4fa0: 7d 20 7b 63 68 61 6e 67 65 73 65 74 20 66 72 61  } {changeset fra
4fb0: 67 6d 65 6e 74 20 69 73 20 6e 6f 74 20 61 20 73  gment is not a s
4fc0: 75 62 73 65 74 7d 0a 09 20 20 20 20 73 74 72 75  ubset}..    stru
4fd0: 63 74 3a 3a 73 65 74 20 61 64 64 20 63 6f 76 65  ct::set add cove
4fe0: 72 20 24 66 72 61 67 6d 65 6e 74 69 74 65 6d 73  r $fragmentitems
4ff0: 0a 09 7d 0a 0a 09 69 6e 74 65 67 72 69 74 79 20  ..}...integrity 
5000: 61 73 73 65 72 74 20 7b 0a 09 20 20 20 20 5b 73  assert {..    [s
5010: 74 72 75 63 74 3a 3a 73 65 74 20 65 71 75 61 6c  truct::set equal
5020: 20 24 63 6f 76 65 72 20 5b 24 63 73 65 74 20 69   $cover [$cset i
5030: 74 65 6d 73 5d 5d 0a 09 20 7d 20 7b 54 68 65 20  tems]].. } {The 
5040: 66 72 61 67 6d 65 6e 74 73 20 64 6f 20 6e 6f 74  fragments do not
5050: 20 63 6f 76 65 72 20 74 68 65 20 6f 72 69 67 69   cover the origi
5060: 6e 61 6c 20 63 68 61 6e 67 65 73 65 74 7d 0a 0a  nal changeset}..
5070: 09 73 65 74 20 69 20 31 0a 09 66 6f 72 65 61 63  .set i 1..foreac
5080: 68 20 66 69 61 20 24 66 72 61 67 6d 65 6e 74 73  h fia $fragments
5090: 20 7b 0a 09 20 20 20 20 66 6f 72 65 61 63 68 20   {..    foreach 
50a0: 66 69 62 20 5b 6c 72 61 6e 67 65 20 24 66 72 61  fib [lrange $fra
50b0: 67 6d 65 6e 74 73 20 24 69 20 65 6e 64 5d 20 7b  gments $i end] {
50c0: 0a 09 09 69 6e 74 65 67 72 69 74 79 20 61 73 73  ...integrity ass
50d0: 65 72 74 20 7b 0a 09 09 20 20 20 20 5b 73 74 72  ert {...    [str
50e0: 75 63 74 3a 3a 73 65 74 20 65 6d 70 74 79 20 5b  uct::set empty [
50f0: 73 74 72 75 63 74 3a 3a 73 65 74 20 69 6e 74 65  struct::set inte
5100: 72 73 65 63 74 20 24 66 69 61 20 24 66 69 62 5d  rsect $fia $fib]
5110: 5d 0a 09 09 7d 20 7b 54 68 65 20 66 72 61 67 6d  ]...} {The fragm
5120: 65 6e 74 73 20 3c 24 66 69 61 3e 20 61 6e 64 20  ents <$fia> and 
5130: 3c 24 66 69 62 3e 20 6f 76 65 72 6c 61 70 7d 0a  <$fib> overlap}.
5140: 09 20 20 20 20 7d 0a 09 20 20 20 20 69 6e 63 72  .    }..    incr
5150: 20 69 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 0a 20   i..}...return. 
5160: 20 20 20 7d 0a 0a 20 20 20 20 23 20 23 20 23 23     }..    # # ##
5170: 20 23 23 23 20 23 23 23 23 23 20 23 23 23 23 23   ### ##### #####
5180: 23 23 23 20 23 23 23 23 23 23 23 23 23 23 23 23  ### ############
5190: 23 0a 20 20 20 20 23 23 20 53 74 61 74 65 0a 0a  #.    ## State..
51a0: 20 20 20 20 76 61 72 69 61 62 6c 65 20 6d 79 69      variable myi
51b0: 64 20 20 20 20 20 20 20 20 7b 7d 20 3b 20 23 20  d        {} ; # 
51c0: 49 64 20 6f 66 20 74 68 65 20 63 73 65 74 20 66  Id of the cset f
51d0: 6f 72 20 74 68 65 20 70 65 72 73 69 73 74 65 6e  or the persisten
51e0: 74 0a 09 09 09 20 20 20 20 20 20 23 20 73 74 61  t....      # sta
51f0: 74 65 2e 0a 20 20 20 20 76 61 72 69 61 62 6c 65  te..    variable
5200: 20 6d 79 70 72 6f 6a 65 63 74 20 20 20 7b 7d 20   myproject   {} 
5210: 3b 20 23 20 52 65 66 65 72 65 6e 63 65 20 6f 66  ; # Reference of
5220: 20 74 68 65 20 70 72 6f 6a 65 63 74 20 6f 62 6a   the project obj
5230: 65 63 74 20 74 68 65 0a 09 09 09 20 20 20 20 20  ect the....     
5240: 20 23 20 63 68 61 6e 67 65 73 65 74 20 62 65 6c   # changeset bel
5250: 6f 6e 67 73 20 74 6f 2e 0a 20 20 20 20 76 61 72  ongs to..    var
5260: 69 61 62 6c 65 20 6d 79 74 79 70 65 20 20 20 20  iable mytype    
5270: 20 20 7b 7d 20 3b 20 23 20 57 68 61 74 20 74 68    {} ; # What th
5280: 65 20 63 68 61 6e 67 65 73 65 74 20 69 73 20 62  e changeset is b
5290: 61 73 65 64 20 6f 6e 0a 09 09 09 20 20 20 20 20  ased on....     
52a0: 20 23 20 28 72 65 76 69 73 69 6f 6e 73 2c 20 74   # (revisions, t
52b0: 61 67 73 2c 20 6f 72 20 62 72 61 6e 63 68 65 73  ags, or branches
52c0: 29 2e 0a 09 09 09 20 20 20 20 20 20 23 20 56 61  ).....      # Va
52d0: 6c 75 65 73 3a 20 53 65 65 20 6d 79 63 73 74 79  lues: See mycsty
52e0: 70 65 2e 20 4e 6f 74 65 20 74 68 61 74 20 77 65  pe. Note that we
52f0: 0a 09 09 09 20 20 20 20 20 20 23 20 68 61 76 65  ....      # have
5300: 20 74 6f 20 6b 65 65 70 20 74 68 65 20 6e 61 6d   to keep the nam
5310: 65 73 20 6f 66 20 74 68 65 20 68 65 6c 70 65 72  es of the helper
5320: 0a 09 09 09 20 20 20 20 20 20 23 20 73 69 6e 67  ....      # sing
5330: 6c 65 74 6f 6e 73 20 69 6e 20 73 79 6e 63 20 77  letons in sync w
5340: 69 74 68 20 74 68 65 20 63 6f 6e 74 65 6e 74 73  ith the contents
5350: 0a 09 09 09 20 20 20 20 20 20 23 20 6f 66 20 73  ....      # of s
5360: 74 61 74 65 20 74 61 62 6c 65 20 27 63 73 74 79  tate table 'csty
5370: 70 65 27 2c 20 61 6e 64 20 76 61 72 69 6f 75 73  pe', and various
5380: 0a 09 09 09 20 20 20 20 20 20 23 20 6f 74 68 65  ....      # othe
5390: 72 20 70 6c 61 63 65 73 20 75 73 69 6e 67 20 74  r places using t
53a0: 68 65 6d 20 68 61 72 64 77 69 72 65 64 2e 0a 20  hem hardwired.. 
53b0: 20 20 20 76 61 72 69 61 62 6c 65 20 6d 79 74 79     variable myty
53c0: 70 65 6f 62 6a 20 20 20 7b 7d 20 3b 20 23 20 52  peobj   {} ; # R
53d0: 65 66 65 72 65 6e 63 65 20 74 6f 20 74 68 65 20  eference to the 
53e0: 63 6f 6e 74 61 69 6e 65 72 20 66 6f 72 20 74 68  container for th
53f0: 65 0a 09 09 09 20 20 20 20 20 20 23 20 74 79 70  e....      # typ
5400: 65 20 64 65 70 65 6e 64 65 6e 74 20 63 6f 64 65  e dependent code
5410: 2e 20 44 65 72 69 76 65 64 20 66 72 6f 6d 0a 09  . Derived from..
5420: 09 09 20 20 20 20 20 20 23 20 6d 79 74 79 70 65  ..      # mytype
5430: 2e 0a 20 20 20 20 76 61 72 69 61 62 6c 65 20 6d  ..    variable m
5440: 79 73 72 63 69 64 20 20 20 20 20 7b 7d 20 3b 20  ysrcid     {} ; 
5450: 23 20 49 64 20 6f 66 20 74 68 65 20 6d 65 74 61  # Id of the meta
5460: 64 61 74 61 20 6f 72 20 73 79 6d 62 6f 6c 20 74  data or symbol t
5470: 68 65 20 63 73 65 74 0a 09 09 09 20 20 20 20 20  he cset....     
5480: 20 23 20 69 73 20 62 61 73 65 64 20 6f 6e 2e 0a   # is based on..
5490: 20 20 20 20 76 61 72 69 61 62 6c 65 20 6d 79 69      variable myi
54a0: 74 65 6d 73 20 20 20 20 20 7b 7d 20 3b 20 23 20  tems     {} ; # 
54b0: 4c 69 73 74 20 6f 66 20 74 68 65 20 66 69 6c 65  List of the file
54c0: 20 6c 65 76 65 6c 20 72 65 76 69 73 69 6f 6e 73   level revisions
54d0: 2c 0a 09 09 09 20 20 20 20 20 20 23 20 74 61 67  ,....      # tag
54e0: 73 2c 20 6f 72 20 62 72 61 6e 63 68 65 73 20 69  s, or branches i
54f0: 6e 20 74 68 65 20 63 73 65 74 2c 20 61 73 0a 09  n the cset, as..
5500: 09 09 20 20 20 20 20 20 23 20 69 64 73 2e 20 4e  ..      # ids. N
5510: 6f 74 20 74 61 67 67 65 64 2e 0a 20 20 20 20 76  ot tagged..    v
5520: 61 72 69 61 62 6c 65 20 6d 79 74 69 74 65 6d 73  ariable mytitems
5530: 20 20 20 20 7b 7d 20 3b 20 23 20 41 73 20 6d 79      {} ; # As my
5540: 69 74 65 6d 73 2c 20 74 68 65 20 74 61 67 67 65  items, the tagge
5550: 64 20 66 6f 72 6d 2e 0a 20 20 20 20 76 61 72 69  d form..    vari
5560: 61 62 6c 65 20 6d 79 70 6f 73 20 20 20 20 20 20  able mypos      
5570: 20 7b 7d 20 3b 20 23 20 43 6f 6d 6d 69 74 20 70   {} ; # Commit p
5580: 6f 73 69 74 69 6f 6e 20 6f 66 20 74 68 65 20 63  osition of the c
5590: 68 61 6e 67 65 73 65 74 2c 20 69 66 0a 09 09 09  hangeset, if....
55a0: 20 20 20 20 20 20 23 20 6b 6e 6f 77 6e 2e 0a 0a        # known...
55b0: 20 20 20 20 23 20 23 20 23 23 20 23 23 23 20 23      # # ## ### #
55c0: 23 23 23 23 20 23 23 23 23 23 23 23 23 20 23 23  #### ######## ##
55d0: 23 23 23 23 23 23 23 23 23 23 23 0a 20 20 20 20  ###########.    
55e0: 23 23 20 49 6e 74 65 72 6e 61 6c 20 6d 65 74 68  ## Internal meth
55f0: 6f 64 73 0a 0a 20 20 20 20 74 79 70 65 76 61 72  ods..    typevar
5600: 69 61 62 6c 65 20 6d 79 63 6f 75 6e 74 65 72 20  iable mycounter 
5610: 20 20 20 20 20 20 20 30 20 3b 20 23 20 49 64 20         0 ; # Id 
5620: 63 6f 75 6e 74 65 72 20 66 6f 72 20 63 73 65 74  counter for cset
5630: 73 2e 20 4c 61 73 74 20 69 64 0a 09 09 09 09 20  s. Last id..... 
5640: 20 20 20 20 20 23 20 75 73 65 64 2e 0a 20 20 20       # used..   
5650: 20 74 79 70 65 76 61 72 69 61 62 6c 65 20 6d 79   typevariable my
5660: 63 73 74 79 70 65 20 2d 61 72 72 61 79 20 7b 7d  cstype -array {}
5670: 20 3b 20 23 20 4d 61 70 20 63 73 74 79 70 65 73   ; # Map cstypes
5680: 20 28 6e 61 6d 65 73 29 20 74 6f 20 70 65 72 73   (names) to pers
5690: 69 73 74 65 6e 74 0a 09 09 09 09 20 20 20 20 20  istent.....     
56a0: 20 23 20 69 64 73 2e 20 4e 6f 74 65 20 74 68 61   # ids. Note tha
56b0: 74 20 77 65 20 68 61 76 65 20 74 6f 20 6b 65 65  t we have to kee
56c0: 70 0a 09 09 09 09 20 20 20 20 20 20 23 20 74 68  p.....      # th
56d0: 65 20 6e 61 6d 65 73 20 69 6e 20 74 68 65 20 74  e names in the t
56e0: 61 62 6c 65 20 27 63 73 74 79 70 65 27 0a 09 09  able 'cstype'...
56f0: 09 09 20 20 20 20 20 20 23 20 69 6e 20 73 79 6e  ..      # in syn
5700: 63 20 77 69 74 68 20 74 68 65 20 6e 61 6d 65 73  c with the names
5710: 20 6f 66 20 74 68 65 0a 09 09 09 09 20 20 20 20   of the.....    
5720: 20 20 23 20 68 65 6c 70 65 72 20 73 69 6e 67 6c    # helper singl
5730: 65 74 6f 6e 73 2e 0a 0a 20 20 20 20 74 79 70 65  etons...    type
5740: 6d 65 74 68 6f 64 20 69 6e 6f 72 64 65 72 20 7b  method inorder {
5750: 70 72 6f 6a 65 63 74 69 64 7d 20 7b 0a 09 23 20  projectid} {..# 
5760: 52 65 74 75 72 6e 20 61 6c 6c 20 72 65 76 69 73  Return all revis
5770: 69 6f 6e 20 63 68 61 6e 67 65 73 65 74 73 20 66  ion changesets f
5780: 6f 72 20 74 68 65 20 73 70 65 63 69 66 69 65 64  or the specified
5790: 20 70 72 6f 6a 65 63 74 2c 20 69 6e 0a 09 23 20   project, in..# 
57a0: 74 68 65 20 6f 72 64 65 72 20 67 69 76 65 6e 20  the order given 
57b0: 74 6f 20 74 68 65 6d 20 62 79 20 74 68 65 20 73  to them by the s
57c0: 6f 72 74 20 70 61 73 73 65 73 2e 20 42 6f 74 68  ort passes. Both
57d0: 20 74 68 65 0a 09 23 20 66 69 6c 74 65 72 69 6e   the..# filterin
57e0: 67 20 62 79 20 70 72 6f 6a 65 63 74 20 61 6e 64  g by project and
57f0: 20 73 6f 72 74 69 6e 67 20 6d 61 6b 65 20 75 73   sorting make us
5800: 65 20 6f 66 20 27 70 72 6f 6a 65 63 74 3a 3a 72  e of 'project::r
5810: 65 76 0a 09 23 20 72 65 76 27 20 69 6d 70 6f 73  ev..# rev' impos
5820: 73 69 62 6c 65 2e 0a 0a 09 73 65 74 20 72 65 73  sible....set res
5830: 20 7b 7d 0a 09 66 6f 72 65 61 63 68 20 7b 63 69   {}..foreach {ci
5840: 64 20 63 64 61 74 65 7d 20 5b 73 74 61 74 65 20  d cdate} [state 
5850: 72 75 6e 20 7b 0a 09 20 20 20 20 53 45 4c 45 43  run {..    SELEC
5860: 54 20 43 2e 63 69 64 2c 20 54 2e 64 61 74 65 0a  T C.cid, T.date.
5870: 09 20 20 20 20 46 52 4f 4d 20 20 20 63 68 61 6e  .    FROM   chan
5880: 67 65 73 65 74 20 43 2c 20 63 73 74 69 6d 65 73  geset C, cstimes
5890: 74 61 6d 70 20 54 0a 09 20 20 20 20 57 48 45 52  tamp T..    WHER
58a0: 45 20 20 43 2e 74 79 70 65 20 3d 20 30 20 20 20  E  C.type = 0   
58b0: 20 20 20 20 20 20 20 2d 2d 20 6c 69 6d 69 74 20         -- limit 
58c0: 74 6f 20 72 65 76 69 73 69 6f 6e 20 63 68 61 6e  to revision chan
58d0: 67 65 73 65 74 73 0a 09 20 20 20 20 41 4e 44 20  gesets..    AND 
58e0: 20 20 20 43 2e 70 69 64 20 20 3d 20 24 70 72 6f     C.pid  = $pro
58f0: 6a 65 63 74 69 64 20 2d 2d 20 6c 69 6d 69 74 20  jectid -- limit 
5900: 74 6f 20 63 68 61 6e 67 65 73 65 74 73 20 69 6e  to changesets in
5910: 20 70 72 6f 6a 65 63 74 0a 09 20 20 20 20 41 4e   project..    AN
5920: 44 20 20 20 20 54 2e 63 69 64 20 20 3d 20 43 2e  D    T.cid  = C.
5930: 63 69 64 20 20 20 20 20 20 2d 2d 20 67 65 74 20  cid      -- get 
5940: 6f 72 64 65 72 69 6e 67 20 69 6e 66 6f 72 6d 61  ordering informa
5950: 74 69 6f 6e 0a 09 20 20 20 20 4f 52 44 45 52 20  tion..    ORDER 
5960: 42 59 20 54 2e 64 61 74 65 20 20 20 20 20 20 20  BY T.date       
5970: 20 20 20 20 20 2d 2d 20 73 6f 72 74 20 69 6e 74       -- sort int
5980: 6f 20 63 6f 6d 6d 69 74 20 6f 72 64 65 72 0a 09  o commit order..
5990: 7d 5d 20 7b 0a 09 20 20 20 20 6c 61 70 70 65 6e  }] {..    lappen
59a0: 64 20 72 65 73 20 24 6d 79 69 64 6d 61 70 28 24  d res $myidmap($
59b0: 63 69 64 29 20 24 63 64 61 74 65 0a 09 7d 0a 09  cid) $cdate..}..
59c0: 72 65 74 75 72 6e 20 24 72 65 73 0a 20 20 20 20  return $res.    
59d0: 7d 0a 0a 20 20 20 20 74 79 70 65 6d 65 74 68 6f  }..    typemetho
59e0: 64 20 67 65 74 63 73 74 79 70 65 73 20 7b 7d 20  d getcstypes {} 
59f0: 7b 0a 09 66 6f 72 65 61 63 68 20 7b 74 69 64 20  {..foreach {tid 
5a00: 6e 61 6d 65 7d 20 5b 73 74 61 74 65 20 72 75 6e  name} [state run
5a10: 20 7b 0a 09 20 20 20 20 53 45 4c 45 43 54 20 74   {..    SELECT t
5a20: 69 64 2c 20 6e 61 6d 65 20 46 52 4f 4d 20 63 73  id, name FROM cs
5a30: 74 79 70 65 3b 0a 09 7d 5d 20 7b 20 73 65 74 20  type;..}] { set 
5a40: 6d 79 63 73 74 79 70 65 28 24 6e 61 6d 65 29 20  mycstype($name) 
5a50: 24 74 69 64 20 7d 0a 09 72 65 74 75 72 6e 0a 20  $tid }..return. 
5a60: 20 20 20 7d 0a 0a 20 20 20 20 74 79 70 65 6d 65     }..    typeme
5a70: 74 68 6f 64 20 6c 6f 61 64 20 7b 72 65 70 6f 73  thod load {repos
5a80: 69 74 6f 72 79 7d 20 7b 0a 09 73 65 74 20 6e 20  itory} {..set n 
5a90: 30 0a 09 6c 6f 67 20 77 72 69 74 65 20 32 20 63  0..log write 2 c
5aa0: 73 65 74 73 20 7b 4c 6f 61 64 69 6e 67 20 74 68  sets {Loading th
5ab0: 65 20 63 68 61 6e 67 65 73 65 74 73 7d 0a 09 66  e changesets}..f
5ac0: 6f 72 65 61 63 68 20 7b 69 64 20 70 69 64 20 63  oreach {id pid c
5ad0: 73 74 79 70 65 20 73 72 63 69 64 7d 20 5b 73 74  stype srcid} [st
5ae0: 61 74 65 20 72 75 6e 20 7b 0a 09 20 20 20 20 53  ate run {..    S
5af0: 45 4c 45 43 54 20 43 2e 63 69 64 2c 20 43 2e 70  ELECT C.cid, C.p
5b00: 69 64 2c 20 43 53 2e 6e 61 6d 65 2c 20 43 2e 73  id, CS.name, C.s
5b10: 72 63 0a 09 20 20 20 20 46 52 4f 4d 20 20 20 63  rc..    FROM   c
5b20: 68 61 6e 67 65 73 65 74 20 43 2c 20 63 73 74 79  hangeset C, csty
5b30: 70 65 20 43 53 0a 09 20 20 20 20 57 48 45 52 45  pe CS..    WHERE
5b40: 20 20 43 2e 74 79 70 65 20 3d 20 43 53 2e 74 69    C.type = CS.ti
5b50: 64 0a 09 20 20 20 20 4f 52 44 45 52 20 42 59 20  d..    ORDER BY 
5b60: 43 2e 63 69 64 0a 09 7d 5d 20 7b 0a 09 20 20 20  C.cid..}] {..   
5b70: 20 6c 6f 67 20 70 72 6f 67 72 65 73 73 20 32 20   log progress 2 
5b80: 63 73 65 74 73 20 24 6e 20 7b 7d 0a 09 20 20 20  csets $n {}..   
5b90: 20 73 65 74 20 72 20 5b 24 74 79 70 65 20 25 41   set r [$type %A
5ba0: 55 54 4f 25 20 5b 24 72 65 70 6f 73 69 74 6f 72  UTO% [$repositor
5bb0: 79 20 70 72 6f 6a 65 63 74 6f 66 20 24 70 69 64  y projectof $pid
5bc0: 5d 20 24 63 73 74 79 70 65 20 24 73 72 63 69 64  ] $cstype $srcid
5bd0: 20 5b 73 74 61 74 65 20 72 75 6e 20 7b 0a 09 09   [state run {...
5be0: 53 45 4c 45 43 54 20 43 2e 69 69 64 0a 09 09 46  SELECT C.iid...F
5bf0: 52 4f 4d 20 20 20 63 73 69 74 65 6d 20 43 0a 09  ROM   csitem C..
5c00: 09 57 48 45 52 45 20 20 43 2e 63 69 64 20 3d 20  .WHERE  C.cid = 
5c10: 24 69 64 0a 09 09 4f 52 44 45 52 20 42 59 20 43  $id...ORDER BY C
5c20: 2e 70 6f 73 0a 09 20 20 20 20 7d 5d 20 24 69 64  .pos..    }] $id
5c30: 5d 0a 09 20 20 20 20 69 6e 63 72 20 6e 0a 09 7d  ]..    incr n..}
5c40: 0a 09 72 65 74 75 72 6e 0a 20 20 20 20 7d 0a 0a  ..return.    }..
5c50: 20 20 20 20 74 79 70 65 6d 65 74 68 6f 64 20 6c      typemethod l
5c60: 6f 61 64 63 6f 75 6e 74 65 72 20 7b 7d 20 7b 0a  oadcounter {} {.
5c70: 09 23 20 49 6e 69 74 69 61 6c 69 7a 65 20 74 68  .# Initialize th
5c80: 65 20 63 6f 75 6e 74 65 72 20 66 72 6f 6d 20 74  e counter from t
5c90: 68 65 20 73 74 61 74 65 0a 09 6c 6f 67 20 77 72  he state..log wr
5ca0: 69 74 65 20 32 20 63 73 65 74 73 20 7b 4c 6f 61  ite 2 csets {Loa
5cb0: 64 69 6e 67 20 63 68 61 6e 67 65 73 65 74 20 63  ding changeset c
5cc0: 6f 75 6e 74 65 72 7d 0a 09 73 65 74 20 6d 79 63  ounter}..set myc
5cd0: 6f 75 6e 74 65 72 20 5b 73 74 61 74 65 20 6f 6e  ounter [state on
5ce0: 65 20 7b 20 53 45 4c 45 43 54 20 4d 41 58 28 63  e { SELECT MAX(c
5cf0: 69 64 29 20 46 52 4f 4d 20 63 68 61 6e 67 65 73  id) FROM changes
5d00: 65 74 20 7d 5d 0a 09 72 65 74 75 72 6e 0a 20 20  et }]..return.  
5d10: 20 20 7d 0a 0a 20 20 20 20 74 79 70 65 6d 65 74    }..    typemet
5d20: 68 6f 64 20 6e 75 6d 20 7b 7d 20 7b 20 72 65 74  hod num {} { ret
5d30: 75 72 6e 20 24 6d 79 63 6f 75 6e 74 65 72 20 7d  urn $mycounter }
5d40: 0a 0a 20 20 20 20 70 72 6f 63 20 49 6e 69 74 69  ..    proc Initi
5d50: 61 6c 69 7a 65 42 72 65 61 6b 53 74 61 74 65 20  alizeBreakState 
5d60: 7b 72 65 76 69 73 69 6f 6e 73 7d 20 7b 0a 09 75  {revisions} {..u
5d70: 70 76 61 72 20 31 20 70 6f 73 20 70 6f 73 20 63  pvar 1 pos pos c
5d80: 72 6f 73 73 20 63 72 6f 73 73 20 72 61 6e 67 65  ross cross range
5d90: 20 72 61 6e 67 65 20 64 65 70 63 20 64 65 70 63   range depc depc
5da0: 20 64 65 6c 74 61 20 64 65 6c 74 61 20 5c 0a 09   delta delta \..
5db0: 20 20 20 20 64 65 70 65 6e 64 65 6e 63 69 65 73      dependencies
5dc0: 20 64 65 70 65 6e 64 65 6e 63 69 65 73 0a 0a 09   dependencies...
5dd0: 23 20 46 69 72 73 74 20 77 65 20 63 72 65 61 74  # First we creat
5de0: 65 20 61 20 6d 61 70 20 6f 66 20 70 6f 73 69 74  e a map of posit
5df0: 69 6f 6e 73 20 74 6f 20 6d 61 6b 65 20 69 74 20  ions to make it 
5e00: 65 61 73 69 65 72 20 74 6f 0a 09 23 20 64 65 74  easier to..# det
5e10: 65 72 6d 69 6e 65 20 77 68 65 74 68 65 72 20 61  ermine whether a
5e20: 20 64 65 70 65 6e 64 65 6e 63 79 20 63 72 6f 73   dependency cros
5e30: 73 65 73 20 61 20 70 61 72 74 69 63 75 6c 61 72  ses a particular
5e40: 20 69 6e 64 65 78 2e 0a 0a 09 61 72 72 61 79 20   index....array 
5e50: 73 65 74 20 70 6f 73 20 20 20 7b 7d 0a 09 61 72  set pos   {}..ar
5e60: 72 61 79 20 73 65 74 20 63 72 6f 73 73 20 7b 7d  ray set cross {}
5e70: 0a 09 61 72 72 61 79 20 73 65 74 20 64 65 70 63  ..array set depc
5e80: 20 20 7b 7d 0a 09 73 65 74 20 72 61 6e 67 65 20    {}..set range 
5e90: 20 20 20 20 20 20 7b 7d 0a 09 73 65 74 20 6e 20        {}..set n 
5ea0: 30 0a 09 66 6f 72 65 61 63 68 20 72 65 76 20 24  0..foreach rev $
5eb0: 72 65 76 69 73 69 6f 6e 73 20 7b 0a 09 20 20 20  revisions {..   
5ec0: 20 6c 61 70 70 65 6e 64 20 72 61 6e 67 65 20 24   lappend range $
5ed0: 6e 0a 09 20 20 20 20 73 65 74 20 70 6f 73 28 24  n..    set pos($
5ee0: 72 65 76 29 20 24 6e 0a 09 20 20 20 20 73 65 74  rev) $n..    set
5ef0: 20 63 72 6f 73 73 28 24 6e 29 20 30 0a 09 20 20   cross($n) 0..  
5f00: 20 20 69 6e 63 72 20 6e 0a 09 7d 0a 0a 09 23 20    incr n..}...# 
5f10: 53 65 63 6f 6e 64 6c 79 20 77 65 20 63 6f 75 6e  Secondly we coun
5f20: 74 20 74 68 65 20 63 72 6f 73 73 69 6e 67 73 20  t the crossings 
5f30: 70 65 72 20 70 6f 73 69 74 69 6f 6e 2c 20 62 79  per position, by
5f40: 20 69 74 65 72 61 74 69 6e 67 0a 09 23 20 6f 76   iterating..# ov
5f50: 65 72 20 74 68 65 20 72 65 63 6f 72 64 65 64 20  er the recorded 
5f60: 69 6e 74 65 72 6e 61 6c 20 64 65 70 65 6e 64 65  internal depende
5f70: 6e 63 69 65 73 2e 0a 0a 09 23 20 4e 6f 74 65 3a  ncies....# Note:
5f80: 20 49 66 20 74 68 65 20 74 69 6d 65 73 74 61 6d   If the timestam
5f90: 70 73 20 61 72 65 20 62 61 64 6c 79 20 6f 75 74  ps are badly out
5fa0: 20 6f 66 20 6f 72 64 65 72 20 69 74 20 69 73 0a   of order it is.
5fb0: 09 23 20 20 20 20 20 20 20 70 6f 73 73 69 62 6c  .#       possibl
5fc0: 65 20 74 6f 20 68 61 76 65 20 61 20 62 61 63 6b  e to have a back
5fd0: 77 61 72 64 20 73 75 63 63 65 73 73 6f 72 20 64  ward successor d
5fe0: 65 70 65 6e 64 65 6e 63 79 2c 0a 09 23 20 20 20  ependency,..#   
5ff0: 20 20 20 20 69 2e 65 2e 20 77 69 74 68 20 73 74      i.e. with st
6000: 61 72 74 20 3e 20 65 6e 64 2e 20 57 65 20 6d 61  art > end. We ma
6010: 79 20 68 61 76 65 20 74 6f 20 73 77 61 70 20 74  y have to swap t
6020: 68 65 20 69 6e 64 69 63 65 73 0a 09 23 20 20 20  he indices..#   
6030: 20 20 20 20 74 6f 20 65 6e 73 75 72 65 20 74 68      to ensure th
6040: 61 74 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67  at the following
6050: 20 6c 6f 6f 70 20 72 75 6e 73 20 63 6f 72 72 65   loop runs corre
6060: 63 74 6c 79 2e 0a 09 23 0a 09 23 20 4e 6f 74 65  ctly...#..# Note
6070: 20 32 3a 20 73 74 61 72 74 20 3d 3d 20 65 6e 64   2: start == end
6080: 20 69 73 20 6e 6f 74 20 70 6f 73 73 69 62 6c 65   is not possible
6090: 2e 20 49 74 20 69 6e 64 69 63 61 74 65 73 20 61  . It indicates a
60a0: 0a 09 23 20 20 20 20 20 20 20 20 20 73 65 6c 66  ..#         self
60b0: 2d 64 65 70 65 6e 64 65 6e 63 79 20 64 75 65 20  -dependency due 
60c0: 74 6f 20 74 68 65 20 75 6e 69 71 75 65 6e 65 73  to the uniquenes
60d0: 73 20 6f 66 20 70 6f 73 69 74 69 6f 6e 73 2c 0a  s of positions,.
60e0: 09 23 20 20 20 20 20 20 20 20 20 61 6e 64 20 74  .#         and t
60f0: 68 61 74 20 69 73 20 73 6f 6d 65 74 68 69 6e 67  hat is something
6100: 20 77 65 20 68 61 76 65 20 72 75 6c 65 64 20 6f   we have ruled o
6110: 75 74 20 61 6c 72 65 61 64 79 2c 20 73 65 65 0a  ut already, see.
6120: 09 23 20 20 20 20 20 20 20 20 20 27 72 65 76 20  .#         'rev 
6130: 69 6e 74 65 72 6e 61 6c 73 75 63 63 65 73 73 6f  internalsuccesso
6140: 72 73 27 2e 0a 0a 09 66 6f 72 65 61 63 68 20 7b  rs'....foreach {
6150: 72 69 64 20 63 68 69 6c 64 72 65 6e 7d 20 5b 61  rid children} [a
6160: 72 72 61 79 20 67 65 74 20 64 65 70 65 6e 64 65  rray get depende
6170: 6e 63 69 65 73 5d 20 7b 0a 09 20 20 20 20 66 6f  ncies] {..    fo
6180: 72 65 61 63 68 20 63 68 69 6c 64 20 24 63 68 69  reach child $chi
6190: 6c 64 72 65 6e 20 7b 0a 09 09 73 65 74 20 64 6b  ldren {...set dk
61a0: 65 79 20 20 20 20 5b 6c 69 73 74 20 24 72 69 64  ey    [list $rid
61b0: 20 24 63 68 69 6c 64 5d 0a 09 09 73 65 74 20 73   $child]...set s
61c0: 74 61 72 74 20 20 20 24 70 6f 73 28 24 72 69 64  tart   $pos($rid
61d0: 29 0a 09 09 73 65 74 20 65 6e 64 20 20 20 20 20  )...set end     
61e0: 24 70 6f 73 28 24 63 68 69 6c 64 29 0a 09 09 73  $pos($child)...s
61f0: 65 74 20 63 72 6f 73 73 65 73 20 7b 7d 0a 0a 09  et crosses {}...
6200: 09 69 66 20 7b 24 73 74 61 72 74 20 3e 20 24 65  .if {$start > $e
6210: 6e 64 7d 20 7b 0a 09 09 20 20 20 20 77 68 69 6c  nd} {...    whil
6220: 65 20 7b 24 65 6e 64 20 3c 20 24 73 74 61 72 74  e {$end < $start
6230: 7d 20 7b 0a 09 09 09 6c 61 70 70 65 6e 64 20 63  } {....lappend c
6240: 72 6f 73 73 65 73 20 24 65 6e 64 0a 09 09 09 69  rosses $end....i
6250: 6e 63 72 20 63 72 6f 73 73 28 24 65 6e 64 29 0a  ncr cross($end).
6260: 09 09 09 69 6e 63 72 20 65 6e 64 0a 09 09 20 20  ...incr end...  
6270: 20 20 7d 0a 09 09 7d 20 65 6c 73 65 20 7b 0a 09    }...} else {..
6280: 09 20 20 20 20 77 68 69 6c 65 20 7b 24 73 74 61  .    while {$sta
6290: 72 74 20 3c 20 24 65 6e 64 7d 20 7b 0a 09 09 09  rt < $end} {....
62a0: 6c 61 70 70 65 6e 64 20 63 72 6f 73 73 65 73 20  lappend crosses 
62b0: 24 73 74 61 72 74 0a 09 09 09 69 6e 63 72 20 63  $start....incr c
62c0: 72 6f 73 73 28 24 73 74 61 72 74 29 0a 09 09 09  ross($start)....
62d0: 69 6e 63 72 20 73 74 61 72 74 0a 09 09 20 20 20  incr start...   
62e0: 20 7d 0a 09 09 7d 0a 09 09 73 65 74 20 64 65 70   }...}...set dep
62f0: 63 28 24 64 6b 65 79 29 20 24 63 72 6f 73 73 65  c($dkey) $crosse
6300: 73 0a 09 20 20 20 20 7d 0a 09 7d 0a 0a 09 49 6e  s..    }..}...In
6310: 69 74 69 61 6c 69 7a 65 44 65 6c 74 61 73 20 24  itializeDeltas $
6320: 72 65 76 69 73 69 6f 6e 73 0a 09 72 65 74 75 72  revisions..retur
6330: 6e 0a 20 20 20 20 7d 0a 0a 20 20 20 20 70 72 6f  n.    }..    pro
6340: 63 20 49 6e 69 74 69 61 6c 69 7a 65 44 65 6c 74  c InitializeDelt
6350: 61 73 20 7b 72 65 76 69 73 69 6f 6e 73 7d 20 7b  as {revisions} {
6360: 0a 09 75 70 76 61 72 20 31 20 64 65 6c 74 61 20  ..upvar 1 delta 
6370: 64 65 6c 74 61 0a 0a 09 23 20 50 75 6c 6c 20 74  delta...# Pull t
6380: 68 65 20 74 69 6d 65 73 74 61 6d 70 73 20 66 6f  he timestamps fo
6390: 72 20 61 6c 6c 20 72 65 76 69 73 69 6f 6e 73 20  r all revisions 
63a0: 69 6e 20 74 68 65 20 63 68 61 6e 67 65 73 65 74  in the changeset
63b0: 73 20 61 6e 64 0a 09 23 20 63 6f 6d 70 75 74 65  s and..# compute
63c0: 20 74 68 65 69 72 20 64 65 6c 74 61 73 20 66 6f   their deltas fo
63d0: 72 20 75 73 65 20 62 79 20 74 68 65 20 62 72 65  r use by the bre
63e0: 61 6b 20 66 69 6e 64 65 72 2e 0a 0a 09 61 72 72  ak finder....arr
63f0: 61 79 20 73 65 74 20 64 65 6c 74 61 20 7b 7d 0a  ay set delta {}.
6400: 09 61 72 72 61 79 20 73 65 74 20 73 74 61 6d 70  .array set stamp
6410: 20 7b 7d 0a 0a 09 73 65 74 20 74 68 65 73 65 74   {}...set theset
6420: 20 28 27 5b 6a 6f 69 6e 20 24 72 65 76 69 73 69   ('[join $revisi
6430: 6f 6e 73 20 7b 27 2c 27 7d 5d 27 29 0a 09 66 6f  ons {','}]')..fo
6440: 72 65 61 63 68 20 7b 72 69 64 20 74 69 6d 65 7d  reach {rid time}
6450: 20 5b 73 74 61 74 65 20 72 75 6e 20 5b 73 75 62   [state run [sub
6460: 73 74 20 2d 6e 6f 63 6f 6d 6d 61 6e 64 73 20 2d  st -nocommands -
6470: 6e 6f 62 61 63 6b 73 6c 61 73 68 65 73 20 7b 0a  nobackslashes {.
6480: 09 20 20 20 20 53 45 4c 45 43 54 20 52 2e 72 69  .    SELECT R.ri
6490: 64 2c 20 52 2e 64 61 74 65 0a 09 20 20 20 20 46  d, R.date..    F
64a0: 52 4f 4d 20 72 65 76 69 73 69 6f 6e 20 52 0a 09  ROM revision R..
64b0: 20 20 20 20 57 48 45 52 45 20 52 2e 72 69 64 20      WHERE R.rid 
64c0: 49 4e 20 24 74 68 65 73 65 74 0a 09 7d 5d 5d 20  IN $theset..}]] 
64d0: 7b 0a 09 20 20 20 20 73 65 74 20 73 74 61 6d 70  {..    set stamp
64e0: 28 24 72 69 64 29 20 24 74 69 6d 65 0a 09 7d 0a  ($rid) $time..}.
64f0: 0a 09 73 65 74 20 6e 20 30 0a 09 66 6f 72 65 61  ..set n 0..forea
6500: 63 68 20 72 69 64 20 5b 6c 72 61 6e 67 65 20 24  ch rid [lrange $
6510: 72 65 76 69 73 69 6f 6e 73 20 30 20 65 6e 64 2d  revisions 0 end-
6520: 31 5d 20 72 6e 65 78 74 20 5b 6c 72 61 6e 67 65  1] rnext [lrange
6530: 20 24 72 65 76 69 73 69 6f 6e 73 20 31 20 65 6e   $revisions 1 en
6540: 64 5d 20 7b 0a 09 20 20 20 20 73 65 74 20 64 65  d] {..    set de
6550: 6c 74 61 28 24 6e 29 20 5b 65 78 70 72 20 7b 24  lta($n) [expr {$
6560: 73 74 61 6d 70 28 24 72 6e 65 78 74 29 20 2d 20  stamp($rnext) - 
6570: 24 73 74 61 6d 70 28 24 72 69 64 29 7d 5d 0a 09  $stamp($rid)}]..
6580: 20 20 20 20 69 6e 63 72 20 6e 0a 09 7d 0a 09 72      incr n..}..r
6590: 65 74 75 72 6e 0a 20 20 20 20 7d 0a 0a 20 20 20  eturn.    }..   
65a0: 20 70 72 6f 63 20 46 69 6e 64 42 65 73 74 42 72   proc FindBestBr
65b0: 65 61 6b 20 7b 72 61 6e 67 65 7d 20 7b 0a 09 75  eak {range} {..u
65c0: 70 76 61 72 20 31 20 63 72 6f 73 73 20 63 72 6f  pvar 1 cross cro
65d0: 73 73 20 64 65 6c 74 61 20 64 65 6c 74 61 0a 0a  ss delta delta..
65e0: 09 23 20 44 65 74 65 72 6d 69 6e 65 20 74 68 65  .# Determine the
65f0: 20 62 65 73 74 20 62 72 65 61 6b 20 6c 6f 63 61   best break loca
6600: 74 69 6f 6e 20 69 6e 20 74 68 65 20 67 69 76 65  tion in the give
6610: 6e 20 72 61 6e 67 65 20 6f 66 0a 09 23 20 70 6f  n range of..# po
6620: 73 69 74 69 6f 6e 73 2e 20 46 69 72 73 74 20 77  sitions. First w
6630: 65 20 6c 6f 6f 6b 20 66 6f 72 20 74 68 65 20 6c  e look for the l
6640: 6f 63 61 74 69 6f 6e 73 20 77 69 74 68 20 74 68  ocations with th
6650: 65 20 6d 61 78 69 6d 61 6c 0a 09 23 20 6e 75 6d  e maximal..# num
6660: 62 65 72 20 6f 66 20 63 72 6f 73 73 69 6e 67 73  ber of crossings
6670: 2e 20 49 66 20 74 68 65 72 65 20 61 72 65 20 73  . If there are s
6680: 65 76 65 72 61 6c 20 77 65 20 6c 6f 6f 6b 20 66  everal we look f
6690: 6f 72 20 74 68 65 0a 09 23 20 73 68 6f 72 74 65  or the..# shorte
66a0: 73 74 20 74 69 6d 65 20 69 6e 74 65 72 76 61 6c  st time interval
66b0: 20 61 6d 6f 6e 67 20 74 68 65 6d 2e 20 49 66 20   among them. If 
66c0: 77 65 20 73 74 69 6c 6c 20 68 61 76 65 20 6d 75  we still have mu
66d0: 6c 74 69 70 6c 65 0a 09 23 20 70 6f 73 73 69 62  ltiple..# possib
66e0: 69 6c 69 74 69 65 73 20 61 66 74 65 72 20 74 68  ilities after th
66f0: 61 74 20 77 65 20 73 65 6c 65 63 74 20 74 68 65  at we select the
6700: 20 65 61 72 6c 69 65 73 74 20 6c 6f 63 61 74 69   earliest locati
6710: 6f 6e 0a 09 23 20 61 6d 6f 6e 67 20 74 68 65 73  on..# among thes
6720: 65 2e 0a 0a 09 23 20 4e 6f 74 65 3a 20 49 66 20  e....# Note: If 
6730: 74 68 65 20 6d 61 78 69 6d 61 6c 20 6e 75 6d 62  the maximal numb
6740: 65 72 20 6f 66 20 63 72 6f 73 73 69 6e 67 73 20  er of crossings 
6750: 69 73 20 30 20 74 68 65 6e 20 74 68 65 20 72 61  is 0 then the ra
6760: 6e 67 65 0a 09 23 20 20 20 20 20 20 20 68 61 73  nge..#       has
6770: 20 6e 6f 20 69 6e 74 65 72 6e 61 6c 20 64 65 70   no internal dep
6780: 65 6e 64 65 6e 63 69 65 73 2c 20 61 6e 64 20 6e  endencies, and n
6790: 6f 20 62 72 65 61 6b 20 6c 6f 63 61 74 69 6f 6e  o break location
67a0: 20 61 74 0a 09 23 20 20 20 20 20 20 20 61 6c 6c   at..#       all
67b0: 2e 20 54 68 69 73 20 70 6f 73 73 69 62 69 6c 69  . This possibili
67c0: 74 79 20 69 73 20 73 69 67 6e 61 6c 65 64 20 76  ty is signaled v
67d0: 69 61 20 72 65 73 75 6c 74 20 2d 31 2e 0a 0a 09  ia result -1....
67e0: 23 20 4e 6f 74 65 3a 20 41 20 72 61 6e 67 65 20  # Note: A range 
67f0: 6f 66 20 6c 65 6e 67 74 68 20 31 20 6f 72 20 6c  of length 1 or l
6800: 65 73 73 20 63 61 6e 6e 6f 74 20 68 61 76 65 20  ess cannot have 
6810: 69 6e 74 65 72 6e 61 6c 0a 09 23 20 20 20 20 20  internal..#     
6820: 20 20 64 65 70 65 6e 64 65 6e 63 69 65 73 2c 20    dependencies, 
6830: 61 73 20 74 68 61 74 20 6e 65 65 64 73 20 61 74  as that needs at
6840: 20 6c 65 61 73 74 20 74 77 6f 20 72 65 76 69 73   least two revis
6850: 69 6f 6e 73 20 69 6e 0a 09 23 20 20 20 20 20 20  ions in..#      
6860: 20 74 68 65 20 72 61 6e 67 65 2e 0a 0a 09 69 66   the range....if
6870: 20 7b 5b 6c 6c 65 6e 67 74 68 20 24 72 61 6e 67   {[llength $rang
6880: 65 5d 20 3c 20 32 7d 20 7b 20 72 65 74 75 72 6e  e] < 2} { return
6890: 20 2d 31 20 7d 0a 0a 09 73 65 74 20 6d 61 78 20   -1 }...set max 
68a0: 2d 31 0a 09 73 65 74 20 62 65 73 74 20 7b 7d 0a  -1..set best {}.
68b0: 0a 09 66 6f 72 65 61 63 68 20 6c 6f 63 61 74 69  ..foreach locati
68c0: 6f 6e 20 24 72 61 6e 67 65 20 7b 0a 09 20 20 20  on $range {..   
68d0: 20 73 65 74 20 63 72 6f 73 73 69 6e 67 73 20 24   set crossings $
68e0: 63 72 6f 73 73 28 24 6c 6f 63 61 74 69 6f 6e 29  cross($location)
68f0: 0a 09 20 20 20 20 69 66 20 7b 24 63 72 6f 73 73  ..    if {$cross
6900: 69 6e 67 73 20 3e 20 24 6d 61 78 7d 20 7b 0a 09  ings > $max} {..
6910: 09 73 65 74 20 6d 61 78 20 20 24 63 72 6f 73 73  .set max  $cross
6920: 69 6e 67 73 0a 09 09 73 65 74 20 62 65 73 74 20  ings...set best 
6930: 5b 6c 69 73 74 20 24 6c 6f 63 61 74 69 6f 6e 5d  [list $location]
6940: 0a 09 09 63 6f 6e 74 69 6e 75 65 0a 09 20 20 20  ...continue..   
6950: 20 7d 20 65 6c 73 65 69 66 20 7b 24 63 72 6f 73   } elseif {$cros
6960: 73 69 6e 67 73 20 3d 3d 20 24 6d 61 78 7d 20 7b  sings == $max} {
6970: 0a 09 09 6c 61 70 70 65 6e 64 20 62 65 73 74 20  ...lappend best 
6980: 24 6c 6f 63 61 74 69 6f 6e 0a 09 20 20 20 20 7d  $location..    }
6990: 0a 09 7d 0a 0a 09 69 66 20 7b 24 6d 61 78 20 3d  ..}...if {$max =
69a0: 3d 20 30 7d 20 20 20 20 20 20 20 20 20 20 20 20  = 0}            
69b0: 7b 20 72 65 74 75 72 6e 20 2d 31 20 7d 0a 09 69  { return -1 }..i
69c0: 66 20 7b 5b 6c 6c 65 6e 67 74 68 20 24 62 65 73  f {[llength $bes
69d0: 74 5d 20 3d 3d 20 31 7d 20 7b 20 72 65 74 75 72  t] == 1} { retur
69e0: 6e 20 5b 6c 69 6e 64 65 78 20 24 62 65 73 74 20  n [lindex $best 
69f0: 30 5d 20 7d 0a 0a 09 73 65 74 20 6c 6f 63 61 74  0] }...set locat
6a00: 69 6f 6e 73 20 24 62 65 73 74 0a 09 73 65 74 20  ions $best..set 
6a10: 62 65 73 74 20 7b 7d 0a 09 73 65 74 20 6d 69 6e  best {}..set min
6a20: 20 2d 31 0a 0a 09 66 6f 72 65 61 63 68 20 6c 6f   -1...foreach lo
6a30: 63 61 74 69 6f 6e 20 24 6c 6f 63 61 74 69 6f 6e  cation $location
6a40: 73 20 7b 0a 09 20 20 20 20 73 65 74 20 69 6e 74  s {..    set int
6a50: 65 72 76 61 6c 20 24 64 65 6c 74 61 28 24 6c 6f  erval $delta($lo
6a60: 63 61 74 69 6f 6e 29 0a 09 20 20 20 20 69 66 20  cation)..    if 
6a70: 7b 28 24 6d 69 6e 20 3c 20 30 29 20 7c 7c 20 28  {($min < 0) || (
6a80: 24 69 6e 74 65 72 76 61 6c 20 3c 20 24 6d 69 6e  $interval < $min
6a90: 29 7d 20 7b 0a 09 09 73 65 74 20 6d 69 6e 20 20  )} {...set min  
6aa0: 24 69 6e 74 65 72 76 61 6c 0a 09 09 73 65 74 20  $interval...set 
6ab0: 62 65 73 74 20 5b 6c 69 73 74 20 24 6c 6f 63 61  best [list $loca
6ac0: 74 69 6f 6e 5d 0a 09 20 20 20 20 7d 20 65 6c 73  tion]..    } els
6ad0: 65 69 66 20 7b 24 69 6e 74 65 72 76 61 6c 20 3d  eif {$interval =
6ae0: 3d 20 24 6d 69 6e 7d 20 7b 0a 09 09 6c 61 70 70  = $min} {...lapp
6af0: 65 6e 64 20 62 65 73 74 20 24 6c 6f 63 61 74 69  end best $locati
6b00: 6f 6e 0a 09 20 20 20 20 7d 0a 09 7d 0a 0a 09 69  on..    }..}...i
6b10: 66 20 7b 5b 6c 6c 65 6e 67 74 68 20 24 62 65 73  f {[llength $bes
6b20: 74 5d 20 3d 3d 20 31 7d 20 7b 20 72 65 74 75 72  t] == 1} { retur
6b30: 6e 20 5b 6c 69 6e 64 65 78 20 24 62 65 73 74 20  n [lindex $best 
6b40: 30 5d 20 7d 0a 0a 09 72 65 74 75 72 6e 20 5b 6c  0] }...return [l
6b50: 69 6e 64 65 78 20 5b 6c 73 6f 72 74 20 2d 69 6e  index [lsort -in
6b60: 74 65 67 65 72 20 2d 69 6e 63 72 65 61 73 69 6e  teger -increasin
6b70: 67 20 24 62 65 73 74 5d 20 30 5d 0a 20 20 20 20  g $best] 0].    
6b80: 7d 0a 0a 20 20 20 20 70 72 6f 63 20 43 75 74 41  }..    proc CutA
6b90: 74 20 7b 6c 6f 63 61 74 69 6f 6e 7d 20 7b 0a 09  t {location} {..
6ba0: 75 70 76 61 72 20 31 20 63 72 6f 73 73 20 63 72  upvar 1 cross cr
6bb0: 6f 73 73 20 64 65 70 63 20 64 65 70 63 0a 0a 09  oss depc depc...
6bc0: 23 20 49 74 20 77 61 73 20 64 65 63 69 64 65 64  # It was decided
6bd0: 20 74 6f 20 73 70 6c 69 74 20 74 68 65 20 63 68   to split the ch
6be0: 61 6e 67 65 73 65 74 20 61 74 20 74 68 65 20 67  angeset at the g
6bf0: 69 76 65 6e 0a 09 23 20 6c 6f 63 61 74 69 6f 6e  iven..# location
6c00: 2e 20 54 68 69 73 20 63 75 74 73 20 61 20 6e 75  . This cuts a nu
6c10: 6d 62 65 72 20 6f 66 20 64 65 70 65 6e 64 65 6e  mber of dependen
6c20: 63 69 65 73 2e 20 48 65 72 65 20 77 65 20 75 70  cies. Here we up
6c30: 64 61 74 65 0a 09 23 20 74 68 65 20 63 72 6f 73  date..# the cros
6c40: 73 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 73 6f  s information so
6c50: 20 74 68 61 74 20 74 68 65 20 62 72 65 61 6b 20   that the break 
6c60: 66 69 6e 64 65 72 20 68 61 73 20 61 63 63 75 72  finder has accur
6c70: 61 74 65 0a 09 23 20 64 61 74 61 20 77 68 65 6e  ate..# data when
6c80: 20 77 65 20 6c 6f 6f 6b 20 61 74 20 74 68 65 20   we look at the 
6c90: 67 65 6e 65 72 61 74 65 64 20 66 72 61 67 6d 65  generated fragme
6ca0: 6e 74 73 2e 0a 0a 09 73 65 74 20 73 69 78 20 5b  nts....set six [
6cb0: 6c 6f 67 20 76 69 73 69 62 6c 65 3f 20 36 5d 0a  log visible? 6].
6cc0: 0a 09 66 6f 72 65 61 63 68 20 7b 64 65 70 20 72  ..foreach {dep r
6cd0: 61 6e 67 65 7d 20 5b 61 72 72 61 79 20 67 65 74  ange} [array get
6ce0: 20 64 65 70 63 5d 20 7b 0a 09 20 20 20 20 23 20   depc] {..    # 
6cf0: 43 68 65 63 6b 20 61 6c 6c 20 64 65 70 65 6e 64  Check all depend
6d00: 65 6e 63 69 65 73 20 73 74 69 6c 6c 20 6b 6e 6f  encies still kno
6d10: 77 6e 2c 20 74 61 6b 65 20 74 68 65 69 72 20 72  wn, take their r
6d20: 61 6e 67 65 20 61 6e 64 0a 09 20 20 20 20 23 20  ange and..    # 
6d30: 73 65 65 20 69 66 20 74 68 65 20 62 72 65 61 6b  see if the break
6d40: 20 6c 6f 63 61 74 69 6f 6e 20 66 61 6c 6c 73 20   location falls 
6d50: 77 69 74 68 69 6e 2e 0a 0a 09 20 20 20 20 42 6f  within....    Bo
6d60: 72 64 65 72 20 24 72 61 6e 67 65 20 73 20 65 0a  rder $range s e.
6d70: 09 20 20 20 20 69 66 20 7b 24 6c 6f 63 61 74 69  .    if {$locati
6d80: 6f 6e 20 3c 20 24 73 7d 20 63 6f 6e 74 69 6e 75  on < $s} continu
6d90: 65 20 3b 20 23 20 62 72 65 61 6b 20 62 65 66 6f  e ; # break befo
6da0: 72 65 20 72 61 6e 67 65 2c 20 69 67 6e 6f 72 65  re range, ignore
6db0: 0a 09 20 20 20 20 69 66 20 7b 24 6c 6f 63 61 74  ..    if {$locat
6dc0: 69 6f 6e 20 3e 20 24 65 7d 20 63 6f 6e 74 69 6e  ion > $e} contin
6dd0: 75 65 20 3b 20 23 20 62 72 65 61 6b 20 61 66 74  ue ; # break aft
6de0: 65 72 20 72 61 6e 67 65 2c 20 69 67 6e 6f 72 65  er range, ignore
6df0: 2e 0a 0a 09 20 20 20 20 23 20 54 68 69 73 20 64  ....    # This d
6e00: 65 70 65 6e 64 65 6e 63 79 20 63 72 6f 73 73 65  ependency crosse
6e10: 73 20 74 68 65 20 62 72 65 61 6b 20 6c 6f 63 61  s the break loca
6e20: 74 69 6f 6e 2e 20 57 65 20 72 65 6d 6f 76 65 20  tion. We remove 
6e30: 69 74 0a 09 20 20 20 20 23 20 66 72 6f 6d 20 74  it..    # from t
6e40: 68 65 20 63 72 6f 73 73 69 6e 67 73 20 63 6f 75  he crossings cou
6e50: 6e 74 65 72 73 2c 20 61 6e 64 20 74 68 65 6e 20  nters, and then 
6e60: 61 6c 73 6f 20 66 72 6f 6d 20 74 68 65 20 73 65  also from the se
6e70: 74 0a 09 20 20 20 20 23 20 6f 66 20 6b 6e 6f 77  t..    # of know
6e80: 6e 20 64 65 70 65 6e 64 65 6e 63 69 65 73 2c 20  n dependencies, 
6e90: 61 73 20 77 65 20 61 72 65 20 64 6f 6e 65 20 77  as we are done w
6ea0: 69 74 68 20 69 74 2e 0a 0a 09 20 20 20 20 66 6f  ith it....    fo
6eb0: 72 65 61 63 68 20 6c 6f 63 20 24 64 65 70 63 28  reach loc $depc(
6ec0: 24 64 65 70 29 20 7b 20 69 6e 63 72 20 63 72 6f  $dep) { incr cro
6ed0: 73 73 28 24 6c 6f 63 29 20 2d 31 20 7d 0a 09 20  ss($loc) -1 }.. 
6ee0: 20 20 20 75 6e 73 65 74 20 64 65 70 63 28 24 64     unset depc($d
6ef0: 65 70 29 0a 0a 09 20 20 20 20 69 66 20 7b 21 24  ep)...    if {!$
6f00: 73 69 78 7d 20 63 6f 6e 74 69 6e 75 65 0a 0a 09  six} continue...
6f10: 20 20 20 20 73 74 72 75 63 74 3a 3a 6c 69 73 74      struct::list
6f20: 20 61 73 73 69 67 6e 20 24 64 65 70 20 70 61 72   assign $dep par
6f30: 65 6e 74 20 63 68 69 6c 64 0a 09 20 20 20 20 6c  ent child..    l
6f40: 6f 67 20 77 72 69 74 65 20 35 20 63 73 65 74 73  og write 5 csets
6f50: 20 22 42 72 6f 6b 65 20 64 65 70 65 6e 64 65 6e   "Broke dependen
6f60: 63 79 20 5b 50 44 20 24 70 61 72 65 6e 74 5d 20  cy [PD $parent] 
6f70: 2d 2d 3e 20 5b 50 44 20 24 63 68 69 6c 64 5d 22  --> [PD $child]"
6f80: 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 0a 20 20 20  ..}...return.   
6f90: 20 7d 0a 0a 20 20 20 20 23 20 50 72 69 6e 74 20   }..    # Print 
6fa0: 69 64 65 6e 74 69 66 79 69 6e 67 20 64 61 74 61  identifying data
6fb0: 20 66 6f 72 20 61 20 72 65 76 69 73 69 6f 6e 20   for a revision 
6fc0: 28 70 72 6f 6a 65 63 74 2c 20 66 69 6c 65 2c 20  (project, file, 
6fd0: 64 6f 74 74 65 64 20 72 65 76 0a 20 20 20 20 23  dotted rev.    #
6fe0: 20 6e 75 6d 62 65 72 29 2c 20 66 6f 72 20 68 69   number), for hi
6ff0: 67 68 20 76 65 72 62 6f 73 69 74 79 20 6c 6f 67  gh verbosity log
7000: 20 6f 75 74 70 75 74 2e 0a 20 20 20 20 23 20 54   output..    # T
7010: 4f 44 4f 3a 20 52 65 70 6c 61 63 65 20 77 69 74  ODO: Replace wit
7020: 68 20 63 61 6c 6c 20 74 6f 20 69 74 65 6d 73 74  h call to itemst
7030: 72 20 28 6c 69 73 74 20 72 65 76 20 24 69 64 29  r (list rev $id)
7040: 0a 0a 20 20 20 20 70 72 6f 63 20 50 44 20 7b 69  ..    proc PD {i
7050: 64 7d 20 7b 0a 09 66 6f 72 65 61 63 68 20 7b 70  d} {..foreach {p
7060: 20 66 20 72 7d 20 5b 73 74 61 74 65 20 72 75 6e   f r} [state run
7070: 20 7b 0a 09 09 53 45 4c 45 43 54 20 50 2e 6e 61   {...SELECT P.na
7080: 6d 65 20 2c 20 46 2e 6e 61 6d 65 2c 20 52 2e 72  me , F.name, R.r
7090: 65 76 0a 09 09 46 52 4f 4d 20 72 65 76 69 73 69  ev...FROM revisi
70a0: 6f 6e 20 52 2c 20 66 69 6c 65 20 46 2c 20 70 72  on R, file F, pr
70b0: 6f 6a 65 63 74 20 50 0a 09 09 57 48 45 52 45 20  oject P...WHERE 
70c0: 52 2e 72 69 64 20 3d 20 24 69 64 20 20 20 20 2d  R.rid = $id    -
70d0: 2d 20 46 69 6e 64 20 73 70 65 63 69 66 69 65 64  - Find specified
70e0: 20 66 69 6c 65 20 72 65 76 69 73 69 6f 6e 0a 09   file revision..
70f0: 09 41 4e 44 20 20 20 46 2e 66 69 64 20 3d 20 52  .AND   F.fid = R
7100: 2e 66 69 64 20 20 2d 2d 20 47 65 74 20 66 69 6c  .fid  -- Get fil
7110: 65 20 6f 66 20 74 68 65 20 72 65 76 69 73 69 6f  e of the revisio
7120: 6e 0a 09 09 41 4e 44 20 20 20 50 2e 70 69 64 20  n...AND   P.pid 
7130: 3d 20 46 2e 70 69 64 20 20 2d 2d 20 47 65 74 20  = F.pid  -- Get 
7140: 70 72 6f 6a 65 63 74 20 6f 66 20 74 68 65 20 66  project of the f
7150: 69 6c 65 2e 0a 09 7d 5d 20 62 72 65 61 6b 0a 09  ile...}] break..
7160: 72 65 74 75 72 6e 20 22 27 24 70 20 3a 20 24 66  return "'$p : $f
7170: 2f 24 72 27 22 0a 20 20 20 20 7d 0a 0a 20 20 20  /$r'".    }..   
7180: 20 23 20 50 72 69 6e 74 69 6e 67 20 6f 6e 65 20   # Printing one 
7190: 6f 72 20 6d 6f 72 65 20 72 61 6e 67 65 73 2c 20  or more ranges, 
71a0: 66 6f 72 6d 61 74 74 65 64 2c 20 61 6e 64 20 6f  formatted, and o
71b0: 6e 6c 79 20 74 68 65 69 72 20 62 6f 72 64 65 72  nly their border
71c0: 20 74 6f 0a 20 20 20 20 23 20 6b 65 65 70 20 74   to.    # keep t
71d0: 68 65 20 73 74 72 69 6e 67 73 20 73 68 6f 72 74  he strings short
71e0: 2e 0a 0a 20 20 20 20 70 72 6f 63 20 50 52 73 20  ...    proc PRs 
71f0: 7b 72 61 6e 67 65 73 7d 20 7b 0a 09 72 65 74 75  {ranges} {..retu
7200: 72 6e 20 5b 73 74 72 75 63 74 3a 3a 6c 69 73 74  rn [struct::list
7210: 20 6d 61 70 20 24 72 61 6e 67 65 73 20 5b 6d 79   map $ranges [my
7220: 70 72 6f 63 20 50 52 5d 5d 0a 20 20 20 20 7d 0a  proc PR]].    }.
7230: 0a 20 20 20 20 70 72 6f 63 20 50 52 20 7b 72 61  .    proc PR {ra
7240: 6e 67 65 7d 20 7b 0a 09 42 6f 72 64 65 72 20 24  nge} {..Border $
7250: 72 61 6e 67 65 20 73 20 65 0a 09 72 65 74 75 72  range s e..retur
7260: 6e 20 3c 24 7b 73 7d 2e 2e 2e 24 7b 65 7d 3e 0a  n <${s}...${e}>.
7270: 20 20 20 20 7d 0a 0a 20 20 20 20 70 72 6f 63 20      }..    proc 
7280: 42 6f 72 64 65 72 20 7b 72 61 6e 67 65 20 73 76  Border {range sv
7290: 20 65 76 7d 20 7b 0a 09 75 70 76 61 72 20 31 20   ev} {..upvar 1 
72a0: 24 73 76 20 73 20 24 65 76 20 65 0a 09 73 65 74  $sv s $ev e..set
72b0: 20 73 20 5b 6c 69 6e 64 65 78 20 24 72 61 6e 67   s [lindex $rang
72c0: 65 20 30 5d 0a 09 73 65 74 20 65 20 5b 6c 69 6e  e 0]..set e [lin
72d0: 64 65 78 20 24 72 61 6e 67 65 20 65 6e 64 5d 0a  dex $range end].
72e0: 09 72 65 74 75 72 6e 0a 20 20 20 20 7d 0a 0a 20  .return.    }.. 
72f0: 20 20 20 23 20 23 20 23 23 20 23 23 23 20 23 23     # # ## ### ##
7300: 23 23 23 20 23 23 23 23 23 23 23 23 20 23 23 23  ### ######## ###
7310: 23 23 23 23 23 23 23 23 23 23 0a 0a 20 20 20 20  ##########..    
7320: 74 79 70 65 76 61 72 69 61 62 6c 65 20 6d 79 63  typevariable myc
7330: 68 61 6e 67 65 73 65 74 73 20 20 20 20 20 20 20  hangesets       
7340: 20 20 7b 7d 20 3b 20 23 20 4c 69 73 74 20 6f 66    {} ; # List of
7350: 20 61 6c 6c 20 6b 6e 6f 77 6e 0a 09 09 09 09 09   all known......
7360: 20 20 20 23 20 63 68 61 6e 67 65 73 65 74 73 2e     # changesets.
7370: 0a 20 20 20 20 74 79 70 65 76 61 72 69 61 62 6c  .    typevariabl
7380: 65 20 6d 79 74 63 68 61 6e 67 65 73 65 74 73 20  e mytchangesets 
7390: 2d 61 72 72 61 79 20 7b 7d 20 3b 20 23 20 4c 69  -array {} ; # Li
73a0: 73 74 20 6f 66 20 61 6c 6c 20 6b 6e 6f 77 6e 0a  st of all known.
73b0: 09 09 09 09 09 20 20 20 23 20 63 68 61 6e 67 65  .....   # change
73c0: 73 65 74 73 20 6f 66 20 61 20 74 79 70 65 2e 0a  sets of a type..
73d0: 20 20 20 20 74 79 70 65 76 61 72 69 61 62 6c 65      typevariable
73e0: 20 6d 79 69 74 65 6d 6d 61 70 20 20 20 20 20 2d   myitemmap     -
73f0: 61 72 72 61 79 20 7b 7d 20 3b 20 23 20 4d 61 70  array {} ; # Map
7400: 20 66 72 6f 6d 20 69 74 65 6d 73 20 28 74 61 67   from items (tag
7410: 67 65 64 29 0a 09 09 09 09 09 20 20 20 23 20 74  ged)......   # t
7420: 6f 20 74 68 65 20 6c 69 73 74 20 6f 66 20 63 68  o the list of ch
7430: 61 6e 67 65 73 65 74 73 0a 09 09 09 09 09 20 20  angesets......  
7440: 20 23 20 63 6f 6e 74 61 69 6e 69 6e 67 20 69 74   # containing it
7450: 2e 20 45 61 63 68 20 69 74 65 6d 0a 09 09 09 09  . Each item.....
7460: 09 20 20 20 23 20 63 61 6e 20 62 65 20 75 73 65  .   # can be use
7470: 64 20 62 79 20 6f 6e 6c 79 20 6f 6e 65 0a 09 09  d by only one...
7480: 09 09 09 20 20 20 23 20 63 68 61 6e 67 65 73 65  ...   # changese
7490: 74 2e 0a 20 20 20 20 74 79 70 65 76 61 72 69 61  t..    typevaria
74a0: 62 6c 65 20 6d 79 69 64 6d 61 70 20 20 20 2d 61  ble myidmap   -a
74b0: 72 72 61 79 20 7b 7d 20 3b 20 23 20 4d 61 70 20  rray {} ; # Map 
74c0: 66 72 6f 6d 20 63 68 61 6e 67 65 73 65 74 20 69  from changeset i
74d0: 64 20 74 6f 0a 09 09 09 09 20 20 20 20 20 20 20  d to.....       
74e0: 23 20 63 68 61 6e 67 65 73 65 74 2e 0a 0a 20 20  # changeset...  
74f0: 20 20 74 79 70 65 6d 65 74 68 6f 64 20 61 6c 6c    typemethod all
7500: 20 20 20 20 7b 7d 20 20 20 20 7b 20 72 65 74 75      {}    { retu
7510: 72 6e 20 24 6d 79 63 68 61 6e 67 65 73 65 74 73  rn $mychangesets
7520: 20 7d 0a 20 20 20 20 74 79 70 65 6d 65 74 68 6f   }.    typemetho
7530: 64 20 6f 66 20 20 20 20 20 7b 63 69 64 7d 20 7b  d of     {cid} {
7540: 20 72 65 74 75 72 6e 20 24 6d 79 69 64 6d 61 70   return $myidmap
7550: 28 24 63 69 64 29 20 7d 0a 20 20 20 20 74 79 70  ($cid) }.    typ
7560: 65 6d 65 74 68 6f 64 20 6f 66 69 74 65 6d 20 7b  emethod ofitem {
7570: 69 69 64 7d 20 7b 20 72 65 74 75 72 6e 20 24 6d  iid} { return $m
7580: 79 69 74 65 6d 6d 61 70 28 24 69 69 64 29 20 7d  yitemmap($iid) }
7590: 0a 0a 20 20 20 20 74 79 70 65 6d 65 74 68 6f 64  ..    typemethod
75a0: 20 72 65 76 20 20 20 20 7b 7d 20 20 20 20 7b 20   rev    {}    { 
75b0: 72 65 74 75 72 6e 20 24 6d 79 74 63 68 61 6e 67  return $mytchang
75c0: 65 73 65 74 73 28 72 65 76 29 20 7d 0a 20 20 20  esets(rev) }.   
75d0: 20 74 79 70 65 6d 65 74 68 6f 64 20 73 79 6d 20   typemethod sym 
75e0: 20 20 20 7b 7d 20 20 20 20 7b 20 72 65 74 75 72     {}    { retur
75f0: 6e 20 5b 63 6f 6e 63 61 74 20 5c 0a 09 09 09 09  n [concat \.....
7600: 09 20 20 24 7b 6d 79 74 63 68 61 6e 67 65 73 65  .  ${mytchangese
7610: 74 73 28 73 79 6d 3a 3a 62 72 61 6e 63 68 29 7d  ts(sym::branch)}
7620: 20 5c 0a 09 09 09 09 09 20 20 24 7b 6d 79 74 63   \......  ${mytc
7630: 68 61 6e 67 65 73 65 74 73 28 73 79 6d 3a 3a 74  hangesets(sym::t
7640: 61 67 29 7d 5d 20 7d 0a 0a 20 20 20 20 23 20 23  ag)}] }..    # #
7650: 20 23 23 20 23 23 23 20 23 23 23 23 23 20 23 23   ## ### ##### ##
7660: 23 23 23 23 23 23 20 23 23 23 23 23 23 23 23 23  ###### #########
7670: 23 23 23 23 0a 20 20 20 20 23 23 20 43 6f 6e 66  ####.    ## Conf
7680: 69 67 75 72 61 74 69 6f 6e 0a 0a 20 20 20 20 70  iguration..    p
7690: 72 61 67 6d 61 20 2d 68 61 73 74 79 70 65 69 6e  ragma -hastypein
76a0: 66 6f 20 20 20 20 6e 6f 20 20 3b 20 23 20 6e 6f  fo    no  ; # no
76b0: 20 74 79 70 65 20 69 6e 74 72 6f 73 70 65 63 74   type introspect
76c0: 69 6f 6e 0a 20 20 20 20 70 72 61 67 6d 61 20 2d  ion.    pragma -
76d0: 68 61 73 69 6e 66 6f 20 20 20 20 20 20 20 20 6e  hasinfo        n
76e0: 6f 20 20 3b 20 23 20 6e 6f 20 6f 62 6a 65 63 74  o  ; # no object
76f0: 20 69 6e 74 72 6f 73 70 65 63 74 69 6f 6e 0a 0a   introspection..
7700: 20 20 20 20 23 20 23 20 23 23 20 23 23 23 20 23      # # ## ### #
7710: 23 23 23 23 20 23 23 23 23 23 23 23 23 20 23 23  #### ######## ##
7720: 23 23 23 23 23 23 23 23 23 23 23 0a 7d 0a 0a 23  ###########.}..#
7730: 23 0a 23 23 20 4e 4f 54 45 3a 20 54 68 65 20 73  #.## NOTE: The s
7740: 75 63 63 65 73 73 6f 72 20 61 6e 64 20 70 72 65  uccessor and pre
7750: 64 65 63 65 73 73 6f 72 20 6d 65 74 68 6f 64 73  decessor methods
7760: 20 64 65 66 69 6e 65 64 20 62 79 20 74 68 65 20   defined by the 
7770: 63 6c 61 73 73 65 73 0a 23 23 20 20 20 20 20 20  classes.##      
7780: 20 62 65 6c 6f 77 20 61 72 65 20 2d 2d 20 62 6f   below are -- bo
7790: 74 74 6c 65 20 6e 65 63 6b 73 20 2d 2d 2e 20 4c  ttle necks --. L
77a0: 6f 6f 6b 20 66 6f 72 20 77 61 79 73 20 74 6f 20  ook for ways to 
77b0: 6d 61 6b 65 20 74 68 65 20 53 51 4c 0a 23 23 20  make the SQL.## 
77c0: 20 20 20 20 20 20 66 61 73 74 65 72 2e 0a 23 23        faster..##
77d0: 0a 0a 23 20 23 20 23 23 20 23 23 23 20 23 23 23  ..# # ## ### ###
77e0: 23 23 20 23 23 23 23 23 23 23 23 20 23 23 23 23  ## ######## ####
77f0: 23 23 23 23 23 23 23 23 23 20 23 23 23 23 23 23  ######### ######
7800: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 0a  ###############.
7810: 23 23 20 48 65 6c 70 65 72 20 73 69 6e 67 6c 65  ## Helper single
7820: 74 6f 6e 2e 20 43 6f 6d 6d 61 6e 64 73 20 66 6f  ton. Commands fo
7830: 72 20 72 65 76 69 73 69 6f 6e 20 63 68 61 6e 67  r revision chang
7840: 65 73 65 74 73 2e 0a 0a 73 6e 69 74 3a 3a 74 79  esets...snit::ty
7850: 70 65 20 3a 3a 76 63 3a 3a 66 6f 73 73 69 6c 3a  pe ::vc::fossil:
7860: 3a 69 6d 70 6f 72 74 3a 3a 63 76 73 3a 3a 70 72  :import::cvs::pr
7870: 6f 6a 65 63 74 3a 3a 72 65 76 3a 3a 72 65 76 20  oject::rev::rev 
7880: 7b 0a 20 20 20 20 74 79 70 65 6d 65 74 68 6f 64  {.    typemethod
7890: 20 62 79 72 65 76 69 73 69 6f 6e 20 7b 7d 20 7b   byrevision {} {
78a0: 20 72 65 74 75 72 6e 20 31 20 7d 0a 20 20 20 20   return 1 }.    
78b0: 74 79 70 65 6d 65 74 68 6f 64 20 62 79 73 79 6d  typemethod bysym
78c0: 62 6f 6c 20 20 20 7b 7d 20 7b 20 72 65 74 75 72  bol   {} { retur
78d0: 6e 20 30 20 7d 0a 20 20 20 20 74 79 70 65 6d 65  n 0 }.    typeme
78e0: 74 68 6f 64 20 69 73 74 61 67 20 20 20 20 20 20  thod istag      
78f0: 7b 7d 20 7b 20 72 65 74 75 72 6e 20 30 20 7d 0a  {} { return 0 }.
7900: 20 20 20 20 74 79 70 65 6d 65 74 68 6f 64 20 69      typemethod i
7910: 73 62 72 61 6e 63 68 20 20 20 7b 7d 20 7b 20 72  sbranch   {} { r
7920: 65 74 75 72 6e 20 30 20 7d 0a 0a 20 20 20 20 74  eturn 0 }..    t
7930: 79 70 65 6d 65 74 68 6f 64 20 73 74 72 20 7b 72  ypemethod str {r
7940: 65 76 69 73 69 6f 6e 7d 20 7b 0a 09 73 74 72 75  evision} {..stru
7950: 63 74 3a 3a 6c 69 73 74 20 61 73 73 69 67 6e 20  ct::list assign 
7960: 5b 73 74 61 74 65 20 72 75 6e 20 7b 0a 09 20 20  [state run {..  
7970: 20 20 53 45 4c 45 43 54 20 52 2e 72 65 76 2c 20    SELECT R.rev, 
7980: 46 2e 6e 61 6d 65 2c 20 50 2e 6e 61 6d 65 0a 09  F.name, P.name..
7990: 20 20 20 20 46 52 4f 4d 20 20 20 72 65 76 69 73      FROM   revis
79a0: 69 6f 6e 20 52 2c 20 66 69 6c 65 20 46 2c 20 70  ion R, file F, p
79b0: 72 6f 6a 65 63 74 20 50 0a 09 20 20 20 20 57 48  roject P..    WH
79c0: 45 52 45 20 20 52 2e 72 69 64 20 3d 20 24 72 65  ERE  R.rid = $re
79d0: 76 69 73 69 6f 6e 20 2d 2d 20 46 69 6e 64 20 73  vision -- Find s
79e0: 70 65 63 69 66 69 65 64 20 66 69 6c 65 20 72 65  pecified file re
79f0: 76 69 73 69 6f 6e 0a 09 20 20 20 20 41 4e 44 20  vision..    AND 
7a00: 20 20 20 46 2e 66 69 64 20 3d 20 52 2e 66 69 64     F.fid = R.fid
7a10: 20 20 20 20 20 2d 2d 20 47 65 74 20 66 69 6c 65       -- Get file
7a20: 20 6f 66 20 74 68 65 20 72 65 76 69 73 69 6f 6e   of the revision
7a30: 0a 09 20 20 20 20 41 4e 44 20 20 20 20 50 2e 70  ..    AND    P.p
7a40: 69 64 20 3d 20 46 2e 70 69 64 20 20 20 20 20 2d  id = F.pid     -
7a50: 2d 20 47 65 74 20 70 72 6f 6a 65 63 74 20 6f 66  - Get project of
7a60: 20 74 68 65 20 66 69 6c 65 2e 0a 09 7d 5d 20 72   the file...}] r
7a70: 65 76 6e 72 20 66 6e 61 6d 65 20 70 6e 61 6d 65  evnr fname pname
7a80: 0a 09 72 65 74 75 72 6e 20 22 24 70 6e 61 6d 65  ..return "$pname
7a90: 2f 24 7b 72 65 76 6e 72 7d 3a 3a 24 66 6e 61 6d  /${revnr}::$fnam
7aa0: 65 22 0a 20 20 20 20 7d 0a 0a 20 20 20 20 23 20  e".    }..    # 
7ab0: 72 65 73 75 6c 74 20 3d 20 6c 69 73 74 20 28 6d  result = list (m
7ac0: 69 6e 74 69 6d 65 2c 20 6d 61 78 74 69 6d 65 29  intime, maxtime)
7ad0: 0a 20 20 20 20 74 79 70 65 6d 65 74 68 6f 64 20  .    typemethod 
7ae0: 74 69 6d 65 72 61 6e 67 65 20 7b 69 74 65 6d 73  timerange {items
7af0: 7d 20 7b 0a 09 73 65 74 20 74 68 65 73 65 74 20  } {..set theset 
7b00: 28 27 5b 6a 6f 69 6e 20 24 69 74 65 6d 73 20 7b  ('[join $items {
7b10: 27 2c 27 7d 5d 27 29 0a 09 72 65 74 75 72 6e 20  ','}]')..return 
7b20: 5b 73 74 61 74 65 20 72 75 6e 20 5b 73 75 62 73  [state run [subs
7b30: 74 20 2d 6e 6f 63 6f 6d 6d 61 6e 64 73 20 2d 6e  t -nocommands -n
7b40: 6f 62 61 63 6b 73 6c 61 73 68 65 73 20 7b 0a 09  obackslashes {..
7b50: 20 20 20 20 53 45 4c 45 43 54 20 4d 49 4e 28 52      SELECT MIN(R
7b60: 2e 64 61 74 65 29 2c 20 4d 41 58 28 52 2e 64 61  .date), MAX(R.da
7b70: 74 65 29 0a 09 20 20 20 20 46 52 4f 4d 20 72 65  te)..    FROM re
7b80: 76 69 73 69 6f 6e 20 52 0a 09 20 20 20 20 57 48  vision R..    WH
7b90: 45 52 45 20 52 2e 72 69 64 20 49 4e 20 24 74 68  ERE R.rid IN $th
7ba0: 65 73 65 74 20 2d 2d 20 52 65 73 74 72 69 63 74  eset -- Restrict
7bb0: 20 74 6f 20 72 65 76 69 73 69 6f 6e 73 20 6f 66   to revisions of
7bc0: 20 69 6e 74 65 72 65 73 74 0a 09 7d 5d 5d 0a 20   interest..}]]. 
7bd0: 20 20 20 7d 0a 0a 20 20 20 20 23 20 76 61 72 28     }..    # var(
7be0: 64 76 29 20 3d 20 64 69 63 74 20 28 72 65 76 69  dv) = dict (revi
7bf0: 73 69 6f 6e 20 2d 3e 20 6c 69 73 74 20 28 72 65  sion -> list (re
7c00: 76 69 73 69 6f 6e 29 29 0a 20 20 20 20 74 79 70  vision)).    typ
7c10: 65 6d 65 74 68 6f 64 20 69 6e 74 65 72 6e 61 6c  emethod internal
7c20: 73 75 63 63 65 73 73 6f 72 73 20 7b 64 76 20 72  successors {dv r
7c30: 65 76 69 73 69 6f 6e 73 7d 20 7b 0a 09 75 70 76  evisions} {..upv
7c40: 61 72 20 31 20 24 64 76 20 64 65 70 65 6e 64 65  ar 1 $dv depende
7c50: 6e 63 69 65 73 0a 09 73 65 74 20 74 68 65 73 65  ncies..set these
7c60: 74 20 28 27 5b 6a 6f 69 6e 20 24 72 65 76 69 73  t ('[join $revis
7c70: 69 6f 6e 73 20 7b 27 2c 27 7d 5d 27 29 0a 0a 09  ions {','}]')...
7c80: 23 20 53 65 65 20 27 73 75 63 63 65 73 73 6f 72  # See 'successor
7c90: 73 27 20 62 65 6c 6f 77 20 66 6f 72 20 74 68 65  s' below for the
7ca0: 20 6d 61 69 6e 20 65 78 70 6c 61 6e 61 74 69 6f   main explanatio
7cb0: 6e 20 6f 66 0a 09 23 20 74 68 65 20 76 61 72 69  n of..# the vari
7cc0: 6f 75 73 20 63 61 73 65 73 2e 20 54 68 69 73 20  ous cases. This 
7cd0: 70 69 65 63 65 20 69 73 20 73 70 65 63 69 61 6c  piece is special
7ce0: 20 69 6e 20 74 68 61 74 20 69 74 0a 09 23 20 72   in that it..# r
7cf0: 65 73 74 72 69 63 74 73 20 74 68 65 20 73 75 63  estricts the suc
7d00: 63 65 73 73 6f 72 73 20 77 65 20 6c 6f 6f 6b 20  cessors we look 
7d10: 66 6f 72 20 74 6f 20 74 68 65 20 73 61 6d 65 20  for to the same 
7d20: 73 65 74 20 6f 66 0a 09 23 20 72 65 76 69 73 69  set of..# revisi
7d30: 6f 6e 73 20 77 65 20 73 74 61 72 74 20 66 72 6f  ons we start fro
7d40: 6d 2e 20 53 65 6e 73 69 62 6c 65 20 61 73 20 77  m. Sensible as w
7d50: 65 20 61 72 65 20 6c 6f 6f 6b 69 6e 67 20 66 6f  e are looking fo
7d60: 72 0a 09 23 20 63 68 61 6e 67 65 73 65 74 20 69  r..# changeset i
7d70: 6e 74 65 72 6e 61 6c 20 64 65 70 65 6e 64 65 6e  nternal dependen
7d80: 63 69 65 73 2e 0a 0a 09 61 72 72 61 79 20 73 65  cies....array se
7d90: 74 20 64 65 70 20 7b 7d 0a 0a 09 66 6f 72 65 61  t dep {}...forea
7da0: 63 68 20 7b 72 69 64 20 63 68 69 6c 64 7d 20 5b  ch {rid child} [
7db0: 73 74 61 74 65 20 72 75 6e 20 5b 73 75 62 73 74  state run [subst
7dc0: 20 2d 6e 6f 63 6f 6d 6d 61 6e 64 73 20 2d 6e 6f   -nocommands -no
7dd0: 62 61 63 6b 73 6c 61 73 68 65 73 20 7b 0a 20 20  backslashes {.  
7de0: 20 20 2d 2d 20 28 31 29 20 50 72 69 6d 61 72 79    -- (1) Primary
7df0: 20 63 68 69 6c 64 0a 09 20 20 20 20 53 45 4c 45   child..    SELE
7e00: 43 54 20 52 2e 72 69 64 2c 20 52 2e 63 68 69 6c  CT R.rid, R.chil
7e10: 64 0a 09 20 20 20 20 46 52 4f 4d 20 20 20 72 65  d..    FROM   re
7e20: 76 69 73 69 6f 6e 20 52 0a 09 20 20 20 20 57 48  vision R..    WH
7e30: 45 52 45 20 20 52 2e 72 69 64 20 20 20 49 4e 20  ERE  R.rid   IN 
7e40: 24 74 68 65 73 65 74 20 20 20 20 20 2d 2d 20 52  $theset     -- R
7e50: 65 73 74 72 69 63 74 20 74 6f 20 72 65 76 69 73  estrict to revis
7e60: 69 6f 6e 73 20 6f 66 20 69 6e 74 65 72 65 73 74  ions of interest
7e70: 0a 09 20 20 20 20 41 4e 44 20 20 20 20 52 2e 63  ..    AND    R.c
7e80: 68 69 6c 64 20 49 53 20 4e 4f 54 20 4e 55 4c 4c  hild IS NOT NULL
7e90: 20 20 20 20 2d 2d 20 48 61 73 20 70 72 69 6d 61      -- Has prima
7ea0: 72 79 20 63 68 69 6c 64 0a 09 20 20 20 20 41 4e  ry child..    AN
7eb0: 44 20 20 20 20 52 2e 63 68 69 6c 64 20 49 4e 20  D    R.child IN 
7ec0: 24 74 68 65 73 65 74 20 20 20 20 20 2d 2d 20 57  $theset     -- W
7ed0: 68 69 63 68 20 69 73 20 61 6c 73 6f 20 6f 66 20  hich is also of 
7ee0: 69 6e 74 65 72 65 73 74 0a 20 20 20 20 55 4e 49  interest.    UNI
7ef0: 4f 4e 0a 20 20 20 20 2d 2d 20 28 32 29 20 53 65  ON.    -- (2) Se
7f00: 63 6f 6e 64 61 72 79 20 28 62 72 61 6e 63 68 29  condary (branch)
7f10: 20 63 68 69 6c 64 72 65 6e 0a 09 20 20 20 20 53   children..    S
7f20: 45 4c 45 43 54 20 52 2e 72 69 64 2c 20 42 2e 62  ELECT R.rid, B.b
7f30: 72 69 64 0a 09 20 20 20 20 46 52 4f 4d 20 20 20  rid..    FROM   
7f40: 72 65 76 69 73 69 6f 6e 20 52 2c 20 72 65 76 69  revision R, revi
7f50: 73 69 6f 6e 62 72 61 6e 63 68 63 68 69 6c 64 72  sionbranchchildr
7f60: 65 6e 20 42 0a 09 20 20 20 20 57 48 45 52 45 20  en B..    WHERE 
7f70: 20 52 2e 72 69 64 20 20 20 49 4e 20 24 74 68 65   R.rid   IN $the
7f80: 73 65 74 20 20 20 20 20 2d 2d 20 52 65 73 74 72  set     -- Restr
7f90: 69 63 74 20 74 6f 20 72 65 76 69 73 69 6f 6e 73  ict to revisions
7fa0: 20 6f 66 20 69 6e 74 65 72 65 73 74 0a 09 20 20   of interest..  
7fb0: 20 20 41 4e 44 20 20 20 20 52 2e 72 69 64 20 3d    AND    R.rid =
7fc0: 20 42 2e 72 69 64 20 20 20 20 20 20 20 20 20 20   B.rid          
7fd0: 2d 2d 20 53 65 6c 65 63 74 20 73 75 62 73 65 74  -- Select subset
7fe0: 20 6f 66 20 62 72 61 6e 63 68 20 63 68 69 6c 64   of branch child
7ff0: 72 65 6e 0a 09 20 20 20 20 41 4e 44 20 20 20 20  ren..    AND    
8000: 42 2e 62 72 69 64 20 49 4e 20 24 74 68 65 73 65  B.brid IN $these
8010: 74 20 20 20 20 20 20 2d 2d 20 57 68 69 63 68 20  t      -- Which 
8020: 69 73 20 61 6c 73 6f 20 6f 66 20 69 6e 74 65 72  is also of inter
8030: 65 73 74 0a 20 20 20 20 55 4e 49 4f 4e 0a 20 20  est.    UNION.  
8040: 20 20 2d 2d 20 28 34 29 20 43 68 69 6c 64 20 6f    -- (4) Child o
8050: 66 20 74 72 75 6e 6b 20 72 6f 6f 74 20 73 75 63  f trunk root suc
8060: 63 65 73 73 6f 72 20 6f 66 20 6c 61 73 74 20 4e  cessor of last N
8070: 54 44 42 20 6f 6e 20 74 72 75 6e 6b 2e 0a 09 20  TDB on trunk... 
8080: 20 20 20 53 45 4c 45 43 54 20 52 2e 72 69 64 2c     SELECT R.rid,
8090: 20 52 41 2e 63 68 69 6c 64 0a 09 20 20 20 20 46   RA.child..    F
80a0: 52 4f 4d 20 72 65 76 69 73 69 6f 6e 20 52 2c 20  ROM revision R, 
80b0: 72 65 76 69 73 69 6f 6e 20 52 41 0a 09 20 20 20  revision RA..   
80c0: 20 57 48 45 52 45 20 52 2e 72 69 64 20 20 20 49   WHERE R.rid   I
80d0: 4e 20 24 74 68 65 73 65 74 20 20 20 20 20 20 2d  N $theset      -
80e0: 2d 20 52 65 73 74 72 69 63 74 20 74 6f 20 72 65  - Restrict to re
80f0: 76 69 73 69 6f 6e 73 20 6f 66 20 69 6e 74 65 72  visions of inter
8100: 65 73 74 0a 09 20 20 20 20 41 4e 44 20 20 20 52  est..    AND   R
8110: 2e 69 73 64 65 66 61 75 6c 74 20 20 20 20 20 20  .isdefault      
8120: 20 20 20 20 20 20 20 2d 2d 20 52 65 73 74 72 69         -- Restri
8130: 63 74 20 74 6f 20 4e 54 44 42 0a 09 20 20 20 20  ct to NTDB..    
8140: 41 4e 44 20 20 20 52 2e 64 62 63 68 69 6c 64 20  AND   R.dbchild 
8150: 49 53 20 4e 4f 54 20 4e 55 4c 4c 20 20 20 2d 2d  IS NOT NULL   --
8160: 20 61 6e 64 20 6c 61 73 74 20 4e 54 44 42 20 62   and last NTDB b
8170: 65 6c 6f 6e 67 69 6e 67 20 74 6f 20 74 72 75 6e  elonging to trun
8180: 6b 0a 09 20 20 20 20 41 4e 44 20 20 20 52 41 2e  k..    AND   RA.
8190: 72 69 64 20 3d 20 52 2e 64 62 63 68 69 6c 64 20  rid = R.dbchild 
81a0: 20 20 20 20 20 2d 2d 20 47 6f 20 64 69 72 65 63       -- Go direc
81b0: 74 6c 79 20 74 6f 20 74 72 75 6e 6b 20 72 6f 6f  tly to trunk roo
81c0: 74 0a 09 20 20 20 20 41 4e 44 20 20 20 52 41 2e  t..    AND   RA.
81d0: 63 68 69 6c 64 20 49 53 20 4e 4f 54 20 4e 55 4c  child IS NOT NUL
81e0: 4c 20 20 20 20 2d 2d 20 48 61 73 20 70 72 69 6d  L    -- Has prim
81f0: 61 72 79 20 63 68 69 6c 64 2e 0a 20 20 20 20 20  ary child..     
8200: 20 20 20 20 20 20 20 41 4e 44 20 20 20 52 41 2e         AND   RA.
8210: 63 68 69 6c 64 20 49 4e 20 24 74 68 65 73 65 74  child IN $theset
8220: 20 20 20 20 20 2d 2d 20 57 68 69 63 68 20 69 73       -- Which is
8230: 20 61 6c 73 6f 20 6f 66 20 69 6e 74 65 72 65 73   also of interes
8240: 74 0a 09 7d 5d 5d 20 7b 0a 09 20 20 20 20 23 20  t..}]] {..    # 
8250: 43 6f 6e 73 69 64 65 72 20 6d 6f 76 69 6e 67 20  Consider moving 
8260: 74 68 69 73 20 74 6f 20 74 68 65 20 69 6e 74 65  this to the inte
8270: 67 72 69 74 79 20 6d 6f 64 75 6c 65 2e 0a 09 20  grity module... 
8280: 20 20 20 69 6e 74 65 67 72 69 74 79 20 61 73 73     integrity ass
8290: 65 72 74 20 7b 24 72 69 64 20 21 3d 20 24 63 68  ert {$rid != $ch
82a0: 69 6c 64 7d 20 7b 52 65 76 69 73 69 6f 6e 20 24  ild} {Revision $
82b0: 72 69 64 20 64 65 70 65 6e 64 73 20 6f 6e 20 69  rid depends on i
82c0: 74 73 65 6c 66 2e 7d 0a 09 20 20 20 20 6c 61 70  tself.}..    lap
82d0: 70 65 6e 64 20 64 65 70 65 6e 64 65 6e 63 69 65  pend dependencie
82e0: 73 28 24 72 69 64 29 20 24 63 68 69 6c 64 0a 09  s($rid) $child..
82f0: 20 20 20 20 73 65 74 20 64 65 70 28 24 72 69 64      set dep($rid
8300: 2c 24 63 68 69 6c 64 29 20 2e 0a 09 7d 0a 0a 09  ,$child) ...}...
8310: 23 20 54 68 65 20 73 71 6c 20 73 74 61 74 65 6d  # The sql statem
8320: 65 6e 74 73 20 61 62 6f 76 65 20 6c 6f 6f 6b 73  ents above looks
8330: 20 6f 6e 6c 79 20 66 6f 72 20 64 69 72 65 63 74   only for direct
8340: 20 64 65 70 65 6e 64 65 6e 63 69 65 73 0a 09 23   dependencies..#
8350: 20 62 65 74 77 65 65 6e 20 72 65 76 69 73 69 6f   between revisio
8360: 6e 20 69 6e 20 74 68 65 20 63 68 61 6e 67 65 73  n in the changes
8370: 65 74 2e 20 48 6f 77 65 76 65 72 20 64 75 65 20  et. However due 
8380: 74 6f 20 74 68 65 0a 09 23 20 76 61 67 61 72 69  to the..# vagari
8390: 65 73 20 6f 66 20 6d 65 74 61 20 64 61 74 61 20  es of meta data 
83a0: 69 74 20 69 73 20 70 6f 73 73 69 62 6c 65 20 66  it is possible f
83b0: 6f 72 20 74 77 6f 20 72 65 76 69 73 69 6f 6e 73  or two revisions
83c0: 20 6f 66 0a 09 23 20 74 68 65 20 73 61 6d 65 20   of..# the same 
83d0: 66 69 6c 65 20 74 6f 20 65 6e 64 20 75 70 20 69  file to end up i
83e0: 6e 20 74 68 65 20 73 61 6d 65 20 63 68 61 6e 67  n the same chang
83f0: 65 73 65 74 2c 20 77 69 74 68 6f 75 74 20 61 0a  eset, without a.
8400: 09 23 20 64 69 72 65 63 74 20 64 65 70 65 6e 64  .# direct depend
8410: 65 6e 63 79 20 62 65 74 77 65 65 6e 20 74 68 65  ency between the
8420: 6d 2e 20 48 6f 77 65 76 65 72 20 77 65 20 6b 6e  m. However we kn
8430: 6f 77 20 74 68 61 74 20 74 68 65 72 65 0a 09 23  ow that there..#
8440: 20 68 61 73 20 74 6f 20 62 65 20 61 20 61 6e 20   has to be a an 
8450: 69 6e 64 69 72 65 63 74 20 64 65 70 65 6e 64 65  indirect depende
8460: 6e 63 79 2c 20 62 65 20 69 74 20 74 68 72 6f 75  ncy, be it throu
8470: 67 68 20 70 72 69 6d 61 72 79 0a 09 23 20 63 68  gh primary..# ch
8480: 69 6c 64 72 65 6e 2c 20 62 72 61 6e 63 68 20 63  ildren, branch c
8490: 68 69 6c 64 72 65 6e 2c 20 6f 72 20 61 20 63 6f  hildren, or a co
84a0: 6d 62 69 6e 61 74 69 6f 6e 20 74 68 65 72 65 6f  mbination thereo
84b0: 66 2e 0a 0a 09 23 20 57 65 20 6e 6f 77 20 66 69  f....# We now fi
84c0: 6c 6c 20 69 6e 20 74 68 65 73 65 20 70 73 65 75  ll in these pseu
84d0: 64 6f 2d 64 65 70 65 6e 64 65 6e 63 69 65 73 2c  do-dependencies,
84e0: 20 69 66 20 6e 6f 20 73 75 63 68 0a 09 23 20 64   if no such..# d
84f0: 65 70 65 6e 64 65 6e 63 79 20 65 78 69 73 74 73  ependency exists
8500: 20 61 6c 72 65 61 64 79 2e 20 54 68 65 20 64 69   already. The di
8510: 72 65 63 74 69 6f 6e 20 6f 66 20 74 68 65 20 64  rection of the d
8520: 65 70 65 6e 64 65 6e 63 79 0a 09 23 20 69 73 20  ependency..# is 
8530: 61 63 74 75 61 6c 6c 79 20 69 72 72 65 6c 65 76  actually irrelev
8540: 61 6e 74 20 66 6f 72 20 74 68 69 73 2e 0a 0a 09  ant for this....
8550: 23 20 4e 4f 54 45 3a 20 54 68 69 73 20 69 73 20  # NOTE: This is 
8560: 64 69 66 66 65 72 65 6e 74 20 66 72 6f 6d 20 63  different from c
8570: 76 73 32 73 76 6e 2e 20 4f 75 72 20 73 70 69 72  vs2svn. Our spir
8580: 69 74 75 61 6c 20 61 6e 63 65 73 74 6f 72 0a 09  itual ancestor..
8590: 23 20 64 6f 65 73 20 6e 6f 74 20 75 73 65 20 73  # does not use s
85a0: 75 63 68 20 70 73 65 75 64 6f 2d 64 65 70 65 6e  uch pseudo-depen
85b0: 64 65 6e 63 69 65 73 2c 20 68 6f 77 65 76 65 72  dencies, however
85c0: 20 69 74 20 75 73 65 73 20 61 0a 09 23 20 43 4f   it uses a..# CO
85d0: 4d 4d 49 54 5f 54 48 52 45 53 48 4f 4c 44 2c 20  MMIT_THRESHOLD, 
85e0: 61 20 74 69 6d 65 20 69 6e 74 65 72 76 61 6c 20  a time interval 
85f0: 63 6f 6d 6d 69 74 73 20 73 68 6f 75 6c 64 20 66  commits should f
8600: 61 6c 6c 2e 20 54 68 69 73 0a 09 23 20 77 69 6c  all. This..# wil
8610: 6c 20 67 72 65 61 74 6c 79 20 72 65 64 75 63 65  l greatly reduce
8620: 73 20 74 68 65 20 72 69 73 6b 20 6f 66 20 67 65  s the risk of ge
8630: 74 74 69 6e 67 20 66 61 72 20 73 65 70 61 72 61  tting far separa
8640: 74 65 64 0a 09 23 20 72 65 76 69 73 69 6f 6e 73  ted..# revisions
8650: 20 6f 66 20 74 68 65 20 73 61 6d 65 20 66 69 6c   of the same fil
8660: 65 20 69 6e 74 6f 20 6f 6e 65 20 63 68 61 6e 67  e into one chang
8670: 65 73 65 74 2e 0a 0a 09 23 20 57 65 20 61 6c 6c  eset....# We all
8680: 6f 77 20 72 65 76 69 73 69 6f 6e 73 20 74 6f 20  ow revisions to 
8690: 62 65 20 66 61 72 20 61 70 61 72 74 20 69 6e 20  be far apart in 
86a0: 74 69 6d 65 20 69 6e 20 74 68 65 20 73 61 6d 65  time in the same
86b0: 0a 09 23 20 63 68 61 6e 67 65 73 65 74 2c 20 62  ..# changeset, b
86c0: 75 74 20 69 6e 20 74 75 72 6e 20 6e 65 65 64 20  ut in turn need 
86d0: 74 68 65 20 70 73 65 75 64 6f 2d 64 65 70 65 6e  the pseudo-depen
86e0: 64 65 6e 63 69 65 73 20 74 6f 0a 09 23 20 68 61  dencies to..# ha
86f0: 6e 64 6c 65 20 74 68 69 73 2e 0a 0a 09 61 72 72  ndle this....arr
8700: 61 79 20 73 65 74 20 66 69 64 73 20 7b 7d 0a 09  ay set fids {}..
8710: 66 6f 72 65 61 63 68 20 7b 72 69 64 20 66 69 64  foreach {rid fid
8720: 7d 20 5b 73 74 61 74 65 20 72 75 6e 20 5b 73 75  } [state run [su
8730: 62 73 74 20 2d 6e 6f 63 6f 6d 6d 61 6e 64 73 20  bst -nocommands 
8740: 2d 6e 6f 62 61 63 6b 73 6c 61 73 68 65 73 20 7b  -nobackslashes {
8750: 0a 09 20 20 20 20 53 45 4c 45 43 54 20 52 2e 72  ..    SELECT R.r
8760: 69 64 2c 20 52 2e 66 69 64 0a 20 20 20 20 20 20  id, R.fid.      
8770: 20 20 20 20 20 20 46 52 4f 4d 20 20 20 72 65 76        FROM   rev
8780: 69 73 69 6f 6e 20 52 0a 20 20 20 20 20 20 20 20  ision R.        
8790: 20 20 20 20 57 48 45 52 45 20 20 52 2e 72 69 64      WHERE  R.rid
87a0: 20 49 4e 20 24 74 68 65 73 65 74 0a 09 7d 5d 5d   IN $theset..}]]
87b0: 20 7b 20 6c 61 70 70 65 6e 64 20 66 69 64 73 28   { lappend fids(
87c0: 24 66 69 64 29 20 24 72 69 64 20 7d 0a 0a 09 66  $fid) $rid }...f
87d0: 6f 72 65 61 63 68 20 7b 66 69 64 20 72 69 64 73  oreach {fid rids
87e0: 7d 20 5b 61 72 72 61 79 20 67 65 74 20 66 69 64  } [array get fid
87f0: 73 5d 20 7b 0a 09 20 20 20 20 69 66 20 7b 5b 6c  s] {..    if {[l
8800: 6c 65 6e 67 74 68 20 24 72 69 64 73 5d 20 3c 20  length $rids] < 
8810: 32 7d 20 63 6f 6e 74 69 6e 75 65 0a 09 20 20 20  2} continue..   
8820: 20 66 6f 72 65 61 63 68 20 61 20 24 72 69 64 73   foreach a $rids
8830: 20 7b 0a 09 09 66 6f 72 65 61 63 68 20 62 20 24   {...foreach b $
8840: 72 69 64 73 20 7b 0a 09 09 20 20 20 20 69 66 20  rids {...    if 
8850: 7b 24 61 20 3d 3d 20 24 62 7d 20 63 6f 6e 74 69  {$a == $b} conti
8860: 6e 75 65 0a 09 09 20 20 20 20 69 66 20 7b 5b 69  nue...    if {[i
8870: 6e 66 6f 20 65 78 69 73 74 73 20 64 65 70 28 24  nfo exists dep($
8880: 61 2c 24 62 29 5d 7d 20 63 6f 6e 74 69 6e 75 65  a,$b)]} continue
8890: 0a 09 09 20 20 20 20 69 66 20 7b 5b 69 6e 66 6f  ...    if {[info
88a0: 20 65 78 69 73 74 73 20 64 65 70 28 24 62 2c 24   exists dep($b,$
88b0: 61 29 5d 7d 20 63 6f 6e 74 69 6e 75 65 0a 09 09  a)]} continue...
88c0: 20 20 20 20 6c 61 70 70 65 6e 64 20 64 65 70 65      lappend depe
88d0: 6e 64 65 6e 63 69 65 73 28 24 61 29 20 24 62 0a  ndencies($a) $b.
88e0: 09 09 20 20 20 20 73 65 74 20 64 65 70 28 24 61  ..    set dep($a
88f0: 2c 24 62 29 20 2e 0a 09 09 20 20 20 20 73 65 74  ,$b) ....    set
8900: 20 64 65 70 28 24 62 2c 24 61 29 20 2e 0a 09 09   dep($b,$a) ....
8910: 7d 0a 09 20 20 20 20 7d 0a 09 7d 0a 09 72 65 74  }..    }..}..ret
8920: 75 72 6e 0a 20 20 20 20 7d 0a 0a 20 20 20 20 23  urn.    }..    #
8930: 20 72 65 73 75 6c 74 20 3d 20 34 2d 6c 69 73 74   result = 4-list
8940: 20 28 69 74 65 6d 74 79 70 65 20 69 74 65 6d 69   (itemtype itemi
8950: 64 20 6e 65 78 74 69 74 65 6d 74 79 70 65 20 6e  d nextitemtype n
8960: 65 78 74 69 74 65 6d 69 64 20 2e 2e 2e 29 0a 20  extitemid ...). 
8970: 20 20 20 74 79 70 65 6d 65 74 68 6f 64 20 6c 6f     typemethod lo
8980: 6f 70 73 20 7b 72 65 76 69 73 69 6f 6e 73 7d 20  ops {revisions} 
8990: 7b 0a 09 23 20 4e 6f 74 65 3a 20 54 61 67 73 20  {..# Note: Tags 
89a0: 61 6e 64 20 62 72 61 6e 63 68 65 73 20 63 61 6e  and branches can
89b0: 6e 6f 74 20 63 61 75 73 65 20 74 68 65 20 6c 6f  not cause the lo
89c0: 6f 70 2e 20 54 68 65 69 72 20 69 64 27 73 2c 0a  op. Their id's,.
89d0: 09 23 20 62 65 69 6e 67 20 6f 66 20 61 20 66 75  .# being of a fu
89e0: 6e 64 61 6d 65 6e 74 61 6c 6c 79 20 64 69 66 66  ndamentally diff
89f0: 65 72 65 6e 74 20 74 79 70 65 20 74 68 61 6e 20  erent type than 
8a00: 74 68 65 20 72 65 76 69 73 69 6f 6e 73 0a 09 23  the revisions..#
8a10: 20 63 6f 6d 69 6e 67 20 69 6e 20 63 61 6e 6e 6f   coming in canno
8a20: 74 20 62 65 20 69 6e 20 74 68 65 20 73 65 74 2e  t be in the set.
8a30: 0a 0a 09 73 65 74 20 74 68 65 73 65 74 20 28 27  ...set theset ('
8a40: 5b 6a 6f 69 6e 20 24 72 65 76 69 73 69 6f 6e 73  [join $revisions
8a50: 20 7b 27 2c 27 7d 5d 27 29 0a 09 72 65 74 75 72   {','}]')..retur
8a60: 6e 20 5b 73 74 61 74 65 20 72 75 6e 20 5b 73 75  n [state run [su
8a70: 62 73 74 20 2d 6e 6f 63 6f 6d 6d 61 6e 64 73 20  bst -nocommands 
8a80: 2d 6e 6f 62 61 63 6b 73 6c 61 73 68 65 73 20 7b  -nobackslashes {
8a90: 0a 09 20 20 20 20 2d 2d 20 28 31 29 20 50 72 69  ..    -- (1) Pri
8aa0: 6d 61 72 79 20 63 68 69 6c 64 0a 09 20 20 20 20  mary child..    
8ab0: 53 45 4c 45 43 54 20 52 2e 72 69 64 2c 20 52 2e  SELECT R.rid, R.
8ac0: 63 68 69 6c 64 0a 09 20 20 20 20 46 52 4f 4d 20  child..    FROM 
8ad0: 20 20 72 65 76 69 73 69 6f 6e 20 52 0a 09 20 20    revision R..  
8ae0: 20 20 57 48 45 52 45 20 20 52 2e 72 69 64 20 20    WHERE  R.rid  
8af0: 20 49 4e 20 24 74 68 65 73 65 74 20 20 20 20 20   IN $theset     
8b00: 2d 2d 20 52 65 73 74 72 69 63 74 20 74 6f 20 72  -- Restrict to r
8b10: 65 76 69 73 69 6f 6e 73 20 6f 66 20 69 6e 74 65  evisions of inte
8b20: 72 65 73 74 0a 09 20 20 20 20 41 4e 44 20 20 20  rest..    AND   
8b30: 20 52 2e 63 68 69 6c 64 20 49 53 20 4e 4f 54 20   R.child IS NOT 
8b40: 4e 55 4c 4c 20 20 20 20 2d 2d 20 48 61 73 20 70  NULL    -- Has p
8b50: 72 69 6d 61 72 79 20 63 68 69 6c 64 0a 09 20 20  rimary child..  
8b60: 20 20 41 4e 44 20 20 20 20 52 2e 63 68 69 6c 64    AND    R.child
8b70: 20 49 4e 20 24 74 68 65 73 65 74 20 20 20 20 20   IN $theset     
8b80: 2d 2d 20 4c 6f 6f 70 0a 09 20 20 20 20 2d 2d 0a  -- Loop..    --.
8b90: 09 20 20 20 20 55 4e 49 4f 4e 0a 09 20 20 20 20  .    UNION..    
8ba0: 2d 2d 20 28 32 29 20 53 65 63 6f 6e 64 61 72 79  -- (2) Secondary
8bb0: 20 28 62 72 61 6e 63 68 29 20 63 68 69 6c 64 72   (branch) childr
8bc0: 65 6e 0a 09 20 20 20 20 53 45 4c 45 43 54 20 52  en..    SELECT R
8bd0: 2e 72 69 64 2c 20 42 2e 62 72 69 64 0a 09 20 20  .rid, B.brid..  
8be0: 20 20 46 52 4f 4d 20 20 20 72 65 76 69 73 69 6f    FROM   revisio
8bf0: 6e 20 52 2c 20 72 65 76 69 73 69 6f 6e 62 72 61  n R, revisionbra
8c00: 6e 63 68 63 68 69 6c 64 72 65 6e 20 42 0a 09 20  nchchildren B.. 
8c10: 20 20 20 57 48 45 52 45 20 20 52 2e 72 69 64 20     WHERE  R.rid 
8c20: 20 20 49 4e 20 24 74 68 65 73 65 74 20 20 20 20    IN $theset    
8c30: 20 2d 2d 20 52 65 73 74 72 69 63 74 20 74 6f 20   -- Restrict to 
8c40: 72 65 76 69 73 69 6f 6e 73 20 6f 66 20 69 6e 74  revisions of int
8c50: 65 72 65 73 74 0a 09 20 20 20 20 41 4e 44 20 20  erest..    AND  
8c60: 20 20 52 2e 72 69 64 20 3d 20 42 2e 72 69 64 20    R.rid = B.rid 
8c70: 20 20 20 20 20 20 20 20 20 2d 2d 20 53 65 6c 65           -- Sele
8c80: 63 74 20 73 75 62 73 65 74 20 6f 66 20 62 72 61  ct subset of bra
8c90: 6e 63 68 20 63 68 69 6c 64 72 65 6e 0a 09 20 20  nch children..  
8ca0: 20 20 41 4e 44 20 20 20 20 42 2e 72 69 64 20 20    AND    B.rid  
8cb0: 20 49 4e 20 24 74 68 65 73 65 74 20 20 20 20 20   IN $theset     
8cc0: 2d 2d 20 4c 6f 6f 70 0a 09 20 20 20 20 2d 2d 0a  -- Loop..    --.
8cd0: 09 20 20 20 20 55 4e 49 4f 4e 0a 09 20 20 20 20  .    UNION..    
8ce0: 2d 2d 20 28 34 29 20 43 68 69 6c 64 20 6f 66 20  -- (4) Child of 
8cf0: 74 72 75 6e 6b 20 72 6f 6f 74 20 73 75 63 63 65  trunk root succe
8d00: 73 73 6f 72 20 6f 66 20 6c 61 73 74 20 4e 54 44  ssor of last NTD
8d10: 42 20 6f 6e 20 74 72 75 6e 6b 2e 0a 09 20 20 20  B on trunk...   
8d20: 20 53 45 4c 45 43 54 20 52 2e 72 69 64 2c 20 52   SELECT R.rid, R
8d30: 41 2e 63 68 69 6c 64 0a 09 20 20 20 20 46 52 4f  A.child..    FRO
8d40: 4d 20 20 20 72 65 76 69 73 69 6f 6e 20 52 2c 20  M   revision R, 
8d50: 72 65 76 69 73 69 6f 6e 20 52 41 0a 09 20 20 20  revision RA..   
8d60: 20 57 48 45 52 45 20 20 52 2e 72 69 64 20 20 20   WHERE  R.rid   
8d70: 20 49 4e 20 24 74 68 65 73 65 74 20 20 20 20 20   IN $theset     
8d80: 2d 2d 20 52 65 73 74 72 69 63 74 20 74 6f 20 72  -- Restrict to r
8d90: 65 76 69 73 69 6f 6e 73 20 6f 66 20 69 6e 74 65  evisions of inte
8da0: 72 65 73 74 0a 09 20 20 20 20 41 4e 44 20 20 20  rest..    AND   
8db0: 20 52 2e 69 73 64 65 66 61 75 6c 74 20 20 20 20   R.isdefault    
8dc0: 20 20 20 20 20 20 20 20 20 2d 2d 20 52 65 73 74           -- Rest
8dd0: 72 69 63 74 20 74 6f 20 4e 54 44 42 0a 09 20 20  rict to NTDB..  
8de0: 20 20 41 4e 44 20 20 20 20 52 2e 64 62 63 68 69    AND    R.dbchi
8df0: 6c 64 20 49 53 20 4e 4f 54 20 4e 55 4c 4c 20 20  ld IS NOT NULL  
8e00: 20 2d 2d 20 61 6e 64 20 6c 61 73 74 20 4e 54 44   -- and last NTD
8e10: 42 20 62 65 6c 6f 6e 67 69 6e 67 20 74 6f 20 74  B belonging to t
8e20: 72 75 6e 6b 0a 09 20 20 20 20 41 4e 44 20 20 20  runk..    AND   
8e30: 20 52 41 2e 72 69 64 20 3d 20 52 2e 64 62 63 68   RA.rid = R.dbch
8e40: 69 6c 64 20 20 20 20 20 20 2d 2d 20 47 6f 20 64  ild      -- Go d
8e50: 69 72 65 63 74 6c 79 20 74 6f 20 74 72 75 6e 6b  irectly to trunk
8e60: 20 72 6f 6f 74 0a 09 20 20 20 20 41 4e 44 20 20   root..    AND  
8e70: 20 20 52 41 2e 63 68 69 6c 64 20 49 53 20 4e 4f    RA.child IS NO
8e80: 54 20 4e 55 4c 4c 20 20 20 20 2d 2d 20 48 61 73  T NULL    -- Has
8e90: 20 70 72 69 6d 61 72 79 20 63 68 69 6c 64 2e 0a   primary child..
8ea0: 09 20 20 20 20 41 4e 44 20 20 20 20 52 41 2e 63  .    AND    RA.c
8eb0: 68 69 6c 64 20 49 4e 20 24 74 68 65 73 65 74 20  hild IN $theset 
8ec0: 20 20 20 20 2d 2d 20 4c 6f 6f 70 0a 09 7d 5d 5d      -- Loop..}]]
8ed0: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 23 20 76 61  .    }..    # va
8ee0: 72 28 64 76 29 20 3d 20 64 69 63 74 20 28 69 74  r(dv) = dict (it
8ef0: 65 6d 20 2d 3e 20 6c 69 73 74 20 28 69 74 65 6d  em -> list (item
8f00: 29 29 2c 20 69 74 65 6d 20 20 3d 20 6c 69 73 74  )), item  = list
8f10: 20 28 74 79 70 65 20 69 64 29 0a 20 20 20 20 74   (type id).    t
8f20: 79 70 65 6d 65 74 68 6f 64 20 73 75 63 63 65 73  ypemethod succes
8f30: 73 6f 72 73 20 7b 64 76 20 72 65 76 69 73 69 6f  sors {dv revisio
8f40: 6e 73 7d 20 7b 0a 09 75 70 76 61 72 20 31 20 24  ns} {..upvar 1 $
8f50: 64 76 20 64 65 70 65 6e 64 65 6e 63 69 65 73 0a  dv dependencies.
8f60: 09 73 65 74 20 74 68 65 73 65 74 20 28 27 5b 6a  .set theset ('[j
8f70: 6f 69 6e 20 24 72 65 76 69 73 69 6f 6e 73 20 7b  oin $revisions {
8f80: 27 2c 27 7d 5d 27 29 0a 0a 09 23 20 54 68 65 20  ','}]')...# The 
8f90: 66 6f 6c 6c 6f 77 69 6e 67 20 63 61 73 65 73 20  following cases 
8fa0: 73 70 65 63 69 66 79 20 77 68 65 6e 20 61 20 72  specify when a r
8fb0: 65 76 69 73 69 6f 6e 20 53 20 69 73 20 61 20 73  evision S is a s
8fc0: 75 63 63 65 73 73 6f 72 0a 09 23 20 6f 66 20 61  uccessor..# of a
8fd0: 20 72 65 76 69 73 69 6f 6e 20 52 2e 20 45 61 63   revision R. Eac
8fe0: 68 20 6f 66 20 74 68 65 20 63 61 73 65 73 20 74  h of the cases t
8ff0: 72 61 6e 73 6c 61 74 65 73 20 69 6e 74 6f 20 6f  ranslates into o
9000: 6e 65 20 6f 66 0a 09 23 20 74 68 65 20 62 72 61  ne of..# the bra
9010: 6e 63 68 65 73 20 6f 66 20 74 68 65 20 53 51 4c  nches of the SQL
9020: 20 55 4e 49 4f 4e 20 63 6f 6d 69 6e 67 20 62 65   UNION coming be
9030: 6c 6f 77 2e 0a 09 23 0a 09 23 20 28 31 29 20 53  low...#..# (1) S
9040: 20 63 61 6e 20 62 65 20 61 20 70 72 69 6d 61 72   can be a primar
9050: 79 20 63 68 69 6c 64 20 6f 66 20 52 2c 20 69 2e  y child of R, i.
9060: 65 2e 20 69 6e 20 74 68 65 20 73 61 6d 65 20 4c  e. in the same L
9070: 4f 44 2e 20 52 0a 09 23 20 20 20 20 20 72 65 66  OD. R..#     ref
9080: 65 72 65 6e 63 65 73 20 53 20 64 69 72 65 63 74  erences S direct
9090: 6c 79 2e 20 52 2e 63 68 69 6c 64 20 3d 20 53 28  ly. R.child = S(
90a0: 2e 72 69 64 29 2c 20 69 66 20 69 74 20 65 78 69  .rid), if it exi
90b0: 73 74 73 2e 0a 09 23 0a 09 23 20 28 32 29 20 53  sts...#..# (2) S
90c0: 20 63 61 6e 20 62 65 20 61 20 73 65 63 6f 6e 64   can be a second
90d0: 61 72 79 2c 20 69 2e 65 2e 20 62 72 61 6e 63 68  ary, i.e. branch
90e0: 2c 20 63 68 69 6c 64 20 6f 66 20 52 2e 20 48 65  , child of R. He
90f0: 72 65 20 74 68 65 0a 09 23 20 20 20 20 20 6c 69  re the..#     li
9100: 6e 6b 20 69 73 20 6d 61 64 65 20 74 68 72 6f 75  nk is made throu
9110: 67 68 20 74 68 65 20 68 65 6c 70 65 72 20 74 61  gh the helper ta
9120: 62 6c 65 0a 09 23 20 20 20 20 20 52 45 56 49 53  ble..#     REVIS
9130: 49 4f 4e 42 52 41 4e 43 48 43 48 49 4c 44 52 45  IONBRANCHCHILDRE
9140: 4e 2e 20 52 2e 72 69 64 20 2d 3e 20 52 42 43 2e  N. R.rid -> RBC.
9150: 72 69 64 2c 20 52 42 43 2e 62 72 69 64 20 3d 0a  rid, RBC.brid =.
9160: 09 23 20 20 20 20 20 53 28 2e 72 69 64 29 0a 09  .#     S(.rid)..
9170: 23 0a 09 23 20 28 33 29 20 4f 72 69 67 69 6e 61  #..# (3) Origina
9180: 6c 6c 79 20 74 68 69 73 20 75 73 65 20 63 61 73  lly this use cas
9190: 65 20 64 65 66 69 6e 65 64 20 74 68 65 20 72 6f  e defined the ro
91a0: 6f 74 20 6f 66 20 61 20 64 65 74 61 63 68 65 64  ot of a detached
91b0: 0a 09 23 20 20 20 20 20 4e 54 44 42 20 61 73 20  ..#     NTDB as 
91c0: 74 68 65 20 73 75 63 63 65 73 73 6f 72 20 6f 66  the successor of
91d0: 20 74 68 65 20 74 72 75 6e 6b 20 72 6f 6f 74 2e   the trunk root.
91e0: 20 54 68 69 73 20 6c 65 61 64 73 20 74 6f 20 61   This leads to a
91f0: 0a 09 23 20 20 20 20 20 62 61 64 20 74 61 6e 67  ..#     bad tang
9200: 6c 65 20 6c 61 74 65 72 20 6f 6e 2e 20 57 69 74  le later on. Wit
9210: 68 20 61 20 64 65 74 61 63 68 65 64 20 4e 54 44  h a detached NTD
9220: 42 20 74 68 65 20 6f 72 69 67 69 6e 61 6c 0a 09  B the original..
9230: 23 20 20 20 20 20 74 72 75 6e 6b 20 72 6f 6f 74  #     trunk root
9240: 20 72 65 76 69 73 69 6f 6e 20 77 61 73 20 72 65   revision was re
9250: 6d 6f 76 65 64 20 61 73 20 69 72 72 65 6c 65 76  moved as irrelev
9260: 61 6e 74 2c 20 61 6c 6c 6f 77 69 6e 67 0a 09 23  ant, allowing..#
9270: 20 20 20 20 20 74 68 65 20 6e 6f 6d 69 6e 61 6c       the nominal
9280: 20 72 6f 6f 74 20 74 6f 20 62 65 20 6c 61 74 65   root to be late
9290: 72 20 69 6e 20 74 69 6d 65 20 74 68 61 6e 20 74  r in time than t
92a0: 68 65 20 4e 54 44 42 0a 09 23 20 20 20 20 20 72  he NTDB..#     r
92b0: 6f 6f 74 2e 20 4e 6f 77 20 73 65 74 74 69 6e 67  oot. Now setting
92c0: 20 74 68 69 73 20 64 65 70 65 6e 64 65 6e 63 79   this dependency
92d0: 20 77 69 6c 6c 20 62 65 20 62 61 63 6b 77 61 72   will be backwar
92e0: 64 20 69 6e 0a 09 23 20 20 20 20 20 74 69 6d 65  d in..#     time
92f0: 2e 20 52 45 4d 4f 56 45 44 2e 0a 09 23 0a 09 23  . REMOVED...#..#
9300: 20 28 34 29 20 49 66 20 52 20 69 73 20 74 68 65   (4) If R is the
9310: 20 6c 61 73 74 20 6f 66 20 74 68 65 20 4e 54 44   last of the NTD
9320: 42 20 72 65 76 69 73 69 6f 6e 73 20 77 68 69 63  B revisions whic
9330: 68 20 62 65 6c 6f 6e 67 20 74 6f 0a 09 23 20 20  h belong to..#  
9340: 20 20 20 74 68 65 20 74 72 75 6e 6b 2c 20 74 68     the trunk, th
9350: 65 6e 20 74 68 65 20 70 72 69 6d 61 72 79 20 63  en the primary c
9360: 68 69 6c 64 20 6f 66 20 74 68 65 20 74 72 75 6e  hild of the trun
9370: 6b 20 72 6f 6f 74 20 28 74 68 65 0a 09 23 20 20  k root (the..#  
9380: 20 20 20 27 31 2e 32 27 20 72 65 76 69 73 69 6f     '1.2' revisio
9390: 6e 29 20 69 73 20 61 20 73 75 63 63 65 73 73 6f  n) is a successo
93a0: 72 2c 20 69 66 20 69 74 20 65 78 69 73 74 73 2e  r, if it exists.
93b0: 0a 0a 09 23 20 4e 6f 74 65 20 74 68 61 74 20 74  ...# Note that t
93c0: 68 65 20 62 72 61 6e 63 68 65 73 20 73 70 61 77  he branches spaw
93d0: 6e 65 64 20 66 72 6f 6d 20 74 68 65 20 72 65 76  ned from the rev
93e0: 69 73 69 6f 6e 73 2c 20 61 6e 64 20 74 68 65 0a  isions, and the.
93f0: 09 23 20 74 61 67 73 20 61 73 73 6f 63 69 61 74  .# tags associat
9400: 65 64 20 77 69 74 68 20 74 68 65 6d 20 61 72 65  ed with them are
9410: 20 73 75 63 63 65 73 73 6f 72 73 20 61 73 20 77   successors as w
9420: 65 6c 6c 2e 0a 0a 09 66 6f 72 65 61 63 68 20 7b  ell....foreach {
9430: 72 69 64 20 63 68 69 6c 64 7d 20 5b 73 74 61 74  rid child} [stat
9440: 65 20 72 75 6e 20 5b 73 75 62 73 74 20 2d 6e 6f  e run [subst -no
9450: 63 6f 6d 6d 61 6e 64 73 20 2d 6e 6f 62 61 63 6b  commands -noback
9460: 73 6c 61 73 68 65 73 20 7b 0a 20 20 20 20 2d 2d  slashes {.    --
9470: 20 28 31 29 20 50 72 69 6d 61 72 79 20 63 68 69   (1) Primary chi
9480: 6c 64 0a 09 20 20 20 20 53 45 4c 45 43 54 20 52  ld..    SELECT R
9490: 2e 72 69 64 2c 20 52 2e 63 68 69 6c 64 0a 09 20  .rid, R.child.. 
94a0: 20 20 20 46 52 4f 4d 20 20 20 72 65 76 69 73 69     FROM   revisi
94b0: 6f 6e 20 52 0a 09 20 20 20 20 57 48 45 52 45 20  on R..    WHERE 
94c0: 20 52 2e 72 69 64 20 20 20 49 4e 20 24 74 68 65   R.rid   IN $the
94d0: 73 65 74 20 20 20 20 20 2d 2d 20 52 65 73 74 72  set     -- Restr
94e0: 69 63 74 20 74 6f 20 72 65 76 69 73 69 6f 6e 73  ict to revisions
94f0: 20 6f 66 20 69 6e 74 65 72 65 73 74 0a 09 20 20   of interest..  
9500: 20 20 41 4e 44 20 20 20 20 52 2e 63 68 69 6c 64    AND    R.child
9510: 20 49 53 20 4e 4f 54 20 4e 55 4c 4c 20 20 20 20   IS NOT NULL    
9520: 2d 2d 20 48 61 73 20 70 72 69 6d 61 72 79 20 63  -- Has primary c
9530: 68 69 6c 64 0a 20 20 20 20 55 4e 49 4f 4e 0a 20  hild.    UNION. 
9540: 20 20 20 2d 2d 20 28 32 29 20 53 65 63 6f 6e 64     -- (2) Second
9550: 61 72 79 20 28 62 72 61 6e 63 68 29 20 63 68 69  ary (branch) chi
9560: 6c 64 72 65 6e 0a 09 20 20 20 20 53 45 4c 45 43  ldren..    SELEC
9570: 54 20 52 2e 72 69 64 2c 20 42 2e 62 72 69 64 0a  T R.rid, B.brid.
9580: 09 20 20 20 20 46 52 4f 4d 20 20 20 72 65 76 69  .    FROM   revi
9590: 73 69 6f 6e 20 52 2c 20 72 65 76 69 73 69 6f 6e  sion R, revision
95a0: 62 72 61 6e 63 68 63 68 69 6c 64 72 65 6e 20 42  branchchildren B
95b0: 0a 09 20 20 20 20 57 48 45 52 45 20 20 52 2e 72  ..    WHERE  R.r
95c0: 69 64 20 20 20 49 4e 20 24 74 68 65 73 65 74 20  id   IN $theset 
95d0: 20 20 20 20 2d 2d 20 52 65 73 74 72 69 63 74 20      -- Restrict 
95e0: 74 6f 20 72 65 76 69 73 69 6f 6e 73 20 6f 66 20  to revisions of 
95f0: 69 6e 74 65 72 65 73 74 0a 09 20 20 20 20 41 4e  interest..    AN
9600: 44 20 20 20 20 52 2e 72 69 64 20 3d 20 42 2e 72  D    R.rid = B.r
9610: 69 64 20 20 20 20 20 20 20 20 20 20 2d 2d 20 53  id          -- S
9620: 65 6c 65 63 74 20 73 75 62 73 65 74 20 6f 66 20  elect subset of 
9630: 62 72 61 6e 63 68 20 63 68 69 6c 64 72 65 6e 0a  branch children.
9640: 20 20 20 20 55 4e 49 4f 4e 0a 20 20 20 20 2d 2d      UNION.    --
9650: 20 28 34 29 20 43 68 69 6c 64 20 6f 66 20 74 72   (4) Child of tr
9660: 75 6e 6b 20 72 6f 6f 74 20 73 75 63 63 65 73 73  unk root success
9670: 6f 72 20 6f 66 20 6c 61 73 74 20 4e 54 44 42 20  or of last NTDB 
9680: 6f 6e 20 74 72 75 6e 6b 2e 0a 09 20 20 20 20 53  on trunk...    S
9690: 45 4c 45 43 54 20 52 2e 72 69 64 2c 20 52 41 2e  ELECT R.rid, RA.
96a0: 63 68 69 6c 64 0a 09 20 20 20 20 46 52 4f 4d 20  child..    FROM 
96b0: 72 65 76 69 73 69 6f 6e 20 52 2c 20 72 65 76 69  revision R, revi
96c0: 73 69 6f 6e 20 52 41 0a 09 20 20 20 20 57 48 45  sion RA..    WHE
96d0: 52 45 20 52 2e 72 69 64 20 20 20 49 4e 20 24 74  RE R.rid   IN $t
96e0: 68 65 73 65 74 20 20 20 20 20 20 2d 2d 20 52 65  heset      -- Re
96f0: 73 74 72 69 63 74 20 74 6f 20 72 65 76 69 73 69  strict to revisi
9700: 6f 6e 73 20 6f 66 20 69 6e 74 65 72 65 73 74 0a  ons of interest.
9710: 09 20 20 20 20 41 4e 44 20 20 20 52 2e 69 73 64  .    AND   R.isd
9720: 65 66 61 75 6c 74 20 20 20 20 20 20 20 20 20 20  efault          
9730: 20 20 20 2d 2d 20 52 65 73 74 72 69 63 74 20 74     -- Restrict t
9740: 6f 20 4e 54 44 42 0a 09 20 20 20 20 41 4e 44 20  o NTDB..    AND 
9750: 20 20 52 2e 64 62 63 68 69 6c 64 20 49 53 20 4e    R.dbchild IS N
9760: 4f 54 20 4e 55 4c 4c 20 20 20 2d 2d 20 61 6e 64  OT NULL   -- and
9770: 20 6c 61 73 74 20 4e 54 44 42 20 62 65 6c 6f 6e   last NTDB belon
9780: 67 69 6e 67 20 74 6f 20 74 72 75 6e 6b 0a 09 20  ging to trunk.. 
9790: 20 20 20 41 4e 44 20 20 20 52 41 2e 72 69 64 20     AND   RA.rid 
97a0: 3d 20 52 2e 64 62 63 68 69 6c 64 20 20 20 20 20  = R.dbchild     
97b0: 20 2d 2d 20 47 6f 20 64 69 72 65 63 74 6c 79 20   -- Go directly 
97c0: 74 6f 20 74 72 75 6e 6b 20 72 6f 6f 74 0a 09 20  to trunk root.. 
97d0: 20 20 20 41 4e 44 20 20 20 52 41 2e 63 68 69 6c     AND   RA.chil
97e0: 64 20 49 53 20 4e 4f 54 20 4e 55 4c 4c 20 20 20  d IS NOT NULL   
97f0: 20 2d 2d 20 48 61 73 20 70 72 69 6d 61 72 79 20   -- Has primary 
9800: 63 68 69 6c 64 2e 0a 09 7d 5d 5d 20 7b 0a 09 20  child...}]] {.. 
9810: 20 20 20 23 20 43 6f 6e 73 69 64 65 72 20 6d 6f     # Consider mo
9820: 76 69 6e 67 20 74 68 69 73 20 74 6f 20 74 68 65  ving this to the
9830: 20 69 6e 74 65 67 72 69 74 79 20 6d 6f 64 75 6c   integrity modul
9840: 65 2e 0a 09 20 20 20 20 69 6e 74 65 67 72 69 74  e...    integrit
9850: 79 20 61 73 73 65 72 74 20 7b 24 72 69 64 20 21  y assert {$rid !
9860: 3d 20 24 63 68 69 6c 64 7d 20 7b 52 65 76 69 73  = $child} {Revis
9870: 69 6f 6e 20 24 72 69 64 20 64 65 70 65 6e 64 73  ion $rid depends
9880: 20 6f 6e 20 69 74 73 65 6c 66 2e 7d 0a 09 20 20   on itself.}..  
9890: 20 20 6c 61 70 70 65 6e 64 20 64 65 70 65 6e 64    lappend depend
98a0: 65 6e 63 69 65 73 28 5b 6c 69 73 74 20 72 65 76  encies([list rev
98b0: 20 24 72 69 64 5d 29 20 5b 6c 69 73 74 20 72 65   $rid]) [list re
98c0: 76 20 24 63 68 69 6c 64 5d 0a 09 7d 0a 09 66 6f  v $child]..}..fo
98d0: 72 65 61 63 68 20 7b 72 69 64 20 63 68 69 6c 64  reach {rid child
98e0: 7d 20 5b 73 74 61 74 65 20 72 75 6e 20 5b 73 75  } [state run [su
98f0: 62 73 74 20 2d 6e 6f 63 6f 6d 6d 61 6e 64 73 20  bst -nocommands 
9900: 2d 6e 6f 62 61 63 6b 73 6c 61 73 68 65 73 20 7b  -nobackslashes {
9910: 0a 09 20 20 20 20 53 45 4c 45 43 54 20 52 2e 72  ..    SELECT R.r
9920: 69 64 2c 20 54 2e 74 69 64 0a 09 20 20 20 20 46  id, T.tid..    F
9930: 52 4f 4d 20 20 20 72 65 76 69 73 69 6f 6e 20 52  ROM   revision R
9940: 2c 20 74 61 67 20 54 0a 09 20 20 20 20 57 48 45  , tag T..    WHE
9950: 52 45 20 20 52 2e 72 69 64 20 49 4e 20 24 74 68  RE  R.rid IN $th
9960: 65 73 65 74 20 20 20 20 20 20 20 2d 2d 20 52 65  eset       -- Re
9970: 73 74 72 69 63 74 20 74 6f 20 72 65 76 69 73 69  strict to revisi
9980: 6f 6e 73 20 6f 66 20 69 6e 74 65 72 65 73 74 0a  ons of interest.
9990: 09 20 20 20 20 41 4e 44 20 20 20 20 54 2e 72 65  .    AND    T.re
99a0: 76 20 3d 20 52 2e 72 69 64 20 20 20 20 20 20 20  v = R.rid       
99b0: 20 20 20 2d 2d 20 53 65 6c 65 63 74 20 74 61 67     -- Select tag
99c0: 73 20 61 74 74 61 63 68 65 64 20 74 6f 20 74 68  s attached to th
99d0: 65 6d 0a 09 7d 5d 5d 20 7b 0a 09 20 20 20 20 6c  em..}]] {..    l
99e0: 61 70 70 65 6e 64 20 64 65 70 65 6e 64 65 6e 63  append dependenc
99f0: 69 65 73 28 5b 6c 69 73 74 20 72 65 76 20 24 72  ies([list rev $r
9a00: 69 64 5d 29 20 5b 6c 69 73 74 20 73 79 6d 3a 3a  id]) [list sym::
9a10: 74 61 67 20 24 63 68 69 6c 64 5d 0a 09 7d 0a 09  tag $child]..}..
9a20: 66 6f 72 65 61 63 68 20 7b 72 69 64 20 63 68 69  foreach {rid chi
9a30: 6c 64 7d 20 5b 73 74 61 74 65 20 72 75 6e 20 5b  ld} [state run [
9a40: 73 75 62 73 74 20 2d 6e 6f 63 6f 6d 6d 61 6e 64  subst -nocommand
9a50: 73 20 2d 6e 6f 62 61 63 6b 73 6c 61 73 68 65 73  s -nobackslashes
9a60: 20 7b 0a 09 20 20 20 20 53 45 4c 45 43 54 20 52   {..    SELECT R
9a70: 2e 72 69 64 2c 20 42 2e 62 69 64 0a 09 20 20 20  .rid, B.bid..   
9a80: 20 46 52 4f 4d 20 20 20 72 65 76 69 73 69 6f 6e   FROM   revision
9a90: 20 52 2c 20 62 72 61 6e 63 68 20 42 0a 09 20 20   R, branch B..  
9aa0: 20 20 57 48 45 52 45 20 20 52 2e 72 69 64 20 49    WHERE  R.rid I
9ab0: 4e 20 24 74 68 65 73 65 74 20 20 20 20 20 20 20  N $theset       
9ac0: 2d 2d 20 52 65 73 74 72 69 63 74 20 74 6f 20 72  -- Restrict to r
9ad0: 65 76 69 73 69 6f 6e 73 20 6f 66 20 69 6e 74 65  evisions of inte
9ae0: 72 65 73 74 0a 09 20 20 20 20 41 4e 44 20 20 20  rest..    AND   
9af0: 20 42 2e 72 6f 6f 74 20 3d 20 52 2e 72 69 64 20   B.root = R.rid 
9b00: 20 20 20 20 20 20 20 20 2d 2d 20 53 65 6c 65 63          -- Selec
9b10: 74 20 62 72 61 6e 63 68 65 73 20 61 74 74 61 63  t branches attac
9b20: 68 65 64 20 74 6f 20 74 68 65 6d 0a 09 7d 5d 5d  hed to them..}]]
9b30: 20 7b 0a 09 20 20 20 20 6c 61 70 70 65 6e 64 20   {..    lappend 
9b40: 64 65 70 65 6e 64 65 6e 63 69 65 73 28 5b 6c 69  dependencies([li
9b50: 73 74 20 72 65 76 20 24 72 69 64 5d 29 20 5b 6c  st rev $rid]) [l
9b60: 69 73 74 20 73 79 6d 3a 3a 62 72 61 6e 63 68 20  ist sym::branch 
9b70: 24 63 68 69 6c 64 5d 0a 09 7d 0a 09 72 65 74 75  $child]..}..retu
9b80: 72 6e 0a 20 20 20 20 7d 0a 0a 20 20 20 20 23 20  rn.    }..    # 
9b90: 72 65 73 75 6c 74 20 3d 20 6c 69 73 74 20 28 63  result = list (c
9ba0: 68 61 6e 67 65 73 65 74 2d 69 64 29 0a 20 20 20  hangeset-id).   
9bb0: 20 74 79 70 65 6d 65 74 68 6f 64 20 63 73 5f 73   typemethod cs_s
9bc0: 75 63 63 65 73 73 6f 72 73 20 7b 72 65 76 69 73  uccessors {revis
9bd0: 69 6f 6e 73 7d 20 7b 0a 20 20 20 20 20 20 20 20  ions} {.        
9be0: 23 20 54 68 69 73 20 69 73 20 61 20 76 61 72 69  # This is a vari
9bf0: 61 6e 74 20 6f 66 20 27 73 75 63 63 65 73 73 6f  ant of 'successo
9c00: 72 73 27 20 77 68 69 63 68 20 6d 61 70 73 20 74  rs' which maps t
9c10: 68 65 20 6c 6f 77 2d 6c 65 76 65 6c 0a 20 20 20  he low-level.   
9c20: 20 20 20 20 20 23 20 64 61 74 61 20 64 69 72 65       # data dire
9c30: 63 74 6c 79 20 74 6f 20 74 68 65 20 61 73 73 6f  ctly to the asso
9c40: 63 69 61 74 65 64 20 63 68 61 6e 67 65 73 65 74  ciated changeset
9c50: 73 2e 20 49 2e 65 2e 20 69 6e 73 74 65 61 64 0a  s. I.e. instead.
9c60: 20 20 20 20 20 20 20 20 23 20 6d 69 6c 6c 69 6f          # millio
9c70: 6e 73 20 6f 66 20 64 65 70 65 6e 64 65 6e 63 79  ns of dependency
9c80: 20 70 61 69 72 73 20 28 69 6e 20 65 78 74 72 65   pairs (in extre
9c90: 6d 65 20 63 61 73 65 73 20 28 45 78 61 6d 70 6c  me cases (Exampl
9ca0: 65 3a 20 54 63 6c 0a 20 20 20 20 20 20 20 20 23  e: Tcl.        #
9cb0: 20 43 56 53 29 29 20 77 65 20 72 65 74 75 72 6e   CVS)) we return
9cc0: 20 61 20 76 65 72 79 20 73 68 6f 72 74 20 61 6e   a very short an
9cd0: 64 20 6d 75 63 68 20 6d 6f 72 65 20 6d 61 6e 61  d much more mana
9ce0: 67 65 61 62 6c 65 20 6c 69 73 74 0a 20 20 20 20  geable list.    
9cf0: 20 20 20 20 23 20 6f 66 20 63 68 61 6e 67 65 73      # of changes
9d00: 65 74 73 2e 0a 0a 09 73 65 74 20 74 68 65 73 65  ets....set these
9d10: 74 20 28 27 5b 6a 6f 69 6e 20 24 72 65 76 69 73  t ('[join $revis
9d20: 69 6f 6e 73 20 7b 27 2c 27 7d 5d 27 29 0a 09 72  ions {','}]')..r
9d30: 65 74 75 72 6e 20 5b 73 74 61 74 65 20 72 75 6e  eturn [state run
9d40: 20 5b 73 75 62 73 74 20 2d 6e 6f 63 6f 6d 6d 61   [subst -nocomma
9d50: 6e 64 73 20 2d 6e 6f 62 61 63 6b 73 6c 61 73 68  nds -nobackslash
9d60: 65 73 20 7b 0a 20 20 20 20 2d 2d 20 28 31 29 20  es {.    -- (1) 
9d70: 50 72 69 6d 61 72 79 20 63 68 69 6c 64 0a 09 20  Primary child.. 
9d80: 20 20 20 53 45 4c 45 43 54 20 43 2e 63 69 64 0a     SELECT C.cid.
9d90: 09 20 20 20 20 46 52 4f 4d 20 20 20 72 65 76 69  .    FROM   revi
9da0: 73 69 6f 6e 20 52 2c 20 63 73 69 74 65 6d 20 43  sion R, csitem C
9db0: 49 2c 20 63 68 61 6e 67 65 73 65 74 20 43 0a 09  I, changeset C..
9dc0: 20 20 20 20 57 48 45 52 45 20 20 52 2e 72 69 64      WHERE  R.rid
9dd0: 20 20 20 49 4e 20 24 74 68 65 73 65 74 20 20 20     IN $theset   
9de0: 20 20 2d 2d 20 52 65 73 74 72 69 63 74 20 74 6f    -- Restrict to
9df0: 20 72 65 76 69 73 69 6f 6e 73 20 6f 66 20 69 6e   revisions of in
9e00: 74 65 72 65 73 74 0a 09 20 20 20 20 41 4e 44 20  terest..    AND 
9e10: 20 20 20 52 2e 63 68 69 6c 64 20 49 53 20 4e 4f     R.child IS NO
9e20: 54 20 4e 55 4c 4c 20 20 20 20 2d 2d 20 48 61 73  T NULL    -- Has
9e30: 20 70 72 69 6d 61 72 79 20 63 68 69 6c 64 0a 20   primary child. 
9e40: 20 20 20 20 20 20 20 20 20 20 20 41 4e 44 20 20             AND  
9e50: 20 20 43 49 2e 69 69 64 20 3d 20 52 2e 63 68 69    CI.iid = R.chi
9e60: 6c 64 20 20 20 20 20 20 20 2d 2d 20 53 65 6c 65  ld       -- Sele
9e70: 63 74 20 61 6c 6c 20 63 68 61 6e 67 65 73 65 74  ct all changeset
9e80: 73 0a 20 20 20 20 20 20 20 20 20 20 20 20 41 4e  s.            AN
9e90: 44 20 20 20 20 43 2e 63 69 64 20 3d 20 43 49 2e  D    C.cid = CI.
9ea0: 63 69 64 20 20 20 20 20 20 20 20 20 2d 2d 20 63  cid         -- c
9eb0: 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 70 72  ontaining the pr
9ec0: 69 6d 61 72 79 20 63 68 69 6c 64 0a 20 20 20 20  imary child.    
9ed0: 20 20 20 20 20 20 20 20 41 4e 44 20 20 20 20 43          AND    C
9ee0: 2e 74 79 70 65 20 3d 20 30 20 20 20 20 20 20 20  .type = 0       
9ef0: 20 20 20 20 20 20 2d 2d 20 77 68 69 63 68 20 61        -- which a
9f00: 72 65 20 72 65 76 69 73 69 6f 6e 20 63 68 61 6e  re revision chan
9f10: 67 65 73 65 74 73 0a 20 20 20 20 55 4e 49 4f 4e  gesets.    UNION
9f20: 0a 20 20 20 20 2d 2d 20 28 32 29 20 53 65 63 6f  .    -- (2) Seco
9f30: 6e 64 61 72 79 20 28 62 72 61 6e 63 68 29 20 63  ndary (branch) c
9f40: 68 69 6c 64 72 65 6e 0a 09 20 20 20 20 53 45 4c  hildren..    SEL
9f50: 45 43 54 20 43 2e 63 69 64 0a 09 20 20 20 20 46  ECT C.cid..    F
9f60: 52 4f 4d 20 20 20 72 65 76 69 73 69 6f 6e 20 52  ROM   revision R
9f70: 2c 20 72 65 76 69 73 69 6f 6e 62 72 61 6e 63 68  , revisionbranch
9f80: 63 68 69 6c 64 72 65 6e 20 42 2c 20 63 73 69 74  children B, csit
9f90: 65 6d 20 43 49 2c 20 63 68 61 6e 67 65 73 65 74  em CI, changeset
9fa0: 20 43 0a 09 20 20 20 20 57 48 45 52 45 20 20 52   C..    WHERE  R
9fb0: 2e 72 69 64 20 20 20 49 4e 20 24 74 68 65 73 65  .rid   IN $these
9fc0: 74 20 20 20 20 20 2d 2d 20 52 65 73 74 72 69 63  t     -- Restric
9fd0: 74 20 74 6f 20 72 65 76 69 73 69 6f 6e 73 20 6f  t to revisions o
9fe0: 66 20 69 6e 74 65 72 65 73 74 0a 09 20 20 20 20  f interest..    
9ff0: 41 4e 44 20 20 20 20 52 2e 72 69 64 20 3d 20 42  AND    R.rid = B
a000: 2e 72 69 64 20 20 20 20 20 20 20 20 20 20 2d 2d  .rid          --
a010: 20 53 65 6c 65 63 74 20 73 75 62 73 65 74 20 6f   Select subset o
a020: 66 20 62 72 61 6e 63 68 20 63 68 69 6c 64 72 65  f branch childre
a030: 6e 0a 20 20 20 20 20 20 20 20 20 20 20 20 41 4e  n.            AN
a040: 44 20 20 20 20 43 49 2e 69 69 64 20 3d 20 42 2e  D    CI.iid = B.
a050: 62 72 69 64 20 20 20 20 20 20 20 20 2d 2d 20 53  brid        -- S
a060: 65 6c 65 63 74 20 61 6c 6c 20 63 68 61 6e 67 65  elect all change
a070: 73 65 74 73 0a 20 20 20 20 20 20 20 20 20 20 20  sets.           
a080: 20 41 4e 44 20 20 20 20 43 2e 63 69 64 20 3d 20   AND    C.cid = 
a090: 43 49 2e 63 69 64 09 20 20 2d 2d 20 63 6f 6e 74  CI.cid.  -- cont
a0a0: 61 69 6e 69 6e 67 20 74 68 65 20 62 72 61 6e 63  aining the branc
a0b0: 68 0a 20 20 20 20 20 20 20 20 20 20 20 20 41 4e  h.            AN
a0c0: 44 20 20 20 20 43 2e 74 79 70 65 20 3d 20 30 09  D    C.type = 0.
a0d0: 09 20 20 2d 2d 20 77 68 69 63 68 20 61 72 65 20  .  -- which are 
a0e0: 72 65 76 69 73 69 6f 6e 20 63 68 61 6e 67 65 73  revision changes
a0f0: 65 74 73 0a 20 20 20 20 55 4e 49 4f 4e 0a 20 20  ets.    UNION.  
a100: 20 20 2d 2d 20 28 34 29 20 43 68 69 6c 64 20 6f    -- (4) Child o
a110: 66 20 74 72 75 6e 6b 20 72 6f 6f 74 20 73 75 63  f trunk root suc
a120: 63 65 73 73 6f 72 20 6f 66 20 6c 61 73 74 20 4e  cessor of last N
a130: 54 44 42 20 6f 6e 20 74 72 75 6e 6b 2e 0a 09 20  TDB on trunk... 
a140: 20 20 20 53 45 4c 45 43 54 20 43 2e 63 69 64 0a     SELECT C.cid.
a150: 09 20 20 20 20 46 52 4f 4d 20 20 20 72 65 76 69  .    FROM   revi
a160: 73 69 6f 6e 20 52 2c 20 72 65 76 69 73 69 6f 6e  sion R, revision
a170: 20 52 41 2c 20 63 73 69 74 65 6d 20 43 49 2c 20   RA, csitem CI, 
a180: 63 68 61 6e 67 65 73 65 74 20 43 0a 09 20 20 20  changeset C..   
a190: 20 57 48 45 52 45 20 20 52 2e 72 69 64 20 20 20   WHERE  R.rid   
a1a0: 49 4e 20 24 74 68 65 73 65 74 20 20 20 20 20 20  IN $theset      
a1b0: 2d 2d 20 52 65 73 74 72 69 63 74 20 74 6f 20 72  -- Restrict to r
a1c0: 65 76 69 73 69 6f 6e 73 20 6f 66 20 69 6e 74 65  evisions of inte
a1d0: 72 65 73 74 0a 09 20 20 20 20 41 4e 44 20 20 20  rest..    AND   
a1e0: 20 52 2e 69 73 64 65 66 61 75 6c 74 20 20 20 20   R.isdefault    
a1f0: 20 20 20 20 20 20 20 20 20 2d 2d 20 52 65 73 74           -- Rest
a200: 72 69 63 74 20 74 6f 20 4e 54 44 42 0a 09 20 20  rict to NTDB..  
a210: 20 20 41 4e 44 20 20 20 20 52 2e 64 62 63 68 69    AND    R.dbchi
a220: 6c 64 20 49 53 20 4e 4f 54 20 4e 55 4c 4c 20 20  ld IS NOT NULL  
a230: 20 2d 2d 20 61 6e 64 20 6c 61 73 74 20 4e 54 44   -- and last NTD
a240: 42 20 62 65 6c 6f 6e 67 69 6e 67 20 74 6f 20 74  B belonging to t
a250: 72 75 6e 6b 0a 09 20 20 20 20 41 4e 44 20 20 20  runk..    AND   
a260: 20 52 41 2e 72 69 64 20 3d 20 52 2e 64 62 63 68   RA.rid = R.dbch
a270: 69 6c 64 20 20 20 20 20 20 2d 2d 20 47 6f 20 64  ild      -- Go d
a280: 69 72 65 63 74 6c 79 20 74 6f 20 74 72 75 6e 6b  irectly to trunk
a290: 20 72 6f 6f 74 0a 09 20 20 20 20 41 4e 44 20 20   root..    AND  
a2a0: 20 20 52 41 2e 63 68 69 6c 64 20 49 53 20 4e 4f    RA.child IS NO
a2b0: 54 20 4e 55 4c 4c 20 20 20 20 2d 2d 20 48 61 73  T NULL    -- Has
a2c0: 20 70 72 69 6d 61 72 79 20 63 68 69 6c 64 2e 0a   primary child..
a2d0: 20 20 20 20 20 20 20 20 20 20 20 20 41 4e 44 20              AND 
a2e0: 20 20 20 43 49 2e 69 69 64 20 3d 20 52 41 2e 63     CI.iid = RA.c
a2f0: 68 69 6c 64 20 20 20 20 20 20 20 2d 2d 20 53 65  hild       -- Se
a300: 6c 65 63 74 20 61 6c 6c 20 63 68 61 6e 67 65 73  lect all changes
a310: 65 74 73 0a 20 20 20 20 20 20 20 20 20 20 20 20  ets.            
a320: 41 4e 44 20 20 20 20 43 2e 63 69 64 20 3d 20 43  AND    C.cid = C
a330: 49 2e 63 69 64 09 20 20 20 2d 2d 20 63 6f 6e 74  I.cid.   -- cont
a340: 61 69 6e 69 6e 67 20 74 68 65 20 70 72 69 6d 61  aining the prima
a350: 72 79 20 63 68 69 6c 64 0a 20 20 20 20 20 20 20  ry child.       
a360: 20 20 20 20 20 41 4e 44 20 20 20 20 43 2e 74 79       AND    C.ty
a370: 70 65 20 3d 20 30 09 09 20 20 20 2d 2d 20 77 68  pe = 0..   -- wh
a380: 69 63 68 20 61 72 65 20 72 65 76 69 73 69 6f 6e  ich are revision
a390: 20 63 68 61 6e 67 65 73 65 74 73 0a 20 20 20 20   changesets.    
a3a0: 55 4e 49 4f 4e 0a 09 20 20 20 20 53 45 4c 45 43  UNION..    SELEC
a3b0: 54 20 43 2e 63 69 64 0a 09 20 20 20 20 46 52 4f  T C.cid..    FRO
a3c0: 4d 20 20 20 72 65 76 69 73 69 6f 6e 20 52 2c 20  M   revision R, 
a3d0: 74 61 67 20 54 2c 20 63 73 69 74 65 6d 20 43 49  tag T, csitem CI
a3e0: 2c 20 63 68 61 6e 67 65 73 65 74 20 43 0a 09 20  , changeset C.. 
a3f0: 20 20 20 57 48 45 52 45 20 20 52 2e 72 69 64 20     WHERE  R.rid 
a400: 69 6e 20 24 74 68 65 73 65 74 20 20 20 20 20 20  in $theset      
a410: 20 20 2d 2d 20 52 65 73 74 72 69 63 74 20 74 6f    -- Restrict to
a420: 20 72 65 76 69 73 69 6f 6e 73 20 6f 66 20 69 6e   revisions of in
a430: 74 65 72 65 73 74 0a 09 20 20 20 20 41 4e 44 20  terest..    AND 
a440: 20 20 20 54 2e 72 65 76 20 3d 20 52 2e 72 69 64     T.rev = R.rid
a450: 09 20 20 20 2d 2d 20 53 65 6c 65 63 74 20 74 61  .   -- Select ta
a460: 67 73 20 61 74 74 61 63 68 65 64 20 74 6f 20 74  gs attached to t
a470: 68 65 6d 0a 20 20 20 20 20 20 20 20 20 20 20 20  hem.            
a480: 41 4e 44 20 20 20 20 43 49 2e 69 69 64 20 3d 20  AND    CI.iid = 
a490: 54 2e 74 69 64 20 20 20 20 20 20 20 20 20 20 2d  T.tid          -
a4a0: 2d 20 53 65 6c 65 63 74 20 61 6c 6c 20 63 68 61  - Select all cha
a4b0: 6e 67 65 73 65 74 73 0a 20 20 20 20 20 20 20 20  ngesets.        
a4c0: 20 20 20 20 41 4e 44 20 20 20 20 43 2e 63 69 64      AND    C.cid
a4d0: 20 3d 20 43 49 2e 63 69 64 09 20 20 20 2d 2d 20   = CI.cid.   -- 
a4e0: 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 74  containing the t
a4f0: 61 67 73 0a 20 20 20 20 20 20 20 20 20 20 20 20  ags.            
a500: 41 4e 44 20 20 20 20 43 2e 74 79 70 65 20 3d 20  AND    C.type = 
a510: 31 09 09 20 20 20 2d 2d 20 77 68 69 63 68 20 61  1..   -- which a
a520: 72 65 20 74 61 67 20 63 68 61 6e 67 65 73 65 74  re tag changeset
a530: 73 0a 20 20 20 20 55 4e 49 4f 4e 0a 09 20 20 20  s.    UNION..   
a540: 20 53 45 4c 45 43 54 20 43 2e 63 69 64 0a 09 20   SELECT C.cid.. 
a550: 20 20 20 46 52 4f 4d 20 20 20 72 65 76 69 73 69     FROM   revisi
a560: 6f 6e 20 52 2c 20 62 72 61 6e 63 68 20 42 2c 20  on R, branch B, 
a570: 63 73 69 74 65 6d 20 43 49 2c 20 63 68 61 6e 67  csitem CI, chang
a580: 65 73 65 74 20 43 0a 09 20 20 20 20 57 48 45 52  eset C..    WHER
a590: 45 20 20 52 2e 72 69 64 20 69 6e 20 24 74 68 65  E  R.rid in $the
a5a0: 73 65 74 20 20 20 20 20 20 20 20 2d 2d 20 52 65  set        -- Re
a5b0: 73 74 72 69 63 74 20 74 6f 20 72 65 76 69 73 69  strict to revisi
a5c0: 6f 6e 73 20 6f 66 20 69 6e 74 65 72 65 73 74 0a  ons of interest.
a5d0: 09 20 20 20 20 41 4e 44 20 20 20 20 42 2e 72 6f  .    AND    B.ro
a5e0: 6f 74 20 3d 20 52 2e 72 69 64 09 20 20 20 2d 2d  ot = R.rid.   --
a5f0: 20 53 65 6c 65 63 74 20 62 72 61 6e 63 68 65 73   Select branches
a600: 20 61 74 74 61 63 68 65 64 20 74 6f 20 74 68 65   attached to the
a610: 6d 0a 20 20 20 20 20 20 20 20 20 20 20 20 41 4e  m.            AN
a620: 44 20 20 20 20 43 49 2e 69 69 64 20 3d 20 42 2e  D    CI.iid = B.
a630: 62 69 64 20 20 20 20 20 20 20 20 20 20 2d 2d 20  bid          -- 
a640: 53 65 6c 65 63 74 20 61 6c 6c 20 63 68 61 6e 67  Select all chang
a650: 65 73 65 74 73 0a 20 20 20 20 20 20 20 20 20 20  esets.          
a660: 20 20 41 4e 44 20 20 20 20 43 2e 63 69 64 20 3d    AND    C.cid =
a670: 20 43 49 2e 63 69 64 09 20 20 20 2d 2d 20 63 6f   CI.cid.   -- co
a680: 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 62 72 61  ntaining the bra
a690: 6e 63 68 65 73 0a 20 20 20 20 20 20 20 20 20 20  nches.          
a6a0: 20 20 41 4e 44 20 20 20 20 43 2e 74 79 70 65 20    AND    C.type 
a6b0: 3d 20 32 09 09 20 20 20 2d 2d 20 77 68 69 63 68  = 2..   -- which
a6c0: 20 61 72 65 20 62 72 61 6e 63 68 20 63 68 61 6e   are branch chan
a6d0: 67 65 73 65 74 73 0a 09 7d 5d 5d 0a 20 20 20 20  gesets..}]].    
a6e0: 7d 0a 7d 0a 0a 23 20 23 20 23 23 20 23 23 23 20  }.}..# # ## ### 
a6f0: 23 23 23 23 23 20 23 23 23 23 23 23 23 23 20 23  ##### ######## #
a700: 23 23 23 23 23 23 23 23 23 23 23 23 20 23 23 23  ############ ###
a710: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
a720: 23 23 0a 23 23 20 48 65 6c 70 65 72 20 73 69 6e  ##.## Helper sin
a730: 67 6c 65 74 6f 6e 2e 20 43 6f 6d 6d 61 6e 64 73  gleton. Commands
a740: 20 66 6f 72 20 74 61 67 20 73 79 6d 62 6f 6c 20   for tag symbol 
a750: 63 68 61 6e 67 65 73 65 74 73 2e 0a 0a 73 6e 69  changesets...sni
a760: 74 3a 3a 74 79 70 65 20 3a 3a 76 63 3a 3a 66 6f  t::type ::vc::fo
a770: 73 73 69 6c 3a 3a 69 6d 70 6f 72 74 3a 3a 63 76  ssil::import::cv
a780: 73 3a 3a 70 72 6f 6a 65 63 74 3a 3a 72 65 76 3a  s::project::rev:
a790: 3a 73 79 6d 3a 3a 74 61 67 20 7b 0a 20 20 20 20  :sym::tag {.    
a7a0: 74 79 70 65 6d 65 74 68 6f 64 20 62 79 72 65 76  typemethod byrev
a7b0: 69 73 69 6f 6e 20 7b 7d 20 7b 20 72 65 74 75 72  ision {} { retur
a7c0: 6e 20 30 20 7d 0a 20 20 20 20 74 79 70 65 6d 65  n 0 }.    typeme
a7d0: 74 68 6f 64 20 62 79 73 79 6d 62 6f 6c 20 20 20  thod bysymbol   
a7e0: 7b 7d 20 7b 20 72 65 74 75 72 6e 20 31 20 7d 0a  {} { return 1 }.
a7f0: 20 20 20 20 74 79 70 65 6d 65 74 68 6f 64 20 69      typemethod i
a800: 73 74 61 67 20 20 20 20 20 20 7b 7d 20 7b 20 72  stag      {} { r
a810: 65 74 75 72 6e 20 31 20 7d 0a 20 20 20 20 74 79  eturn 1 }.    ty
a820: 70 65 6d 65 74 68 6f 64 20 69 73 62 72 61 6e 63  pemethod isbranc
a830: 68 20 20 20 7b 7d 20 7b 20 72 65 74 75 72 6e 20  h   {} { return 
a840: 30 20 7d 0a 0a 20 20 20 20 74 79 70 65 6d 65 74  0 }..    typemet
a850: 68 6f 64 20 73 74 72 20 7b 74 61 67 7d 20 7b 0a  hod str {tag} {.
a860: 09 73 74 72 75 63 74 3a 3a 6c 69 73 74 20 61 73  .struct::list as
a870: 73 69 67 6e 20 5b 73 74 61 74 65 20 72 75 6e 20  sign [state run 
a880: 7b 0a 09 20 20 20 20 53 45 4c 45 43 54 20 53 2e  {..    SELECT S.
a890: 6e 61 6d 65 2c 20 46 2e 6e 61 6d 65 2c 20 50 2e  name, F.name, P.
a8a0: 6e 61 6d 65 0a 09 20 20 20 20 46 52 4f 4d 20 20  name..    FROM  
a8b0: 20 74 61 67 20 54 2c 20 73 79 6d 62 6f 6c 20 53   tag T, symbol S
a8c0: 2c 20 66 69 6c 65 20 46 2c 20 70 72 6f 6a 65 63  , file F, projec
a8d0: 74 20 50 0a 09 20 20 20 20 57 48 45 52 45 20 20  t P..    WHERE  
a8e0: 54 2e 74 69 64 20 3d 20 24 74 61 67 20 20 20 2d  T.tid = $tag   -
a8f0: 2d 20 46 69 6e 64 20 73 70 65 63 69 66 69 65 64  - Find specified
a900: 20 74 61 67 0a 09 20 20 20 20 41 4e 44 20 20 20   tag..    AND   
a910: 20 46 2e 66 69 64 20 3d 20 54 2e 66 69 64 20 20   F.fid = T.fid  
a920: 2d 2d 20 47 65 74 20 66 69 6c 65 20 6f 66 20 74  -- Get file of t
a930: 61 67 0a 09 20 20 20 20 41 4e 44 20 20 20 20 50  ag..    AND    P
a940: 2e 70 69 64 20 3d 20 46 2e 70 69 64 20 20 2d 2d  .pid = F.pid  --
a950: 20 47 65 74 20 70 72 6f 6a 65 63 74 20 6f 66 20   Get project of 
a960: 66 69 6c 65 0a 09 20 20 20 20 41 4e 44 20 20 20  file..    AND   
a970: 20 53 2e 73 69 64 20 3d 20 54 2e 73 69 64 20 20   S.sid = T.sid  
a980: 2d 2d 20 47 65 74 20 73 79 6d 62 6f 6c 20 6f 66  -- Get symbol of
a990: 20 74 61 67 0a 09 7d 5d 20 73 6e 61 6d 65 20 66   tag..}] sname f
a9a0: 6e 61 6d 65 20 70 6e 61 6d 65 0a 09 72 65 74 75  name pname..retu
a9b0: 72 6e 20 22 24 70 6e 61 6d 65 2f 54 27 24 7b 73  rn "$pname/T'${s
a9c0: 6e 61 6d 65 7d 27 3a 3a 24 66 6e 61 6d 65 22 0a  name}'::$fname".
a9d0: 20 20 20 20 7d 0a 0a 20 20 20 20 23 20 72 65 73      }..    # res
a9e0: 75 6c 74 20 3d 20 6c 69 73 74 20 28 6d 69 6e 74  ult = list (mint
a9f0: 69 6d 65 2c 20 6d 61 78 74 69 6d 65 29 0a 20 20  ime, maxtime).  
aa00: 20 20 74 79 70 65 6d 65 74 68 6f 64 20 74 69 6d    typemethod tim
aa10: 65 72 61 6e 67 65 20 7b 74 61 67 73 7d 20 7b 0a  erange {tags} {.
aa20: 09 23 20 54 68 65 20 72 61 6e 67 65 20 69 73 20  .# The range is 
aa30: 64 65 66 69 6e 65 64 20 61 73 20 74 68 65 20 72  defined as the r
aa40: 61 6e 67 65 20 6f 66 20 74 68 65 20 72 65 76 69  ange of the revi
aa50: 73 69 6f 6e 73 20 74 68 65 20 74 61 67 73 0a 09  sions the tags..
aa60: 23 20 61 72 65 20 61 74 74 61 63 68 65 64 20 74  # are attached t
aa70: 6f 2e 0a 0a 09 73 65 74 20 74 68 65 73 65 74 20  o....set theset 
aa80: 28 27 5b 6a 6f 69 6e 20 24 74 61 67 73 20 7b 27  ('[join $tags {'
aa90: 2c 27 7d 5d 27 29 0a 09 72 65 74 75 72 6e 20 5b  ,'}]')..return [
aaa0: 73 74 61 74 65 20 72 75 6e 20 5b 73 75 62 73 74  state run [subst
aab0: 20 2d 6e 6f 63 6f 6d 6d 61 6e 64 73 20 2d 6e 6f   -nocommands -no
aac0: 62 61 63 6b 73 6c 61 73 68 65 73 20 7b 0a 09 20  backslashes {.. 
aad0: 20 20 20 53 45 4c 45 43 54 20 4d 49 4e 28 52 2e     SELECT MIN(R.
aae0: 64 61 74 65 29 2c 20 4d 41 58 28 52 2e 64 61 74  date), MAX(R.dat
aaf0: 65 29 0a 09 20 20 20 20 46 52 4f 4d 20 20 20 74  e)..    FROM   t
ab00: 61 67 20 54 2c 20 72 65 76 69 73 69 6f 6e 20 52  ag T, revision R
ab10: 0a 09 20 20 20 20 57 48 45 52 45 20 20 54 2e 74  ..    WHERE  T.t
ab20: 69 64 20 49 4e 20 24 74 68 65 73 65 74 20 20 2d  id IN $theset  -
ab30: 2d 20 52 65 73 74 72 69 63 74 20 74 6f 20 74 61  - Restrict to ta
ab40: 67 73 20 6f 66 20 69 6e 74 65 72 65 73 74 0a 20  gs of interest. 
ab50: 20 20 20 20 20 20 20 20 20 20 20 41 4e 44 20 20             AND  
ab60: 20 20 52 2e 72 69 64 20 3d 20 54 2e 72 65 76 20    R.rid = T.rev 
ab70: 20 20 20 20 2d 2d 20 53 65 6c 65 63 74 20 74 61      -- Select ta
ab80: 67 20 70 61 72 65 6e 74 20 72 65 76 69 73 69 6f  g parent revisio
ab90: 6e 73 0a 09 7d 5d 5d 0a 20 20 20 20 7d 0a 0a 20  ns..}]].    }.. 
aba0: 20 20 20 23 20 76 61 72 28 64 76 29 20 3d 20 64     # var(dv) = d
abb0: 69 63 74 20 28 69 74 65 6d 20 2d 3e 20 6c 69 73  ict (item -> lis
abc0: 74 20 28 69 74 65 6d 29 29 2c 20 69 74 65 6d 20  t (item)), item 
abd0: 20 3d 20 6c 69 73 74 20 28 74 79 70 65 20 69 64   = list (type id
abe0: 29 0a 20 20 20 20 74 79 70 65 6d 65 74 68 6f 64  ).    typemethod
abf0: 20 73 75 63 63 65 73 73 6f 72 73 20 7b 64 76 20   successors {dv 
ac00: 74 61 67 73 7d 20 7b 0a 09 23 20 54 61 67 73 20  tags} {..# Tags 
ac10: 68 61 76 65 20 6e 6f 20 73 75 63 63 65 73 73 6f  have no successo
ac20: 72 73 2e 0a 09 72 65 74 75 72 6e 0a 20 20 20 20  rs...return.    
ac30: 7d 0a 0a 20 20 20 20 23 20 72 65 73 75 6c 74 20  }..    # result 
ac40: 3d 20 34 2d 6c 69 73 74 20 28 69 74 65 6d 74 79  = 4-list (itemty
ac50: 70 65 20 69 74 65 6d 69 64 20 6e 65 78 74 69 74  pe itemid nextit
ac60: 65 6d 74 79 70 65 20 6e 65 78 74 69 74 65 6d 69  emtype nextitemi
ac70: 64 20 2e 2e 2e 29 0a 20 20 20 20 74 79 70 65 6d  d ...).    typem
ac80: 65 74 68 6f 64 20 6c 6f 6f 70 73 20 7b 74 61 67  ethod loops {tag
ac90: 73 7d 20 7b 0a 09 23 20 54 61 67 73 20 68 61 76  s} {..# Tags hav
aca0: 65 20 6e 6f 20 73 75 63 63 65 73 73 6f 72 73 2c  e no successors,
acb0: 20 74 68 65 72 65 66 6f 72 65 20 63 61 6e 6e 6f   therefore canno
acc0: 74 20 63 61 75 73 65 20 6c 6f 6f 70 73 0a 09 72  t cause loops..r
acd0: 65 74 75 72 6e 20 7b 7d 0a 20 20 20 20 7d 0a 0a  eturn {}.    }..
ace0: 20 20 20 20 23 20 72 65 73 75 6c 74 20 3d 20 6c      # result = l
acf0: 69 73 74 20 28 63 68 61 6e 67 65 73 65 74 2d 69  ist (changeset-i
ad00: 64 29 0a 20 20 20 20 74 79 70 65 6d 65 74 68 6f  d).    typemetho
ad10: 64 20 63 73 5f 73 75 63 63 65 73 73 6f 72 73 20  d cs_successors 
ad20: 7b 74 61 67 73 7d 20 7b 0a 09 23 20 54 61 67 73  {tags} {..# Tags
ad30: 20 68 61 76 65 20 6e 6f 20 73 75 63 63 65 73 73   have no success
ad40: 6f 72 73 2e 0a 09 72 65 74 75 72 6e 0a 20 20 20  ors...return.   
ad50: 20 7d 0a 7d 0a 0a 23 20 23 20 23 23 20 23 23 23   }.}..# # ## ###
ad60: 20 23 23 23 23 23 20 23 23 23 23 23 23 23 23 20   ##### ######## 
ad70: 23 23 23 23 23 23 23 23 23 23 23 23 23 20 23 23  ############# ##
ad80: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
ad90: 23 23 23 0a 23 23 20 48 65 6c 70 65 72 20 73 69  ###.## Helper si
ada0: 6e 67 6c 65 74 6f 6e 2e 20 43 6f 6d 6d 61 6e 64  ngleton. Command
adb0: 73 20 66 6f 72 20 62 72 61 6e 63 68 20 73 79 6d  s for branch sym
adc0: 62 6f 6c 20 63 68 61 6e 67 65 73 65 74 73 2e 0a  bol changesets..
add0: 0a 73 6e 69 74 3a 3a 74 79 70 65 20 3a 3a 76 63  .snit::type ::vc
ade0: 3a 3a 66 6f 73 73 69 6c 3a 3a 69 6d 70 6f 72 74  ::fossil::import
adf0: 3a 3a 63 76 73 3a 3a 70 72 6f 6a 65 63 74 3a 3a  ::cvs::project::
ae00: 72 65 76 3a 3a 73 79 6d 3a 3a 62 72 61 6e 63 68  rev::sym::branch
ae10: 20 7b 0a 20 20 20 20 74 79 70 65 6d 65 74 68 6f   {.    typemetho
ae20: 64 20 62 79 72 65 76 69 73 69 6f 6e 20 7b 7d 20  d byrevision {} 
ae30: 7b 20 72 65 74 75 72 6e 20 30 20 7d 0a 20 20 20  { return 0 }.   
ae40: 20 74 79 70 65 6d 65 74 68 6f 64 20 62 79 73 79   typemethod bysy
ae50: 6d 62 6f 6c 20 20 20 7b 7d 20 7b 20 72 65 74 75  mbol   {} { retu
ae60: 72 6e 20 31 20 7d 0a 20 20 20 20 74 79 70 65 6d  rn 1 }.    typem
ae70: 65 74 68 6f 64 20 69 73 74 61 67 20 20 20 20 20  ethod istag     
ae80: 20 7b 7d 20 7b 20 72 65 74 75 72 6e 20 30 20 7d   {} { return 0 }
ae90: 0a 20 20 20 20 74 79 70 65 6d 65 74 68 6f 64 20  .    typemethod 
aea0: 69 73 62 72 61 6e 63 68 20 20 20 7b 7d 20 7b 20  isbranch   {} { 
aeb0: 72 65 74 75 72 6e 20 31 20 7d 0a 0a 20 20 20 20  return 1 }..    
aec0: 74 79 70 65 6d 65 74 68 6f 64 20 73 74 72 20 7b  typemethod str {
aed0: 62 72 61 6e 63 68 7d 20 7b 0a 09 73 74 72 75 63  branch} {..struc
aee0: 74 3a 3a 6c 69 73 74 20 61 73 73 69 67 6e 20 5b  t::list assign [
aef0: 73 74 61 74 65 20 72 75 6e 20 7b 0a 09 20 20 20  state run {..   
af00: 20 53 45 4c 45 43 54 20 53 2e 6e 61 6d 65 2c 20   SELECT S.name, 
af10: 46 2e 6e 61 6d 65 2c 20 50 2e 6e 61 6d 65 0a 09  F.name, P.name..
af20: 20 20 20 20 46 52 4f 4d 20 20 20 62 72 61 6e 63      FROM   branc
af30: 68 20 42 2c 20 73 79 6d 62 6f 6c 20 53 2c 20 66  h B, symbol S, f
af40: 69 6c 65 20 46 2c 20 70 72 6f 6a 65 63 74 20 50  ile F, project P
af50: 0a 09 20 20 20 20 57 48 45 52 45 20 20 42 2e 62  ..    WHERE  B.b
af60: 69 64 20 3d 20 24 62 72 61 6e 63 68 20 20 2d 2d  id = $branch  --
af70: 20 46 69 6e 64 20 73 70 65 63 69 66 69 65 64 20   Find specified 
af80: 62 72 61 6e 63 68 0a 09 20 20 20 20 41 4e 44 20  branch..    AND 
af90: 20 20 20 46 2e 66 69 64 20 3d 20 42 2e 66 69 64     F.fid = B.fid
afa0: 20 20 20 20 2d 2d 20 47 65 74 20 66 69 6c 65 20      -- Get file 
afb0: 6f 66 20 62 72 61 6e 63 68 0a 09 20 20 20 20 41  of branch..    A
afc0: 4e 44 20 20 20 20 50 2e 70 69 64 20 3d 20 46 2e  ND    P.pid = F.
afd0: 70 69 64 20 20 20 20 2d 2d 20 47 65 74 20 70 72  pid    -- Get pr
afe0: 6f 6a 65 63 74 20 6f 66 20 66 69 6c 65 0a 09 20  oject of file.. 
aff0: 20 20 20 41 4e 44 20 20 20 20 53 2e 73 69 64 20     AND    S.sid 
b000: 3d 20 42 2e 73 69 64 20 20 20 20 2d 2d 20 47 65  = B.sid    -- Ge
b010: 74 20 73 79 6d 62 6f 6c 20 6f 66 20 62 72 61 6e  t symbol of bran
b020: 63 68 0a 09 7d 5d 20 73 6e 61 6d 65 20 66 6e 61  ch..}] sname fna
b030: 6d 65 20 70 6e 61 6d 65 0a 09 72 65 74 75 72 6e  me pname..return
b040: 20 22 24 70 6e 61 6d 65 2f 42 27 24 7b 73 6e 61   "$pname/B'${sna
b050: 6d 65 7d 27 3a 3a 24 66 6e 61 6d 65 22 0a 20 20  me}'::$fname".  
b060: 20 20 7d 0a 0a 20 20 20 20 23 20 72 65 73 75 6c    }..    # resul
b070: 74 20 3d 20 6c 69 73 74 20 28 6d 69 6e 74 69 6d  t = list (mintim
b080: 65 2c 20 6d 61 78 74 69 6d 65 29 0a 20 20 20 20  e, maxtime).    
b090: 74 79 70 65 6d 65 74 68 6f 64 20 74 69 6d 65 72  typemethod timer
b0a0: 61 6e 67 65 20 7b 62 72 61 6e 63 68 65 73 7d 20  ange {branches} 
b0b0: 7b 0a 09 23 20 54 68 65 20 72 61 6e 67 65 20 6f  {..# The range o
b0c0: 66 20 61 20 62 72 61 6e 63 68 20 69 73 20 64 65  f a branch is de
b0d0: 66 69 6e 65 64 20 61 73 20 74 68 65 20 72 61 6e  fined as the ran
b0e0: 67 65 20 6f 66 20 74 68 65 0a 09 23 20 72 65 76  ge of the..# rev
b0f0: 69 73 69 6f 6e 73 20 74 68 65 20 62 72 61 6e 63  isions the branc
b100: 68 65 73 20 61 72 65 20 73 70 61 77 6e 65 64 20  hes are spawned 
b110: 62 79 2e 20 4e 4f 54 45 20 68 6f 77 65 76 65 72  by. NOTE however
b120: 20 74 68 61 74 20 74 68 65 0a 09 23 20 62 72 61   that the..# bra
b130: 6e 63 68 65 73 20 61 73 73 6f 63 69 61 74 65 64  nches associated
b140: 20 77 69 74 68 20 61 20 64 65 74 61 63 68 65 64   with a detached
b150: 20 4e 54 44 42 20 77 69 6c 6c 20 68 61 76 65 20   NTDB will have 
b160: 6e 6f 20 72 6f 6f 74 0a 09 23 20 73 70 61 77 6e  no root..# spawn
b170: 69 6e 67 20 74 68 65 6d 2c 20 68 65 6e 63 65 20  ing them, hence 
b180: 74 68 65 79 20 68 61 76 65 20 6e 6f 20 72 65 61  they have no rea
b190: 6c 20 74 69 6d 65 72 61 6e 67 65 20 61 6e 79 0a  l timerange any.
b1a0: 09 23 20 6c 6f 6e 67 65 72 2e 20 42 79 20 75 73  .# longer. By us
b1b0: 69 6e 67 20 30 20 77 65 20 70 75 74 20 74 68 65  ing 0 we put the
b1c0: 6d 20 69 6e 20 66 72 6f 6e 74 20 6f 66 20 65 76  m in front of ev
b1d0: 65 72 79 74 68 69 6e 67 20 65 6c 73 65 2c 0a 09  erything else,..
b1e0: 23 20 61 73 20 74 68 65 79 20 6c 6f 67 69 63 61  # as they logica
b1f0: 6c 6c 79 20 61 72 65 2e 0a 0a 09 73 65 74 20 74  lly are....set t
b200: 68 65 73 65 74 20 28 27 5b 6a 6f 69 6e 20 24 62  heset ('[join $b
b210: 72 61 6e 63 68 65 73 20 7b 27 2c 27 7d 5d 27 29  ranches {','}]')
b220: 0a 09 72 65 74 75 72 6e 20 5b 73 74 61 74 65 20  ..return [state 
b230: 72 75 6e 20 5b 73 75 62 73 74 20 2d 6e 6f 63 6f  run [subst -noco
b240: 6d 6d 61 6e 64 73 20 2d 6e 6f 62 61 63 6b 73 6c  mmands -nobacksl
b250: 61 73 68 65 73 20 7b 0a 09 20 20 20 20 53 45 4c  ashes {..    SEL
b260: 45 43 54 20 49 46 4e 55 4c 4c 28 4d 49 4e 28 52  ECT IFNULL(MIN(R
b270: 2e 64 61 74 65 29 2c 30 29 2c 20 49 46 4e 55 4c  .date),0), IFNUL
b280: 4c 28 4d 41 58 28 52 2e 64 61 74 65 29 2c 30 29  L(MAX(R.date),0)
b290: 0a 09 20 20 20 20 46 52 4f 4d 20 20 62 72 61 6e  ..    FROM  bran
b2a0: 63 68 20 42 2c 20 72 65 76 69 73 69 6f 6e 20 52  ch B, revision R
b2b0: 0a 09 20 20 20 20 57 48 45 52 45 20 42 2e 62 69  ..    WHERE B.bi
b2c0: 64 20 49 4e 20 24 74 68 65 73 65 74 20 20 20 2d  d IN $theset   -
b2d0: 2d 20 52 65 73 74 72 69 63 74 20 74 6f 20 62 72  - Restrict to br
b2e0: 61 6e 63 68 65 73 20 6f 66 20 69 6e 74 65 72 65  anches of intere
b2f0: 73 74 0a 20 20 20 20 20 20 20 20 20 20 20 20 41  st.            A
b300: 4e 44 20 20 20 52 2e 72 69 64 20 3d 20 42 2e 72  ND   R.rid = B.r
b310: 6f 6f 74 20 20 20 20 20 2d 2d 20 53 65 6c 65 63  oot     -- Selec
b320: 74 20 62 72 61 6e 63 68 20 70 61 72 65 6e 74 20  t branch parent 
b330: 72 65 76 69 73 69 6f 6e 73 0a 09 7d 5d 5d 0a 20  revisions..}]]. 
b340: 20 20 20 7d 0a 0a 20 20 20 20 23 20 72 65 73 75     }..    # resu
b350: 6c 74 20 3d 20 34 2d 6c 69 73 74 20 28 69 74 65  lt = 4-list (ite
b360: 6d 74 79 70 65 20 69 74 65 6d 69 64 20 6e 65 78  mtype itemid nex
b370: 74 69 74 65 6d 74 79 70 65 20 6e 65 78 74 69 74  titemtype nextit
b380: 65 6d 69 64 20 2e 2e 2e 29 0a 20 20 20 20 74 79  emid ...).    ty
b390: 70 65 6d 65 74 68 6f 64 20 6c 6f 6f 70 73 20 7b  pemethod loops {
b3a0: 62 72 61 6e 63 68 65 73 7d 20 7b 0a 09 23 20 4e  branches} {..# N
b3b0: 6f 74 65 3a 20 52 65 76 69 73 69 6f 6e 73 20 61  ote: Revisions a
b3c0: 6e 64 20 74 61 67 73 20 63 61 6e 6e 6f 74 20 63  nd tags cannot c
b3d0: 61 75 73 65 20 74 68 65 20 6c 6f 6f 70 2e 20 42  ause the loop. B
b3e0: 65 69 6e 67 20 6f 66 20 61 0a 09 23 20 66 75 6e  eing of a..# fun
b3f0: 64 61 6d 65 6e 74 61 6c 6c 79 20 64 69 66 66 65  damentally diffe
b400: 72 65 6e 74 20 74 79 70 65 20 74 68 65 79 20 63  rent type they c
b410: 61 6e 6e 6f 74 20 62 65 20 69 6e 20 74 68 65 20  annot be in the 
b420: 69 6e 63 6f 6d 69 6e 67 0a 09 23 20 73 65 74 20  incoming..# set 
b430: 6f 66 20 69 64 73 2e 0a 0a 09 73 65 74 20 74 68  of ids....set th
b440: 65 73 65 74 20 28 27 5b 6a 6f 69 6e 20 24 62 72  eset ('[join $br
b450: 61 6e 63 68 65 73 20 7b 27 2c 27 7d 5d 27 29 0a  anches {','}]').
b460: 09 72 65 74 75 72 6e 20 5b 73 74 61 74 65 20 72  .return [state r
b470: 75 6e 20 5b 73 75 62 73 74 20 2d 6e 6f 63 6f 6d  un [subst -nocom
b480: 6d 61 6e 64 73 20 2d 6e 6f 62 61 63 6b 73 6c 61  mands -nobacksla
b490: 73 68 65 73 20 7b 0a 09 20 20 20 20 53 45 4c 45  shes {..    SELE
b4a0: 43 54 20 42 2e 62 69 64 2c 20 42 58 2e 62 69 64  CT B.bid, BX.bid
b4b0: 0a 09 20 20 20 20 46 52 4f 4d 20 20 20 62 72 61  ..    FROM   bra
b4c0: 6e 63 68 20 42 2c 20 70 72 65 66 65 72 65 64 70  nch B, preferedp
b4d0: 61 72 65 6e 74 20 50 2c 20 62 72 61 6e 63 68 20  arent P, branch 
b4e0: 42 58 0a 09 20 20 20 20 57 48 45 52 45 20 20 42  BX..    WHERE  B
b4f0: 2e 62 69 64 20 49 4e 20 24 74 68 65 73 65 74 20  .bid IN $theset 
b500: 20 20 2d 2d 20 52 65 73 74 72 69 63 74 20 74 6f    -- Restrict to
b510: 20 62 72 61 6e 63 68 65 73 20 6f 66 20 69 6e 74   branches of int
b520: 65 72 65 73 74 0a 09 20 20 20 20 41 4e 44 20 20  erest..    AND  
b530: 20 20 42 2e 73 69 64 20 3d 20 50 2e 70 69 64 20    B.sid = P.pid 
b540: 20 20 20 20 20 2d 2d 20 47 65 74 20 74 68 65 20       -- Get the 
b550: 70 72 65 66 65 72 65 64 20 62 72 61 6e 63 68 65  prefered branche
b560: 73 20 76 69 61 0a 09 20 20 20 20 41 4e 44 20 20  s via..    AND  
b570: 20 20 42 58 2e 73 69 64 20 3d 20 50 2e 73 69 64    BX.sid = P.sid
b580: 20 20 20 20 20 2d 2d 20 74 68 65 20 62 72 61 6e       -- the bran
b590: 63 68 20 73 79 6d 62 6f 6c 73 0a 09 20 20 20 20  ch symbols..    
b5a0: 41 4e 44 20 20 20 20 42 58 2e 62 69 64 20 49 4e  AND    BX.bid IN
b5b0: 20 24 74 68 65 73 65 74 20 20 2d 2d 20 4c 6f 6f   $theset  -- Loo
b5c0: 70 0a 09 7d 5d 5d 0a 20 20 20 20 7d 0a 0a 20 20  p..}]].    }..  
b5d0: 20 20 23 20 76 61 72 28 64 76 29 20 3d 20 64 69    # var(dv) = di
b5e0: 63 74 20 28 69 74 65 6d 20 2d 3e 20 6c 69 73 74  ct (item -> list
b5f0: 20 28 69 74 65 6d 29 29 2c 20 69 74 65 6d 20 20   (item)), item  
b600: 3d 20 6c 69 73 74 20 28 74 79 70 65 20 69 64 29  = list (type id)
b610: 0a 20 20 20 20 74 79 70 65 6d 65 74 68 6f 64 20  .    typemethod 
b620: 73 75 63 63 65 73 73 6f 72 73 20 7b 64 76 20 62  successors {dv b
b630: 72 61 6e 63 68 65 73 7d 20 7b 0a 09 75 70 76 61  ranches} {..upva
b640: 72 20 31 20 24 64 76 20 64 65 70 65 6e 64 65 6e  r 1 $dv dependen
b650: 63 69 65 73 0a 09 23 20 54 68 65 20 66 69 72 73  cies..# The firs
b660: 74 20 72 65 76 69 73 69 6f 6e 20 63 6f 6d 6d 69  t revision commi
b670: 74 74 65 64 20 6f 6e 20 61 20 62 72 61 6e 63 68  tted on a branch
b680: 2c 20 61 6e 64 20 61 6c 6c 20 62 72 61 6e 63 68  , and all branch
b690: 65 73 0a 09 23 20 61 6e 64 20 74 61 67 73 20 77  es..# and tags w
b6a0: 68 69 63 68 20 68 61 76 65 20 69 74 20 61 73 20  hich have it as 
b6b0: 74 68 65 69 72 20 70 72 65 66 65 72 65 64 20 70  their prefered p
b6c0: 61 72 65 6e 74 20 61 72 65 20 74 68 65 0a 09 23  arent are the..#
b6d0: 20 73 75 63 63 65 73 73 6f 72 73 20 6f 66 20 61   successors of a
b6e0: 20 62 72 61 6e 63 68 2e 0a 0a 09 73 65 74 20 74   branch....set t
b6f0: 68 65 73 65 74 20 28 27 5b 6a 6f 69 6e 20 24 62  heset ('[join $b
b700: 72 61 6e 63 68 65 73 20 7b 27 2c 27 7d 5d 27 29  ranches {','}]')
b710: 0a 09 66 6f 72 65 61 63 68 20 7b 62 69 64 20 63  ..foreach {bid c
b720: 68 69 6c 64 7d 20 5b 73 74 61 74 65 20 72 75 6e  hild} [state run
b730: 20 5b 73 75 62 73 74 20 2d 6e 6f 63 6f 6d 6d 61   [subst -nocomma
b740: 6e 64 73 20 2d 6e 6f 62 61 63 6b 73 6c 61 73 68  nds -nobackslash
b750: 65 73 20 7b 0a 09 20 20 20 20 53 45 4c 45 43 54  es {..    SELECT
b760: 20 42 2e 62 69 64 2c 20 52 2e 72 69 64 0a 09 20   B.bid, R.rid.. 
b770: 20 20 20 46 52 4f 4d 20 20 20 62 72 61 6e 63 68     FROM   branch
b780: 20 42 2c 20 72 65 76 69 73 69 6f 6e 20 52 0a 09   B, revision R..
b790: 20 20 20 20 57 48 45 52 45 20 20 42 2e 62 69 64      WHERE  B.bid
b7a0: 20 49 4e 20 24 74 68 65 73 65 74 20 20 20 20 20   IN $theset     
b7b0: 2d 2d 20 52 65 73 74 72 69 63 74 20 74 6f 20 62  -- Restrict to b
b7c0: 72 61 6e 63 68 65 73 20 6f 66 20 69 6e 74 65 72  ranches of inter
b7d0: 65 73 74 0a 09 20 20 20 20 41 4e 44 20 20 20 20  est..    AND    
b7e0: 42 2e 66 69 72 73 74 20 3d 20 52 2e 72 69 64 20  B.first = R.rid 
b7f0: 20 20 20 20 20 2d 2d 20 47 65 74 20 66 69 72 73       -- Get firs
b800: 74 20 72 65 76 69 73 69 6f 6e 20 6f 6e 20 74 68  t revision on th
b810: 65 20 62 72 61 6e 63 68 0a 09 7d 5d 5d 20 7b 0a  e branch..}]] {.
b820: 09 20 20 20 20 6c 61 70 70 65 6e 64 20 64 65 70  .    lappend dep
b830: 65 6e 64 65 6e 63 69 65 73 28 5b 6c 69 73 74 20  endencies([list 
b840: 73 79 6d 3a 3a 62 72 61 6e 63 68 20 24 62 69 64  sym::branch $bid
b850: 5d 29 20 5b 6c 69 73 74 20 72 65 76 20 24 63 68  ]) [list rev $ch
b860: 69 6c 64 5d 0a 09 7d 0a 09 66 6f 72 65 61 63 68  ild]..}..foreach
b870: 20 7b 62 69 64 20 63 68 69 6c 64 7d 20 5b 73 74   {bid child} [st
b880: 61 74 65 20 72 75 6e 20 5b 73 75 62 73 74 20 2d  ate run [subst -
b890: 6e 6f 63 6f 6d 6d 61 6e 64 73 20 2d 6e 6f 62 61  nocommands -noba
b8a0: 63 6b 73 6c 61 73 68 65 73 20 7b 0a 09 20 20 20  ckslashes {..   
b8b0: 20 53 45 4c 45 43 54 20 42 2e 62 69 64 2c 20 42   SELECT B.bid, B
b8c0: 58 2e 62 69 64 0a 09 20 20 20 20 46 52 4f 4d 20  X.bid..    FROM 
b8d0: 20 20 62 72 61 6e 63 68 20 42 2c 20 70 72 65 66    branch B, pref
b8e0: 65 72 65 64 70 61 72 65 6e 74 20 50 2c 20 62 72  eredparent P, br
b8f0: 61 6e 63 68 20 42 58 0a 09 20 20 20 20 57 48 45  anch BX..    WHE
b900: 52 45 20 20 42 2e 62 69 64 20 49 4e 20 24 74 68  RE  B.bid IN $th
b910: 65 73 65 74 20 20 20 20 20 2d 2d 20 52 65 73 74  eset     -- Rest
b920: 72 69 63 74 20 74 6f 20 62 72 61 6e 63 68 65 73  rict to branches
b930: 20 6f 66 20 69 6e 74 65 72 65 73 74 0a 09 20 20   of interest..  
b940: 20 20 41 4e 44 20 20 20 20 42 2e 73 69 64 20 3d    AND    B.sid =
b950: 20 50 2e 70 69 64 20 20 20 20 20 20 20 20 2d 2d   P.pid        --
b960: 20 47 65 74 20 73 75 62 6f 72 64 69 6e 61 74 65   Get subordinate
b970: 20 62 72 61 6e 63 68 65 73 20 76 69 61 20 74 68   branches via th
b980: 65 0a 09 20 20 20 20 41 4e 44 20 20 20 20 42 58  e..    AND    BX
b990: 2e 73 69 64 20 3d 20 50 2e 73 69 64 20 20 20 20  .sid = P.sid    
b9a0: 20 20 20 2d 2d 20 70 72 65 66 65 72 65 64 20 70     -- prefered p
b9b0: 61 72 65 6e 74 73 20 6f 66 20 74 68 65 69 72 20  arents of their 
b9c0: 73 79 6d 62 6f 6c 73 0a 09 7d 5d 5d 20 7b 0a 09  symbols..}]] {..
b9d0: 20 20 20 20 6c 61 70 70 65 6e 64 20 64 65 70 65      lappend depe
b9e0: 6e 64 65 6e 63 69 65 73 28 5b 6c 69 73 74 20 73  ndencies([list s
b9f0: 79 6d 3a 3a 62 72 61 6e 63 68 20 24 62 69 64 5d  ym::branch $bid]
ba00: 29 20 5b 6c 69 73 74 20 73 79 6d 3a 3a 62 72 61  ) [list sym::bra
ba10: 6e 63 68 20 24 63 68 69 6c 64 5d 0a 09 7d 0a 09  nch $child]..}..
ba20: 66 6f 72 65 61 63 68 20 7b 62 69 64 20 63 68 69  foreach {bid chi
ba30: 6c 64 7d 20 5b 73 74 61 74 65 20 72 75 6e 20 5b  ld} [state run [
ba40: 73 75 62 73 74 20 2d 6e 6f 63 6f 6d 6d 61 6e 64  subst -nocommand
ba50: 73 20 2d 6e 6f 62 61 63 6b 73 6c 61 73 68 65 73  s -nobackslashes
ba60: 20 7b 0a 09 20 20 20 20 53 45 4c 45 43 54 20 42   {..    SELECT B
ba70: 2e 62 69 64 2c 20 54 2e 74 69 64 0a 09 20 20 20  .bid, T.tid..   
ba80: 20 46 52 4f 4d 20 20 20 62 72 61 6e 63 68 20 42   FROM   branch B
ba90: 2c 20 70 72 65 66 65 72 65 64 70 61 72 65 6e 74  , preferedparent
baa0: 20 50 2c 20 74 61 67 20 54 0a 09 20 20 20 20 57   P, tag T..    W
bab0: 48 45 52 45 20 20 42 2e 62 69 64 20 49 4e 20 24  HERE  B.bid IN $
bac0: 74 68 65 73 65 74 20 20 20 20 20 2d 2d 20 52 65  theset     -- Re
bad0: 73 74 72 69 63 74 20 74 6f 20 62 72 61 6e 63 68  strict to branch
bae0: 65 73 20 6f 66 20 69 6e 74 65 72 65 73 74 0a 09  es of interest..
baf0: 20 20 20 20 41 4e 44 20 20 20 20 42 2e 73 69 64      AND    B.sid
bb00: 20 3d 20 50 2e 70 69 64 20 20 20 20 20 20 20 20   = P.pid        
bb10: 2d 2d 20 47 65 74 20 73 75 62 6f 72 64 69 6e 61  -- Get subordina
bb20: 74 65 20 74 61 67 73 20 76 69 61 20 74 68 65 0a  te tags via the.
bb30: 09 20 20 20 20 41 4e 44 20 20 20 20 54 2e 73 69  .    AND    T.si
bb40: 64 20 3d 20 50 2e 73 69 64 20 20 20 20 20 20 20  d = P.sid       
bb50: 20 2d 2d 20 70 72 65 66 65 72 65 64 20 70 61 72   -- prefered par
bb60: 65 6e 74 73 20 6f 66 20 74 68 65 69 72 20 73 79  ents of their sy
bb70: 6d 62 6f 6c 73 0a 09 7d 5d 5d 20 7b 0a 09 20 20  mbols..}]] {..  
bb80: 20 20 6c 61 70 70 65 6e 64 20 64 65 70 65 6e 64    lappend depend
bb90: 65 6e 63 69 65 73 28 5b 6c 69 73 74 20 73 79 6d  encies([list sym
bba0: 3a 3a 62 72 61 6e 63 68 20 24 62 69 64 5d 29 20  ::branch $bid]) 
bbb0: 5b 6c 69 73 74 20 73 79 6d 3a 3a 74 61 67 20 24  [list sym::tag $
bbc0: 63 68 69 6c 64 5d 0a 09 7d 0a 09 72 65 74 75 72  child]..}..retur
bbd0: 6e 0a 20 20 20 20 7d 0a 0a 20 20 20 20 23 20 72  n.    }..    # r
bbe0: 65 73 75 6c 74 20 3d 20 6c 69 73 74 20 28 63 68  esult = list (ch
bbf0: 61 6e 67 65 73 65 74 2d 69 64 29 0a 20 20 20 20  angeset-id).    
bc00: 74 79 70 65 6d 65 74 68 6f 64 20 63 73 5f 73 75  typemethod cs_su
bc10: 63 63 65 73 73 6f 72 73 20 7b 62 72 61 6e 63 68  ccessors {branch
bc20: 65 73 7d 20 7b 0a 20 20 20 20 20 20 20 20 23 20  es} {.        # 
bc30: 54 68 69 73 20 69 73 20 61 20 76 61 72 69 61 6e  This is a varian
bc40: 74 20 6f 66 20 27 73 75 63 63 65 73 73 6f 72 73  t of 'successors
bc50: 27 20 77 68 69 63 68 20 6d 61 70 73 20 74 68 65  ' which maps the
bc60: 20 6c 6f 77 2d 6c 65 76 65 6c 0a 20 20 20 20 20   low-level.     
bc70: 20 20 20 23 20 64 61 74 61 20 64 69 72 65 63 74     # data direct
bc80: 6c 79 20 74 6f 20 74 68 65 20 61 73 73 6f 63 69  ly to the associ
bc90: 61 74 65 64 20 63 68 61 6e 67 65 73 65 74 73 2e  ated changesets.
bca0: 20 49 2e 65 2e 20 69 6e 73 74 65 61 64 0a 20 20   I.e. instead.  
bcb0: 20 20 20 20 20 20 23 20 6d 69 6c 6c 69 6f 6e 73        # millions
bcc0: 20 6f 66 20 64 65 70 65 6e 64 65 6e 63 79 20 70   of dependency p
bcd0: 61 69 72 73 20 28 69 6e 20 65 78 74 72 65 6d 65  airs (in extreme
bce0: 20 63 61 73 65 73 20 28 45 78 61 6d 70 6c 65 3a   cases (Example:
bcf0: 20 54 63 6c 0a 20 20 20 20 20 20 20 20 23 20 43   Tcl.        # C
bd00: 56 53 29 29 20 77 65 20 72 65 74 75 72 6e 20 61  VS)) we return a
bd10: 20 76 65 72 79 20 73 68 6f 72 74 20 61 6e 64 20   very short and 
bd20: 6d 75 63 68 20 6d 6f 72 65 20 6d 61 6e 61 67 65  much more manage
bd30: 61 62 6c 65 20 6c 69 73 74 0a 20 20 20 20 20 20  able list.      
bd40: 20 20 23 20 6f 66 20 63 68 61 6e 67 65 73 65 74    # of changeset
bd50: 73 2e 0a 0a 09 73 65 74 20 74 68 65 73 65 74 20  s....set theset 
bd60: 28 27 5b 6a 6f 69 6e 20 24 62 72 61 6e 63 68 65  ('[join $branche
bd70: 73 20 7b 27 2c 27 7d 5d 27 29 0a 20 20 20 20 20  s {','}]').     
bd80: 20 20 20 72 65 74 75 72 6e 20 5b 73 74 61 74 65     return [state
bd90: 20 72 75 6e 20 5b 73 75 62 73 74 20 2d 6e 6f 63   run [subst -noc
bda0: 6f 6d 6d 61 6e 64 73 20 2d 6e 6f 62 61 63 6b 73  ommands -nobacks
bdb0: 6c 61 73 68 65 73 20 7b 0a 09 20 20 20 20 53 45  lashes {..    SE
bdc0: 4c 45 43 54 20 43 2e 63 69 64 0a 09 20 20 20 20  LECT C.cid..    
bdd0: 46 52 4f 4d 20 20 20 62 72 61 6e 63 68 20 42 2c  FROM   branch B,
bde0: 20 72 65 76 69 73 69 6f 6e 20 52 2c 20 63 73 69   revision R, csi
bdf0: 74 65 6d 20 43 49 2c 20 63 68 61 6e 67 65 73 65  tem CI, changese
be00: 74 20 43 0a 09 20 20 20 20 57 48 45 52 45 20 20  t C..    WHERE  
be10: 42 2e 62 69 64 20 49 4e 20 24 74 68 65 73 65 74  B.bid IN $theset
be20: 20 20 20 20 20 2d 2d 20 52 65 73 74 72 69 63 74       -- Restrict
be30: 20 74 6f 20 62 72 61 6e 63 68 65 73 20 6f 66 20   to branches of 
be40: 69 6e 74 65 72 65 73 74 0a 09 20 20 20 20 41 4e  interest..    AN
be50: 44 20 20 20 20 42 2e 66 69 72 73 74 20 3d 20 52  D    B.first = R
be60: 2e 72 69 64 09 2d 2d 20 47 65 74 20 66 69 72 73  .rid.-- Get firs
be70: 74 20 72 65 76 69 73 69 6f 6e 20 6f 6e 20 74 68  t revision on th
be80: 65 20 62 72 61 6e 63 68 0a 20 20 20 20 20 20 20  e branch.       
be90: 20 20 20 20 20 41 4e 44 20 20 20 20 43 49 2e 69       AND    CI.i
bea0: 69 64 20 3d 20 52 2e 72 69 64 20 20 20 20 20 20  id = R.rid      
beb0: 20 2d 2d 20 53 65 6c 65 63 74 20 61 6c 6c 20 63   -- Select all c
bec0: 68 61 6e 67 65 73 65 74 73 0a 20 20 20 20 20 20  hangesets.      
bed0: 20 20 20 20 20 20 41 4e 44 20 20 20 20 43 2e 63        AND    C.c
bee0: 69 64 20 3d 20 43 49 2e 63 69 64 09 2d 2d 20 63  id = CI.cid.-- c
bef0: 6f 6e 74 61 69 6e 69 6e 67 20 74 68 69 73 20 72  ontaining this r
bf00: 65 76 69 73 69 6f 6e 0a 20 20 20 20 20 20 20 20  evision.        
bf10: 20 20 20 20 41 4e 44 20 20 20 20 43 2e 74 79 70      AND    C.typ
bf20: 65 20 3d 20 30 09 09 2d 2d 20 77 68 69 63 68 20  e = 0..-- which 
bf30: 61 72 65 20 72 65 76 69 73 69 6f 6e 20 63 68 61  are revision cha
bf40: 6e 67 65 73 65 74 73 0a 20 20 20 20 55 4e 49 4f  ngesets.    UNIO
bf50: 4e 0a 09 20 20 20 20 53 45 4c 45 43 54 20 43 2e  N..    SELECT C.
bf60: 63 69 64 0a 09 20 20 20 20 46 52 4f 4d 20 20 20  cid..    FROM   
bf70: 62 72 61 6e 63 68 20 42 2c 20 70 72 65 66 65 72  branch B, prefer
bf80: 65 64 70 61 72 65 6e 74 20 50 2c 20 62 72 61 6e  edparent P, bran
bf90: 63 68 20 42 58 2c 20 63 73 69 74 65 6d 20 43 49  ch BX, csitem CI
bfa0: 2c 20 63 68 61 6e 67 65 73 65 74 20 43 0a 09 20  , changeset C.. 
bfb0: 20 20 20 57 48 45 52 45 20 20 42 2e 62 69 64 20     WHERE  B.bid 
bfc0: 49 4e 20 24 74 68 65 73 65 74 20 20 20 20 20 2d  IN $theset     -
bfd0: 2d 20 52 65 73 74 72 69 63 74 20 74 6f 20 62 72  - Restrict to br
bfe0: 61 6e 63 68 65 73 20 6f 66 20 69 6e 74 65 72 65  anches of intere
bff0: 73 74 0a 09 20 20 20 20 41 4e 44 20 20 20 20 42  st..    AND    B
c000: 2e 73 69 64 20 3d 20 50 2e 70 69 64 09 2d 2d 20  .sid = P.pid.-- 
c010: 47 65 74 20 73 75 62 6f 72 64 69 6e 61 74 65 20  Get subordinate 
c020: 62 72 61 6e 63 68 65 73 20 76 69 61 20 74 68 65  branches via the
c030: 0a 09 20 20 20 20 41 4e 44 20 20 20 20 42 58 2e  ..    AND    BX.
c040: 73 69 64 20 3d 20 50 2e 73 69 64 09 2d 2d 20 70  sid = P.sid.-- p
c050: 72 65 66 65 72 65 64 20 70 61 72 65 6e 74 73 20  refered parents 
c060: 6f 66 20 74 68 65 69 72 20 73 79 6d 62 6f 6c 73  of their symbols
c070: 0a 20 20 20 20 20 20 20 20 20 20 20 20 41 4e 44  .            AND
c080: 20 20 20 20 43 49 2e 69 69 64 20 3d 20 42 58 2e      CI.iid = BX.
c090: 62 69 64 20 20 20 20 20 20 2d 2d 20 53 65 6c 65  bid      -- Sele
c0a0: 63 74 20 61 6c 6c 20 63 68 61 6e 67 65 73 65 74  ct all changeset
c0b0: 73 0a 20 20 20 20 20 20 20 20 20 20 20 20 41 4e  s.            AN
c0c0: 44 20 20 20 20 43 2e 63 69 64 20 3d 20 43 49 2e  D    C.cid = CI.
c0d0: 63 69 64 09 2d 2d 20 63 6f 6e 74 61 69 6e 69 6e  cid.-- containin
c0e0: 67 20 74 68 65 20 73 75 62 6f 72 64 69 6e 61 74  g the subordinat
c0f0: 65 20 62 72 61 6e 63 68 65 73 0a 20 20 20 20 20  e branches.     
c100: 20 20 20 20 20 20 20 41 4e 44 20 20 20 20 43 2e         AND    C.
c110: 74 79 70 65 20 3d 20 32 09 09 2d 2d 20 77 68 69  type = 2..-- whi
c120: 63 68 20 61 72 65 20 62 72 61 6e 63 68 20 63 68  ch are branch ch
c130: 61 6e 67 65 73 65 74 73 0a 20 20 20 20 55 4e 49  angesets.    UNI
c140: 4f 4e 0a 09 20 20 20 20 53 45 4c 45 43 54 20 43  ON..    SELECT C
c150: 2e 63 69 64 0a 09 20 20 20 20 46 52 4f 4d 20 20  .cid..    FROM  
c160: 20 62 72 61 6e 63 68 20 42 2c 20 70 72 65 66 65   branch B, prefe
c170: 72 65 64 70 61 72 65 6e 74 20 50 2c 20 74 61 67  redparent P, tag
c180: 20 54 2c 20 63 73 69 74 65 6d 20 43 49 2c 20 63   T, csitem CI, c
c190: 68 61 6e 67 65 73 65 74 20 43 0a 09 20 20 20 20  hangeset C..    
c1a0: 57 48 45 52 45 20 20 42 2e 62 69 64 20 49 4e 20  WHERE  B.bid IN 
c1b0: 24 74 68 65 73 65 74 20 20 20 20 20 2d 2d 20 52  $theset     -- R
c1c0: 65 73 74 72 69 63 74 20 74 6f 20 62 72 61 6e 63  estrict to branc
c1d0: 68 65 73 20 6f 66 20 69 6e 74 65 72 65 73 74 0a  hes of interest.
c1e0: 09 20 20 20 20 41 4e 44 20 20 20 20 42 2e 73 69  .    AND    B.si
c1f0: 64 20 3d 20 50 2e 70 69 64 09 2d 2d 20 47 65 74  d = P.pid.-- Get
c200: 20 73 75 62 6f 72 64 69 6e 61 74 65 20 74 61 67   subordinate tag
c210: 73 20 76 69 61 20 74 68 65 0a 09 20 20 20 20 41  s via the..    A
c220: 4e 44 20 20 20 20 54 2e 73 69 64 20 3d 20 50 2e  ND    T.sid = P.
c230: 73 69 64 09 2d 2d 20 70 72 65 66 65 72 65 64 20  sid.-- prefered 
c240: 70 61 72 65 6e 74 73 20 6f 66 20 74 68 65 69 72  parents of their
c250: 20 73 79 6d 62 6f 6c 73 0a 20 20 20 20 20 20 20   symbols.       
c260: 20 20 20 20 20 41 4e 44 20 20 20 20 43 49 2e 69       AND    CI.i
c270: 69 64 20 3d 20 54 2e 74 69 64 20 20 20 20 20 20  id = T.tid      
c280: 20 2d 2d 20 53 65 6c 65 63 74 20 61 6c 6c 20 63   -- Select all c
c290: 68 61 6e 67 65 73 65 74 73 0a 20 20 20 20 20 20  hangesets.      
c2a0: 20 20 20 20 20 20 41 4e 44 20 20 20 20 43 2e 63        AND    C.c
c2b0: 69 64 20 3d 20 43 49 2e 63 69 64 09 2d 2d 20 63  id = CI.cid.-- c
c2c0: 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 73 75  ontaining the su
c2d0: 62 6f 72 64 69 6e 61 74 65 20 74 61 67 73 0a 20  bordinate tags. 
c2e0: 20 20 20 20 20 20 20 20 20 20 20 41 4e 44 20 20             AND  
c2f0: 20 20 43 2e 74 79 70 65 20 3d 20 31 09 09 2d 2d    C.type = 1..--
c300: 20 77 68 69 63 68 20 61 72 65 20 74 61 67 20 63   which are tag c
c310: 68 61 6e 67 65 73 65 74 73 0a 09 7d 5d 5d 0a 09  hangesets..}]]..
c320: 72 65 74 75 72 6e 0a 20 20 20 20 7d 0a 0a 20 20  return.    }..  
c330: 20 20 74 79 70 65 6d 65 74 68 6f 64 20 6c 69 6d    typemethod lim
c340: 69 74 73 20 7b 62 72 61 6e 63 68 65 73 7d 20 7b  its {branches} {
c350: 0a 09 23 20 4e 6f 74 65 73 2e 20 54 68 69 73 20  ..# Notes. This 
c360: 6d 65 74 68 6f 64 20 65 78 69 73 74 73 20 6f 6e  method exists on
c370: 6c 79 20 66 6f 72 20 62 72 61 6e 63 68 65 73 2e  ly for branches.
c380: 20 49 74 20 69 73 20 6e 65 65 64 65 64 20 74 6f   It is needed to
c390: 0a 09 23 20 67 65 74 20 64 65 74 61 69 6c 65 64  ..# get detailed
c3a0: 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f   information abo
c3b0: 75 74 20 61 20 62 61 63 6b 77 61 72 64 20 62 72  ut a backward br
c3c0: 61 6e 63 68 2e 20 49 74 20 64 6f 65 73 0a 09 23  anch. It does..#
c3d0: 20 6e 6f 74 20 61 70 70 6c 79 20 74 6f 20 74 61   not apply to ta
c3e0: 67 73 2c 20 6e 6f 72 20 72 65 76 69 73 69 6f 6e  gs, nor revision
c3f0: 73 2e 20 54 68 65 20 71 75 65 72 69 65 73 20 63  s. The queries c
c400: 61 6e 20 61 6c 73 6f 0a 09 23 20 72 65 73 74 72  an also..# restr
c410: 69 63 74 20 74 68 65 6d 73 65 6c 76 65 73 20 74  ict themselves t
c420: 6f 20 74 68 65 20 72 65 76 69 73 69 6f 6e 20 73  o the revision s
c430: 75 63 65 73 73 6f 72 73 2f 70 72 65 64 65 63 65  ucessors/predece
c440: 73 73 6f 72 73 0a 09 23 20 6f 66 20 62 72 61 6e  ssors..# of bran
c450: 63 68 65 73 2c 20 61 73 20 6f 6e 6c 79 20 74 68  ches, as only th
c460: 65 79 20 68 61 76 65 20 6f 72 64 65 72 69 6e 67  ey have ordering
c470: 20 64 61 74 61 20 61 6e 64 20 74 68 75 73 20 63   data and thus c
c480: 61 6e 0a 09 23 20 63 61 75 73 65 20 74 68 65 20  an..# cause the 
c490: 62 61 63 6b 77 61 72 64 6e 65 73 73 2e 0a 0a 09  backwardness....
c4a0: 73 65 74 20 74 68 65 73 65 74 20 28 27 5b 6a 6f  set theset ('[jo
c4b0: 69 6e 20 24 62 72 61 6e 63 68 65 73 20 7b 27 2c  in $branches {',
c4c0: 27 7d 5d 27 29 0a 0a 09 73 65 74 20 6d 61 78 70  '}]')...set maxp
c4d0: 20 5b 73 74 61 74 65 20 72 75 6e 20 5b 73 75 62   [state run [sub
c4e0: 73 74 20 2d 6e 6f 63 6f 6d 6d 61 6e 64 73 20 2d  st -nocommands -
c4f0: 6e 6f 62 61 63 6b 73 6c 61 73 68 65 73 20 7b 0a  nobackslashes {.
c500: 09 20 20 20 20 2d 2d 20 6d 61 78 69 6d 61 6c 20  .    -- maximal 
c510: 70 72 65 64 65 63 65 73 73 6f 72 20 70 6f 73 69  predecessor posi
c520: 74 69 6f 6e 20 70 65 72 20 62 72 61 6e 63 68 0a  tion per branch.
c530: 09 20 20 20 20 53 45 4c 45 43 54 20 42 2e 62 69  .    SELECT B.bi
c540: 64 2c 20 4d 41 58 20 28 43 4f 2e 70 6f 73 29 0a  d, MAX (CO.pos).
c550: 09 20 20 20 20 46 52 4f 4d 20 20 20 62 72 61 6e  .    FROM   bran
c560: 63 68 20 42 2c 20 72 65 76 69 73 69 6f 6e 20 52  ch B, revision R
c570: 2c 20 63 73 69 74 65 6d 20 43 49 2c 20 63 68 61  , csitem CI, cha
c580: 6e 67 65 73 65 74 20 43 2c 20 63 73 6f 72 64 65  ngeset C, csorde
c590: 72 20 43 4f 0a 09 20 20 20 20 57 48 45 52 45 20  r CO..    WHERE 
c5a0: 20 42 2e 62 69 64 20 49 4e 20 24 74 68 65 73 65   B.bid IN $these
c5b0: 74 20 20 20 20 20 2d 2d 20 52 65 73 74 72 69 63  t     -- Restric
c5c0: 74 20 74 6f 20 62 72 61 6e 63 68 65 73 20 6f 66  t to branches of
c5d0: 20 69 6e 74 65 72 65 73 74 0a 09 20 20 20 20 41   interest..    A
c5e0: 4e 44 20 20 20 20 42 2e 72 6f 6f 74 20 3d 20 52  ND    B.root = R
c5f0: 2e 72 69 64 20 20 20 20 20 20 20 2d 2d 20 47 65  .rid       -- Ge
c600: 74 20 62 72 61 6e 63 68 20 72 6f 6f 74 20 72 65  t branch root re
c610: 76 69 73 69 6f 6e 73 0a 09 20 20 20 20 41 4e 44  visions..    AND
c620: 20 20 20 20 43 49 2e 69 69 64 20 3d 20 52 2e 72      CI.iid = R.r
c630: 69 64 20 20 20 20 20 20 20 2d 2d 20 47 65 74 20  id       -- Get 
c640: 63 68 61 6e 67 65 73 65 74 73 20 63 6f 6e 74 61  changesets conta
c650: 69 6e 69 6e 67 20 74 68 65 0a 09 20 20 20 20 41  ining the..    A
c660: 4e 44 20 20 20 20 43 2e 63 69 64 20 3d 20 43 49  ND    C.cid = CI
c670: 2e 63 69 64 20 20 20 20 20 20 20 2d 2d 20 72 6f  .cid       -- ro
c680: 6f 74 20 72 65 76 69 73 69 6f 6e 73 2c 20 77 68  ot revisions, wh
c690: 69 63 68 20 61 72 65 0a 09 20 20 20 20 41 4e 44  ich are..    AND
c6a0: 20 20 20 20 43 2e 74 79 70 65 20 3d 20 30 20 20      C.type = 0  
c6b0: 20 20 20 20 20 20 20 20 20 2d 2d 20 72 65 76 69           -- revi
c6c0: 73 69 6f 6e 20 63 68 61 6e 67 65 73 65 74 73 0a  sion changesets.
c6d0: 09 20 20 20 20 41 4e 44 20 20 20 20 43 4f 2e 63  .    AND    CO.c
c6e0: 69 64 20 3d 20 43 2e 63 69 64 20 20 20 20 20 20  id = C.cid      
c6f0: 20 2d 2d 20 47 65 74 20 74 68 65 69 72 20 74 6f   -- Get their to
c700: 70 6f 6c 6f 67 69 63 61 6c 20 6f 72 64 65 72 69  pological orderi
c710: 6e 67 0a 09 20 20 20 20 47 52 4f 55 50 20 42 59  ng..    GROUP BY
c720: 20 42 2e 62 69 64 0a 09 7d 5d 5d 0a 0a 09 73 65   B.bid..}]]...se
c730: 74 20 6d 69 6e 73 20 5b 73 74 61 74 65 20 72 75  t mins [state ru
c740: 6e 20 5b 73 75 62 73 74 20 2d 6e 6f 63 6f 6d 6d  n [subst -nocomm
c750: 61 6e 64 73 20 2d 6e 6f 62 61 63 6b 73 6c 61 73  ands -nobackslas
c760: 68 65 73 20 7b 0a 09 20 20 20 20 2d 2d 20 6d 69  hes {..    -- mi
c770: 6e 69 6d 61 6c 20 73 75 63 63 65 73 73 6f 72 20  nimal successor 
c780: 70 6f 73 69 74 69 6f 6e 20 70 65 72 20 62 72 61  position per bra
c790: 6e 63 68 0a 09 20 20 20 20 53 45 4c 45 43 54 20  nch..    SELECT 
c7a0: 42 2e 62 69 64 2c 20 4d 49 4e 20 28 43 4f 2e 70  B.bid, MIN (CO.p
c7b0: 6f 73 29 0a 09 20 20 20 20 46 52 4f 4d 20 20 20  os)..    FROM   
c7c0: 62 72 61 6e 63 68 20 42 2c 20 72 65 76 69 73 69  branch B, revisi
c7d0: 6f 6e 20 52 2c 20 63 73 69 74 65 6d 20 43 49 2c  on R, csitem CI,
c7e0: 20 63 68 61 6e 67 65 73 65 74 20 43 2c 20 63 73   changeset C, cs
c7f0: 6f 72 64 65 72 20 43 4f 0a 09 20 20 20 20 57 48  order CO..    WH
c800: 45 52 45 20 20 42 2e 62 69 64 20 49 4e 20 24 74  ERE  B.bid IN $t
c810: 68 65 73 65 74 20 20 20 20 20 2d 2d 20 52 65 73  heset     -- Res
c820: 74 72 69 63 74 20 74 6f 20 62 72 61 6e 63 68 65  trict to branche
c830: 73 20 6f 66 20 69 6e 74 65 72 65 73 74 0a 09 20  s of interest.. 
c840: 20 20 20 41 4e 44 20 20 20 20 42 2e 66 69 72 73     AND    B.firs
c850: 74 20 3d 20 52 2e 72 69 64 20 20 20 20 20 20 2d  t = R.rid      -
c860: 2d 20 47 65 74 20 74 68 65 20 66 69 72 73 74 20  - Get the first 
c870: 72 65 76 69 73 69 6f 6e 73 20 6f 6e 20 74 68 65  revisions on the
c880: 20 62 72 61 6e 63 68 65 73 0a 09 20 20 20 20 41   branches..    A
c890: 4e 44 20 20 20 20 43 49 2e 69 69 64 20 3d 20 52  ND    CI.iid = R
c8a0: 2e 72 69 64 20 20 20 20 20 20 20 2d 2d 20 47 65  .rid       -- Ge
c8b0: 74 20 63 68 61 6e 67 65 73 65 74 73 20 63 6f 6e  t changesets con
c8c0: 74 61 69 6e 69 6e 67 20 74 68 65 0a 09 20 20 20  taining the..   
c8d0: 20 41 4e 44 20 20 20 20 43 2e 63 69 64 20 3d 20   AND    C.cid = 
c8e0: 43 49 2e 63 69 64 09 2d 2d 20 66 69 72 73 74 20  CI.cid.-- first 
c8f0: 72 65 76 69 73 69 6f 6e 73 2c 20 77 68 69 63 68  revisions, which
c900: 20 61 72 65 0a 09 20 20 20 20 41 4e 44 20 20 20   are..    AND   
c910: 20 43 2e 74 79 70 65 20 3d 20 30 09 09 2d 2d 20   C.type = 0..-- 
c920: 72 65 76 69 73 69 6f 6e 20 63 68 61 6e 67 65 73  revision changes
c930: 65 74 73 0a 09 20 20 20 20 41 4e 44 20 20 20 20  ets..    AND    
c940: 43 4f 2e 63 69 64 20 3d 20 43 2e 63 69 64 09 2d  CO.cid = C.cid.-
c950: 2d 20 47 65 74 20 74 68 65 69 72 20 74 6f 70 6f  - Get their topo
c960: 6c 6f 67 69 63 61 6c 20 6f 72 64 65 72 69 6e 67  logical ordering
c970: 0a 09 20 20 20 20 47 52 4f 55 50 20 42 59 20 42  ..    GROUP BY B
c980: 2e 62 69 64 0a 09 7d 5d 5d 0a 0a 20 20 20 20 20  .bid..}]]..     
c990: 20 20 20 72 65 74 75 72 6e 20 5b 6c 69 73 74 20     return [list 
c9a0: 24 6d 61 78 70 20 24 6d 69 6e 73 5d 0a 20 20 20  $maxp $mins].   
c9b0: 20 7d 0a 0a 20 20 20 20 23 20 23 20 23 23 20 23   }..    # # ## #
c9c0: 23 23 20 23 23 23 23 23 20 23 23 23 23 23 23 23  ## ##### #######
c9d0: 23 20 23 23 23 23 23 23 23 23 23 23 23 23 23 0a  # #############.
c9e0: 20 20 20 20 23 23 20 43 6f 6e 66 69 67 75 72 61      ## Configura
c9f0: 74 69 6f 6e 0a 0a 20 20 20 20 70 72 61 67 6d 61  tion..    pragma
ca00: 20 2d 68 61 73 69 6e 73 74 61 6e 63 65 73 20 20   -hasinstances  
ca10: 20 6e 6f 20 3b 20 23 20 73 69 6e 67 6c 65 74 6f   no ; # singleto
ca20: 6e 0a 20 20 20 20 70 72 61 67 6d 61 20 2d 68 61  n.    pragma -ha
ca30: 73 74 79 70 65 69 6e 66 6f 20 20 20 20 6e 6f 20  stypeinfo    no 
ca40: 3b 20 23 20 6e 6f 20 69 6e 74 72 6f 73 70 65 63  ; # no introspec
ca50: 74 69 6f 6e 0a 20 20 20 20 70 72 61 67 6d 61 20  tion.    pragma 
ca60: 2d 68 61 73 74 79 70 65 64 65 73 74 72 6f 79 20  -hastypedestroy 
ca70: 6e 6f 20 3b 20 23 20 69 6d 6d 6f 72 74 61 6c 0a  no ; # immortal.
ca80: 7d 0a 0a 23 20 23 20 23 23 20 23 23 23 20 23 23  }..# # ## ### ##
ca90: 23 23 23 20 23 23 23 23 23 23 23 23 20 23 23 23  ### ######## ###
caa0: 23 23 23 23 23 23 23 23 23 23 20 23 23 23 23 23  ########## #####
cab0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
cac0: 0a 23 23 0a 0a 6e 61 6d 65 73 70 61 63 65 20 65  .##..namespace e
cad0: 76 61 6c 20 3a 3a 76 63 3a 3a 66 6f 73 73 69 6c  val ::vc::fossil
cae0: 3a 3a 69 6d 70 6f 72 74 3a 3a 63 76 73 3a 3a 70  ::import::cvs::p
caf0: 72 6f 6a 65 63 74 20 7b 0a 20 20 20 20 6e 61 6d  roject {.    nam
cb00: 65 73 70 61 63 65 20 65 78 70 6f 72 74 20 72 65  espace export re
cb10: 76 0a 20 20 20 20 6e 61 6d 65 73 70 61 63 65 20  v.    namespace 
cb20: 65 76 61 6c 20 72 65 76 20 7b 0a 09 6e 61 6d 65  eval rev {..name
cb30: 73 70 61 63 65 20 69 6d 70 6f 72 74 20 3a 3a 76  space import ::v
cb40: 63 3a 3a 66 6f 73 73 69 6c 3a 3a 69 6d 70 6f 72  c::fossil::impor
cb50: 74 3a 3a 63 76 73 3a 3a 73 74 61 74 65 0a 09 6e  t::cvs::state..n
cb60: 61 6d 65 73 70 61 63 65 20 69 6d 70 6f 72 74 20  amespace import 
cb70: 3a 3a 76 63 3a 3a 66 6f 73 73 69 6c 3a 3a 69 6d  ::vc::fossil::im
cb80: 70 6f 72 74 3a 3a 63 76 73 3a 3a 69 6e 74 65 67  port::cvs::integ
cb90: 72 69 74 79 0a 09 6e 61 6d 65 73 70 61 63 65 20  rity..namespace 
cba0: 69 6d 70 6f 72 74 20 3a 3a 76 63 3a 3a 74 6f 6f  import ::vc::too
cbb0: 6c 73 3a 3a 6d 69 73 63 3a 3a 2a 0a 09 6e 61 6d  ls::misc::*..nam
cbc0: 65 73 70 61 63 65 20 69 6d 70 6f 72 74 20 3a 3a  espace import ::
cbd0: 76 63 3a 3a 74 6f 6f 6c 73 3a 3a 74 72 6f 75 62  vc::tools::troub
cbe0: 6c 65 0a 09 6e 61 6d 65 73 70 61 63 65 20 69 6d  le..namespace im
cbf0: 70 6f 72 74 20 3a 3a 76 63 3a 3a 74 6f 6f 6c 73  port ::vc::tools
cc00: 3a 3a 6c 6f 67 0a 09 6c 6f 67 20 72 65 67 69 73  ::log..log regis
cc10: 74 65 72 20 63 73 65 74 73 0a 0a 09 23 20 53 65  ter csets...# Se
cc20: 74 20 75 70 20 74 68 65 20 68 65 6c 70 65 72 20  t up the helper 
cc30: 73 69 6e 67 6c 65 74 6f 6e 73 0a 09 6e 61 6d 65  singletons..name
cc40: 73 70 61 63 65 20 65 76 61 6c 20 72 65 76 20 7b  space eval rev {
cc50: 0a 09 20 20 20 20 6e 61 6d 65 73 70 61 63 65 20  ..    namespace 
cc60: 69 6d 70 6f 72 74 20 3a 3a 76 63 3a 3a 66 6f 73  import ::vc::fos
cc70: 73 69 6c 3a 3a 69 6d 70 6f 72 74 3a 3a 63 76 73  sil::import::cvs
cc80: 3a 3a 73 74 61 74 65 0a 09 20 20 20 20 6e 61 6d  ::state..    nam
cc90: 65 73 70 61 63 65 20 69 6d 70 6f 72 74 20 3a 3a  espace import ::
cca0: 76 63 3a 3a 66 6f 73 73 69 6c 3a 3a 69 6d 70 6f  vc::fossil::impo
ccb0: 72 74 3a 3a 63 76 73 3a 3a 69 6e 74 65 67 72 69  rt::cvs::integri
ccc0: 74 79 0a 09 7d 0a 09 6e 61 6d 65 73 70 61 63 65  ty..}..namespace
ccd0: 20 65 76 61 6c 20 73 79 6d 3a 3a 74 61 67 20 7b   eval sym::tag {
cce0: 0a 09 20 20 20 20 6e 61 6d 65 73 70 61 63 65 20  ..    namespace 
ccf0: 69 6d 70 6f 72 74 20 3a 3a 76 63 3a 3a 66 6f 73  import ::vc::fos
cd00: 73 69 6c 3a 3a 69 6d 70 6f 72 74 3a 3a 63 76 73  sil::import::cvs
cd10: 3a 3a 73 74 61 74 65 0a 09 20 20 20 20 6e 61 6d  ::state..    nam
cd20: 65 73 70 61 63 65 20 69 6d 70 6f 72 74 20 3a 3a  espace import ::
cd30: 76 63 3a 3a 66 6f 73 73 69 6c 3a 3a 69 6d 70 6f  vc::fossil::impo
cd40: 72 74 3a 3a 63 76 73 3a 3a 69 6e 74 65 67 72 69  rt::cvs::integri
cd50: 74 79 0a 09 7d 0a 09 6e 61 6d 65 73 70 61 63 65  ty..}..namespace
cd60: 20 65 76 61 6c 20 73 79 6d 3a 3a 62 72 61 6e 63   eval sym::branc
cd70: 68 20 7b 0a 09 20 20 20 20 6e 61 6d 65 73 70 61  h {..    namespa
cd80: 63 65 20 69 6d 70 6f 72 74 20 3a 3a 76 63 3a 3a  ce import ::vc::
cd90: 66 6f 73 73 69 6c 3a 3a 69 6d 70 6f 72 74 3a 3a  fossil::import::
cda0: 63 76 73 3a 3a 73 74 61 74 65 0a 09 20 20 20 20  cvs::state..    
cdb0: 6e 61 6d 65 73 70 61 63 65 20 69 6d 70 6f 72 74  namespace import
cdc0: 20 3a 3a 76 63 3a 3a 66 6f 73 73 69 6c 3a 3a 69   ::vc::fossil::i
cdd0: 6d 70 6f 72 74 3a 3a 63 76 73 3a 3a 69 6e 74 65  mport::cvs::inte
cde0: 67 72 69 74 79 0a 09 7d 0a 20 20 20 20 7d 0a 7d  grity..}.    }.}
cdf0: 0a 0a 23 20 23 20 23 23 20 23 23 23 20 23 23 23  ..# # ## ### ###
ce00: 23 23 20 23 23 23 23 23 23 23 23 20 23 23 23 23  ## ######## ####
ce10: 23 23 23 23 23 23 23 23 23 20 23 23 23 23 23 23  ######### ######
ce20: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 0a  ###############.
ce30: 23 23 20 52 65 61 64 79 0a 0a 70 61 63 6b 61 67  ## Ready..packag
ce40: 65 20 70 72 6f 76 69 64 65 20 76 63 3a 3a 66 6f  e provide vc::fo
ce50: 73 73 69 6c 3a 3a 69 6d 70 6f 72 74 3a 3a 63 76  ssil::import::cv
ce60: 73 3a 3a 70 72 6f 6a 65 63 74 3a 3a 72 65 76 20  s::project::rev 
ce70: 31 2e 30 0a 72 65 74 75 72 6e 0a                 1.0.return.