about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2014-06-06 21:56:47 +0100
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2014-06-06 21:56:47 +0100
commit7f6dc0fe8e3c9aaec8aa295cc4459eabb8f2ada2 (patch)
tree28093b2432239835d8564e42fb95db47ac84c43b
parent605cc1ba579ad6de619f1dca0f3d2857350a3c07 (diff)
downloadzsh-7f6dc0fe8e3c9aaec8aa295cc4459eabb8f2ada2.tar.gz
zsh-7f6dc0fe8e3c9aaec8aa295cc4459eabb8f2ada2.tar.xz
zsh-7f6dc0fe8e3c9aaec8aa295cc4459eabb8f2ada2.zip
32682 with tweaks: Add INC_APPEND_HISTORY_TIME.
Revert INC_APPEND_HISTORY behaviour.
-rw-r--r--ChangeLog5
-rw-r--r--Doc/Zsh/options.yo30
-rw-r--r--Src/hist.c14
-rw-r--r--Src/options.c1
-rw-r--r--Src/zsh.h1
5 files changed, 40 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 2c44530d7..776e4d980 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2014-06-06  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
+	* 32682 with tweaks: Doc/Zsh/options.yo, Src/hist.c,
+	Src/options.c, Src/zsh.h: INC_APPEND_HISTORY_TIME is new
+	behaviour, with INC_APPEND_HISTORY reverting to its previous
+	behaviour.
+
 	* Andrew Magee: 32698: Completion/Unix/Command/_hg: show
 	committable files.
 
diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index 349946d82..7788cd755 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -971,6 +971,23 @@ The file will still be periodically re-written to trim it when the
 number of lines grows 20% beyond the value specified by
 tt($SAVEHIST) (see also the HIST_SAVE_BY_COPY option).
 )
+pindex(INC_APPEND_HISTORY_TIME)
+pindex(NO_INC_APPEND_HISTORY_TIME)
+pindex(INCAPPENDHISTORYTIME)
+pindex(NOINCAPPENDHISTORYTIME)
+cindex(history, incremental appending to a file with time)
+item(tt(INC_APPEND_HISTORY_TIME))(
+This option is a variant of tt(INC_APPEND_HISTORY) in which, where
+possible, the history entry is written out to the file after the
+command is finished, so that the time taken by the command is recorded
+correctly in the history file in tt(EXTENDED_HISTORY) format.  This
+means that the history entry will not be available immediately from
+other instances of the shell that are using the same history file.
+
+This option is only useful if tt(INC_APPEND_HISTORY) and
+tt(SHARE_HISTORY) are turned off.  The three options should be
+considered mutually exclusive.
+)
 pindex(SHARE_HISTORY)
 pindex(NO_SHARE_HISTORY)
 pindex(SHAREHISTORY)
@@ -981,10 +998,10 @@ item(tt(SHARE_HISTORY) <K>)(
 
 This option both imports new commands from the history file, and also
 causes your typed commands to be appended to the history file (the
-latter is like specifying tt(INC_APPEND_HISTORY)).
-The history lines are also output with timestamps ala
-tt(EXTENDED_HISTORY) (which makes it easier to find the spot where
-we left off reading the file after it gets re-written).
+latter is like specifying tt(INC_APPEND_HISTORY), which should be turned
+off if this option is in effect).  The history lines are also output
+with timestamps ala tt(EXTENDED_HISTORY) (which makes it easier to find
+the spot where we left off reading the file after it gets re-written).
 
 By default, history movement commands visit the imported lines as
 well as the local lines, but you can toggle this on and off with the
@@ -994,8 +1011,9 @@ some include them.
 
 If you find that you want more control over when commands
 get imported, you may wish to turn tt(SHARE_HISTORY) off,
-tt(INC_APPEND_HISTORY) on, and then manually import
-commands whenever you need them using `tt(fc -RI)'.
+tt(INC_APPEND_HISTORY) or tt(INC_APPEND_HISTORY_TIME) (see above) on,
+and then manually import commands whenever you need them using `tt(fc
+-RI)'.
 )
 enditem()
 
