| ︙ | | | ︙ | |
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
** merchantability or fitness for a particular purpose.
**
** Author contact information:
** drh@hwaci.com
** http://www.hwaci.com/drh/
**
*******************************************************************************
**
** This file implements the undo/redo functionality.
*/
#include "config.h"
#include "undo.h"
|
|
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
** merchantability or fitness for a particular purpose.
**
** Author contact information:
** drh@hwaci.com
** http://www.hwaci.com/drh/
**
*******************************************************************************
**
** This file implements the undo/redo functionality.
*/
#include "config.h"
#include "undo.h"
|
| ︙ | | | ︙ | |
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
int new_exe;
int new_link;
int old_link;
Blob current;
Blob new;
zFullname = mprintf("%s/%s", g.zLocalRoot, zPathname);
old_link = db_column_int(&q, 3);
new_link = file_wd_islink(zFullname);
new_exists = file_wd_size(zFullname)>=0;
if( new_exists ){
if( new_link ){
blob_read_link(¤t, zFullname);
}else{
blob_read_from_file(¤t, zFullname);
}
new_exe = file_wd_isexe(zFullname);
}else{
blob_zero(¤t);
new_exe = 0;
}
blob_zero(&new);
old_exists = db_column_int(&q, 1);
old_exe = db_column_int(&q, 2);
|
<
>
|
|
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
int new_exe;
int new_link;
int old_link;
Blob current;
Blob new;
zFullname = mprintf("%s/%s", g.zLocalRoot, zPathname);
old_link = db_column_int(&q, 3);
new_exists = file_wd_size(zFullname)>=0;
new_link = file_wd_islink(0);
if( new_exists ){
if( new_link ){
blob_read_link(¤t, zFullname);
}else{
blob_read_from_file(¤t, zFullname);
}
new_exe = file_wd_isexe(0);
}else{
blob_zero(¤t);
new_exe = 0;
}
blob_zero(&new);
old_exists = db_column_int(&q, 1);
old_exe = db_column_int(&q, 2);
|
| ︙ | | | ︙ | |
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
}else{
fossil_print("DELETE %s\n", zPathname);
file_delete(zFullname);
}
blob_reset(&new);
free(zFullname);
db_finalize(&q);
db_prepare(&q,
"UPDATE undo SET content=:c, existsflag=%d, isExe=%d, isLink=%d,"
" redoflag=NOT redoflag"
" WHERE pathname=%Q",
new_exists, new_exe, new_link, zPathname
);
if( new_exists ){
db_bind_blob(&q, ":c", ¤t);
|
|
|
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
}else{
fossil_print("DELETE %s\n", zPathname);
file_delete(zFullname);
}
blob_reset(&new);
free(zFullname);
db_finalize(&q);
db_prepare(&q,
"UPDATE undo SET content=:c, existsflag=%d, isExe=%d, isLink=%d,"
" redoflag=NOT redoflag"
" WHERE pathname=%Q",
new_exists, new_exe, new_link, zPathname
);
if( new_exists ){
db_bind_blob(&q, ":c", ¤t);
|
| ︙ | | | ︙ | |
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
/*
** Begin capturing a snapshot that can be undone.
*/
void undo_begin(void){
int cid;
const char *zDb = db_name("localdb");
static const char zSql[] =
@ CREATE TABLE "%w".undo(
@ pathname TEXT UNIQUE, -- Name of the file
@ redoflag BOOLEAN, -- 0 for undoable. 1 for redoable
@ existsflag BOOLEAN, -- True if the file exists
@ isExe BOOLEAN, -- True if the file is executable
@ isLink BOOLEAN, -- True if the file is symlink
@ content BLOB -- Saved content
|
|
|
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
/*
** Begin capturing a snapshot that can be undone.
*/
void undo_begin(void){
int cid;
const char *zDb = db_name("localdb");
static const char zSql[] =
@ CREATE TABLE "%w".undo(
@ pathname TEXT UNIQUE, -- Name of the file
@ redoflag BOOLEAN, -- 0 for undoable. 1 for redoable
@ existsflag BOOLEAN, -- True if the file exists
@ isExe BOOLEAN, -- True if the file is executable
@ isLink BOOLEAN, -- True if the file is symlink
@ content BLOB -- Saved content
|
| ︙ | | | ︙ | |
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
db_lset_int("undo_checkout", cid);
db_lset_int("undo_available", 1);
db_lset("undo_cmdline", undoCmd);
undoActive = 1;
}
/*
** Permanently disable undo
*/
void undo_disable(void){
undoDisable = 1;
}
/*
** This flag is true if one or more files have changed and have been
|
|
|
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
db_lset_int("undo_checkout", cid);
db_lset_int("undo_available", 1);
db_lset("undo_cmdline", undoCmd);
undoActive = 1;
}
/*
** Permanently disable undo
*/
void undo_disable(void){
undoDisable = 1;
}
/*
** This flag is true if one or more files have changed and have been
|
| ︙ | | | ︙ | |
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
"INSERT OR IGNORE INTO"
" undo(pathname,redoflag,existsflag,isExe,isLink,content)"
" VALUES(%Q,0,%d,%d,%d,:c)",
zPathname, existsFlag, file_wd_isexe(zFullname), isLink
);
if( existsFlag ){
if( isLink ){
blob_read_link(&content, zFullname);
}else{
blob_read_from_file(&content, zFullname);
}
db_bind_blob(&q, ":c", &content);
}
free(zFullname);
db_step(&q);
|
|
|
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
"INSERT OR IGNORE INTO"
" undo(pathname,redoflag,existsflag,isExe,isLink,content)"
" VALUES(%Q,0,%d,%d,%d,:c)",
zPathname, existsFlag, file_wd_isexe(zFullname), isLink
);
if( existsFlag ){
if( isLink ){
blob_read_link(&content, zFullname);
}else{
blob_read_from_file(&content, zFullname);
}
db_bind_blob(&q, ":c", &content);
}
free(zFullname);
db_step(&q);
|
| ︙ | | | ︙ | |
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
**
** (1) fossil update (5) fossil stash apply
** (2) fossil merge (6) fossil stash drop
** (3) fossil revert (7) fossil stash goto
** (4) fossil stash pop
**
** If FILENAME is specified then restore the content of the named
** file(s) but otherwise leave the update or merge or revert in effect.
** The redo command undoes the effect of the most recent undo.
**
** If the -n|--dry-run option is present, no changes are made and instead
** the undo or redo command explains what actions the undo or redo would
** have done had the -n|--dry-run been omitted.
**
** A single level of undo/redo is supported. The undo/redo stack
|
|
|
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
**
** (1) fossil update (5) fossil stash apply
** (2) fossil merge (6) fossil stash drop
** (3) fossil revert (7) fossil stash goto
** (4) fossil stash pop
**
** If FILENAME is specified then restore the content of the named
** file(s) but otherwise leave the update or merge or revert in effect.
** The redo command undoes the effect of the most recent undo.
**
** If the -n|--dry-run option is present, no changes are made and instead
** the undo or redo command explains what actions the undo or redo would
** have done had the -n|--dry-run been omitted.
**
** A single level of undo/redo is supported. The undo/redo stack
|
| ︙ | | | ︙ | |
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
);
while( db_step(&q)==SQLITE_ROW ){
if( nChng==0 ){
fossil_print("The following file changes would occur if the "
"command above is %sne:\n\n", zCmd);
}
nChng++;
fossil_print("%s %s\n",
db_column_int(&q,0) ? "UPDATE" : "DELETE",
db_column_text(&q, 1)
);
}
db_finalize(&q);
if( nChng==0 ){
fossil_print("No file changes would occur with this undo/redo.\n");
|
|
|
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
);
while( db_step(&q)==SQLITE_ROW ){
if( nChng==0 ){
fossil_print("The following file changes would occur if the "
"command above is %sne:\n\n", zCmd);
}
nChng++;
fossil_print("%s %s\n",
db_column_int(&q,0) ? "UPDATE" : "DELETE",
db_column_text(&q, 1)
);
}
db_finalize(&q);
if( nChng==0 ){
fossil_print("No file changes would occur with this undo/redo.\n");
|
| ︙ | | | ︙ | |