Code

Refactor add_line_text parts into add_line_data; use it in main_read
authorJonas Fonseca <fonseca@diku.dk>
Wed, 30 May 2007 18:22:04 +0000 (20:22 +0200)
committerJonas Fonseca <fonseca@diku.dk>
Wed, 30 May 2007 18:22:50 +0000 (20:22 +0200)
tig.c

diff --git a/tig.c b/tig.c
index be4b80c774d44902a1160f271d5bc4c8a11bdef8..ca380a30a6d3b9eac6eed506a78c3b09ee96cf66 100644 (file)
--- 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: