From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4578 invoked by alias); 3 Jun 2014 19:56:28 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32682 Received: (qmail 11571 invoked from network); 3 Jun 2014 19:56:12 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, UC_GIBBERISH_OBFU autolearn=no version=3.3.2 X-Originating-IP: [86.6.157.246] X-Spam: 0 X-Authority: v=2.1 cv=TM7LSjVa c=1 sm=1 tr=0 a=BvYiZ/UW0Fmn8Wufq9dPrg==:117 a=BvYiZ/UW0Fmn8Wufq9dPrg==:17 a=NLZqzBF-AAAA:8 a=MJF4xiadgiEA:10 a=uObrxnre4hsA:10 a=kj9zAlcOel0A:10 a=02rWKl3eAAAA:8 a=H7bjTCH-LaMXjTaoZCUA:9 a=CjuIK1q_8ugA:10 a=_dQi-Dcv4p4A:10 a=iVFYgQKhOj0A:10 Date: Tue, 3 Jun 2014 20:56:07 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Cc: 749969-forwarded@bugs.debian.org Subject: Re: Bug#749969: history no longer syncs immediately, INC_APPEND_HISTORY broken Message-ID: <20140603205607.00cc39f1@pws-pc.ntlworld.com> In-Reply-To: <20140531202211.396cd06e@pws-pc.ntlworld.com> References: <20140531074936.GA9011@valiant.palfrader.org> <87d2eu5mmg.fsf@ft.bewatermyfriend.org> <20140531202211.396cd06e@pws-pc.ntlworld.com> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sat, 31 May 2014 20:22:11 +0100 Peter Stephenson wrote: > On Sat, 31 May 2014 11:21:59 +0200 > Frank Terbeck wrote: > > I think to enable both ways to be possible, there should be two options: > > INC_APPEND_HISTORY that enables the original behaviour and (if the name > > is agreeable) DELAY_INC_APPEND_HISTORY, that amends the behaviour of the > > original option in the way that is reflected by the current behaviour. > > The issue is that, without rewriting the history, either the time taken > for the command is wrong (that was the old case) or the command isn't > written out to the history until it's finished (that's the current > position). Writing the history to get the best of both worlds probably > isn't beyond the bounds of 21st century science, but it's beyond my > understanding of the history code at the moment. So at the moment > having two options looks like the only way to allow you to achieve any > one of the effects. I think the new behaviour could be > INC_APPEND_HISTORY_TIME which puts it next to the original one and > indicates why it exists. > > I haven't looked, but I don't think this ought to be too difficult --- > there are still some reasons why you might have to deal with history at > the original place anyway, so it should be possible to add an option > test at that point as well as one at the later point. I think this works, but it's getting pretty silly. diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 349946d..7e46048 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -971,6 +971,19 @@ 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. +) pindex(SHARE_HISTORY) pindex(NO_SHARE_HISTORY) pindex(SHAREHISTORY) diff --git a/Src/hist.c b/Src/hist.c index 1182994..64f88f5 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 e83dc58..2163bff 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 620883b..05d582c 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2115,6 +2115,7 @@ enum { IGNORECLOSEBRACES, IGNOREEOF, INCAPPENDHISTORY, + INCAPPENDHISTORYTIME, INTERACTIVE, INTERACTIVECOMMENTS, KSHARRAYS, -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/