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.
Commit
eaef1a77cc2f1145215c410cb984d0ed1e1042d3
Parent
81b0597fcdd66bd…
1 file changed
+43
-20
+43
-20
| --- src/update.c | ||
| +++ src/update.c | ||
| @@ -348,38 +348,59 @@ | ||
| 348 | 348 | ** |
| 349 | 349 | ** If a file is reverted accidently, it can be restored using |
| 350 | 350 | ** the "fossil undo" command. |
| 351 | 351 | */ |
| 352 | 352 | void revert_cmd(void){ |
| 353 | - char *zFile; | |
| 353 | + const char *zFile; | |
| 354 | 354 | const char *zRevision; |
| 355 | - Blob fname; | |
| 356 | 355 | Blob record; |
| 357 | 356 | int i; |
| 358 | 357 | int errCode; |
| 359 | 358 | int rid = 0; |
| 359 | + Stmt q; | |
| 360 | 360 | |
| 361 | 361 | zRevision = find_option("revision", "r", 1); |
| 362 | 362 | verify_all_options(); |
| 363 | 363 | |
| 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"); | |
| 366 | 369 | } |
| 367 | 370 | db_must_be_within_tree(); |
| 368 | 371 | db_begin_transaction(); |
| 369 | 372 | 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); | |
| 381 | 402 | if( rid==0 ){ |
| 382 | 403 | errCode = 2; |
| 383 | 404 | }else{ |
| 384 | 405 | content_get(rid, &record); |
| 385 | 406 | errCode = 0; |
| @@ -387,16 +408,18 @@ | ||
| 387 | 408 | } |
| 388 | 409 | |
| 389 | 410 | if( errCode==2 ){ |
| 390 | 411 | fossil_warning("file not in repository: %s", zFile); |
| 391 | 412 | }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); | |
| 395 | 418 | } |
| 396 | 419 | blob_reset(&record); |
| 397 | - blob_reset(&fname); | |
| 398 | - free(zFile); | |
| 399 | 420 | } |
| 421 | + db_finalize(&q); | |
| 400 | 422 | undo_finish(); |
| 401 | 423 | db_end_transaction(0); |
| 424 | + printf("\"fossil undo\" is available to undo the changes shown above.\n"); | |
| 402 | 425 | } |
| 403 | 426 |
| --- 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 |