index f022f17a974b2424f32e6c729a191f6672ac2792..e7e34b1a3d3546f2e4b9f2192a2c65665467a766 100644 (file)
--- a/tig.c
+++ b/tig.c
static enum option_code
parse_args(const char ***args, const char *argv[])
{
- if (!argv_copy(args, argv))
+ if (*args == NULL && !argv_copy(args, argv))
return OPT_ERR_OUT_OF_MEMORY;
return OPT_OK;
}
if (argc < 3)
return OPT_ERR_WRONG_NUMBER_OF_ARGUMENTS;
- if (!opt_blame_argv && !strcmp(argv[0], "blame-options"))
+ if (strcmp(argv[1], "="))
+ return OPT_ERR_NO_VALUE_ASSIGNED;
+
+ if (!strcmp(argv[0], "blame-options"))
return parse_args(&opt_blame_argv, argv + 2);
if (argc != 3)
return OPT_ERR_WRONG_NUMBER_OF_ARGUMENTS;
- if (strcmp(argv[1], "="))
- return OPT_ERR_NO_VALUE_ASSIGNED;
-
if (!strcmp(argv[0], "show-author"))
return parse_enum(&opt_author, argv[2], author_map);
struct view {
enum view_type type; /* View type */
const char *name; /* View name */
- const char *cmd_env; /* Command line set via environment */
const char *id; /* Points to either of ref_{head,commit,blob} */
struct view_ops *ops; /* View operations */
time_t update_secs;
};
+enum open_flags {
+ OPEN_DEFAULT = 0, /* Use default view switching. */
+ OPEN_SPLIT = 1, /* Split current view. */
+ OPEN_RELOAD = 4, /* Reload view even if it is the current. */
+ OPEN_REFRESH = 16, /* Refresh view using previous command. */
+ OPEN_PREPARED = 32, /* Open already prepared command. */
+};
+
struct view_ops {
/* What type of content being displayed. Used in the title bar. */
const char *type;
/* Default command arguments. */
const char **argv;
/* Open and reads in all view content. */
- bool (*open)(struct view *view);
+ bool (*open)(struct view *view, enum open_flags flags);
/* Read one line; updates view->line. */
bool (*read)(struct view *view, char *data);
/* Draw one line; @lineno must be < view->height. */
static struct view_ops tree_ops;
static struct view_ops branch_ops;
-#define VIEW_STR(type, name, env, ref, ops, map, git) \
- { type, name, #env, ref, ops, map, git }
+#define VIEW_STR(type, name, ref, ops, map, git) \
+ { type, name, ref, ops, map, git }
#define VIEW_(id, name, ops, git, ref) \
- VIEW_STR(VIEW_##id, name, TIG_##id##_CMD, ref, ops, KEYMAP_##id, git)
+ VIEW_STR(VIEW_##id, name, ref, ops, KEYMAP_##id, git)
static struct view views[] = {
VIEW_(MAIN, "main", &main_ops, TRUE, ref_head),
}
}
+#define VIEW_MAX_LEN(view) ((view)->width + (view)->yoffset - (view)->col)
+
static int
draw_chars(struct view *view, enum line_type type, const char *string,
int max_len, bool use_tilde)
do {
size_t pos = string_expand(text, sizeof(text), string, opt_tab_size);
- view->col += draw_chars(view, type, text, view->width + view->yoffset - view->col, TRUE);
+ view->col += draw_chars(view, type, text, VIEW_MAX_LEN(view), TRUE);
string += pos;
- } while (*string && view->width + view->yoffset > view->col);
+ } while (*string && VIEW_MAX_LEN(view) > 0);
- return view->width + view->yoffset <= view->col;
+ return VIEW_MAX_LEN(view) <= 0;
}
static bool
draw_graphic(struct view *view, enum line_type type, const chtype graphic[], size_t size, bool separator)
{
size_t skip = view->yoffset > view->col ? view->yoffset - view->col : 0;
- int max = view->width + view->yoffset - view->col;
+ int max = VIEW_MAX_LEN(view);
int i;
if (max < size)
@@ -1615,13 +1624,13 @@ draw_graphic(struct view *view, enum line_type type, const chtype graphic[], siz
view->col++;
}
- return view->width + view->yoffset <= view->col;
+ return VIEW_MAX_LEN(view) <= 0;
}
static bool
draw_field(struct view *view, enum line_type type, const char *text, int len, bool trim)
{
- int max = MIN(view->width + view->yoffset - view->col, len);
+ int max = MIN(VIEW_MAX_LEN(view), len);
int col;
if (text)
@@ -1631,7 +1640,7 @@ draw_field(struct view *view, enum line_type type, const char *text, int len, bo
view->col += col;
view->col += draw_space(view, LINE_DEFAULT, max - col, max - col);
- return view->width + view->yoffset <= view->col;
+ return VIEW_MAX_LEN(view) <= 0;
}
static bool
{
char number[10];
int digits3 = view->digits < 3 ? 3 : view->digits;
- int max = MIN(view->width + view->yoffset - view->col, digits3);
+ int max = MIN(VIEW_MAX_LEN(view), digits3);
char *text = NULL;
chtype separator = opt_line_graphics ? ACS_VLINE : '|';
@@ -2686,14 +2695,6 @@ add_line_format(struct view *view, enum line_type type, const char *fmt, ...)
* View opening
*/
-enum open_flags {
- OPEN_DEFAULT = 0, /* Use default view switching. */
- OPEN_SPLIT = 1, /* Split current view. */
- OPEN_RELOAD = 4, /* Reload view even if it is the current. */
- OPEN_REFRESH = 16, /* Refresh view using previous command. */
- OPEN_PREPARED = 32, /* Open already prepared command. */
-};
-
static void
open_view(struct view *prev, enum request request, enum open_flags flags)
{
if (view->ops->open) {
if (view->pipe)
end_update(view, TRUE);
- if (!view->ops->open(view)) {
+ if (!view->ops->open(view, flags)) {
report("Failed to load %s view", view->name);
return;
}
}
static bool
-help_open(struct view *view)
+help_open(struct view *view, enum open_flags flags)
{
enum keymap keymap;
};
static bool
-blame_open(struct view *view)
+blame_open(struct view *view, enum open_flags flags)
{
char path[SIZEOF_STR];
size_t i;
}
static bool
-branch_open(struct view *view)
+branch_open(struct view *view, enum open_flags flags)
{
const char *branch_log[] = {
"git", "log", "--no-color", "--pretty=raw",
* info using git-diff-files(1), and finally untracked files using
* git-ls-files(1). */
static bool
-status_open(struct view *view)
+status_open(struct view *view, enum open_flags flags)
{
reset_view(view);
const char *codeset = "UTF-8";
enum request request = parse_options(argc, argv);
struct view *view;
- size_t i;
signal(SIGINT, quit);
signal(SIGPIPE, SIG_IGN);
if (load_refs() == ERR)
die("Failed to load refs.");
- foreach_view (view, i) {
- if (getenv(view->cmd_env))
- warn("Use of the %s environment variable is deprecated,"
- " use options or TIG_DIFF_ARGS instead",
- view->cmd_env);
- if (!argv_from_env(view->ops->argv, view->cmd_env))
- die("Too many arguments in the `%s` environment variable",
- view->cmd_env);
- }
-
init_display();
while (view_driver(display[current_view], request)) {