Code

Internalize format flags in the IO layer
[tig.git] / tig.c
diff --git a/tig.c b/tig.c
index f9d23ab53026e12236854ab0c168ebb783b6f91b..b17d8dd07b50607a0a40c44c4ba236aa76810e4a 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -892,11 +892,11 @@ io_run_fg(const char **argv, const char *dir)
 }
 
 static bool
-io_run_append(const char **argv, enum format_flags flags, int fd)
+io_run_append(const char **argv, int fd)
 {
        struct io io = {};
 
-       if (!io_format(&io, NULL, IO_AP, argv, flags)) {
+       if (!io_format(&io, NULL, IO_AP, argv, FORMAT_NONE)) {
                close(fd);
                return FALSE;
        }
@@ -906,9 +906,9 @@ io_run_append(const char **argv, enum format_flags flags, int fd)
 }
 
 static bool
-io_run_rd(struct io *io, const char **argv, const char *dir, enum format_flags flags)
+io_run_rd(struct io *io, const char **argv, const char *dir)
 {
-       return io_format(io, dir, IO_RD, argv, flags) && io_start(io);
+       return io_format(io, dir, IO_RD, argv, FORMAT_NONE) && io_start(io);
 }
 
 static bool
@@ -1045,8 +1045,7 @@ io_run_buf(const char **argv, char buf[], size_t bufsize)
 {
        struct io io = {};
 
-       return io_run_rd(&io, argv, NULL, FORMAT_NONE)
-           && io_read_buf(&io, buf, bufsize);
+       return io_run_rd(&io, argv, NULL) && io_read_buf(&io, buf, bufsize);
 }
 
 static int
@@ -2223,7 +2222,6 @@ struct view {
 
        enum keymap keymap;     /* What keymap does this view have */
        bool git_dir;           /* Whether the view requires a git directory. */
-       bool refresh;           /* Whether the view supports refreshing. */
 
        char ref[SIZEOF_REF];   /* Hovered commit reference */
        char vid[SIZEOF_REF];   /* View ID. Set to id member when updating. */
@@ -2301,24 +2299,24 @@ static struct view_ops status_ops;
 static struct view_ops tree_ops;
 static struct view_ops branch_ops;
 
-#define VIEW_STR(type, name, env, ref, ops, map, git, refresh) \
-       { type, name, #env, ref, ops, map, git, refresh }
+#define VIEW_STR(type, name, env, ref, ops, map, git) \
+       { type, name, #env, ref, ops, map, git }
 
-#define VIEW_(id, name, ops, git, refresh, ref) \
-       VIEW_STR(VIEW_##id, name, TIG_##id##_CMD, ref, ops, KEYMAP_##id, git, refresh)
+#define VIEW_(id, name, ops, git, ref) \
+       VIEW_STR(VIEW_##id, name, TIG_##id##_CMD, ref, ops, KEYMAP_##id, git)
 
 static struct view views[] = {
-       VIEW_(MAIN,   "main",   &main_ops,   TRUE,  TRUE,  ref_head),
-       VIEW_(DIFF,   "diff",   &diff_ops,   TRUE,  FALSE, ref_commit),
-       VIEW_(LOG,    "log",    &log_ops,    TRUE,  TRUE,  ref_head),
-       VIEW_(TREE,   "tree",   &tree_ops,   TRUE,  FALSE, ref_commit),
-       VIEW_(BLOB,   "blob",   &blob_ops,   TRUE,  FALSE, ref_blob),
-       VIEW_(BLAME,  "blame",  &blame_ops,  TRUE,  FALSE, ref_commit),
-       VIEW_(BRANCH, "branch", &branch_ops, TRUE,  TRUE,  ref_head),
-       VIEW_(HELP,   "help",   &help_ops,   FALSE, FALSE, ""),
-       VIEW_(PAGER,  "pager",  &pager_ops,  FALSE, FALSE, "stdin"),
-       VIEW_(STATUS, "status", &status_ops, TRUE,  TRUE,  ""),
-       VIEW_(STAGE,  "stage",  &stage_ops,  TRUE,  TRUE,  ""),
+       VIEW_(MAIN,   "main",   &main_ops,   TRUE,  ref_head),
+       VIEW_(DIFF,   "diff",   &diff_ops,   TRUE,  ref_commit),
+       VIEW_(LOG,    "log",    &log_ops,    TRUE,  ref_head),
+       VIEW_(TREE,   "tree",   &tree_ops,   TRUE,  ref_commit),
+       VIEW_(BLOB,   "blob",   &blob_ops,   TRUE,  ref_blob),
+       VIEW_(BLAME,  "blame",  &blame_ops,  TRUE,  ref_commit),
+       VIEW_(BRANCH, "branch", &branch_ops, TRUE,  ref_head),
+       VIEW_(HELP,   "help",   &help_ops,   FALSE, ""),
+       VIEW_(PAGER,  "pager",  &pager_ops,  FALSE, "stdin"),
+       VIEW_(STATUS, "status", &status_ops, TRUE,  ""),
+       VIEW_(STAGE,  "stage",  &stage_ops,  TRUE,  ""),
 };
 
 #define VIEW(req)      (&views[(req) - REQ_OFFSET - 1])
@@ -3622,11 +3620,8 @@ view_driver(struct view *view, enum request request)
 
        if (request > REQ_NONE) {
                open_run_request(request);
-               /* FIXME: When all views can refresh always do this. */
-               if (view->refresh)
-                       request = REQ_REFRESH;
-               else
-                       return TRUE;
+               view_request(view, REQ_REFRESH);
+               return TRUE;
        }
 
        request = view_request(view, request);
@@ -4531,7 +4526,7 @@ tree_read_date(struct view *view, char *text, bool *read_date)
                        return TRUE;
                }
 
-               if (!io_run_rd(&io, log_file, opt_cdup, FORMAT_NONE)) {
+               if (!io_run_rd(&io, log_file, opt_cdup)) {
                        report("Failed to load tree data");
                        return TRUE;
                }
@@ -4674,7 +4669,7 @@ open_blob_editor(const char *id)
 
        if (fd == -1)
                report("Failed to create temporary file");
-       else if (!io_run_append(blob_argv, FORMAT_NONE, fd))
+       else if (!io_run_append(blob_argv, fd))
                report("Failed to save blob data to file");
        else
                open_editor(file);
@@ -4886,18 +4881,6 @@ static struct view_ops blob_ops = {
  *     reading output from git-blame.
  */
 
-static const char *blame_head_argv[] = {
-       "git", "blame", "--incremental", "--", "%(file)", NULL
-};
-
-static const char *blame_ref_argv[] = {
-       "git", "blame", "--incremental", "%(ref)", "--", "%(file)", NULL
-};
-
-static const char *blame_cat_file_argv[] = {
-       "git", "cat-file", "blob", "%(ref):%(file)", NULL
-};
-
 struct blame_commit {
        char id[SIZEOF_REV];            /* SHA1 ID. */
        char title[128];                /* First line of the commit message. */
@@ -4925,7 +4908,12 @@ blame_open(struct view *view)
        }
 
        if (*opt_ref || !io_open(&view->io, "%s%s", opt_cdup, opt_file)) {
-               if (!io_run_rd(&view->io, blame_cat_file_argv, opt_cdup, FORMAT_ALL))
+               const char *blame_cat_file_argv[] = {
+                       "git", "cat-file", "blob", path, NULL
+               };
+
+               if (!string_format(path, "%s:%s", opt_ref, opt_file) ||
+                   !io_run_rd(&view->io, blame_cat_file_argv, opt_cdup))
                        return FALSE;
        }
 
@@ -5015,13 +5003,16 @@ static bool
 blame_read_file(struct view *view, const char *line, bool *read_file)
 {
        if (!line) {
-               const char **argv = *opt_ref ? blame_ref_argv : blame_head_argv;
+               const char *blame_argv[] = {
+                       "git", "blame", "--incremental",
+                               *opt_ref ? opt_ref : "--incremental", "--", opt_file, NULL
+               };
                struct io io = {};
 
                if (view->lines == 0 && !view->prev)
                        die("No blame exist for %s", view->vid);
 
-               if (view->lines == 0 || !io_run_rd(&io, argv, opt_cdup, FORMAT_ALL)) {
+               if (view->lines == 0 || !io_run_rd(&io, blame_argv, opt_cdup)) {
                        report("Failed to load blame data");
                        return TRUE;
                }
@@ -5455,7 +5446,7 @@ branch_open(struct view *view)
                        "--simplify-by-decoration", "--all", NULL
        };
 
-       if (!io_run_rd(&view->io, branch_log, NULL, FORMAT_NONE)) {
+       if (!io_run_rd(&view->io, branch_log, NULL)) {
                report("Failed to load branch data");
                return TRUE;
        }