Code

main_read: cleanup and simplify
authorJonas Fonseca <fonseca@diku.dk>
Wed, 30 May 2007 18:53:20 +0000 (20:53 +0200)
committerJonas Fonseca <fonseca@diku.dk>
Wed, 30 May 2007 19:01:12 +0000 (21:01 +0200)
tig.c

diff --git a/tig.c b/tig.c
index ca380a30a6d3b9eac6eed506a78c3b09ee96cf66..b71217337935aa620c2a37d6df8b1dbedbb341df 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -3073,8 +3073,7 @@ main_read(struct view *view, char *line)
 {
        static struct rev_graph *graph = graph_stacks;
        enum line_type type;
-       struct commit *commit = view->lines
-                             ? view->line[view->lines - 1].data : NULL;
+       struct commit *commit;
 
        if (!line) {
                update_rev_graph(graph);
@@ -3082,26 +3081,25 @@ main_read(struct view *view, char *line)
        }
 
        type = get_line_type(line);
-
-       switch (type) {
-       case LINE_COMMIT:
+       if (type == LINE_COMMIT) {
                commit = calloc(1, sizeof(struct commit));
                if (!commit)
                        return FALSE;
 
-               line += STRING_SIZE("commit ");
-
-               string_copy_rev(commit->id, line);
+               string_copy_rev(commit->id, line + STRING_SIZE("commit "));
                commit->refs = get_refs(commit->id);
                graph->commit = commit;
                add_line_data(view, commit, LINE_MAIN_COMMIT);
-               break;
+               return TRUE;
+       }
 
+       if (!view->lines)
+               return TRUE;
+       commit = view->line[view->lines - 1].data;
+
+       switch (type) {
        case LINE_PARENT:
-               if (commit) {
-                       line += STRING_SIZE("parent ");
-                       push_rev_graph(graph->parents, line);
-               }
+               push_rev_graph(graph->parents, line + STRING_SIZE("parent "));
                break;
 
        case LINE_AUTHOR:
@@ -3113,7 +3111,7 @@ main_read(struct view *view, char *line)
                char *nameend = strchr(ident, '<');
                char *emailend = strchr(ident, '>');
 
-               if (!commit || !nameend || !emailend)
+               if (!nameend || !emailend)
                        break;
 
                update_rev_graph(graph);
@@ -3155,9 +3153,6 @@ main_read(struct view *view, char *line)
                break;
        }
        default:
-               if (!commit)
-                       break;
-
                /* Fill in the commit title if it has not already been set. */
                if (commit->title[0])
                        break;