Fossil SCM
Allow the deletion of multiple stash entries using "fossil stash rm" with multiple arguments. Multi-stash deletion is undoable.
Commit
f41308d7800a96da130f31167eeb8f70e71dd1a2
Parent
fb565614db96487…
2 files changed
+10
-3
+6
-4
+10
-3
| --- src/stash.c | ||
| +++ src/stash.c | ||
| @@ -560,22 +560,29 @@ | ||
| 560 | 560 | if( fDetail ) db_finalize(&q2); |
| 561 | 561 | if( n==0 ) fossil_print("empty stash\n"); |
| 562 | 562 | }else |
| 563 | 563 | if( memcmp(zCmd, "drop", nCmd)==0 || memcmp(zCmd, "rm", nCmd)==0 ){ |
| 564 | 564 | int allFlag = find_option("all", 0, 0)!=0; |
| 565 | - if( g.argc>4 ) usage("drop STASHID"); | |
| 566 | 565 | if( allFlag ){ |
| 567 | 566 | Blob ans; |
| 568 | 567 | blob_zero(&ans); |
| 569 | 568 | prompt_user("This action is not undoable. Continue (y/N)? ", &ans); |
| 570 | 569 | if( blob_str(&ans)[0]=='y' ){ |
| 571 | 570 | db_multi_exec("DELETE FROM stash; DELETE FROM stashfile;"); |
| 572 | 571 | } |
| 572 | + }else if( g.argc>=4 ){ | |
| 573 | + int i; | |
| 574 | + undo_begin(); | |
| 575 | + for(i=3; i<g.argc; i++){ | |
| 576 | + stashid = stash_get_id(g.argv[i]); | |
| 577 | + undo_save_stash(stashid); | |
| 578 | + stash_drop(stashid); | |
| 579 | + } | |
| 580 | + undo_finish(); | |
| 573 | 581 | }else{ |
| 574 | - stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0); | |
| 575 | 582 | undo_begin(); |
| 576 | - undo_save_stash(stashid); | |
| 583 | + undo_save_stash(0); | |
| 577 | 584 | stash_drop(stashid); |
| 578 | 585 | undo_finish(); |
| 579 | 586 | } |
| 580 | 587 | }else |
| 581 | 588 | if( memcmp(zCmd, "pop", nCmd)==0 ){ |
| 582 | 589 |
| --- src/stash.c | |
| +++ src/stash.c | |
| @@ -560,22 +560,29 @@ | |
| 560 | if( fDetail ) db_finalize(&q2); |
| 561 | if( n==0 ) fossil_print("empty stash\n"); |
| 562 | }else |
| 563 | if( memcmp(zCmd, "drop", nCmd)==0 || memcmp(zCmd, "rm", nCmd)==0 ){ |
| 564 | int allFlag = find_option("all", 0, 0)!=0; |
| 565 | if( g.argc>4 ) usage("drop STASHID"); |
| 566 | if( allFlag ){ |
| 567 | Blob ans; |
| 568 | blob_zero(&ans); |
| 569 | prompt_user("This action is not undoable. Continue (y/N)? ", &ans); |
| 570 | if( blob_str(&ans)[0]=='y' ){ |
| 571 | db_multi_exec("DELETE FROM stash; DELETE FROM stashfile;"); |
| 572 | } |
| 573 | }else{ |
| 574 | stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0); |
| 575 | undo_begin(); |
| 576 | undo_save_stash(stashid); |
| 577 | stash_drop(stashid); |
| 578 | undo_finish(); |
| 579 | } |
| 580 | }else |
| 581 | if( memcmp(zCmd, "pop", nCmd)==0 ){ |
| 582 |
| --- src/stash.c | |
| +++ src/stash.c | |
| @@ -560,22 +560,29 @@ | |
| 560 | if( fDetail ) db_finalize(&q2); |
| 561 | if( n==0 ) fossil_print("empty stash\n"); |
| 562 | }else |
| 563 | if( memcmp(zCmd, "drop", nCmd)==0 || memcmp(zCmd, "rm", nCmd)==0 ){ |
| 564 | int allFlag = find_option("all", 0, 0)!=0; |
| 565 | if( allFlag ){ |
| 566 | Blob ans; |
| 567 | blob_zero(&ans); |
| 568 | prompt_user("This action is not undoable. Continue (y/N)? ", &ans); |
| 569 | if( blob_str(&ans)[0]=='y' ){ |
| 570 | db_multi_exec("DELETE FROM stash; DELETE FROM stashfile;"); |
| 571 | } |
| 572 | }else if( g.argc>=4 ){ |
| 573 | int i; |
| 574 | undo_begin(); |
| 575 | for(i=3; i<g.argc; i++){ |
| 576 | stashid = stash_get_id(g.argv[i]); |
| 577 | undo_save_stash(stashid); |
| 578 | stash_drop(stashid); |
| 579 | } |
| 580 | undo_finish(); |
| 581 | }else{ |
| 582 | undo_begin(); |
| 583 | undo_save_stash(0); |
| 584 | stash_drop(stashid); |
| 585 | undo_finish(); |
| 586 | } |
| 587 | }else |
| 588 | if( memcmp(zCmd, "pop", nCmd)==0 ){ |
| 589 |
+6
-4
| --- src/undo.c | ||
| +++ src/undo.c | ||
| @@ -301,18 +301,20 @@ | ||
| 301 | 301 | ** Make the current state of stashid undoable. |
| 302 | 302 | */ |
| 303 | 303 | void undo_save_stash(int stashid){ |
| 304 | 304 | const char *zDb = db_name("localdb"); |
| 305 | 305 | db_multi_exec( |
| 306 | - "DROP TABLE IF EXISTS undo_stash;" | |
| 307 | - "CREATE TABLE %s.undo_stash AS" | |
| 306 | + "CREATE TABLE IF NOT EXISTS %s.undo_stash" | |
| 307 | + " AS SELECT * FROM stash WHERE 0;" | |
| 308 | + "INSERT INTO undo_stash" | |
| 308 | 309 | " SELECT * FROM stash WHERE stashid=%d;", |
| 309 | 310 | zDb, stashid |
| 310 | 311 | ); |
| 311 | 312 | db_multi_exec( |
| 312 | - "DROP TABLE IF EXISTS undo_stashfile;" | |
| 313 | - "CREATE TABLE %s.undo_stashfile AS" | |
| 313 | + "CREATE TABLE IF NOT EXISTS %s.undo_stashfile" | |
| 314 | + " AS SELECT * FROM stashfile WHERE 0;" | |
| 315 | + "INSERT INTO undo_stashfile" | |
| 314 | 316 | " SELECT * FROM stashfile WHERE stashid=%d;", |
| 315 | 317 | zDb, stashid |
| 316 | 318 | ); |
| 317 | 319 | } |
| 318 | 320 | |
| 319 | 321 |
| --- src/undo.c | |
| +++ src/undo.c | |
| @@ -301,18 +301,20 @@ | |
| 301 | ** Make the current state of stashid undoable. |
| 302 | */ |
| 303 | void undo_save_stash(int stashid){ |
| 304 | const char *zDb = db_name("localdb"); |
| 305 | db_multi_exec( |
| 306 | "DROP TABLE IF EXISTS undo_stash;" |
| 307 | "CREATE TABLE %s.undo_stash AS" |
| 308 | " SELECT * FROM stash WHERE stashid=%d;", |
| 309 | zDb, stashid |
| 310 | ); |
| 311 | db_multi_exec( |
| 312 | "DROP TABLE IF EXISTS undo_stashfile;" |
| 313 | "CREATE TABLE %s.undo_stashfile AS" |
| 314 | " SELECT * FROM stashfile WHERE stashid=%d;", |
| 315 | zDb, stashid |
| 316 | ); |
| 317 | } |
| 318 | |
| 319 |
| --- src/undo.c | |
| +++ src/undo.c | |
| @@ -301,18 +301,20 @@ | |
| 301 | ** Make the current state of stashid undoable. |
| 302 | */ |
| 303 | void undo_save_stash(int stashid){ |
| 304 | const char *zDb = db_name("localdb"); |
| 305 | db_multi_exec( |
| 306 | "CREATE TABLE IF NOT EXISTS %s.undo_stash" |
| 307 | " AS SELECT * FROM stash WHERE 0;" |
| 308 | "INSERT INTO undo_stash" |
| 309 | " SELECT * FROM stash WHERE stashid=%d;", |
| 310 | zDb, stashid |
| 311 | ); |
| 312 | db_multi_exec( |
| 313 | "CREATE TABLE IF NOT EXISTS %s.undo_stashfile" |
| 314 | " AS SELECT * FROM stashfile WHERE 0;" |
| 315 | "INSERT INTO undo_stashfile" |
| 316 | " SELECT * FROM stashfile WHERE stashid=%d;", |
| 317 | zDb, stashid |
| 318 | ); |
| 319 | } |
| 320 | |
| 321 |