X-Git-Url: https://git.tokkee.org/?p=tig.git;a=blobdiff_plain;f=tig.c;h=86be4a2973615219fb321863eaa648e73210a8b6;hp=46f289ec1335debbcff6bc0ba014455bf7d06c77;hb=01223083701dfebf0d5588b4217452b902e3a78b;hpb=2ae980f4dec0c8f239fa00544c29a4869117db7c diff --git a/tig.c b/tig.c index 46f289e..86be4a2 100644 --- a/tig.c +++ b/tig.c @@ -685,15 +685,18 @@ argv_free(const char *argv[]) for (argc = 0; argv[argc]; argc++) free((void *) argv[argc]); + 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; } @@ -747,15 +750,7 @@ static void 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); -} - -static bool -io_format(struct io *io, const char *dir, enum io_type type, - const char *argv[], enum format_flags flags) -{ - io_init(io, dir, type); - return format_argv(io->argv, argv, flags); + argv_copy(io->argv, argv, FALSE); } static bool @@ -879,44 +874,32 @@ io_run(struct io *io, const char **argv, const char *dir, enum io_type type) return io_start(io); } -static int -io_complete(struct io *io) -{ - return io_start(io) && io_done(io); -} - -static int -io_run_bg(const char **argv) +static bool +io_complete(enum io_type type, const char **argv, const char *dir, int fd) { struct io io = {}; - io_prepare(&io, NULL, IO_BG, argv); - return io_complete(&io); + io_prepare(&io, dir, type, argv); + io.pipe = fd; + return io_start(&io) && io_done(&io); } static bool -io_run_fg(const char **argv, const char *dir) +io_run_bg(const char **argv) { - struct io io = {}; - - io_prepare(&io, dir, IO_FG, argv); - return io_complete(&io); + return io_complete(IO_BG, argv, NULL, -1); } static bool -io_run_append(const char **argv, int fd) +io_run_fg(const char **argv, const char *dir) { - struct io io = {}; - - io_prepare(&io, NULL, IO_AP, argv); - io.pipe = fd; - return io_complete(&io); + return io_complete(IO_FG, argv, dir, -1); } static bool -io_run_rd(struct io *io, const char **argv, const char *dir) +io_run_append(const char **argv, int fd) { - return io_format(io, dir, IO_RD, argv, FORMAT_NONE) && io_start(io); + return io_complete(IO_AP, argv, NULL, -1); } static bool @@ -1754,7 +1737,7 @@ add_run_request(enum keymap keymap, int key, int argc, const char **argv) 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; @@ -3287,12 +3270,28 @@ setup_update(struct view *view, const char *vid) view->start_time = time(NULL); } +static bool +prepare_io(struct view *view, const char *dir, const char *argv[], bool replace) +{ + io_init(&view->io, dir, IO_RD); + return format_argv(view->io.argv, argv, replace ? FORMAT_ALL : FORMAT_NONE); +} + static bool prepare_update(struct view *view, const char *argv[], const char *dir) { if (view->pipe) end_update(view, TRUE); - return io_format(&view->io, dir, IO_RD, argv, FORMAT_NONE); + return prepare_io(view, dir, argv, FALSE); +} + +static bool +start_update(struct view *view, const char **argv, const char *dir) +{ + if (view->pipe) + io_done(view->pipe); + return prepare_io(view, dir, argv, FALSE) && + io_start(&view->io); } static bool @@ -3313,7 +3312,7 @@ begin_update(struct view *view, bool refresh) if (view->ops->prepare) { if (!view->ops->prepare(view)) return FALSE; - } else if (!io_format(&view->io, NULL, IO_RD, view->ops->argv, FORMAT_ALL)) { + } else if (!prepare_io(view, NULL, view->ops->argv, TRUE)) { return FALSE; } @@ -4527,7 +4526,6 @@ tree_read_date(struct view *view, char *text, bool *read_date) "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); @@ -4535,13 +4533,11 @@ tree_read_date(struct view *view, char *text, bool *read_date) 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; @@ -4825,7 +4821,7 @@ tree_prepare(struct view *view) opt_path[0] = 0; } - return io_format(&view->io, opt_cdup, IO_RD, view->ops->argv, FORMAT_ALL); + return prepare_io(view, opt_cdup, view->ops->argv, TRUE); } static const char *tree_argv[SIZEOF_ARG] = { @@ -4922,7 +4918,7 @@ blame_open(struct view *view) }; 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; } @@ -5016,18 +5012,15 @@ blame_read_file(struct view *view, const char *line, bool *read_file) "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; @@ -5455,7 +5448,7 @@ branch_open(struct view *view) "--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; }