mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-11 13:01:28 +02:00
Improved resizehistents() so that it honors HISTEXPIREDUPSFIRST.
This commit is contained in:
parent
8b7c9d40d4
commit
c24a38cdaa
1 changed files with 33 additions and 25 deletions
72
Src/hist.c
72
Src/hist.c
|
@ -913,34 +913,10 @@ gethistent(int ev, int nearmatch)
|
||||||
return he;
|
return he;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**/
|
static void
|
||||||
Histent
|
putoldhistentryontop(void)
|
||||||
prepnexthistent(void)
|
|
||||||
{
|
{
|
||||||
Histent he;
|
Histent he = hist_ring->down;
|
||||||
int curline_in_ring = hist_ring == &curline;
|
|
||||||
|
|
||||||
if (curline_in_ring)
|
|
||||||
unlinkcurline();
|
|
||||||
if (hist_ring && hist_ring->flags & HIST_TMPSTORE) {
|
|
||||||
curhist--;
|
|
||||||
freehistnode((HashNode)hist_ring);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (histlinect < histsiz) {
|
|
||||||
he = (Histent)zcalloc(sizeof *he);
|
|
||||||
if (!hist_ring)
|
|
||||||
hist_ring = he->up = he->down = he;
|
|
||||||
else {
|
|
||||||
he->up = hist_ring;
|
|
||||||
he->down = hist_ring->down;
|
|
||||||
hist_ring->down = he->down->up = he;
|
|
||||||
hist_ring = he;
|
|
||||||
}
|
|
||||||
histlinect++;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
he = hist_ring->down;
|
|
||||||
if (isset(HISTEXPIREDUPSFIRST) && !(he->flags & HIST_DUP)) {
|
if (isset(HISTEXPIREDUPSFIRST) && !(he->flags & HIST_DUP)) {
|
||||||
int max_unique_ct = getiparam("SAVEHIST");
|
int max_unique_ct = getiparam("SAVEHIST");
|
||||||
do {
|
do {
|
||||||
|
@ -958,12 +934,42 @@ prepnexthistent(void)
|
||||||
hist_ring->down = he->down->up = he;
|
hist_ring->down = he->down->up = he;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
freehistdata(hist_ring = he, 0);
|
hist_ring = he;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**/
|
||||||
|
Histent
|
||||||
|
prepnexthistent(void)
|
||||||
|
{
|
||||||
|
int curline_in_ring = hist_ring == &curline;
|
||||||
|
|
||||||
|
if (curline_in_ring)
|
||||||
|
unlinkcurline();
|
||||||
|
if (hist_ring && hist_ring->flags & HIST_TMPSTORE) {
|
||||||
|
curhist--;
|
||||||
|
freehistnode((HashNode)hist_ring);
|
||||||
}
|
}
|
||||||
he->histnum = ++curhist;
|
|
||||||
|
if (histlinect < histsiz) {
|
||||||
|
Histent he = (Histent)zcalloc(sizeof *he);
|
||||||
|
if (!hist_ring)
|
||||||
|
hist_ring = he->up = he->down = he;
|
||||||
|
else {
|
||||||
|
he->up = hist_ring;
|
||||||
|
he->down = hist_ring->down;
|
||||||
|
hist_ring->down = he->down->up = he;
|
||||||
|
hist_ring = he;
|
||||||
|
}
|
||||||
|
histlinect++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
putoldhistentryontop();
|
||||||
|
freehistdata(hist_ring, 0);
|
||||||
|
}
|
||||||
|
hist_ring->histnum = ++curhist;
|
||||||
if (curline_in_ring)
|
if (curline_in_ring)
|
||||||
linkcurline();
|
linkcurline();
|
||||||
return he;
|
return hist_ring;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A helper function for hend() */
|
/* A helper function for hend() */
|
||||||
|
@ -1756,8 +1762,10 @@ inithist(void)
|
||||||
void
|
void
|
||||||
resizehistents(void)
|
resizehistents(void)
|
||||||
{
|
{
|
||||||
while (histlinect > histsiz)
|
while (histlinect > histsiz) {
|
||||||
freehistnode((HashNode)hist_ring->down);
|
putoldhistentryontop();
|
||||||
|
freehistnode((HashNode)hist_ring);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remember the last line in the history file so we can find it again. */
|
/* Remember the last line in the history file so we can find it again. */
|
||||||
|
|
Loading…
Reference in a new issue