Fossil SCM

Enchance the "revert" command so that it reverts all changes when no arguments are given. It also prints a message saying that "undo" is available to undo the revert.

drh 2010-01-14 16:17 trunk
Commit eaef1a77cc2f1145215c410cb984d0ed1e1042d3
1 file changed +43 -20
+43 -20
--- src/update.c
+++ src/update.c
@@ -348,38 +348,59 @@
348348
**
349349
** If a file is reverted accidently, it can be restored using
350350
** the "fossil undo" command.
351351
*/
352352
void revert_cmd(void){
353
- char *zFile;
353
+ const char *zFile;
354354
const char *zRevision;
355
- Blob fname;
356355
Blob record;
357356
int i;
358357
int errCode;
359358
int rid = 0;
359
+ Stmt q;
360360
361361
zRevision = find_option("revision", "r", 1);
362362
verify_all_options();
363363
364
- if( g.argc<3 ){
365
- usage("?OPTIONS? FILE ...");
364
+ if( g.argc<2 ){
365
+ usage("?OPTIONS? [FILE] ...");
366
+ }
367
+ if( zRevision && g.argc<3 ){
368
+ fossil_fatal("the --revision option does not work for the entire tree");
366369
}
367370
db_must_be_within_tree();
368371
db_begin_transaction();
369372
undo_begin();
370
-
371
- blob_zero(&record);
372
- for(i=2; i<g.argc; i++){
373
- zFile = mprintf("%/", g.argv[i]);
374
- file_tree_name(zFile, &fname, 1);
375
-
376
- if( zRevision!=0 ){
377
- errCode = historical_version_of_file(zRevision, blob_str(&fname),
378
- &record, 2);
379
- }else{
380
- rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname);
373
+ db_multi_exec("CREATE TEMP TABLE torevert(name UNIQUE);");
374
+
375
+ if( g.argc>2 ){
376
+ for(i=2; i<g.argc; i++){
377
+ Blob fname;
378
+ zFile = mprintf("%/", g.argv[i]);
379
+ file_tree_name(zFile, &fname, 1);
380
+ db_multi_exec("REPLACE INTO torevert VALUES(%B)", &fname);
381
+ blob_reset(&fname);
382
+ }
383
+ }else{
384
+ int vid;
385
+ vid = db_lget_int("checkout", 0);
386
+ vfile_check_signature(vid, 0);
387
+ db_multi_exec(
388
+ "INSERT INTO torevert "
389
+ "SELECT pathname"
390
+ " FROM vfile "
391
+ " WHERE chnged OR deleted OR rid=0 OR pathname!=origname"
392
+ );
393
+ }
394
+ blob_zero(&record);
395
+ db_prepare(&q, "SELECT name FROM torevert");
396
+ while( db_step(&q)==SQLITE_ROW ){
397
+ zFile = db_column_text(&q, 0);
398
+ if( zRevision!=0 ){
399
+ errCode = historical_version_of_file(zRevision, zFile, &record, 2);
400
+ }else{
401
+ rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q", zFile);
381402
if( rid==0 ){
382403
errCode = 2;
383404
}else{
384405
content_get(rid, &record);
385406
errCode = 0;
@@ -387,16 +408,18 @@
387408
}
388409
389410
if( errCode==2 ){
390411
fossil_warning("file not in repository: %s", zFile);
391412
}else{
392
- undo_save(blob_str(&fname));
393
- blob_write_to_file(&record, zFile);
394
- printf("%s reverted\n", zFile);
413
+ char *zFull = mprintf("%//%/", g.zLocalRoot, zFile);
414
+ undo_save(zFile);
415
+ blob_write_to_file(&record, zFull);
416
+ printf("REVERTED: %s\n", zFile);
417
+ free(zFull);
395418
}
396419
blob_reset(&record);
397
- blob_reset(&fname);
398
- free(zFile);
399420
}
421
+ db_finalize(&q);
400422
undo_finish();
401423
db_end_transaction(0);
424
+ printf("\"fossil undo\" is available to undo the changes shown above.\n");
402425
}
403426
--- src/update.c
+++ src/update.c
@@ -348,38 +348,59 @@
348 **
349 ** If a file is reverted accidently, it can be restored using
350 ** the "fossil undo" command.
351 */
352 void revert_cmd(void){
353 char *zFile;
354 const char *zRevision;
355 Blob fname;
356 Blob record;
357 int i;
358 int errCode;
359 int rid = 0;
 
360
361 zRevision = find_option("revision", "r", 1);
362 verify_all_options();
363
364 if( g.argc<3 ){
365 usage("?OPTIONS? FILE ...");
 
 
 
366 }
367 db_must_be_within_tree();
368 db_begin_transaction();
369 undo_begin();
370
371 blob_zero(&record);
372 for(i=2; i<g.argc; i++){
373 zFile = mprintf("%/", g.argv[i]);
374 file_tree_name(zFile, &fname, 1);
375
376 if( zRevision!=0 ){
377 errCode = historical_version_of_file(zRevision, blob_str(&fname),
378 &record, 2);
379 }else{
380 rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381 if( rid==0 ){
382 errCode = 2;
383 }else{
384 content_get(rid, &record);
385 errCode = 0;
@@ -387,16 +408,18 @@
387 }
388
389 if( errCode==2 ){
390 fossil_warning("file not in repository: %s", zFile);
391 }else{
392 undo_save(blob_str(&fname));
393 blob_write_to_file(&record, zFile);
394 printf("%s reverted\n", zFile);
 
 
395 }
396 blob_reset(&record);
397 blob_reset(&fname);
398 free(zFile);
399 }
 
400 undo_finish();
401 db_end_transaction(0);
 
402 }
403
--- src/update.c
+++ src/update.c
@@ -348,38 +348,59 @@
348 **
349 ** If a file is reverted accidently, it can be restored using
350 ** the "fossil undo" command.
351 */
352 void revert_cmd(void){
353 const char *zFile;
354 const char *zRevision;
 
355 Blob record;
356 int i;
357 int errCode;
358 int rid = 0;
359 Stmt q;
360
361 zRevision = find_option("revision", "r", 1);
362 verify_all_options();
363
364 if( g.argc<2 ){
365 usage("?OPTIONS? [FILE] ...");
366 }
367 if( zRevision && g.argc<3 ){
368 fossil_fatal("the --revision option does not work for the entire tree");
369 }
370 db_must_be_within_tree();
371 db_begin_transaction();
372 undo_begin();
373 db_multi_exec("CREATE TEMP TABLE torevert(name UNIQUE);");
374
375 if( g.argc>2 ){
376 for(i=2; i<g.argc; i++){
377 Blob fname;
378 zFile = mprintf("%/", g.argv[i]);
379 file_tree_name(zFile, &fname, 1);
380 db_multi_exec("REPLACE INTO torevert VALUES(%B)", &fname);
381 blob_reset(&fname);
382 }
383 }else{
384 int vid;
385 vid = db_lget_int("checkout", 0);
386 vfile_check_signature(vid, 0);
387 db_multi_exec(
388 "INSERT INTO torevert "
389 "SELECT pathname"
390 " FROM vfile "
391 " WHERE chnged OR deleted OR rid=0 OR pathname!=origname"
392 );
393 }
394 blob_zero(&record);
395 db_prepare(&q, "SELECT name FROM torevert");
396 while( db_step(&q)==SQLITE_ROW ){
397 zFile = db_column_text(&q, 0);
398 if( zRevision!=0 ){
399 errCode = historical_version_of_file(zRevision, zFile, &record, 2);
400 }else{
401 rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q", zFile);
402 if( rid==0 ){
403 errCode = 2;
404 }else{
405 content_get(rid, &record);
406 errCode = 0;
@@ -387,16 +408,18 @@
408 }
409
410 if( errCode==2 ){
411 fossil_warning("file not in repository: %s", zFile);
412 }else{
413 char *zFull = mprintf("%//%/", g.zLocalRoot, zFile);
414 undo_save(zFile);
415 blob_write_to_file(&record, zFull);
416 printf("REVERTED: %s\n", zFile);
417 free(zFull);
418 }
419 blob_reset(&record);
 
 
420 }
421 db_finalize(&q);
422 undo_finish();
423 db_end_transaction(0);
424 printf("\"fossil undo\" is available to undo the changes shown above.\n");
425 }
426

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button