summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSkip Montanaro <skip@pobox.com>2002-06-11 14:32:46 (GMT)
committerSkip Montanaro <skip@pobox.com>2002-06-11 14:32:46 (GMT)
commita039274cccd24631f2b2de39d31ae4ffe7399bf8 (patch)
treebc67aa10ead4e0bdbf8d5798adbad41bb967088e
parent60e04cd317201f43b612e99444eac297fae0ea40 (diff)
downloadcpython-a039274cccd24631f2b2de39d31ae4ffe7399bf8.zip
cpython-a039274cccd24631f2b2de39d31ae4ffe7399bf8.tar.gz
cpython-a039274cccd24631f2b2de39d31ae4ffe7399bf8.tar.bz2
patch #562492 - prevent duplicate lines in history
also call using_history() to properly initialize history variables
-rw-r--r--Modules/readline.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/Modules/readline.c b/Modules/readline.c
index 6850b01..1ca8ec3 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -552,6 +552,8 @@ flex_complete(char *text, int start, int end)
static void
setup_readline(void)
{
+ using_history();
+
rl_readline_name = "python";
#if defined(PYOS_OS2) && defined(PYCC_GCC)
/* Allow $if term= in .inputrc to work */
@@ -628,8 +630,23 @@ call_readline(char *prompt)
return p;
}
n = strlen(p);
- if (n > 0)
- add_history(p);
+ if (n > 0) {
+ char *line;
+ HISTORY_STATE *state = history_get_history_state();
+ if (state->length > 0)
+ line = history_get(state->length)->line;
+ else
+ line = "";
+ if (strcmp(p, line))
+ add_history(p);
+ /* the history docs don't say so, but the address of state
+ changes each time history_get_history_state is called
+ which makes me think it's freshly malloc'd memory...
+ on the other hand, the address of the last line stays the
+ same as long as history isn't extended, so it appears to
+ be malloc'd but managed by the history package... */
+ free(state);
+ }
/* Copy the malloc'ed buffer into a PyMem_Malloc'ed one and
release the original. */
q = p;