From patchwork Wed Jun 3 03:22:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 7022 Received: (qmail 2715 invoked by alias); 3 Jun 2015 03:22:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 2698 invoked by uid 89); 3 Jun 2015 03:22:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-qg0-f46.google.com Received: from mail-qg0-f46.google.com (HELO mail-qg0-f46.google.com) (209.85.192.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 03 Jun 2015 03:22:54 +0000 Received: by qgep100 with SMTP id p100so4886471qge.3 for ; Tue, 02 Jun 2015 20:22:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Iow7r6frtP3guydxT8t6jSyiimP6PeT0GNeUtAsSPfc=; b=mf1oeTMOoQorMpELJ/YFgwKqwVlafuQIGBjRLDkoTyM3Jj+Yd7Dl8TSqOotGTtb7vu J5BX15pU0+fRucFkL81fvUjPj9hEEeHedoi12fdtTQbb6J8AYm6ONeVqmQwd8hsItKin b2a8vFW+RSZq//rnWoCRM6WJ8iP9LHEFp1lFsXcoiZLCOUbSAQoEgUxmyM+H8tWzqXhi 7UxQKrivx/F1HksHrjs1wgZpH++z047KXgKZ7i8topUqk+lwZJwfZF/EJCL5cJhgBqwa pVtXxiXCxPzsijZFakRndQGiAG2a8a+nLbbei7A0cBXNe47oYBCj+UgceD95WNu7v00R KhIg== X-Gm-Message-State: ALoCoQn4uGg1euFxX1X7KxE6JmGGHPgWNm6MzipJHZOEWDs4X9ypuLTVgOrkS45/ep3dZyhhdBDW X-Received: by 10.55.25.145 with SMTP id 17mr54762917qkz.46.1433301772795; Tue, 02 Jun 2015 20:22:52 -0700 (PDT) Received: from localhost.localdomain (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by mx.google.com with ESMTPSA id r31sm8459366qkr.42.2015.06.02.20.22.51 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Jun 2015 20:22:51 -0700 (PDT) From: Patrick Palka To: gdb-patches@sourceware.org Cc: Patrick Palka Subject: [PATCH] Prune duplicate command history entries Date: Tue, 2 Jun 2015 23:22:46 -0400 Message-Id: <1433301766-20101-1-git-send-email-patrick@parcs.ath.cx> 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++; }