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 53 69 6d 70 6c 69 66 69 65 64 20 42 53 44 20 Simplified BSD
00a0: 4c 69 63 65 6e 73 65 20 28 61 6c 73 6f 0a 2a 2a License (also.**
00b0: 20 6b 6e 6f 77 6e 20 61 73 20 74 68 65 20 22 32 known as the "2
00c0: 2d 43 6c 61 75 73 65 20 4c 69 63 65 6e 73 65 22 -Clause License"
00d0: 20 6f 72 20 22 46 72 65 65 42 53 44 20 4c 69 63 or "FreeBSD Lic
00e0: 65 6e 73 65 22 2e 29 0a 0a 2a 2a 20 54 68 69 73 ense".)..** This
00f0: 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73 74 program is dist
0100: 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20 68 ributed in the h
0110: 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c 6c ope that it will
0120: 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20 62 be useful,.** b
0130: 75 74 20 77 69 74 68 6f 75 74 20 61 6e 79 20 77 ut without any w
0140: 61 72 72 61 6e 74 79 3b 20 77 69 74 68 6f 75 74 arranty; without
0150: 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69 65 even the implie
0160: 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a 2a d warranty of.**
0170: 20 6d 65 72 63 68 61 6e 74 61 62 69 6c 69 74 79 merchantability
0180: 20 6f 72 20 66 69 74 6e 65 73 73 20 66 6f 72 20 or fitness for
0190: 61 20 70 61 72 74 69 63 75 6c 61 72 20 70 75 72 a particular pur
01a0: 70 6f 73 65 2e 0a 2a 2a 0a 2a 2a 20 41 75 74 68 pose..**.** Auth
01b0: 6f 72 20 63 6f 6e 74 61 63 74 20 69 6e 66 6f 72 or contact infor
01c0: 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20 20 64 72 68 mation:.** drh
01d0: 40 68 77 61 63 69 2e 63 6f 6d 0a 2a 2a 20 20 20 @hwaci.com.**
01e0: 68 74 74 70 3a 2f 2f 77 77 77 2e 68 77 61 63 69 http://www.hwaci
01f0: 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a 0a 2a 2a 2a .com/drh/.**.***
0200: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0210: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0220: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0230: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0240: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 2a 2a 0a ************.**.
0250: 2a 2a 20 54 68 69 73 20 66 69 6c 65 20 63 6f 6e ** This file con
0260: 74 61 69 6e 73 20 63 6f 64 65 20 75 73 65 64 20 tains code used
0270: 74 6f 20 66 69 6e 64 20 64 65 73 63 65 6e 64 61 to find descenda
0280: 6e 74 73 20 6f 66 20 61 20 76 65 72 73 69 6f 6e nts of a version
0290: 0a 2a 2a 20 6f 72 20 6c 65 61 76 65 73 20 6f 66 .** or leaves of
02a0: 20 61 20 76 65 72 73 69 6f 6e 20 74 72 65 65 2e a version tree.
02b0: 0a 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22 63 6f .*/.#include "co
02c0: 6e 66 69 67 2e 68 22 0a 23 69 6e 63 6c 75 64 65 nfig.h".#include
02d0: 20 22 64 65 73 63 65 6e 64 61 6e 74 73 2e 68 22 "descendants.h"
02e0: 0a 23 69 6e 63 6c 75 64 65 20 3c 61 73 73 65 72 .#include <asser
02f0: 74 2e 68 3e 0a 0a 0a 2f 2a 0a 2a 2a 20 43 72 65 t.h>.../*.** Cre
0300: 61 74 65 20 61 20 74 65 6d 70 6f 72 61 72 79 20 ate a temporary
0310: 74 61 62 6c 65 20 6e 61 6d 65 64 20 22 6c 65 61 table named "lea
0320: 76 65 73 22 20 69 66 20 69 74 20 64 6f 65 73 20 ves" if it does
0330: 6e 6f 74 0a 2a 2a 20 61 6c 72 65 61 64 79 20 65 not.** already e
0340: 78 69 73 74 2e 20 20 4c 6f 61 64 20 74 68 69 73 xist. Load this
0350: 20 74 61 62 6c 65 20 77 69 74 68 20 74 68 65 20 table with the
0360: 52 49 44 20 6f 66 20 61 6c 6c 0a 2a 2a 20 63 68 RID of all.** ch
0370: 65 63 6b 2d 69 6e 73 20 74 68 61 74 20 61 72 65 eck-ins that are
0380: 20 6c 65 61 76 65 73 20 77 68 69 63 68 20 61 72 leaves which ar
0390: 65 20 64 65 73 63 65 6e 64 65 64 20 66 72 6f 6d e descended from
03a0: 0a 2a 2a 20 63 68 65 63 6b 2d 69 6e 20 69 42 61 .** check-in iBa
03b0: 73 65 2e 0a 2a 2a 0a 2a 2a 20 41 20 22 6c 65 61 se..**.** A "lea
03c0: 66 22 20 69 73 20 61 20 63 68 65 63 6b 2d 69 6e f" is a check-in
03d0: 20 74 68 61 74 20 68 61 73 20 6e 6f 20 63 68 69 that has no chi
03e0: 6c 64 72 65 6e 20 69 6e 20 74 68 65 20 73 61 6d ldren in the sam
03f0: 65 20 62 72 61 6e 63 68 2e 0a 2a 2a 20 54 68 65 e branch..** The
0400: 72 65 20 69 73 20 61 20 73 65 70 61 72 61 74 65 re is a separate
0410: 20 70 65 72 6d 61 6e 65 6e 74 20 74 61 62 6c 65 permanent table
0420: 20 4c 45 41 46 20 74 68 61 74 20 63 6f 6e 74 61 LEAF that conta
0430: 69 6e 73 20 61 6c 6c 20 6c 65 61 76 65 73 0a 2a ins all leaves.*
0440: 2a 20 69 6e 20 74 68 65 20 74 72 65 65 2e 20 20 * in the tree.
0450: 54 68 69 73 20 72 6f 75 74 69 6e 65 20 69 73 20 This routine is
0460: 75 73 65 64 20 74 6f 20 63 6f 6d 70 75 74 65 20 used to compute
0470: 61 20 73 75 62 73 65 74 20 6f 66 20 74 68 61 74 a subset of that
0480: 0a 2a 2a 20 74 61 62 6c 65 20 63 6f 6e 73 69 73 .** table consis
0490: 74 69 6e 67 20 6f 66 20 6c 65 61 76 65 73 20 74 ting of leaves t
04a0: 68 61 74 20 61 72 65 20 64 65 73 63 65 6e 64 65 hat are descende
04b0: 64 20 66 72 6f 6d 20 61 20 73 69 6e 67 6c 65 20 d from a single
04c0: 63 68 65 63 6b 2d 69 6e 2e 0a 2a 2a 0a 2a 2a 20 check-in..**.**
04d0: 54 68 65 20 63 6c 6f 73 65 4d 6f 64 65 20 66 6c The closeMode fl
04e0: 61 67 20 64 65 74 65 72 6d 69 6e 65 73 20 62 65 ag determines be
04f0: 68 61 76 69 6f 72 20 61 73 73 6f 63 69 61 74 65 havior associate
0500: 64 20 77 69 74 68 20 74 68 65 20 22 63 6c 6f 73 d with the "clos
0510: 65 64 22 0a 2a 2a 20 74 61 67 3a 0a 2a 2a 0a 2a ed".** tag:.**.*
0520: 2a 20 20 20 20 63 6c 6f 73 65 4d 6f 64 65 3d 3d * closeMode==
0530: 30 20 20 20 20 20 20 20 53 68 6f 77 20 61 6c 6c 0 Show all
0540: 20 6c 65 61 76 65 73 20 72 65 67 61 72 64 6c 65 leaves regardle
0550: 73 73 20 6f 66 20 74 68 65 20 22 63 6c 6f 73 65 ss of the "close
0560: 64 22 20 74 61 67 2e 0a 2a 2a 0a 2a 2a 20 20 20 d" tag..**.**
0570: 20 63 6c 6f 73 65 4d 6f 64 65 3d 3d 31 20 20 20 closeMode==1
0580: 20 20 20 20 53 68 6f 77 20 6f 6e 6c 79 20 6c 65 Show only le
0590: 61 76 65 73 20 77 69 74 68 6f 75 74 20 74 68 65 aves without the
05a0: 20 22 63 6c 6f 73 65 64 22 20 74 61 67 2e 0a 2a "closed" tag..*
05b0: 2a 0a 2a 2a 20 20 20 20 63 6c 6f 73 65 4d 6f 64 *.** closeMod
05c0: 65 3d 3d 32 20 20 20 20 20 20 20 53 68 6f 77 20 e==2 Show
05d0: 6f 6e 6c 79 20 6c 65 61 76 65 73 20 77 69 74 68 only leaves with
05e0: 20 74 68 65 20 22 63 6c 6f 73 65 64 22 20 74 61 the "closed" ta
05f0: 67 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 64 65 66 g..**.** The def
0600: 61 75 6c 74 20 62 65 68 61 76 69 6f 72 20 69 73 ault behavior is
0610: 20 74 6f 20 69 67 6e 6f 72 65 20 63 6c 6f 73 65 to ignore close
0620: 64 20 6c 65 61 76 65 73 20 28 63 6c 6f 73 65 4d d leaves (closeM
0630: 6f 64 65 3d 3d 30 29 2e 20 20 54 6f 0a 2a 2a 20 ode==0). To.**
0640: 53 68 6f 77 20 61 6c 6c 20 6c 65 61 76 65 73 2c Show all leaves,
0650: 20 75 73 65 20 63 6c 6f 73 65 4d 6f 64 65 3d 3d use closeMode==
0660: 31 2e 20 20 54 6f 20 73 68 6f 77 20 6f 6e 6c 79 1. To show only
0670: 20 63 6c 6f 73 65 64 20 6c 65 61 76 65 73 2c 20 closed leaves,
0680: 75 73 65 0a 2a 2a 20 63 6c 6f 73 65 4d 6f 64 65 use.** closeMode
0690: 3d 3d 32 2e 0a 2a 2f 0a 76 6f 69 64 20 63 6f 6d ==2..*/.void com
06a0: 70 75 74 65 5f 6c 65 61 76 65 73 28 69 6e 74 20 pute_leaves(int
06b0: 69 42 61 73 65 2c 20 69 6e 74 20 63 6c 6f 73 65 iBase, int close
06c0: 4d 6f 64 65 29 7b 0a 0a 20 20 2f 2a 20 43 72 65 Mode){.. /* Cre
06d0: 61 74 65 20 74 68 65 20 4c 45 41 56 45 53 20 74 ate the LEAVES t
06e0: 61 62 6c 65 20 69 66 20 69 74 20 64 6f 65 73 20 able if it does
06f0: 6e 6f 74 20 61 6c 72 65 61 64 79 20 65 78 69 73 not already exis
0700: 74 2e 20 20 4d 61 6b 65 20 73 75 72 65 0a 20 20 t. Make sure.
0710: 2a 2a 20 69 74 20 69 73 20 65 6d 70 74 79 2e 0a ** it is empty..
0720: 20 20 2a 2f 0a 20 20 64 62 5f 6d 75 6c 74 69 5f */. db_multi_
0730: 65 78 65 63 28 0a 20 20 20 20 22 43 52 45 41 54 exec(. "CREAT
0740: 45 20 54 45 4d 50 20 54 41 42 4c 45 20 49 46 20 E TEMP TABLE IF
0750: 4e 4f 54 20 45 58 49 53 54 53 20 6c 65 61 76 65 NOT EXISTS leave
0760: 73 28 22 0a 20 20 20 20 22 20 20 72 69 64 20 49 s(". " rid I
0770: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b NTEGER PRIMARY K
0780: 45 59 22 0a 20 20 20 20 22 29 3b 22 0a 20 20 20 EY". ");".
0790: 20 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 6c 65 "DELETE FROM le
07a0: 61 76 65 73 3b 22 0a 20 20 29 3b 0a 0a 20 20 69 aves;". );.. i
07b0: 66 28 20 69 42 61 73 65 3e 30 20 29 7b 0a 20 20 f( iBase>0 ){.
07c0: 20 20 42 61 67 20 73 65 65 6e 3b 20 20 20 20 20 Bag seen;
07d0: 2f 2a 20 44 65 73 63 65 6e 64 61 6e 74 73 20 73 /* Descendants s
07e0: 65 65 6e 20 2a 2f 0a 20 20 20 20 42 61 67 20 70 een */. Bag p
07f0: 65 6e 64 69 6e 67 3b 20 20 2f 2a 20 55 6e 70 72 ending; /* Unpr
0800: 6f 70 61 67 61 74 65 64 20 64 65 73 63 65 6e 64 opagated descend
0810: 61 6e 74 73 20 2a 2f 0a 20 20 20 20 53 74 6d 74 ants */. Stmt
0820: 20 71 31 3b 20 20 20 20 20 20 2f 2a 20 51 75 65 q1; /* Que
0830: 72 79 20 74 6f 20 66 69 6e 64 20 63 68 69 6c 64 ry to find child
0840: 72 65 6e 20 6f 66 20 61 20 63 68 65 63 6b 2d 69 ren of a check-i
0850: 6e 20 2a 2f 0a 20 20 20 20 53 74 6d 74 20 69 73 n */. Stmt is
0860: 42 72 3b 20 20 20 20 2f 2a 20 51 75 65 72 79 20 Br; /* Query
0870: 74 6f 20 63 68 65 63 6b 20 74 6f 20 73 65 65 20 to check to see
0880: 69 66 20 61 20 63 68 65 63 6b 2d 69 6e 20 73 74 if a check-in st
0890: 61 72 74 73 20 61 20 6e 65 77 20 62 72 61 6e 63 arts a new branc
08a0: 68 20 2a 2f 0a 20 20 20 20 53 74 6d 74 20 69 6e h */. Stmt in
08b0: 73 3b 20 20 20 20 20 2f 2a 20 49 4e 53 45 52 54 s; /* INSERT
08c0: 20 73 74 61 74 65 6d 65 6e 74 20 66 6f 72 20 61 statement for a
08d0: 20 6e 65 77 20 72 65 63 6f 72 64 20 2a 2f 0a 0a new record */..
08e0: 20 20 20 20 2f 2a 20 49 6e 69 74 69 61 6c 69 7a /* Initializ
08f0: 65 20 74 68 65 20 62 61 67 73 2e 20 2a 2f 0a 20 e the bags. */.
0900: 20 20 20 62 61 67 5f 69 6e 69 74 28 26 73 65 65 bag_init(&see
0910: 6e 29 3b 0a 20 20 20 20 62 61 67 5f 69 6e 69 74 n);. bag_init
0920: 28 26 70 65 6e 64 69 6e 67 29 3b 0a 20 20 20 20 (&pending);.
0930: 62 61 67 5f 69 6e 73 65 72 74 28 26 70 65 6e 64 bag_insert(&pend
0940: 69 6e 67 2c 20 69 42 61 73 65 29 3b 0a 0a 20 20 ing, iBase);..
0950: 20 20 2f 2a 20 54 68 69 73 20 71 75 65 72 79 20 /* This query
0960: 72 65 74 75 72 6e 73 20 61 6c 6c 20 6e 6f 6e 2d returns all non-
0970: 62 72 61 6e 63 68 2d 6d 65 72 67 65 20 63 68 69 branch-merge chi
0980: 6c 64 72 65 6e 20 6f 66 20 63 68 65 63 6b 2d 69 ldren of check-i
0990: 6e 20 3a 72 69 64 2e 0a 20 20 20 20 2a 2a 0a 20 n :rid.. **.
09a0: 20 20 20 2a 2a 20 49 66 20 61 20 63 68 69 6c 64 ** If a child
09b0: 20 69 73 20 61 20 6d 65 72 67 65 20 6f 66 20 61 is a merge of a
09c0: 20 66 6f 72 6b 20 77 69 74 68 69 6e 20 74 68 65 fork within the
09d0: 20 73 61 6d 65 20 62 72 61 6e 63 68 2c 20 69 74 same branch, it
09e0: 20 69 73 0a 20 20 20 20 2a 2a 20 72 65 74 75 72 is. ** retur
09f0: 6e 65 64 2e 20 20 4f 6e 6c 79 20 6d 65 72 67 65 ned. Only merge
0a00: 20 63 68 69 6c 64 72 65 6e 20 69 6e 20 64 69 66 children in dif
0a10: 66 65 72 65 6e 74 20 62 72 61 6e 63 68 65 73 20 ferent branches
0a20: 61 72 65 20 65 78 63 6c 75 64 65 64 2e 0a 20 20 are excluded..
0a30: 20 20 2a 2f 0a 20 20 20 20 64 62 5f 70 72 65 70 */. db_prep
0a40: 61 72 65 28 26 71 31 2c 0a 20 20 20 20 20 20 22 are(&q1,. "
0a50: 53 45 4c 45 43 54 20 63 69 64 20 46 52 4f 4d 20 SELECT cid FROM
0a60: 70 6c 69 6e 6b 22 0a 20 20 20 20 20 20 22 20 57 plink". " W
0a70: 48 45 52 45 20 70 69 64 3d 3a 72 69 64 22 0a 20 HERE pid=:rid".
0a80: 20 20 20 20 20 22 20 20 20 41 4e 44 20 28 69 73 " AND (is
0a90: 70 72 69 6d 22 0a 20 20 20 20 20 20 22 20 20 20 prim". "
0aa0: 20 20 20 20 20 4f 52 20 63 6f 61 6c 65 73 63 65 OR coalesce
0ab0: 28 28 53 45 4c 45 43 54 20 76 61 6c 75 65 20 46 ((SELECT value F
0ac0: 52 4f 4d 20 74 61 67 78 72 65 66 22 0a 20 20 20 ROM tagxref".
0ad0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0ae0: 20 20 20 20 20 22 20 20 20 57 48 45 52 45 20 74 " WHERE t
0af0: 61 67 69 64 3d 25 64 20 41 4e 44 20 72 69 64 3d agid=%d AND rid=
0b00: 70 6c 69 6e 6b 2e 70 69 64 29 2c 20 27 74 72 75 plink.pid), 'tru
0b10: 6e 6b 27 29 22 0a 20 20 20 20 20 20 20 20 20 20 nk')".
0b20: 20 20 20 20 20 20 20 22 3d 63 6f 61 6c 65 73 63 "=coalesc
0b30: 65 28 28 53 45 4c 45 43 54 20 76 61 6c 75 65 20 e((SELECT value
0b40: 46 52 4f 4d 20 74 61 67 78 72 65 66 22 0a 20 20 FROM tagxref".
0b50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0b60: 20 20 20 20 20 20 22 20 20 20 57 48 45 52 45 20 " WHERE
0b70: 74 61 67 69 64 3d 25 64 20 41 4e 44 20 72 69 64 tagid=%d AND rid
0b80: 3d 70 6c 69 6e 6b 2e 63 69 64 29 2c 20 27 74 72 =plink.cid), 'tr
0b90: 75 6e 6b 27 29 29 22 2c 0a 20 20 20 20 20 20 54 unk'))",. T
0ba0: 41 47 5f 42 52 41 4e 43 48 2c 20 54 41 47 5f 42 AG_BRANCH, TAG_B
0bb0: 52 41 4e 43 48 0a 20 20 20 20 29 3b 0a 0a 20 20 RANCH. );..
0bc0: 20 20 2f 2a 20 54 68 69 73 20 71 75 65 72 79 20 /* This query
0bd0: 72 65 74 75 72 6e 73 20 61 20 73 69 6e 67 6c 65 returns a single
0be0: 20 72 6f 77 20 69 66 20 63 68 65 63 6b 2d 69 6e row if check-in
0bf0: 20 3a 72 69 64 20 69 73 20 74 68 65 20 66 69 72 :rid is the fir
0c00: 73 74 0a 20 20 20 20 2a 2a 20 63 68 65 63 6b 2d st. ** check-
0c10: 69 6e 20 6f 66 20 61 20 6e 65 77 20 62 72 61 6e in of a new bran
0c20: 63 68 2e 0a 20 20 20 20 2a 2f 0a 20 20 20 20 64 ch.. */. d
0c30: 62 5f 70 72 65 70 61 72 65 28 26 69 73 42 72 2c b_prepare(&isBr,
0c40: 0a 20 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 . "SELECT
0c50: 31 20 46 52 4f 4d 20 74 61 67 78 72 65 66 22 0a 1 FROM tagxref".
0c60: 20 20 20 20 20 20 20 22 20 57 48 45 52 45 20 72 " WHERE r
0c70: 69 64 3d 3a 72 69 64 20 41 4e 44 20 74 61 67 69 id=:rid AND tagi
0c80: 64 3d 25 64 20 41 4e 44 20 74 61 67 74 79 70 65 d=%d AND tagtype
0c90: 3d 32 22 0a 20 20 20 20 20 20 20 22 20 20 20 41 =2". " A
0ca0: 4e 44 20 73 72 63 69 64 3e 30 22 2c 0a 20 20 20 ND srcid>0",.
0cb0: 20 20 20 20 54 41 47 5f 42 52 41 4e 43 48 0a 20 TAG_BRANCH.
0cc0: 20 20 20 29 3b 0a 0a 20 20 20 20 2f 2a 20 54 68 );.. /* Th
0cd0: 69 73 20 73 74 61 74 65 6d 65 6e 74 20 69 6e 73 is statement ins
0ce0: 65 72 74 73 20 63 68 65 63 6b 2d 69 6e 20 3a 72 erts check-in :r
0cf0: 69 64 20 69 6e 74 6f 20 74 68 65 20 4c 45 41 56 id into the LEAV
0d00: 45 53 20 74 61 62 6c 65 2e 0a 20 20 20 20 2a 2f ES table.. */
0d10: 0a 20 20 20 20 64 62 5f 70 72 65 70 61 72 65 28 . db_prepare(
0d20: 26 69 6e 73 2c 20 22 49 4e 53 45 52 54 20 4f 52 &ins, "INSERT OR
0d30: 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 6c 65 61 IGNORE INTO lea
0d40: 76 65 73 20 56 41 4c 55 45 53 28 3a 72 69 64 29 ves VALUES(:rid)
0d50: 22 29 3b 0a 0a 20 20 20 20 77 68 69 6c 65 28 20 ");.. while(
0d60: 62 61 67 5f 63 6f 75 6e 74 28 26 70 65 6e 64 69 bag_count(&pendi
0d70: 6e 67 29 20 29 7b 0a 20 20 20 20 20 20 69 6e 74 ng) ){. int
0d80: 20 72 69 64 20 3d 20 62 61 67 5f 66 69 72 73 74 rid = bag_first
0d90: 28 26 70 65 6e 64 69 6e 67 29 3b 0a 20 20 20 20 (&pending);.
0da0: 20 20 69 6e 74 20 63 6e 74 20 3d 20 30 3b 0a 20 int cnt = 0;.
0db0: 20 20 20 20 20 62 61 67 5f 72 65 6d 6f 76 65 28 bag_remove(
0dc0: 26 70 65 6e 64 69 6e 67 2c 20 72 69 64 29 3b 0a &pending, rid);.
0dd0: 20 20 20 20 20 20 64 62 5f 62 69 6e 64 5f 69 6e db_bind_in
0de0: 74 28 26 71 31 2c 20 22 3a 72 69 64 22 2c 20 72 t(&q1, ":rid", r
0df0: 69 64 29 3b 0a 20 20 20 20 20 20 77 68 69 6c 65 id);. while
0e00: 28 20 64 62 5f 73 74 65 70 28 26 71 31 29 3d 3d ( db_step(&q1)==
0e10: 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 SQLITE_ROW ){.
0e20: 20 20 20 20 20 20 69 6e 74 20 63 69 64 20 3d 20 int cid =
0e30: 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 db_column_int(&q
0e40: 31 2c 20 30 29 3b 0a 20 20 20 20 20 20 20 20 69 1, 0);. i
0e50: 66 28 20 62 61 67 5f 69 6e 73 65 72 74 28 26 73 f( bag_insert(&s
0e60: 65 65 6e 2c 20 63 69 64 29 20 29 7b 0a 20 20 20 een, cid) ){.
0e70: 20 20 20 20 20 20 20 62 61 67 5f 69 6e 73 65 72 bag_inser
0e80: 74 28 26 70 65 6e 64 69 6e 67 2c 20 63 69 64 29 t(&pending, cid)
0e90: 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 ;. }.
0ea0: 20 20 20 20 64 62 5f 62 69 6e 64 5f 69 6e 74 28 db_bind_int(
0eb0: 26 69 73 42 72 2c 20 22 3a 72 69 64 22 2c 20 63 &isBr, ":rid", c
0ec0: 69 64 29 3b 0a 20 20 20 20 20 20 20 20 69 66 28 id);. if(
0ed0: 20 64 62 5f 73 74 65 70 28 26 69 73 42 72 29 3d db_step(&isBr)=
0ee0: 3d 53 51 4c 49 54 45 5f 44 4f 4e 45 20 29 7b 0a =SQLITE_DONE ){.
0ef0: 20 20 20 20 20 20 20 20 20 20 63 6e 74 2b 2b 3b cnt++;
0f00: 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 . }.
0f10: 20 20 20 64 62 5f 72 65 73 65 74 28 26 69 73 42 db_reset(&isB
0f20: 72 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 r);. }.
0f30: 20 20 64 62 5f 72 65 73 65 74 28 26 71 31 29 3b db_reset(&q1);
0f40: 0a 20 20 20 20 20 20 69 66 28 20 63 6e 74 3d 3d . if( cnt==
0f50: 30 20 26 26 20 21 69 73 5f 61 5f 6c 65 61 66 28 0 && !is_a_leaf(
0f60: 72 69 64 29 20 29 7b 0a 20 20 20 20 20 20 20 20 rid) ){.
0f70: 63 6e 74 2b 2b 3b 0a 20 20 20 20 20 20 7d 0a 20 cnt++;. }.
0f80: 20 20 20 20 20 69 66 28 20 63 6e 74 3d 3d 30 20 if( cnt==0
0f90: 29 7b 0a 20 20 20 20 20 20 20 20 64 62 5f 62 69 ){. db_bi
0fa0: 6e 64 5f 69 6e 74 28 26 69 6e 73 2c 20 22 3a 72 nd_int(&ins, ":r
0fb0: 69 64 22 2c 20 72 69 64 29 3b 0a 20 20 20 20 20 id", rid);.
0fc0: 20 20 20 64 62 5f 73 74 65 70 28 26 69 6e 73 29 db_step(&ins)
0fd0: 3b 0a 20 20 20 20 20 20 20 20 64 62 5f 72 65 73 ;. db_res
0fe0: 65 74 28 26 69 6e 73 29 3b 0a 20 20 20 20 20 20 et(&ins);.
0ff0: 7d 0a 20 20 20 20 7d 0a 20 20 20 20 64 62 5f 66 }. }. db_f
1000: 69 6e 61 6c 69 7a 65 28 26 69 6e 73 29 3b 0a 20 inalize(&ins);.
1010: 20 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 db_finalize(&
1020: 69 73 42 72 29 3b 0a 20 20 20 20 64 62 5f 66 69 isBr);. db_fi
1030: 6e 61 6c 69 7a 65 28 26 71 31 29 3b 0a 20 20 20 nalize(&q1);.
1040: 20 62 61 67 5f 63 6c 65 61 72 28 26 70 65 6e 64 bag_clear(&pend
1050: 69 6e 67 29 3b 0a 20 20 20 20 62 61 67 5f 63 6c ing);. bag_cl
1060: 65 61 72 28 26 73 65 65 6e 29 3b 0a 20 20 7d 65 ear(&seen);. }e
1070: 6c 73 65 7b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 lse{. db_mult
1080: 69 5f 65 78 65 63 28 0a 20 20 20 20 20 20 22 49 i_exec(. "I
1090: 4e 53 45 52 54 20 49 4e 54 4f 20 6c 65 61 76 65 NSERT INTO leave
10a0: 73 22 0a 20 20 20 20 20 20 22 20 20 53 45 4c 45 s". " SELE
10b0: 43 54 20 6c 65 61 66 2e 72 69 64 20 46 52 4f 4d CT leaf.rid FROM
10c0: 20 6c 65 61 66 22 0a 20 20 20 20 29 3b 0a 20 20 leaf". );.
10d0: 7d 0a 20 20 69 66 28 20 63 6c 6f 73 65 4d 6f 64 }. if( closeMod
10e0: 65 3d 3d 31 20 29 7b 0a 20 20 20 20 64 62 5f 6d e==1 ){. db_m
10f0: 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 20 20 ulti_exec(.
1100: 20 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 6c 65 "DELETE FROM le
1110: 61 76 65 73 20 57 48 45 52 45 20 72 69 64 20 49 aves WHERE rid I
1120: 4e 22 0a 20 20 20 20 20 20 22 20 20 28 53 45 4c N". " (SEL
1130: 45 43 54 20 6c 65 61 76 65 73 2e 72 69 64 20 46 ECT leaves.rid F
1140: 52 4f 4d 20 6c 65 61 76 65 73 2c 20 74 61 67 78 ROM leaves, tagx
1150: 72 65 66 22 0a 20 20 20 20 20 20 22 20 20 20 20 ref". "
1160: 57 48 45 52 45 20 74 61 67 78 72 65 66 2e 72 69 WHERE tagxref.ri
1170: 64 3d 6c 65 61 76 65 73 2e 72 69 64 20 22 0a 20 d=leaves.rid ".
1180: 20 20 20 20 20 22 20 20 20 20 20 20 41 4e 44 20 " AND
1190: 74 61 67 78 72 65 66 2e 74 61 67 69 64 3d 25 64 tagxref.tagid=%d
11a0: 22 0a 20 20 20 20 20 20 22 20 20 20 20 20 20 41 ". " A
11b0: 4e 44 20 74 61 67 78 72 65 66 2e 74 61 67 74 79 ND tagxref.tagty
11c0: 70 65 3e 30 29 22 2c 0a 20 20 20 20 20 20 54 41 pe>0)",. TA
11d0: 47 5f 43 4c 4f 53 45 44 0a 20 20 20 20 29 3b 0a G_CLOSED. );.
11e0: 20 20 7d 65 6c 73 65 20 69 66 28 20 63 6c 6f 73 }else if( clos
11f0: 65 4d 6f 64 65 3d 3d 32 20 29 7b 0a 20 20 20 20 eMode==2 ){.
1200: 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 db_multi_exec(.
1210: 20 20 20 20 20 22 44 45 4c 45 54 45 20 46 52 4f "DELETE FRO
1220: 4d 20 6c 65 61 76 65 73 20 57 48 45 52 45 20 72 M leaves WHERE r
1230: 69 64 20 4e 4f 54 20 49 4e 22 0a 20 20 20 20 20 id NOT IN".
1240: 20 22 20 20 28 53 45 4c 45 43 54 20 6c 65 61 76 " (SELECT leav
1250: 65 73 2e 72 69 64 20 46 52 4f 4d 20 6c 65 61 76 es.rid FROM leav
1260: 65 73 2c 20 74 61 67 78 72 65 66 22 0a 20 20 20 es, tagxref".
1270: 20 20 20 22 20 20 20 20 57 48 45 52 45 20 74 61 " WHERE ta
1280: 67 78 72 65 66 2e 72 69 64 3d 6c 65 61 76 65 73 gxref.rid=leaves
1290: 2e 72 69 64 20 22 0a 20 20 20 20 20 20 22 20 20 .rid ". "
12a0: 20 20 20 20 41 4e 44 20 74 61 67 78 72 65 66 2e AND tagxref.
12b0: 74 61 67 69 64 3d 25 64 22 0a 20 20 20 20 20 20 tagid=%d".
12c0: 22 20 20 20 20 20 20 41 4e 44 20 74 61 67 78 72 " AND tagxr
12d0: 65 66 2e 74 61 67 74 79 70 65 3e 30 29 22 2c 0a ef.tagtype>0)",.
12e0: 20 20 20 20 20 20 54 41 47 5f 43 4c 4f 53 45 44 TAG_CLOSED
12f0: 0a 20 20 20 20 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f . );. }.}../
1300: 2a 0a 2a 2a 20 4c 6f 61 64 20 74 68 65 20 72 65 *.** Load the re
1310: 63 6f 72 64 20 49 44 20 72 69 64 20 61 6e 64 20 cord ID rid and
1320: 75 70 20 74 6f 20 4e 2d 31 20 63 6c 6f 73 65 73 up to N-1 closes
1330: 74 20 61 6e 63 65 73 74 6f 72 73 20 69 6e 74 6f t ancestors into
1340: 0a 2a 2a 20 74 68 65 20 22 6f 6b 22 20 74 61 62 .** the "ok" tab
1350: 6c 65 2e 0a 2a 2f 0a 76 6f 69 64 20 63 6f 6d 70 le..*/.void comp
1360: 75 74 65 5f 61 6e 63 65 73 74 6f 72 73 28 69 6e ute_ancestors(in
1370: 74 20 72 69 64 2c 20 69 6e 74 20 4e 2c 20 69 6e t rid, int N, in
1380: 74 20 64 69 72 65 63 74 4f 6e 6c 79 29 7b 0a 20 t directOnly){.
1390: 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a db_multi_exec(.
13a0: 20 20 20 20 22 57 49 54 48 20 52 45 43 55 52 53 "WITH RECURS
13b0: 49 56 45 20 22 0a 20 20 20 20 22 20 20 61 6e 63 IVE ". " anc
13c0: 65 73 74 6f 72 28 72 69 64 2c 20 6d 74 69 6d 65 estor(rid, mtime
13d0: 29 20 41 53 20 28 22 0a 20 20 20 20 22 20 20 20 ) AS (". "
13e0: 20 53 45 4c 45 43 54 20 25 64 2c 20 6d 74 69 6d SELECT %d, mtim
13f0: 65 20 46 52 4f 4d 20 65 76 65 6e 74 20 57 48 45 e FROM event WHE
1400: 52 45 20 6f 62 6a 69 64 3d 25 64 20 22 0a 20 20 RE objid=%d ".
1410: 20 20 22 20 20 20 20 55 4e 49 4f 4e 20 22 0a 20 " UNION ".
1420: 20 20 20 22 20 20 20 20 53 45 4c 45 43 54 20 70 " SELECT p
1430: 6c 69 6e 6b 2e 70 69 64 2c 20 65 76 65 6e 74 2e link.pid, event.
1440: 6d 74 69 6d 65 22 0a 20 20 20 20 22 20 20 20 20 mtime". "
1450: 20 20 46 52 4f 4d 20 61 6e 63 65 73 74 6f 72 2c FROM ancestor,
1460: 20 70 6c 69 6e 6b 2c 20 65 76 65 6e 74 22 0a 20 plink, event".
1470: 20 20 20 22 20 20 20 20 20 57 48 45 52 45 20 70 " WHERE p
1480: 6c 69 6e 6b 2e 63 69 64 3d 61 6e 63 65 73 74 6f link.cid=ancesto
1490: 72 2e 72 69 64 22 0a 20 20 20 20 22 20 20 20 20 r.rid". "
14a0: 20 20 20 41 4e 44 20 65 76 65 6e 74 2e 6f 62 6a AND event.obj
14b0: 69 64 3d 70 6c 69 6e 6b 2e 70 69 64 20 25 73 22 id=plink.pid %s"
14c0: 0a 20 20 20 20 22 20 20 20 20 20 4f 52 44 45 52 . " ORDER
14d0: 20 42 59 20 6d 74 69 6d 65 20 44 45 53 43 20 4c BY mtime DESC L
14e0: 49 4d 49 54 20 25 64 22 0a 20 20 20 20 22 20 20 IMIT %d". "
14f0: 29 22 0a 20 20 20 20 22 49 4e 53 45 52 54 20 49 )". "INSERT I
1500: 4e 54 4f 20 6f 6b 22 0a 20 20 20 20 22 20 20 53 NTO ok". " S
1510: 45 4c 45 43 54 20 72 69 64 20 46 52 4f 4d 20 61 ELECT rid FROM a
1520: 6e 63 65 73 74 6f 72 3b 22 2c 0a 20 20 20 20 72 ncestor;",. r
1530: 69 64 2c 20 72 69 64 2c 20 64 69 72 65 63 74 4f id, rid, directO
1540: 6e 6c 79 20 3f 20 22 41 4e 44 20 70 6c 69 6e 6b nly ? "AND plink
1550: 2e 69 73 50 72 69 6d 22 20 3a 20 22 22 2c 20 4e .isPrim" : "", N
1560: 0a 20 20 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 . );.}../*.** C
1570: 6f 6d 70 75 74 65 20 61 6c 6c 20 64 69 72 65 63 ompute all direc
1580: 74 20 61 6e 63 65 73 74 6f 72 73 20 28 6d 65 72 t ancestors (mer
1590: 67 65 20 61 6e 63 65 73 74 6f 72 73 20 64 6f 20 ge ancestors do
15a0: 6e 6f 74 20 63 6f 75 6e 74 29 0a 2a 2a 20 66 6f not count).** fo
15b0: 72 20 74 68 65 20 63 68 65 63 6b 2d 69 6e 20 72 r the check-in r
15c0: 69 64 20 61 6e 64 20 70 75 74 20 74 68 65 6d 20 id and put them
15d0: 69 6e 20 61 20 74 61 62 6c 65 20 6e 61 6d 65 64 in a table named
15e0: 20 22 61 6e 63 65 73 74 6f 72 22 2e 0a 2a 2a 20 "ancestor"..**
15f0: 4c 61 62 65 6c 20 65 61 63 68 20 67 65 6e 65 72 Label each gener
1600: 61 74 69 6f 6e 20 77 69 74 68 20 63 6f 6e 73 65 ation with conse
1610: 63 75 74 69 76 65 20 69 6e 74 65 67 65 72 73 20 cutive integers
1620: 67 6f 69 6e 67 20 62 61 63 6b 77 61 72 64 73 0a going backwards.
1630: 2a 2a 20 69 6e 20 74 69 6d 65 20 73 75 63 68 20 ** in time such
1640: 74 68 61 74 20 72 69 64 20 68 61 73 20 74 68 65 that rid has the
1650: 20 73 6d 61 6c 6c 65 73 74 20 67 65 6e 65 72 61 smallest genera
1660: 74 69 6f 6e 20 6e 75 6d 62 65 72 20 61 6e 64 20 tion number and
1670: 74 68 65 20 6f 6c 64 65 73 74 0a 2a 2a 20 64 69 the oldest.** di
1680: 72 65 63 74 20 61 6e 63 65 73 74 6f 72 20 61 73 rect ancestor as
1690: 20 74 68 65 20 6c 61 72 67 65 73 74 20 67 65 6e the largest gen
16a0: 65 72 61 74 69 6f 6e 20 6e 75 6d 62 65 72 2e 0a eration number..
16b0: 2a 2f 0a 76 6f 69 64 20 63 6f 6d 70 75 74 65 5f */.void compute_
16c0: 64 69 72 65 63 74 5f 61 6e 63 65 73 74 6f 72 73 direct_ancestors
16d0: 28 69 6e 74 20 72 69 64 29 7b 0a 20 20 64 62 5f (int rid){. db_
16e0: 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 20 multi_exec(.
16f0: 22 43 52 45 41 54 45 20 54 45 4d 50 20 54 41 42 "CREATE TEMP TAB
1700: 4c 45 20 49 46 20 4e 4f 54 20 45 58 49 53 54 53 LE IF NOT EXISTS
1710: 20 61 6e 63 65 73 74 6f 72 28 72 69 64 20 49 4e ancestor(rid IN
1720: 54 45 47 45 52 20 55 4e 49 51 55 45 20 4e 4f 54 TEGER UNIQUE NOT
1730: 20 4e 55 4c 4c 2c 22 0a 20 20 20 20 20 20 20 20 NULL,".
1740: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1750: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1760: 20 20 20 20 22 20 67 65 6e 65 72 61 74 69 6f 6e " generation
1770: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY
1780: 20 4b 45 59 29 3b 22 0a 20 20 20 20 22 44 45 4c KEY);". "DEL
1790: 45 54 45 20 46 52 4f 4d 20 61 6e 63 65 73 74 6f ETE FROM ancesto
17a0: 72 3b 22 0a 20 20 20 20 22 57 49 54 48 20 52 45 r;". "WITH RE
17b0: 43 55 52 53 49 56 45 20 67 28 78 2c 69 29 20 41 CURSIVE g(x,i) A
17c0: 53 20 28 22 0a 20 20 20 20 22 20 20 56 41 4c 55 S (". " VALU
17d0: 45 53 28 25 64 2c 31 29 22 0a 20 20 20 20 22 20 ES(%d,1)". "
17e0: 20 55 4e 49 4f 4e 20 41 4c 4c 22 0a 20 20 20 20 UNION ALL".
17f0: 22 20 20 53 45 4c 45 43 54 20 70 6c 69 6e 6b 2e " SELECT plink.
1800: 70 69 64 2c 20 67 2e 69 2b 31 20 46 52 4f 4d 20 pid, g.i+1 FROM
1810: 70 6c 69 6e 6b 2c 20 67 22 0a 20 20 20 20 22 20 plink, g". "
1820: 20 20 57 48 45 52 45 20 70 6c 69 6e 6b 2e 63 69 WHERE plink.ci
1830: 64 3d 67 2e 78 20 41 4e 44 20 70 6c 69 6e 6b 2e d=g.x AND plink.
1840: 69 73 70 72 69 6d 29 22 0a 20 20 20 20 22 49 4e isprim)". "IN
1850: 53 45 52 54 20 49 4e 54 4f 20 61 6e 63 65 73 74 SERT INTO ancest
1860: 6f 72 28 72 69 64 2c 67 65 6e 65 72 61 74 69 6f or(rid,generatio
1870: 6e 29 20 53 45 4c 45 43 54 20 78 2c 69 20 46 52 n) SELECT x,i FR
1880: 4f 4d 20 67 3b 22 2c 20 0a 20 20 20 20 72 69 64 OM g;", . rid
1890: 0a 20 20 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 . );.}../*.** C
18a0: 6f 6d 70 75 74 65 20 74 68 65 20 22 6d 74 69 6d ompute the "mtim
18b0: 65 22 20 6f 66 20 74 68 65 20 66 69 6c 65 20 67 e" of the file g
18c0: 69 76 65 6e 20 77 68 6f 73 65 20 62 6c 6f 62 2e iven whose blob.
18d0: 72 69 64 20 69 73 20 22 66 69 64 22 20 74 68 61 rid is "fid" tha
18e0: 74 0a 2a 2a 20 69 73 20 70 61 72 74 20 6f 66 20 t.** is part of
18f0: 63 68 65 63 6b 2d 69 6e 20 22 76 69 64 22 2e 20 check-in "vid".
1900: 20 54 68 65 20 6d 74 69 6d 65 20 77 69 6c 6c 20 The mtime will
1910: 62 65 20 74 68 65 20 6d 74 69 6d 65 20 6f 6e 20 be the mtime on
1920: 76 69 64 20 6f 72 0a 2a 2a 20 73 6f 6d 65 20 61 vid or.** some a
1930: 6e 63 65 73 74 6f 72 20 6f 66 20 76 69 64 20 77 ncestor of vid w
1940: 68 65 72 65 20 66 69 64 20 66 69 72 73 74 20 61 here fid first a
1950: 70 70 65 61 72 73 2e 0a 2a 2f 0a 69 6e 74 20 6d ppears..*/.int m
1960: 74 69 6d 65 5f 6f 66 5f 6d 61 6e 69 66 65 73 74 time_of_manifest
1970: 5f 66 69 6c 65 28 0a 20 20 69 6e 74 20 76 69 64 _file(. int vid
1980: 2c 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 63 , /* The c
1990: 68 65 63 6b 2d 69 6e 20 74 68 61 74 20 63 6f 6e heck-in that con
19a0: 74 61 69 6e 73 20 66 69 64 20 2a 2f 0a 20 20 69 tains fid */. i
19b0: 6e 74 20 66 69 64 2c 20 20 20 20 20 20 20 2f 2a nt fid, /*
19c0: 20 54 68 65 20 69 64 20 6f 66 20 74 68 65 20 66 The id of the f
19d0: 69 6c 65 20 77 68 6f 73 65 20 63 68 65 63 6b 2d ile whose check-
19e0: 69 6e 20 74 69 6d 65 20 69 73 20 73 6f 75 67 68 in time is sough
19f0: 74 20 2a 2f 0a 20 20 69 36 34 20 2a 70 4d 54 69 t */. i64 *pMTi
1a00: 6d 65 20 20 20 20 2f 2a 20 57 72 69 74 65 20 72 me /* Write r
1a10: 65 73 75 6c 74 20 68 65 72 65 20 2a 2f 0a 29 7b esult here */.){
1a20: 0a 20 20 73 74 61 74 69 63 20 69 6e 74 20 70 72 . static int pr
1a30: 65 76 56 69 64 20 3d 20 2d 31 3b 0a 20 20 73 74 evVid = -1;. st
1a40: 61 74 69 63 20 53 74 6d 74 20 71 3b 0a 0a 20 20 atic Stmt q;..
1a50: 69 66 28 20 70 72 65 76 56 69 64 21 3d 76 69 64 if( prevVid!=vid
1a60: 20 29 7b 0a 20 20 20 20 70 72 65 76 56 69 64 20 ){. prevVid
1a70: 3d 20 76 69 64 3b 0a 20 20 20 20 64 62 5f 6d 75 = vid;. db_mu
1a80: 6c 74 69 5f 65 78 65 63 28 22 44 52 4f 50 20 54 lti_exec("DROP T
1a90: 41 42 4c 45 20 49 46 20 45 58 49 53 54 53 20 74 ABLE IF EXISTS t
1aa0: 65 6d 70 2e 6f 6b 3b 22 0a 20 20 20 20 20 20 20 emp.ok;".
1ab0: 20 20 20 20 20 20 20 20 20 20 20 22 43 52 45 41 "CREA
1ac0: 54 45 20 54 45 4d 50 20 54 41 42 4c 45 20 6f 6b TE TEMP TABLE ok
1ad0: 28 78 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 (x INTEGER PRIMA
1ae0: 52 59 20 4b 45 59 29 3b 22 29 3b 0a 20 20 20 20 RY KEY);");.
1af0: 63 6f 6d 70 75 74 65 5f 61 6e 63 65 73 74 6f 72 compute_ancestor
1b00: 73 28 76 69 64 2c 20 31 30 30 30 30 30 30 30 30 s(vid, 100000000
1b10: 2c 20 31 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 73 , 1);. }. db_s
1b20: 74 61 74 69 63 5f 70 72 65 70 61 72 65 28 26 71 tatic_prepare(&q
1b30: 2c 0a 20 20 20 20 22 53 45 4c 45 43 54 20 28 6d ,. "SELECT (m
1b40: 61 78 28 65 76 65 6e 74 2e 6d 74 69 6d 65 29 2d ax(event.mtime)-
1b50: 32 34 34 30 35 38 37 2e 35 29 2a 38 36 34 30 30 2440587.5)*86400
1b60: 20 46 52 4f 4d 20 6d 6c 69 6e 6b 2c 20 65 76 65 FROM mlink, eve
1b70: 6e 74 22 0a 20 20 20 20 22 20 57 48 45 52 45 20 nt". " WHERE
1b80: 6d 6c 69 6e 6b 2e 6d 69 64 3d 65 76 65 6e 74 2e mlink.mid=event.
1b90: 6f 62 6a 69 64 22 0a 20 20 20 20 22 20 20 20 41 objid". " A
1ba0: 4e 44 20 2b 6d 6c 69 6e 6b 2e 6d 69 64 20 49 4e ND +mlink.mid IN
1bb0: 20 6f 6b 22 0a 20 20 20 20 22 20 20 20 41 4e 44 ok". " AND
1bc0: 20 6d 6c 69 6e 6b 2e 66 69 64 3d 3a 66 69 64 22 mlink.fid=:fid"
1bd0: 29 3b 0a 20 20 64 62 5f 62 69 6e 64 5f 69 6e 74 );. db_bind_int
1be0: 28 26 71 2c 20 22 3a 66 69 64 22 2c 20 66 69 64 (&q, ":fid", fid
1bf0: 29 3b 0a 20 20 69 66 28 20 64 62 5f 73 74 65 70 );. if( db_step
1c00: 28 26 71 29 21 3d 53 51 4c 49 54 45 5f 52 4f 57 (&q)!=SQLITE_ROW
1c10: 20 29 7b 0a 20 20 20 20 64 62 5f 72 65 73 65 74 ){. db_reset
1c20: 28 26 71 29 3b 0a 20 20 20 20 72 65 74 75 72 6e (&q);. return
1c30: 20 31 3b 0a 20 20 7d 0a 20 20 2a 70 4d 54 69 6d 1;. }. *pMTim
1c40: 65 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e e = db_column_in
1c50: 74 36 34 28 26 71 2c 20 30 29 3b 0a 20 20 64 62 t64(&q, 0);. db
1c60: 5f 72 65 73 65 74 28 26 71 29 3b 0a 20 20 72 65 _reset(&q);. re
1c70: 74 75 72 6e 20 30 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a turn 0;.}../*.**
1c80: 20 4c 6f 61 64 20 74 68 65 20 72 65 63 6f 72 64 Load the record
1c90: 20 49 44 20 72 69 64 20 61 6e 64 20 75 70 20 74 ID rid and up t
1ca0: 6f 20 4e 2d 31 20 63 6c 6f 73 65 73 74 20 64 65 o N-1 closest de
1cb0: 73 63 65 6e 64 61 6e 74 73 20 69 6e 74 6f 0a 2a scendants into.*
1cc0: 2a 20 74 68 65 20 22 6f 6b 22 20 74 61 62 6c 65 * the "ok" table
1cd0: 2e 0a 2a 2f 0a 76 6f 69 64 20 63 6f 6d 70 75 74 ..*/.void comput
1ce0: 65 5f 64 65 73 63 65 6e 64 61 6e 74 73 28 69 6e e_descendants(in
1cf0: 74 20 72 69 64 2c 20 69 6e 74 20 4e 29 7b 0a 20 t rid, int N){.
1d00: 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a db_multi_exec(.
1d10: 20 20 20 20 22 57 49 54 48 20 52 45 43 55 52 53 "WITH RECURS
1d20: 49 56 45 22 0a 20 20 20 20 22 20 20 64 78 28 72 IVE". " dx(r
1d30: 69 64 2c 6d 74 69 6d 65 29 20 41 53 20 28 22 0a id,mtime) AS (".
1d40: 20 20 20 20 22 20 20 20 20 20 53 45 4c 45 43 54 " SELECT
1d50: 20 25 64 2c 20 30 22 0a 20 20 20 20 22 20 20 20 %d, 0". "
1d60: 20 20 55 4e 49 4f 4e 22 0a 20 20 20 20 22 20 20 UNION". "
1d70: 20 20 20 53 45 4c 45 43 54 20 70 6c 69 6e 6b 2e SELECT plink.
1d80: 63 69 64 2c 20 70 6c 69 6e 6b 2e 6d 74 69 6d 65 cid, plink.mtime
1d90: 20 46 52 4f 4d 20 64 78 2c 20 70 6c 69 6e 6b 22 FROM dx, plink"
1da0: 0a 20 20 20 20 22 20 20 20 20 20 20 57 48 45 52 . " WHER
1db0: 45 20 70 6c 69 6e 6b 2e 70 69 64 3d 64 78 2e 72 E plink.pid=dx.r
1dc0: 69 64 22 0a 20 20 20 20 22 20 20 20 20 20 20 4f id". " O
1dd0: 52 44 45 52 20 42 59 20 32 22 0a 20 20 20 20 22 RDER BY 2". "
1de0: 20 20 29 22 0a 20 20 20 20 22 49 4e 53 45 52 54 )". "INSERT
1df0: 20 4f 52 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 OR IGNORE INTO
1e00: 6f 6b 20 53 45 4c 45 43 54 20 72 69 64 20 46 52 ok SELECT rid FR
1e10: 4f 4d 20 64 78 20 4c 49 4d 49 54 20 25 64 22 2c OM dx LIMIT %d",
1e20: 0a 20 20 20 20 72 69 64 2c 20 4e 0a 20 20 29 3b . rid, N. );
1e30: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e .}../*.** COMMAN
1e40: 44 3a 20 64 65 73 63 65 6e 64 61 6e 74 73 2a 0a D: descendants*.
1e50: 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f **.** Usage: %fo
1e60: 73 73 69 6c 20 64 65 73 63 65 6e 64 61 6e 74 73 ssil descendants
1e70: 20 3f 43 48 45 43 4b 49 4e 3f 20 3f 4f 50 54 49 ?CHECKIN? ?OPTI
1e80: 4f 4e 53 3f 0a 2a 2a 0a 2a 2a 20 46 69 6e 64 20 ONS?.**.** Find
1e90: 61 6c 6c 20 6c 65 61 66 20 64 65 73 63 65 6e 64 all leaf descend
1ea0: 61 6e 74 73 20 6f 66 20 74 68 65 20 63 68 65 63 ants of the chec
1eb0: 6b 2d 69 6e 20 73 70 65 63 69 66 69 65 64 20 6f k-in specified o
1ec0: 72 20 69 66 20 74 68 65 20 61 72 67 75 6d 65 6e r if the argumen
1ed0: 74 0a 2a 2a 20 69 73 20 6f 6d 69 74 74 65 64 2c t.** is omitted,
1ee0: 20 6f 66 20 74 68 65 20 63 68 65 63 6b 2d 69 6e of the check-in
1ef0: 20 63 75 72 72 65 6e 74 6c 79 20 63 68 65 63 6b currently check
1f00: 65 64 20 6f 75 74 2e 0a 2a 2a 0a 2a 2a 20 4f 70 ed out..**.** Op
1f10: 74 69 6f 6e 73 3a 0a 2a 2a 20 20 20 20 2d 52 7c tions:.** -R|
1f20: 2d 2d 72 65 70 6f 73 69 74 6f 72 79 20 46 49 4c --repository FIL
1f30: 45 20 20 20 20 20 20 20 45 78 74 72 61 63 74 20 E Extract
1f40: 69 6e 66 6f 20 66 72 6f 6d 20 72 65 70 6f 73 69 info from reposi
1f50: 74 6f 72 79 20 46 49 4c 45 0a 2a 2a 20 20 20 20 tory FILE.**
1f60: 2d 57 7c 2d 2d 77 69 64 74 68 20 3c 6e 75 6d 3e -W|--width <num>
1f70: 20 20 20 20 20 20 20 20 20 20 20 57 69 64 74 68 Width
1f80: 20 6f 66 20 6c 69 6e 65 73 20 28 64 65 66 61 75 of lines (defau
1f90: 6c 74 20 69 73 20 74 6f 20 61 75 74 6f 2d 64 65 lt is to auto-de
1fa0: 74 65 63 74 29 2e 0a 2a 2a 20 20 20 20 20 20 20 tect)..**
1fb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fc0: 20 20 20 20 20 20 20 20 4d 75 73 74 20 62 65 20 Must be
1fd0: 3e 32 30 20 6f 72 20 30 20 28 3d 20 6e 6f 20 6c >20 or 0 (= no l
1fe0: 69 6d 69 74 2c 20 72 65 73 75 6c 74 69 6e 67 20 imit, resulting
1ff0: 69 6e 20 61 0a 2a 2a 20 20 20 20 20 20 20 20 20 in a.**
2000: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2010: 20 20 20 20 20 20 73 69 6e 67 6c 65 20 6c 69 6e single lin
2020: 65 20 70 65 72 20 65 6e 74 72 79 29 2e 0a 2a 2a e per entry)..**
2030: 0a 2a 2a 20 53 65 65 20 61 6c 73 6f 3a 20 66 69 .** See also: fi
2040: 6e 66 6f 2c 20 69 6e 66 6f 2c 20 6c 65 61 76 65 nfo, info, leave
2050: 73 0a 2a 2f 0a 76 6f 69 64 20 64 65 73 63 65 6e s.*/.void descen
2060: 64 61 6e 74 73 5f 63 6d 64 28 76 6f 69 64 29 7b dants_cmd(void){
2070: 0a 20 20 53 74 6d 74 20 71 3b 0a 20 20 69 6e 74 . Stmt q;. int
2080: 20 62 61 73 65 2c 20 77 69 64 74 68 3b 0a 20 20 base, width;.
2090: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 57 69 64 const char *zWid
20a0: 74 68 3b 0a 0a 20 20 64 62 5f 66 69 6e 64 5f 61 th;.. db_find_a
20b0: 6e 64 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f nd_open_reposito
20c0: 72 79 28 30 2c 30 29 3b 0a 20 20 7a 57 69 64 74 ry(0,0);. zWidt
20d0: 68 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 h = find_option(
20e0: 22 77 69 64 74 68 22 2c 22 57 22 2c 31 29 3b 0a "width","W",1);.
20f0: 20 20 69 66 28 20 7a 57 69 64 74 68 20 29 7b 0a if( zWidth ){.
2100: 20 20 20 20 77 69 64 74 68 20 3d 20 61 74 6f 69 width = atoi
2110: 28 7a 57 69 64 74 68 29 3b 0a 20 20 20 20 69 66 (zWidth);. if
2120: 28 20 28 77 69 64 74 68 21 3d 30 29 20 26 26 20 ( (width!=0) &&
2130: 28 77 69 64 74 68 3c 3d 32 30 29 20 29 7b 0a 20 (width<=20) ){.
2140: 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 fossil_fata
2150: 6c 28 22 2d 57 7c 2d 2d 77 69 64 74 68 20 76 61 l("-W|--width va
2160: 6c 75 65 20 6d 75 73 74 20 62 65 20 3e 32 30 20 lue must be >20
2170: 6f 72 20 30 22 29 3b 0a 20 20 20 20 7d 0a 20 20 or 0");. }.
2180: 7d 65 6c 73 65 7b 0a 20 20 20 20 77 69 64 74 68 }else{. width
2190: 20 3d 20 2d 31 3b 0a 20 20 7d 0a 0a 20 20 2f 2a = -1;. }.. /*
21a0: 20 57 65 20 73 68 6f 75 6c 64 20 62 65 20 64 6f We should be do
21b0: 6e 65 20 77 69 74 68 20 6f 70 74 69 6f 6e 73 2e ne with options.
21c0: 2e 20 2a 2f 0a 20 20 76 65 72 69 66 79 5f 61 6c . */. verify_al
21d0: 6c 5f 6f 70 74 69 6f 6e 73 28 29 3b 0a 0a 20 20 l_options();..
21e0: 69 66 28 20 67 2e 61 72 67 63 3d 3d 32 20 29 7b if( g.argc==2 ){
21f0: 0a 20 20 20 20 62 61 73 65 20 3d 20 64 62 5f 6c . base = db_l
2200: 67 65 74 5f 69 6e 74 28 22 63 68 65 63 6b 6f 75 get_int("checkou
2210: 74 22 2c 20 30 29 3b 0a 20 20 7d 65 6c 73 65 7b t", 0);. }else{
2220: 0a 20 20 20 20 62 61 73 65 20 3d 20 6e 61 6d 65 . base = name
2230: 5f 74 6f 5f 74 79 70 65 64 5f 72 69 64 28 67 2e _to_typed_rid(g.
2240: 61 72 67 76 5b 32 5d 2c 20 22 63 69 22 29 3b 0a argv[2], "ci");.
2250: 20 20 7d 0a 20 20 69 66 28 20 62 61 73 65 3d 3d }. if( base==
2260: 30 20 29 20 72 65 74 75 72 6e 3b 0a 20 20 63 6f 0 ) return;. co
2270: 6d 70 75 74 65 5f 6c 65 61 76 65 73 28 62 61 73 mpute_leaves(bas
2280: 65 2c 20 30 29 3b 0a 20 20 64 62 5f 70 72 65 70 e, 0);. db_prep
2290: 61 72 65 28 26 71 2c 0a 20 20 20 20 22 25 73 22 are(&q,. "%s"
22a0: 0a 20 20 20 20 22 20 20 20 41 4e 44 20 65 76 65 . " AND eve
22b0: 6e 74 2e 6f 62 6a 69 64 20 49 4e 20 28 53 45 4c nt.objid IN (SEL
22c0: 45 43 54 20 72 69 64 20 46 52 4f 4d 20 6c 65 61 ECT rid FROM lea
22d0: 76 65 73 29 22 0a 20 20 20 20 22 20 4f 52 44 45 ves)". " ORDE
22e0: 52 20 42 59 20 65 76 65 6e 74 2e 6d 74 69 6d 65 R BY event.mtime
22f0: 20 44 45 53 43 22 2c 0a 20 20 20 20 74 69 6d 65 DESC",. time
2300: 6c 69 6e 65 5f 71 75 65 72 79 5f 66 6f 72 5f 74 line_query_for_t
2310: 74 79 28 29 0a 20 20 29 3b 0a 20 20 70 72 69 6e ty(). );. prin
2320: 74 5f 74 69 6d 65 6c 69 6e 65 28 26 71 2c 20 30 t_timeline(&q, 0
2330: 2c 20 77 69 64 74 68 2c 20 30 29 3b 0a 20 20 64 , width, 0);. d
2340: 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a b_finalize(&q);.
2350: 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 }../*.** COMMAND
2360: 3a 20 6c 65 61 76 65 73 2a 0a 2a 2a 0a 2a 2a 20 : leaves*.**.**
2370: 55 73 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 6c Usage: %fossil l
2380: 65 61 76 65 73 20 3f 4f 50 54 49 4f 4e 53 3f 0a eaves ?OPTIONS?.
2390: 2a 2a 0a 2a 2a 20 46 69 6e 64 20 6c 65 61 76 65 **.** Find leave
23a0: 73 20 6f 66 20 61 6c 6c 20 62 72 61 6e 63 68 65 s of all branche
23b0: 73 2e 20 20 42 79 20 64 65 66 61 75 6c 74 20 73 s. By default s
23c0: 68 6f 77 20 6f 6e 6c 79 20 6f 70 65 6e 20 6c 65 how only open le
23d0: 61 76 65 73 2e 0a 2a 2a 20 54 68 65 20 2d 61 7c aves..** The -a|
23e0: 2d 2d 61 6c 6c 20 66 6c 61 67 20 63 61 75 73 65 --all flag cause
23f0: 73 20 61 6c 6c 20 6c 65 61 76 65 73 20 28 63 6c s all leaves (cl
2400: 6f 73 65 64 20 61 6e 64 20 6f 70 65 6e 29 20 74 osed and open) t
2410: 6f 20 62 65 20 73 68 6f 77 6e 2e 0a 2a 2a 20 54 o be shown..** T
2420: 68 65 20 2d 63 7c 2d 2d 63 6c 6f 73 65 64 20 66 he -c|--closed f
2430: 6c 61 67 20 73 68 6f 77 73 20 6f 6e 6c 79 20 63 lag shows only c
2440: 6c 6f 73 65 64 20 6c 65 61 76 65 73 2e 0a 2a 2a losed leaves..**
2450: 0a 2a 2a 20 54 68 65 20 2d 2d 72 65 63 6f 6d 70 .** The --recomp
2460: 75 74 65 20 66 6c 61 67 20 63 61 75 73 65 73 20 ute flag causes
2470: 74 68 65 20 63 6f 6e 74 65 6e 74 20 6f 66 20 74 the content of t
2480: 68 65 20 22 6c 65 61 66 22 20 74 61 62 6c 65 20 he "leaf" table
2490: 69 6e 20 74 68 65 0a 2a 2a 20 72 65 70 6f 73 69 in the.** reposi
24a0: 74 6f 72 79 20 64 61 74 61 62 61 73 65 20 74 6f tory database to
24b0: 20 62 65 20 72 65 63 6f 6d 70 75 74 65 64 2e 0a be recomputed..
24c0: 2a 2a 0a 2a 2a 20 4f 70 74 69 6f 6e 73 3a 0a 2a **.** Options:.*
24d0: 2a 20 20 20 2d 61 7c 2d 2d 61 6c 6c 20 20 20 20 * -a|--all
24e0: 20 20 20 20 20 73 68 6f 77 20 41 4c 4c 20 6c 65 show ALL le
24f0: 61 76 65 73 0a 2a 2a 20 20 20 2d 2d 62 79 62 72 aves.** --bybr
2500: 61 6e 63 68 20 20 20 20 20 20 20 6f 72 64 65 72 anch order
2510: 20 6f 75 74 70 75 74 20 62 79 20 62 72 61 6e 63 output by branc
2520: 68 20 6e 61 6d 65 0a 2a 2a 20 20 20 2d 63 7c 2d h name.** -c|-
2530: 2d 63 6c 6f 73 65 64 20 20 20 20 20 20 73 68 6f -closed sho
2540: 77 20 6f 6e 6c 79 20 63 6c 6f 73 65 64 20 6c 65 w only closed le
2550: 61 76 65 73 0a 2a 2a 20 20 20 2d 6d 7c 2d 2d 6d aves.** -m|--m
2560: 75 6c 74 69 70 6c 65 20 20 20 20 73 68 6f 77 20 ultiple show
2570: 6f 6e 6c 79 20 63 61 73 65 73 20 77 69 74 68 20 only cases with
2580: 6d 75 6c 74 69 70 6c 65 20 6c 65 61 76 65 73 20 multiple leaves
2590: 6f 6e 20 61 20 73 69 6e 67 6c 65 20 62 72 61 6e on a single bran
25a0: 63 68 0a 2a 2a 20 20 20 2d 2d 72 65 63 6f 6d 70 ch.** --recomp
25b0: 75 74 65 20 20 20 20 20 20 72 65 63 6f 6d 70 75 ute recompu
25c0: 74 65 20 74 68 65 20 22 6c 65 61 66 22 20 74 61 te the "leaf" ta
25d0: 62 6c 65 20 69 6e 20 74 68 65 20 72 65 70 6f 73 ble in the repos
25e0: 69 74 6f 72 79 20 44 42 0a 2a 2a 20 20 20 2d 57 itory DB.** -W
25f0: 7c 2d 2d 77 69 64 74 68 20 3c 6e 75 6d 3e 20 57 |--width <num> W
2600: 69 64 74 68 20 6f 66 20 6c 69 6e 65 73 20 28 64 idth of lines (d
2610: 65 66 61 75 6c 74 20 69 73 20 74 6f 20 61 75 74 efault is to aut
2620: 6f 2d 64 65 74 65 63 74 29 2e 20 4d 75 73 74 20 o-detect). Must
2630: 62 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 be.**
2640: 20 20 20 20 20 20 20 20 20 3e 33 39 20 6f 72 20 >39 or
2650: 30 20 28 3d 20 6e 6f 20 6c 69 6d 69 74 2c 20 72 0 (= no limit, r
2660: 65 73 75 6c 74 69 6e 67 20 69 6e 20 61 20 73 69 esulting in a si
2670: 6e 67 6c 65 20 6c 69 6e 65 20 70 65 72 0a 2a 2a ngle line per.**
2680: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2690: 20 20 20 20 65 6e 74 72 79 29 2e 0a 2a 2a 0a 2a entry)..**.*
26a0: 2a 20 53 65 65 20 61 6c 73 6f 3a 20 64 65 73 63 * See also: desc
26b0: 65 6e 64 61 6e 74 73 2c 20 66 69 6e 66 6f 2c 20 endants, finfo,
26c0: 69 6e 66 6f 2c 20 62 72 61 6e 63 68 0a 2a 2f 0a info, branch.*/.
26d0: 76 6f 69 64 20 6c 65 61 76 65 73 5f 63 6d 64 28 void leaves_cmd(
26e0: 76 6f 69 64 29 7b 0a 20 20 53 74 6d 74 20 71 3b void){. Stmt q;
26f0: 0a 20 20 42 6c 6f 62 20 73 71 6c 3b 0a 20 20 69 . Blob sql;. i
2700: 6e 74 20 73 68 6f 77 41 6c 6c 20 3d 20 66 69 6e nt showAll = fin
2710: 64 5f 6f 70 74 69 6f 6e 28 22 61 6c 6c 22 2c 20 d_option("all",
2720: 22 61 22 2c 20 30 29 21 3d 30 3b 0a 20 20 69 6e "a", 0)!=0;. in
2730: 74 20 73 68 6f 77 43 6c 6f 73 65 64 20 3d 20 66 t showClosed = f
2740: 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 63 6c 6f 73 ind_option("clos
2750: 65 64 22 2c 20 22 63 22 2c 20 30 29 21 3d 30 3b ed", "c", 0)!=0;
2760: 0a 20 20 69 6e 74 20 72 65 63 6f 6d 70 75 74 65 . int recompute
2770: 46 6c 61 67 20 3d 20 66 69 6e 64 5f 6f 70 74 69 Flag = find_opti
2780: 6f 6e 28 22 72 65 63 6f 6d 70 75 74 65 22 2c 30 on("recompute",0
2790: 2c 30 29 21 3d 30 3b 0a 20 20 69 6e 74 20 62 79 ,0)!=0;. int by
27a0: 42 72 61 6e 63 68 20 3d 20 66 69 6e 64 5f 6f 70 Branch = find_op
27b0: 74 69 6f 6e 28 22 62 79 62 72 61 6e 63 68 22 2c tion("bybranch",
27c0: 30 2c 30 29 21 3d 30 3b 0a 20 20 69 6e 74 20 6d 0,0)!=0;. int m
27d0: 75 6c 74 69 70 6c 65 46 6c 61 67 20 3d 20 66 69 ultipleFlag = fi
27e0: 6e 64 5f 6f 70 74 69 6f 6e 28 22 6d 75 6c 74 69 nd_option("multi
27f0: 70 6c 65 22 2c 22 6d 22 2c 30 29 21 3d 30 3b 0a ple","m",0)!=0;.
2800: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 57 const char *zW
2810: 69 64 74 68 20 3d 20 66 69 6e 64 5f 6f 70 74 69 idth = find_opti
2820: 6f 6e 28 22 77 69 64 74 68 22 2c 22 57 22 2c 31 on("width","W",1
2830: 29 3b 0a 20 20 63 68 61 72 20 2a 7a 4c 61 73 74 );. char *zLast
2840: 42 72 20 3d 20 30 3b 0a 20 20 69 6e 74 20 6e 2c Br = 0;. int n,
2850: 20 77 69 64 74 68 3b 0a 20 20 63 68 61 72 20 7a width;. char z
2860: 4c 69 6e 65 4e 6f 5b 31 30 5d 3b 0a 0a 20 20 69 LineNo[10];.. i
2870: 66 28 20 6d 75 6c 74 69 70 6c 65 46 6c 61 67 20 f( multipleFlag
2880: 29 20 62 79 42 72 61 6e 63 68 20 3d 20 31 3b 0a ) byBranch = 1;.
2890: 20 20 69 66 28 20 7a 57 69 64 74 68 20 29 7b 0a if( zWidth ){.
28a0: 20 20 20 20 77 69 64 74 68 20 3d 20 61 74 6f 69 width = atoi
28b0: 28 7a 57 69 64 74 68 29 3b 0a 20 20 20 20 69 66 (zWidth);. if
28c0: 28 20 28 77 69 64 74 68 21 3d 30 29 20 26 26 20 ( (width!=0) &&
28d0: 28 77 69 64 74 68 3c 3d 33 39 29 20 29 7b 0a 20 (width<=39) ){.
28e0: 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 fossil_fata
28f0: 6c 28 22 2d 57 7c 2d 2d 77 69 64 74 68 20 76 61 l("-W|--width va
2900: 6c 75 65 20 6d 75 73 74 20 62 65 20 3e 33 39 20 lue must be >39
2910: 6f 72 20 30 22 29 3b 0a 20 20 20 20 7d 0a 20 20 or 0");. }.
2920: 7d 65 6c 73 65 7b 0a 20 20 20 20 77 69 64 74 68 }else{. width
2930: 20 3d 20 2d 31 3b 0a 20 20 7d 0a 20 20 64 62 5f = -1;. }. db_
2940: 66 69 6e 64 5f 61 6e 64 5f 6f 70 65 6e 5f 72 65 find_and_open_re
2950: 70 6f 73 69 74 6f 72 79 28 30 2c 30 29 3b 0a 0a pository(0,0);..
2960: 20 20 2f 2a 20 57 65 20 73 68 6f 75 6c 64 20 62 /* We should b
2970: 65 20 64 6f 6e 65 20 77 69 74 68 20 6f 70 74 69 e done with opti
2980: 6f 6e 73 2e 2e 20 2a 2f 0a 20 20 76 65 72 69 66 ons.. */. verif
2990: 79 5f 61 6c 6c 5f 6f 70 74 69 6f 6e 73 28 29 3b y_all_options();
29a0: 0a 0a 20 20 69 66 28 20 72 65 63 6f 6d 70 75 74 .. if( recomput
29b0: 65 46 6c 61 67 20 29 20 6c 65 61 66 5f 72 65 62 eFlag ) leaf_reb
29c0: 75 69 6c 64 28 29 3b 0a 20 20 62 6c 6f 62 5f 7a uild();. blob_z
29d0: 65 72 6f 28 26 73 71 6c 29 3b 0a 20 20 62 6c 6f ero(&sql);. blo
29e0: 62 5f 61 70 70 65 6e 64 28 26 73 71 6c 2c 20 74 b_append(&sql, t
29f0: 69 6d 65 6c 69 6e 65 5f 71 75 65 72 79 5f 66 6f imeline_query_fo
2a00: 72 5f 74 74 79 28 29 2c 20 2d 31 29 3b 0a 20 20 r_tty(), -1);.
2a10: 69 66 28 20 21 6d 75 6c 74 69 70 6c 65 46 6c 61 if( !multipleFla
2a20: 67 20 29 7b 0a 20 20 20 20 2f 2a 20 54 68 65 20 g ){. /* The
2a30: 75 73 75 61 6c 20 63 61 73 65 20 2d 20 73 68 6f usual case - sho
2a40: 77 20 61 6c 6c 20 6c 65 61 76 65 73 20 2a 2f 0a w all leaves */.
2a50: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 5f blob_append_
2a60: 73 71 6c 28 26 73 71 6c 2c 20 22 20 41 4e 44 20 sql(&sql, " AND
2a70: 62 6c 6f 62 2e 72 69 64 20 49 4e 20 6c 65 61 66 blob.rid IN leaf
2a80: 22 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 ");. }else{.
2a90: 20 2f 2a 20 53 68 6f 77 20 6f 6e 6c 79 20 6c 65 /* Show only le
2aa0: 61 76 65 73 20 77 68 65 72 65 20 74 77 6f 20 61 aves where two a
2ab0: 72 65 20 6d 6f 72 65 20 6f 63 63 75 72 20 69 6e re more occur in
2ac0: 20 74 68 65 20 73 61 6d 65 20 62 72 61 6e 63 68 the same branch
2ad0: 20 2a 2f 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 */. db_multi
2ae0: 5f 65 78 65 63 28 0a 20 20 20 20 20 20 22 43 52 _exec(. "CR
2af0: 45 41 54 45 20 54 45 4d 50 20 54 41 42 4c 45 20 EATE TEMP TABLE
2b00: 6f 70 65 6e 4c 65 61 66 28 72 69 64 20 49 4e 54 openLeaf(rid INT
2b10: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 EGER PRIMARY KEY
2b20: 29 3b 22 0a 20 20 20 20 20 20 22 49 4e 53 45 52 );". "INSER
2b30: 54 20 49 4e 54 4f 20 6f 70 65 6e 4c 65 61 66 28 T INTO openLeaf(
2b40: 72 69 64 29 22 0a 20 20 20 20 20 20 22 20 20 53 rid)". " S
2b50: 45 4c 45 43 54 20 72 69 64 20 46 52 4f 4d 20 6c ELECT rid FROM l
2b60: 65 61 66 22 0a 20 20 20 20 20 20 22 20 20 20 57 eaf". " W
2b70: 48 45 52 45 20 4e 4f 54 20 45 58 49 53 54 53 28 HERE NOT EXISTS(
2b80: 22 0a 20 20 20 20 20 20 22 20 20 20 20 20 53 45 ". " SE
2b90: 4c 45 43 54 20 31 20 46 52 4f 4d 20 74 61 67 78 LECT 1 FROM tagx
2ba0: 72 65 66 22 0a 20 20 20 20 20 20 22 20 20 20 20 ref". "
2bb0: 20 20 57 48 45 52 45 20 74 61 67 69 64 3d 25 64 WHERE tagid=%d
2bc0: 20 41 4e 44 20 74 61 67 74 79 70 65 3e 30 20 41 AND tagtype>0 A
2bd0: 4e 44 20 72 69 64 3d 6c 65 61 66 2e 72 69 64 29 ND rid=leaf.rid)
2be0: 3b 22 2c 0a 20 20 20 20 20 20 54 41 47 5f 43 4c ;",. TAG_CL
2bf0: 4f 53 45 44 0a 20 20 20 20 29 3b 0a 20 20 20 20 OSED. );.
2c00: 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 db_multi_exec(.
2c10: 20 20 20 20 20 22 43 52 45 41 54 45 20 54 45 4d "CREATE TEM
2c20: 50 20 54 41 42 4c 45 20 61 6d 62 69 67 75 6f 75 P TABLE ambiguou
2c30: 73 42 72 61 6e 63 68 28 62 72 6e 61 6d 65 20 54 sBranch(brname T
2c40: 45 58 54 29 3b 22 0a 20 20 20 20 20 20 22 49 4e EXT);". "IN
2c50: 53 45 52 54 20 49 4e 54 4f 20 61 6d 62 69 67 75 SERT INTO ambigu
2c60: 6f 75 73 42 72 61 6e 63 68 28 62 72 6e 61 6d 65 ousBranch(brname
2c70: 29 22 0a 20 20 20 20 20 20 22 20 53 45 4c 45 43 )". " SELEC
2c80: 54 20 28 53 45 4c 45 43 54 20 76 61 6c 75 65 20 T (SELECT value
2c90: 46 52 4f 4d 20 74 61 67 78 72 65 66 20 57 48 45 FROM tagxref WHE
2ca0: 52 45 20 74 61 67 69 64 3d 25 64 20 41 4e 44 20 RE tagid=%d AND
2cb0: 72 69 64 3d 6f 70 65 6e 4c 65 61 66 2e 72 69 64 rid=openLeaf.rid
2cc0: 29 22 0a 20 20 20 20 20 20 22 20 20 20 46 52 4f )". " FRO
2cd0: 4d 20 6f 70 65 6e 4c 65 61 66 22 0a 20 20 20 20 M openLeaf".
2ce0: 20 20 22 20 20 47 52 4f 55 50 20 42 59 20 31 20 " GROUP BY 1
2cf0: 48 41 56 49 4e 47 20 63 6f 75 6e 74 28 2a 29 3e HAVING count(*)>
2d00: 31 3b 22 2c 0a 20 20 20 20 20 20 54 41 47 5f 42 1;",. TAG_B
2d10: 52 41 4e 43 48 0a 20 20 20 20 29 3b 0a 20 20 20 RANCH. );.
2d20: 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a db_multi_exec(.
2d30: 20 20 20 20 20 20 22 43 52 45 41 54 45 20 54 45 "CREATE TE
2d40: 4d 50 20 54 41 42 4c 45 20 61 6d 62 69 67 75 6f MP TABLE ambiguo
2d50: 75 73 4c 65 61 66 28 72 69 64 20 49 4e 54 45 47 usLeaf(rid INTEG
2d60: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 29 3b ER PRIMARY KEY);
2d70: 5c 6e 22 0a 20 20 20 20 20 20 22 49 4e 53 45 52 \n". "INSER
2d80: 54 20 49 4e 54 4f 20 61 6d 62 69 67 75 6f 75 73 T INTO ambiguous
2d90: 4c 65 61 66 28 72 69 64 29 5c 6e 22 0a 20 20 20 Leaf(rid)\n".
2da0: 20 20 20 22 20 20 53 45 4c 45 43 54 20 72 69 64 " SELECT rid
2db0: 20 46 52 4f 4d 20 6f 70 65 6e 4c 65 61 66 5c 6e FROM openLeaf\n
2dc0: 22 0a 20 20 20 20 20 20 22 20 20 20 57 48 45 52 ". " WHER
2dd0: 45 20 28 53 45 4c 45 43 54 20 76 61 6c 75 65 20 E (SELECT value
2de0: 46 52 4f 4d 20 74 61 67 78 72 65 66 20 57 48 45 FROM tagxref WHE
2df0: 52 45 20 74 61 67 69 64 3d 25 64 20 41 4e 44 20 RE tagid=%d AND
2e00: 72 69 64 3d 6f 70 65 6e 4c 65 61 66 2e 72 69 64 rid=openLeaf.rid
2e10: 29 22 0a 20 20 20 20 20 20 22 20 20 20 20 20 20 )". "
2e20: 20 20 20 49 4e 20 28 53 45 4c 45 43 54 20 62 72 IN (SELECT br
2e30: 6e 61 6d 65 20 46 52 4f 4d 20 61 6d 62 69 67 75 name FROM ambigu
2e40: 6f 75 73 42 72 61 6e 63 68 29 3b 22 2c 0a 20 20 ousBranch);",.
2e50: 20 20 20 20 54 41 47 5f 42 52 41 4e 43 48 0a 20 TAG_BRANCH.
2e60: 20 20 20 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 );. blob_a
2e70: 70 70 65 6e 64 5f 73 71 6c 28 26 73 71 6c 2c 20 ppend_sql(&sql,
2e80: 22 20 41 4e 44 20 62 6c 6f 62 2e 72 69 64 20 49 " AND blob.rid I
2e90: 4e 20 61 6d 62 69 67 75 6f 75 73 4c 65 61 66 22 N ambiguousLeaf"
2ea0: 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 73 68 6f );. }. if( sho
2eb0: 77 43 6c 6f 73 65 64 20 29 7b 0a 20 20 20 20 62 wClosed ){. b
2ec0: 6c 6f 62 5f 61 70 70 65 6e 64 5f 73 71 6c 28 26 lob_append_sql(&
2ed0: 73 71 6c 2c 22 20 41 4e 44 20 25 7a 22 2c 20 6c sql," AND %z", l
2ee0: 65 61 66 5f 69 73 5f 63 6c 6f 73 65 64 5f 73 71 eaf_is_closed_sq
2ef0: 6c 28 22 62 6c 6f 62 2e 72 69 64 22 29 29 3b 0a l("blob.rid"));.
2f00: 20 20 7d 65 6c 73 65 20 69 66 28 20 21 73 68 6f }else if( !sho
2f10: 77 41 6c 6c 20 29 7b 0a 20 20 20 20 62 6c 6f 62 wAll ){. blob
2f20: 5f 61 70 70 65 6e 64 5f 73 71 6c 28 26 73 71 6c _append_sql(&sql
2f30: 2c 22 20 41 4e 44 20 4e 4f 54 20 25 7a 22 2c 20 ," AND NOT %z",
2f40: 6c 65 61 66 5f 69 73 5f 63 6c 6f 73 65 64 5f 73 leaf_is_closed_s
2f50: 71 6c 28 22 62 6c 6f 62 2e 72 69 64 22 29 29 3b ql("blob.rid"));
2f60: 0a 20 20 7d 0a 20 20 69 66 28 20 62 79 42 72 61 . }. if( byBra
2f70: 6e 63 68 20 29 7b 0a 20 20 20 20 64 62 5f 70 72 nch ){. db_pr
2f80: 65 70 61 72 65 28 26 71 2c 20 22 25 73 20 4f 52 epare(&q, "%s OR
2f90: 44 45 52 20 42 59 20 6e 75 6c 6c 69 66 28 62 72 DER BY nullif(br
2fa0: 61 6e 63 68 2c 27 74 72 75 6e 6b 27 29 20 43 4f anch,'trunk') CO
2fb0: 4c 4c 41 54 45 20 6e 6f 63 61 73 65 2c 22 0a 20 LLATE nocase,".
2fc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2fd0: 20 20 22 20 65 76 65 6e 74 2e 6d 74 69 6d 65 20 " event.mtime
2fe0: 44 45 53 43 22 2c 0a 20 20 20 20 20 20 20 20 20 DESC",.
2ff0: 20 20 20 20 20 20 20 20 20 20 62 6c 6f 62 5f 73 blob_s
3000: 71 6c 5f 74 65 78 74 28 26 73 71 6c 29 29 3b 0a ql_text(&sql));.
3010: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 64 62 5f }else{. db_
3020: 70 72 65 70 61 72 65 28 26 71 2c 20 22 25 73 20 prepare(&q, "%s
3030: 4f 52 44 45 52 20 42 59 20 65 76 65 6e 74 2e 6d ORDER BY event.m
3040: 74 69 6d 65 20 44 45 53 43 22 2c 20 62 6c 6f 62 time DESC", blob
3050: 5f 73 71 6c 5f 74 65 78 74 28 26 73 71 6c 29 29 _sql_text(&sql))
3060: 3b 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f 72 65 73 ;. }. blob_res
3070: 65 74 28 26 73 71 6c 29 3b 0a 20 20 6e 20 3d 20 et(&sql);. n =
3080: 30 3b 0a 20 20 77 68 69 6c 65 28 20 64 62 5f 73 0;. while( db_s
3090: 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f tep(&q)==SQLITE_
30a0: 52 4f 57 20 29 7b 0a 20 20 20 20 63 6f 6e 73 74 ROW ){. const
30b0: 20 63 68 61 72 20 2a 7a 49 64 20 3d 20 64 62 5f char *zId = db_
30c0: 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 column_text(&q,
30d0: 31 29 3b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 1);. const ch
30e0: 61 72 20 2a 7a 44 61 74 65 20 3d 20 64 62 5f 63 ar *zDate = db_c
30f0: 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 32 olumn_text(&q, 2
3100: 29 3b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 );. const cha
3110: 72 20 2a 7a 43 6f 6d 20 3d 20 64 62 5f 63 6f 6c r *zCom = db_col
3120: 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 33 29 3b umn_text(&q, 3);
3130: 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 . const char
3140: 2a 7a 42 72 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e *zBr = db_column
3150: 5f 74 65 78 74 28 26 71 2c 20 37 29 3b 0a 20 20 _text(&q, 7);.
3160: 20 20 63 68 61 72 20 2a 7a 3b 0a 0a 20 20 20 20 char *z;..
3170: 69 66 28 20 62 79 42 72 61 6e 63 68 20 26 26 20 if( byBranch &&
3180: 66 6f 73 73 69 6c 5f 73 74 72 63 6d 70 28 7a 42 fossil_strcmp(zB
3190: 72 2c 20 7a 4c 61 73 74 42 72 29 21 3d 30 20 29 r, zLastBr)!=0 )
31a0: 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 {. fossil_p
31b0: 72 69 6e 74 28 22 2a 2a 2a 20 25 73 20 2a 2a 2a rint("*** %s ***
31c0: 5c 6e 22 2c 20 7a 42 72 29 3b 0a 20 20 20 20 20 \n", zBr);.
31d0: 20 66 6f 73 73 69 6c 5f 66 72 65 65 28 7a 4c 61 fossil_free(zLa
31e0: 73 74 42 72 29 3b 0a 20 20 20 20 20 20 7a 4c 61 stBr);. zLa
31f0: 73 74 42 72 20 3d 20 66 6f 73 73 69 6c 5f 73 74 stBr = fossil_st
3200: 72 64 75 70 28 7a 42 72 29 3b 0a 20 20 20 20 20 rdup(zBr);.
3210: 20 69 66 28 20 6d 75 6c 74 69 70 6c 65 46 6c 61 if( multipleFla
3220: 67 20 29 20 6e 20 3d 20 30 3b 0a 20 20 20 20 7d g ) n = 0;. }
3230: 0a 20 20 20 20 6e 2b 2b 3b 0a 20 20 20 20 73 71 . n++;. sq
3240: 6c 69 74 65 33 5f 73 6e 70 72 69 6e 74 66 28 73 lite3_snprintf(s
3250: 69 7a 65 6f 66 28 7a 4c 69 6e 65 4e 6f 29 2c 20 izeof(zLineNo),
3260: 7a 4c 69 6e 65 4e 6f 2c 20 22 28 25 64 29 22 2c zLineNo, "(%d)",
3270: 20 6e 29 3b 0a 20 20 20 20 66 6f 73 73 69 6c 5f n);. fossil_
3280: 70 72 69 6e 74 28 22 25 36 73 20 22 2c 20 7a 4c print("%6s ", zL
3290: 69 6e 65 4e 6f 29 3b 0a 20 20 20 20 7a 20 3d 20 ineNo);. z =
32a0: 6d 70 72 69 6e 74 66 28 22 25 73 20 5b 25 53 5d mprintf("%s [%S]
32b0: 20 25 73 22 2c 20 7a 44 61 74 65 2c 20 7a 49 64 %s", zDate, zId
32c0: 2c 20 7a 43 6f 6d 29 3b 0a 20 20 20 20 63 6f 6d , zCom);. com
32d0: 6d 65 6e 74 5f 70 72 69 6e 74 28 7a 2c 20 7a 43 ment_print(z, zC
32e0: 6f 6d 2c 20 37 2c 20 77 69 64 74 68 2c 20 67 2e om, 7, width, g.
32f0: 63 6f 6d 46 6d 74 46 6c 61 67 73 29 3b 0a 20 20 comFmtFlags);.
3300: 20 20 66 6f 73 73 69 6c 5f 66 72 65 65 28 7a 29 fossil_free(z)
3310: 3b 0a 20 20 7d 0a 20 20 66 6f 73 73 69 6c 5f 66 ;. }. fossil_f
3320: 72 65 65 28 7a 4c 61 73 74 42 72 29 3b 0a 20 20 ree(zLastBr);.
3330: 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b db_finalize(&q);
3340: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 57 45 42 50 41 47 .}../*.** WEBPAG
3350: 45 3a 20 20 6c 65 61 76 65 73 0a 2a 2a 0a 2a 2a E: leaves.**.**
3360: 20 53 68 6f 77 20 6c 65 61 66 20 63 68 65 63 6b Show leaf check
3370: 2d 69 6e 73 20 69 6e 20 61 20 74 69 6d 65 6c 69 -ins in a timeli
3380: 6e 65 2e 20 20 42 79 20 64 65 66 61 75 6c 74 20 ne. By default
3390: 6f 6e 6c 79 20 6f 70 65 6e 20 6c 65 61 76 65 73 only open leaves
33a0: 0a 2a 2a 20 61 72 65 20 6c 69 73 74 65 64 2e 0a .** are listed..
33b0: 2a 2a 0a 2a 2a 20 41 20 22 6c 65 61 66 22 20 69 **.** A "leaf" i
33c0: 73 20 61 20 63 68 65 63 6b 2d 69 6e 20 77 69 74 s a check-in wit
33d0: 68 20 6e 6f 20 63 68 69 6c 64 72 65 6e 20 69 6e h no children in
33e0: 20 74 68 65 20 73 61 6d 65 20 62 72 61 6e 63 68 the same branch
33f0: 2e 20 20 41 0a 2a 2a 20 22 63 6c 6f 73 65 64 20 . A.** "closed
3400: 6c 65 61 66 22 20 69 73 20 61 20 6c 65 61 66 20 leaf" is a leaf
3410: 74 68 61 74 20 68 61 73 20 61 20 22 63 6c 6f 73 that has a "clos
3420: 65 64 22 20 74 61 67 2e 20 20 41 6e 20 22 6f 70 ed" tag. An "op
3430: 65 6e 20 6c 65 61 66 22 0a 2a 2a 20 69 73 20 61 en leaf".** is a
3440: 20 6c 65 61 66 20 77 69 74 68 6f 75 74 20 61 20 leaf without a
3450: 22 63 6c 6f 73 65 64 22 20 74 61 67 2e 0a 2a 2a "closed" tag..**
3460: 0a 2a 2a 20 51 75 65 72 79 20 70 61 72 61 6d 65 .** Query parame
3470: 74 65 72 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 ters:.**.**
3480: 61 6c 6c 20 20 20 20 20 20 20 20 20 20 20 53 68 all Sh
3490: 6f 77 20 61 6c 6c 20 6c 65 61 76 65 73 0a 2a 2a ow all leaves.**
34a0: 20 20 20 20 20 63 6c 6f 73 65 64 20 20 20 20 20 closed
34b0: 20 20 20 53 68 6f 77 20 6f 6e 6c 79 20 63 6c 6f Show only clo
34c0: 73 65 64 20 6c 65 61 76 65 73 0a 2a 2f 0a 76 6f sed leaves.*/.vo
34d0: 69 64 20 6c 65 61 76 65 73 5f 70 61 67 65 28 76 id leaves_page(v
34e0: 6f 69 64 29 7b 0a 20 20 42 6c 6f 62 20 73 71 6c oid){. Blob sql
34f0: 3b 0a 20 20 53 74 6d 74 20 71 3b 0a 20 20 69 6e ;. Stmt q;. in
3500: 74 20 73 68 6f 77 41 6c 6c 20 3d 20 50 28 22 61 t showAll = P("a
3510: 6c 6c 22 29 21 3d 30 3b 0a 20 20 69 6e 74 20 73 ll")!=0;. int s
3520: 68 6f 77 43 6c 6f 73 65 64 20 3d 20 50 28 22 63 howClosed = P("c
3530: 6c 6f 73 65 64 22 29 21 3d 30 3b 0a 0a 20 20 6c losed")!=0;.. l
3540: 6f 67 69 6e 5f 63 68 65 63 6b 5f 63 72 65 64 65 ogin_check_crede
3550: 6e 74 69 61 6c 73 28 29 3b 0a 20 20 69 66 28 20 ntials();. if(
3560: 21 67 2e 70 65 72 6d 2e 52 65 61 64 20 29 7b 20 !g.perm.Read ){
3570: 6c 6f 67 69 6e 5f 6e 65 65 64 65 64 28 67 2e 61 login_needed(g.a
3580: 6e 6f 6e 2e 52 65 61 64 29 3b 20 72 65 74 75 72 non.Read); retur
3590: 6e 3b 20 7d 0a 0a 20 20 69 66 28 20 21 73 68 6f n; }.. if( !sho
35a0: 77 41 6c 6c 20 29 7b 0a 20 20 20 20 73 74 79 6c wAll ){. styl
35b0: 65 5f 73 75 62 6d 65 6e 75 5f 65 6c 65 6d 65 6e e_submenu_elemen
35c0: 74 28 22 41 6c 6c 22 2c 20 22 41 6c 6c 22 2c 20 t("All", "All",
35d0: 22 6c 65 61 76 65 73 3f 61 6c 6c 22 29 3b 0a 20 "leaves?all");.
35e0: 20 7d 0a 20 20 69 66 28 20 21 73 68 6f 77 43 6c }. if( !showCl
35f0: 6f 73 65 64 20 29 7b 0a 20 20 20 20 73 74 79 6c osed ){. styl
3600: 65 5f 73 75 62 6d 65 6e 75 5f 65 6c 65 6d 65 6e e_submenu_elemen
3610: 74 28 22 43 6c 6f 73 65 64 22 2c 20 22 43 6c 6f t("Closed", "Clo
3620: 73 65 64 22 2c 20 22 6c 65 61 76 65 73 3f 63 6c sed", "leaves?cl
3630: 6f 73 65 64 22 29 3b 0a 20 20 7d 0a 20 20 69 66 osed");. }. if
3640: 28 20 73 68 6f 77 43 6c 6f 73 65 64 20 7c 7c 20 ( showClosed ||
3650: 73 68 6f 77 41 6c 6c 20 29 7b 0a 20 20 20 20 73 showAll ){. s
3660: 74 79 6c 65 5f 73 75 62 6d 65 6e 75 5f 65 6c 65 tyle_submenu_ele
3670: 6d 65 6e 74 28 22 4f 70 65 6e 22 2c 20 22 4f 70 ment("Open", "Op
3680: 65 6e 22 2c 20 22 6c 65 61 76 65 73 22 29 3b 0a en", "leaves");.
3690: 20 20 7d 0a 20 20 73 74 79 6c 65 5f 68 65 61 64 }. style_head
36a0: 65 72 28 22 4c 65 61 76 65 73 22 29 3b 0a 20 20 er("Leaves");.
36b0: 6c 6f 67 69 6e 5f 61 6e 6f 6e 79 6d 6f 75 73 5f login_anonymous_
36c0: 61 76 61 69 6c 61 62 6c 65 28 29 3b 0a 23 69 66 available();.#if
36d0: 20 30 0a 20 20 73 74 79 6c 65 5f 73 69 64 65 62 0. style_sideb
36e0: 6f 78 5f 62 65 67 69 6e 28 22 4e 6f 6d 65 6e 63 ox_begin("Nomenc
36f0: 6c 61 74 75 72 65 3a 22 2c 20 22 33 33 25 22 29 lature:", "33%")
3700: 3b 0a 20 20 40 20 3c 6f 6c 3e 0a 20 20 40 20 3c ;. @ <ol>. @ <
3710: 6c 69 3e 20 41 20 3c 64 69 76 20 63 6c 61 73 73 li> A <div class
3720: 3d 22 73 69 64 65 62 6f 78 44 65 73 63 72 69 62 ="sideboxDescrib
3730: 65 64 22 3e 6c 65 61 66 3c 2f 64 69 76 3e 0a 20 ed">leaf</div>.
3740: 20 40 20 69 73 20 61 20 63 68 65 63 6b 2d 69 6e @ is a check-in
3750: 20 77 69 74 68 20 6e 6f 20 64 65 73 63 65 6e 64 with no descend
3760: 61 6e 74 73 20 69 6e 20 74 68 65 20 73 61 6d 65 ants in the same
3770: 20 62 72 61 6e 63 68 2e 3c 2f 6c 69 3e 0a 20 20 branch.</li>.
3780: 40 20 3c 6c 69 3e 20 41 6e 20 3c 64 69 76 20 63 @ <li> An <div c
3790: 6c 61 73 73 3d 22 73 69 64 65 62 6f 78 44 65 73 lass="sideboxDes
37a0: 63 72 69 62 65 64 22 3e 6f 70 65 6e 20 6c 65 61 cribed">open lea
37b0: 66 3c 2f 64 69 76 3e 0a 20 20 40 20 69 73 20 61 f</div>. @ is a
37c0: 20 6c 65 61 66 20 74 68 61 74 20 64 6f 65 73 20 leaf that does
37d0: 6e 6f 74 20 68 61 76 65 20 61 20 22 63 6c 6f 73 not have a "clos
37e0: 65 64 22 20 74 61 67 0a 20 20 40 20 61 6e 64 20 ed" tag. @ and
37f0: 69 73 20 74 68 75 73 20 61 73 73 75 6d 65 64 20 is thus assumed
3800: 74 6f 20 73 74 69 6c 6c 20 62 65 20 69 6e 20 75 to still be in u
3810: 73 65 2e 3c 2f 6c 69 3e 0a 20 20 40 20 3c 6c 69 se.</li>. @ <li
3820: 3e 20 41 20 3c 64 69 76 20 63 6c 61 73 73 3d 22 > A <div class="
3830: 73 69 64 65 62 6f 78 44 65 73 63 72 69 62 65 64 sideboxDescribed
3840: 22 3e 63 6c 6f 73 65 64 20 6c 65 61 66 3c 2f 64 ">closed leaf</d
3850: 69 76 3e 0a 20 20 40 20 68 61 73 20 61 20 22 63 iv>. @ has a "c
3860: 6c 6f 73 65 64 22 20 74 61 67 20 61 6e 64 20 69 losed" tag and i
3870: 73 20 74 68 75 73 20 61 73 73 75 6d 65 64 20 74 s thus assumed t
3880: 6f 0a 20 20 40 20 62 65 20 68 69 73 74 6f 72 69 o. @ be histori
3890: 63 61 6c 20 61 6e 64 20 6e 6f 20 6c 6f 6e 67 65 cal and no longe
38a0: 72 20 69 6e 20 61 63 74 69 76 65 20 75 73 65 2e r in active use.
38b0: 3c 2f 6c 69 3e 0a 20 20 40 20 3c 2f 6f 6c 3e 0a </li>. @ </ol>.
38c0: 20 20 73 74 79 6c 65 5f 73 69 64 65 62 6f 78 5f style_sidebox_
38d0: 65 6e 64 28 29 3b 0a 23 65 6e 64 69 66 0a 0a 20 end();.#endif..
38e0: 20 69 66 28 20 73 68 6f 77 41 6c 6c 20 29 7b 0a if( showAll ){.
38f0: 20 20 20 20 40 20 3c 68 31 3e 41 6c 6c 20 6c 65 @ <h1>All le
3900: 61 76 65 73 2c 20 62 6f 74 68 20 6f 70 65 6e 20 aves, both open
3910: 61 6e 64 20 63 6c 6f 73 65 64 3a 3c 2f 68 31 3e and closed:</h1>
3920: 0a 20 20 7d 65 6c 73 65 20 69 66 28 20 73 68 6f . }else if( sho
3930: 77 43 6c 6f 73 65 64 20 29 7b 0a 20 20 20 20 40 wClosed ){. @
3940: 20 3c 68 31 3e 43 6c 6f 73 65 64 20 6c 65 61 76 <h1>Closed leav
3950: 65 73 3a 3c 2f 68 31 3e 0a 20 20 7d 65 6c 73 65 es:</h1>. }else
3960: 7b 0a 20 20 20 20 40 20 3c 68 31 3e 4f 70 65 6e {. @ <h1>Open
3970: 20 6c 65 61 76 65 73 3a 3c 2f 68 31 3e 0a 20 20 leaves:</h1>.
3980: 7d 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 73 }. blob_zero(&s
3990: 71 6c 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 ql);. blob_appe
39a0: 6e 64 28 26 73 71 6c 2c 20 74 69 6d 65 6c 69 6e nd(&sql, timelin
39b0: 65 5f 71 75 65 72 79 5f 66 6f 72 5f 77 77 77 28 e_query_for_www(
39c0: 29 2c 20 2d 31 29 3b 0a 20 20 62 6c 6f 62 5f 61 ), -1);. blob_a
39d0: 70 70 65 6e 64 5f 73 71 6c 28 26 73 71 6c 2c 20 ppend_sql(&sql,
39e0: 22 20 41 4e 44 20 62 6c 6f 62 2e 72 69 64 20 49 " AND blob.rid I
39f0: 4e 20 6c 65 61 66 22 29 3b 0a 20 20 69 66 28 20 N leaf");. if(
3a00: 73 68 6f 77 43 6c 6f 73 65 64 20 29 7b 0a 20 20 showClosed ){.
3a10: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 5f 73 71 blob_append_sq
3a20: 6c 28 26 73 71 6c 2c 22 20 41 4e 44 20 25 7a 22 l(&sql," AND %z"
3a30: 2c 20 6c 65 61 66 5f 69 73 5f 63 6c 6f 73 65 64 , leaf_is_closed
3a40: 5f 73 71 6c 28 22 62 6c 6f 62 2e 72 69 64 22 29 _sql("blob.rid")
3a50: 29 3b 0a 20 20 7d 65 6c 73 65 20 69 66 28 20 21 );. }else if( !
3a60: 73 68 6f 77 41 6c 6c 20 29 7b 0a 20 20 20 20 62 showAll ){. b
3a70: 6c 6f 62 5f 61 70 70 65 6e 64 5f 73 71 6c 28 26 lob_append_sql(&
3a80: 73 71 6c 2c 22 20 41 4e 44 20 4e 4f 54 20 25 7a sql," AND NOT %z
3a90: 22 2c 20 6c 65 61 66 5f 69 73 5f 63 6c 6f 73 65 ", leaf_is_close
3aa0: 64 5f 73 71 6c 28 22 62 6c 6f 62 2e 72 69 64 22 d_sql("blob.rid"
3ab0: 29 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 70 72 65 ));. }. db_pre
3ac0: 70 61 72 65 28 26 71 2c 20 22 25 73 20 4f 52 44 pare(&q, "%s ORD
3ad0: 45 52 20 42 59 20 65 76 65 6e 74 2e 6d 74 69 6d ER BY event.mtim
3ae0: 65 20 44 45 53 43 22 2c 20 62 6c 6f 62 5f 73 71 e DESC", blob_sq
3af0: 6c 5f 74 65 78 74 28 26 73 71 6c 29 29 3b 0a 20 l_text(&sql));.
3b00: 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 73 71 6c blob_reset(&sql
3b10: 29 3b 0a 20 20 77 77 77 5f 70 72 69 6e 74 5f 74 );. www_print_t
3b20: 69 6d 65 6c 69 6e 65 28 26 71 2c 20 54 49 4d 45 imeline(&q, TIME
3b30: 4c 49 4e 45 5f 4c 45 41 46 4f 4e 4c 59 2c 20 30 LINE_LEAFONLY, 0
3b40: 2c 20 30 2c 20 30 2c 20 30 29 3b 0a 20 20 64 62 , 0, 0, 0);. db
3b50: 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 _finalize(&q);.
3b60: 20 40 20 3c 62 72 20 2f 3e 0a 20 20 73 74 79 6c @ <br />. styl
3b70: 65 5f 66 6f 6f 74 65 72 28 29 3b 0a 7d 0a 0a 23 e_footer();.}..#
3b80: 69 66 20 49 4e 54 45 52 46 41 43 45 0a 2f 2a 20 if INTERFACE./*
3b90: 46 6c 61 67 20 70 61 72 61 6d 65 74 65 72 73 20 Flag parameters
3ba0: 74 6f 20 63 6f 6d 70 75 74 65 5f 75 73 65 73 5f to compute_uses_
3bb0: 66 69 6c 65 28 29 20 2a 2f 0a 23 64 65 66 69 6e file() */.#defin
3bc0: 65 20 55 53 45 53 46 49 4c 45 5f 44 45 4c 45 54 e USESFILE_DELET
3bd0: 45 20 20 20 30 78 30 31 20 20 2f 2a 20 49 6e 63 E 0x01 /* Inc
3be0: 6c 75 64 65 20 74 68 65 20 63 68 65 63 6b 2d 69 lude the check-i
3bf0: 6e 73 20 77 68 65 72 65 20 66 69 6c 65 20 64 65 ns where file de
3c00: 6c 65 74 65 64 20 2a 2f 0a 0a 23 65 6e 64 69 66 leted */..#endif
3c10: 0a 0a 0a 2f 2a 0a 2a 2a 20 41 64 64 20 74 6f 20 .../*.** Add to
3c20: 74 61 62 6c 65 20 7a 54 61 62 20 74 68 65 20 72 table zTab the r
3c30: 65 63 6f 72 64 20 49 44 20 28 72 69 64 29 20 6f ecord ID (rid) o
3c40: 66 20 65 76 65 72 79 20 63 68 65 63 6b 2d 69 6e f every check-in
3c50: 20 74 68 61 74 20 63 6f 6e 74 61 69 6e 73 0a 2a that contains.*
3c60: 2a 20 74 68 65 20 66 69 6c 65 20 66 69 64 2e 0a * the file fid..
3c70: 2a 2f 0a 76 6f 69 64 20 63 6f 6d 70 75 74 65 5f */.void compute_
3c80: 75 73 65 73 5f 66 69 6c 65 28 63 6f 6e 73 74 20 uses_file(const
3c90: 63 68 61 72 20 2a 7a 54 61 62 2c 20 69 6e 74 20 char *zTab, int
3ca0: 66 69 64 2c 20 69 6e 74 20 75 73 65 73 46 6c 61 fid, int usesFla
3cb0: 67 73 29 7b 0a 20 20 42 61 67 20 73 65 65 6e 3b gs){. Bag seen;
3cc0: 0a 20 20 42 61 67 20 70 65 6e 64 69 6e 67 3b 0a . Bag pending;.
3cd0: 20 20 53 74 6d 74 20 69 6e 73 3b 0a 20 20 53 74 Stmt ins;. St
3ce0: 6d 74 20 71 3b 0a 20 20 69 6e 74 20 72 69 64 3b mt q;. int rid;
3cf0: 0a 0a 20 20 62 61 67 5f 69 6e 69 74 28 26 73 65 .. bag_init(&se
3d00: 65 6e 29 3b 0a 20 20 62 61 67 5f 69 6e 69 74 28 en);. bag_init(
3d10: 26 70 65 6e 64 69 6e 67 29 3b 0a 20 20 64 62 5f &pending);. db_
3d20: 70 72 65 70 61 72 65 28 26 69 6e 73 2c 20 22 49 prepare(&ins, "I
3d30: 4e 53 45 52 54 20 4f 52 20 49 47 4e 4f 52 45 20 NSERT OR IGNORE
3d40: 49 4e 54 4f 20 5c 22 25 77 5c 22 20 56 41 4c 55 INTO \"%w\" VALU
3d50: 45 53 28 3a 72 69 64 29 22 2c 20 7a 54 61 62 29 ES(:rid)", zTab)
3d60: 3b 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 ;. db_prepare(&
3d70: 71 2c 20 22 53 45 4c 45 43 54 20 6d 69 64 20 46 q, "SELECT mid F
3d80: 52 4f 4d 20 6d 6c 69 6e 6b 20 57 48 45 52 45 20 ROM mlink WHERE
3d90: 66 69 64 3d 25 64 22 2c 20 66 69 64 29 3b 0a 20 fid=%d", fid);.
3da0: 20 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 while( db_step(
3db0: 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 &q)==SQLITE_ROW
3dc0: 29 7b 0a 20 20 20 20 69 6e 74 20 6d 69 64 20 3d ){. int mid =
3dd0: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 db_column_int(&
3de0: 71 2c 20 30 29 3b 0a 20 20 20 20 62 61 67 5f 69 q, 0);. bag_i
3df0: 6e 73 65 72 74 28 26 70 65 6e 64 69 6e 67 2c 20 nsert(&pending,
3e00: 6d 69 64 29 3b 0a 20 20 20 20 62 61 67 5f 69 6e mid);. bag_in
3e10: 73 65 72 74 28 26 73 65 65 6e 2c 20 6d 69 64 29 sert(&seen, mid)
3e20: 3b 0a 20 20 20 20 64 62 5f 62 69 6e 64 5f 69 6e ;. db_bind_in
3e30: 74 28 26 69 6e 73 2c 20 22 3a 72 69 64 22 2c 20 t(&ins, ":rid",
3e40: 6d 69 64 29 3b 0a 20 20 20 20 64 62 5f 73 74 65 mid);. db_ste
3e50: 70 28 26 69 6e 73 29 3b 0a 20 20 20 20 64 62 5f p(&ins);. db_
3e60: 72 65 73 65 74 28 26 69 6e 73 29 3b 0a 20 20 7d reset(&ins);. }
3e70: 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 . db_finalize(&
3e80: 71 29 3b 0a 0a 20 20 64 62 5f 70 72 65 70 61 72 q);.. db_prepar
3e90: 65 28 26 71 2c 20 22 53 45 4c 45 43 54 20 6d 69 e(&q, "SELECT mi
3ea0: 64 20 46 52 4f 4d 20 6d 6c 69 6e 6b 20 57 48 45 d FROM mlink WHE
3eb0: 52 45 20 70 69 64 3d 25 64 22 2c 20 66 69 64 29 RE pid=%d", fid)
3ec0: 3b 0a 20 20 77 68 69 6c 65 28 20 64 62 5f 73 74 ;. while( db_st
3ed0: 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 ep(&q)==SQLITE_R
3ee0: 4f 57 20 29 7b 0a 20 20 20 20 69 6e 74 20 6d 69 OW ){. int mi
3ef0: 64 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e d = db_column_in
3f00: 74 28 26 71 2c 20 30 29 3b 0a 20 20 20 20 62 61 t(&q, 0);. ba
3f10: 67 5f 69 6e 73 65 72 74 28 26 73 65 65 6e 2c 20 g_insert(&seen,
3f20: 6d 69 64 29 3b 0a 20 20 20 20 69 66 28 20 75 73 mid);. if( us
3f30: 65 73 46 6c 61 67 73 20 26 20 55 53 45 53 46 49 esFlags & USESFI
3f40: 4c 45 5f 44 45 4c 45 54 45 20 29 7b 0a 20 20 20 LE_DELETE ){.
3f50: 20 20 20 64 62 5f 62 69 6e 64 5f 69 6e 74 28 26 db_bind_int(&
3f60: 69 6e 73 2c 20 22 3a 72 69 64 22 2c 20 6d 69 64 ins, ":rid", mid
3f70: 29 3b 0a 20 20 20 20 20 20 64 62 5f 73 74 65 70 );. db_step
3f80: 28 26 69 6e 73 29 3b 0a 20 20 20 20 20 20 64 62 (&ins);. db
3f90: 5f 72 65 73 65 74 28 26 69 6e 73 29 3b 0a 20 20 _reset(&ins);.
3fa0: 20 20 7d 0a 20 20 7d 0a 20 20 64 62 5f 66 69 6e }. }. db_fin
3fb0: 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 64 62 5f alize(&q);. db_
3fc0: 70 72 65 70 61 72 65 28 26 71 2c 20 22 53 45 4c prepare(&q, "SEL
3fd0: 45 43 54 20 63 69 64 20 46 52 4f 4d 20 70 6c 69 ECT cid FROM pli
3fe0: 6e 6b 20 57 48 45 52 45 20 70 69 64 3d 3a 72 69 nk WHERE pid=:ri
3ff0: 64 20 41 4e 44 20 69 73 70 72 69 6d 22 29 3b 0a d AND isprim");.
4000: 0a 20 20 77 68 69 6c 65 28 20 28 72 69 64 20 3d . while( (rid =
4010: 20 62 61 67 5f 66 69 72 73 74 28 26 70 65 6e 64 bag_first(&pend
4020: 69 6e 67 29 29 21 3d 30 20 29 7b 0a 20 20 20 20 ing))!=0 ){.
4030: 62 61 67 5f 72 65 6d 6f 76 65 28 26 70 65 6e 64 bag_remove(&pend
4040: 69 6e 67 2c 20 72 69 64 29 3b 0a 20 20 20 20 64 ing, rid);. d
4050: 62 5f 62 69 6e 64 5f 69 6e 74 28 26 71 2c 20 22 b_bind_int(&q, "
4060: 3a 72 69 64 22 2c 20 72 69 64 29 3b 0a 20 20 20 :rid", rid);.
4070: 20 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 while( db_step(
4080: 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 &q)==SQLITE_ROW
4090: 29 7b 0a 20 20 20 20 20 20 69 6e 74 20 6d 69 64 ){. int mid
40a0: 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 = db_column_int
40b0: 28 26 71 2c 20 30 29 3b 0a 20 20 20 20 20 20 69 (&q, 0);. i
40c0: 66 28 20 62 61 67 5f 66 69 6e 64 28 26 73 65 65 f( bag_find(&see
40d0: 6e 2c 20 6d 69 64 29 20 29 20 63 6f 6e 74 69 6e n, mid) ) contin
40e0: 75 65 3b 0a 20 20 20 20 20 20 62 61 67 5f 69 6e ue;. bag_in
40f0: 73 65 72 74 28 26 73 65 65 6e 2c 20 6d 69 64 29 sert(&seen, mid)
4100: 3b 0a 20 20 20 20 20 20 62 61 67 5f 69 6e 73 65 ;. bag_inse
4110: 72 74 28 26 70 65 6e 64 69 6e 67 2c 20 6d 69 64 rt(&pending, mid
4120: 29 3b 0a 20 20 20 20 20 20 64 62 5f 62 69 6e 64 );. db_bind
4130: 5f 69 6e 74 28 26 69 6e 73 2c 20 22 3a 72 69 64 _int(&ins, ":rid
4140: 22 2c 20 6d 69 64 29 3b 0a 20 20 20 20 20 20 64 ", mid);. d
4150: 62 5f 73 74 65 70 28 26 69 6e 73 29 3b 0a 20 20 b_step(&ins);.
4160: 20 20 20 20 64 62 5f 72 65 73 65 74 28 26 69 6e db_reset(&in
4170: 73 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 64 62 s);. }. db
4180: 5f 72 65 73 65 74 28 26 71 29 3b 0a 20 20 7d 0a _reset(&q);. }.
4190: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 db_finalize(&q
41a0: 29 3b 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 );. db_finalize
41b0: 28 26 69 6e 73 29 3b 0a 20 20 62 61 67 5f 63 6c (&ins);. bag_cl
41c0: 65 61 72 28 26 73 65 65 6e 29 3b 0a 20 20 62 61 ear(&seen);. ba
41d0: 67 5f 63 6c 65 61 72 28 26 70 65 6e 64 69 6e 67 g_clear(&pending
41e0: 29 3b 0a 7d 0a );.}.