Hex Artifact Content
Not logged in

Artifact a19ebf91b91d2424393c63b985fa8cf48b0a92dd:

File src/descendants.c part of check-in [b6e22e62cf] - Attempting to rationalize the tagging and branching logic. The "branch" command has been resurrected and appears to work now. The "tag branch" command has been removed. Special tags "newbranch" and "closed" used to manage branches. New changes are not well-tested - use with caution. You must "rebuild" when upgrading through this version. by drh on 2009-01-20 16:51:19.

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 7d 0a 20 20 62 61 67 5f 69 6e 73 65 72  .  }.  bag_inser
0ab0: 74 28 26 70 65 6e 64 69 6e 67 2c 20 69 42 61 73  t(&pending, iBas
0ac0: 65 29 3b 0a 20 20 64 62 5f 70 72 65 70 61 72 65  e);.  db_prepare
0ad0: 28 26 71 2c 20 22 53 45 4c 45 43 54 20 63 69 64  (&q, "SELECT cid
0ae0: 20 46 52 4f 4d 20 70 6c 69 6e 6b 20 57 48 45 52   FROM plink WHER
0af0: 45 20 70 69 64 3d 3a 72 69 64 22 29 3b 0a 20 20  E pid=:rid");.  
0b00: 64 62 5f 70 72 65 70 61 72 65 28 26 69 73 42 72  db_prepare(&isBr
0b10: 2c 20 0a 20 20 20 20 20 22 53 45 4c 45 43 54 20  , .     "SELECT 
0b20: 31 20 46 52 4f 4d 20 74 61 67 78 72 65 66 20 57  1 FROM tagxref W
0b30: 48 45 52 45 20 72 69 64 3d 3a 72 69 64 20 41 4e  HERE rid=:rid AN
0b40: 44 20 74 61 67 69 64 3d 25 64 20 41 4e 44 20 74  D tagid=%d AND t
0b50: 61 67 74 79 70 65 3d 31 22 2c 0a 20 20 20 20 20  agtype=1",.     
0b60: 54 41 47 5f 4e 45 57 42 52 41 4e 43 48 0a 20 20  TAG_NEWBRANCH.  
0b70: 29 3b 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28  );.  db_prepare(
0b80: 26 69 6e 73 2c 20 22 49 4e 53 45 52 54 20 4f 52  &ins, "INSERT OR
0b90: 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 6c 65 61   IGNORE INTO lea
0ba0: 76 65 73 20 56 41 4c 55 45 53 28 3a 72 69 64 29  ves VALUES(:rid)
0bb0: 22 29 3b 0a 20 20 77 68 69 6c 65 28 20 62 61 67  ");.  while( bag
0bc0: 5f 63 6f 75 6e 74 28 26 70 65 6e 64 69 6e 67 29  _count(&pending)
0bd0: 20 29 7b 0a 20 20 20 20 69 6e 74 20 72 69 64 20   ){.    int rid 
0be0: 3d 20 62 61 67 5f 66 69 72 73 74 28 26 70 65 6e  = bag_first(&pen
0bf0: 64 69 6e 67 29 3b 0a 20 20 20 20 69 6e 74 20 63  ding);.    int c
0c00: 6e 74 20 3d 20 30 3b 0a 20 20 20 20 62 61 67 5f  nt = 0;.    bag_
0c10: 72 65 6d 6f 76 65 28 26 70 65 6e 64 69 6e 67 2c  remove(&pending,
0c20: 20 72 69 64 29 3b 0a 20 20 20 20 64 62 5f 62 69   rid);.    db_bi
0c30: 6e 64 5f 69 6e 74 28 26 71 2c 20 22 3a 72 69 64  nd_int(&q, ":rid
0c40: 22 2c 20 72 69 64 29 3b 0a 20 20 20 20 77 68 69  ", rid);.    whi
0c50: 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d  le( db_step(&q)=
0c60: 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20  =SQLITE_ROW ){. 
0c70: 20 20 20 20 20 69 6e 74 20 63 69 64 20 3d 20 64       int cid = d
0c80: 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c  b_column_int(&q,
0c90: 20 30 29 3b 0a 20 20 20 20 20 20 69 66 28 20 62   0);.      if( b
0ca0: 61 67 5f 69 6e 73 65 72 74 28 26 73 65 65 6e 2c  ag_insert(&seen,
0cb0: 20 63 69 64 29 20 29 7b 0a 20 20 20 20 20 20 20   cid) ){.       
0cc0: 20 62 61 67 5f 69 6e 73 65 72 74 28 26 70 65 6e   bag_insert(&pen
0cd0: 64 69 6e 67 2c 20 63 69 64 29 3b 0a 20 20 20 20  ding, cid);.    
0ce0: 20 20 7d 0a 20 20 20 20 20 20 64 62 5f 62 69 6e    }.      db_bin
0cf0: 64 5f 69 6e 74 28 26 69 73 42 72 2c 20 22 3a 72  d_int(&isBr, ":r
0d00: 69 64 22 2c 20 63 69 64 29 3b 0a 20 20 20 20 20  id", cid);.     
0d10: 20 69 66 28 20 64 62 5f 73 74 65 70 28 26 69 73   if( db_step(&is
0d20: 42 72 29 3d 3d 53 51 4c 49 54 45 5f 44 4f 4e 45  Br)==SQLITE_DONE
0d30: 20 29 7b 0a 20 20 20 20 20 20 20 20 63 6e 74 2b   ){.        cnt+
0d40: 2b 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20  +;.      }.     
0d50: 20 64 62 5f 72 65 73 65 74 28 26 69 73 42 72 29   db_reset(&isBr)
0d60: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 64 62 5f 72  ;.    }.    db_r
0d70: 65 73 65 74 28 26 71 29 3b 0a 20 20 20 20 69 66  eset(&q);.    if
0d80: 28 20 63 6e 74 3d 3d 30 20 29 7b 0a 20 20 20 20  ( cnt==0 ){.    
0d90: 20 20 64 62 5f 62 69 6e 64 5f 69 6e 74 28 26 69    db_bind_int(&i
0da0: 6e 73 2c 20 22 3a 72 69 64 22 2c 20 72 69 64 29  ns, ":rid", rid)
0db0: 3b 0a 20 20 20 20 20 20 64 62 5f 73 74 65 70 28  ;.      db_step(
0dc0: 26 69 6e 73 29 3b 0a 20 20 20 20 20 20 64 62 5f  &ins);.      db_
0dd0: 72 65 73 65 74 28 26 69 6e 73 29 3b 0a 20 20 20  reset(&ins);.   
0de0: 20 7d 0a 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61   }.  }.  db_fina
0df0: 6c 69 7a 65 28 26 69 6e 73 29 3b 0a 20 20 64 62  lize(&ins);.  db
0e00: 5f 66 69 6e 61 6c 69 7a 65 28 26 69 73 42 72 29  _finalize(&isBr)
0e10: 3b 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28  ;.  db_finalize(
0e20: 26 71 29 3b 0a 20 20 62 61 67 5f 63 6c 65 61 72  &q);.  bag_clear
0e30: 28 26 70 65 6e 64 69 6e 67 29 3b 0a 20 20 62 61  (&pending);.  ba
0e40: 67 5f 63 6c 65 61 72 28 26 73 65 65 6e 29 3b 0a  g_clear(&seen);.
0e50: 20 20 69 66 28 20 63 6c 6f 73 65 4d 6f 64 65 3d    if( closeMode=
0e60: 3d 31 20 29 7b 0a 20 20 20 20 64 62 5f 6d 75 6c  =1 ){.    db_mul
0e70: 74 69 5f 65 78 65 63 28 0a 20 20 20 20 20 20 22  ti_exec(.      "
0e80: 44 45 4c 45 54 45 20 46 52 4f 4d 20 6c 65 61 76  DELETE FROM leav
0e90: 65 73 20 57 48 45 52 45 20 72 69 64 20 49 4e 22  es WHERE rid IN"
0ea0: 0a 20 20 20 20 20 20 22 20 20 28 53 45 4c 45 43  .      "  (SELEC
0eb0: 54 20 6c 65 61 76 65 73 2e 72 69 64 20 46 52 4f  T leaves.rid FRO
0ec0: 4d 20 6c 65 61 76 65 73 2c 20 74 61 67 78 72 65  M leaves, tagxre
0ed0: 66 22 0a 20 20 20 20 20 20 22 20 20 20 20 57 48  f".      "    WH
0ee0: 45 52 45 20 74 61 67 78 72 65 66 2e 72 69 64 3d  ERE tagxref.rid=
0ef0: 6c 65 61 76 65 73 2e 72 69 64 20 22 0a 20 20 20  leaves.rid ".   
0f00: 20 20 20 22 20 20 20 20 20 20 41 4e 44 20 74 61     "      AND ta
0f10: 67 78 72 65 66 2e 74 61 67 69 64 3d 25 64 22 0a  gxref.tagid=%d".
0f20: 20 20 20 20 20 20 22 20 20 20 20 20 20 41 4e 44        "      AND
0f30: 20 74 61 67 78 72 65 66 2e 74 61 67 74 79 70 65   tagxref.tagtype
0f40: 3e 30 29 22 2c 0a 20 20 20 20 20 20 54 41 47 5f  >0)",.      TAG_
0f50: 43 4c 4f 53 45 44 0a 20 20 20 20 29 3b 0a 20 20  CLOSED.    );.  
0f60: 7d 65 6c 73 65 20 69 66 28 20 63 6c 6f 73 65 4d  }else if( closeM
0f70: 6f 64 65 3d 3d 32 20 29 7b 0a 20 20 20 20 64 62  ode==2 ){.    db
0f80: 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20  _multi_exec(.   
0f90: 20 20 20 22 44 45 4c 45 54 45 20 46 52 4f 4d 20     "DELETE FROM 
0fa0: 6c 65 61 76 65 73 20 57 48 45 52 45 20 72 69 64  leaves WHERE rid
0fb0: 20 4e 4f 54 20 49 4e 22 0a 20 20 20 20 20 20 22   NOT IN".      "
0fc0: 20 20 28 53 45 4c 45 43 54 20 6c 65 61 76 65 73    (SELECT leaves
0fd0: 2e 72 69 64 20 46 52 4f 4d 20 6c 65 61 76 65 73  .rid FROM leaves
0fe0: 2c 20 74 61 67 78 72 65 66 22 0a 20 20 20 20 20  , tagxref".     
0ff0: 20 22 20 20 20 20 57 48 45 52 45 20 74 61 67 78   "    WHERE tagx
1000: 72 65 66 2e 72 69 64 3d 6c 65 61 76 65 73 2e 72  ref.rid=leaves.r
1010: 69 64 20 22 0a 20 20 20 20 20 20 22 20 20 20 20  id ".      "    
1020: 20 20 41 4e 44 20 74 61 67 78 72 65 66 2e 74 61    AND tagxref.ta
1030: 67 69 64 3d 25 64 22 0a 20 20 20 20 20 20 22 20  gid=%d".      " 
1040: 20 20 20 20 20 41 4e 44 20 74 61 67 78 72 65 66       AND tagxref
1050: 2e 74 61 67 74 79 70 65 3e 30 29 22 2c 0a 20 20  .tagtype>0)",.  
1060: 20 20 20 20 54 41 47 5f 43 4c 4f 53 45 44 0a 20      TAG_CLOSED. 
1070: 20 20 20 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a     );.  }.}../*.
1080: 2a 2a 20 4c 6f 61 64 20 74 68 65 20 72 65 63 6f  ** Load the reco
1090: 72 64 20 49 44 20 72 69 64 20 61 6e 64 20 75 70  rd ID rid and up
10a0: 20 74 6f 20 4e 2d 31 20 63 6c 6f 73 65 73 74 20   to N-1 closest 
10b0: 61 6e 63 65 73 74 6f 72 73 20 69 6e 74 6f 0a 2a  ancestors into.*
10c0: 2a 20 74 68 65 20 22 6f 6b 22 20 74 61 62 6c 65  * the "ok" table
10d0: 2e 0a 2a 2f 0a 76 6f 69 64 20 63 6f 6d 70 75 74  ..*/.void comput
10e0: 65 5f 61 6e 63 65 73 74 6f 72 73 28 69 6e 74 20  e_ancestors(int 
10f0: 72 69 64 2c 20 69 6e 74 20 4e 29 7b 0a 20 20 42  rid, int N){.  B
1100: 61 67 20 73 65 65 6e 3b 0a 20 20 50 51 75 65 75  ag seen;.  PQueu
1110: 65 20 71 75 65 75 65 3b 0a 20 20 62 61 67 5f 69  e queue;.  bag_i
1120: 6e 69 74 28 26 73 65 65 6e 29 3b 0a 20 20 70 71  nit(&seen);.  pq
1130: 75 65 75 65 5f 69 6e 69 74 28 26 71 75 65 75 65  ueue_init(&queue
1140: 29 3b 0a 20 20 62 61 67 5f 69 6e 73 65 72 74 28  );.  bag_insert(
1150: 26 73 65 65 6e 2c 20 72 69 64 29 3b 0a 20 20 70  &seen, rid);.  p
1160: 71 75 65 75 65 5f 69 6e 73 65 72 74 28 26 71 75  queue_insert(&qu
1170: 65 75 65 2c 20 72 69 64 2c 20 30 2e 30 29 3b 0a  eue, rid, 0.0);.
1180: 20 20 77 68 69 6c 65 28 20 28 4e 2d 2d 29 3e 30    while( (N--)>0
1190: 20 26 26 20 28 72 69 64 20 3d 20 70 71 75 65 75   && (rid = pqueu
11a0: 65 5f 65 78 74 72 61 63 74 28 26 71 75 65 75 65  e_extract(&queue
11b0: 29 29 21 3d 30 20 29 7b 0a 20 20 20 20 53 74 6d  ))!=0 ){.    Stm
11c0: 74 20 71 3b 0a 20 20 20 20 64 62 5f 6d 75 6c 74  t q;.    db_mult
11d0: 69 5f 65 78 65 63 28 22 49 4e 53 45 52 54 20 4f  i_exec("INSERT O
11e0: 52 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 6f 6b  R IGNORE INTO ok
11f0: 20 56 41 4c 55 45 53 28 25 64 29 22 2c 20 72 69   VALUES(%d)", ri
1200: 64 29 3b 0a 20 20 20 20 64 62 5f 70 72 65 70 61  d);.    db_prepa
1210: 72 65 28 26 71 2c 0a 20 20 20 20 20 20 20 22 53  re(&q,.       "S
1220: 45 4c 45 43 54 20 61 2e 70 69 64 2c 20 62 2e 6d  ELECT a.pid, b.m
1230: 74 69 6d 65 20 46 52 4f 4d 20 70 6c 69 6e 6b 20  time FROM plink 
1240: 61 20 4c 45 46 54 20 4a 4f 49 4e 20 70 6c 69 6e  a LEFT JOIN plin
1250: 6b 20 62 20 4f 4e 20 62 2e 63 69 64 3d 61 2e 70  k b ON b.cid=a.p
1260: 69 64 22 0a 20 20 20 20 20 20 20 22 20 57 48 45  id".       " WHE
1270: 52 45 20 61 2e 63 69 64 3d 25 64 22 2c 20 72 69  RE a.cid=%d", ri
1280: 64 0a 20 20 20 20 29 3b 0a 20 20 20 20 77 68 69  d.    );.    whi
1290: 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d  le( db_step(&q)=
12a0: 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20  =SQLITE_ROW ){. 
12b0: 20 20 20 20 20 69 6e 74 20 70 69 64 20 3d 20 64       int pid = d
12c0: 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c  b_column_int(&q,
12d0: 20 30 29 3b 0a 20 20 20 20 20 20 64 6f 75 62 6c   0);.      doubl
12e0: 65 20 6d 74 69 6d 65 20 3d 20 64 62 5f 63 6f 6c  e mtime = db_col
12f0: 75 6d 6e 5f 64 6f 75 62 6c 65 28 26 71 2c 20 31  umn_double(&q, 1
1300: 29 3b 0a 20 20 20 20 20 20 69 66 28 20 62 61 67  );.      if( bag
1310: 5f 69 6e 73 65 72 74 28 26 73 65 65 6e 2c 20 70  _insert(&seen, p
1320: 69 64 29 20 29 7b 0a 20 20 20 20 20 20 20 20 70  id) ){.        p
1330: 71 75 65 75 65 5f 69 6e 73 65 72 74 28 26 71 75  queue_insert(&qu
1340: 65 75 65 2c 20 70 69 64 2c 20 2d 6d 74 69 6d 65  eue, pid, -mtime
1350: 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d  );.      }.    }
1360: 0a 20 20 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65  .    db_finalize
1370: 28 26 71 29 3b 0a 20 20 7d 0a 20 20 62 61 67 5f  (&q);.  }.  bag_
1380: 63 6c 65 61 72 28 26 73 65 65 6e 29 3b 0a 20 20  clear(&seen);.  
1390: 70 71 75 65 75 65 5f 63 6c 65 61 72 28 26 71 75  pqueue_clear(&qu
13a0: 65 75 65 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 4c  eue);.}../*.** L
13b0: 6f 61 64 20 74 68 65 20 72 65 63 6f 72 64 20 49  oad the record I
13c0: 44 20 72 69 64 20 61 6e 64 20 75 70 20 74 6f 20  D rid and up to 
13d0: 4e 2d 31 20 63 6c 6f 73 65 73 74 20 64 65 73 63  N-1 closest desc
13e0: 65 6e 64 61 6e 74 73 20 69 6e 74 6f 0a 2a 2a 20  endants into.** 
13f0: 74 68 65 20 22 6f 6b 22 20 74 61 62 6c 65 2e 0a  the "ok" table..
1400: 2a 2f 0a 76 6f 69 64 20 63 6f 6d 70 75 74 65 5f  */.void compute_
1410: 64 65 73 63 65 6e 64 61 6e 74 73 28 69 6e 74 20  descendants(int 
1420: 72 69 64 2c 20 69 6e 74 20 4e 29 7b 0a 20 20 42  rid, int N){.  B
1430: 61 67 20 73 65 65 6e 3b 0a 20 20 50 51 75 65 75  ag seen;.  PQueu
1440: 65 20 71 75 65 75 65 3b 0a 20 20 62 61 67 5f 69  e queue;.  bag_i
1450: 6e 69 74 28 26 73 65 65 6e 29 3b 0a 20 20 70 71  nit(&seen);.  pq
1460: 75 65 75 65 5f 69 6e 69 74 28 26 71 75 65 75 65  ueue_init(&queue
1470: 29 3b 0a 20 20 62 61 67 5f 69 6e 73 65 72 74 28  );.  bag_insert(
1480: 26 73 65 65 6e 2c 20 72 69 64 29 3b 0a 20 20 70  &seen, rid);.  p
1490: 71 75 65 75 65 5f 69 6e 73 65 72 74 28 26 71 75  queue_insert(&qu
14a0: 65 75 65 2c 20 72 69 64 2c 20 30 2e 30 29 3b 0a  eue, rid, 0.0);.
14b0: 20 20 77 68 69 6c 65 28 20 28 4e 2d 2d 29 3e 30    while( (N--)>0
14c0: 20 26 26 20 28 72 69 64 20 3d 20 70 71 75 65 75   && (rid = pqueu
14d0: 65 5f 65 78 74 72 61 63 74 28 26 71 75 65 75 65  e_extract(&queue
14e0: 29 29 21 3d 30 20 29 7b 0a 20 20 20 20 53 74 6d  ))!=0 ){.    Stm
14f0: 74 20 71 3b 0a 20 20 20 20 64 62 5f 6d 75 6c 74  t q;.    db_mult
1500: 69 5f 65 78 65 63 28 22 49 4e 53 45 52 54 20 4f  i_exec("INSERT O
1510: 52 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 6f 6b  R IGNORE INTO ok
1520: 20 56 41 4c 55 45 53 28 25 64 29 22 2c 20 72 69   VALUES(%d)", ri
1530: 64 29 3b 0a 20 20 20 20 64 62 5f 70 72 65 70 61  d);.    db_prepa
1540: 72 65 28 26 71 2c 22 53 45 4c 45 43 54 20 63 69  re(&q,"SELECT ci
1550: 64 2c 20 6d 74 69 6d 65 20 46 52 4f 4d 20 70 6c  d, mtime FROM pl
1560: 69 6e 6b 20 57 48 45 52 45 20 70 69 64 3d 25 64  ink WHERE pid=%d
1570: 22 2c 20 72 69 64 29 3b 0a 20 20 20 20 77 68 69  ", rid);.    whi
1580: 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d  le( db_step(&q)=
1590: 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20  =SQLITE_ROW ){. 
15a0: 20 20 20 20 20 69 6e 74 20 70 69 64 20 3d 20 64       int pid = d
15b0: 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c  b_column_int(&q,
15c0: 20 30 29 3b 0a 20 20 20 20 20 20 64 6f 75 62 6c   0);.      doubl
15d0: 65 20 6d 74 69 6d 65 20 3d 20 64 62 5f 63 6f 6c  e mtime = db_col
15e0: 75 6d 6e 5f 64 6f 75 62 6c 65 28 26 71 2c 20 31  umn_double(&q, 1
15f0: 29 3b 0a 20 20 20 20 20 20 69 66 28 20 62 61 67  );.      if( bag
1600: 5f 69 6e 73 65 72 74 28 26 73 65 65 6e 2c 20 70  _insert(&seen, p
1610: 69 64 29 20 29 7b 0a 20 20 20 20 20 20 20 20 70  id) ){.        p
1620: 71 75 65 75 65 5f 69 6e 73 65 72 74 28 26 71 75  queue_insert(&qu
1630: 65 75 65 2c 20 70 69 64 2c 20 6d 74 69 6d 65 29  eue, pid, mtime)
1640: 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a  ;.      }.    }.
1650: 20 20 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28      db_finalize(
1660: 26 71 29 3b 0a 20 20 7d 0a 20 20 62 61 67 5f 63  &q);.  }.  bag_c
1670: 6c 65 61 72 28 26 73 65 65 6e 29 3b 0a 20 20 70  lear(&seen);.  p
1680: 71 75 65 75 65 5f 63 6c 65 61 72 28 26 71 75 65  queue_clear(&que
1690: 75 65 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f  ue);.}../*.** CO
16a0: 4d 4d 41 4e 44 3a 20 20 64 65 73 63 65 6e 64 61  MMAND:  descenda
16b0: 6e 74 73 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a  nts.**.** Usage:
16c0: 20 25 66 6f 73 73 69 6c 20 64 65 73 63 65 6e 64   %fossil descend
16d0: 61 6e 74 73 20 3f 42 41 53 45 4c 49 4e 45 2d 49  ants ?BASELINE-I
16e0: 44 3f 0a 2a 2a 0a 2a 2a 20 46 69 6e 64 20 61 6c  D?.**.** Find al
16f0: 6c 20 6c 65 61 66 20 64 65 73 63 65 6e 64 61 6e  l leaf descendan
1700: 74 73 20 6f 66 20 74 68 65 20 62 61 73 65 6c 69  ts of the baseli
1710: 6e 65 20 73 70 65 63 69 66 69 65 64 20 6f 72 20  ne specified or 
1720: 69 66 20 74 68 65 20 61 72 67 75 6d 65 6e 74 0a  if the argument.
1730: 2a 2a 20 69 73 20 6f 6d 69 74 74 65 64 2c 20 6f  ** is omitted, o
1740: 66 20 74 68 65 20 62 61 73 65 6c 69 6e 65 20 63  f the baseline c
1750: 75 72 72 65 6e 74 6c 79 20 63 68 65 63 6b 65 64  urrently checked
1760: 20 6f 75 74 2e 0a 2a 2f 0a 76 6f 69 64 20 64 65   out..*/.void de
1770: 73 63 65 6e 64 61 6e 74 73 5f 63 6d 64 28 76 6f  scendants_cmd(vo
1780: 69 64 29 7b 0a 20 20 53 74 6d 74 20 71 3b 0a 20  id){.  Stmt q;. 
1790: 20 69 6e 74 20 62 61 73 65 3b 0a 0a 20 20 64 62   int base;..  db
17a0: 5f 6d 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f  _must_be_within_
17b0: 74 72 65 65 28 29 3b 0a 20 20 69 66 28 20 67 2e  tree();.  if( g.
17c0: 61 72 67 63 3d 3d 32 20 29 7b 0a 20 20 20 20 62  argc==2 ){.    b
17d0: 61 73 65 20 3d 20 64 62 5f 6c 67 65 74 5f 69 6e  ase = db_lget_in
17e0: 74 28 22 63 68 65 63 6b 6f 75 74 22 2c 20 30 29  t("checkout", 0)
17f0: 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 62  ;.  }else{.    b
1800: 61 73 65 20 3d 20 6e 61 6d 65 5f 74 6f 5f 72 69  ase = name_to_ri
1810: 64 28 67 2e 61 72 67 76 5b 32 5d 29 3b 0a 20 20  d(g.argv[2]);.  
1820: 7d 0a 20 20 69 66 28 20 62 61 73 65 3d 3d 30 20  }.  if( base==0 
1830: 29 20 72 65 74 75 72 6e 3b 0a 20 20 63 6f 6d 70  ) return;.  comp
1840: 75 74 65 5f 6c 65 61 76 65 73 28 62 61 73 65 2c  ute_leaves(base,
1850: 20 30 29 3b 0a 20 20 64 62 5f 70 72 65 70 61 72   0);.  db_prepar
1860: 65 28 26 71 2c 0a 20 20 20 20 22 25 73 22 0a 20  e(&q,.    "%s". 
1870: 20 20 20 22 20 20 20 41 4e 44 20 65 76 65 6e 74     "   AND event
1880: 2e 6f 62 6a 69 64 20 49 4e 20 28 53 45 4c 45 43  .objid IN (SELEC
1890: 54 20 72 69 64 20 46 52 4f 4d 20 6c 65 61 76 65  T rid FROM leave
18a0: 73 29 22 0a 20 20 20 20 22 20 4f 52 44 45 52 20  s)".    " ORDER 
18b0: 42 59 20 65 76 65 6e 74 2e 6d 74 69 6d 65 20 44  BY event.mtime D
18c0: 45 53 43 22 2c 0a 20 20 20 20 74 69 6d 65 6c 69  ESC",.    timeli
18d0: 6e 65 5f 71 75 65 72 79 5f 66 6f 72 5f 74 74 79  ne_query_for_tty
18e0: 28 29 0a 20 20 29 3b 0a 20 20 70 72 69 6e 74 5f  ().  );.  print_
18f0: 74 69 6d 65 6c 69 6e 65 28 26 71 2c 20 32 30 29  timeline(&q, 20)
1900: 3b 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28  ;.  db_finalize(
1910: 26 71 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f  &q);.}../*.** CO
1920: 4d 4d 41 4e 44 3a 20 20 6c 65 61 76 65 73 0a 2a  MMAND:  leaves.*
1930: 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f 73  *.** Usage: %fos
1940: 73 69 6c 20 6c 65 61 76 65 73 20 3f 2d 2d 61 6c  sil leaves ?--al
1950: 6c 3f 20 3f 2d 2d 63 6c 6f 73 65 64 3f 0a 2a 2a  l? ?--closed?.**
1960: 0a 2a 2a 20 46 69 6e 64 20 6c 65 61 76 65 73 20  .** Find leaves 
1970: 6f 66 20 61 6c 6c 20 62 72 61 6e 63 68 65 73 2e  of all branches.
1980: 20 20 42 79 20 64 65 66 61 75 6c 74 20 73 68 6f    By default sho
1990: 77 20 6f 6e 6c 79 20 6f 70 65 6e 20 6c 65 61 76  w only open leav
19a0: 65 73 2e 0a 2a 2a 20 54 68 65 20 2d 2d 61 6c 6c  es..** The --all
19b0: 20 66 6c 61 67 20 63 61 75 73 65 73 20 61 6c 6c   flag causes all
19c0: 20 6c 65 61 76 65 73 20 28 63 6c 6f 73 65 64 20   leaves (closed 
19d0: 61 6e 64 20 6f 70 65 6e 29 20 74 6f 20 62 65 20  and open) to be 
19e0: 73 68 6f 77 6e 2e 0a 2a 2a 20 54 68 65 20 2d 2d  shown..** The --
19f0: 63 6c 6f 73 65 64 20 66 6c 61 67 20 73 68 6f 77  closed flag show
1a00: 73 20 6f 6e 6c 79 20 63 6c 6f 73 65 64 20 6c 65  s only closed le
1a10: 61 76 65 73 2e 0a 2a 2f 0a 76 6f 69 64 20 6c 65  aves..*/.void le
1a20: 61 76 65 73 5f 63 6d 64 28 76 6f 69 64 29 7b 0a  aves_cmd(void){.
1a30: 20 20 53 74 6d 74 20 71 3b 0a 20 20 69 6e 74 20    Stmt q;.  int 
1a40: 73 68 6f 77 41 6c 6c 20 3d 20 66 69 6e 64 5f 6f  showAll = find_o
1a50: 70 74 69 6f 6e 28 22 61 6c 6c 22 2c 20 30 2c 20  ption("all", 0, 
1a60: 30 29 21 3d 30 3b 0a 20 20 69 6e 74 20 73 68 6f  0)!=0;.  int sho
1a70: 77 43 6c 6f 73 65 64 20 3d 20 66 69 6e 64 5f 6f  wClosed = find_o
1a80: 70 74 69 6f 6e 28 22 63 6c 6f 73 65 64 22 2c 20  ption("closed", 
1a90: 30 2c 20 30 29 21 3d 30 3b 0a 0a 20 20 64 62 5f  0, 0)!=0;..  db_
1aa0: 6d 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74  must_be_within_t
1ab0: 72 65 65 28 29 3b 0a 20 20 63 6f 6d 70 75 74 65  ree();.  compute
1ac0: 5f 6c 65 61 76 65 73 28 30 2c 20 73 68 6f 77 41  _leaves(0, showA
1ad0: 6c 6c 20 3f 20 30 20 3a 20 73 68 6f 77 43 6c 6f  ll ? 0 : showClo
1ae0: 73 65 64 20 3f 20 32 20 3a 20 31 29 3b 0a 20 20  sed ? 2 : 1);.  
1af0: 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c 0a 20  db_prepare(&q,. 
1b00: 20 20 20 22 25 73 22 0a 20 20 20 20 22 20 20 20     "%s".    "   
1b10: 41 4e 44 20 62 6c 6f 62 2e 72 69 64 20 49 4e 20  AND blob.rid IN 
1b20: 6c 65 61 76 65 73 22 0a 20 20 20 20 22 20 4f 52  leaves".    " OR
1b30: 44 45 52 20 42 59 20 65 76 65 6e 74 2e 6d 74 69  DER BY event.mti
1b40: 6d 65 20 44 45 53 43 22 2c 0a 20 20 20 20 74 69  me DESC",.    ti
1b50: 6d 65 6c 69 6e 65 5f 71 75 65 72 79 5f 66 6f 72  meline_query_for
1b60: 5f 74 74 79 28 29 0a 20 20 29 3b 0a 20 20 70 72  _tty().  );.  pr
1b70: 69 6e 74 5f 74 69 6d 65 6c 69 6e 65 28 26 71 2c  int_timeline(&q,
1b80: 20 32 30 30 30 29 3b 0a 20 20 64 62 5f 66 69 6e   2000);.  db_fin
1b90: 61 6c 69 7a 65 28 26 71 29 3b 0a 7d 0a 0a 2f 2a  alize(&q);.}../*
1ba0: 0a 2a 2a 20 57 45 42 50 41 47 45 3a 20 20 6c 65  .** WEBPAGE:  le
1bb0: 61 76 65 73 0a 2a 2a 0a 2a 2a 20 46 69 6e 64 20  aves.**.** Find 
1bc0: 6c 65 61 76 65 73 20 6f 66 20 61 6c 6c 20 62 72  leaves of all br
1bd0: 61 6e 63 68 65 73 2e 0a 2a 2f 0a 76 6f 69 64 20  anches..*/.void 
1be0: 6c 65 61 76 65 73 5f 70 61 67 65 28 76 6f 69 64  leaves_page(void
1bf0: 29 7b 0a 20 20 53 74 6d 74 20 71 3b 0a 20 20 69  ){.  Stmt q;.  i
1c00: 6e 74 20 73 68 6f 77 41 6c 6c 20 3d 20 50 28 22  nt showAll = P("
1c10: 61 6c 6c 22 29 21 3d 30 3b 0a 20 20 69 6e 74 20  all")!=0;.  int 
1c20: 73 68 6f 77 43 6c 6f 73 65 64 20 3d 20 50 28 22  showClosed = P("
1c30: 63 6c 6f 73 65 64 22 29 21 3d 30 3b 0a 0a 20 20  closed")!=0;..  
1c40: 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f 63 72 65 64  login_check_cred
1c50: 65 6e 74 69 61 6c 73 28 29 3b 0a 20 20 69 66 28  entials();.  if(
1c60: 20 21 67 2e 6f 6b 52 65 61 64 20 29 7b 20 6c 6f   !g.okRead ){ lo
1c70: 67 69 6e 5f 6e 65 65 64 65 64 28 29 3b 20 72 65  gin_needed(); re
1c80: 74 75 72 6e 3b 20 7d 0a 0a 20 20 69 66 28 20 21  turn; }..  if( !
1c90: 73 68 6f 77 41 6c 6c 20 29 7b 0a 20 20 20 20 73  showAll ){.    s
1ca0: 74 79 6c 65 5f 73 75 62 6d 65 6e 75 5f 65 6c 65  tyle_submenu_ele
1cb0: 6d 65 6e 74 28 22 41 6c 6c 22 2c 20 22 41 6c 6c  ment("All", "All
1cc0: 22 2c 20 22 6c 65 61 76 65 73 3f 61 6c 6c 22 29  ", "leaves?all")
1cd0: 3b 0a 20 20 7d 0a 20 20 69 66 28 20 21 73 68 6f  ;.  }.  if( !sho
1ce0: 77 43 6c 6f 73 65 64 20 29 7b 0a 20 20 20 20 73  wClosed ){.    s
1cf0: 74 79 6c 65 5f 73 75 62 6d 65 6e 75 5f 65 6c 65  tyle_submenu_ele
1d00: 6d 65 6e 74 28 22 43 6c 6f 73 65 64 22 2c 20 22  ment("Closed", "
1d10: 43 6c 6f 73 65 64 22 2c 20 22 6c 65 61 76 65 73  Closed", "leaves
1d20: 3f 63 6c 6f 73 65 64 22 29 3b 0a 20 20 7d 0a 20  ?closed");.  }. 
1d30: 20 69 66 28 20 73 68 6f 77 43 6c 6f 73 65 64 20   if( showClosed 
1d40: 7c 7c 20 73 68 6f 77 41 6c 6c 20 29 7b 0a 20 20  || showAll ){.  
1d50: 20 20 73 74 79 6c 65 5f 73 75 62 6d 65 6e 75 5f    style_submenu_
1d60: 65 6c 65 6d 65 6e 74 28 22 4f 70 65 6e 22 2c 20  element("Open", 
1d70: 22 4f 70 65 6e 22 2c 20 22 6c 65 61 76 65 73 22  "Open", "leaves"
1d80: 29 3b 0a 20 20 7d 0a 20 20 73 74 79 6c 65 5f 68  );.  }.  style_h
1d90: 65 61 64 65 72 28 22 4c 65 61 76 65 73 22 29 3b  eader("Leaves");
1da0: 0a 20 20 6c 6f 67 69 6e 5f 61 6e 6f 6e 79 6d 6f  .  login_anonymo
1db0: 75 73 5f 61 76 61 69 6c 61 62 6c 65 28 29 3b 0a  us_available();.
1dc0: 20 20 63 6f 6d 70 75 74 65 5f 6c 65 61 76 65 73    compute_leaves
1dd0: 28 30 2c 20 73 68 6f 77 41 6c 6c 20 3f 20 30 20  (0, showAll ? 0 
1de0: 3a 20 73 68 6f 77 43 6c 6f 73 65 64 20 3f 20 32  : showClosed ? 2
1df0: 20 3a 20 31 29 3b 0a 20 20 69 66 28 20 73 68 6f   : 1);.  if( sho
1e00: 77 41 6c 6c 20 29 7b 0a 20 20 20 20 40 20 3c 68  wAll ){.    @ <h
1e10: 31 3e 41 6c 6c 20 6c 65 61 76 65 73 2c 20 62 6f  1>All leaves, bo
1e20: 74 68 20 6f 70 65 6e 20 61 6e 64 20 63 6c 6f 73  th open and clos
1e30: 65 64 3c 2f 68 31 3e 0a 20 20 7d 65 6c 73 65 20  ed</h1>.  }else 
1e40: 69 66 28 20 73 68 6f 77 43 6c 6f 73 65 64 20 29  if( showClosed )
1e50: 7b 0a 20 20 20 20 40 20 3c 68 31 3e 43 6c 6f 73  {.    @ <h1>Clos
1e60: 65 64 20 6c 65 61 76 65 73 20 6f 6e 6c 79 3c 2f  ed leaves only</
1e70: 68 31 3e 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20  h1>.  }else{.   
1e80: 20 40 20 3c 68 31 3e 41 6c 6c 20 6f 70 65 6e 20   @ <h1>All open 
1e90: 6c 65 61 76 65 73 3c 2f 68 31 3e 0a 20 20 7d 0a  leaves</h1>.  }.
1ea0: 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c    db_prepare(&q,
1eb0: 0a 20 20 20 20 22 25 73 22 0a 20 20 20 20 22 20  .    "%s".    " 
1ec0: 20 20 41 4e 44 20 62 6c 6f 62 2e 72 69 64 20 49    AND blob.rid I
1ed0: 4e 20 6c 65 61 76 65 73 22 0a 20 20 20 20 22 20  N leaves".    " 
1ee0: 4f 52 44 45 52 20 42 59 20 65 76 65 6e 74 2e 6d  ORDER BY event.m
1ef0: 74 69 6d 65 20 44 45 53 43 22 2c 0a 20 20 20 20  time DESC",.    
1f00: 74 69 6d 65 6c 69 6e 65 5f 71 75 65 72 79 5f 66  timeline_query_f
1f10: 6f 72 5f 77 77 77 28 29 0a 20 20 29 3b 0a 20 20  or_www().  );.  
1f20: 77 77 77 5f 70 72 69 6e 74 5f 74 69 6d 65 6c 69  www_print_timeli
1f30: 6e 65 28 26 71 29 3b 0a 20 20 64 62 5f 66 69 6e  ne(&q);.  db_fin
1f40: 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 40 20 3c  alize(&q);.  @ <
1f50: 73 63 72 69 70 74 3e 0a 20 20 40 20 66 75 6e 63  script>.  @ func
1f60: 74 69 6f 6e 20 78 69 6e 28 69 64 29 7b 0a 20 20  tion xin(id){.  
1f70: 40 20 7d 0a 20 20 40 20 66 75 6e 63 74 69 6f 6e  @ }.  @ function
1f80: 20 78 6f 75 74 28 69 64 29 7b 0a 20 20 40 20 7d   xout(id){.  @ }
1f90: 0a 20 20 40 20 3c 2f 73 63 72 69 70 74 3e 0a 20  .  @ </script>. 
1fa0: 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28 29 3b   style_footer();
1fb0: 0a 7d 0a                                         .}.