zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: fix unshared history lines
@ 2000-07-17  2:05 Wayne Davison
  0 siblings, 0 replies; only message in thread
From: Wayne Davison @ 2000-07-17  2:05 UTC (permalink / raw)
  To: Zsh Workers

The following patch fixes the breakage in gethistent() that I managed
to introduce back on May 30th.  It also ensures that if SHARE_HISTORY
is set, we only save our outstanding history lines if we successfully
locked the history file back before the readhistfile() call (i.e.  if
the lock is in place to encompass both operations, not just the one).
This ensures that we don't fail to read in some history events from a
sibling process.

..wayne..

---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Src/hist.c
@@ -882,21 +882,19 @@
 
     if (ev - hist_ring->down->histnum < hist_ring->histnum - ev) {
 	for (he = hist_ring->down; he->histnum < ev; he = he->down) ;
-	if (nearmatch == 0) {
-	    if (he->histnum != ev)
+	if (he->histnum != ev) {
+	    if (nearmatch == 0
+	     || (nearmatch < 0 && (he = up_histent(he)) == NULL))
 		return NULL;
 	}
-	else if (nearmatch < 0 && (he = up_histent(he)) == NULL)
-	    return NULL;
     }
     else {
 	for (he = hist_ring; he->histnum > ev; he = he->up) ;
-	if (nearmatch == 0) {
-	    if (he->histnum != ev)
+	if (he->histnum != ev) {
+	    if (nearmatch == 0
+	     || (nearmatch > 0 && (he = down_histent(he)) == NULL))
 		return NULL;
 	}
-	else if (nearmatch > 0 && (he = down_histent(he)) == NULL)
-	    return NULL;
     }
 
     checkcurline(he);
@@ -1060,7 +1058,7 @@
     zfree(chwords, chwordlen*sizeof(short));
     chline = NULL;
     histactive = 0;
-    if (isset(SHAREHISTORY) || isset(INCAPPENDHISTORY))
+    if (isset(SHAREHISTORY)? histfileIsLocked() : isset(INCAPPENDHISTORY))
 	savehistfile(hf, 0, HFILE_USE_OPTIONS | HFILE_FAST);
     unlockhistfile(hf); /* It's OK to call this even if we aren't locked */
     return !(flag & HISTFLAG_NOEXEC || errflag);
@@ -2065,6 +2063,13 @@
 	unlink(lockfile);
 	free(lockfile);
     }
+}
+
+/**/
+int
+histfileIsLocked(void)
+{
+    return lockhistct > 0;
 }
 
 /* Get the words in the current buffer. Using the lexer. */
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-07-17  2:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-17  2:05 PATCH: fix unshared history lines Wayne Davison

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).