From 93afcbad8a315c69ca98ce6c8aed61a2d0ad1da1 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Tue, 7 Oct 2008 20:42:23 +0200 Subject: [PATCH] Consolidate and share view resetting via new reset_view() --- tig.c | 54 +++++++++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/tig.c b/tig.c index 3da49f2..51cbb20 100644 --- a/tig.c +++ b/tig.c @@ -2184,6 +2184,24 @@ search_view(struct view *view, enum request request) * Incremental updating */ +static void +reset_view(struct view *view) +{ + int i; + + for (i = 0; i < view->lines; i++) + free(view->line[i].data); + free(view->line); + + view->line = NULL; + view->offset = 0; + view->lines = 0; + view->lineno = 0; + view->line_size = 0; + view->line_alloc = 0; + view->vid[0] = 0; +} + static void end_update(struct view *view, bool force) { @@ -2252,23 +2270,9 @@ begin_update(struct view *view, bool refresh) return FALSE; set_nonblocking_input(TRUE); - - view->offset = 0; - view->lines = 0; - view->lineno = 0; + reset_view(view); string_copy_rev(view->vid, view->id); - if (view->line) { - int i; - - for (i = 0; i < view->lines; i++) - if (view->line[i].data) - free(view->line[i].data); - - free(view->line); - view->line = NULL; - } - view->start_time = time(NULL); return TRUE; @@ -3518,21 +3522,10 @@ blame_open(struct view *view) if (!string_format(view->cmd, BLAME_INCREMENTAL_CMD, ref, path)) return FALSE; + reset_view(view); string_format(view->ref, "%s ...", opt_file); string_copy_rev(view->vid, opt_file); set_nonblocking_input(TRUE); - - if (view->line) { - int i; - - for (i = 0; i < view->lines; i++) - free(view->line[i].data); - free(view->line); - } - - view->lines = view->line_alloc = view->line_size = view->lineno = 0; - view->offset = view->lines = view->lineno = 0; - view->line = NULL; view->start_time = time(NULL); return TRUE; @@ -4029,13 +4022,8 @@ static bool status_open(struct view *view) { unsigned long prev_lineno = view->lineno; - size_t i; - for (i = 0; i < view->lines; i++) - free(view->line[i].data); - free(view->line); - view->lines = view->line_alloc = view->line_size = view->lineno = 0; - view->line = NULL; + reset_view(view); if (!realloc_lines(view, view->line_size + 7)) return FALSE; -- 2.30.2