| ︙ | | |
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
-
+
+
+
+
+
+
-
+
+
-
-
+
+
+
+
-
+
-
+
-
+
-
+
+
-
-
+
+
-
+
+
-
+
|
** true the redo a change. If there is nothing to undo (or redo) then
** this routine is a noop.
*/
static void undo_one(const char *zPathname, int redoFlag){
Stmt q;
char *zFullname;
db_prepare(&q,
"SELECT content, existsflag, islink FROM undo WHERE pathname=%Q AND redoflag=%d",
"SELECT content, existsflag, isExe, isLink FROM undo"
" WHERE pathname=%Q AND redoflag=%d",
zPathname, redoFlag
);
if( db_step(&q)==SQLITE_ROW ){
int old_exists;
int new_exists;
int old_exe;
int new_exe;
int new_link;
int old_link;
Blob current;
Blob new;
int isLink = db_column_int(&q, 2);
zFullname = mprintf("%s/%s", g.zLocalRoot, zPathname);
old_link = db_column_int(&q, 3);
new_link = file_islink(zFullname);
new_exists = file_size(zFullname)>=0;
int isNewLink = file_islink(zFullname);
if( new_exists ){
if( isNewLink ){
if( new_link ){
blob_read_link(¤t, zFullname);
}else{
blob_read_from_file(¤t, zFullname);
}
new_exe = file_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);
if( old_exists ){
db_ephemeral_blob(&q, 0, &new);
}
if( old_exists ){
if( new_exists ){
printf("%s %s\n", redoFlag ? "REDO" : "UNDO", zPathname);
fossil_print("%s %s\n", redoFlag ? "REDO" : "UNDO", zPathname);
}else{
printf("NEW %s\n", zPathname);
fossil_print("NEW %s\n", zPathname);
}
if( new_exists && (isNewLink || isLink) ){
if( new_exists && (new_link || old_link) ){
unlink(zFullname);
}
if( isLink ){
if( new_link ){
create_symlink(blob_str(&new), zFullname);
}else{
blob_write_to_file(&new, zFullname);
}
file_setexe(zFullname, old_exe);
}else{
printf("DELETE %s\n", zPathname);
unlink(zFullname);
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, redoflag=NOT redoflag, islink=%d"
"UPDATE undo SET content=:c, existsflag=%d, isExe=%d, isLink=%d"
" redoflag=NOT redoflag"
" WHERE pathname=%Q",
new_exists, isNewLink, zPathname
new_exists, new_exe, new_link, zPathname
);
if( new_exists ){
db_bind_blob(&q, ":c", ¤t);
}
db_step(&q);
blob_reset(¤t);
}
|
| ︙ | | |
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
+
-
+
|
int cid;
const char *zDb = db_name("localdb");
static const char zSql[] =
@ CREATE TABLE %s.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
@ isLink BOOLEAN, -- True if the file is symlink
@ content BLOB -- Saved content
@ );
@ CREATE TABLE %s.undo_vfile AS SELECT * FROM vfile;
@ CREATE TABLE %s.undo_vmerge AS SELECT * FROM vmerge;
;
if( undoDisable ) return;
undo_reset();
|
| ︙ | | |
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
-
-
-
-
+
+
+
|
int existsFlag;
int isLink;
Stmt q;
if( !undoActive ) return;
zFullname = mprintf("%s%s", g.zLocalRoot, zPathname);
existsFlag = file_size(zFullname)>=0;
isLink = file_islink(zFullname);
db_prepare(&q,
"INSERT OR IGNORE INTO undo(pathname,redoflag,existsflag,islink,content)"
" VALUES(%Q,0,%d,%d,:c)",
zPathname, existsFlag, isLink
"INSERT OR IGNORE INTO undo(pathname,redoflag,existsflag,isExe,isLink,content)"
" VALUES(%Q,0,%d,%d,%d,:c)",
zPathname, existsFlag, file_isexe(zFullname), file_islink(zFullname)
);
if( existsFlag ){
if( isLink ){
blob_read_link(&content, zFullname);
}else{
blob_read_from_file(&content, zFullname);
}
|
| ︙ | | |
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
-
+
|
/*
** Complete the undo process is one is currently in process.
*/
void undo_finish(void){
if( undoActive ){
if( undoNeedRollback ){
printf("\"fossil undo\" is available to undo changes"
fossil_print("\"fossil undo\" is available to undo changes"
" to the working checkout.\n");
}
undoActive = 0;
undoNeedRollback = 0;
}
}
|
| ︙ | | |
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
-
+
|
** was locked or had permissions turned off.
*/
void undo_rollback(void){
if( !undoNeedRollback ) return;
assert( undoActive );
undoNeedRollback = 0;
undoActive = 0;
printf("Rolling back prior filesystem changes...\n");
fossil_print("Rolling back prior filesystem changes...\n");
undo_all_filesystem(0);
}
/*
** COMMAND: undo
** COMMAND: redo
**
|
| ︙ | | |
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
|
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
-
+
-
-
+
+
+
-
-
+
+
-
+
-
+
|
const char *zCmd = isRedo ? "redo" : "undo";
db_must_be_within_tree();
verify_all_options();
db_begin_transaction();
undo_available = db_lget_int("undo_available", 0);
if( explainFlag ){
if( undo_available==0 ){
printf("No undo or redo is available\n");
fossil_print("No undo or redo is available\n");
}else{
Stmt q;
int nChng = 0;
zCmd = undo_available==1 ? "undo" : "redo";
printf("A %s is available for the following command:\n\n %s %s\n\n",
zCmd, g.argv[0], db_lget("undo_cmdline", "???"));
fossil_print("A %s is available for the following command:\n\n"
" %s %s\n\n",
zCmd, g.argv[0], db_lget("undo_cmdline", "???"));
db_prepare(&q,
"SELECT existsflag, pathname FROM undo ORDER BY pathname"
);
while( db_step(&q)==SQLITE_ROW ){
if( nChng==0 ){
printf("The following file changes would occur if the "
"command above is %sne:\n\n", zCmd);
fossil_print("The following file changes would occur if the "
"command above is %sne:\n\n", zCmd);
}
nChng++;
printf("%s %s\n",
fossil_print("%s %s\n",
db_column_int(&q,0) ? "UPDATE" : "DELETE",
db_column_text(&q, 1)
);
}
db_finalize(&q);
if( nChng==0 ){
printf("No file changes would occur with this undo/redo.\n");
fossil_print("No file changes would occur with this undo/redo.\n");
}
}
}else{
int vid1 = db_lget_int("checkout", 0);
int vid2;
if( g.argc==2 ){
if( undo_available!=(1+isRedo) ){
|
| ︙ | | |
419
420
421
422
423
424
425
426
427
428
429
430
431
|
430
431
432
433
434
435
436
437
438
439
440
441
442
|
-
+
|
file_tree_name(zFile, &path, 1);
undo_one(blob_str(&path), isRedo);
blob_reset(&path);
}
}
vid2 = db_lget_int("checkout", 0);
if( vid1!=vid2 ){
printf("--------------------\n");
fossil_print("--------------------\n");
show_common_info(vid2, "updated-to:", 1, 0);
}
}
db_end_transaction(0);
}
|