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 3b 20 20 s */. Stmt q;
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 64 w record */.. d
0970: 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 b_multi_exec(.
0980: 20 20 22 43 52 45 41 54 45 20 54 45 4d 50 20 54 "CREATE TEMP T
0990: 41 42 4c 45 20 49 46 20 4e 4f 54 20 45 58 49 53 ABLE IF NOT EXIS
09a0: 54 53 20 6c 65 61 76 65 73 28 22 0a 20 20 20 20 TS leaves(".
09b0: 22 20 20 72 69 64 20 49 4e 54 45 47 45 52 20 50 " rid INTEGER P
09c0: 52 49 4d 41 52 59 20 4b 45 59 22 0a 20 20 20 20 RIMARY KEY".
09d0: 22 29 3b 22 0a 20 20 20 20 22 44 45 4c 45 54 45 ");". "DELETE
09e0: 20 46 52 4f 4d 20 6c 65 61 76 65 73 3b 22 0a 20 FROM leaves;".
09f0: 20 29 3b 0a 20 20 62 61 67 5f 69 6e 69 74 28 26 );. bag_init(&
0a00: 73 65 65 6e 29 3b 0a 20 20 62 61 67 5f 69 6e 69 seen);. bag_ini
0a10: 74 28 26 70 65 6e 64 69 6e 67 29 3b 0a 20 20 69 t(&pending);. i
0a20: 66 28 20 69 42 61 73 65 3c 3d 30 20 29 7b 0a 20 f( iBase<=0 ){.
0a30: 20 20 20 69 42 61 73 65 20 3d 20 64 62 5f 69 6e iBase = db_in
0a40: 74 28 30 2c 20 22 53 45 4c 45 43 54 20 6f 62 6a t(0, "SELECT obj
0a50: 69 64 20 46 52 4f 4d 20 65 76 65 6e 74 20 57 48 id FROM event WH
0a60: 45 52 45 20 74 79 70 65 3d 27 63 69 27 22 0a 20 ERE type='ci'".
0a70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0a80: 20 20 20 20 20 22 20 4f 52 44 45 52 20 42 59 20 " ORDER BY
0a90: 6d 74 69 6d 65 20 4c 49 4d 49 54 20 31 22 29 3b mtime LIMIT 1");
0aa0: 0a 20 20 20 20 69 66 28 20 69 42 61 73 65 3d 3d . if( iBase==
0ab0: 30 20 29 20 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 0 ) return;. }.
0ac0: 20 20 62 61 67 5f 69 6e 73 65 72 74 28 26 70 65 bag_insert(&pe
0ad0: 6e 64 69 6e 67 2c 20 69 42 61 73 65 29 3b 0a 20 nding, iBase);.
0ae0: 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c 20 db_prepare(&q,
0af0: 22 53 45 4c 45 43 54 20 63 69 64 20 46 52 4f 4d "SELECT cid FROM
0b00: 20 70 6c 69 6e 6b 20 57 48 45 52 45 20 70 69 64 plink WHERE pid
0b10: 3d 3a 72 69 64 22 29 3b 0a 20 20 64 62 5f 70 72 =:rid");. db_pr
0b20: 65 70 61 72 65 28 26 69 73 42 72 2c 20 0a 20 20 epare(&isBr, .
0b30: 20 20 20 22 53 45 4c 45 43 54 20 31 20 46 52 4f "SELECT 1 FRO
0b40: 4d 20 74 61 67 78 72 65 66 20 57 48 45 52 45 20 M tagxref WHERE
0b50: 72 69 64 3d 3a 72 69 64 20 41 4e 44 20 74 61 67 rid=:rid AND tag
0b60: 69 64 3d 25 64 20 41 4e 44 20 74 61 67 74 79 70 id=%d AND tagtyp
0b70: 65 3d 31 22 2c 0a 20 20 20 20 20 54 41 47 5f 4e e=1",. TAG_N
0b80: 45 57 42 52 41 4e 43 48 0a 20 20 29 3b 0a 20 20 EWBRANCH. );.
0b90: 64 62 5f 70 72 65 70 61 72 65 28 26 69 6e 73 2c db_prepare(&ins,
0ba0: 20 22 49 4e 53 45 52 54 20 4f 52 20 49 47 4e 4f "INSERT OR IGNO
0bb0: 52 45 20 49 4e 54 4f 20 6c 65 61 76 65 73 20 56 RE INTO leaves V
0bc0: 41 4c 55 45 53 28 3a 72 69 64 29 22 29 3b 0a 20 ALUES(:rid)");.
0bd0: 20 77 68 69 6c 65 28 20 62 61 67 5f 63 6f 75 6e while( bag_coun
0be0: 74 28 26 70 65 6e 64 69 6e 67 29 20 29 7b 0a 20 t(&pending) ){.
0bf0: 20 20 20 69 6e 74 20 72 69 64 20 3d 20 62 61 67 int rid = bag
0c00: 5f 66 69 72 73 74 28 26 70 65 6e 64 69 6e 67 29 _first(&pending)
0c10: 3b 0a 20 20 20 20 69 6e 74 20 63 6e 74 20 3d 20 ;. int cnt =
0c20: 30 3b 0a 20 20 20 20 62 61 67 5f 72 65 6d 6f 76 0;. bag_remov
0c30: 65 28 26 70 65 6e 64 69 6e 67 2c 20 72 69 64 29 e(&pending, rid)
0c40: 3b 0a 20 20 20 20 64 62 5f 62 69 6e 64 5f 69 6e ;. db_bind_in
0c50: 74 28 26 71 2c 20 22 3a 72 69 64 22 2c 20 72 69 t(&q, ":rid", ri
0c60: 64 29 3b 0a 20 20 20 20 77 68 69 6c 65 28 20 64 d);. while( d
0c70: 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 b_step(&q)==SQLI
0c80: 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 20 20 TE_ROW ){.
0c90: 69 6e 74 20 63 69 64 20 3d 20 64 62 5f 63 6f 6c int cid = db_col
0ca0: 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 30 29 3b 0a umn_int(&q, 0);.
0cb0: 20 20 20 20 20 20 69 66 28 20 62 61 67 5f 69 6e if( bag_in
0cc0: 73 65 72 74 28 26 73 65 65 6e 2c 20 63 69 64 29 sert(&seen, cid)
0cd0: 20 29 7b 0a 20 20 20 20 20 20 20 20 62 61 67 5f ){. bag_
0ce0: 69 6e 73 65 72 74 28 26 70 65 6e 64 69 6e 67 2c insert(&pending,
0cf0: 20 63 69 64 29 3b 0a 20 20 20 20 20 20 7d 0a 20 cid);. }.
0d00: 20 20 20 20 20 64 62 5f 62 69 6e 64 5f 69 6e 74 db_bind_int
0d10: 28 26 69 73 42 72 2c 20 22 3a 72 69 64 22 2c 20 (&isBr, ":rid",
0d20: 63 69 64 29 3b 0a 20 20 20 20 20 20 69 66 28 20 cid);. if(
0d30: 64 62 5f 73 74 65 70 28 26 69 73 42 72 29 3d 3d db_step(&isBr)==
0d40: 53 51 4c 49 54 45 5f 44 4f 4e 45 20 29 7b 0a 20 SQLITE_DONE ){.
0d50: 20 20 20 20 20 20 20 63 6e 74 2b 2b 3b 0a 20 20 cnt++;.
0d60: 20 20 20 20 7d 0a 20 20 20 20 20 20 64 62 5f 72 }. db_r
0d70: 65 73 65 74 28 26 69 73 42 72 29 3b 0a 20 20 20 eset(&isBr);.
0d80: 20 7d 0a 20 20 20 20 64 62 5f 72 65 73 65 74 28 }. db_reset(
0d90: 26 71 29 3b 0a 20 20 20 20 69 66 28 20 63 6e 74 &q);. if( cnt
0da0: 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 64 62 5f ==0 ){. db_
0db0: 62 69 6e 64 5f 69 6e 74 28 26 69 6e 73 2c 20 22 bind_int(&ins, "
0dc0: 3a 72 69 64 22 2c 20 72 69 64 29 3b 0a 20 20 20 :rid", rid);.
0dd0: 20 20 20 64 62 5f 73 74 65 70 28 26 69 6e 73 29 db_step(&ins)
0de0: 3b 0a 20 20 20 20 20 20 64 62 5f 72 65 73 65 74 ;. db_reset
0df0: 28 26 69 6e 73 29 3b 0a 20 20 20 20 7d 0a 20 20 (&ins);. }.
0e00: 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 }. db_finalize(
0e10: 26 69 6e 73 29 3b 0a 20 20 64 62 5f 66 69 6e 61 &ins);. db_fina
0e20: 6c 69 7a 65 28 26 69 73 42 72 29 3b 0a 20 20 64 lize(&isBr);. d
0e30: 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a b_finalize(&q);.
0e40: 20 20 62 61 67 5f 63 6c 65 61 72 28 26 70 65 6e bag_clear(&pen
0e50: 64 69 6e 67 29 3b 0a 20 20 62 61 67 5f 63 6c 65 ding);. bag_cle
0e60: 61 72 28 26 73 65 65 6e 29 3b 0a 20 20 69 66 28 ar(&seen);. if(
0e70: 20 63 6c 6f 73 65 4d 6f 64 65 3d 3d 31 20 29 7b closeMode==1 ){
0e80: 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 . db_multi_ex
0e90: 65 63 28 0a 20 20 20 20 20 20 22 44 45 4c 45 54 ec(. "DELET
0ea0: 45 20 46 52 4f 4d 20 6c 65 61 76 65 73 20 57 48 E FROM leaves WH
0eb0: 45 52 45 20 72 69 64 20 49 4e 22 0a 20 20 20 20 ERE rid IN".
0ec0: 20 20 22 20 20 28 53 45 4c 45 43 54 20 6c 65 61 " (SELECT lea
0ed0: 76 65 73 2e 72 69 64 20 46 52 4f 4d 20 6c 65 61 ves.rid FROM lea
0ee0: 76 65 73 2c 20 74 61 67 78 72 65 66 22 0a 20 20 ves, tagxref".
0ef0: 20 20 20 20 22 20 20 20 20 57 48 45 52 45 20 74 " WHERE t
0f00: 61 67 78 72 65 66 2e 72 69 64 3d 6c 65 61 76 65 agxref.rid=leave
0f10: 73 2e 72 69 64 20 22 0a 20 20 20 20 20 20 22 20 s.rid ". "
0f20: 20 20 20 20 20 41 4e 44 20 74 61 67 78 72 65 66 AND tagxref
0f30: 2e 74 61 67 69 64 3d 25 64 22 0a 20 20 20 20 20 .tagid=%d".
0f40: 20 22 20 20 20 20 20 20 41 4e 44 20 74 61 67 78 " AND tagx
0f50: 72 65 66 2e 74 61 67 74 79 70 65 3e 30 29 22 2c ref.tagtype>0)",
0f60: 0a 20 20 20 20 20 20 54 41 47 5f 43 4c 4f 53 45 . TAG_CLOSE
0f70: 44 0a 20 20 20 20 29 3b 0a 20 20 7d 65 6c 73 65 D. );. }else
0f80: 20 69 66 28 20 63 6c 6f 73 65 4d 6f 64 65 3d 3d if( closeMode==
0f90: 32 20 29 7b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 2 ){. db_mult
0fa0: 69 5f 65 78 65 63 28 0a 20 20 20 20 20 20 22 44 i_exec(. "D
0fb0: 45 4c 45 54 45 20 46 52 4f 4d 20 6c 65 61 76 65 ELETE FROM leave
0fc0: 73 20 57 48 45 52 45 20 72 69 64 20 4e 4f 54 20 s WHERE rid NOT
0fd0: 49 4e 22 0a 20 20 20 20 20 20 22 20 20 28 53 45 IN". " (SE
0fe0: 4c 45 43 54 20 6c 65 61 76 65 73 2e 72 69 64 20 LECT leaves.rid
0ff0: 46 52 4f 4d 20 6c 65 61 76 65 73 2c 20 74 61 67 FROM leaves, tag
1000: 78 72 65 66 22 0a 20 20 20 20 20 20 22 20 20 20 xref". "
1010: 20 57 48 45 52 45 20 74 61 67 78 72 65 66 2e 72 WHERE tagxref.r
1020: 69 64 3d 6c 65 61 76 65 73 2e 72 69 64 20 22 0a id=leaves.rid ".
1030: 20 20 20 20 20 20 22 20 20 20 20 20 20 41 4e 44 " AND
1040: 20 74 61 67 78 72 65 66 2e 74 61 67 69 64 3d 25 tagxref.tagid=%
1050: 64 22 0a 20 20 20 20 20 20 22 20 20 20 20 20 20 d". "
1060: 41 4e 44 20 74 61 67 78 72 65 66 2e 74 61 67 74 AND tagxref.tagt
1070: 79 70 65 3e 30 29 22 2c 0a 20 20 20 20 20 20 54 ype>0)",. T
1080: 41 47 5f 43 4c 4f 53 45 44 0a 20 20 20 20 29 3b AG_CLOSED. );
1090: 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 4c 6f . }.}../*.** Lo
10a0: 61 64 20 74 68 65 20 72 65 63 6f 72 64 20 49 44 ad the record ID
10b0: 20 72 69 64 20 61 6e 64 20 75 70 20 74 6f 20 4e rid and up to N
10c0: 2d 31 20 63 6c 6f 73 65 73 74 20 61 6e 63 65 73 -1 closest ances
10d0: 74 6f 72 73 20 69 6e 74 6f 0a 2a 2a 20 74 68 65 tors into.** the
10e0: 20 22 6f 6b 22 20 74 61 62 6c 65 2e 0a 2a 2f 0a "ok" table..*/.
10f0: 76 6f 69 64 20 63 6f 6d 70 75 74 65 5f 61 6e 63 void compute_anc
1100: 65 73 74 6f 72 73 28 69 6e 74 20 72 69 64 2c 20 estors(int rid,
1110: 69 6e 74 20 4e 29 7b 0a 20 20 42 61 67 20 73 65 int N){. Bag se
1120: 65 6e 3b 0a 20 20 50 51 75 65 75 65 20 71 75 65 en;. PQueue que
1130: 75 65 3b 0a 20 20 62 61 67 5f 69 6e 69 74 28 26 ue;. bag_init(&
1140: 73 65 65 6e 29 3b 0a 20 20 70 71 75 65 75 65 5f seen);. pqueue_
1150: 69 6e 69 74 28 26 71 75 65 75 65 29 3b 0a 20 20 init(&queue);.
1160: 62 61 67 5f 69 6e 73 65 72 74 28 26 73 65 65 6e bag_insert(&seen
1170: 2c 20 72 69 64 29 3b 0a 20 20 70 71 75 65 75 65 , rid);. pqueue
1180: 5f 69 6e 73 65 72 74 28 26 71 75 65 75 65 2c 20 _insert(&queue,
1190: 72 69 64 2c 20 30 2e 30 29 3b 0a 20 20 77 68 69 rid, 0.0);. whi
11a0: 6c 65 28 20 28 4e 2d 2d 29 3e 30 20 26 26 20 28 le( (N--)>0 && (
11b0: 72 69 64 20 3d 20 70 71 75 65 75 65 5f 65 78 74 rid = pqueue_ext
11c0: 72 61 63 74 28 26 71 75 65 75 65 29 29 21 3d 30 ract(&queue))!=0
11d0: 20 29 7b 0a 20 20 20 20 53 74 6d 74 20 71 3b 0a ){. Stmt q;.
11e0: 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 db_multi_exe
11f0: 63 28 22 49 4e 53 45 52 54 20 4f 52 20 49 47 4e c("INSERT OR IGN
1200: 4f 52 45 20 49 4e 54 4f 20 6f 6b 20 56 41 4c 55 ORE INTO ok VALU
1210: 45 53 28 25 64 29 22 2c 20 72 69 64 29 3b 0a 20 ES(%d)", rid);.
1220: 20 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 db_prepare(&q
1230: 2c 0a 20 20 20 20 20 20 20 22 53 45 4c 45 43 54 ,. "SELECT
1240: 20 61 2e 70 69 64 2c 20 62 2e 6d 74 69 6d 65 20 a.pid, b.mtime
1250: 46 52 4f 4d 20 70 6c 69 6e 6b 20 61 20 4c 45 46 FROM plink a LEF
1260: 54 20 4a 4f 49 4e 20 70 6c 69 6e 6b 20 62 20 4f T JOIN plink b O
1270: 4e 20 62 2e 63 69 64 3d 61 2e 70 69 64 22 0a 20 N b.cid=a.pid".
1280: 20 20 20 20 20 20 22 20 57 48 45 52 45 20 61 2e " WHERE a.
1290: 63 69 64 3d 25 64 22 2c 20 72 69 64 0a 20 20 20 cid=%d", rid.
12a0: 20 29 3b 0a 20 20 20 20 77 68 69 6c 65 28 20 64 );. while( d
12b0: 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 b_step(&q)==SQLI
12c0: 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 20 20 TE_ROW ){.
12d0: 69 6e 74 20 70 69 64 20 3d 20 64 62 5f 63 6f 6c int pid = db_col
12e0: 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 30 29 3b 0a umn_int(&q, 0);.
12f0: 20 20 20 20 20 20 64 6f 75 62 6c 65 20 6d 74 69 double mti
1300: 6d 65 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 64 me = db_column_d
1310: 6f 75 62 6c 65 28 26 71 2c 20 31 29 3b 0a 20 20 ouble(&q, 1);.
1320: 20 20 20 20 69 66 28 20 62 61 67 5f 69 6e 73 65 if( bag_inse
1330: 72 74 28 26 73 65 65 6e 2c 20 70 69 64 29 20 29 rt(&seen, pid) )
1340: 7b 0a 20 20 20 20 20 20 20 20 70 71 75 65 75 65 {. pqueue
1350: 5f 69 6e 73 65 72 74 28 26 71 75 65 75 65 2c 20 _insert(&queue,
1360: 70 69 64 2c 20 2d 6d 74 69 6d 65 29 3b 0a 20 20 pid, -mtime);.
1370: 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 20 20 }. }.
1380: 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b db_finalize(&q);
1390: 0a 20 20 7d 0a 20 20 62 61 67 5f 63 6c 65 61 72 . }. bag_clear
13a0: 28 26 73 65 65 6e 29 3b 0a 20 20 70 71 75 65 75 (&seen);. pqueu
13b0: 65 5f 63 6c 65 61 72 28 26 71 75 65 75 65 29 3b e_clear(&queue);
13c0: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 4c 6f 61 64 20 74 .}../*.** Load t
13d0: 68 65 20 72 65 63 6f 72 64 20 49 44 20 72 69 64 he record ID rid
13e0: 20 61 6e 64 20 75 70 20 74 6f 20 4e 2d 31 20 63 and up to N-1 c
13f0: 6c 6f 73 65 73 74 20 64 65 73 63 65 6e 64 61 6e losest descendan
1400: 74 73 20 69 6e 74 6f 0a 2a 2a 20 74 68 65 20 22 ts into.** the "
1410: 6f 6b 22 20 74 61 62 6c 65 2e 0a 2a 2f 0a 76 6f ok" table..*/.vo
1420: 69 64 20 63 6f 6d 70 75 74 65 5f 64 65 73 63 65 id compute_desce
1430: 6e 64 61 6e 74 73 28 69 6e 74 20 72 69 64 2c 20 ndants(int rid,
1440: 69 6e 74 20 4e 29 7b 0a 20 20 42 61 67 20 73 65 int N){. Bag se
1450: 65 6e 3b 0a 20 20 50 51 75 65 75 65 20 71 75 65 en;. PQueue que
1460: 75 65 3b 0a 20 20 62 61 67 5f 69 6e 69 74 28 26 ue;. bag_init(&
1470: 73 65 65 6e 29 3b 0a 20 20 70 71 75 65 75 65 5f seen);. pqueue_
1480: 69 6e 69 74 28 26 71 75 65 75 65 29 3b 0a 20 20 init(&queue);.
1490: 62 61 67 5f 69 6e 73 65 72 74 28 26 73 65 65 6e bag_insert(&seen
14a0: 2c 20 72 69 64 29 3b 0a 20 20 70 71 75 65 75 65 , rid);. pqueue
14b0: 5f 69 6e 73 65 72 74 28 26 71 75 65 75 65 2c 20 _insert(&queue,
14c0: 72 69 64 2c 20 30 2e 30 29 3b 0a 20 20 77 68 69 rid, 0.0);. whi
14d0: 6c 65 28 20 28 4e 2d 2d 29 3e 30 20 26 26 20 28 le( (N--)>0 && (
14e0: 72 69 64 20 3d 20 70 71 75 65 75 65 5f 65 78 74 rid = pqueue_ext
14f0: 72 61 63 74 28 26 71 75 65 75 65 29 29 21 3d 30 ract(&queue))!=0
1500: 20 29 7b 0a 20 20 20 20 53 74 6d 74 20 71 3b 0a ){. Stmt q;.
1510: 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 db_multi_exe
1520: 63 28 22 49 4e 53 45 52 54 20 4f 52 20 49 47 4e c("INSERT OR IGN
1530: 4f 52 45 20 49 4e 54 4f 20 6f 6b 20 56 41 4c 55 ORE INTO ok VALU
1540: 45 53 28 25 64 29 22 2c 20 72 69 64 29 3b 0a 20 ES(%d)", rid);.
1550: 20 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 db_prepare(&q
1560: 2c 22 53 45 4c 45 43 54 20 63 69 64 2c 20 6d 74 ,"SELECT cid, mt
1570: 69 6d 65 20 46 52 4f 4d 20 70 6c 69 6e 6b 20 57 ime FROM plink W
1580: 48 45 52 45 20 70 69 64 3d 25 64 22 2c 20 72 69 HERE pid=%d", ri
1590: 64 29 3b 0a 20 20 20 20 77 68 69 6c 65 28 20 64 d);. while( d
15a0: 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 b_step(&q)==SQLI
15b0: 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 20 20 TE_ROW ){.
15c0: 69 6e 74 20 70 69 64 20 3d 20 64 62 5f 63 6f 6c int pid = db_col
15d0: 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 30 29 3b 0a umn_int(&q, 0);.
15e0: 20 20 20 20 20 20 64 6f 75 62 6c 65 20 6d 74 69 double mti
15f0: 6d 65 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 64 me = db_column_d
1600: 6f 75 62 6c 65 28 26 71 2c 20 31 29 3b 0a 20 20 ouble(&q, 1);.
1610: 20 20 20 20 69 66 28 20 62 61 67 5f 69 6e 73 65 if( bag_inse
1620: 72 74 28 26 73 65 65 6e 2c 20 70 69 64 29 20 29 rt(&seen, pid) )
1630: 7b 0a 20 20 20 20 20 20 20 20 70 71 75 65 75 65 {. pqueue
1640: 5f 69 6e 73 65 72 74 28 26 71 75 65 75 65 2c 20 _insert(&queue,
1650: 70 69 64 2c 20 6d 74 69 6d 65 29 3b 0a 20 20 20 pid, mtime);.
1660: 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 20 20 64 }. }. d
1670: 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a b_finalize(&q);.
1680: 20 20 7d 0a 20 20 62 61 67 5f 63 6c 65 61 72 28 }. bag_clear(
1690: 26 73 65 65 6e 29 3b 0a 20 20 70 71 75 65 75 65 &seen);. pqueue
16a0: 5f 63 6c 65 61 72 28 26 71 75 65 75 65 29 3b 0a _clear(&queue);.
16b0: 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 }../*.** COMMAND
16c0: 3a 20 20 64 65 73 63 65 6e 64 61 6e 74 73 0a 2a : descendants.*
16d0: 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f 73 *.** Usage: %fos
16e0: 73 69 6c 20 64 65 73 63 65 6e 64 61 6e 74 73 20 sil descendants
16f0: 3f 42 41 53 45 4c 49 4e 45 2d 49 44 3f 0a 2a 2a ?BASELINE-ID?.**
1700: 0a 2a 2a 20 46 69 6e 64 20 61 6c 6c 20 6c 65 61 .** Find all lea
1710: 66 20 64 65 73 63 65 6e 64 61 6e 74 73 20 6f 66 f descendants of
1720: 20 74 68 65 20 62 61 73 65 6c 69 6e 65 20 73 70 the baseline sp
1730: 65 63 69 66 69 65 64 20 6f 72 20 69 66 20 74 68 ecified or if th
1740: 65 20 61 72 67 75 6d 65 6e 74 0a 2a 2a 20 69 73 e argument.** is
1750: 20 6f 6d 69 74 74 65 64 2c 20 6f 66 20 74 68 65 omitted, of the
1760: 20 62 61 73 65 6c 69 6e 65 20 63 75 72 72 65 6e baseline curren
1770: 74 6c 79 20 63 68 65 63 6b 65 64 20 6f 75 74 2e tly checked out.
1780: 0a 2a 2f 0a 76 6f 69 64 20 64 65 73 63 65 6e 64 .*/.void descend
1790: 61 6e 74 73 5f 63 6d 64 28 76 6f 69 64 29 7b 0a ants_cmd(void){.
17a0: 20 20 53 74 6d 74 20 71 3b 0a 20 20 69 6e 74 20 Stmt q;. int
17b0: 62 61 73 65 3b 0a 0a 20 20 64 62 5f 6d 75 73 74 base;.. db_must
17c0: 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72 65 65 28 _be_within_tree(
17d0: 29 3b 0a 20 20 69 66 28 20 67 2e 61 72 67 63 3d );. if( g.argc=
17e0: 3d 32 20 29 7b 0a 20 20 20 20 62 61 73 65 20 3d =2 ){. base =
17f0: 20 64 62 5f 6c 67 65 74 5f 69 6e 74 28 22 63 68 db_lget_int("ch
1800: 65 63 6b 6f 75 74 22 2c 20 30 29 3b 0a 20 20 7d eckout", 0);. }
1810: 65 6c 73 65 7b 0a 20 20 20 20 62 61 73 65 20 3d else{. base =
1820: 20 6e 61 6d 65 5f 74 6f 5f 72 69 64 28 67 2e 61 name_to_rid(g.a
1830: 72 67 76 5b 32 5d 29 3b 0a 20 20 7d 0a 20 20 69 rgv[2]);. }. i
1840: 66 28 20 62 61 73 65 3d 3d 30 20 29 20 72 65 74 f( base==0 ) ret
1850: 75 72 6e 3b 0a 20 20 63 6f 6d 70 75 74 65 5f 6c urn;. compute_l
1860: 65 61 76 65 73 28 62 61 73 65 2c 20 30 29 3b 0a eaves(base, 0);.
1870: 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c db_prepare(&q,
1880: 0a 20 20 20 20 22 25 73 22 0a 20 20 20 20 22 20 . "%s". "
1890: 20 20 41 4e 44 20 65 76 65 6e 74 2e 6f 62 6a 69 AND event.obji
18a0: 64 20 49 4e 20 28 53 45 4c 45 43 54 20 72 69 64 d IN (SELECT rid
18b0: 20 46 52 4f 4d 20 6c 65 61 76 65 73 29 22 0a 20 FROM leaves)".
18c0: 20 20 20 22 20 4f 52 44 45 52 20 42 59 20 65 76 " ORDER BY ev
18d0: 65 6e 74 2e 6d 74 69 6d 65 20 44 45 53 43 22 2c ent.mtime DESC",
18e0: 0a 20 20 20 20 74 69 6d 65 6c 69 6e 65 5f 71 75 . timeline_qu
18f0: 65 72 79 5f 66 6f 72 5f 74 74 79 28 29 0a 20 20 ery_for_tty().
1900: 29 3b 0a 20 20 70 72 69 6e 74 5f 74 69 6d 65 6c );. print_timel
1910: 69 6e 65 28 26 71 2c 20 32 30 29 3b 0a 20 20 64 ine(&q, 20);. d
1920: 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a b_finalize(&q);.
1930: 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 }../*.** COMMAND
1940: 3a 20 20 6c 65 61 76 65 73 0a 2a 2a 0a 2a 2a 20 : leaves.**.**
1950: 55 73 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 6c Usage: %fossil l
1960: 65 61 76 65 73 20 3f 2d 2d 61 6c 6c 3f 20 3f 2d eaves ?--all? ?-
1970: 2d 63 6c 6f 73 65 64 3f 0a 2a 2a 0a 2a 2a 20 46 -closed?.**.** F
1980: 69 6e 64 20 6c 65 61 76 65 73 20 6f 66 20 61 6c ind leaves of al
1990: 6c 20 62 72 61 6e 63 68 65 73 2e 20 20 42 79 20 l branches. By
19a0: 64 65 66 61 75 6c 74 20 73 68 6f 77 20 6f 6e 6c default show onl
19b0: 79 20 6f 70 65 6e 20 6c 65 61 76 65 73 2e 0a 2a y open leaves..*
19c0: 2a 20 54 68 65 20 2d 2d 61 6c 6c 20 66 6c 61 67 * The --all flag
19d0: 20 63 61 75 73 65 73 20 61 6c 6c 20 6c 65 61 76 causes all leav
19e0: 65 73 20 28 63 6c 6f 73 65 64 20 61 6e 64 20 6f es (closed and o
19f0: 70 65 6e 29 20 74 6f 20 62 65 20 73 68 6f 77 6e pen) to be shown
1a00: 2e 0a 2a 2a 20 54 68 65 20 2d 2d 63 6c 6f 73 65 ..** The --close
1a10: 64 20 66 6c 61 67 20 73 68 6f 77 73 20 6f 6e 6c d flag shows onl
1a20: 79 20 63 6c 6f 73 65 64 20 6c 65 61 76 65 73 2e y closed leaves.
1a30: 0a 2a 2f 0a 76 6f 69 64 20 6c 65 61 76 65 73 5f .*/.void leaves_
1a40: 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 53 74 6d cmd(void){. Stm
1a50: 74 20 71 3b 0a 20 20 69 6e 74 20 73 68 6f 77 41 t q;. int showA
1a60: 6c 6c 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e ll = find_option
1a70: 28 22 61 6c 6c 22 2c 20 30 2c 20 30 29 21 3d 30 ("all", 0, 0)!=0
1a80: 3b 0a 20 20 69 6e 74 20 73 68 6f 77 43 6c 6f 73 ;. int showClos
1a90: 65 64 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e ed = find_option
1aa0: 28 22 63 6c 6f 73 65 64 22 2c 20 30 2c 20 30 29 ("closed", 0, 0)
1ab0: 21 3d 30 3b 0a 0a 20 20 64 62 5f 6d 75 73 74 5f !=0;.. db_must_
1ac0: 62 65 5f 77 69 74 68 69 6e 5f 74 72 65 65 28 29 be_within_tree()
1ad0: 3b 0a 20 20 63 6f 6d 70 75 74 65 5f 6c 65 61 76 ;. compute_leav
1ae0: 65 73 28 30 2c 20 73 68 6f 77 41 6c 6c 20 3f 20 es(0, showAll ?
1af0: 30 20 3a 20 73 68 6f 77 43 6c 6f 73 65 64 20 3f 0 : showClosed ?
1b00: 20 32 20 3a 20 31 29 3b 0a 20 20 64 62 5f 70 72 2 : 1);. db_pr
1b10: 65 70 61 72 65 28 26 71 2c 0a 20 20 20 20 22 25 epare(&q,. "%
1b20: 73 22 0a 20 20 20 20 22 20 20 20 41 4e 44 20 62 s". " AND b
1b30: 6c 6f 62 2e 72 69 64 20 49 4e 20 6c 65 61 76 65 lob.rid IN leave
1b40: 73 22 0a 20 20 20 20 22 20 4f 52 44 45 52 20 42 s". " ORDER B
1b50: 59 20 65 76 65 6e 74 2e 6d 74 69 6d 65 20 44 45 Y event.mtime DE
1b60: 53 43 22 2c 0a 20 20 20 20 74 69 6d 65 6c 69 6e SC",. timelin
1b70: 65 5f 71 75 65 72 79 5f 66 6f 72 5f 74 74 79 28 e_query_for_tty(
1b80: 29 0a 20 20 29 3b 0a 20 20 70 72 69 6e 74 5f 74 ). );. print_t
1b90: 69 6d 65 6c 69 6e 65 28 26 71 2c 20 32 30 30 30 imeline(&q, 2000
1ba0: 29 3b 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 );. db_finalize
1bb0: 28 26 71 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 57 (&q);.}../*.** W
1bc0: 45 42 50 41 47 45 3a 20 20 6c 65 61 76 65 73 0a EBPAGE: leaves.
1bd0: 2a 2a 0a 2a 2a 20 46 69 6e 64 20 6c 65 61 76 65 **.** Find leave
1be0: 73 20 6f 66 20 61 6c 6c 20 62 72 61 6e 63 68 65 s of all branche
1bf0: 73 2e 0a 2a 2f 0a 76 6f 69 64 20 6c 65 61 76 65 s..*/.void leave
1c00: 73 5f 70 61 67 65 28 76 6f 69 64 29 7b 0a 20 20 s_page(void){.
1c10: 53 74 6d 74 20 71 3b 0a 20 20 69 6e 74 20 73 68 Stmt q;. int sh
1c20: 6f 77 41 6c 6c 20 3d 20 50 28 22 61 6c 6c 22 29 owAll = P("all")
1c30: 21 3d 30 3b 0a 20 20 69 6e 74 20 73 68 6f 77 43 !=0;. int showC
1c40: 6c 6f 73 65 64 20 3d 20 50 28 22 63 6c 6f 73 65 losed = P("close
1c50: 64 22 29 21 3d 30 3b 0a 0a 20 20 6c 6f 67 69 6e d")!=0;.. login
1c60: 5f 63 68 65 63 6b 5f 63 72 65 64 65 6e 74 69 61 _check_credentia
1c70: 6c 73 28 29 3b 0a 20 20 69 66 28 20 21 67 2e 6f ls();. if( !g.o
1c80: 6b 52 65 61 64 20 29 7b 20 6c 6f 67 69 6e 5f 6e kRead ){ login_n
1c90: 65 65 64 65 64 28 29 3b 20 72 65 74 75 72 6e 3b eeded(); return;
1ca0: 20 7d 0a 0a 20 20 69 66 28 20 21 73 68 6f 77 41 }.. if( !showA
1cb0: 6c 6c 20 29 7b 0a 20 20 20 20 73 74 79 6c 65 5f ll ){. style_
1cc0: 73 75 62 6d 65 6e 75 5f 65 6c 65 6d 65 6e 74 28 submenu_element(
1cd0: 22 41 6c 6c 22 2c 20 22 41 6c 6c 22 2c 20 22 6c "All", "All", "l
1ce0: 65 61 76 65 73 3f 61 6c 6c 22 29 3b 0a 20 20 7d eaves?all");. }
1cf0: 0a 20 20 69 66 28 20 21 73 68 6f 77 43 6c 6f 73 . if( !showClos
1d00: 65 64 20 29 7b 0a 20 20 20 20 73 74 79 6c 65 5f ed ){. style_
1d10: 73 75 62 6d 65 6e 75 5f 65 6c 65 6d 65 6e 74 28 submenu_element(
1d20: 22 43 6c 6f 73 65 64 22 2c 20 22 43 6c 6f 73 65 "Closed", "Close
1d30: 64 22 2c 20 22 6c 65 61 76 65 73 3f 63 6c 6f 73 d", "leaves?clos
1d40: 65 64 22 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 ed");. }. if(
1d50: 73 68 6f 77 43 6c 6f 73 65 64 20 7c 7c 20 73 68 showClosed || sh
1d60: 6f 77 41 6c 6c 20 29 7b 0a 20 20 20 20 73 74 79 owAll ){. sty
1d70: 6c 65 5f 73 75 62 6d 65 6e 75 5f 65 6c 65 6d 65 le_submenu_eleme
1d80: 6e 74 28 22 4f 70 65 6e 22 2c 20 22 4f 70 65 6e nt("Open", "Open
1d90: 22 2c 20 22 6c 65 61 76 65 73 22 29 3b 0a 20 20 ", "leaves");.
1da0: 7d 0a 20 20 73 74 79 6c 65 5f 68 65 61 64 65 72 }. style_header
1db0: 28 22 4c 65 61 76 65 73 22 29 3b 0a 20 20 6c 6f ("Leaves");. lo
1dc0: 67 69 6e 5f 61 6e 6f 6e 79 6d 6f 75 73 5f 61 76 gin_anonymous_av
1dd0: 61 69 6c 61 62 6c 65 28 29 3b 0a 20 20 63 6f 6d ailable();. com
1de0: 70 75 74 65 5f 6c 65 61 76 65 73 28 30 2c 20 73 pute_leaves(0, s
1df0: 68 6f 77 41 6c 6c 20 3f 20 30 20 3a 20 73 68 6f howAll ? 0 : sho
1e00: 77 43 6c 6f 73 65 64 20 3f 20 32 20 3a 20 31 29 wClosed ? 2 : 1)
1e10: 3b 0a 20 20 40 20 3c 74 61 62 6c 65 20 77 69 64 ;. @ <table wid
1e20: 74 68 3d 22 33 33 25 25 22 20 61 6c 69 67 6e 3d th="33%%" align=
1e30: 22 72 69 67 68 74 22 20 62 6f 72 64 65 72 3d 22 "right" border="
1e40: 31 22 3e 0a 20 20 40 20 3c 74 72 3e 3c 74 64 3e 1">. @ <tr><td>
1e50: 0a 20 20 40 20 3c 62 3e 4e 6f 6d 65 6e 63 6c 61 . @ <b>Nomencla
1e60: 74 75 72 65 3a 3c 2f 62 3e 0a 20 20 40 20 3c 6f ture:</b>. @ <o
1e70: 6c 3e 0a 20 20 40 20 3c 6c 69 3e 20 41 20 3c 62 l>. @ <li> A <b
1e80: 3e 6c 65 61 66 3c 2f 62 3e 20 69 73 20 61 20 63 >leaf</b> is a c
1e90: 68 65 63 6b 2d 69 6e 20 77 69 74 68 20 6e 6f 20 heck-in with no
1ea0: 64 65 73 63 65 6e 64 61 6e 74 73 2e 3c 2f 6c 69 descendants.</li
1eb0: 3e 0a 20 20 40 20 3c 6c 69 3e 20 41 6e 20 3c 62 >. @ <li> An <b
1ec0: 3e 6f 70 65 6e 20 6c 65 61 66 3c 2f 62 3e 20 69 >open leaf</b> i
1ed0: 73 20 61 20 6c 65 61 66 20 74 68 61 74 20 64 6f s a leaf that do
1ee0: 65 73 20 6e 6f 74 20 68 61 76 65 20 61 20 22 63 es not have a "c
1ef0: 6c 6f 73 65 64 22 20 74 61 67 0a 20 20 40 20 61 losed" tag. @ a
1f00: 6e 64 20 69 73 20 74 68 75 73 20 61 73 73 75 6d nd is thus assum
1f10: 65 64 20 74 6f 20 73 74 69 6c 6c 20 62 65 20 69 ed to still be i
1f20: 6e 20 75 73 65 2e 3c 2f 6c 69 3e 0a 20 20 40 20 n use.</li>. @
1f30: 3c 6c 69 3e 20 41 20 3c 62 3e 63 6c 6f 73 65 64 <li> A <b>closed
1f40: 20 6c 65 61 66 3c 2f 62 3e 20 68 61 73 20 61 20 leaf</b> has a
1f50: 22 63 6c 6f 73 65 64 22 20 74 61 67 20 61 6e 64 "closed" tag and
1f60: 20 69 73 20 74 68 75 73 20 61 73 73 75 6d 65 64 is thus assumed
1f70: 20 74 6f 0a 20 20 40 20 62 65 20 68 69 73 74 6f to. @ be histo
1f80: 72 69 63 61 6c 20 61 6e 64 20 6e 6f 20 6c 6f 6e rical and no lon
1f90: 67 65 72 20 69 6e 20 61 63 74 69 76 65 20 75 73 ger in active us
1fa0: 65 2e 3c 2f 6c 69 3e 0a 20 20 40 20 3c 2f 6f 6c e.</li>. @ </ol
1fb0: 3e 0a 20 20 40 20 3c 2f 74 64 3e 3c 2f 74 72 3e >. @ </td></tr>
1fc0: 3c 2f 74 61 62 6c 65 3e 0a 20 20 69 66 28 20 73 </table>. if( s
1fd0: 68 6f 77 41 6c 6c 20 29 7b 0a 20 20 20 20 40 20 howAll ){. @
1fe0: 3c 68 31 3e 41 6c 6c 20 6c 65 61 76 65 73 2c 20 <h1>All leaves,
1ff0: 62 6f 74 68 20 6f 70 65 6e 20 61 6e 64 20 63 6c both open and cl
2000: 6f 73 65 64 3c 2f 68 31 3e 0a 20 20 7d 65 6c 73 osed</h1>. }els
2010: 65 20 69 66 28 20 73 68 6f 77 43 6c 6f 73 65 64 e if( showClosed
2020: 20 29 7b 0a 20 20 20 20 40 20 3c 68 31 3e 43 6c ){. @ <h1>Cl
2030: 6f 73 65 64 20 6c 65 61 76 65 73 20 6f 6e 6c 79 osed leaves only
2040: 3c 2f 68 31 3e 0a 20 20 7d 65 6c 73 65 7b 0a 20 </h1>. }else{.
2050: 20 20 20 40 20 3c 68 31 3e 41 6c 6c 20 6f 70 65 @ <h1>All ope
2060: 6e 20 6c 65 61 76 65 73 3c 2f 68 31 3e 0a 20 20 n leaves</h1>.
2070: 7d 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 }. db_prepare(&
2080: 71 2c 0a 20 20 20 20 22 25 73 22 0a 20 20 20 20 q,. "%s".
2090: 22 20 20 20 41 4e 44 20 62 6c 6f 62 2e 72 69 64 " AND blob.rid
20a0: 20 49 4e 20 6c 65 61 76 65 73 22 0a 20 20 20 20 IN leaves".
20b0: 22 20 4f 52 44 45 52 20 42 59 20 65 76 65 6e 74 " ORDER BY event
20c0: 2e 6d 74 69 6d 65 20 44 45 53 43 22 2c 0a 20 20 .mtime DESC",.
20d0: 20 20 74 69 6d 65 6c 69 6e 65 5f 71 75 65 72 79 timeline_query
20e0: 5f 66 6f 72 5f 77 77 77 28 29 0a 20 20 29 3b 0a _for_www(). );.
20f0: 20 20 77 77 77 5f 70 72 69 6e 74 5f 74 69 6d 65 www_print_time
2100: 6c 69 6e 65 28 26 71 2c 20 30 2c 20 30 29 3b 0a line(&q, 0, 0);.
2110: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 db_finalize(&q
2120: 29 3b 0a 20 20 40 20 3c 62 72 20 63 6c 65 61 72 );. @ <br clear
2130: 3d 22 62 6f 74 68 22 3e 0a 20 20 40 20 3c 73 63 ="both">. @ <sc
2140: 72 69 70 74 3e 0a 20 20 40 20 66 75 6e 63 74 69 ript>. @ functi
2150: 6f 6e 20 78 69 6e 28 69 64 29 7b 0a 20 20 40 20 on xin(id){. @
2160: 7d 0a 20 20 40 20 66 75 6e 63 74 69 6f 6e 20 78 }. @ function x
2170: 6f 75 74 28 69 64 29 7b 0a 20 20 40 20 7d 0a 20 out(id){. @ }.
2180: 20 40 20 3c 2f 73 63 72 69 70 74 3e 0a 20 20 73 @ </script>. s
2190: 74 79 6c 65 5f 66 6f 6f 74 65 72 28 29 3b 0a 7d tyle_footer();.}
21a0: 0a .