summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ea035bc)
raw | patch | inline | side by side (parent: ea035bc)
author | Jonas Fonseca <fonseca@diku.dk> | |
Thu, 27 Nov 2008 16:55:52 +0000 (17:55 +0100) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 13 Jan 2009 21:55:18 +0000 (22:55 +0100) |
tig.c | patch | blob | history |
index d77180928d42e710323f6266ac024bdaf4bb8867..6665d61145761253a6278403927a369e62bc07cb 100644 (file)
--- a/tig.c
+++ b/tig.c
io->dir = dir;
}
+static bool
+init_io_rd(struct io *io, const char *argv[], const char *dir,
+ enum format_flags flags)
+{
+ init_io(io, dir, IO_RD);
+ return format_command(io->sh, argv, flags);
+}
+
static bool
init_io_fd(struct io *io, FILE *pipe)
{
view->start_time = time(NULL);
}
+static bool
+prepare_update(struct view *view, const char *argv[], const char *dir,
+ enum format_flags flags)
+{
+ if (view->pipe)
+ end_update(view, TRUE);
+ return init_io_rd(&view->io, argv, dir, flags);
+}
+
static bool
begin_update(struct view *view, bool refresh)
{
} else if (opt_cmd[0]) {
if (!run_io(&view->io, IO_RD, opt_cmd))
return FALSE;
- /* When running random commands, initially show the
- * command in the title. However, it maybe later be
- * overwritten if a commit line is selected. */
- if (view == VIEW(REQ_VIEW_PAGER))
- string_copy(view->ref, opt_cmd);
- else
- view->ref[0] = 0;
+ view->ref[0] = 0;
opt_cmd[0] = 0;
} else if (refresh) {
OPEN_RELOAD = 4, /* Reload view even if it is the current. */
OPEN_NOMAXIMIZE = 8, /* Do not maximize the current view. */
OPEN_REFRESH = 16, /* Refresh view using previous command. */
+ OPEN_PREPARED = 32, /* Open already prepared command. */
};
static void
{
bool backgrounded = !!(flags & OPEN_BACKGROUNDED);
bool split = !!(flags & OPEN_SPLIT);
- bool reload = !!(flags & (OPEN_RELOAD | OPEN_REFRESH));
+ bool reload = !!(flags & (OPEN_RELOAD | OPEN_REFRESH | OPEN_PREPARED));
bool nomaximize = !!(flags & (OPEN_NOMAXIMIZE | OPEN_REFRESH));
struct view *view = VIEW(request);
int nviews = displayed_views();
}
} else if ((reload || strcmp(view->vid, view->id)) &&
- !begin_update(view, flags & OPEN_REFRESH)) {
+ !begin_update(view, flags & (OPEN_REFRESH | OPEN_PREPARED))) {
report("Failed to load %s view", view->name);
return;
}
read_prompt(const char *prompt)
{
enum { READING, STOP, CANCEL } status = READING;
- static char buf[sizeof(opt_cmd) - STRING_SIZE("git \0")];
+ static char buf[SIZEOF_STR];
int pos = 0;
while (status == READING) {
{
char *cmd = read_prompt(":");
- if (cmd && string_format(opt_cmd, "git %s", cmd)) {
- if (strncmp(cmd, "show", 4) && isspace(cmd[4])) {
- request = REQ_VIEW_DIFF;
+ if (cmd) {
+ struct view *next = VIEW(REQ_VIEW_PAGER);
+ const char *argv[SIZEOF_ARG] = { "git" };
+ int argc = 1;
+
+ /* When running random commands, initially show the
+ * command in the title. However, it maybe later be
+ * overwritten if a commit line is selected. */
+ string_ncopy(next->ref, cmd, strlen(cmd));
+
+ if (!argv_from_string(argv, &argc, cmd)) {
+ report("Too many arguments");
+ } else if (!prepare_update(next, argv, NULL, FORMAT_DASH)) {
+ report("Failed to format command");
} else {
- request = REQ_VIEW_PAGER;
+ open_view(view, REQ_VIEW_PAGER, OPEN_PREPARED);
}
-
- /* Always reload^Wrerun commands from the prompt. */
- open_view(view, request, OPEN_RELOAD);
}
request = REQ_NONE;