From: Jonas Fonseca Date: Wed, 30 May 2007 18:22:04 +0000 (+0200) Subject: Refactor add_line_text parts into add_line_data; use it in main_read X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e314c36d0422488191aea046b2485d5a22c2c791;p=tig.git Refactor add_line_text parts into add_line_data; use it in main_read --- diff --git a/tig.c b/tig.c index be4b80c..ca380a3 100644 --- a/tig.c +++ b/tig.c @@ -1983,23 +1983,26 @@ end: } static struct line * -add_line_text(struct view *view, char *data, enum line_type type) +add_line_data(struct view *view, void *data, enum line_type type) { - struct line *line = &view->line[view->lines]; - - if (!data) - return NULL; - - line->data = strdup(data); - if (!line->data) - return NULL; + struct line *line = &view->line[view->lines++]; + memset(line, 0, sizeof(*line)); line->type = type; - view->lines++; + line->data = data; return line; } +static struct line * +add_line_text(struct view *view, char *data, enum line_type type) +{ + if (data) + data = strdup(data); + + return data ? add_line_data(view, data, type) : NULL; +} + /* * View opening @@ -3088,10 +3091,10 @@ main_read(struct view *view, char *line) line += STRING_SIZE("commit "); - view->line[view->lines++].data = commit; string_copy_rev(commit->id, line); commit->refs = get_refs(commit->id); graph->commit = commit; + add_line_data(view, commit, LINE_MAIN_COMMIT); break; case LINE_PARENT: