zsh-workers
 help / color / mirror / code / Atom feed
From: Wayne Davison <wayned@users.sourceforge.net>
To: zsh-workers@sunsite.dk
Subject: skip rewriting history if exiting due to signal
Date: Fri, 1 Oct 2004 12:36:58 -0700	[thread overview]
Message-ID: <20041001193658.GD26529@blorf.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 650 bytes --]

Here's my patch that implements the behavior that skips the history
rewrite-after-appending if zsh is exiting because it received a signal.
This should make the simultaneous closing of multiple zsh programs less
contentious over the history file.  The safest way to go is to use
INC_APPEND_HISTORY or SHARE_HISTORY (since new history lines are being
appended as they are entered, not all at once on exit).

People who don't append to the history file won't see any change in
behavior from this patch (that will have to be improved in some other
manner, possibly by switching over to using a *.new file to write out
the new history lines).

..wayne..

[-- Attachment #2: sighist.patch --]
[-- Type: text/plain, Size: 2572 bytes --]

--- Src/builtin.c	1 Oct 2004 18:51:44 -0000	1.127
+++ Src/builtin.c	1 Oct 2004 19:12:23 -0000
@@ -1340,7 +1340,7 @@ bin_fc(char *nam, char **argv, Options o
 	    zwarnnam("fc", "too many arguments", NULL, 0);
 	    return 1;
 	}
-	return !saveandpophiststack(-1);
+	return !saveandpophiststack(-1, HFILE_USE_OPTIONS);
     }
     /* with the -m option, the first argument is taken *
      * as a pattern that history lines have to match   */
@@ -4111,8 +4111,11 @@ zexit(int val, int from_where)
     }
     if (isset(RCS) && interact) {
 	if (!nohistsave) {
-	    saveandpophiststack(1);
-	    savehistfile(NULL, 1, HFILE_USE_OPTIONS);
+	    int writeflags = HFILE_USE_OPTIONS;
+	    if (from_where == 1)
+		writeflags |= HFILE_NO_REWRITE;
+	    saveandpophiststack(1, writeflags);
+	    savehistfile(NULL, 1, writeflags);
 	}
 	if (islogin && !subsh) {
 	    sourcehome(".zlogout");
--- Src/hist.c	9 Sep 2004 10:12:47 -0000	1.53
+++ Src/hist.c	1 Oct 2004 19:12:24 -0000
@@ -2093,7 +2093,8 @@ savehistfile(char *fn, int err, int writ
 	}
 	fclose(out);
 
-	if ((writeflags & (HFILE_SKIPOLD | HFILE_FAST)) == HFILE_SKIPOLD) {
+	if (writeflags & HFILE_SKIPOLD
+	 && !(writeflags & (HFILE_FAST | HFILE_NO_REWRITE))) {
 	    int remember_histactive = histactive;
 
 	    /* Zeroing histactive avoids unnecessary munging of curline. */
@@ -2445,7 +2446,7 @@ pophiststack(void)
 
 /**/
 int
-saveandpophiststack(int pop_through)
+saveandpophiststack(int pop_through, int writeflags)
 {
     if (pop_through <= 0) {
 	pop_through += histsave_stack_pos + 1;
@@ -2459,7 +2460,7 @@ saveandpophiststack(int pop_through)
 	return 0;
     do {
 	if (!nohistsave)
-	    savehistfile(NULL, 1, HFILE_USE_OPTIONS);
+	    savehistfile(NULL, 1, writeflags);
 	pophiststack();
     } while (histsave_stack_pos >= pop_through);
     return 1;
--- Src/params.c	1 Oct 2004 19:06:49 -0000	1.91
+++ Src/params.c	1 Oct 2004 19:12:24 -0000
@@ -3611,7 +3611,8 @@ mod_export void
 endparamscope(void)
 {
     locallevel--;
-    saveandpophiststack(0); /* Pops anything from a higher locallevel */
+    /* This pops anything from a higher locallevel */
+    saveandpophiststack(0, HFILE_USE_OPTIONS);
     scanhashtable(paramtab, 0, 0, 0, scanendscope, 0);
 }
 
--- Src/zsh.h	9 Sep 2004 10:12:47 -0000	1.60
+++ Src/zsh.h	1 Oct 2004 19:10:59 -0000	1.62
@@ -1365,6 +1365,7 @@ struct histent {
 #define HFILE_SKIPDUPS		0x0004
 #define HFILE_SKIPFOREIGN	0x0008
 #define HFILE_FAST		0x0010
+#define HFILE_NO_REWRITE	0x0020
 #define HFILE_USE_OPTIONS	0x8000
 
 /******************************************/

             reply	other threads:[~2004-10-01 19:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-01 19:36 Wayne Davison [this message]
2004-10-17 19:48 ` Wayne Davison
2004-10-18  0:21   ` Bart Schaefer
2004-10-18  5:00     ` Wayne Davison
2004-10-18 19:36       ` Improved HISTFILE locking Wayne Davison

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041001193658.GD26529@blorf.net \
    --to=wayned@users.sourceforge.net \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).