Fossil Forum

fossil stash pop printing the stash message?
Login

fossil stash pop printing the stash message?

fossil stash pop printing the stash message?

(1) By Alfred M. Szmidt (ams) on 2022-08-04 10:52:29 [source]

Just a random idea, and not sure if it is a good one.

"fossil stash save" accepts a message, which is super useful, and "fossil stash ls" lists said message.. But when you "fossil stash pop" you get no mention of what you poped ... maybe it could print the message (and stash ID)?

I realise that there is some similarity to "fossil commit" and "fossil pop" -- and that "fossil commit" doesn't print the message (which you need to supply anwyay).

/Alfred

(2) By Stephan Beal (stephan) on 2022-08-04 11:02:17 in reply to 1 [link] [source]

maybe it could print the message (and stash ID)?

That's a great idea. If nobody's beaten me to it in about 12 hours i'll get that added for you tonight.

(3) By Stephan Beal (stephan) on 2022-08-04 23:55:40 in reply to 2 [link] [source]

If nobody's beaten me to it in about 12 hours i'll get that added for you tonight.

Follow-up: my initial implementation, in trying to introduce minimal changes, leads to locking errors because of the requirement for fetching the stash info while "undo" support is manipulating the stash. It needs to be scrapped and reimplemented. It's miserably hot here so i'm putting that on hold for the time being but will get back to it as temperature allows.

(4) By Alfred M. Szmidt (ams) on 2022-08-10 06:36:04 in reply to 3 [link] [source]

I gave it a shot, and ended up in a similar situation as you :-( This was a bit tricky.

(5) By Stephan Beal (stephan) on 2022-08-10 06:38:12 in reply to 4 [link] [source]

I gave it a shot, and ended up in a similar situation as you

Confirmation is good :). What needs to happen is the comment/date need to pulled out first and saved in allocated strings, then the stash processing, then the strings freed. If you're up to that, please do it. My proverbial plate is currently overflowing so i won't get to this for a while (but agree that it's a very useful addition, even if it's only cosmetic).

(6) By Stephan Beal (stephan) on 2022-08-10 06:39:14 in reply to 4 [link] [source]

I gave it a shot, and ended up in a similar situation as you

And as a point of reference, he was my initial attempt:

--- src/stash.c
+++ src/stash.c
@@ -693,25 +693,39 @@
       undo_save_stash(0);
       stash_drop(stashid);
       undo_finish();
     }
   }else
-  if( memcmp(zCmd, "pop", nCmd)==0 ){
-    if( g.argc>3 ) usage("pop");
-    stashid = stash_get_id(0);
-    undo_begin();
-    stash_apply(stashid, 0);
-    undo_save_stash(stashid);
-    undo_finish();
-    stash_drop(stashid);
-  }else
-  if( memcmp(zCmd, "apply", nCmd)==0 ){
-    if( g.argc>4 ) usage("apply STASHID");
-    stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
-    undo_begin();
-    stash_apply(stashid, 0);
-    undo_finish();
+  if( memcmp(zCmd, "pop", nCmd)==0 || memcmp(zCmd, "apply", nCmd)==0 ){
+    const int isPop = 'p'==zCmd[0];
+    Stmt q;
+    const char *zComment = 0;
+    const char *zTime  = 0;
+    if( isPop ){
+      if( g.argc>3 ) usage("pop");
+      stashid = stash_get_id(0);
+    }else{
+      if( g.argc>4 ) usage("apply STASHID");
+      stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
+    }
+    db_multi_exec("CREATE TEMP TABLE xstash AS "
+                  "SELECT comment, datetime(ctime) as time "
+                  "FROM stash WHERE stashid=%d", stashid);
+    db_prepare(&q, "SELECT comment, time FROM xstash");
+    if( SQLITE_ROW==db_step(&q) ){
+      zComment = db_column_text(&q, 0);
+      zTime = db_column_text(&q, 1);
+    }
+    undo_begin();
+    stash_apply(stashid, 0);
+    if( isPop ) undo_save_stash(stashid);
+    fossil_print("%s stash ID %d from %s: %s\n",
+                 isPop ? "Popped" : "Applied",
+                 stashid, zTime, zComment);
+    db_finalize(&q);
+    undo_finish();
+    if( isPop ) stash_drop(stashid);
   }else
   if( memcmp(zCmd, "goto", nCmd)==0 ){
     int nConflict;
     int vid;
     if( g.argc>4 ) usage("apply STASHID");

(7) By mark on 2022-09-27 11:14:49 in reply to 1 [link] [source]

Thanks for this idea! An implementation of it has now landed on trunk: 1392710fb455840c

(8) By Alfred M. Szmidt (ams) on 2022-09-28 07:28:12 in reply to 7 [link] [source]

Very nice! Thank you, and Stephan for this!