From: Patrick Palka <patrick@parcs.ath.cx>
To: gdb-patches@sourceware.org
Cc: Patrick Palka <patrick@parcs.ath.cx>
Subject: [PATCH] Prune duplicate command history entries
Date: Wed, 03 Jun 2015 03:22:00 -0000 [thread overview]
Message-ID: <1433301766-20101-1-git-send-email-patrick@parcs.ath.cx> (raw)
This patch implements pruning of duplicate command-history entries using
a modest amount of lookbehind. The motivation for this patch is to
reduce the prevalence of basic commands such as "up" and "down" in the
history file. These common commands crowd out more unique commands in
the history file (when the history file has a fixed size), and they make
navigation of the history file via ^P, ^N and ^R more inconvenient. By
pruning duplicate command-history entries we can significantly reduce
the occurrence of such entries, leaving the history file filled with
more interesting commands.
The maximum lookbehind is fixed to 50 (an arbitrary number) so that the
operation will be guaranteed to not take too long.
gdb/ChangeLog:
* top.c (gdb_add_history): Prune duplicate command-history
entries.
---
gdb/top.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/gdb/top.c b/gdb/top.c
index 74e1e07..ec88fa3 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -897,6 +897,34 @@ static int command_count = 0;
void
gdb_add_history (const char *command)
{
+ int lookbehind;
+ const int lookbehind_threshold = 50;
+
+ /* To help avoid cluttering the history file with entries for "up", "down",
+ "list", "bt", and so on, perform pruning of duplicate command-history
+ entries, but only among history entries added during this session. Since
+ we update the history file by appending to it, history entries that are
+ already stored in the history file can't be pruned. */
+ using_history ();
+ for (lookbehind = 0;
+ lookbehind < command_count && lookbehind < lookbehind_threshold;
+ lookbehind++)
+ {
+ HIST_ENTRY *temp = previous_history ();
+
+ if (temp == NULL)
+ break;
+
+ if (strcmp (temp->line, command) == 0)
+ {
+ HIST_ENTRY *prev = remove_history (where_history ());
+ command_count--;
+ free_history_entry (prev);
+ break;
+ }
+ }
+ using_history ();
+
add_history (command);
command_count++;
}
--
2.4.2.387.gf86f31a.dirty
next reply other threads:[~2015-06-03 3:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-03 3:22 Patrick Palka [this message]
2015-06-03 8:20 ` Andrew Burgess
2015-06-03 14:16 ` Patrick Palka
2015-06-03 17:42 ` Andrew Burgess
2015-06-03 17:10 ` Joel Brobecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1433301766-20101-1-git-send-email-patrick@parcs.ath.cx \
--to=patrick@parcs.ath.cx \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).