index f842de567b03108f63dbfe44f3ec7af3bed82a9d..1bf95cda407dbcc43715223558e0c38fa20cdda3 100644 (file)
--- a/tig.c
+++ b/tig.c
argv[0] = NULL;
}
-static void
-argv_copy(const char *dst[], const char *src[])
+static bool
+argv_copy(const char *dst[], const char *src[], bool allocate)
{
int argc;
for (argc = 0; src[argc]; argc++)
- dst[argc] = src[argc];
+ if (!(dst[argc] = allocate ? strdup(src[argc]) : src[argc]))
+ return FALSE;
+ return TRUE;
}
io_prepare(struct io *io, const char *dir, enum io_type type, const char *argv[])
{
io_init(io, dir, type);
- argv_copy(io->argv, argv);
+ argv_copy(io->argv, argv, FALSE);
}
static bool
return io_complete(IO_AP, argv, NULL, -1);
}
-static bool
-io_run_rd(struct io *io, const char **argv, const char *dir)
-{
- return io_format(io, dir, IO_RD, argv, FORMAT_NONE) && io_start(io);
-}
-
static bool
io_eof(struct io *io)
{
req->key = key;
req->argv[0] = NULL;
- if (!format_argv(req->argv, argv, FORMAT_NONE))
+ if (!argv_copy(req->argv, argv, TRUE))
return REQ_NONE;
return REQ_NONE + ++run_requests;
return io_format(&view->io, dir, IO_RD, argv, FORMAT_NONE);
}
+static bool
+start_update(struct view *view, const char **argv, const char *dir)
+{
+ if (view->pipe)
+ io_done(view->pipe);
+ return io_format(&view->io, dir, IO_RD, argv, FORMAT_NONE) &&
+ io_start(&view->io);
+}
+
static bool
prepare_update_file(struct view *view, const char *name)
{
"git", "log", "--no-color", "--pretty=raw",
"--cc", "--raw", view->id, "--", path, NULL
};
- struct io io = {};
if (!view->lines) {
tree_entry(view, LINE_TREE_HEAD, opt_path, NULL, NULL);
return TRUE;
}
- if (!io_run_rd(&io, log_file, opt_cdup)) {
+ if (!start_update(view, log_file, opt_cdup)) {
report("Failed to load tree data");
return TRUE;
}
- io_done(view->pipe);
- view->io = io;
*read_date = TRUE;
return FALSE;
};
if (!string_format(path, "%s:%s", opt_ref, opt_file) ||
- !io_run_rd(&view->io, blame_cat_file_argv, opt_cdup))
+ !start_update(view, blame_cat_file_argv, opt_cdup))
return FALSE;
}
"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, blame_argv, opt_cdup)) {
+ if (view->lines == 0 || !start_update(view, blame_argv, opt_cdup)) {
report("Failed to load blame data");
return TRUE;
}
- io_done(view->pipe);
- view->io = io;
*read_file = FALSE;
return FALSE;
"--simplify-by-decoration", "--all", NULL
};
- if (!io_run_rd(&view->io, branch_log, NULL)) {
+ if (!start_update(view, branch_log, NULL)) {
report("Failed to load branch data");
return TRUE;
}