0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20 /*.** Copyright
0010: 28 63 29 20 32 30 30 37 20 44 2e 20 52 69 63 68 (c) 2007 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54 ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66 his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75 u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20 te it and/or.**
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20 modify it under
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65 the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62 GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 76 lic.** License v
00b0: 65 72 73 69 6f 6e 20 32 20 61 73 20 70 75 62 6c ersion 2 as publ
00c0: 69 73 68 65 64 20 62 79 20 74 68 65 20 46 72 65 ished by the Fre
00d0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 e Software Found
00e0: 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69 ation..**.** Thi
00f0: 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73 s program is dis
0100: 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20 tributed in the
0110: 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c hope that it wil
0120: 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20 l be useful,.**
0130: 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20 but WITHOUT ANY
0140: 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75 WARRANTY; withou
0150: 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69 t even the impli
0160: 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a ed warranty of.*
0170: 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54 * MERCHANTABILIT
0180: 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52 Y or FITNESS FOR
0190: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55 A PARTICULAR PU
01a0: 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 20 RPOSE. See the
01b0: 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20 50 GNU.** General P
01c0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66 6f ublic License fo
01d0: 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e 0a r more details..
01e0: 2a 2a 20 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c ** .** You shoul
01f0: 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20 d have received
0200: 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e a copy of the GN
0210: 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63 U General Public
0220: 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e .** License alon
0230: 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72 g with this libr
0240: 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69 ary; if not, wri
0250: 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65 te to the.** Fre
0260: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 e Software Found
0270: 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20 ation, Inc., 59
0280: 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53 Temple Place - S
0290: 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73 uite 330,.** Bos
02a0: 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31 ton, MA 02111-1
02b0: 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20 307, USA..**.**
02c0: 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69 Author contact i
02d0: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20 nformation:.**
02e0: 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a drh@hwaci.com.*
02f0: 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68 * http://www.h
0300: 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a waci.com/drh/.**
0310: 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a .***************
0320: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0330: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0340: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0350: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0360: 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 66 69 6c 65 .**.** This file
0370: 20 63 6f 6e 74 61 69 6e 73 20 63 6f 64 65 20 75 contains code u
0380: 73 65 64 20 74 6f 20 66 69 6e 64 20 64 65 63 65 sed to find dece
0390: 6e 64 61 6e 74 73 20 6f 66 20 61 20 76 65 72 73 ndants of a vers
03a0: 69 6f 6e 0a 2a 2a 20 6f 72 20 6c 65 61 76 65 73 ion.** or leaves
03b0: 20 6f 66 20 61 20 76 65 72 73 69 6f 6e 20 74 72 of a version tr
03c0: 65 65 2e 0a 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 ee..*/.#include
03d0: 22 63 6f 6e 66 69 67 2e 68 22 0a 23 69 6e 63 6c "config.h".#incl
03e0: 75 64 65 20 22 64 65 73 63 65 6e 64 61 6e 74 73 ude "descendants
03f0: 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 3c 61 73 .h".#include <as
0400: 73 65 72 74 2e 68 3e 0a 0a 0a 2f 2a 0a 2a 2a 20 sert.h>.../*.**
0410: 43 72 65 61 74 65 20 61 20 74 65 6d 70 6f 72 61 Create a tempora
0420: 72 79 20 74 61 62 6c 65 20 6e 61 6d 65 64 20 22 ry table named "
0430: 6c 65 61 76 65 73 22 20 69 66 20 69 74 20 64 6f leaves" if it do
0440: 65 73 20 6e 6f 74 0a 2a 2a 20 61 6c 72 65 61 64 es not.** alread
0450: 79 20 65 78 69 73 74 2e 20 20 4c 6f 61 64 20 74 y exist. Load t
0460: 68 69 73 20 74 61 62 6c 65 20 77 69 74 68 20 74 his table with t
0470: 68 65 20 52 49 44 20 6f 66 20 61 6c 6c 0a 2a 2a he RID of all.**
0480: 20 63 68 65 63 6b 2d 69 6e 73 20 74 68 61 74 20 check-ins that
0490: 61 72 65 20 6c 65 61 76 65 73 20 77 68 69 63 68 are leaves which
04a0: 20 61 72 65 20 64 65 63 65 6e 64 65 64 20 66 72 are decended fr
04b0: 6f 6d 0a 2a 2a 20 63 68 65 63 6b 2d 69 6e 20 69 om.** check-in i
04c0: 42 61 73 65 2e 0a 2a 2a 0a 2a 2a 20 41 20 22 6c Base..**.** A "l
04d0: 65 61 66 22 20 69 73 20 61 20 63 68 65 63 6b 2d eaf" is a check-
04e0: 69 6e 20 74 68 61 74 20 68 61 73 20 6e 6f 20 63 in that has no c
04f0: 68 69 6c 64 72 65 6e 2e 20 20 46 6f 72 20 74 68 hildren. For th
0500: 65 20 70 75 72 70 6f 73 65 0a 2a 2a 20 6f 66 20 e purpose.** of
0510: 66 69 6e 64 69 6e 67 20 6c 65 61 76 65 73 2c 20 finding leaves,
0520: 63 68 69 6c 64 72 65 6e 20 6d 61 72 6b 65 64 20 children marked
0530: 77 69 74 68 20 74 68 65 20 22 6e 65 77 62 72 61 with the "newbra
0540: 6e 63 68 22 20 74 61 67 20 61 72 65 0a 2a 2a 20 nch" tag are.**
0550: 6e 6f 74 20 63 6f 75 6e 74 65 64 20 61 73 20 63 not counted as c
0560: 68 69 6c 64 72 65 6e 2e 20 20 46 6f 72 20 65 78 hildren. For ex
0570: 61 6d 70 6c 65 3a 0a 2a 2a 0a 2a 2a 0a 2a 2a 20 ample:.**.**.**
0580: 20 20 20 41 20 2d 3e 20 42 20 2d 3e 20 43 20 2d A -> B -> C -
0590: 3e 20 44 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 > D.**
05a0: 60 2d 3e 20 45 0a 2a 2a 0a 2a 2a 20 44 20 61 6e `-> E.**.** D an
05b0: 64 20 45 20 61 72 65 20 63 6c 65 61 72 6c 79 20 d E are clearly
05c0: 6c 65 61 76 65 73 20 73 69 6e 63 65 20 74 68 65 leaves since the
05d0: 79 20 68 61 76 65 20 6e 6f 20 63 68 69 6c 64 72 y have no childr
05e0: 65 6e 2e 20 20 49 66 0a 2a 2a 20 44 20 68 61 73 en. If.** D has
05f0: 20 74 68 65 20 22 6e 65 77 62 72 61 6e 63 68 22 the "newbranch"
0600: 20 74 61 67 2c 20 74 68 65 6e 20 43 20 69 73 20 tag, then C is
0610: 61 6c 73 6f 20 61 20 6c 65 61 66 20 73 69 6e 63 also a leaf sinc
0620: 65 20 69 74 73 20 6f 6e 6c 79 0a 2a 2a 20 63 68 e its only.** ch
0630: 69 6c 64 20 69 73 20 6d 61 72 6b 65 64 20 61 73 ild is marked as
0640: 20 61 20 6e 65 77 62 72 61 6e 63 68 2e 0a 2a 2a a newbranch..**
0650: 0a 2a 2a 20 54 68 65 20 63 6c 6f 73 65 4d 6f 64 .** The closeMod
0660: 65 20 66 6c 61 67 20 64 65 74 65 72 6d 69 6e 65 e flag determine
0670: 73 20 62 65 68 61 76 69 6f 72 20 61 73 73 6f 63 s behavior assoc
0680: 69 61 74 65 64 20 77 69 74 68 20 74 68 65 20 22 iated with the "
0690: 63 6c 6f 73 65 64 22 0a 2a 2a 20 74 61 67 3a 0a closed".** tag:.
06a0: 2a 2a 0a 2a 2a 20 20 20 20 63 6c 6f 73 65 4d 6f **.** closeMo
06b0: 64 65 3d 3d 30 20 20 20 20 20 20 20 53 68 6f 77 de==0 Show
06c0: 20 61 6c 6c 20 6c 65 61 76 65 73 20 72 65 67 61 all leaves rega
06d0: 72 64 6c 65 73 73 20 6f 66 20 74 68 65 20 22 63 rdless of the "c
06e0: 6c 6f 73 65 64 22 20 74 61 67 2e 0a 2a 2a 0a 2a losed" tag..**.*
06f0: 2a 20 20 20 20 63 6c 6f 73 65 4d 6f 64 65 3d 3d * closeMode==
0700: 31 20 20 20 20 20 20 20 53 68 6f 77 20 6f 6e 6c 1 Show onl
0710: 79 20 6c 65 61 76 65 73 20 77 69 74 68 6f 75 74 y leaves without
0720: 20 74 68 65 20 22 63 6c 6f 73 65 64 22 20 74 61 the "closed" ta
0730: 67 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 63 6c 6f 73 g..**.** clos
0740: 65 4d 6f 64 65 3d 3d 32 20 20 20 20 20 20 20 53 eMode==2 S
0750: 68 6f 77 20 6f 6e 6c 79 20 6c 65 61 76 65 73 20 how only leaves
0760: 77 69 74 68 20 74 68 65 20 22 63 6c 6f 73 65 64 with the "closed
0770: 22 20 74 61 67 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 " tag..**.** The
0780: 20 64 65 66 61 75 6c 74 20 62 65 68 61 76 69 6f default behavio
0790: 72 20 69 73 20 74 6f 20 69 67 6e 6f 72 65 20 63 r is to ignore c
07a0: 6c 6f 73 65 64 20 6c 65 61 76 65 73 20 28 63 6c losed leaves (cl
07b0: 6f 73 65 4d 6f 64 65 3d 3d 30 29 2e 20 20 54 6f oseMode==0). To
07c0: 0a 2a 2a 20 53 68 6f 77 20 61 6c 6c 20 6c 65 61 .** Show all lea
07d0: 76 65 73 2c 20 75 73 65 20 63 6c 6f 73 65 4d 6f ves, use closeMo
07e0: 64 65 3d 3d 31 2e 20 20 54 6f 20 73 68 6f 77 20 de==1. To show
07f0: 6f 6e 6c 79 20 63 6c 6f 73 65 64 20 6c 65 61 76 only closed leav
0800: 65 73 2c 20 75 73 65 0a 2a 2a 20 63 6c 6f 73 65 es, use.** close
0810: 4d 6f 64 65 3d 3d 32 2e 0a 2a 2f 0a 76 6f 69 64 Mode==2..*/.void
0820: 20 63 6f 6d 70 75 74 65 5f 6c 65 61 76 65 73 28 compute_leaves(
0830: 69 6e 74 20 69 42 61 73 65 2c 20 69 6e 74 20 63 int iBase, int c
0840: 6c 6f 73 65 4d 6f 64 65 29 7b 0a 20 20 42 61 67 loseMode){. Bag
0850: 20 73 65 65 6e 3b 20 20 20 20 20 20 20 2f 2a 20 seen; /*
0860: 44 65 73 63 65 6e 64 61 6e 74 73 20 73 65 65 6e Descendants seen
0870: 20 2a 2f 0a 20 20 42 61 67 20 70 65 6e 64 69 6e */. Bag pendin
0880: 67 3b 20 20 20 20 2f 2a 20 55 6e 70 72 6f 70 61 g; /* Unpropa
0890: 67 61 74 65 64 20 64 65 73 63 65 6e 64 61 6e 74 gated descendant
08a0: 73 20 2a 2f 0a 20 20 53 74 6d 74 20 71 31 3b 20 s */. Stmt q1;
08b0: 20 20 20 20 20 20 20 2f 2a 20 51 75 65 72 79 20 /* Query
08c0: 74 6f 20 66 69 6e 64 20 63 68 69 6c 64 72 65 6e to find children
08d0: 20 6f 66 20 61 20 63 68 65 63 6b 2d 69 6e 20 2a of a check-in *
08e0: 2f 0a 20 20 53 74 6d 74 20 69 73 42 72 3b 20 20 /. Stmt isBr;
08f0: 20 20 20 20 2f 2a 20 51 75 65 72 79 20 74 6f 20 /* Query to
0900: 63 68 65 63 6b 20 74 6f 20 73 65 65 20 69 66 20 check to see if
0910: 61 20 63 68 65 63 6b 2d 69 6e 20 73 74 61 72 74 a check-in start
0920: 73 20 61 20 6e 65 77 20 62 72 61 6e 63 68 20 2a s a new branch *
0930: 2f 0a 20 20 53 74 6d 74 20 69 6e 73 3b 20 20 20 /. Stmt ins;
0940: 20 20 20 20 2f 2a 20 49 4e 53 45 52 54 20 73 74 /* INSERT st
0950: 61 74 65 6d 65 6e 74 20 66 6f 72 20 61 20 6e 65 atement for a ne
0960: 77 20 72 65 63 6f 72 64 20 2a 2f 0a 0a 20 20 2f w record */.. /
0970: 2a 20 43 72 65 61 74 65 20 74 68 65 20 4c 45 41 * Create the LEA
0980: 56 45 53 20 74 61 62 6c 65 20 69 66 20 69 74 20 VES table if it
0990: 64 6f 65 73 20 6e 6f 74 20 61 6c 72 65 61 64 79 does not already
09a0: 20 65 78 69 73 74 2e 20 20 4d 61 6b 65 20 73 75 exist. Make su
09b0: 72 65 0a 20 20 2a 2a 20 69 74 20 69 73 20 65 6d re. ** it is em
09c0: 70 74 79 2e 0a 20 20 2a 2f 0a 20 20 64 62 5f 6d pty.. */. db_m
09d0: 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 20 22 ulti_exec(. "
09e0: 43 52 45 41 54 45 20 54 45 4d 50 20 54 41 42 4c CREATE TEMP TABL
09f0: 45 20 49 46 20 4e 4f 54 20 45 58 49 53 54 53 20 E IF NOT EXISTS
0a00: 6c 65 61 76 65 73 28 22 0a 20 20 20 20 22 20 20 leaves(". "
0a10: 72 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d rid INTEGER PRIM
0a20: 41 52 59 20 4b 45 59 22 0a 20 20 20 20 22 29 3b ARY KEY". ");
0a30: 22 0a 20 20 20 20 22 44 45 4c 45 54 45 20 46 52 ". "DELETE FR
0a40: 4f 4d 20 6c 65 61 76 65 73 3b 22 0a 20 20 29 3b OM leaves;". );
0a50: 0a 0a 20 20 2f 2a 20 57 65 20 61 72 65 20 63 68 .. /* We are ch
0a60: 65 63 6b 69 6e 67 20 61 6c 6c 20 64 65 73 63 65 ecking all desce
0a70: 6e 64 61 6e 74 73 20 6f 66 20 69 42 61 73 65 2e ndants of iBase.
0a80: 20 20 49 66 20 69 42 61 73 65 3d 3d 30 2c 20 74 If iBase==0, t
0a90: 68 65 6e 0a 20 20 2a 2a 20 63 68 61 6e 67 65 20 hen. ** change
0aa0: 69 42 61 73 65 20 74 6f 20 62 65 20 74 68 65 20 iBase to be the
0ab0: 72 6f 6f 74 20 6f 66 20 74 68 65 20 65 6e 74 69 root of the enti
0ac0: 72 65 20 63 68 65 63 6b 2d 69 6e 20 68 69 65 72 re check-in hier
0ad0: 61 72 63 68 79 2e 0a 20 20 2a 2f 0a 20 20 69 66 archy.. */. if
0ae0: 28 20 69 42 61 73 65 3c 3d 30 20 29 7b 0a 20 20 ( iBase<=0 ){.
0af0: 20 20 69 42 61 73 65 20 3d 20 64 62 5f 69 6e 74 iBase = db_int
0b00: 28 30 2c 20 22 53 45 4c 45 43 54 20 6f 62 6a 69 (0, "SELECT obji
0b10: 64 20 46 52 4f 4d 20 65 76 65 6e 74 20 57 48 45 d FROM event WHE
0b20: 52 45 20 74 79 70 65 3d 27 63 69 27 22 0a 20 20 RE type='ci'".
0b30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0b40: 20 20 20 20 22 20 4f 52 44 45 52 20 42 59 20 6d " ORDER BY m
0b50: 74 69 6d 65 20 4c 49 4d 49 54 20 31 22 29 3b 0a time LIMIT 1");.
0b60: 20 20 20 20 69 66 28 20 69 42 61 73 65 3d 3d 30 if( iBase==0
0b70: 20 29 20 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 0a ) return;. }..
0b80: 20 20 2f 2a 20 49 6e 69 74 69 61 6c 69 7a 65 20 /* Initialize
0b90: 74 68 65 20 62 61 67 73 2e 20 2a 2f 0a 20 20 62 the bags. */. b
0ba0: 61 67 5f 69 6e 69 74 28 26 73 65 65 6e 29 3b 0a ag_init(&seen);.
0bb0: 20 20 62 61 67 5f 69 6e 69 74 28 26 70 65 6e 64 bag_init(&pend
0bc0: 69 6e 67 29 3b 0a 20 20 62 61 67 5f 69 6e 73 65 ing);. bag_inse
0bd0: 72 74 28 26 70 65 6e 64 69 6e 67 2c 20 69 42 61 rt(&pending, iBa
0be0: 73 65 29 3b 0a 0a 20 20 2f 2a 20 54 68 69 73 20 se);.. /* This
0bf0: 71 75 65 72 79 20 72 65 74 75 72 6e 73 20 61 6c query returns al
0c00: 6c 20 6e 6f 6e 2d 6d 65 72 67 65 20 63 68 69 6c l non-merge chil
0c10: 64 72 65 6e 20 6f 66 20 63 68 65 63 6b 2d 69 6e dren of check-in
0c20: 20 3a 72 69 64 20 2a 2f 0a 20 20 64 62 5f 70 72 :rid */. db_pr
0c30: 65 70 61 72 65 28 26 71 31 2c 20 22 53 45 4c 45 epare(&q1, "SELE
0c40: 43 54 20 63 69 64 20 46 52 4f 4d 20 70 6c 69 6e CT cid FROM plin
0c50: 6b 20 57 48 45 52 45 20 70 69 64 3d 3a 72 69 64 k WHERE pid=:rid
0c60: 20 41 4e 44 20 69 73 70 72 69 6d 22 29 3b 0a 0a AND isprim");..
0c70: 20 20 2f 2a 20 54 68 69 73 20 71 75 65 72 79 20 /* This query
0c80: 72 65 74 75 72 6e 73 20 61 20 73 69 6e 67 6c 65 returns a single
0c90: 20 72 6f 77 20 69 66 20 63 68 65 63 6b 2d 69 6e row if check-in
0ca0: 20 3a 72 69 64 20 69 73 20 74 68 65 20 66 69 72 :rid is the fir
0cb0: 73 74 0a 20 20 2a 2a 20 63 68 65 63 6b 2d 69 6e st. ** check-in
0cc0: 20 6f 66 20 61 20 6e 65 77 20 62 72 61 6e 63 68 of a new branch
0cd0: 2e 20 20 49 6e 20 6f 74 68 65 72 20 77 6f 72 64 . In other word
0ce0: 73 2c 20 69 74 20 72 65 74 75 72 6e 73 20 61 20 s, it returns a
0cf0: 72 6f 77 20 69 66 0a 20 20 2a 2a 20 63 68 65 63 row if. ** chec
0d00: 6b 2d 69 6e 20 3a 72 69 64 20 68 61 73 20 74 68 k-in :rid has th
0d10: 65 20 27 6e 65 77 62 72 61 6e 63 68 27 20 74 61 e 'newbranch' ta
0d20: 67 2e 0a 20 20 2a 2f 0a 20 20 64 62 5f 70 72 65 g.. */. db_pre
0d30: 70 61 72 65 28 26 69 73 42 72 2c 20 0a 20 20 20 pare(&isBr, .
0d40: 20 20 22 53 45 4c 45 43 54 20 31 20 46 52 4f 4d "SELECT 1 FROM
0d50: 20 74 61 67 78 72 65 66 20 57 48 45 52 45 20 72 tagxref WHERE r
0d60: 69 64 3d 3a 72 69 64 20 41 4e 44 20 74 61 67 69 id=:rid AND tagi
0d70: 64 3d 25 64 20 41 4e 44 20 74 61 67 74 79 70 65 d=%d AND tagtype
0d80: 3d 31 22 2c 0a 20 20 20 20 20 54 41 47 5f 4e 45 =1",. TAG_NE
0d90: 57 42 52 41 4e 43 48 0a 20 20 29 3b 0a 0a 20 20 WBRANCH. );..
0da0: 2f 2a 20 54 68 69 73 20 73 74 61 74 65 6d 65 6e /* This statemen
0db0: 74 20 69 6e 73 65 72 74 73 20 63 68 65 63 6b 2d t inserts check-
0dc0: 69 6e 20 3a 72 69 64 20 69 6e 74 6f 20 74 68 65 in :rid into the
0dd0: 20 4c 45 41 56 45 53 20 74 61 62 6c 65 2e 0a 20 LEAVES table..
0de0: 20 2a 2f 0a 20 20 64 62 5f 70 72 65 70 61 72 65 */. db_prepare
0df0: 28 26 69 6e 73 2c 20 22 49 4e 53 45 52 54 20 4f (&ins, "INSERT O
0e00: 52 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 6c 65 R IGNORE INTO le
0e10: 61 76 65 73 20 56 41 4c 55 45 53 28 3a 72 69 64 aves VALUES(:rid
0e20: 29 22 29 3b 0a 0a 20 20 77 68 69 6c 65 28 20 62 )");.. while( b
0e30: 61 67 5f 63 6f 75 6e 74 28 26 70 65 6e 64 69 6e ag_count(&pendin
0e40: 67 29 20 29 7b 0a 20 20 20 20 69 6e 74 20 72 69 g) ){. int ri
0e50: 64 20 3d 20 62 61 67 5f 66 69 72 73 74 28 26 70 d = bag_first(&p
0e60: 65 6e 64 69 6e 67 29 3b 0a 20 20 20 20 69 6e 74 ending);. int
0e70: 20 63 6e 74 20 3d 20 30 3b 0a 20 20 20 20 62 61 cnt = 0;. ba
0e80: 67 5f 72 65 6d 6f 76 65 28 26 70 65 6e 64 69 6e g_remove(&pendin
0e90: 67 2c 20 72 69 64 29 3b 0a 20 20 20 20 64 62 5f g, rid);. db_
0ea0: 62 69 6e 64 5f 69 6e 74 28 26 71 31 2c 20 22 3a bind_int(&q1, ":
0eb0: 72 69 64 22 2c 20 72 69 64 29 3b 0a 20 20 20 20 rid", rid);.
0ec0: 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 while( db_step(&
0ed0: 71 31 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 q1)==SQLITE_ROW
0ee0: 29 7b 0a 20 20 20 20 20 20 69 6e 74 20 63 69 64 ){. int cid
0ef0: 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 = db_column_int
0f00: 28 26 71 31 2c 20 30 29 3b 0a 20 20 20 20 20 20 (&q1, 0);.
0f10: 69 66 28 20 62 61 67 5f 69 6e 73 65 72 74 28 26 if( bag_insert(&
0f20: 73 65 65 6e 2c 20 63 69 64 29 20 29 7b 0a 20 20 seen, cid) ){.
0f30: 20 20 20 20 20 20 62 61 67 5f 69 6e 73 65 72 74 bag_insert
0f40: 28 26 70 65 6e 64 69 6e 67 2c 20 63 69 64 29 3b (&pending, cid);
0f50: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 64 . }. d
0f60: 62 5f 62 69 6e 64 5f 69 6e 74 28 26 69 73 42 72 b_bind_int(&isBr
0f70: 2c 20 22 3a 72 69 64 22 2c 20 63 69 64 29 3b 0a , ":rid", cid);.
0f80: 20 20 20 20 20 20 69 66 28 20 64 62 5f 73 74 65 if( db_ste
0f90: 70 28 26 69 73 42 72 29 3d 3d 53 51 4c 49 54 45 p(&isBr)==SQLITE
0fa0: 5f 44 4f 4e 45 20 29 7b 0a 20 20 20 20 20 20 20 _DONE ){.
0fb0: 20 63 6e 74 2b 2b 3b 0a 20 20 20 20 20 20 7d 0a cnt++;. }.
0fc0: 20 20 20 20 20 20 64 62 5f 72 65 73 65 74 28 26 db_reset(&
0fd0: 69 73 42 72 29 3b 0a 20 20 20 20 7d 0a 20 20 20 isBr);. }.
0fe0: 20 64 62 5f 72 65 73 65 74 28 26 71 31 29 3b 0a db_reset(&q1);.
0ff0: 20 20 20 20 69 66 28 20 63 6e 74 3d 3d 30 20 26 if( cnt==0 &
1000: 26 20 21 69 73 5f 61 5f 6c 65 61 66 28 72 69 64 & !is_a_leaf(rid
1010: 29 20 29 7b 0a 20 20 20 20 20 20 63 6e 74 2b 2b ) ){. cnt++
1020: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 ;. }. if(
1030: 63 6e 74 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 cnt==0 ){.
1040: 64 62 5f 62 69 6e 64 5f 69 6e 74 28 26 69 6e 73 db_bind_int(&ins
1050: 2c 20 22 3a 72 69 64 22 2c 20 72 69 64 29 3b 0a , ":rid", rid);.
1060: 20 20 20 20 20 20 64 62 5f 73 74 65 70 28 26 69 db_step(&i
1070: 6e 73 29 3b 0a 20 20 20 20 20 20 64 62 5f 72 65 ns);. db_re
1080: 73 65 74 28 26 69 6e 73 29 3b 0a 20 20 20 20 7d set(&ins);. }
1090: 0a 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 . }. db_finali
10a0: 7a 65 28 26 69 6e 73 29 3b 0a 20 20 64 62 5f 66 ze(&ins);. db_f
10b0: 69 6e 61 6c 69 7a 65 28 26 69 73 42 72 29 3b 0a inalize(&isBr);.
10c0: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 db_finalize(&q
10d0: 31 29 3b 0a 20 20 62 61 67 5f 63 6c 65 61 72 28 1);. bag_clear(
10e0: 26 70 65 6e 64 69 6e 67 29 3b 0a 20 20 62 61 67 &pending);. bag
10f0: 5f 63 6c 65 61 72 28 26 73 65 65 6e 29 3b 0a 20 _clear(&seen);.
1100: 20 69 66 28 20 63 6c 6f 73 65 4d 6f 64 65 3d 3d if( closeMode==
1110: 31 20 29 7b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 1 ){. db_mult
1120: 69 5f 65 78 65 63 28 0a 20 20 20 20 20 20 22 44 i_exec(. "D
1130: 45 4c 45 54 45 20 46 52 4f 4d 20 6c 65 61 76 65 ELETE FROM leave
1140: 73 20 57 48 45 52 45 20 72 69 64 20 49 4e 22 0a s WHERE rid IN".
1150: 20 20 20 20 20 20 22 20 20 28 53 45 4c 45 43 54 " (SELECT
1160: 20 6c 65 61 76 65 73 2e 72 69 64 20 46 52 4f 4d leaves.rid FROM
1170: 20 6c 65 61 76 65 73 2c 20 74 61 67 78 72 65 66 leaves, tagxref
1180: 22 0a 20 20 20 20 20 20 22 20 20 20 20 57 48 45 ". " WHE
1190: 52 45 20 74 61 67 78 72 65 66 2e 72 69 64 3d 6c RE tagxref.rid=l
11a0: 65 61 76 65 73 2e 72 69 64 20 22 0a 20 20 20 20 eaves.rid ".
11b0: 20 20 22 20 20 20 20 20 20 41 4e 44 20 74 61 67 " AND tag
11c0: 78 72 65 66 2e 74 61 67 69 64 3d 25 64 22 0a 20 xref.tagid=%d".
11d0: 20 20 20 20 20 22 20 20 20 20 20 20 41 4e 44 20 " AND
11e0: 74 61 67 78 72 65 66 2e 74 61 67 74 79 70 65 3e tagxref.tagtype>
11f0: 30 29 22 2c 0a 20 20 20 20 20 20 54 41 47 5f 43 0)",. TAG_C
1200: 4c 4f 53 45 44 0a 20 20 20 20 29 3b 0a 20 20 7d LOSED. );. }
1210: 65 6c 73 65 20 69 66 28 20 63 6c 6f 73 65 4d 6f else if( closeMo
1220: 64 65 3d 3d 32 20 29 7b 0a 20 20 20 20 64 62 5f de==2 ){. db_
1230: 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 20 multi_exec(.
1240: 20 20 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 6c "DELETE FROM l
1250: 65 61 76 65 73 20 57 48 45 52 45 20 72 69 64 20 eaves WHERE rid
1260: 4e 4f 54 20 49 4e 22 0a 20 20 20 20 20 20 22 20 NOT IN". "
1270: 20 28 53 45 4c 45 43 54 20 6c 65 61 76 65 73 2e (SELECT leaves.
1280: 72 69 64 20 46 52 4f 4d 20 6c 65 61 76 65 73 2c rid FROM leaves,
1290: 20 74 61 67 78 72 65 66 22 0a 20 20 20 20 20 20 tagxref".
12a0: 22 20 20 20 20 57 48 45 52 45 20 74 61 67 78 72 " WHERE tagxr
12b0: 65 66 2e 72 69 64 3d 6c 65 61 76 65 73 2e 72 69 ef.rid=leaves.ri
12c0: 64 20 22 0a 20 20 20 20 20 20 22 20 20 20 20 20 d ". "
12d0: 20 41 4e 44 20 74 61 67 78 72 65 66 2e 74 61 67 AND tagxref.tag
12e0: 69 64 3d 25 64 22 0a 20 20 20 20 20 20 22 20 20 id=%d". "
12f0: 20 20 20 20 41 4e 44 20 74 61 67 78 72 65 66 2e AND tagxref.
1300: 74 61 67 74 79 70 65 3e 30 29 22 2c 0a 20 20 20 tagtype>0)",.
1310: 20 20 20 54 41 47 5f 43 4c 4f 53 45 44 0a 20 20 TAG_CLOSED.
1320: 20 20 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a );. }.}../*.*
1330: 2a 20 4c 6f 61 64 20 74 68 65 20 72 65 63 6f 72 * Load the recor
1340: 64 20 49 44 20 72 69 64 20 61 6e 64 20 75 70 20 d ID rid and up
1350: 74 6f 20 4e 2d 31 20 63 6c 6f 73 65 73 74 20 61 to N-1 closest a
1360: 6e 63 65 73 74 6f 72 73 20 69 6e 74 6f 0a 2a 2a ncestors into.**
1370: 20 74 68 65 20 22 6f 6b 22 20 74 61 62 6c 65 2e the "ok" table.
1380: 0a 2a 2f 0a 76 6f 69 64 20 63 6f 6d 70 75 74 65 .*/.void compute
1390: 5f 61 6e 63 65 73 74 6f 72 73 28 69 6e 74 20 72 _ancestors(int r
13a0: 69 64 2c 20 69 6e 74 20 4e 29 7b 0a 20 20 42 61 id, int N){. Ba
13b0: 67 20 73 65 65 6e 3b 0a 20 20 50 51 75 65 75 65 g seen;. PQueue
13c0: 20 71 75 65 75 65 3b 0a 20 20 62 61 67 5f 69 6e queue;. bag_in
13d0: 69 74 28 26 73 65 65 6e 29 3b 0a 20 20 70 71 75 it(&seen);. pqu
13e0: 65 75 65 5f 69 6e 69 74 28 26 71 75 65 75 65 29 eue_init(&queue)
13f0: 3b 0a 20 20 62 61 67 5f 69 6e 73 65 72 74 28 26 ;. bag_insert(&
1400: 73 65 65 6e 2c 20 72 69 64 29 3b 0a 20 20 70 71 seen, rid);. pq
1410: 75 65 75 65 5f 69 6e 73 65 72 74 28 26 71 75 65 ueue_insert(&que
1420: 75 65 2c 20 72 69 64 2c 20 30 2e 30 29 3b 0a 20 ue, rid, 0.0);.
1430: 20 77 68 69 6c 65 28 20 28 4e 2d 2d 29 3e 30 20 while( (N--)>0
1440: 26 26 20 28 72 69 64 20 3d 20 70 71 75 65 75 65 && (rid = pqueue
1450: 5f 65 78 74 72 61 63 74 28 26 71 75 65 75 65 29 _extract(&queue)
1460: 29 21 3d 30 20 29 7b 0a 20 20 20 20 53 74 6d 74 )!=0 ){. Stmt
1470: 20 71 3b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 q;. db_multi
1480: 5f 65 78 65 63 28 22 49 4e 53 45 52 54 20 4f 52 _exec("INSERT OR
1490: 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 6f 6b 20 IGNORE INTO ok
14a0: 56 41 4c 55 45 53 28 25 64 29 22 2c 20 72 69 64 VALUES(%d)", rid
14b0: 29 3b 0a 20 20 20 20 64 62 5f 70 72 65 70 61 72 );. db_prepar
14c0: 65 28 26 71 2c 0a 20 20 20 20 20 20 20 22 53 45 e(&q,. "SE
14d0: 4c 45 43 54 20 61 2e 70 69 64 2c 20 62 2e 6d 74 LECT a.pid, b.mt
14e0: 69 6d 65 20 46 52 4f 4d 20 70 6c 69 6e 6b 20 61 ime FROM plink a
14f0: 20 4c 45 46 54 20 4a 4f 49 4e 20 70 6c 69 6e 6b LEFT JOIN plink
1500: 20 62 20 4f 4e 20 62 2e 63 69 64 3d 61 2e 70 69 b ON b.cid=a.pi
1510: 64 22 0a 20 20 20 20 20 20 20 22 20 57 48 45 52 d". " WHER
1520: 45 20 61 2e 63 69 64 3d 25 64 22 2c 20 72 69 64 E a.cid=%d", rid
1530: 0a 20 20 20 20 29 3b 0a 20 20 20 20 77 68 69 6c . );. whil
1540: 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d e( db_step(&q)==
1550: 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 SQLITE_ROW ){.
1560: 20 20 20 20 69 6e 74 20 70 69 64 20 3d 20 64 62 int pid = db
1570: 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 _column_int(&q,
1580: 30 29 3b 0a 20 20 20 20 20 20 64 6f 75 62 6c 65 0);. double
1590: 20 6d 74 69 6d 65 20 3d 20 64 62 5f 63 6f 6c 75 mtime = db_colu
15a0: 6d 6e 5f 64 6f 75 62 6c 65 28 26 71 2c 20 31 29 mn_double(&q, 1)
15b0: 3b 0a 20 20 20 20 20 20 69 66 28 20 62 61 67 5f ;. if( bag_
15c0: 69 6e 73 65 72 74 28 26 73 65 65 6e 2c 20 70 69 insert(&seen, pi
15d0: 64 29 20 29 7b 0a 20 20 20 20 20 20 20 20 70 71 d) ){. pq
15e0: 75 65 75 65 5f 69 6e 73 65 72 74 28 26 71 75 65 ueue_insert(&que
15f0: 75 65 2c 20 70 69 64 2c 20 2d 6d 74 69 6d 65 29 ue, pid, -mtime)
1600: 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a ;. }. }.
1610: 20 20 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 db_finalize(
1620: 26 71 29 3b 0a 20 20 7d 0a 20 20 62 61 67 5f 63 &q);. }. bag_c
1630: 6c 65 61 72 28 26 73 65 65 6e 29 3b 0a 20 20 70 lear(&seen);. p
1640: 71 75 65 75 65 5f 63 6c 65 61 72 28 26 71 75 65 queue_clear(&que
1650: 75 65 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 4c 6f ue);.}../*.** Lo
1660: 61 64 20 74 68 65 20 72 65 63 6f 72 64 20 49 44 ad the record ID
1670: 20 72 69 64 20 61 6e 64 20 75 70 20 74 6f 20 4e rid and up to N
1680: 2d 31 20 63 6c 6f 73 65 73 74 20 64 65 73 63 65 -1 closest desce
1690: 6e 64 61 6e 74 73 20 69 6e 74 6f 0a 2a 2a 20 74 ndants into.** t
16a0: 68 65 20 22 6f 6b 22 20 74 61 62 6c 65 2e 0a 2a he "ok" table..*
16b0: 2f 0a 76 6f 69 64 20 63 6f 6d 70 75 74 65 5f 64 /.void compute_d
16c0: 65 73 63 65 6e 64 61 6e 74 73 28 69 6e 74 20 72 escendants(int r
16d0: 69 64 2c 20 69 6e 74 20 4e 29 7b 0a 20 20 42 61 id, int N){. Ba
16e0: 67 20 73 65 65 6e 3b 0a 20 20 50 51 75 65 75 65 g seen;. PQueue
16f0: 20 71 75 65 75 65 3b 0a 20 20 62 61 67 5f 69 6e queue;. bag_in
1700: 69 74 28 26 73 65 65 6e 29 3b 0a 20 20 70 71 75 it(&seen);. pqu
1710: 65 75 65 5f 69 6e 69 74 28 26 71 75 65 75 65 29 eue_init(&queue)
1720: 3b 0a 20 20 62 61 67 5f 69 6e 73 65 72 74 28 26 ;. bag_insert(&
1730: 73 65 65 6e 2c 20 72 69 64 29 3b 0a 20 20 70 71 seen, rid);. pq
1740: 75 65 75 65 5f 69 6e 73 65 72 74 28 26 71 75 65 ueue_insert(&que
1750: 75 65 2c 20 72 69 64 2c 20 30 2e 30 29 3b 0a 20 ue, rid, 0.0);.
1760: 20 77 68 69 6c 65 28 20 28 4e 2d 2d 29 3e 30 20 while( (N--)>0
1770: 26 26 20 28 72 69 64 20 3d 20 70 71 75 65 75 65 && (rid = pqueue
1780: 5f 65 78 74 72 61 63 74 28 26 71 75 65 75 65 29 _extract(&queue)
1790: 29 21 3d 30 20 29 7b 0a 20 20 20 20 53 74 6d 74 )!=0 ){. Stmt
17a0: 20 71 3b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 q;. db_multi
17b0: 5f 65 78 65 63 28 22 49 4e 53 45 52 54 20 4f 52 _exec("INSERT OR
17c0: 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 6f 6b 20 IGNORE INTO ok
17d0: 56 41 4c 55 45 53 28 25 64 29 22 2c 20 72 69 64 VALUES(%d)", rid
17e0: 29 3b 0a 20 20 20 20 64 62 5f 70 72 65 70 61 72 );. db_prepar
17f0: 65 28 26 71 2c 22 53 45 4c 45 43 54 20 63 69 64 e(&q,"SELECT cid
1800: 2c 20 6d 74 69 6d 65 20 46 52 4f 4d 20 70 6c 69 , mtime FROM pli
1810: 6e 6b 20 57 48 45 52 45 20 70 69 64 3d 25 64 22 nk WHERE pid=%d"
1820: 2c 20 72 69 64 29 3b 0a 20 20 20 20 77 68 69 6c , rid);. whil
1830: 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d e( db_step(&q)==
1840: 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 SQLITE_ROW ){.
1850: 20 20 20 20 69 6e 74 20 70 69 64 20 3d 20 64 62 int pid = db
1860: 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 _column_int(&q,
1870: 30 29 3b 0a 20 20 20 20 20 20 64 6f 75 62 6c 65 0);. double
1880: 20 6d 74 69 6d 65 20 3d 20 64 62 5f 63 6f 6c 75 mtime = db_colu
1890: 6d 6e 5f 64 6f 75 62 6c 65 28 26 71 2c 20 31 29 mn_double(&q, 1)
18a0: 3b 0a 20 20 20 20 20 20 69 66 28 20 62 61 67 5f ;. if( bag_
18b0: 69 6e 73 65 72 74 28 26 73 65 65 6e 2c 20 70 69 insert(&seen, pi
18c0: 64 29 20 29 7b 0a 20 20 20 20 20 20 20 20 70 71 d) ){. pq
18d0: 75 65 75 65 5f 69 6e 73 65 72 74 28 26 71 75 65 ueue_insert(&que
18e0: 75 65 2c 20 70 69 64 2c 20 6d 74 69 6d 65 29 3b ue, pid, mtime);
18f0: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 . }. }.
1900: 20 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 db_finalize(&
1910: 71 29 3b 0a 20 20 7d 0a 20 20 62 61 67 5f 63 6c q);. }. bag_cl
1920: 65 61 72 28 26 73 65 65 6e 29 3b 0a 20 20 70 71 ear(&seen);. pq
1930: 75 65 75 65 5f 63 6c 65 61 72 28 26 71 75 65 75 ueue_clear(&queu
1940: 65 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d e);.}../*.** COM
1950: 4d 41 4e 44 3a 20 20 64 65 73 63 65 6e 64 61 6e MAND: descendan
1960: 74 73 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 ts.**.** Usage:
1970: 25 66 6f 73 73 69 6c 20 64 65 73 63 65 6e 64 61 %fossil descenda
1980: 6e 74 73 20 3f 42 41 53 45 4c 49 4e 45 2d 49 44 nts ?BASELINE-ID
1990: 3f 0a 2a 2a 0a 2a 2a 20 46 69 6e 64 20 61 6c 6c ?.**.** Find all
19a0: 20 6c 65 61 66 20 64 65 73 63 65 6e 64 61 6e 74 leaf descendant
19b0: 73 20 6f 66 20 74 68 65 20 62 61 73 65 6c 69 6e s of the baselin
19c0: 65 20 73 70 65 63 69 66 69 65 64 20 6f 72 20 69 e specified or i
19d0: 66 20 74 68 65 20 61 72 67 75 6d 65 6e 74 0a 2a f the argument.*
19e0: 2a 20 69 73 20 6f 6d 69 74 74 65 64 2c 20 6f 66 * is omitted, of
19f0: 20 74 68 65 20 62 61 73 65 6c 69 6e 65 20 63 75 the baseline cu
1a00: 72 72 65 6e 74 6c 79 20 63 68 65 63 6b 65 64 20 rrently checked
1a10: 6f 75 74 2e 0a 2a 2f 0a 76 6f 69 64 20 64 65 73 out..*/.void des
1a20: 63 65 6e 64 61 6e 74 73 5f 63 6d 64 28 76 6f 69 cendants_cmd(voi
1a30: 64 29 7b 0a 20 20 53 74 6d 74 20 71 3b 0a 20 20 d){. Stmt q;.
1a40: 69 6e 74 20 62 61 73 65 3b 0a 0a 20 20 64 62 5f int base;.. db_
1a50: 6d 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 must_be_within_t
1a60: 72 65 65 28 29 3b 0a 20 20 69 66 28 20 67 2e 61 ree();. if( g.a
1a70: 72 67 63 3d 3d 32 20 29 7b 0a 20 20 20 20 62 61 rgc==2 ){. ba
1a80: 73 65 20 3d 20 64 62 5f 6c 67 65 74 5f 69 6e 74 se = db_lget_int
1a90: 28 22 63 68 65 63 6b 6f 75 74 22 2c 20 30 29 3b ("checkout", 0);
1aa0: 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 62 61 . }else{. ba
1ab0: 73 65 20 3d 20 6e 61 6d 65 5f 74 6f 5f 72 69 64 se = name_to_rid
1ac0: 28 67 2e 61 72 67 76 5b 32 5d 29 3b 0a 20 20 7d (g.argv[2]);. }
1ad0: 0a 20 20 69 66 28 20 62 61 73 65 3d 3d 30 20 29 . if( base==0 )
1ae0: 20 72 65 74 75 72 6e 3b 0a 20 20 63 6f 6d 70 75 return;. compu
1af0: 74 65 5f 6c 65 61 76 65 73 28 62 61 73 65 2c 20 te_leaves(base,
1b00: 30 29 3b 0a 20 20 64 62 5f 70 72 65 70 61 72 65 0);. db_prepare
1b10: 28 26 71 2c 0a 20 20 20 20 22 25 73 22 0a 20 20 (&q,. "%s".
1b20: 20 20 22 20 20 20 41 4e 44 20 65 76 65 6e 74 2e " AND event.
1b30: 6f 62 6a 69 64 20 49 4e 20 28 53 45 4c 45 43 54 objid IN (SELECT
1b40: 20 72 69 64 20 46 52 4f 4d 20 6c 65 61 76 65 73 rid FROM leaves
1b50: 29 22 0a 20 20 20 20 22 20 4f 52 44 45 52 20 42 )". " ORDER B
1b60: 59 20 65 76 65 6e 74 2e 6d 74 69 6d 65 20 44 45 Y event.mtime DE
1b70: 53 43 22 2c 0a 20 20 20 20 74 69 6d 65 6c 69 6e SC",. timelin
1b80: 65 5f 71 75 65 72 79 5f 66 6f 72 5f 74 74 79 28 e_query_for_tty(
1b90: 29 0a 20 20 29 3b 0a 20 20 70 72 69 6e 74 5f 74 ). );. print_t
1ba0: 69 6d 65 6c 69 6e 65 28 26 71 2c 20 32 30 29 3b imeline(&q, 20);
1bb0: 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 . db_finalize(&
1bc0: 71 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d q);.}../*.** COM
1bd0: 4d 41 4e 44 3a 20 20 6c 65 61 76 65 73 0a 2a 2a MAND: leaves.**
1be0: 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f 73 73 .** Usage: %foss
1bf0: 69 6c 20 6c 65 61 76 65 73 20 3f 2d 2d 61 6c 6c il leaves ?--all
1c00: 3f 20 3f 2d 2d 63 6c 6f 73 65 64 3f 0a 2a 2a 0a ? ?--closed?.**.
1c10: 2a 2a 20 46 69 6e 64 20 6c 65 61 76 65 73 20 6f ** Find leaves o
1c20: 66 20 61 6c 6c 20 62 72 61 6e 63 68 65 73 2e 20 f all branches.
1c30: 20 42 79 20 64 65 66 61 75 6c 74 20 73 68 6f 77 By default show
1c40: 20 6f 6e 6c 79 20 6f 70 65 6e 20 6c 65 61 76 65 only open leave
1c50: 73 2e 0a 2a 2a 20 54 68 65 20 2d 2d 61 6c 6c 20 s..** The --all
1c60: 66 6c 61 67 20 63 61 75 73 65 73 20 61 6c 6c 20 flag causes all
1c70: 6c 65 61 76 65 73 20 28 63 6c 6f 73 65 64 20 61 leaves (closed a
1c80: 6e 64 20 6f 70 65 6e 29 20 74 6f 20 62 65 20 73 nd open) to be s
1c90: 68 6f 77 6e 2e 0a 2a 2a 20 54 68 65 20 2d 2d 63 hown..** The --c
1ca0: 6c 6f 73 65 64 20 66 6c 61 67 20 73 68 6f 77 73 losed flag shows
1cb0: 20 6f 6e 6c 79 20 63 6c 6f 73 65 64 20 6c 65 61 only closed lea
1cc0: 76 65 73 2e 0a 2a 2f 0a 76 6f 69 64 20 6c 65 61 ves..*/.void lea
1cd0: 76 65 73 5f 63 6d 64 28 76 6f 69 64 29 7b 0a 20 ves_cmd(void){.
1ce0: 20 53 74 6d 74 20 71 3b 0a 20 20 69 6e 74 20 73 Stmt q;. int s
1cf0: 68 6f 77 41 6c 6c 20 3d 20 66 69 6e 64 5f 6f 70 howAll = find_op
1d00: 74 69 6f 6e 28 22 61 6c 6c 22 2c 20 30 2c 20 30 tion("all", 0, 0
1d10: 29 21 3d 30 3b 0a 20 20 69 6e 74 20 73 68 6f 77 )!=0;. int show
1d20: 43 6c 6f 73 65 64 20 3d 20 66 69 6e 64 5f 6f 70 Closed = find_op
1d30: 74 69 6f 6e 28 22 63 6c 6f 73 65 64 22 2c 20 30 tion("closed", 0
1d40: 2c 20 30 29 21 3d 30 3b 0a 0a 20 20 64 62 5f 6d , 0)!=0;.. db_m
1d50: 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72 ust_be_within_tr
1d60: 65 65 28 29 3b 0a 20 20 63 6f 6d 70 75 74 65 5f ee();. compute_
1d70: 6c 65 61 76 65 73 28 30 2c 20 73 68 6f 77 41 6c leaves(0, showAl
1d80: 6c 20 3f 20 30 20 3a 20 73 68 6f 77 43 6c 6f 73 l ? 0 : showClos
1d90: 65 64 20 3f 20 32 20 3a 20 31 29 3b 0a 20 20 64 ed ? 2 : 1);. d
1da0: 62 5f 70 72 65 70 61 72 65 28 26 71 2c 0a 20 20 b_prepare(&q,.
1db0: 20 20 22 25 73 22 0a 20 20 20 20 22 20 20 20 41 "%s". " A
1dc0: 4e 44 20 62 6c 6f 62 2e 72 69 64 20 49 4e 20 6c ND blob.rid IN l
1dd0: 65 61 76 65 73 22 0a 20 20 20 20 22 20 4f 52 44 eaves". " ORD
1de0: 45 52 20 42 59 20 65 76 65 6e 74 2e 6d 74 69 6d ER BY event.mtim
1df0: 65 20 44 45 53 43 22 2c 0a 20 20 20 20 74 69 6d e DESC",. tim
1e00: 65 6c 69 6e 65 5f 71 75 65 72 79 5f 66 6f 72 5f eline_query_for_
1e10: 74 74 79 28 29 0a 20 20 29 3b 0a 20 20 70 72 69 tty(). );. pri
1e20: 6e 74 5f 74 69 6d 65 6c 69 6e 65 28 26 71 2c 20 nt_timeline(&q,
1e30: 32 30 30 30 29 3b 0a 20 20 64 62 5f 66 69 6e 61 2000);. db_fina
1e40: 6c 69 7a 65 28 26 71 29 3b 0a 7d 0a 0a 2f 2a 0a lize(&q);.}../*.
1e50: 2a 2a 20 54 68 69 73 20 72 6f 75 74 69 6e 65 20 ** This routine
1e60: 69 73 20 63 61 6c 6c 65 64 20 77 68 69 6c 65 20 is called while
1e70: 66 6f 72 20 65 61 63 68 20 63 68 65 63 6b 2d 69 for each check-i
1e80: 6e 20 74 68 61 74 20 69 73 20 72 65 6e 64 65 72 n that is render
1e90: 65 64 20 62 79 0a 2a 2a 20 74 68 65 20 22 6c 65 ed by.** the "le
1ea0: 61 76 65 73 22 20 70 61 67 65 2e 20 20 41 64 64 aves" page. Add
1eb0: 20 73 6f 6d 65 20 61 64 64 69 74 69 6f 6e 61 6c some additional
1ec0: 20 68 79 70 65 72 6c 69 6e 6b 20 74 6f 20 73 68 hyperlink to sh
1ed0: 6f 77 20 74 68 65 20 0a 2a 2a 20 61 6e 63 65 73 ow the .** ances
1ee0: 74 6f 72 73 20 6f 66 20 74 68 65 20 6c 65 61 66 tors of the leaf
1ef0: 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 ..*/.static void
1f00: 20 6c 65 61 76 65 73 5f 65 78 74 72 61 28 69 6e leaves_extra(in
1f10: 74 20 72 69 64 29 7b 0a 20 20 40 20 3c 61 20 68 t rid){. @ <a h
1f20: 72 65 66 3d 22 25 73 28 67 2e 7a 42 61 73 65 55 ref="%s(g.zBaseU
1f30: 52 4c 29 2f 74 69 6d 65 6c 69 6e 65 3f 70 3d 25 RL)/timeline?p=%
1f40: 64 28 72 69 64 29 22 3e 5b 74 69 6d 65 6c 69 6e d(rid)">[timelin
1f50: 65 5d 3c 2f 61 3e 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 e]</a>.}../*.**
1f60: 57 45 42 50 41 47 45 3a 20 20 6c 65 61 76 65 73 WEBPAGE: leaves
1f70: 0a 2a 2a 0a 2a 2a 20 46 69 6e 64 20 6c 65 61 76 .**.** Find leav
1f80: 65 73 20 6f 66 20 61 6c 6c 20 62 72 61 6e 63 68 es of all branch
1f90: 65 73 2e 0a 2a 2f 0a 76 6f 69 64 20 6c 65 61 76 es..*/.void leav
1fa0: 65 73 5f 70 61 67 65 28 76 6f 69 64 29 7b 0a 20 es_page(void){.
1fb0: 20 53 74 6d 74 20 71 3b 0a 20 20 69 6e 74 20 73 Stmt q;. int s
1fc0: 68 6f 77 41 6c 6c 20 3d 20 50 28 22 61 6c 6c 22 howAll = P("all"
1fd0: 29 21 3d 30 3b 0a 20 20 69 6e 74 20 73 68 6f 77 )!=0;. int show
1fe0: 43 6c 6f 73 65 64 20 3d 20 50 28 22 63 6c 6f 73 Closed = P("clos
1ff0: 65 64 22 29 21 3d 30 3b 0a 0a 20 20 6c 6f 67 69 ed")!=0;.. logi
2000: 6e 5f 63 68 65 63 6b 5f 63 72 65 64 65 6e 74 69 n_check_credenti
2010: 61 6c 73 28 29 3b 0a 20 20 69 66 28 20 21 67 2e als();. if( !g.
2020: 6f 6b 52 65 61 64 20 29 7b 20 6c 6f 67 69 6e 5f okRead ){ login_
2030: 6e 65 65 64 65 64 28 29 3b 20 72 65 74 75 72 6e needed(); return
2040: 3b 20 7d 0a 0a 20 20 69 66 28 20 21 73 68 6f 77 ; }.. if( !show
2050: 41 6c 6c 20 29 7b 0a 20 20 20 20 73 74 79 6c 65 All ){. style
2060: 5f 73 75 62 6d 65 6e 75 5f 65 6c 65 6d 65 6e 74 _submenu_element
2070: 28 22 41 6c 6c 22 2c 20 22 41 6c 6c 22 2c 20 22 ("All", "All", "
2080: 6c 65 61 76 65 73 3f 61 6c 6c 22 29 3b 0a 20 20 leaves?all");.
2090: 7d 0a 20 20 69 66 28 20 21 73 68 6f 77 43 6c 6f }. if( !showClo
20a0: 73 65 64 20 29 7b 0a 20 20 20 20 73 74 79 6c 65 sed ){. style
20b0: 5f 73 75 62 6d 65 6e 75 5f 65 6c 65 6d 65 6e 74 _submenu_element
20c0: 28 22 43 6c 6f 73 65 64 22 2c 20 22 43 6c 6f 73 ("Closed", "Clos
20d0: 65 64 22 2c 20 22 6c 65 61 76 65 73 3f 63 6c 6f ed", "leaves?clo
20e0: 73 65 64 22 29 3b 0a 20 20 7d 0a 20 20 69 66 28 sed");. }. if(
20f0: 20 73 68 6f 77 43 6c 6f 73 65 64 20 7c 7c 20 73 showClosed || s
2100: 68 6f 77 41 6c 6c 20 29 7b 0a 20 20 20 20 73 74 howAll ){. st
2110: 79 6c 65 5f 73 75 62 6d 65 6e 75 5f 65 6c 65 6d yle_submenu_elem
2120: 65 6e 74 28 22 4f 70 65 6e 22 2c 20 22 4f 70 65 ent("Open", "Ope
2130: 6e 22 2c 20 22 6c 65 61 76 65 73 22 29 3b 0a 20 n", "leaves");.
2140: 20 7d 0a 20 20 73 74 79 6c 65 5f 68 65 61 64 65 }. style_heade
2150: 72 28 22 4c 65 61 76 65 73 22 29 3b 0a 20 20 6c r("Leaves");. l
2160: 6f 67 69 6e 5f 61 6e 6f 6e 79 6d 6f 75 73 5f 61 ogin_anonymous_a
2170: 76 61 69 6c 61 62 6c 65 28 29 3b 0a 20 20 63 6f vailable();. co
2180: 6d 70 75 74 65 5f 6c 65 61 76 65 73 28 30 2c 20 mpute_leaves(0,
2190: 73 68 6f 77 41 6c 6c 20 3f 20 30 20 3a 20 73 68 showAll ? 0 : sh
21a0: 6f 77 43 6c 6f 73 65 64 20 3f 20 32 20 3a 20 31 owClosed ? 2 : 1
21b0: 29 3b 0a 20 20 40 20 3c 74 61 62 6c 65 20 77 69 );. @ <table wi
21c0: 64 74 68 3d 22 33 33 25 25 22 20 61 6c 69 67 6e dth="33%%" align
21d0: 3d 22 72 69 67 68 74 22 20 62 6f 72 64 65 72 3d ="right" border=
21e0: 22 31 22 3e 0a 20 20 40 20 3c 74 72 3e 3c 74 64 "1">. @ <tr><td
21f0: 3e 0a 20 20 40 20 3c 62 3e 4e 6f 6d 65 6e 63 6c >. @ <b>Nomencl
2200: 61 74 75 72 65 3a 3c 2f 62 3e 0a 20 20 40 20 3c ature:</b>. @ <
2210: 6f 6c 3e 0a 20 20 40 20 3c 6c 69 3e 20 41 20 3c ol>. @ <li> A <
2220: 62 3e 6c 65 61 66 3c 2f 62 3e 20 69 73 20 61 20 b>leaf</b> is a
2230: 63 68 65 63 6b 2d 69 6e 20 77 69 74 68 20 6e 6f check-in with no
2240: 20 64 65 73 63 65 6e 64 61 6e 74 73 2e 3c 2f 6c descendants.</l
2250: 69 3e 0a 20 20 40 20 3c 6c 69 3e 20 41 6e 20 3c i>. @ <li> An <
2260: 62 3e 6f 70 65 6e 20 6c 65 61 66 3c 2f 62 3e 20 b>open leaf</b>
2270: 69 73 20 61 20 6c 65 61 66 20 74 68 61 74 20 64 is a leaf that d
2280: 6f 65 73 20 6e 6f 74 20 68 61 76 65 20 61 20 22 oes not have a "
2290: 63 6c 6f 73 65 64 22 20 74 61 67 0a 20 20 40 20 closed" tag. @
22a0: 61 6e 64 20 69 73 20 74 68 75 73 20 61 73 73 75 and is thus assu
22b0: 6d 65 64 20 74 6f 20 73 74 69 6c 6c 20 62 65 20 med to still be
22c0: 69 6e 20 75 73 65 2e 3c 2f 6c 69 3e 0a 20 20 40 in use.</li>. @
22d0: 20 3c 6c 69 3e 20 41 20 3c 62 3e 63 6c 6f 73 65 <li> A <b>close
22e0: 64 20 6c 65 61 66 3c 2f 62 3e 20 68 61 73 20 61 d leaf</b> has a
22f0: 20 22 63 6c 6f 73 65 64 22 20 74 61 67 20 61 6e "closed" tag an
2300: 64 20 69 73 20 74 68 75 73 20 61 73 73 75 6d 65 d is thus assume
2310: 64 20 74 6f 0a 20 20 40 20 62 65 20 68 69 73 74 d to. @ be hist
2320: 6f 72 69 63 61 6c 20 61 6e 64 20 6e 6f 20 6c 6f orical and no lo
2330: 6e 67 65 72 20 69 6e 20 61 63 74 69 76 65 20 75 nger in active u
2340: 73 65 2e 3c 2f 6c 69 3e 0a 20 20 40 20 3c 2f 6f se.</li>. @ </o
2350: 6c 3e 0a 20 20 40 20 3c 2f 74 64 3e 3c 2f 74 72 l>. @ </td></tr
2360: 3e 3c 2f 74 61 62 6c 65 3e 0a 20 20 69 66 28 20 ></table>. if(
2370: 73 68 6f 77 41 6c 6c 20 29 7b 0a 20 20 20 20 40 showAll ){. @
2380: 20 3c 68 31 3e 41 6c 6c 20 6c 65 61 76 65 73 2c <h1>All leaves,
2390: 20 62 6f 74 68 20 6f 70 65 6e 20 61 6e 64 20 63 both open and c
23a0: 6c 6f 73 65 64 3c 2f 68 31 3e 0a 20 20 7d 65 6c losed</h1>. }el
23b0: 73 65 20 69 66 28 20 73 68 6f 77 43 6c 6f 73 65 se if( showClose
23c0: 64 20 29 7b 0a 20 20 20 20 40 20 3c 68 31 3e 43 d ){. @ <h1>C
23d0: 6c 6f 73 65 64 20 6c 65 61 76 65 73 20 6f 6e 6c losed leaves onl
23e0: 79 3c 2f 68 31 3e 0a 20 20 7d 65 6c 73 65 7b 0a y</h1>. }else{.
23f0: 20 20 20 20 40 20 3c 68 31 3e 41 6c 6c 20 6f 70 @ <h1>All op
2400: 65 6e 20 6c 65 61 76 65 73 3c 2f 68 31 3e 0a 20 en leaves</h1>.
2410: 20 7d 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 }. db_prepare(
2420: 26 71 2c 0a 20 20 20 20 22 25 73 22 0a 20 20 20 &q,. "%s".
2430: 20 22 20 20 20 41 4e 44 20 62 6c 6f 62 2e 72 69 " AND blob.ri
2440: 64 20 49 4e 20 6c 65 61 76 65 73 22 0a 20 20 20 d IN leaves".
2450: 20 22 20 4f 52 44 45 52 20 42 59 20 65 76 65 6e " ORDER BY even
2460: 74 2e 6d 74 69 6d 65 20 44 45 53 43 22 2c 0a 20 t.mtime DESC",.
2470: 20 20 20 74 69 6d 65 6c 69 6e 65 5f 71 75 65 72 timeline_quer
2480: 79 5f 66 6f 72 5f 77 77 77 28 29 0a 20 20 29 3b y_for_www(). );
2490: 0a 20 20 77 77 77 5f 70 72 69 6e 74 5f 74 69 6d . www_print_tim
24a0: 65 6c 69 6e 65 28 26 71 2c 20 54 49 4d 45 4c 49 eline(&q, TIMELI
24b0: 4e 45 5f 4c 45 41 46 4f 4e 4c 59 2c 20 6c 65 61 NE_LEAFONLY, lea
24c0: 76 65 73 5f 65 78 74 72 61 29 3b 0a 20 20 64 62 ves_extra);. db
24d0: 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 _finalize(&q);.
24e0: 20 40 20 3c 62 72 20 63 6c 65 61 72 3d 22 62 6f @ <br clear="bo
24f0: 74 68 22 3e 0a 20 20 40 20 3c 73 63 72 69 70 74 th">. @ <script
2500: 3e 0a 20 20 40 20 66 75 6e 63 74 69 6f 6e 20 78 >. @ function x
2510: 69 6e 28 69 64 29 7b 0a 20 20 40 20 7d 0a 20 20 in(id){. @ }.
2520: 40 20 66 75 6e 63 74 69 6f 6e 20 78 6f 75 74 28 @ function xout(
2530: 69 64 29 7b 0a 20 20 40 20 7d 0a 20 20 40 20 3c id){. @ }. @ <
2540: 2f 73 63 72 69 70 74 3e 0a 20 20 73 74 79 6c 65 /script>. style
2550: 5f 66 6f 6f 74 65 72 28 29 3b 0a 7d 0a _footer();.}.