index d2dff15fd17bcd60c6a56209a420f33c9fc37a5a..0d16f767be7d2375875d26c68b75060834364401 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -107,6 +107,7 @@ static size_t utf8_length(const char **string, size_t col, int *width, size_t ma
#define DATE_SHORT_COLS STRING_SIZE("2006-04-29 ")
#define ID_COLS 8
+#define AUTHOR_COLS 19
#define MIN_VIEW_HEIGHT 4
}
+#define AUTHOR_VALUES \
+ AUTHOR_(NO), \
+ AUTHOR_(FULL), \
+ AUTHOR_(ABBREVIATED)
+
+enum author {
+#define AUTHOR_(name) AUTHOR_##name
+ AUTHOR_VALUES,
+#undef AUTHOR_
+ AUTHOR_DEFAULT = AUTHOR_FULL
+};
+
+static const struct enum_map author_map[] = {
+#define AUTHOR_(name) ENUM_MAP(#name, AUTHOR_##name)
+ AUTHOR_VALUES
+#undef AUTHOR_
+};
+
+/* FIXME: Handle multi-byte and multi-column characters. */
+static const char *
+get_author_initials(const char *author, size_t max_columns)
+{
+ static char initials[AUTHOR_COLS];
+ size_t pos;
+
+#define is_initial_sep(c) (isspace(c) || ispunct(c) || (c) == '@' || (c) == '-')
+
+ memset(initials, 0, sizeof(initials));
+ for (pos = 0; *author && pos < sizeof(initials) - 1; author++, pos++) {
+ while (is_initial_sep(*author))
+ author++;
+ strncpy(&initials[pos], author, sizeof(initials) - 1 - pos);
+ while (*author && author[1] && !is_initial_sep(author[1]))
+ author++;
+ }
+
+ return initials;
+}
+
+
static bool
argv_from_string(const char *argv[SIZEOF_ARG], int *argc, char *cmd)
{
/* Option and state variables. */
static enum date opt_date = DATE_DEFAULT;
-static bool opt_author = TRUE;
+static enum author opt_author = AUTHOR_DEFAULT;
static bool opt_line_number = FALSE;
static bool opt_line_graphics = TRUE;
static bool opt_rev_graph = FALSE;
static double opt_hscroll = 0.50;
static double opt_scale_split_view = 2.0 / 3.0;
static int opt_tab_size = 8;
-static int opt_author_cols = 19;
+static int opt_author_cols = AUTHOR_COLS;
static char opt_path[SIZEOF_STR] = "";
static char opt_file[SIZEOF_STR] = "";
static char opt_ref[SIZEOF_REF] = "";
}
if (!strcmp(argv[0], "show-author"))
- return parse_bool(&opt_author, argv[2]);
+ return parse_enum(&opt_author, argv[2], author_map);
if (!strcmp(argv[0], "show-date"))
return parse_enum(&opt_date, argv[2], date_map);
static bool
draw_author(struct view *view, const char *author)
{
- bool trim = opt_author_cols == 0 || opt_author_cols > 5 || !author;
+ bool trim = opt_author_cols == 0 || opt_author_cols > 5;
+ bool abbreviate = opt_author == AUTHOR_ABBREVIATED || !trim;
- if (!trim) {
- static char initials[10];
- size_t pos;
-
-#define is_initial_sep(c) (isspace(c) || ispunct(c) || (c) == '@')
-
- memset(initials, 0, sizeof(initials));
- for (pos = 0; *author && pos < opt_author_cols - 1; author++, pos++) {
- while (is_initial_sep(*author))
- author++;
- strncpy(&initials[pos], author, sizeof(initials) - 1 - pos);
- while (*author && !is_initial_sep(author[1]))
- author++;
- }
-
- author = initials;
- }
+ if (abbreviate && author)
+ author = get_author_initials(author, opt_author_cols);
return draw_field(view, LINE_AUTHOR, author, opt_author_cols, trim);
}
toggle_enum_option_do(opt, help, map, ARRAY_SIZE(map))
#define toggle_date() toggle_enum_option(&opt_date, "dates", date_map)
+#define toggle_author() toggle_enum_option(&opt_author, "author names", author_map)
static void
toggle_view_option(bool *option, const char *help)
if (prompt_menu("Toggle option", menu, &selected)) {
if (menu[selected].data == &opt_date)
toggle_date();
+ else if (menu[selected].data == &opt_author)
+ toggle_author();
else
toggle_view_option(menu[selected].data, menu[selected].text);
}
{
if (view->pipe)
end_update(view, TRUE);
- return io_open(&view->io, "%s", name);
+ return io_open(&view->io, "%s/%s", opt_cdup[0] ? opt_cdup : ".", name);
}
static bool
}
static void
-open_editor(bool from_root, const char *file)
+open_editor(const char *file)
{
const char *editor_argv[] = { "vi", file, NULL };
const char *editor;
editor = "vi";
editor_argv[0] = editor;
- open_external_viewer(editor_argv, from_root ? opt_cdup : NULL);
+ open_external_viewer(editor_argv, opt_cdup);
}
static void
break;
case REQ_TOGGLE_AUTHOR:
- toggle_view_option(&opt_author, "author display");
+ toggle_author();
break;
case REQ_TOGGLE_REV_GRAPH:
if (add_title && help_open_keymap_title(view, keymap))
return;
- add_title = false;
+ add_title = FALSE;
if (group) {
add_line_text(view, group, LINE_HELP_GROUP);
else if (!run_io_append(blob_ops.argv, FORMAT_ALL, fd))
report("Failed to save blob data to file");
else
- open_editor(FALSE, file);
+ open_editor(file);
if (fd != -1)
unlink(file);
}
} else if (!is_head_commit(view->vid)) {
open_blob_editor();
} else {
- open_editor(TRUE, opt_file);
+ open_editor(opt_file);
}
return REQ_NONE;
};
static const char *status_list_other_argv[] = {
- "git", "ls-files", "-z", "--others", "--exclude-standard", NULL
+ "git", "ls-files", "-z", "--others", "--exclude-standard", opt_prefix, NULL
};
static const char *status_list_no_head_argv[] = {
return REQ_NONE;
}
- open_editor(status->status != '?', status->new.name);
+ open_editor(status->new.name);
break;
case REQ_VIEW_BLAME:
return REQ_NONE;
}
- open_editor(stage_status.status != '?', stage_status.new.name);
+ open_editor(stage_status.new.name);
break;
case REQ_REFRESH: