Check-in [6f5654c7ab]
Not logged in
Overview

SHA1 Hash:6f5654c7ab4b38848a362bda2c0422c369283233
Date: 2007-09-12 01:46:14
User: drh
Comment:Fix bugs in undo/redo. Appears to work now but not heavily tested.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/undo.c from [1e4377482c] to [e0974f5428].

@@ -36,11 +36,11 @@
 */
 static void undo_one(const char *zPathname, int redoFlag){
   Stmt q;
   char *zFullname;
   db_prepare(&q,
-    "SELECT content, exists FROM undo WHERE pathname=%Q AND redoflag=%d",
+    "SELECT content, existsflag FROM undo WHERE pathname=%Q AND redoflag=%d",
      zPathname, redoFlag
   );
   if( db_step(&q)==SQLITE_ROW ){
     int old_exists;
     int new_exists;
@@ -56,11 +56,10 @@
     blob_zero(&new);
     old_exists = db_column_int(&q, 1);
     if( old_exists ){
       db_ephemeral_blob(&q, 0, &new);
     }
-    printf("%sdo changes to %s\n", redoFlag ? "Re" : "Un", zPathname);
     if( old_exists ){
       if( new_exists ){
         printf("%s %s\n", redoFlag ? "REDO" : "UNDO", zPathname);
       }else{
         printf("NEW %s\n", zPathname);
@@ -90,13 +89,15 @@
 /*
 ** Undo or redo all undoable or redoable changes.
 */
 static void undo_all(int redoFlag){
   Stmt q;
+  int ucid;
+  int ncid;
   db_prepare(&q, "SELECT pathname FROM undo WHERE redoflag=%d"
                  " ORDER BY +pathname", redoFlag);
-  while( db_step(&q) ){
+  while( db_step(&q)==SQLITE_ROW ){
     const char *zPathname = db_column_text(&q, 0);
     undo_one(zPathname, redoFlag);
   }
   db_finalize(&q);
   db_multi_exec(
@@ -111,10 +112,14 @@
     "INSERT INTO vmerge SELECT * FROM undo_vmerge;"
     "DELETE FROM undo_vmerge;"
     "INSERT INTO undo_vmerge SELECT * FROM undo_vmerge_2;"
     "DROP TABLE undo_vmerge_2;"
   );
+  ncid = db_lget_int("undo_checkout", 0);
+  ucid = db_lget_int("checkout", 0);
+  db_lset_int("undo_checkout", ucid);
+  db_lset_int("checkout", ncid);
 }
 
 /*
 ** Reset the the undo memory.
 */
@@ -124,28 +129,32 @@
     @ DROP TABLE IF EXISTS undo_vfile;
     @ DROP TABLE IF EXISTS undo_vmerge;
     ;
   db_multi_exec(zSql);
   db_lset_int("undo_available", 0);
+  db_lset_int("undo_checkout", 0);
 }
 
 /*
 ** Begin capturing a snapshot that can be undone.
 */
 void undo_begin(void){
+  int cid;
   static const char zSql[] =
     @ CREATE TABLE undo(
     @   pathname TEXT UNIQUE,             -- Name of the file
     @   redoflag BOOLEAN,                 -- 0 for undoable.  1 for redoable
     @   existsflag BOOLEAN,               -- True if the file exists
     @   content BLOB                      -- Saved content
     @ );
     @ CREATE TABLE undo_vfile AS SELECT * FROM vfile;
-    @ CREATE TABLE undo_vfile AS SELECT * FROM vmerge;
+    @ CREATE TABLE undo_vmerge AS SELECT * FROM vmerge;
   ;
   undo_reset();
   db_multi_exec(zSql);
+  cid = db_lget_int("checkout", 0);
+  db_lset_int("undo_checkout", cid);
   db_lset_int("undo_available", 1);
 }
 
 /*
 ** Save the current content of the file zPathname so that it
@@ -170,11 +179,13 @@
     db_bind_blob(&q, ":c", &content);
   }
   free(zFullname);
   db_step(&q);
   db_finalize(&q);
-  blob_reset(&content);
+  if( existsFlag ){
+    blob_reset(&content);
+  }
 }
 
 /*
 ** COMMAND: undo
 **