Hex Artifact Content
Not logged in

Artifact 1e4377482c84195c43fb6283b5ef21a0668cfe15:

File src/undo.c part of check-in [a36177bcce] - Add the "undo" and "redo" commands. Untested at this point so don't try to use them yet. by drh on 2007-09-11 02:25:19.

0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20  /*.** Copyright 
0010: 28 63 29 20 32 30 30 37 20 44 2e 20 52 69 63 68  (c) 2007 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54  ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66  his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f  ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75  u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20  te it and/or.** 
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20  modify it under 
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65  the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62   GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 76  lic.** License v
00b0: 65 72 73 69 6f 6e 20 32 20 61 73 20 70 75 62 6c  ersion 2 as publ
00c0: 69 73 68 65 64 20 62 79 20 74 68 65 20 46 72 65  ished by the Fre
00d0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
00e0: 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69  ation..**.** Thi
00f0: 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73  s program is dis
0100: 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20  tributed in the 
0110: 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c  hope that it wil
0120: 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20  l be useful,.** 
0130: 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20  but WITHOUT ANY 
0140: 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75  WARRANTY; withou
0150: 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69  t even the impli
0160: 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a  ed warranty of.*
0170: 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54  * MERCHANTABILIT
0180: 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52  Y or FITNESS FOR
0190: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55   A PARTICULAR PU
01a0: 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 20  RPOSE.  See the 
01b0: 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20 50  GNU.** General P
01c0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66 6f  ublic License fo
01d0: 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e 0a  r more details..
01e0: 2a 2a 20 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c  ** .** You shoul
01f0: 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20  d have received 
0200: 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e  a copy of the GN
0210: 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63  U General Public
0220: 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e  .** License alon
0230: 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72  g with this libr
0240: 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69  ary; if not, wri
0250: 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65  te to the.** Fre
0260: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
0270: 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20  ation, Inc., 59 
0280: 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53  Temple Place - S
0290: 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73  uite 330,.** Bos
02a0: 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31  ton, MA  02111-1
02b0: 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20  307, USA..**.** 
02c0: 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69  Author contact i
02d0: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20  nformation:.**  
02e0: 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a   drh@hwaci.com.*
02f0: 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68  *   http://www.h
0300: 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a  waci.com/drh/.**
0310: 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  .***************
0320: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0330: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0340: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0350: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0360: 0a 2a 2a 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 20 46  ontent, exists F
0540: 52 4f 4d 20 75 6e 64 6f 20 57 48 45 52 45 20 70  ROM undo WHERE p
0550: 61 74 68 6e 61 6d 65 3d 25 51 20 41 4e 44 20 72  athname=%Q AND r
0560: 65 64 6f 66 6c 61 67 3d 25 64 22 2c 0a 20 20 20  edoflag=%d",.   
0570: 20 20 7a 50 61 74 68 6e 61 6d 65 2c 20 72 65 64    zPathname, red
0580: 6f 46 6c 61 67 0a 20 20 29 3b 0a 20 20 69 66 28  oFlag.  );.  if(
0590: 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51   db_step(&q)==SQ
05a0: 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20  LITE_ROW ){.    
05b0: 69 6e 74 20 6f 6c 64 5f 65 78 69 73 74 73 3b 0a  int old_exists;.
05c0: 20 20 20 20 69 6e 74 20 6e 65 77 5f 65 78 69 73      int new_exis
05d0: 74 73 3b 0a 20 20 20 20 42 6c 6f 62 20 63 75 72  ts;.    Blob cur
05e0: 72 65 6e 74 3b 0a 20 20 20 20 42 6c 6f 62 20 6e  rent;.    Blob n
05f0: 65 77 3b 0a 20 20 20 20 7a 46 75 6c 6c 6e 61 6d  ew;.    zFullnam
0600: 65 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 2f  e = mprintf("%s/
0610: 25 73 22 2c 20 67 2e 7a 4c 6f 63 61 6c 52 6f 6f  %s", g.zLocalRoo
0620: 74 2c 20 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20  t, zPathname);. 
0630: 20 20 20 6e 65 77 5f 65 78 69 73 74 73 20 3d 20     new_exists = 
0640: 66 69 6c 65 5f 73 69 7a 65 28 7a 46 75 6c 6c 6e  file_size(zFulln
0650: 61 6d 65 29 3e 3d 30 3b 0a 20 20 20 20 69 66 28  ame)>=0;.    if(
0660: 20 6e 65 77 5f 65 78 69 73 74 73 20 29 7b 0a 20   new_exists ){. 
0670: 20 20 20 20 20 62 6c 6f 62 5f 72 65 61 64 5f 66       blob_read_f
0680: 72 6f 6d 5f 66 69 6c 65 28 26 63 75 72 72 65 6e  rom_file(&curren
0690: 74 2c 20 7a 46 75 6c 6c 6e 61 6d 65 29 3b 0a 20  t, zFullname);. 
06a0: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20     }else{.      
06b0: 62 6c 6f 62 5f 7a 65 72 6f 28 26 63 75 72 72 65  blob_zero(&curre
06c0: 6e 74 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 62  nt);.    }.    b
06d0: 6c 6f 62 5f 7a 65 72 6f 28 26 6e 65 77 29 3b 0a  lob_zero(&new);.
06e0: 20 20 20 20 6f 6c 64 5f 65 78 69 73 74 73 20 3d      old_exists =
06f0: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26   db_column_int(&
0700: 71 2c 20 31 29 3b 0a 20 20 20 20 69 66 28 20 6f  q, 1);.    if( o
0710: 6c 64 5f 65 78 69 73 74 73 20 29 7b 0a 20 20 20  ld_exists ){.   
0720: 20 20 20 64 62 5f 65 70 68 65 6d 65 72 61 6c 5f     db_ephemeral_
0730: 62 6c 6f 62 28 26 71 2c 20 30 2c 20 26 6e 65 77  blob(&q, 0, &new
0740: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 70 72 69  );.    }.    pri
0750: 6e 74 66 28 22 25 73 64 6f 20 63 68 61 6e 67 65  ntf("%sdo change
0760: 73 20 74 6f 20 25 73 5c 6e 22 2c 20 72 65 64 6f  s to %s\n", redo
0770: 46 6c 61 67 20 3f 20 22 52 65 22 20 3a 20 22 55  Flag ? "Re" : "U
0780: 6e 22 2c 20 7a 50 61 74 68 6e 61 6d 65 29 3b 0a  n", zPathname);.
0790: 20 20 20 20 69 66 28 20 6f 6c 64 5f 65 78 69 73      if( old_exis
07a0: 74 73 20 29 7b 0a 20 20 20 20 20 20 69 66 28 20  ts ){.      if( 
07b0: 6e 65 77 5f 65 78 69 73 74 73 20 29 7b 0a 20 20  new_exists ){.  
07c0: 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 25 73        printf("%s
07d0: 20 25 73 5c 6e 22 2c 20 72 65 64 6f 46 6c 61 67   %s\n", redoFlag
07e0: 20 3f 20 22 52 45 44 4f 22 20 3a 20 22 55 4e 44   ? "REDO" : "UND
07f0: 4f 22 2c 20 7a 50 61 74 68 6e 61 6d 65 29 3b 0a  O", zPathname);.
0800: 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20        }else{.   
0810: 20 20 20 20 20 70 72 69 6e 74 66 28 22 4e 45 57       printf("NEW
0820: 20 25 73 5c 6e 22 2c 20 7a 50 61 74 68 6e 61 6d   %s\n", zPathnam
0830: 65 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20  e);.      }.    
0840: 20 20 62 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f    blob_write_to_
0850: 66 69 6c 65 28 26 6e 65 77 2c 20 7a 46 75 6c 6c  file(&new, zFull
0860: 6e 61 6d 65 29 3b 0a 20 20 20 20 7d 65 6c 73 65  name);.    }else
0870: 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28 22  {.      printf("
0880: 44 45 4c 45 54 45 20 25 73 5c 6e 22 2c 20 7a 50  DELETE %s\n", zP
0890: 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20 20 20  athname);.      
08a0: 75 6e 6c 69 6e 6b 28 7a 46 75 6c 6c 6e 61 6d 65  unlink(zFullname
08b0: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 62 6c 6f  );.    }.    blo
08c0: 62 5f 72 65 73 65 74 28 26 6e 65 77 29 3b 0a 20  b_reset(&new);. 
08d0: 20 20 20 66 72 65 65 28 7a 46 75 6c 6c 6e 61 6d     free(zFullnam
08e0: 65 29 3b 0a 20 20 20 20 64 62 5f 66 69 6e 61 6c  e);.    db_final
08f0: 69 7a 65 28 26 71 29 3b 0a 20 20 20 20 64 62 5f  ize(&q);.    db_
0900: 70 72 65 70 61 72 65 28 26 71 2c 20 0a 20 20 20  prepare(&q, .   
0910: 20 20 20 20 22 55 50 44 41 54 45 20 75 6e 64 6f      "UPDATE undo
0920: 20 53 45 54 20 63 6f 6e 74 65 6e 74 3d 3a 63 2c   SET content=:c,
0930: 20 65 78 69 73 74 73 66 6c 61 67 3d 25 64 2c 20   existsflag=%d, 
0940: 72 65 64 6f 66 6c 61 67 3d 4e 4f 54 20 72 65 64  redoflag=NOT red
0950: 6f 66 6c 61 67 22 0a 20 20 20 20 20 20 20 22 20  oflag".       " 
0960: 57 48 45 52 45 20 70 61 74 68 6e 61 6d 65 3d 25  WHERE pathname=%
0970: 51 22 2c 0a 20 20 20 20 20 20 20 6e 65 77 5f 65  Q",.       new_e
0980: 78 69 73 74 73 2c 20 7a 50 61 74 68 6e 61 6d 65  xists, zPathname
0990: 0a 20 20 20 20 29 3b 0a 20 20 20 20 69 66 28 20  .    );.    if( 
09a0: 6e 65 77 5f 65 78 69 73 74 73 20 29 7b 0a 20 20  new_exists ){.  
09b0: 20 20 20 20 64 62 5f 62 69 6e 64 5f 62 6c 6f 62      db_bind_blob
09c0: 28 26 71 2c 20 22 3a 63 22 2c 20 26 63 75 72 72  (&q, ":c", &curr
09d0: 65 6e 74 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20  ent);.    }.    
09e0: 64 62 5f 73 74 65 70 28 26 71 29 3b 0a 20 20 20  db_step(&q);.   
09f0: 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 63 75 72   blob_reset(&cur
0a00: 72 65 6e 74 29 3b 0a 20 20 7d 0a 20 20 64 62 5f  rent);.  }.  db_
0a10: 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 7d 0a  finalize(&q);.}.
0a20: 0a 2f 2a 0a 2a 2a 20 55 6e 64 6f 20 6f 72 20 72  ./*.** Undo or r
0a30: 65 64 6f 20 61 6c 6c 20 75 6e 64 6f 61 62 6c 65  edo all undoable
0a40: 20 6f 72 20 72 65 64 6f 61 62 6c 65 20 63 68 61   or redoable cha
0a50: 6e 67 65 73 2e 0a 2a 2f 0a 73 74 61 74 69 63 20  nges..*/.static 
0a60: 76 6f 69 64 20 75 6e 64 6f 5f 61 6c 6c 28 69 6e  void undo_all(in
0a70: 74 20 72 65 64 6f 46 6c 61 67 29 7b 0a 20 20 53  t redoFlag){.  S
0a80: 74 6d 74 20 71 3b 0a 20 20 64 62 5f 70 72 65 70  tmt q;.  db_prep
0a90: 61 72 65 28 26 71 2c 20 22 53 45 4c 45 43 54 20  are(&q, "SELECT 
0aa0: 70 61 74 68 6e 61 6d 65 20 46 52 4f 4d 20 75 6e  pathname FROM un
0ab0: 64 6f 20 57 48 45 52 45 20 72 65 64 6f 66 6c 61  do WHERE redofla
0ac0: 67 3d 25 64 22 0a 20 20 20 20 20 20 20 20 20 20  g=%d".          
0ad0: 20 20 20 20 20 20 20 22 20 4f 52 44 45 52 20 42         " ORDER B
0ae0: 59 20 2b 70 61 74 68 6e 61 6d 65 22 2c 20 72 65  Y +pathname", re
0af0: 64 6f 46 6c 61 67 29 3b 0a 20 20 77 68 69 6c 65  doFlag);.  while
0b00: 28 20 64 62 5f 73 74 65 70 28 26 71 29 20 29 7b  ( db_step(&q) ){
0b10: 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20  .    const char 
0b20: 2a 7a 50 61 74 68 6e 61 6d 65 20 3d 20 64 62 5f  *zPathname = db_
0b30: 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20  column_text(&q, 
0b40: 30 29 3b 0a 20 20 20 20 75 6e 64 6f 5f 6f 6e 65  0);.    undo_one
0b50: 28 7a 50 61 74 68 6e 61 6d 65 2c 20 72 65 64 6f  (zPathname, redo
0b60: 46 6c 61 67 29 3b 0a 20 20 7d 0a 20 20 64 62 5f  Flag);.  }.  db_
0b70: 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20  finalize(&q);.  
0b80: 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20  db_multi_exec(. 
0b90: 20 20 20 22 43 52 45 41 54 45 20 54 45 4d 50 20     "CREATE TEMP 
0ba0: 54 41 42 4c 45 20 75 6e 64 6f 5f 76 66 69 6c 65  TABLE undo_vfile
0bb0: 5f 32 20 41 53 20 53 45 4c 45 43 54 20 2a 20 46  _2 AS SELECT * F
0bc0: 52 4f 4d 20 76 66 69 6c 65 3b 22 0a 20 20 20 20  ROM vfile;".    
0bd0: 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 76 66 69  "DELETE FROM vfi
0be0: 6c 65 3b 22 0a 20 20 20 20 22 49 4e 53 45 52 54  le;".    "INSERT
0bf0: 20 49 4e 54 4f 20 76 66 69 6c 65 20 53 45 4c 45   INTO vfile SELE
0c00: 43 54 20 2a 20 46 52 4f 4d 20 75 6e 64 6f 5f 76  CT * FROM undo_v
0c10: 66 69 6c 65 3b 22 0a 20 20 20 20 22 44 45 4c 45  file;".    "DELE
0c20: 54 45 20 46 52 4f 4d 20 75 6e 64 6f 5f 76 66 69  TE FROM undo_vfi
0c30: 6c 65 3b 22 0a 20 20 20 20 22 49 4e 53 45 52 54  le;".    "INSERT
0c40: 20 49 4e 54 4f 20 75 6e 64 6f 5f 76 66 69 6c 65   INTO undo_vfile
0c50: 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 75   SELECT * FROM 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 44 52 4f 50 20 54 41 42 4c 45 20 75 6e    "DROP TABLE un
0c80: 64 6f 5f 76 66 69 6c 65 5f 32 3b 22 0a 20 20 20  do_vfile_2;".   
0c90: 20 22 43 52 45 41 54 45 20 54 45 4d 50 20 54 41   "CREATE TEMP TA
0ca0: 42 4c 45 20 75 6e 64 6f 5f 76 6d 65 72 67 65 5f  BLE undo_vmerge_
0cb0: 32 20 41 53 20 53 45 4c 45 43 54 20 2a 20 46 52  2 AS SELECT * FR
0cc0: 4f 4d 20 76 6d 65 72 67 65 3b 22 0a 20 20 20 20  OM vmerge;".    
0cd0: 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 76 6d 65  "DELETE FROM vme
0ce0: 72 67 65 3b 22 0a 20 20 20 20 22 49 4e 53 45 52  rge;".    "INSER
0cf0: 54 20 49 4e 54 4f 20 76 6d 65 72 67 65 20 53 45  T INTO vmerge SE
0d00: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 75 6e 64 6f  LECT * FROM undo
0d10: 5f 76 6d 65 72 67 65 3b 22 0a 20 20 20 20 22 44  _vmerge;".    "D
0d20: 45 4c 45 54 45 20 46 52 4f 4d 20 75 6e 64 6f 5f  ELETE FROM undo_
0d30: 76 6d 65 72 67 65 3b 22 0a 20 20 20 20 22 49 4e  vmerge;".    "IN
0d40: 53 45 52 54 20 49 4e 54 4f 20 75 6e 64 6f 5f 76  SERT INTO undo_v
0d50: 6d 65 72 67 65 20 53 45 4c 45 43 54 20 2a 20 46  merge SELECT * F
0d60: 52 4f 4d 20 75 6e 64 6f 5f 76 6d 65 72 67 65 5f  ROM undo_vmerge_
0d70: 32 3b 22 0a 20 20 20 20 22 44 52 4f 50 20 54 41  2;".    "DROP TA
0d80: 42 4c 45 20 75 6e 64 6f 5f 76 6d 65 72 67 65 5f  BLE undo_vmerge_
0d90: 32 3b 22 0a 20 20 29 3b 0a 7d 0a 0a 2f 2a 0a 2a  2;".  );.}../*.*
0da0: 2a 20 52 65 73 65 74 20 74 68 65 20 74 68 65 20  * Reset the the 
0db0: 75 6e 64 6f 20 6d 65 6d 6f 72 79 2e 0a 2a 2f 0a  undo memory..*/.
0dc0: 76 6f 69 64 20 75 6e 64 6f 5f 72 65 73 65 74 28  void undo_reset(
0dd0: 76 6f 69 64 29 7b 0a 20 20 73 74 61 74 69 63 20  void){.  static 
0de0: 63 6f 6e 73 74 20 63 68 61 72 20 7a 53 71 6c 5b  const char zSql[
0df0: 5d 20 3d 0a 20 20 20 20 40 20 44 52 4f 50 20 54  ] =.    @ DROP T
0e00: 41 42 4c 45 20 49 46 20 45 58 49 53 54 53 20 75  ABLE IF EXISTS u
0e10: 6e 64 6f 3b 0a 20 20 20 20 40 20 44 52 4f 50 20  ndo;.    @ DROP 
0e20: 54 41 42 4c 45 20 49 46 20 45 58 49 53 54 53 20  TABLE IF EXISTS 
0e30: 75 6e 64 6f 5f 76 66 69 6c 65 3b 0a 20 20 20 20  undo_vfile;.    
0e40: 40 20 44 52 4f 50 20 54 41 42 4c 45 20 49 46 20  @ DROP TABLE IF 
0e50: 45 58 49 53 54 53 20 75 6e 64 6f 5f 76 6d 65 72  EXISTS undo_vmer
0e60: 67 65 3b 0a 20 20 20 20 3b 0a 20 20 64 62 5f 6d  ge;.    ;.  db_m
0e70: 75 6c 74 69 5f 65 78 65 63 28 7a 53 71 6c 29 3b  ulti_exec(zSql);
0e80: 0a 20 20 64 62 5f 6c 73 65 74 5f 69 6e 74 28 22  .  db_lset_int("
0e90: 75 6e 64 6f 5f 61 76 61 69 6c 61 62 6c 65 22 2c  undo_available",
0ea0: 20 30 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 42 65   0);.}../*.** Be
0eb0: 67 69 6e 20 63 61 70 74 75 72 69 6e 67 20 61 20  gin capturing a 
0ec0: 73 6e 61 70 73 68 6f 74 20 74 68 61 74 20 63 61  snapshot that ca
0ed0: 6e 20 62 65 20 75 6e 64 6f 6e 65 2e 0a 2a 2f 0a  n be undone..*/.
0ee0: 76 6f 69 64 20 75 6e 64 6f 5f 62 65 67 69 6e 28  void undo_begin(
0ef0: 76 6f 69 64 29 7b 0a 20 20 73 74 61 74 69 63 20  void){.  static 
0f00: 63 6f 6e 73 74 20 63 68 61 72 20 7a 53 71 6c 5b  const char zSql[
0f10: 5d 20 3d 20 0a 20 20 20 20 40 20 43 52 45 41 54  ] = .    @ CREAT
0f20: 45 20 54 41 42 4c 45 20 75 6e 64 6f 28 0a 20 20  E TABLE undo(.  
0f30: 20 20 40 20 20 20 70 61 74 68 6e 61 6d 65 20 54    @   pathname T
0f40: 45 58 54 20 55 4e 49 51 55 45 2c 20 20 20 20 20  EXT UNIQUE,     
0f50: 20 20 20 20 20 20 20 20 2d 2d 20 4e 61 6d 65 20          -- Name 
0f60: 6f 66 20 74 68 65 20 66 69 6c 65 0a 20 20 20 20  of the file.    
0f70: 40 20 20 20 72 65 64 6f 66 6c 61 67 20 42 4f 4f  @   redoflag BOO
0f80: 4c 45 41 4e 2c 20 20 20 20 20 20 20 20 20 20 20  LEAN,           
0f90: 20 20 20 20 20 20 2d 2d 20 30 20 66 6f 72 20 75        -- 0 for u
0fa0: 6e 64 6f 61 62 6c 65 2e 20 20 31 20 66 6f 72 20  ndoable.  1 for 
0fb0: 72 65 64 6f 61 62 6c 65 0a 20 20 20 20 40 20 20  redoable.    @  
0fc0: 20 65 78 69 73 74 73 66 6c 61 67 20 42 4f 4f 4c   existsflag BOOL
0fd0: 45 41 4e 2c 20 20 20 20 20 20 20 20 20 20 20 20  EAN,            
0fe0: 20 20 20 2d 2d 20 54 72 75 65 20 69 66 20 74 68     -- True if th
0ff0: 65 20 66 69 6c 65 20 65 78 69 73 74 73 0a 20 20  e file exists.  
1000: 20 20 40 20 20 20 63 6f 6e 74 65 6e 74 20 42 4c    @   content BL
1010: 4f 42 20 20 20 20 20 20 20 20 20 20 20 20 20 20  OB              
1020: 20 20 20 20 20 20 20 20 2d 2d 20 53 61 76 65 64          -- Saved
1030: 20 63 6f 6e 74 65 6e 74 0a 20 20 20 20 40 20 29   content.    @ )
1040: 3b 0a 20 20 20 20 40 20 43 52 45 41 54 45 20 54  ;.    @ CREATE T
1050: 41 42 4c 45 20 75 6e 64 6f 5f 76 66 69 6c 65 20  ABLE undo_vfile 
1060: 41 53 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d  AS SELECT * FROM
1070: 20 76 66 69 6c 65 3b 0a 20 20 20 20 40 20 43 52   vfile;.    @ CR
1080: 45 41 54 45 20 54 41 42 4c 45 20 75 6e 64 6f 5f  EATE TABLE undo_
1090: 76 66 69 6c 65 20 41 53 20 53 45 4c 45 43 54 20  vfile AS SELECT 
10a0: 2a 20 46 52 4f 4d 20 76 6d 65 72 67 65 3b 0a 20  * FROM vmerge;. 
10b0: 20 3b 0a 20 20 75 6e 64 6f 5f 72 65 73 65 74 28   ;.  undo_reset(
10c0: 29 3b 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78  );.  db_multi_ex
10d0: 65 63 28 7a 53 71 6c 29 3b 0a 20 20 64 62 5f 6c  ec(zSql);.  db_l
10e0: 73 65 74 5f 69 6e 74 28 22 75 6e 64 6f 5f 61 76  set_int("undo_av
10f0: 61 69 6c 61 62 6c 65 22 2c 20 31 29 3b 0a 7d 0a  ailable", 1);.}.
1100: 0a 2f 2a 0a 2a 2a 20 53 61 76 65 20 74 68 65 20  ./*.** Save the 
1110: 63 75 72 72 65 6e 74 20 63 6f 6e 74 65 6e 74 20  current content 
1120: 6f 66 20 74 68 65 20 66 69 6c 65 20 7a 50 61 74  of the file zPat
1130: 68 6e 61 6d 65 20 73 6f 20 74 68 61 74 20 69 74  hname so that it
1140: 0a 2a 2a 20 77 69 6c 6c 20 62 65 20 75 6e 64 6f  .** will be undo
1150: 61 62 6c 65 2e 20 20 54 68 65 20 6e 61 6d 65 20  able.  The name 
1160: 69 73 20 72 65 6c 61 74 69 76 65 20 74 6f 20 74  is relative to t
1170: 68 65 20 72 6f 6f 74 20 6f 66 20 74 68 65 0a 2a  he root of the.*
1180: 2a 20 74 72 65 65 2e 0a 2a 2f 0a 76 6f 69 64 20  * tree..*/.void 
1190: 75 6e 64 6f 5f 73 61 76 65 28 63 6f 6e 73 74 20  undo_save(const 
11a0: 63 68 61 72 20 2a 7a 50 61 74 68 6e 61 6d 65 29  char *zPathname)
11b0: 7b 0a 20 20 63 68 61 72 20 2a 7a 46 75 6c 6c 6e  {.  char *zFulln
11c0: 61 6d 65 3b 0a 20 20 42 6c 6f 62 20 63 6f 6e 74  ame;.  Blob cont
11d0: 65 6e 74 3b 0a 20 20 69 6e 74 20 65 78 69 73 74  ent;.  int exist
11e0: 73 46 6c 61 67 3b 0a 20 20 53 74 6d 74 20 71 3b  sFlag;.  Stmt q;
11f0: 0a 0a 20 20 7a 46 75 6c 6c 6e 61 6d 65 20 3d 20  ..  zFullname = 
1200: 6d 70 72 69 6e 74 66 28 22 25 73 2f 25 73 22 2c  mprintf("%s/%s",
1210: 20 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 2c 20 7a   g.zLocalRoot, z
1220: 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20 65 78 69  Pathname);.  exi
1230: 73 74 73 46 6c 61 67 20 3d 20 66 69 6c 65 5f 73  stsFlag = file_s
1240: 69 7a 65 28 7a 46 75 6c 6c 6e 61 6d 65 29 3e 3d  ize(zFullname)>=
1250: 30 3b 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28  0;.  db_prepare(
1260: 26 71 2c 0a 20 20 20 20 22 52 45 50 4c 41 43 45  &q,.    "REPLACE
1270: 20 49 4e 54 4f 20 75 6e 64 6f 28 70 61 74 68 6e   INTO undo(pathn
1280: 61 6d 65 2c 72 65 64 6f 66 6c 61 67 2c 65 78 69  ame,redoflag,exi
1290: 73 74 73 66 6c 61 67 2c 63 6f 6e 74 65 6e 74 29  stsflag,content)
12a0: 22 0a 20 20 20 20 22 20 56 41 4c 55 45 53 28 25  ".    " VALUES(%
12b0: 51 2c 30 2c 25 64 2c 3a 63 29 22 2c 0a 20 20 20  Q,0,%d,:c)",.   
12c0: 20 7a 50 61 74 68 6e 61 6d 65 2c 20 65 78 69 73   zPathname, exis
12d0: 74 73 46 6c 61 67 0a 20 20 29 3b 0a 20 20 69 66  tsFlag.  );.  if
12e0: 28 20 65 78 69 73 74 73 46 6c 61 67 20 29 7b 0a  ( existsFlag ){.
12f0: 20 20 20 20 62 6c 6f 62 5f 72 65 61 64 5f 66 72      blob_read_fr
1300: 6f 6d 5f 66 69 6c 65 28 26 63 6f 6e 74 65 6e 74  om_file(&content
1310: 2c 20 7a 46 75 6c 6c 6e 61 6d 65 29 3b 0a 20 20  , zFullname);.  
1320: 20 20 64 62 5f 62 69 6e 64 5f 62 6c 6f 62 28 26    db_bind_blob(&
1330: 71 2c 20 22 3a 63 22 2c 20 26 63 6f 6e 74 65 6e  q, ":c", &conten
1340: 74 29 3b 0a 20 20 7d 0a 20 20 66 72 65 65 28 7a  t);.  }.  free(z
1350: 46 75 6c 6c 6e 61 6d 65 29 3b 0a 20 20 64 62 5f  Fullname);.  db_
1360: 73 74 65 70 28 26 71 29 3b 0a 20 20 64 62 5f 66  step(&q);.  db_f
1370: 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 62  inalize(&q);.  b
1380: 6c 6f 62 5f 72 65 73 65 74 28 26 63 6f 6e 74 65  lob_reset(&conte
1390: 6e 74 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f  nt);.}../*.** CO
13a0: 4d 4d 41 4e 44 3a 20 75 6e 64 6f 0a 2a 2a 0a 2a  MMAND: undo.**.*
13b0: 2a 20 55 73 61 67 65 3a 20 25 66 6f 73 73 69 6c  * Usage: %fossil
13c0: 20 75 6e 64 6f 20 3f 46 49 4c 45 4e 41 4d 45 2e   undo ?FILENAME.
13d0: 2e 2e 3f 0a 2a 2a 0a 2a 2a 20 55 6e 64 6f 20 74  ..?.**.** Undo t
13e0: 68 65 20 6d 6f 73 74 20 72 65 63 65 6e 74 20 75  he most recent u
13f0: 70 64 61 74 65 20 6f 72 20 6d 65 72 67 65 20 6f  pdate or merge o
1400: 70 65 72 61 74 69 6f 6e 2e 20 20 49 66 20 46 49  peration.  If FI
1410: 4c 45 4e 41 4d 45 20 69 73 0a 2a 2a 20 73 70 65  LENAME is.** spe
1420: 63 69 66 69 65 64 20 74 68 65 6e 20 72 65 73 74  cified then rest
1430: 6f 72 65 20 74 68 65 20 63 6f 6e 74 65 6e 74 20  ore the content 
1440: 6f 66 20 74 68 65 20 6e 61 6d 65 64 20 66 69 6c  of the named fil
1450: 65 28 73 29 20 62 75 74 20 6f 74 68 65 72 77 69  e(s) but otherwi
1460: 73 65 0a 2a 2a 20 6c 65 61 76 65 20 74 68 65 20  se.** leave the 
1470: 75 70 64 61 74 65 20 6f 72 20 6d 65 72 67 65 20  update or merge 
1480: 69 6e 20 65 66 66 65 63 74 2e 0a 2a 2a 0a 2a 2a  in effect..**.**
1490: 20 41 20 73 69 6e 67 6c 65 20 6c 65 76 65 6c 20   A single level 
14a0: 6f 66 20 75 6e 64 6f 2f 72 65 64 6f 20 69 73 20  of undo/redo is 
14b0: 73 75 70 70 6f 72 74 65 64 2e 20 20 54 68 65 20  supported.  The 
14c0: 75 6e 64 6f 2f 72 65 64 6f 20 73 74 61 63 6b 0a  undo/redo stack.
14d0: 2a 2a 20 69 73 20 63 6c 65 61 72 65 64 20 62 79  ** is cleared by
14e0: 20 74 68 65 20 63 6f 6d 6d 69 74 20 61 6e 64 20   the commit and 
14f0: 63 68 65 63 6b 6f 75 74 20 63 6f 6d 6d 61 6e 64  checkout command
1500: 73 2e 0a 2a 2f 0a 76 6f 69 64 20 75 6e 64 6f 5f  s..*/.void undo_
1510: 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 69 6e 74  cmd(void){.  int
1520: 20 75 6e 64 6f 5f 61 76 61 69 6c 61 62 6c 65 3b   undo_available;
1530: 0a 20 20 64 62 5f 6d 75 73 74 5f 62 65 5f 77 69  .  db_must_be_wi
1540: 74 68 69 6e 5f 74 72 65 65 28 29 3b 0a 20 20 64  thin_tree();.  d
1550: 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 61 63 74  b_begin_transact
1560: 69 6f 6e 28 29 3b 0a 20 20 75 6e 64 6f 5f 61 76  ion();.  undo_av
1570: 61 69 6c 61 62 6c 65 20 3d 20 64 62 5f 6c 67 65  ailable = db_lge
1580: 74 5f 69 6e 74 28 22 75 6e 64 6f 5f 61 76 61 69  t_int("undo_avai
1590: 6c 61 62 6c 65 22 2c 20 30 29 3b 0a 20 20 69 66  lable", 0);.  if
15a0: 28 20 67 2e 61 72 67 63 3d 3d 32 20 29 7b 0a 20  ( g.argc==2 ){. 
15b0: 20 20 20 69 66 28 20 75 6e 64 6f 5f 61 76 61 69     if( undo_avai
15c0: 6c 61 62 6c 65 21 3d 31 20 29 7b 0a 20 20 20 20  lable!=1 ){.    
15d0: 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22    fossil_fatal("
15e0: 6e 6f 20 75 70 64 61 74 65 20 6f 72 20 6d 65 72  no update or mer
15f0: 67 65 20 6f 70 65 72 61 74 69 6f 6e 20 69 73 20  ge operation is 
1600: 61 76 61 69 6c 61 62 6c 65 20 74 6f 20 75 6e 64  available to und
1610: 6f 22 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 75  o");.    }.    u
1620: 6e 64 6f 5f 61 6c 6c 28 30 29 3b 0a 20 20 20 20  ndo_all(0);.    
1630: 64 62 5f 6c 73 65 74 5f 69 6e 74 28 22 75 6e 64  db_lset_int("und
1640: 6f 5f 61 76 61 69 6c 61 62 6c 65 22 2c 20 32 29  o_available", 2)
1650: 3b 0a 20 20 7d 65 6c 73 65 20 69 66 28 20 67 2e  ;.  }else if( g.
1660: 61 72 67 63 3e 3d 33 20 29 7b 0a 20 20 20 20 69  argc>=3 ){.    i
1670: 6e 74 20 69 3b 0a 20 20 20 20 69 66 28 20 75 6e  nt i;.    if( un
1680: 64 6f 5f 61 76 61 69 6c 61 62 6c 65 3d 3d 30 20  do_available==0 
1690: 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f  ){.      fossil_
16a0: 66 61 74 61 6c 28 22 6e 6f 20 75 70 64 61 74 65  fatal("no update
16b0: 20 6f 72 20 6d 65 72 67 65 20 6f 70 65 72 61 74   or merge operat
16c0: 69 6f 6e 20 69 73 20 61 76 61 69 6c 61 62 6c 65  ion is available
16d0: 20 74 6f 20 75 6e 64 6f 22 29 3b 0a 20 20 20 20   to undo");.    
16e0: 7d 0a 20 20 20 20 66 6f 72 28 69 3d 32 3b 20 69  }.    for(i=2; i
16f0: 3c 67 2e 61 72 67 63 3b 20 69 2b 2b 29 7b 0a 20  <g.argc; i++){. 
1700: 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20       const char 
1710: 2a 7a 46 69 6c 65 20 3d 20 67 2e 61 72 67 76 5b  *zFile = g.argv[
1720: 69 5d 3b 0a 20 20 20 20 20 20 42 6c 6f 62 20 70  i];.      Blob p
1730: 61 74 68 3b 0a 20 20 20 20 20 20 66 69 6c 65 5f  ath;.      file_
1740: 74 72 65 65 5f 6e 61 6d 65 28 7a 46 69 6c 65 2c  tree_name(zFile,
1750: 20 26 70 61 74 68 29 3b 0a 20 20 20 20 20 20 75   &path);.      u
1760: 6e 64 6f 5f 6f 6e 65 28 62 6c 6f 62 5f 73 74 72  ndo_one(blob_str
1770: 28 26 70 61 74 68 29 2c 20 30 29 3b 0a 20 20 20  (&path), 0);.   
1780: 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 70     blob_reset(&p
1790: 61 74 68 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a  ath);.    }.  }.
17a0: 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63    db_end_transac
17b0: 74 69 6f 6e 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 2a  tion(0);.}../*.*
17c0: 2a 20 43 4f 4d 4d 41 4e 44 3a 20 72 65 64 6f 0a  * COMMAND: redo.
17d0: 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f  **.** Usage: %fo
17e0: 73 73 69 6c 20 72 65 64 6f 20 3f 46 49 4c 45 4e  ssil redo ?FILEN
17f0: 41 4d 45 2e 2e 2e 3f 0a 2a 2a 0a 2a 2a 20 52 65  AME...?.**.** Re
1800: 64 6f 20 74 68 65 20 61 6e 20 75 70 64 61 74 65  do the an update
1810: 20 6f 72 20 6d 65 72 67 65 20 6f 70 65 72 61 74   or merge operat
1820: 69 6f 6e 20 74 68 61 74 20 68 61 73 20 62 65 65  ion that has bee
1830: 6e 20 75 6e 64 6f 6e 65 20 62 79 20 74 68 65 0a  n undone by the.
1840: 2a 2a 20 75 6e 64 6f 20 63 6f 6d 6d 61 6e 64 2e  ** undo command.
1850: 20 20 49 66 20 46 49 4c 45 4e 41 4d 45 20 69 73    If FILENAME is
1860: 20 73 70 65 63 69 66 69 65 64 20 74 68 65 6e 20   specified then 
1870: 72 65 73 74 6f 72 65 20 74 68 65 20 63 68 61 6e  restore the chan
1880: 67 65 73 0a 2a 2a 20 61 73 73 6f 63 69 61 74 65  ges.** associate
1890: 64 20 77 69 74 68 20 74 68 65 20 6e 61 6d 65 64  d with the named
18a0: 20 66 69 6c 65 28 73 29 20 62 75 74 20 6f 74 68   file(s) but oth
18b0: 65 72 77 69 73 65 20 6c 65 61 76 65 20 74 68 65  erwise leave the
18c0: 20 75 70 64 61 74 65 0a 2a 2a 20 6f 72 20 6d 65   update.** or me
18d0: 72 67 65 20 75 6e 64 6f 6e 65 2e 0a 2a 2a 0a 2a  rge undone..**.*
18e0: 2a 20 41 20 73 69 6e 67 6c 65 20 6c 65 76 65 6c  * A single level
18f0: 20 6f 66 20 75 6e 64 6f 2f 72 65 64 6f 20 69 73   of undo/redo is
1900: 20 73 75 70 70 6f 72 74 65 64 2e 20 20 54 68 65   supported.  The
1910: 20 75 6e 64 6f 2f 72 65 64 6f 20 73 74 61 63 6b   undo/redo stack
1920: 0a 2a 2a 20 69 73 20 63 6c 65 61 72 65 64 20 62  .** is cleared b
1930: 79 20 74 68 65 20 63 6f 6d 6d 69 74 20 61 6e 64  y the commit and
1940: 20 63 68 65 63 6b 6f 75 74 20 63 6f 6d 6d 61 6e   checkout comman
1950: 64 73 2e 0a 2a 2f 0a 76 6f 69 64 20 72 65 64 6f  ds..*/.void redo
1960: 5f 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 69 6e  _cmd(void){.  in
1970: 74 20 75 6e 64 6f 5f 61 76 61 69 6c 61 62 6c 65  t undo_available
1980: 3b 0a 20 20 64 62 5f 6d 75 73 74 5f 62 65 5f 77  ;.  db_must_be_w
1990: 69 74 68 69 6e 5f 74 72 65 65 28 29 3b 0a 20 20  ithin_tree();.  
19a0: 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 61 63  db_begin_transac
19b0: 74 69 6f 6e 28 29 3b 0a 20 20 75 6e 64 6f 5f 61  tion();.  undo_a
19c0: 76 61 69 6c 61 62 6c 65 20 3d 20 64 62 5f 6c 67  vailable = db_lg
19d0: 65 74 5f 69 6e 74 28 22 75 6e 64 6f 5f 61 76 61  et_int("undo_ava
19e0: 69 6c 61 62 6c 65 22 2c 20 30 29 3b 0a 20 20 69  ilable", 0);.  i
19f0: 66 28 20 67 2e 61 72 67 63 3d 3d 32 20 29 7b 0a  f( g.argc==2 ){.
1a00: 20 20 20 20 69 66 28 20 75 6e 64 6f 5f 61 76 61      if( undo_ava
1a10: 69 6c 61 62 6c 65 21 3d 32 20 29 7b 0a 20 20 20  ilable!=2 ){.   
1a20: 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28     fossil_fatal(
1a30: 22 6e 6f 20 75 6e 64 6f 6e 65 20 75 70 64 61 74  "no undone updat
1a40: 65 20 6f 72 20 6d 65 72 67 65 20 6f 70 65 72 61  e or merge opera
1a50: 74 69 6f 6e 20 69 73 20 61 76 61 69 6c 61 62 6c  tion is availabl
1a60: 65 20 74 6f 20 72 65 64 6f 22 29 3b 0a 20 20 20  e to redo");.   
1a70: 20 7d 0a 20 20 20 20 75 6e 64 6f 5f 61 6c 6c 28   }.    undo_all(
1a80: 31 29 3b 0a 20 20 20 20 64 62 5f 6c 73 65 74 5f  1);.    db_lset_
1a90: 69 6e 74 28 22 75 6e 64 6f 5f 61 76 61 69 6c 61  int("undo_availa
1aa0: 62 6c 65 22 2c 20 31 29 3b 0a 20 20 7d 65 6c 73  ble", 1);.  }els
1ab0: 65 20 69 66 28 20 67 2e 61 72 67 63 3e 3d 33 20  e if( g.argc>=3 
1ac0: 29 7b 0a 20 20 20 20 69 6e 74 20 69 3b 0a 20 20  ){.    int i;.  
1ad0: 20 20 69 66 28 20 75 6e 64 6f 5f 61 76 61 69 6c    if( undo_avail
1ae0: 61 62 6c 65 3d 3d 30 20 29 7b 0a 20 20 20 20 20  able==0 ){.     
1af0: 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 6e   fossil_fatal("n
1b00: 6f 20 75 70 64 61 74 65 20 6f 72 20 6d 65 72 67  o update or merg
1b10: 65 20 6f 70 65 72 61 74 69 6f 6e 20 69 73 20 61  e operation is a
1b20: 76 61 69 6c 61 62 6c 65 20 74 6f 20 72 65 64 6f  vailable to redo
1b30: 22 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 66 6f  ");.    }.    fo
1b40: 72 28 69 3d 32 3b 20 69 3c 67 2e 61 72 67 63 3b  r(i=2; i<g.argc;
1b50: 20 69 2b 2b 29 7b 0a 20 20 20 20 20 20 63 6f 6e   i++){.      con
1b60: 73 74 20 63 68 61 72 20 2a 7a 46 69 6c 65 20 3d  st char *zFile =
1b70: 20 67 2e 61 72 67 76 5b 69 5d 3b 0a 20 20 20 20   g.argv[i];.    
1b80: 20 20 42 6c 6f 62 20 70 61 74 68 3b 0a 20 20 20    Blob path;.   
1b90: 20 20 20 66 69 6c 65 5f 74 72 65 65 5f 6e 61 6d     file_tree_nam
1ba0: 65 28 7a 46 69 6c 65 2c 20 26 70 61 74 68 29 3b  e(zFile, &path);
1bb0: 0a 20 20 20 20 20 20 75 6e 64 6f 5f 6f 6e 65 28  .      undo_one(
1bc0: 62 6c 6f 62 5f 73 74 72 28 26 70 61 74 68 29 2c  blob_str(&path),
1bd0: 20 30 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f   0);.      blob_
1be0: 72 65 73 65 74 28 26 70 61 74 68 29 3b 0a 20 20  reset(&path);.  
1bf0: 20 20 7d 0a 20 20 7d 0a 20 20 64 62 5f 65 6e 64    }.  }.  db_end
1c00: 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30 29 3b  _transaction(0);
1c10: 0a 7d 0a                                         .}.