Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Simplifications to the implementation of undo/redo. Add the --explain option to undo/redo that shows what would be undone or redone without actually doing anything. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
30981b64a4fcf74d2a0019d03c1e7479 |
| User & Date: | drh 2010-12-18 14:18:41.000 |
Context
|
2010-12-18
| ||
| 21:26 | Bring the "stash" enhancement into the trunk. check-in: 12a2a5eaf2 user: drh tags: trunk | |
| 17:24 | Begin adding code to implement the "stash" command. The code compiles and runs but is currently incomplete. This is an incremental check-in to preserve state. (Ironically, if "stash" were working, I'd have probably just done a "stash snapshot" to capture this state, rather than an experimental branch.) check-in: b3dadcc4a6 user: drh tags: experimental | |
| 14:18 | Simplifications to the implementation of undo/redo. Add the --explain option to undo/redo that shows what would be undone or redone without actually doing anything. check-in: 30981b64a4 user: drh tags: trunk | |
| 01:46 | Fix the tag propagator so that when a non-propagating tag overrides a propagating tag, the propagation is undo. Ticket [fcadf658ed282b3a2] check-in: 6007b2075c user: drh tags: trunk | |
Changes
Changes to src/merge.c.
| ︙ | ︙ | |||
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
/* Notation:
**
** V The current checkout
** M The version being merged in
** P The "pivot" - the most recent common ancestor of V and M.
*/
detailFlag = find_option("detail",0,0)!=0;
pickFlag = find_option("cherrypick",0,0)!=0;
backoutFlag = find_option("backout",0,0)!=0;
debugFlag = find_option("debug",0,0)!=0;
zBinGlob = find_option("binary",0,1);
nochangeFlag = find_option("nochange","n",0)!=0;
if( g.argc!=3 ){
| > | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
/* Notation:
**
** V The current checkout
** M The version being merged in
** P The "pivot" - the most recent common ancestor of V and M.
*/
undo_capture_command_line();
detailFlag = find_option("detail",0,0)!=0;
pickFlag = find_option("cherrypick",0,0)!=0;
backoutFlag = find_option("backout",0,0)!=0;
debugFlag = find_option("debug",0,0)!=0;
zBinGlob = find_option("binary",0,1);
nochangeFlag = find_option("nochange","n",0)!=0;
if( g.argc!=3 ){
|
| ︙ | ︙ |
Changes to src/undo.c.
| ︙ | ︙ | |||
131 132 133 134 135 136 137 |
** Reset the undo memory.
*/
void undo_reset(void){
static const char zSql[] =
@ DROP TABLE IF EXISTS undo;
@ DROP TABLE IF EXISTS undo_vfile;
@ DROP TABLE IF EXISTS undo_vmerge;
| < > > > > > > > > > > > > > > > > > > > > > > > | 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
** Reset the undo memory.
*/
void undo_reset(void){
static const char zSql[] =
@ DROP TABLE IF EXISTS undo;
@ 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);
}
/*
** The following variable stores the original command-line of the
** command that is a candidate to be undone.
*/
static char *undoCmd = 0;
/*
** Capture the current command-line and store it as part of the undo
** state. This routine is called before options are extracted from the
** command-line so that we can record the complete command-line.
*/
void undo_capture_command_line(void){
Blob cmdline;
int i;
assert( undoCmd==0 );
blob_zero(&cmdline);
for(i=1; i<g.argc; i++){
if( i>1 ) blob_append(&cmdline, " ", 1);
blob_append(&cmdline, g.argv[i], -1);
}
undoCmd = blob_str(&cmdline);
}
/*
** This flag is true if we are in the process of collecting file changes
** for undo. When this flag is false, undo_save() is a no-op.
*/
static int undoActive = 0;
|
| ︙ | ︙ | |||
159 160 161 162 163 164 165 |
@ 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 %s.undo_vfile AS SELECT * FROM vfile;
@ CREATE TABLE %s.undo_vmerge AS SELECT * FROM vmerge;
| < > | 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
@ 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 %s.undo_vfile AS SELECT * FROM vfile;
@ CREATE TABLE %s.undo_vmerge AS SELECT * FROM vmerge;
;
undo_reset();
if( strcmp(g.zMainDbType,zDb)==0 ) zDb = "main";
db_multi_exec(zSql, zDb, zDb, zDb, zDb);
cid = db_lget_int("checkout", 0);
db_lset_int("undo_checkout", cid);
db_lset_int("undo_available", 1);
db_lset("undo_cmdline", undoCmd);
undoActive = 1;
}
/*
** This flag is true if one or more files have changed and have been
** recorded in the undo log but the undo log has not yet been committed.
**
|
| ︙ | ︙ | |||
241 242 243 244 245 246 247 248 |
undoActive = 0;
printf("Rolling back prior filesystem changes...\n");
undo_all_filesystem(0);
}
/*
** COMMAND: undo
**
| > | > | > > > > > > > > | | < < < | | > | | | < | | | | | | < < < < | < < < < < < < < < < < | < < > > | > > | > | < > > > > | | | | | | | | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
undoActive = 0;
printf("Rolling back prior filesystem changes...\n");
undo_all_filesystem(0);
}
/*
** COMMAND: undo
** COMMAND: redo
**
** Usage: %fossil undo ?--explain? ?FILENAME...?
** or: %fossil redo ?--explain? ?FILENAME...?
**
** Undo the most recent update or merge or revert operation. 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 --explain option is present, not changes are made and instead
** the undo or redo command explains what actions the undo or redo would
** have done had the --explain been omitted.
**
** A single level of undo/redo is supported. The undo/redo stack
** is cleared by the commit and checkout commands.
*/
void undo_cmd(void){
int isRedo = g.argv[1][0]=='r';
int undo_available;
int explainFlag = find_option("explain", 0, 0)!=0;
const char *zCmd = isRedo ? "redo" : "undo";
db_must_be_within_tree();
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");
}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", "???"));
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);
}
nChng++;
printf("%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");
}
}
}else if( g.argc==2 ){
if( undo_available!=(1+isRedo) ){
fossil_fatal("nothing to %s", zCmd);
}
undo_all(isRedo);
db_lset_int("undo_available", 2-isRedo);
}else if( g.argc>=3 ){
int i;
if( undo_available==0 ){
fossil_fatal("nothing to %s", zCmd);
}
for(i=2; i<g.argc; i++){
const char *zFile = g.argv[i];
Blob path;
file_tree_name(zFile, &path, 1);
undo_one(blob_str(&path), isRedo);
blob_reset(&path);
}
}
db_end_transaction(0);
}
|
Changes to src/update.c.
| ︙ | ︙ | |||
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
int verboseFlag; /* -v or --verbose. Output extra information */
int debugFlag; /* --debug option */
int nChng; /* Number of file renames */
int *aChng; /* Array of file renames */
int i; /* Loop counter */
int nConflict = 0; /* Number of merge conflicts */
url_proxy_options();
latestFlag = find_option("latest",0, 0)!=0;
nochangeFlag = find_option("nochange","n",0)!=0;
verboseFlag = find_option("verbose","v",0)!=0;
debugFlag = find_option("debug",0,0)!=0;
db_must_be_within_tree();
vid = db_lget_int("checkout", 0);
| > | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
int verboseFlag; /* -v or --verbose. Output extra information */
int debugFlag; /* --debug option */
int nChng; /* Number of file renames */
int *aChng; /* Array of file renames */
int i; /* Loop counter */
int nConflict = 0; /* Number of merge conflicts */
undo_capture_command_line();
url_proxy_options();
latestFlag = find_option("latest",0, 0)!=0;
nochangeFlag = find_option("nochange","n",0)!=0;
verboseFlag = find_option("verbose","v",0)!=0;
debugFlag = find_option("debug",0,0)!=0;
db_must_be_within_tree();
vid = db_lget_int("checkout", 0);
|
| ︙ | ︙ | |||
462 463 464 465 466 467 468 | const char *zFile; const char *zRevision; Blob record; int i; int errCode; int rid = 0; Stmt q; | | > | 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
const char *zFile;
const char *zRevision;
Blob record;
int i;
int errCode;
int rid = 0;
Stmt q;
undo_capture_command_line();
zRevision = find_option("revision", "r", 1);
verify_all_options();
if( g.argc<2 ){
usage("?OPTIONS? [FILE] ...");
}
if( zRevision && g.argc<3 ){
|
| ︙ | ︙ |