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 20 0a 2a 2a 20 54 68 69 73 20 66 69 6c .** .** This fil
0370: 65 20 69 6d 70 6c 65 6d 65 6e 74 73 20 74 68 65 e implements the
0380: 20 75 6e 64 6f 2f 72 65 64 6f 20 66 75 6e 63 74 undo/redo funct
0390: 69 6f 6e 61 6c 69 74 79 2e 0a 2a 2f 0a 23 69 6e ionality..*/.#in
03a0: 63 6c 75 64 65 20 22 63 6f 6e 66 69 67 2e 68 22 clude "config.h"
03b0: 0a 23 69 6e 63 6c 75 64 65 20 22 75 6e 64 6f 2e .#include "undo.
03c0: 68 22 0a 0a 0a 0a 2f 2a 0a 2a 2a 20 55 6e 64 6f h"..../*.** Undo
03d0: 20 74 68 65 20 63 68 61 6e 67 65 20 74 6f 20 74 the change to t
03e0: 68 65 20 66 69 6c 65 20 7a 50 61 74 68 6e 61 6d he file zPathnam
03f0: 65 2e 20 20 7a 50 61 74 68 6e 61 6d 65 20 69 73 e. zPathname is
0400: 20 74 68 65 20 70 61 74 68 6e 61 6d 65 0a 2a 2a the pathname.**
0410: 20 6f 66 20 74 68 65 20 66 69 6c 65 20 72 65 6c of the file rel
0420: 61 74 69 76 65 20 74 6f 20 74 68 65 20 72 6f 6f ative to the roo
0430: 74 20 6f 66 20 74 68 65 20 72 65 70 6f 73 69 74 t of the reposit
0440: 6f 72 79 2e 20 20 49 66 20 72 65 64 6f 46 6c 61 ory. If redoFla
0450: 67 20 69 73 0a 2a 2a 20 74 72 75 65 20 74 68 65 g is.** true the
0460: 20 72 65 64 6f 20 61 20 63 68 61 6e 67 65 2e 20 redo a change.
0470: 20 49 66 20 74 68 65 72 65 20 69 73 20 6e 6f 74 If there is not
0480: 68 69 6e 67 20 74 6f 20 75 6e 64 6f 20 28 6f 72 hing to undo (or
0490: 20 72 65 64 6f 29 20 74 68 65 6e 0a 2a 2a 20 74 redo) then.** t
04a0: 68 69 73 20 72 6f 75 74 69 6e 65 20 69 73 20 61 his routine is a
04b0: 20 6e 6f 6f 70 2e 0a 2a 2f 0a 73 74 61 74 69 63 noop..*/.static
04c0: 20 76 6f 69 64 20 75 6e 64 6f 5f 6f 6e 65 28 63 void undo_one(c
04d0: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 50 61 74 68 onst char *zPath
04e0: 6e 61 6d 65 2c 20 69 6e 74 20 72 65 64 6f 46 6c name, int redoFl
04f0: 61 67 29 7b 0a 20 20 53 74 6d 74 20 71 3b 0a 20 ag){. Stmt q;.
0500: 20 63 68 61 72 20 2a 7a 46 75 6c 6c 6e 61 6d 65 char *zFullname
0510: 3b 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 ;. db_prepare(&
0520: 71 2c 0a 20 20 20 20 22 53 45 4c 45 43 54 20 63 q,. "SELECT c
0530: 6f 6e 74 65 6e 74 2c 20 65 78 69 73 74 73 66 6c ontent, existsfl
0540: 61 67 20 46 52 4f 4d 20 75 6e 64 6f 20 57 48 45 ag FROM undo WHE
0550: 52 45 20 70 61 74 68 6e 61 6d 65 3d 25 51 20 41 RE pathname=%Q A
0560: 4e 44 20 72 65 64 6f 66 6c 61 67 3d 25 64 22 2c ND redoflag=%d",
0570: 0a 20 20 20 20 20 7a 50 61 74 68 6e 61 6d 65 2c . zPathname,
0580: 20 72 65 64 6f 46 6c 61 67 0a 20 20 29 3b 0a 20 redoFlag. );.
0590: 20 69 66 28 20 64 62 5f 73 74 65 70 28 26 71 29 if( db_step(&q)
05a0: 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a ==SQLITE_ROW ){.
05b0: 20 20 20 20 69 6e 74 20 6f 6c 64 5f 65 78 69 73 int old_exis
05c0: 74 73 3b 0a 20 20 20 20 69 6e 74 20 6e 65 77 5f ts;. int new_
05d0: 65 78 69 73 74 73 3b 0a 20 20 20 20 42 6c 6f 62 exists;. Blob
05e0: 20 63 75 72 72 65 6e 74 3b 0a 20 20 20 20 42 6c current;. Bl
05f0: 6f 62 20 6e 65 77 3b 0a 20 20 20 20 7a 46 75 6c ob new;. zFul
0600: 6c 6e 61 6d 65 20 3d 20 6d 70 72 69 6e 74 66 28 lname = mprintf(
0610: 22 25 73 2f 25 73 22 2c 20 67 2e 7a 4c 6f 63 61 "%s/%s", g.zLoca
0620: 6c 52 6f 6f 74 2c 20 7a 50 61 74 68 6e 61 6d 65 lRoot, zPathname
0630: 29 3b 0a 20 20 20 20 6e 65 77 5f 65 78 69 73 74 );. new_exist
0640: 73 20 3d 20 66 69 6c 65 5f 73 69 7a 65 28 7a 46 s = file_size(zF
0650: 75 6c 6c 6e 61 6d 65 29 3e 3d 30 3b 0a 20 20 20 ullname)>=0;.
0660: 20 69 66 28 20 6e 65 77 5f 65 78 69 73 74 73 20 if( new_exists
0670: 29 7b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 ){. blob_re
0680: 61 64 5f 66 72 6f 6d 5f 66 69 6c 65 28 26 63 75 ad_from_file(&cu
0690: 72 72 65 6e 74 2c 20 7a 46 75 6c 6c 6e 61 6d 65 rrent, zFullname
06a0: 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 );. }else{.
06b0: 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 63 blob_zero(&c
06c0: 75 72 72 65 6e 74 29 3b 0a 20 20 20 20 7d 0a 20 urrent);. }.
06d0: 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 6e 65 blob_zero(&ne
06e0: 77 29 3b 0a 20 20 20 20 6f 6c 64 5f 65 78 69 73 w);. old_exis
06f0: 74 73 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 ts = db_column_i
0700: 6e 74 28 26 71 2c 20 31 29 3b 0a 20 20 20 20 69 nt(&q, 1);. i
0710: 66 28 20 6f 6c 64 5f 65 78 69 73 74 73 20 29 7b f( old_exists ){
0720: 0a 20 20 20 20 20 20 64 62 5f 65 70 68 65 6d 65 . db_epheme
0730: 72 61 6c 5f 62 6c 6f 62 28 26 71 2c 20 30 2c 20 ral_blob(&q, 0,
0740: 26 6e 65 77 29 3b 0a 20 20 20 20 7d 0a 20 20 20 &new);. }.
0750: 20 69 66 28 20 6f 6c 64 5f 65 78 69 73 74 73 20 if( old_exists
0760: 29 7b 0a 20 20 20 20 20 20 69 66 28 20 6e 65 77 ){. if( new
0770: 5f 65 78 69 73 74 73 20 29 7b 0a 20 20 20 20 20 _exists ){.
0780: 20 20 20 70 72 69 6e 74 66 28 22 25 73 20 25 73 printf("%s %s
0790: 5c 6e 22 2c 20 72 65 64 6f 46 6c 61 67 20 3f 20 \n", redoFlag ?
07a0: 22 52 45 44 4f 22 20 3a 20 22 55 4e 44 4f 22 2c "REDO" : "UNDO",
07b0: 20 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20 zPathname);.
07c0: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 }else{.
07d0: 20 20 70 72 69 6e 74 66 28 22 4e 45 57 20 25 73 printf("NEW %s
07e0: 5c 6e 22 2c 20 7a 50 61 74 68 6e 61 6d 65 29 3b \n", zPathname);
07f0: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 62 . }. b
0800: 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f 66 69 6c lob_write_to_fil
0810: 65 28 26 6e 65 77 2c 20 7a 46 75 6c 6c 6e 61 6d e(&new, zFullnam
0820: 65 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 e);. }else{.
0830: 20 20 20 20 20 70 72 69 6e 74 66 28 22 44 45 4c printf("DEL
0840: 45 54 45 20 25 73 5c 6e 22 2c 20 7a 50 61 74 68 ETE %s\n", zPath
0850: 6e 61 6d 65 29 3b 0a 20 20 20 20 20 20 75 6e 6c name);. unl
0860: 69 6e 6b 28 7a 46 75 6c 6c 6e 61 6d 65 29 3b 0a ink(zFullname);.
0870: 20 20 20 20 7d 0a 20 20 20 20 62 6c 6f 62 5f 72 }. blob_r
0880: 65 73 65 74 28 26 6e 65 77 29 3b 0a 20 20 20 20 eset(&new);.
0890: 66 72 65 65 28 7a 46 75 6c 6c 6e 61 6d 65 29 3b free(zFullname);
08a0: 0a 20 20 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 . db_finalize
08b0: 28 26 71 29 3b 0a 20 20 20 20 64 62 5f 70 72 65 (&q);. db_pre
08c0: 70 61 72 65 28 26 71 2c 20 0a 20 20 20 20 20 20 pare(&q, .
08d0: 20 22 55 50 44 41 54 45 20 75 6e 64 6f 20 53 45 "UPDATE undo SE
08e0: 54 20 63 6f 6e 74 65 6e 74 3d 3a 63 2c 20 65 78 T content=:c, ex
08f0: 69 73 74 73 66 6c 61 67 3d 25 64 2c 20 72 65 64 istsflag=%d, red
0900: 6f 66 6c 61 67 3d 4e 4f 54 20 72 65 64 6f 66 6c oflag=NOT redofl
0910: 61 67 22 0a 20 20 20 20 20 20 20 22 20 57 48 45 ag". " WHE
0920: 52 45 20 70 61 74 68 6e 61 6d 65 3d 25 51 22 2c RE pathname=%Q",
0930: 0a 20 20 20 20 20 20 20 6e 65 77 5f 65 78 69 73 . new_exis
0940: 74 73 2c 20 7a 50 61 74 68 6e 61 6d 65 0a 20 20 ts, zPathname.
0950: 20 20 29 3b 0a 20 20 20 20 69 66 28 20 6e 65 77 );. if( new
0960: 5f 65 78 69 73 74 73 20 29 7b 0a 20 20 20 20 20 _exists ){.
0970: 20 64 62 5f 62 69 6e 64 5f 62 6c 6f 62 28 26 71 db_bind_blob(&q
0980: 2c 20 22 3a 63 22 2c 20 26 63 75 72 72 65 6e 74 , ":c", ¤t
0990: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 64 62 5f );. }. db_
09a0: 73 74 65 70 28 26 71 29 3b 0a 20 20 20 20 62 6c step(&q);. bl
09b0: 6f 62 5f 72 65 73 65 74 28 26 63 75 72 72 65 6e ob_reset(¤
09c0: 74 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 66 69 6e t);. }. db_fin
09d0: 61 6c 69 7a 65 28 26 71 29 3b 0a 7d 0a 0a 2f 2a alize(&q);.}../*
09e0: 0a 2a 2a 20 55 6e 64 6f 20 6f 72 20 72 65 64 6f .** Undo or redo
09f0: 20 61 6c 6c 20 75 6e 64 6f 61 62 6c 65 20 6f 72 all undoable or
0a00: 20 72 65 64 6f 61 62 6c 65 20 63 68 61 6e 67 65 redoable change
0a10: 73 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 s..*/.static voi
0a20: 64 20 75 6e 64 6f 5f 61 6c 6c 28 69 6e 74 20 72 d undo_all(int r
0a30: 65 64 6f 46 6c 61 67 29 7b 0a 20 20 53 74 6d 74 edoFlag){. Stmt
0a40: 20 71 3b 0a 20 20 69 6e 74 20 75 63 69 64 3b 0a q;. int ucid;.
0a50: 20 20 69 6e 74 20 6e 63 69 64 3b 0a 20 20 64 62 int ncid;. db
0a60: 5f 70 72 65 70 61 72 65 28 26 71 2c 20 22 53 45 _prepare(&q, "SE
0a70: 4c 45 43 54 20 70 61 74 68 6e 61 6d 65 20 46 52 LECT pathname FR
0a80: 4f 4d 20 75 6e 64 6f 20 57 48 45 52 45 20 72 65 OM undo WHERE re
0a90: 64 6f 66 6c 61 67 3d 25 64 22 0a 20 20 20 20 20 doflag=%d".
0aa0: 20 20 20 20 20 20 20 20 20 20 20 20 22 20 4f 52 " OR
0ab0: 44 45 52 20 42 59 20 2b 70 61 74 68 6e 61 6d 65 DER BY +pathname
0ac0: 22 2c 20 72 65 64 6f 46 6c 61 67 29 3b 0a 20 20 ", redoFlag);.
0ad0: 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 while( db_step(&
0ae0: 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 q)==SQLITE_ROW )
0af0: 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 {. const char
0b00: 20 2a 7a 50 61 74 68 6e 61 6d 65 20 3d 20 64 62 *zPathname = db
0b10: 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c _column_text(&q,
0b20: 20 30 29 3b 0a 20 20 20 20 75 6e 64 6f 5f 6f 6e 0);. undo_on
0b30: 65 28 7a 50 61 74 68 6e 61 6d 65 2c 20 72 65 64 e(zPathname, red
0b40: 6f 46 6c 61 67 29 3b 0a 20 20 7d 0a 20 20 64 62 oFlag);. }. db
0b50: 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 _finalize(&q);.
0b60: 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a db_multi_exec(.
0b70: 20 20 20 20 22 43 52 45 41 54 45 20 54 45 4d 50 "CREATE TEMP
0b80: 20 54 41 42 4c 45 20 75 6e 64 6f 5f 76 66 69 6c TABLE undo_vfil
0b90: 65 5f 32 20 41 53 20 53 45 4c 45 43 54 20 2a 20 e_2 AS SELECT *
0ba0: 46 52 4f 4d 20 76 66 69 6c 65 3b 22 0a 20 20 20 FROM vfile;".
0bb0: 20 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 76 66 "DELETE FROM vf
0bc0: 69 6c 65 3b 22 0a 20 20 20 20 22 49 4e 53 45 52 ile;". "INSER
0bd0: 54 20 49 4e 54 4f 20 76 66 69 6c 65 20 53 45 4c T INTO vfile SEL
0be0: 45 43 54 20 2a 20 46 52 4f 4d 20 75 6e 64 6f 5f ECT * FROM undo_
0bf0: 76 66 69 6c 65 3b 22 0a 20 20 20 20 22 44 45 4c vfile;". "DEL
0c00: 45 54 45 20 46 52 4f 4d 20 75 6e 64 6f 5f 76 66 ETE FROM undo_vf
0c10: 69 6c 65 3b 22 0a 20 20 20 20 22 49 4e 53 45 52 ile;". "INSER
0c20: 54 20 49 4e 54 4f 20 75 6e 64 6f 5f 76 66 69 6c T INTO undo_vfil
0c30: 65 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 e SELECT * FROM
0c40: 75 6e 64 6f 5f 76 66 69 6c 65 5f 32 3b 22 0a 20 undo_vfile_2;".
0c50: 20 20 20 22 44 52 4f 50 20 54 41 42 4c 45 20 75 "DROP TABLE u
0c60: 6e 64 6f 5f 76 66 69 6c 65 5f 32 3b 22 0a 20 20 ndo_vfile_2;".
0c70: 20 20 22 43 52 45 41 54 45 20 54 45 4d 50 20 54 "CREATE TEMP T
0c80: 41 42 4c 45 20 75 6e 64 6f 5f 76 6d 65 72 67 65 ABLE undo_vmerge
0c90: 5f 32 20 41 53 20 53 45 4c 45 43 54 20 2a 20 46 _2 AS SELECT * F
0ca0: 52 4f 4d 20 76 6d 65 72 67 65 3b 22 0a 20 20 20 ROM vmerge;".
0cb0: 20 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 76 6d "DELETE FROM vm
0cc0: 65 72 67 65 3b 22 0a 20 20 20 20 22 49 4e 53 45 erge;". "INSE
0cd0: 52 54 20 49 4e 54 4f 20 76 6d 65 72 67 65 20 53 RT INTO vmerge S
0ce0: 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 75 6e 64 ELECT * FROM und
0cf0: 6f 5f 76 6d 65 72 67 65 3b 22 0a 20 20 20 20 22 o_vmerge;". "
0d00: 44 45 4c 45 54 45 20 46 52 4f 4d 20 75 6e 64 6f DELETE FROM undo
0d10: 5f 76 6d 65 72 67 65 3b 22 0a 20 20 20 20 22 49 _vmerge;". "I
0d20: 4e 53 45 52 54 20 49 4e 54 4f 20 75 6e 64 6f 5f NSERT INTO undo_
0d30: 76 6d 65 72 67 65 20 53 45 4c 45 43 54 20 2a 20 vmerge SELECT *
0d40: 46 52 4f 4d 20 75 6e 64 6f 5f 76 6d 65 72 67 65 FROM undo_vmerge
0d50: 5f 32 3b 22 0a 20 20 20 20 22 44 52 4f 50 20 54 _2;". "DROP T
0d60: 41 42 4c 45 20 75 6e 64 6f 5f 76 6d 65 72 67 65 ABLE undo_vmerge
0d70: 5f 32 3b 22 0a 20 20 29 3b 0a 20 20 6e 63 69 64 _2;". );. ncid
0d80: 20 3d 20 64 62 5f 6c 67 65 74 5f 69 6e 74 28 22 = db_lget_int("
0d90: 75 6e 64 6f 5f 63 68 65 63 6b 6f 75 74 22 2c 20 undo_checkout",
0da0: 30 29 3b 0a 20 20 75 63 69 64 20 3d 20 64 62 5f 0);. ucid = db_
0db0: 6c 67 65 74 5f 69 6e 74 28 22 63 68 65 63 6b 6f lget_int("checko
0dc0: 75 74 22 2c 20 30 29 3b 0a 20 20 64 62 5f 6c 73 ut", 0);. db_ls
0dd0: 65 74 5f 69 6e 74 28 22 75 6e 64 6f 5f 63 68 65 et_int("undo_che
0de0: 63 6b 6f 75 74 22 2c 20 75 63 69 64 29 3b 0a 20 ckout", ucid);.
0df0: 20 64 62 5f 6c 73 65 74 5f 69 6e 74 28 22 63 68 db_lset_int("ch
0e00: 65 63 6b 6f 75 74 22 2c 20 6e 63 69 64 29 3b 0a eckout", ncid);.
0e10: 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 73 65 74 20 74 }../*.** Reset t
0e20: 68 65 20 74 68 65 20 75 6e 64 6f 20 6d 65 6d 6f he the undo memo
0e30: 72 79 2e 0a 2a 2f 0a 76 6f 69 64 20 75 6e 64 6f ry..*/.void undo
0e40: 5f 72 65 73 65 74 28 76 6f 69 64 29 7b 0a 20 20 _reset(void){.
0e50: 73 74 61 74 69 63 20 63 6f 6e 73 74 20 63 68 61 static const cha
0e60: 72 20 7a 53 71 6c 5b 5d 20 3d 0a 20 20 20 20 40 r zSql[] =. @
0e70: 20 44 52 4f 50 20 54 41 42 4c 45 20 49 46 20 45 DROP TABLE IF E
0e80: 58 49 53 54 53 20 75 6e 64 6f 3b 0a 20 20 20 20 XISTS undo;.
0e90: 40 20 44 52 4f 50 20 54 41 42 4c 45 20 49 46 20 @ DROP TABLE IF
0ea0: 45 58 49 53 54 53 20 75 6e 64 6f 5f 76 66 69 6c EXISTS undo_vfil
0eb0: 65 3b 0a 20 20 20 20 40 20 44 52 4f 50 20 54 41 e;. @ DROP TA
0ec0: 42 4c 45 20 49 46 20 45 58 49 53 54 53 20 75 6e BLE IF EXISTS un
0ed0: 64 6f 5f 76 6d 65 72 67 65 3b 0a 20 20 20 20 3b do_vmerge;. ;
0ee0: 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 . db_multi_exec
0ef0: 28 7a 53 71 6c 29 3b 0a 20 20 64 62 5f 6c 73 65 (zSql);. db_lse
0f00: 74 5f 69 6e 74 28 22 75 6e 64 6f 5f 61 76 61 69 t_int("undo_avai
0f10: 6c 61 62 6c 65 22 2c 20 30 29 3b 0a 20 20 64 62 lable", 0);. db
0f20: 5f 6c 73 65 74 5f 69 6e 74 28 22 75 6e 64 6f 5f _lset_int("undo_
0f30: 63 68 65 63 6b 6f 75 74 22 2c 20 30 29 3b 0a 7d checkout", 0);.}
0f40: 0a 0a 2f 2a 0a 2a 2a 20 42 65 67 69 6e 20 63 61 ../*.** Begin ca
0f50: 70 74 75 72 69 6e 67 20 61 20 73 6e 61 70 73 68 pturing a snapsh
0f60: 6f 74 20 74 68 61 74 20 63 61 6e 20 62 65 20 75 ot that can be u
0f70: 6e 64 6f 6e 65 2e 0a 2a 2f 0a 76 6f 69 64 20 75 ndone..*/.void u
0f80: 6e 64 6f 5f 62 65 67 69 6e 28 76 6f 69 64 29 7b ndo_begin(void){
0f90: 0a 20 20 69 6e 74 20 63 69 64 3b 0a 20 20 73 74 . int cid;. st
0fa0: 61 74 69 63 20 63 6f 6e 73 74 20 63 68 61 72 20 atic const char
0fb0: 7a 53 71 6c 5b 5d 20 3d 20 0a 20 20 20 20 40 20 zSql[] = . @
0fc0: 43 52 45 41 54 45 20 54 41 42 4c 45 20 75 6e 64 CREATE TABLE und
0fd0: 6f 28 0a 20 20 20 20 40 20 20 20 70 61 74 68 6e o(. @ pathn
0fe0: 61 6d 65 20 54 45 58 54 20 55 4e 49 51 55 45 2c ame TEXT UNIQUE,
0ff0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 --
1000: 4e 61 6d 65 20 6f 66 20 74 68 65 20 66 69 6c 65 Name of the file
1010: 0a 20 20 20 20 40 20 20 20 72 65 64 6f 66 6c 61 . @ redofla
1020: 67 20 42 4f 4f 4c 45 41 4e 2c 20 20 20 20 20 20 g BOOLEAN,
1030: 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 30 20 -- 0
1040: 66 6f 72 20 75 6e 64 6f 61 62 6c 65 2e 20 20 31 for undoable. 1
1050: 20 66 6f 72 20 72 65 64 6f 61 62 6c 65 0a 20 20 for redoable.
1060: 20 20 40 20 20 20 65 78 69 73 74 73 66 6c 61 67 @ existsflag
1070: 20 42 4f 4f 4c 45 41 4e 2c 20 20 20 20 20 20 20 BOOLEAN,
1080: 20 20 20 20 20 20 20 20 2d 2d 20 54 72 75 65 20 -- True
1090: 69 66 20 74 68 65 20 66 69 6c 65 20 65 78 69 73 if the file exis
10a0: 74 73 0a 20 20 20 20 40 20 20 20 63 6f 6e 74 65 ts. @ conte
10b0: 6e 74 20 42 4c 4f 42 20 20 20 20 20 20 20 20 20 nt BLOB
10c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 --
10d0: 53 61 76 65 64 20 63 6f 6e 74 65 6e 74 0a 20 20 Saved content.
10e0: 20 20 40 20 29 3b 0a 20 20 20 20 40 20 43 52 45 @ );. @ CRE
10f0: 41 54 45 20 54 41 42 4c 45 20 75 6e 64 6f 5f 76 ATE TABLE undo_v
1100: 66 69 6c 65 20 41 53 20 53 45 4c 45 43 54 20 2a file AS SELECT *
1110: 20 46 52 4f 4d 20 76 66 69 6c 65 3b 0a 20 20 20 FROM vfile;.
1120: 20 40 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 @ CREATE TABLE
1130: 75 6e 64 6f 5f 76 6d 65 72 67 65 20 41 53 20 53 undo_vmerge AS S
1140: 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 76 6d 65 ELECT * FROM vme
1150: 72 67 65 3b 0a 20 20 3b 0a 20 20 75 6e 64 6f 5f rge;. ;. undo_
1160: 72 65 73 65 74 28 29 3b 0a 20 20 64 62 5f 6d 75 reset();. db_mu
1170: 6c 74 69 5f 65 78 65 63 28 7a 53 71 6c 29 3b 0a lti_exec(zSql);.
1180: 20 20 63 69 64 20 3d 20 64 62 5f 6c 67 65 74 5f cid = db_lget_
1190: 69 6e 74 28 22 63 68 65 63 6b 6f 75 74 22 2c 20 int("checkout",
11a0: 30 29 3b 0a 20 20 64 62 5f 6c 73 65 74 5f 69 6e 0);. db_lset_in
11b0: 74 28 22 75 6e 64 6f 5f 63 68 65 63 6b 6f 75 74 t("undo_checkout
11c0: 22 2c 20 63 69 64 29 3b 0a 20 20 64 62 5f 6c 73 ", cid);. db_ls
11d0: 65 74 5f 69 6e 74 28 22 75 6e 64 6f 5f 61 76 61 et_int("undo_ava
11e0: 69 6c 61 62 6c 65 22 2c 20 31 29 3b 0a 7d 0a 0a ilable", 1);.}..
11f0: 2f 2a 0a 2a 2a 20 53 61 76 65 20 74 68 65 20 63 /*.** Save the c
1200: 75 72 72 65 6e 74 20 63 6f 6e 74 65 6e 74 20 6f urrent content o
1210: 66 20 74 68 65 20 66 69 6c 65 20 7a 50 61 74 68 f the file zPath
1220: 6e 61 6d 65 20 73 6f 20 74 68 61 74 20 69 74 0a name so that it.
1230: 2a 2a 20 77 69 6c 6c 20 62 65 20 75 6e 64 6f 61 ** will be undoa
1240: 62 6c 65 2e 20 20 54 68 65 20 6e 61 6d 65 20 69 ble. The name i
1250: 73 20 72 65 6c 61 74 69 76 65 20 74 6f 20 74 68 s relative to th
1260: 65 20 72 6f 6f 74 20 6f 66 20 74 68 65 0a 2a 2a e root of the.**
1270: 20 74 72 65 65 2e 0a 2a 2f 0a 76 6f 69 64 20 75 tree..*/.void u
1280: 6e 64 6f 5f 73 61 76 65 28 63 6f 6e 73 74 20 63 ndo_save(const c
1290: 68 61 72 20 2a 7a 50 61 74 68 6e 61 6d 65 29 7b har *zPathname){
12a0: 0a 20 20 63 68 61 72 20 2a 7a 46 75 6c 6c 6e 61 . char *zFullna
12b0: 6d 65 3b 0a 20 20 42 6c 6f 62 20 63 6f 6e 74 65 me;. Blob conte
12c0: 6e 74 3b 0a 20 20 69 6e 74 20 65 78 69 73 74 73 nt;. int exists
12d0: 46 6c 61 67 3b 0a 20 20 53 74 6d 74 20 71 3b 0a Flag;. Stmt q;.
12e0: 0a 20 20 7a 46 75 6c 6c 6e 61 6d 65 20 3d 20 6d . zFullname = m
12f0: 70 72 69 6e 74 66 28 22 25 73 2f 25 73 22 2c 20 printf("%s/%s",
1300: 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 2c 20 7a 50 g.zLocalRoot, zP
1310: 61 74 68 6e 61 6d 65 29 3b 0a 20 20 65 78 69 73 athname);. exis
1320: 74 73 46 6c 61 67 20 3d 20 66 69 6c 65 5f 73 69 tsFlag = file_si
1330: 7a 65 28 7a 46 75 6c 6c 6e 61 6d 65 29 3e 3d 30 ze(zFullname)>=0
1340: 3b 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 ;. db_prepare(&
1350: 71 2c 0a 20 20 20 20 22 52 45 50 4c 41 43 45 20 q,. "REPLACE
1360: 49 4e 54 4f 20 75 6e 64 6f 28 70 61 74 68 6e 61 INTO undo(pathna
1370: 6d 65 2c 72 65 64 6f 66 6c 61 67 2c 65 78 69 73 me,redoflag,exis
1380: 74 73 66 6c 61 67 2c 63 6f 6e 74 65 6e 74 29 22 tsflag,content)"
1390: 0a 20 20 20 20 22 20 56 41 4c 55 45 53 28 25 51 . " VALUES(%Q
13a0: 2c 30 2c 25 64 2c 3a 63 29 22 2c 0a 20 20 20 20 ,0,%d,:c)",.
13b0: 7a 50 61 74 68 6e 61 6d 65 2c 20 65 78 69 73 74 zPathname, exist
13c0: 73 46 6c 61 67 0a 20 20 29 3b 0a 20 20 69 66 28 sFlag. );. if(
13d0: 20 65 78 69 73 74 73 46 6c 61 67 20 29 7b 0a 20 existsFlag ){.
13e0: 20 20 20 62 6c 6f 62 5f 72 65 61 64 5f 66 72 6f blob_read_fro
13f0: 6d 5f 66 69 6c 65 28 26 63 6f 6e 74 65 6e 74 2c m_file(&content,
1400: 20 7a 46 75 6c 6c 6e 61 6d 65 29 3b 0a 20 20 20 zFullname);.
1410: 20 64 62 5f 62 69 6e 64 5f 62 6c 6f 62 28 26 71 db_bind_blob(&q
1420: 2c 20 22 3a 63 22 2c 20 26 63 6f 6e 74 65 6e 74 , ":c", &content
1430: 29 3b 0a 20 20 7d 0a 20 20 66 72 65 65 28 7a 46 );. }. free(zF
1440: 75 6c 6c 6e 61 6d 65 29 3b 0a 20 20 64 62 5f 73 ullname);. db_s
1450: 74 65 70 28 26 71 29 3b 0a 20 20 64 62 5f 66 69 tep(&q);. db_fi
1460: 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 69 66 nalize(&q);. if
1470: 28 20 65 78 69 73 74 73 46 6c 61 67 20 29 7b 0a ( existsFlag ){.
1480: 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 blob_reset(&
1490: 63 6f 6e 74 65 6e 74 29 3b 0a 20 20 7d 0a 7d 0a content);. }.}.
14a0: 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 ./*.** COMMAND:
14b0: 75 6e 64 6f 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 undo.**.** Usage
14c0: 3a 20 25 66 6f 73 73 69 6c 20 75 6e 64 6f 20 3f : %fossil undo ?
14d0: 46 49 4c 45 4e 41 4d 45 2e 2e 2e 3f 0a 2a 2a 0a FILENAME...?.**.
14e0: 2a 2a 20 55 6e 64 6f 20 74 68 65 20 6d 6f 73 74 ** Undo the most
14f0: 20 72 65 63 65 6e 74 20 75 70 64 61 74 65 20 6f recent update o
1500: 72 20 6d 65 72 67 65 20 6f 70 65 72 61 74 69 6f r merge operatio
1510: 6e 2e 20 20 49 66 20 46 49 4c 45 4e 41 4d 45 20 n. If FILENAME
1520: 69 73 0a 2a 2a 20 73 70 65 63 69 66 69 65 64 20 is.** specified
1530: 74 68 65 6e 20 72 65 73 74 6f 72 65 20 74 68 65 then restore the
1540: 20 63 6f 6e 74 65 6e 74 20 6f 66 20 74 68 65 20 content of the
1550: 6e 61 6d 65 64 20 66 69 6c 65 28 73 29 20 62 75 named file(s) bu
1560: 74 20 6f 74 68 65 72 77 69 73 65 0a 2a 2a 20 6c t otherwise.** l
1570: 65 61 76 65 20 74 68 65 20 75 70 64 61 74 65 20 eave the update
1580: 6f 72 20 6d 65 72 67 65 20 69 6e 20 65 66 66 65 or merge in effe
1590: 63 74 2e 0a 2a 2a 0a 2a 2a 20 41 20 73 69 6e 67 ct..**.** A sing
15a0: 6c 65 20 6c 65 76 65 6c 20 6f 66 20 75 6e 64 6f le level of undo
15b0: 2f 72 65 64 6f 20 69 73 20 73 75 70 70 6f 72 74 /redo is support
15c0: 65 64 2e 20 20 54 68 65 20 75 6e 64 6f 2f 72 65 ed. The undo/re
15d0: 64 6f 20 73 74 61 63 6b 0a 2a 2a 20 69 73 20 63 do stack.** is c
15e0: 6c 65 61 72 65 64 20 62 79 20 74 68 65 20 63 6f leared by the co
15f0: 6d 6d 69 74 20 61 6e 64 20 63 68 65 63 6b 6f 75 mmit and checkou
1600: 74 20 63 6f 6d 6d 61 6e 64 73 2e 0a 2a 2f 0a 76 t commands..*/.v
1610: 6f 69 64 20 75 6e 64 6f 5f 63 6d 64 28 76 6f 69 oid undo_cmd(voi
1620: 64 29 7b 0a 20 20 69 6e 74 20 75 6e 64 6f 5f 61 d){. int undo_a
1630: 76 61 69 6c 61 62 6c 65 3b 0a 20 20 64 62 5f 6d vailable;. db_m
1640: 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72 ust_be_within_tr
1650: 65 65 28 29 3b 0a 20 20 64 62 5f 62 65 67 69 6e ee();. db_begin
1660: 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 29 3b 0a _transaction();.
1670: 20 20 75 6e 64 6f 5f 61 76 61 69 6c 61 62 6c 65 undo_available
1680: 20 3d 20 64 62 5f 6c 67 65 74 5f 69 6e 74 28 22 = db_lget_int("
1690: 75 6e 64 6f 5f 61 76 61 69 6c 61 62 6c 65 22 2c undo_available",
16a0: 20 30 29 3b 0a 20 20 69 66 28 20 67 2e 61 72 67 0);. if( g.arg
16b0: 63 3d 3d 32 20 29 7b 0a 20 20 20 20 69 66 28 20 c==2 ){. if(
16c0: 75 6e 64 6f 5f 61 76 61 69 6c 61 62 6c 65 21 3d undo_available!=
16d0: 31 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 1 ){. fossi
16e0: 6c 5f 66 61 74 61 6c 28 22 6e 6f 20 75 70 64 61 l_fatal("no upda
16f0: 74 65 20 6f 72 20 6d 65 72 67 65 20 6f 70 65 72 te or merge oper
1700: 61 74 69 6f 6e 20 69 73 20 61 76 61 69 6c 61 62 ation is availab
1710: 6c 65 20 74 6f 20 75 6e 64 6f 22 29 3b 0a 20 20 le to undo");.
1720: 20 20 7d 0a 20 20 20 20 75 6e 64 6f 5f 61 6c 6c }. undo_all
1730: 28 30 29 3b 0a 20 20 20 20 64 62 5f 6c 73 65 74 (0);. db_lset
1740: 5f 69 6e 74 28 22 75 6e 64 6f 5f 61 76 61 69 6c _int("undo_avail
1750: 61 62 6c 65 22 2c 20 32 29 3b 0a 20 20 7d 65 6c able", 2);. }el
1760: 73 65 20 69 66 28 20 67 2e 61 72 67 63 3e 3d 33 se if( g.argc>=3
1770: 20 29 7b 0a 20 20 20 20 69 6e 74 20 69 3b 0a 20 ){. int i;.
1780: 20 20 20 69 66 28 20 75 6e 64 6f 5f 61 76 61 69 if( undo_avai
1790: 6c 61 62 6c 65 3d 3d 30 20 29 7b 0a 20 20 20 20 lable==0 ){.
17a0: 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 fossil_fatal("
17b0: 6e 6f 20 75 70 64 61 74 65 20 6f 72 20 6d 65 72 no update or mer
17c0: 67 65 20 6f 70 65 72 61 74 69 6f 6e 20 69 73 20 ge operation is
17d0: 61 76 61 69 6c 61 62 6c 65 20 74 6f 20 75 6e 64 available to und
17e0: 6f 22 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 66 o");. }. f
17f0: 6f 72 28 69 3d 32 3b 20 69 3c 67 2e 61 72 67 63 or(i=2; i<g.argc
1800: 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 20 20 63 6f ; i++){. co
1810: 6e 73 74 20 63 68 61 72 20 2a 7a 46 69 6c 65 20 nst char *zFile
1820: 3d 20 67 2e 61 72 67 76 5b 69 5d 3b 0a 20 20 20 = g.argv[i];.
1830: 20 20 20 42 6c 6f 62 20 70 61 74 68 3b 0a 20 20 Blob path;.
1840: 20 20 20 20 66 69 6c 65 5f 74 72 65 65 5f 6e 61 file_tree_na
1850: 6d 65 28 7a 46 69 6c 65 2c 20 26 70 61 74 68 29 me(zFile, &path)
1860: 3b 0a 20 20 20 20 20 20 75 6e 64 6f 5f 6f 6e 65 ;. undo_one
1870: 28 62 6c 6f 62 5f 73 74 72 28 26 70 61 74 68 29 (blob_str(&path)
1880: 2c 20 30 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 , 0);. blob
1890: 5f 72 65 73 65 74 28 26 70 61 74 68 29 3b 0a 20 _reset(&path);.
18a0: 20 20 20 7d 0a 20 20 7d 0a 20 20 64 62 5f 65 6e }. }. db_en
18b0: 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30 29 d_transaction(0)
18c0: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 ;.}../*.** COMMA
18d0: 4e 44 3a 20 72 65 64 6f 0a 2a 2a 0a 2a 2a 20 55 ND: redo.**.** U
18e0: 73 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 72 65 sage: %fossil re
18f0: 64 6f 20 3f 46 49 4c 45 4e 41 4d 45 2e 2e 2e 3f do ?FILENAME...?
1900: 0a 2a 2a 0a 2a 2a 20 52 65 64 6f 20 74 68 65 20 .**.** Redo the
1910: 61 6e 20 75 70 64 61 74 65 20 6f 72 20 6d 65 72 an update or mer
1920: 67 65 20 6f 70 65 72 61 74 69 6f 6e 20 74 68 61 ge operation tha
1930: 74 20 68 61 73 20 62 65 65 6e 20 75 6e 64 6f 6e t has been undon
1940: 65 20 62 79 20 74 68 65 0a 2a 2a 20 75 6e 64 6f e by the.** undo
1950: 20 63 6f 6d 6d 61 6e 64 2e 20 20 49 66 20 46 49 command. If FI
1960: 4c 45 4e 41 4d 45 20 69 73 20 73 70 65 63 69 66 LENAME is specif
1970: 69 65 64 20 74 68 65 6e 20 72 65 73 74 6f 72 65 ied then restore
1980: 20 74 68 65 20 63 68 61 6e 67 65 73 0a 2a 2a 20 the changes.**
1990: 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 associated with
19a0: 74 68 65 20 6e 61 6d 65 64 20 66 69 6c 65 28 73 the named file(s
19b0: 29 20 62 75 74 20 6f 74 68 65 72 77 69 73 65 20 ) but otherwise
19c0: 6c 65 61 76 65 20 74 68 65 20 75 70 64 61 74 65 leave the update
19d0: 0a 2a 2a 20 6f 72 20 6d 65 72 67 65 20 75 6e 64 .** or merge und
19e0: 6f 6e 65 2e 0a 2a 2a 0a 2a 2a 20 41 20 73 69 6e one..**.** A sin
19f0: 67 6c 65 20 6c 65 76 65 6c 20 6f 66 20 75 6e 64 gle level of und
1a00: 6f 2f 72 65 64 6f 20 69 73 20 73 75 70 70 6f 72 o/redo is suppor
1a10: 74 65 64 2e 20 20 54 68 65 20 75 6e 64 6f 2f 72 ted. The undo/r
1a20: 65 64 6f 20 73 74 61 63 6b 0a 2a 2a 20 69 73 20 edo stack.** is
1a30: 63 6c 65 61 72 65 64 20 62 79 20 74 68 65 20 63 cleared by the c
1a40: 6f 6d 6d 69 74 20 61 6e 64 20 63 68 65 63 6b 6f ommit and checko
1a50: 75 74 20 63 6f 6d 6d 61 6e 64 73 2e 0a 2a 2f 0a ut commands..*/.
1a60: 76 6f 69 64 20 72 65 64 6f 5f 63 6d 64 28 76 6f void redo_cmd(vo
1a70: 69 64 29 7b 0a 20 20 69 6e 74 20 75 6e 64 6f 5f id){. int undo_
1a80: 61 76 61 69 6c 61 62 6c 65 3b 0a 20 20 64 62 5f available;. db_
1a90: 6d 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 must_be_within_t
1aa0: 72 65 65 28 29 3b 0a 20 20 64 62 5f 62 65 67 69 ree();. db_begi
1ab0: 6e 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 29 3b n_transaction();
1ac0: 0a 20 20 75 6e 64 6f 5f 61 76 61 69 6c 61 62 6c . undo_availabl
1ad0: 65 20 3d 20 64 62 5f 6c 67 65 74 5f 69 6e 74 28 e = db_lget_int(
1ae0: 22 75 6e 64 6f 5f 61 76 61 69 6c 61 62 6c 65 22 "undo_available"
1af0: 2c 20 30 29 3b 0a 20 20 69 66 28 20 67 2e 61 72 , 0);. if( g.ar
1b00: 67 63 3d 3d 32 20 29 7b 0a 20 20 20 20 69 66 28 gc==2 ){. if(
1b10: 20 75 6e 64 6f 5f 61 76 61 69 6c 61 62 6c 65 21 undo_available!
1b20: 3d 32 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 =2 ){. foss
1b30: 69 6c 5f 66 61 74 61 6c 28 22 6e 6f 20 75 6e 64 il_fatal("no und
1b40: 6f 6e 65 20 75 70 64 61 74 65 20 6f 72 20 6d 65 one update or me
1b50: 72 67 65 20 6f 70 65 72 61 74 69 6f 6e 20 69 73 rge operation is
1b60: 20 61 76 61 69 6c 61 62 6c 65 20 74 6f 20 72 65 available to re
1b70: 64 6f 22 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 do");. }.
1b80: 75 6e 64 6f 5f 61 6c 6c 28 31 29 3b 0a 20 20 20 undo_all(1);.
1b90: 20 64 62 5f 6c 73 65 74 5f 69 6e 74 28 22 75 6e db_lset_int("un
1ba0: 64 6f 5f 61 76 61 69 6c 61 62 6c 65 22 2c 20 31 do_available", 1
1bb0: 29 3b 0a 20 20 7d 65 6c 73 65 20 69 66 28 20 67 );. }else if( g
1bc0: 2e 61 72 67 63 3e 3d 33 20 29 7b 0a 20 20 20 20 .argc>=3 ){.
1bd0: 69 6e 74 20 69 3b 0a 20 20 20 20 69 66 28 20 75 int i;. if( u
1be0: 6e 64 6f 5f 61 76 61 69 6c 61 62 6c 65 3d 3d 30 ndo_available==0
1bf0: 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c ){. fossil
1c00: 5f 66 61 74 61 6c 28 22 6e 6f 20 75 70 64 61 74 _fatal("no updat
1c10: 65 20 6f 72 20 6d 65 72 67 65 20 6f 70 65 72 61 e or merge opera
1c20: 74 69 6f 6e 20 69 73 20 61 76 61 69 6c 61 62 6c tion is availabl
1c30: 65 20 74 6f 20 72 65 64 6f 22 29 3b 0a 20 20 20 e to redo");.
1c40: 20 7d 0a 20 20 20 20 66 6f 72 28 69 3d 32 3b 20 }. for(i=2;
1c50: 69 3c 67 2e 61 72 67 63 3b 20 69 2b 2b 29 7b 0a i<g.argc; i++){.
1c60: 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 const char
1c70: 20 2a 7a 46 69 6c 65 20 3d 20 67 2e 61 72 67 76 *zFile = g.argv
1c80: 5b 69 5d 3b 0a 20 20 20 20 20 20 42 6c 6f 62 20 [i];. Blob
1c90: 70 61 74 68 3b 0a 20 20 20 20 20 20 66 69 6c 65 path;. file
1ca0: 5f 74 72 65 65 5f 6e 61 6d 65 28 7a 46 69 6c 65 _tree_name(zFile
1cb0: 2c 20 26 70 61 74 68 29 3b 0a 20 20 20 20 20 20 , &path);.
1cc0: 75 6e 64 6f 5f 6f 6e 65 28 62 6c 6f 62 5f 73 74 undo_one(blob_st
1cd0: 72 28 26 70 61 74 68 29 2c 20 30 29 3b 0a 20 20 r(&path), 0);.
1ce0: 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 blob_reset(&
1cf0: 70 61 74 68 29 3b 0a 20 20 20 20 7d 0a 20 20 7d path);. }. }
1d00: 0a 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 . db_end_transa
1d10: 63 74 69 6f 6e 28 30 29 3b 0a 7d 0a ction(0);.}.