diff --git a/Src/hist.c b/Src/hist.c
index 1182994a2..64f88f559 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -935,9 +935,11 @@ hbegin(int dohist)
 
     hf = getsparam("HISTFILE");
     /*
-     * For INCAPPENDHISTORY, when interactive, save the history here
+     * For INCAPPENDHISTORYTIME, when interactive, save the history here
      * as it gives a better estimate of the times of commands.
      *
+     * If INCAPPENDHISTORY is also set we've already done it.
+     *
      * If SHAREHISTORY is also set continue to do so in the
      * standard place, because that's safer about reading and
      * rewriting history atomically.
@@ -950,7 +952,8 @@ hbegin(int dohist)
      * so that (correctly) nothing happens here.  But it shows
      * I thought about it.
      */
-    if (isset(INCAPPENDHISTORY) && !isset(SHAREHISTORY) &&
+    if (isset(INCAPPENDHISTORYTIME) && !isset(SHAREHISTORY) &&
+	!isset(INCAPPENDHISTORY) &&
 	!(histactive & HA_NOINC) && !strin && histsave_stack_pos == 0)
 	savehistfile(hf, 0, HFILE_USE_OPTIONS | HFILE_FAST);
 }
@@ -1378,7 +1381,8 @@ hend(Eprog prog)
      * For normal INCAPPENDHISTORY case and reasoning, see hbegin().
      */
     if (isset(SHAREHISTORY) ? histfileIsLocked() :
-	(isset(INCAPPENDHISTORY) && histsave_stack_pos != 0))
+	(isset(INCAPPENDHISTORY) || (isset(INCAPPENDHISTORYTIME) &&
+				     histsave_stack_pos != 0)))
 	savehistfile(hf, 0, HFILE_USE_OPTIONS | HFILE_FAST);
     unlockhistfile(hf); /* It's OK to call this even if we aren't locked */
     /*
@@ -2542,7 +2546,7 @@ savehistfile(char *fn, int err, int writeflags)
     }
     if (writeflags & HFILE_USE_OPTIONS) {
 	if (isset(APPENDHISTORY) || isset(INCAPPENDHISTORY)
-	 || isset(SHAREHISTORY))
+	 || isset(INCAPPENDHISTORYTIME) || isset(SHAREHISTORY))
 	    writeflags |= HFILE_APPEND | HFILE_SKIPOLD;
 	else
 	    histfile_linect = 0;
@@ -2578,7 +2582,7 @@ savehistfile(char *fn, int err, int writeflags)
 		tmpfile = NULL;
 		if (err) {
 		    if (isset(APPENDHISTORY) || isset(INCAPPENDHISTORY)
-		     || isset(SHAREHISTORY))
+		     || isset(INCAPPENDHISTORYTIME) || isset(SHAREHISTORY))
 			zerr("rewriting %s would change its ownership -- skipped", fn);
 		    else
 			zerr("rewriting %s would change its ownership -- history not saved", fn);
diff --git a/Src/options.c b/Src/options.c
index e83dc5839..2163bff4d 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -165,6 +165,7 @@ static struct optname optns[] = {
 {{NULL, "ignoreclosebraces",  OPT_EMULATE},		 IGNORECLOSEBRACES},
 {{NULL, "ignoreeof",	      0},			 IGNOREEOF},
 {{NULL, "incappendhistory",   0},			 INCAPPENDHISTORY},
+{{NULL, "incappendhistorytime",   0},			 INCAPPENDHISTORYTIME},
 {{NULL, "interactive",	      OPT_SPECIAL},		 INTERACTIVE},
 {{NULL, "interactivecomments",OPT_BOURNE},		 INTERACTIVECOMMENTS},
 {{NULL, "ksharrays",	      OPT_EMULATE|OPT_BOURNE},	 KSHARRAYS},
diff --git a/Src/zsh.h b/Src/zsh.h
index 620883b81..05d582cda 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2115,6 +2115,7 @@ enum {
     IGNORECLOSEBRACES,
     IGNOREEOF,
     INCAPPENDHISTORY,
+    INCAPPENDHISTORYTIME,
     INTERACTIVE,
     INTERACTIVECOMMENTS,
     KSHARRAYS,