This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Prune duplicate command history entries
- From: Patrick Palka <patrick at parcs dot ath dot cx>
- To: gdb-patches at sourceware dot org
- Cc: Patrick Palka <patrick at parcs dot ath dot cx>
- Date: Tue, 2 Jun 2015 23:22:46 -0400
- Subject: [PATCH] Prune duplicate command history entries
- Authentication-results: sourceware.org; auth=none
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