Code

Use rewritten parent info from --parents to simplify the revgraph
authorJonas Fonseca <fonseca@diku.dk>
Fri, 21 Mar 2008 16:53:46 +0000 (17:53 +0100)
committerJonas Fonseca <fonseca@diku.dk>
Fri, 21 Mar 2008 17:20:45 +0000 (18:20 +0100)
TODO
tig.c

diff --git a/TODO b/TODO
index 464e1226937420918280294de7bec99c6dd040fb..437f0d431d8baf36d60a1c9e279995de0c71024b 100644 (file)
--- a/TODO
+++ b/TODO
@@ -24,8 +24,7 @@ Features that should be explored.
 
  - Split sources of tig.c into multiple files.
 
- - Rewrite revgraph handling to use --parents, which should help to
-   cleanup this messy part of the code.
+ - Rewrite revgraph handling.
 
  - Color the revgraph to make it easier to follow branches. Idea by
    Dominik Vogt
diff --git a/tig.c b/tig.c
index 36f03c2a4cd9a2823da14e38bba88d1550a59bed..4a50268b742f08714c10b8bcc6ac083ccfefae6c 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -116,7 +116,7 @@ static size_t utf8_length(const char *string, size_t max_width, int *trimmed, bo
        "git log --no-color --cc --stat -n100 %s 2>/dev/null"
 
 #define TIG_MAIN_CMD \
-       "git log --no-color --topo-order --boundary --pretty=raw %s 2>/dev/null"
+       "git log --no-color --topo-order --parents --boundary --pretty=raw %s 2>/dev/null"
 
 #define TIG_TREE_CMD   \
        "git ls-tree %s %s"
@@ -584,7 +584,7 @@ parse_options(int argc, char *argv[])
                if (opt_request == REQ_VIEW_MAIN)
                        /* XXX: This is vulnerable to the user overriding
                         * options required for the main view parser. */
-                       string_copy(opt_cmd, "git log --no-color --pretty=raw --boundary");
+                       string_copy(opt_cmd, "git log --no-color --pretty=raw --boundary --parents");
                else
                        string_copy(opt_cmd, "git");
                buf_size = strlen(opt_cmd);
@@ -4016,6 +4016,7 @@ struct commit {
        struct ref **refs;              /* Repository references. */
        chtype graph[SIZEOF_REVGRAPH];  /* Ancestry chain graphics. */
        size_t graph_size;              /* The width of the graph array. */
+       bool has_parents;               /* Rewritten --parents seen. */
 };
 
 /* Size of rev graph with no  "padding" columns */
@@ -4368,6 +4369,12 @@ main_read(struct view *view, char *line)
                commit->refs = get_refs(commit->id);
                graph->commit = commit;
                add_line_data(view, commit, LINE_MAIN_COMMIT);
+
+               while ((line = strchr(line, ' '))) {
+                       line++;
+                       push_rev_graph(graph->parents, line);
+                       commit->has_parents = TRUE;
+               }
                return TRUE;
        }
 
@@ -4377,6 +4384,8 @@ main_read(struct view *view, char *line)
 
        switch (type) {
        case LINE_PARENT:
+               if (commit->has_parents)
+                       break;
                push_rev_graph(graph->parents, line + STRING_SIZE("parent "));
                break;