Fossil SCM

Allow the deletion of multiple stash entries using "fossil stash rm" with multiple arguments. Multi-stash deletion is undoable.

drh 2012-10-25 13:59 trunk
Commit f41308d7800a96da130f31167eeb8f70e71dd1a2
2 files changed +10 -3 +6 -4
+10 -3
--- src/stash.c
+++ src/stash.c
@@ -560,22 +560,29 @@
560560
if( fDetail ) db_finalize(&q2);
561561
if( n==0 ) fossil_print("empty stash\n");
562562
}else
563563
if( memcmp(zCmd, "drop", nCmd)==0 || memcmp(zCmd, "rm", nCmd)==0 ){
564564
int allFlag = find_option("all", 0, 0)!=0;
565
- if( g.argc>4 ) usage("drop STASHID");
566565
if( allFlag ){
567566
Blob ans;
568567
blob_zero(&ans);
569568
prompt_user("This action is not undoable. Continue (y/N)? ", &ans);
570569
if( blob_str(&ans)[0]=='y' ){
571570
db_multi_exec("DELETE FROM stash; DELETE FROM stashfile;");
572571
}
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();
573581
}else{
574
- stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
575582
undo_begin();
576
- undo_save_stash(stashid);
583
+ undo_save_stash(0);
577584
stash_drop(stashid);
578585
undo_finish();
579586
}
580587
}else
581588
if( memcmp(zCmd, "pop", nCmd)==0 ){
582589
--- 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 @@
301301
** Make the current state of stashid undoable.
302302
*/
303303
void undo_save_stash(int stashid){
304304
const char *zDb = db_name("localdb");
305305
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"
308309
" SELECT * FROM stash WHERE stashid=%d;",
309310
zDb, stashid
310311
);
311312
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"
314316
" SELECT * FROM stashfile WHERE stashid=%d;",
315317
zDb, stashid
316318
);
317319
}
318320
319321
--- 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

Keyboard Shortcuts

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