From dd0d010d232d0a8bdfa6e944c94ae4ada37a5a5c Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Mon, 9 Jun 2014 15:31:53 +0200 Subject: [PATCH] Don't write to history file for history size of 0. --- doc/vimb.1 | 3 ++- src/history.c | 10 +++++++++- src/util.c | 10 ++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/doc/vimb.1 b/doc/vimb.1 index 83dbc8b..2ba401a 100644 --- a/doc/vimb.1 +++ b/doc/vimb.1 @@ -778,7 +778,8 @@ Header completely from request. .RE .TP .B history-max-items (int) -Maximum number of unique items stored in search-, command or URI history. +Maximum number of unique items stored in search-, command or URI history. If +history-max-items is set to 0, the history file will not be changed. .TP .B home-page (string) Homepage that vimb opens if started without a URI. diff --git a/src/history.c b/src/history.c index 149c1c6..147fc46 100644 --- a/src/history.c +++ b/src/history.c @@ -56,6 +56,12 @@ void history_cleanup(void) { const char *file; GList *list; + + /* don't cleanup the history file if history max size is 0 */ + if (!vb.config.history_max) { + return; + } + for (HistoryType i = HISTORY_FIRST; i < HISTORY_LAST; i++) { file = get_file_by_type(i); list = load(file); @@ -71,7 +77,9 @@ void history_add(HistoryType type, const char *value, const char *additional) { const char *file; - if (!vb.state.enable_history) { + /* don't write a history entry to the file if history is disabled or + * history max size is set to 0 */ + if (!vb.state.enable_history || !vb.config.history_max) { return; } diff --git a/src/util.c b/src/util.c index dba1c75..8f54144 100644 --- a/src/util.c +++ b/src/util.c @@ -122,11 +122,17 @@ GList *util_file_to_unique_list(const char *filename, Util_Content_Func func, /* yes, the whole file is read and wen possible don not need all the * lines, but this is easier to implement compared to reading the file * line wise from ent to begining */ - char *line, **lines = util_get_lines(filename); + char *line, **lines; void *value; int len, num_items = 0; - len = g_strv_length(lines); + /* return empty list if max items is 0 */ + if (!max_items) { + return gl; + } + + lines = util_get_lines(filename); + len = g_strv_length(lines); if (!len) { return gl; } -- 2.20.1