Code

Move formatting of blame --incremental command to blame_read_file
authorJonas Fonseca <fonseca@diku.dk>
Wed, 31 Dec 2008 18:23:43 +0000 (13:23 -0500)
committerJonas Fonseca <fonseca@diku.dk>
Wed, 31 Dec 2008 19:20:08 +0000 (14:20 -0500)
Doing it in blame_open after starting the command makes error handling
harder and the code was indeed buggy.

tig.c

diff --git a/tig.c b/tig.c
index bcbc5fa027907a78e87946c558442595774917f2..ec97f564d8e878e0bfcce70f400cd3f489238463 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -3536,9 +3536,6 @@ blame_open(struct view *view)
                        return FALSE;
        }
 
-       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);
@@ -3626,13 +3623,18 @@ static bool
 blame_read_file(struct view *view, const char *line, bool *read_file)
 {
        if (!line) {
+               char ref[SIZEOF_STR] = "";
+               char path[SIZEOF_STR];
                FILE *pipe = NULL;
 
-               if (view->lines > 0)
-                       pipe = popen(view->cmd, "r");
-               else if (!view->parent)
+               if (view->lines == 0 && !view->parent)
                        die("No blame exist for %s", view->vid);
-               if (!pipe) {
+
+               if (view->lines == 0 ||
+                   sq_quote(path, 0, opt_file) >= sizeof(path) ||
+                   (*opt_ref && sq_quote(ref, 0, opt_ref) >= sizeof(ref)) ||
+                   !string_format(view->cmd, BLAME_INCREMENTAL_CMD, ref, path) ||
+                   !(pipe = popen(view->cmd, "r"))) {
                        report("Failed to load blame data");
                        return TRUE;
                }