diff options
author | Wayne Davison <wayned@users.sourceforge.net> | 2002-02-13 18:13:14 +0000 |
---|---|---|
committer | Wayne Davison <wayned@users.sourceforge.net> | 2002-02-13 18:13:14 +0000 |
commit | c24a38cdaa16b0efa272e3ec588d1d89d3397d2d (patch) | |
tree | 68f234788b64c771e3f86481478d2deab4efbd63 | |
parent | 8b7c9d40d41dd0a3bfec681210ad6070b2d104b7 (diff) | |
download | zsh-c24a38cdaa16b0efa272e3ec588d1d89d3397d2d.tar.gz zsh-c24a38cdaa16b0efa272e3ec588d1d89d3397d2d.tar.xz zsh-c24a38cdaa16b0efa272e3ec588d1d89d3397d2d.zip |
Improved resizehistents() so that it honors HISTEXPIREDUPSFIRST.
-rw-r--r-- | Src/hist.c | 58 |
1 files changed, 33 insertions, 25 deletions
diff --git a/Src/hist.c b/Src/hist.c index e5fcf5ff8..dbd3ce1bc 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -913,11 +913,34 @@ gethistent(int ev, int nearmatch) return he; } +static void +putoldhistentryontop(void) +{ + Histent he = hist_ring->down; + if (isset(HISTEXPIREDUPSFIRST) && !(he->flags & HIST_DUP)) { + int max_unique_ct = getiparam("SAVEHIST"); + do { + if (max_unique_ct-- <= 0) { + he = hist_ring->down; + break; + } + he = he->down; + } while (he != hist_ring->down && !(he->flags & HIST_DUP)); + if (he != hist_ring->down) { + he->up->down = he->down; + he->down->up = he->up; + he->up = hist_ring; + he->down = hist_ring->down; + hist_ring->down = he->down->up = he; + } + } + hist_ring = he; +} + /**/ Histent prepnexthistent(void) { - Histent he; int curline_in_ring = hist_ring == &curline; if (curline_in_ring) @@ -928,7 +951,7 @@ prepnexthistent(void) } if (histlinect < histsiz) { - he = (Histent)zcalloc(sizeof *he); + Histent he = (Histent)zcalloc(sizeof *he); if (!hist_ring) hist_ring = he->up = he->down = he; else { @@ -940,30 +963,13 @@ prepnexthistent(void) histlinect++; } else { - he = hist_ring->down; - if (isset(HISTEXPIREDUPSFIRST) && !(he->flags & HIST_DUP)) { - int max_unique_ct = getiparam("SAVEHIST"); - do { - if (max_unique_ct-- <= 0) { - he = hist_ring->down; - break; - } - he = he->down; - } while (he != hist_ring->down && !(he->flags & HIST_DUP)); - if (he != hist_ring->down) { - he->up->down = he->down; - he->down->up = he->up; - he->up = hist_ring; - he->down = hist_ring->down; - hist_ring->down = he->down->up = he; - } - } - freehistdata(hist_ring = he, 0); + putoldhistentryontop(); + freehistdata(hist_ring, 0); } - he->histnum = ++curhist; + hist_ring->histnum = ++curhist; if (curline_in_ring) linkcurline(); - return he; + return hist_ring; } /* A helper function for hend() */ @@ -1756,8 +1762,10 @@ inithist(void) void resizehistents(void) { - while (histlinect > histsiz) - freehistnode((HashNode)hist_ring->down); + while (histlinect > histsiz) { + putoldhistentryontop(); + freehistnode((HashNode)hist_ring); + } } /* Remember the last line in the history file so we can find it again. */ |