@@ -37,9 +37,9 @@
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;
@@ -57,9 +57,8 @@
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{
@@ -91,11 +90,13 @@
** 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);
@@ -112,8 +113,12 @@
"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.
@@ -125,14 +130,16 @@
@ 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
@@ -139,12 +146,14 @@
@ 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);
}
/*
@@ -171,9 +180,11 @@
}
free(zFullname);
db_step(&q);
db_finalize(&q);
- blob_reset(&content);
+ if( existsFlag ){
+ blob_reset(&content);
+ }
}
/*
** COMMAND: undo