index 54821405ed627ab290c3c5b366b3710151703ffa..41d8123379eec382c30f9e7d9e9bb9c1f09892d2 100644 (file)
--- a/tig.c
+++ b/tig.c
#include <sys/stat.h>
#include <sys/select.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/select.h>
#include <unistd.h>
+#include <sys/time.h>
#include <time.h>
#include <fcntl.h>
#include <time.h>
#include <fcntl.h>
@@ -113,10 +114,6 @@ static size_t utf8_length(const char **string, size_t col, int *width, size_t ma
#define S_ISGITLINK(mode) (((mode) & S_IFMT) == 0160000)
#define S_ISGITLINK(mode) (((mode) & S_IFMT) == 0160000)
-#ifndef GIT_CONFIG
-#define GIT_CONFIG "config"
-#endif
-
/* Some ASCII-shorthands fitted into the ncurses namespace. */
#define KEY_TAB '\t'
#define KEY_RETURN '\r'
/* Some ASCII-shorthands fitted into the ncurses namespace. */
#define KEY_TAB '\t'
#define KEY_RETURN '\r'
};
static struct ref_list *get_ref_list(const char *id);
};
static struct ref_list *get_ref_list(const char *id);
-static void foreach_ref(bool (*visitor)(void *data, struct ref *ref), void *data);
+static void foreach_ref(bool (*visitor)(void *data, const struct ref *ref), void *data);
static int load_refs(void);
enum format_flags {
static int load_refs(void);
enum format_flags {
#define ENUM_MAP(name, value) { name, STRING_SIZE(name), value }
#define ENUM_MAP(name, value) { name, STRING_SIZE(name), value }
+static char *
+enum_map_name(const char *name, size_t namelen)
+{
+ static char buf[SIZEOF_STR];
+ int bufpos;
+
+ for (bufpos = 0; bufpos <= namelen; bufpos++) {
+ buf[bufpos] = tolower(name[bufpos]);
+ if (buf[bufpos] == '_')
+ buf[bufpos] = '-';
+ }
+
+ buf[bufpos] = 0;
+ return buf;
+}
+
+#define enum_name(entry) enum_map_name((entry).name, (entry).namelen)
+
static bool
map_enum_do(const struct enum_map *map, size_t map_size, int *value, const char *name)
{
static bool
map_enum_do(const struct enum_map *map, size_t map_size, int *value, const char *name)
{
}
}
-static const char *
-mkdate(const time_t *time)
+/*
+ * What value of "tz" was in effect back then at "time" in the
+ * local timezone?
+ */
+static int local_tzoffset(time_t time)
+{
+ time_t t, t_local;
+ struct tm tm;
+ int offset, eastwest;
+
+ t = time;
+ localtime_r(&t, &tm);
+ t_local = mktime(&tm);
+
+ if (t_local < t) {
+ eastwest = -1;
+ offset = t - t_local;
+ } else {
+ eastwest = 1;
+ offset = t_local - t;
+ }
+ offset /= 60; /* in minutes */
+ offset = (offset % 60) + ((offset / 60) * 100);
+ return offset * eastwest;
+}
+
+enum date {
+ DATE_NONE = 0,
+ DATE_DEFAULT,
+ DATE_RELATIVE,
+ DATE_SHORT
+};
+
+static char *
+string_date(const time_t *time, enum date date)
{
static char buf[DATE_COLS + 1];
{
static char buf[DATE_COLS + 1];
+ static const struct enum_map reldate[] = {
+ { "second", 1, 60 * 2 },
+ { "minute", 60, 60 * 60 * 2 },
+ { "hour", 60 * 60, 60 * 60 * 24 * 2 },
+ { "day", 60 * 60 * 24, 60 * 60 * 24 * 7 * 2 },
+ { "week", 60 * 60 * 24 * 7, 60 * 60 * 24 * 7 * 5 },
+ { "month", 60 * 60 * 24 * 30, 60 * 60 * 24 * 30 * 12 },
+ };
struct tm tm;
struct tm tm;
+ if (date == DATE_RELATIVE) {
+ struct timeval now;
+ time_t date = *time + local_tzoffset(*time);
+ time_t seconds;
+ int i;
+
+ gettimeofday(&now, NULL);
+ seconds = now.tv_sec < date ? date - now.tv_sec : now.tv_sec - date;
+ for (i = 0; i < ARRAY_SIZE(reldate); i++) {
+ if (seconds >= reldate[i].value)
+ continue;
+
+ seconds /= reldate[i].namelen;
+ if (!string_format(buf, "%ld %s%s %s",
+ seconds, reldate[i].name,
+ seconds > 1 ? "s" : "",
+ now.tv_sec >= date ? "ago" : "ahead"))
+ break;
+ return buf;
+ }
+ }
+
gmtime_r(time, &tm);
return strftime(buf, sizeof(buf), DATE_FORMAT, &tm) ? buf : NULL;
}
gmtime_r(time, &tm);
return strftime(buf, sizeof(buf), DATE_FORMAT, &tm) ? buf : NULL;
}
}
static bool
}
static bool
-io_open(struct io *io, const char *name)
+io_open(struct io *io, const char *fmt, ...)
{
{
+ char name[SIZEOF_STR] = "";
+ bool fits;
+ va_list args;
+
init_io(io, NULL, IO_FD);
init_io(io, NULL, IO_FD);
+
+ va_start(args, fmt);
+ fits = vsnprintf(name, sizeof(name), fmt, args) < sizeof(name);
+ va_end(args);
+
+ if (!fits) {
+ io->error = ENAMETOOLONG;
+ return FALSE;
+ }
io->pipe = *name ? open(name, O_RDONLY) : STDIN_FILENO;
if (io->pipe == -1)
io->error = errno;
io->pipe = *name ? open(name, O_RDONLY) : STDIN_FILENO;
if (io->pipe == -1)
io->error = errno;
}
static bool
}
static bool
-run_io_rd(struct io *io, const char **argv, enum format_flags flags)
+run_io_rd(struct io *io, const char **argv, const char *dir, enum format_flags flags)
{
{
- return init_io_rd(io, argv, NULL, flags) && start_io(io);
+ return init_io_rd(io, argv, dir, flags) && start_io(io);
}
static bool
}
static bool
{
struct io io = {};
{
struct io io = {};
- return run_io_rd(&io, argv, FORMAT_NONE) && io_read_buf(&io, buf, bufsize);
+ return run_io_rd(&io, argv, NULL, FORMAT_NONE)
+ && io_read_buf(&io, buf, bufsize);
}
static int
}
static int
*/
/* Option and state variables. */
*/
/* Option and state variables. */
-static bool opt_date = TRUE;
-static bool opt_date_short = FALSE;
+static enum date opt_date = DATE_DEFAULT;
static bool opt_author = TRUE;
static bool opt_line_number = FALSE;
static bool opt_line_graphics = TRUE;
static bool opt_author = TRUE;
static bool opt_line_number = FALSE;
static bool opt_line_graphics = TRUE;
static char opt_head_rev[SIZEOF_REV] = "";
static char opt_remote[SIZEOF_REF] = "";
static char opt_encoding[20] = "UTF-8";
static char opt_head_rev[SIZEOF_REV] = "";
static char opt_remote[SIZEOF_REF] = "";
static char opt_encoding[20] = "UTF-8";
-static bool opt_utf8 = TRUE;
static char opt_codeset[20] = "UTF-8";
static char opt_codeset[20] = "UTF-8";
-static iconv_t opt_iconv = ICONV_NONE;
+static iconv_t opt_iconv_in = ICONV_NONE;
+static iconv_t opt_iconv_out = ICONV_NONE;
static char opt_search[SIZEOF_STR] = "";
static char opt_cdup[SIZEOF_STR] = "";
static char opt_prefix[SIZEOF_STR] = "";
static char opt_search[SIZEOF_STR] = "";
static char opt_cdup[SIZEOF_STR] = "";
static char opt_prefix[SIZEOF_STR] = "";
#define is_initial_commit() (!*opt_head_rev)
#define is_head_commit(rev) (!strcmp((rev), "HEAD") || !strcmp(opt_head_rev, (rev)))
#define is_initial_commit() (!*opt_head_rev)
#define is_head_commit(rev) (!strcmp((rev), "HEAD") || !strcmp(opt_head_rev, (rev)))
+#define mkdate(time) string_date(time, opt_date)
/*
/*
{ 'o', REQ_OPTIONS },
{ '.', REQ_TOGGLE_LINENO },
{ 'D', REQ_TOGGLE_DATE },
{ 'o', REQ_OPTIONS },
{ '.', REQ_TOGGLE_LINENO },
{ 'D', REQ_TOGGLE_DATE },
- { 'T', REQ_TOGGLE_DATE_SHORT },
{ 'A', REQ_TOGGLE_AUTHOR },
{ 'g', REQ_TOGGLE_REV_GRAPH },
{ 'F', REQ_TOGGLE_REFS },
{ 'A', REQ_TOGGLE_AUTHOR },
{ 'g', REQ_TOGGLE_REV_GRAPH },
{ 'F', REQ_TOGGLE_REFS },
if (!strcmp(argv[0], "show-author"))
return parse_bool(&opt_author, argv[2]);
if (!strcmp(argv[0], "show-author"))
return parse_bool(&opt_author, argv[2]);
- if (!strcmp(argv[0], "show-date"))
- return parse_bool(&opt_date, argv[2]);
-
- if (!strcmp(argv[0], "date-short"))
- return parse_bool(&opt_date_short, argv[2]);
+ if (!strcmp(argv[0], "show-date")) {
+ bool show_date;
+
+ if (!strcmp(argv[2], "relative")) {
+ opt_date = DATE_RELATIVE;
+ return OK;
+ } else if (!strcmp(argv[2], "short")) {
+ opt_date = DATE_SHORT;
+ return OK;
+ } else if (parse_bool(&show_date, argv[2]) == OK) {
+ opt_date = show_date ? DATE_DEFAULT : DATE_NONE;
+ return OK;
+ }
+ return ERR;
+ }
if (!strcmp(argv[0], "show-rev-graph"))
return parse_bool(&opt_rev_graph, argv[2]);
if (!strcmp(argv[0], "show-rev-graph"))
return parse_bool(&opt_rev_graph, argv[2]);
struct io io = {};
/* It's OK that the file doesn't exist. */
struct io io = {};
/* It's OK that the file doesn't exist. */
- if (!io_open(&io, path))
+ if (!io_open(&io, "%s", path))
return;
config_lineno = 0;
return;
config_lineno = 0;
bool (*grep)(struct view *view, struct line *line);
/* Select line */
void (*select)(struct view *view, struct line *line);
bool (*grep)(struct view *view, struct line *line);
/* Select line */
void (*select)(struct view *view, struct line *line);
+ /* Prepare view for loading */
+ bool (*prepare)(struct view *view);
};
static struct view_ops blame_ops;
};
static struct view_ops blame_ops;
draw_chars(struct view *view, enum line_type type, const char *string,
int max_len, bool use_tilde)
{
draw_chars(struct view *view, enum line_type type, const char *string,
int max_len, bool use_tilde)
{
+ static char out_buffer[BUFSIZ * 2];
int len = 0;
int col = 0;
int trimmed = FALSE;
int len = 0;
int col = 0;
int trimmed = FALSE;
if (max_len <= 0)
return 0;
if (max_len <= 0)
return 0;
- if (opt_utf8) {
- len = utf8_length(&string, skip, &col, max_len, &trimmed, use_tilde);
- } else {
- col = len = strlen(string);
- if (len > max_len) {
- if (use_tilde) {
- max_len -= 1;
+ len = utf8_length(&string, skip, &col, max_len, &trimmed, use_tilde);
+
+ set_view_attr(view, type);
+ if (len > 0) {
+ if (opt_iconv_out != ICONV_NONE) {
+ ICONV_CONST char *inbuf = (ICONV_CONST char *) string;
+ size_t inlen = len + 1;
+
+ char *outbuf = out_buffer;
+ size_t outlen = sizeof(out_buffer);
+
+ size_t ret;
+
+ ret = iconv(opt_iconv_out, &inbuf, &inlen, &outbuf, &outlen);
+ if (ret != (size_t) -1) {
+ string = out_buffer;
+ len = sizeof(out_buffer) - outlen;
}
}
- col = len = max_len;
- trimmed = TRUE;
}
}
- }
- set_view_attr(view, type);
- if (len > 0)
waddnstr(view->win, string, len);
waddnstr(view->win, string, len);
+ }
if (trimmed && use_tilde) {
set_view_attr(view, LINE_DELIMITER);
waddch(view->win, '~');
if (trimmed && use_tilde) {
set_view_attr(view, LINE_DELIMITER);
waddch(view->win, '~');
@@ -2077,8 +2187,8 @@ draw_field(struct view *view, enum line_type type, const char *text, int len, bo
static bool
draw_date(struct view *view, time_t *time)
{
static bool
draw_date(struct view *view, time_t *time)
{
- const char *date = mkdate(time);
- int cols = opt_date_short ? DATE_SHORT_COLS : DATE_COLS;
+ const char *date = time ? mkdate(time) : "";
+ int cols = opt_date == DATE_SHORT ? DATE_SHORT_COLS : DATE_COLS;
return draw_field(view, LINE_DATE, date, cols, FALSE);
}
return draw_field(view, LINE_DATE, date, cols, FALSE);
}
}
}
}
}
+static void
+toggle_date_option(enum date *date)
+{
+ static const char *help[] = {
+ "no",
+ "default",
+ "relative",
+ "short"
+ };
+
+ *date = (*date + 1) % ARRAY_SIZE(help);
+ redraw_display(FALSE);
+ report("Displaying %s dates", help[*date]);
+}
+
static void
toggle_view_option(bool *option, const char *help)
{
static void
toggle_view_option(bool *option, const char *help)
{
};
int selected = 0;
};
int selected = 0;
- if (prompt_menu("Toggle option", menu, &selected))
- toggle_view_option(menu[selected].data, menu[selected].text);
+ if (prompt_menu("Toggle option", menu, &selected)) {
+ if (menu[selected].data == &opt_date)
+ toggle_date_option(menu[selected].data);
+ else
+ toggle_view_option(menu[selected].data, menu[selected].text);
+ }
}
static void
}
static void
{
if (view->pipe)
end_update(view, TRUE);
{
if (view->pipe)
end_update(view, TRUE);
- return io_open(&view->io, name);
+ return io_open(&view->io, "%s", name);
}
static bool
}
static bool
if (view->pipe)
end_update(view, TRUE);
if (view->pipe)
end_update(view, TRUE);
- if (refresh) {
- if (!start_io(&view->io))
- return FALSE;
-
- } else {
- if (view == VIEW(REQ_VIEW_TREE) && strcmp(view->vid, view->id))
- opt_path[0] = 0;
-
- if (!run_io_rd(&view->io, view->ops->argv, FORMAT_ALL))
+ if (!refresh) {
+ if (view->ops->prepare) {
+ if (!view->ops->prepare(view))
+ return FALSE;
+ } else if (!init_io_rd(&view->io, view->ops->argv, NULL, FORMAT_ALL)) {
return FALSE;
return FALSE;
+ }
/* Put the current ref_* value to the view title ref
* member. This is needed by the blob view. Most other
/* Put the current ref_* value to the view title ref
* member. This is needed by the blob view. Most other
string_copy_rev(view->ref, view->id);
}
string_copy_rev(view->ref, view->id);
}
+ if (!start_io(&view->io))
+ return FALSE;
+
setup_update(view, view->id);
return TRUE;
setup_update(view, view->id);
return TRUE;
}
for (; (line = io_get(view->pipe, '\n', can_read)); can_read = FALSE) {
}
for (; (line = io_get(view->pipe, '\n', can_read)); can_read = FALSE) {
- if (opt_iconv != ICONV_NONE) {
+ if (opt_iconv_in != ICONV_NONE) {
ICONV_CONST char *inbuf = line;
size_t inlen = strlen(line) + 1;
ICONV_CONST char *inbuf = line;
size_t inlen = strlen(line) + 1;
size_t ret;
size_t ret;
- ret = iconv(opt_iconv, &inbuf, &inlen, &outbuf, &outlen);
+ ret = iconv(opt_iconv_in, &inbuf, &inlen, &outbuf, &outlen);
if (ret != (size_t) -1)
line = out_buffer;
}
if (ret != (size_t) -1)
line = out_buffer;
}
display[current_view] = view;
}
display[current_view] = view;
}
+ /* No parent signals that this is the first loaded view. */
+ if (prev && view != prev) {
+ view->parent = prev;
+ }
+
/* Resize the view when switching between split- and full-screen,
* or when switching between two different full-screen views. */
if (nviews != displayed_views() ||
/* Resize the view when switching between split- and full-screen,
* or when switching between two different full-screen views. */
if (nviews != displayed_views() ||
do_scroll_view(prev, lines);
}
do_scroll_view(prev, lines);
}
- if (prev && view != prev) {
- if (split) {
- /* "Blur" the previous view. */
- update_view_title(prev);
- }
-
- view->parent = prev;
+ if (prev && view != prev && split && view_is_displayed(prev)) {
+ /* "Blur" the previous view. */
+ update_view_title(prev);
}
if (view->pipe && view->lines == 0) {
}
if (view->pipe && view->lines == 0) {
break;
case REQ_TOGGLE_DATE:
break;
case REQ_TOGGLE_DATE:
- toggle_view_option(&opt_date, "date display");
- break;
-
- case REQ_TOGGLE_DATE_SHORT:
- toggle_view_option(&opt_date_short, "date shortening");
+ toggle_date_option(&opt_date);
break;
case REQ_TOGGLE_AUTHOR:
break;
case REQ_TOGGLE_AUTHOR:
static bool help_keymap_hidden[ARRAY_SIZE(keymap_table)];
static bool help_keymap_hidden[ARRAY_SIZE(keymap_table)];
-static char *
-help_name(char buf[SIZEOF_STR], const char *name, size_t namelen)
-{
- int bufpos;
-
- for (bufpos = 0; bufpos <= namelen; bufpos++) {
- buf[bufpos] = tolower(name[bufpos]);
- if (buf[bufpos] == '_')
- buf[bufpos] = '-';
- }
-
- buf[bufpos] = 0;
- return buf;
-}
-
-#define help_keymap_name(buf, keymap) \
- help_name(buf, keymap_table[keymap].name, keymap_table[keymap].namelen)
-
static bool
help_open_keymap_title(struct view *view, enum keymap keymap)
{
static bool
help_open_keymap_title(struct view *view, enum keymap keymap)
{
- char buf[SIZEOF_STR];
struct line *line;
line = add_line_format(view, LINE_HELP_KEYMAP, "[%c] %s bindings",
help_keymap_hidden[keymap] ? '+' : '-',
struct line *line;
line = add_line_format(view, LINE_HELP_KEYMAP, "[%c] %s bindings",
help_keymap_hidden[keymap] ? '+' : '-',
- help_keymap_name(buf, keymap));
+ enum_name(keymap_table[keymap]));
if (line)
line->other = keymap;
if (line)
line->other = keymap;
}
add_line_format(view, LINE_DEFAULT, " %-25s %-20s %s", key,
}
add_line_format(view, LINE_DEFAULT, " %-25s %-20s %s", key,
- help_name(buf, req_info[i].name, req_info[i].namelen),
- req_info[i].help);
+ enum_name(req_info[i]), req_info[i].help);
}
group = "External commands:";
}
group = "External commands:";
return TRUE;
}
return TRUE;
}
- if (!run_io_rd(&io, log_file, FORMAT_NONE)) {
+ if (!run_io_rd(&io, log_file, opt_cdup, FORMAT_NONE)) {
report("Failed to load tree data");
return TRUE;
}
report("Failed to load tree data");
return TRUE;
}
if (!pos)
return TRUE;
text = pos + 1;
if (!pos)
return TRUE;
text = pos + 1;
- if (*opt_prefix && !strncmp(text, opt_prefix, strlen(opt_prefix)))
- text += strlen(opt_prefix);
if (*opt_path && !strncmp(text, opt_path, strlen(opt_path)))
text += strlen(opt_path);
pos = strchr(text, '/');
if (*opt_path && !strncmp(text, opt_path, strlen(opt_path)))
text += strlen(opt_path);
pos = strchr(text, '/');
string_copy_rev(view->ref, entry->id);
}
string_copy_rev(view->ref, entry->id);
}
+static bool
+tree_prepare(struct view *view)
+{
+ if (view->lines == 0 && opt_prefix[0]) {
+ char *pos = opt_prefix;
+
+ while (pos && *pos) {
+ char *end = strchr(pos, '/');
+
+ if (end)
+ *end = 0;
+ push_tree_stack_entry(pos, 0);
+ pos = end;
+ if (end) {
+ *end = '/';
+ pos++;
+ }
+ }
+
+ } else if (strcmp(view->vid, view->id)) {
+ opt_path[0] = 0;
+ }
+
+ return init_io_rd(&view->io, view->ops->argv, opt_cdup, FORMAT_ALL);
+}
+
static const char *tree_argv[SIZEOF_ARG] = {
"git", "ls-tree", "%(commit)", "%(directory)", NULL
};
static const char *tree_argv[SIZEOF_ARG] = {
"git", "ls-tree", "%(commit)", "%(directory)", NULL
};
tree_request,
tree_grep,
tree_select,
tree_request,
tree_grep,
tree_select,
+ tree_prepare,
};
static bool
};
static bool
static bool
blame_open(struct view *view)
{
static bool
blame_open(struct view *view)
{
- if (*opt_ref || !io_open(&view->io, opt_file)) {
- if (!run_io_rd(&view->io, blame_cat_file_argv, FORMAT_ALL))
+ char path[SIZEOF_STR];
+
+ if (!view->parent && *opt_prefix) {
+ string_copy(path, opt_file);
+ if (!string_format(opt_file, "%s%s", opt_prefix, path))
+ return FALSE;
+ }
+
+ if (*opt_ref || !io_open(&view->io, "%s%s", opt_cdup, opt_file)) {
+ if (!run_io_rd(&view->io, blame_cat_file_argv, opt_cdup, FORMAT_ALL))
return FALSE;
}
return FALSE;
}
if (view->lines == 0 && !view->parent)
die("No blame exist for %s", view->vid);
if (view->lines == 0 && !view->parent)
die("No blame exist for %s", view->vid);
- if (view->lines == 0 || !run_io_rd(&io, argv, FORMAT_ALL)) {
+ if (view->lines == 0 || !run_io_rd(&io, argv, opt_cdup, FORMAT_ALL)) {
report("Failed to load blame data");
return TRUE;
}
report("Failed to load blame data");
return TRUE;
}
struct branch {
const char *author; /* Author of the last commit. */
time_t time; /* Date of the last activity. */
struct branch {
const char *author; /* Author of the last commit. */
time_t time; /* Date of the last activity. */
- struct ref *ref; /* Name and commit ID information. */
+ const struct ref *ref; /* Name and commit ID information. */
};
};
+static const struct ref branch_all;
+
static const enum sort_field branch_sort_fields[] = {
ORDERBY_NAME, ORDERBY_DATE, ORDERBY_AUTHOR
};
static const enum sort_field branch_sort_fields[] = {
ORDERBY_NAME, ORDERBY_DATE, ORDERBY_AUTHOR
};
if (opt_author && draw_author(view, branch->author))
return TRUE;
if (opt_author && draw_author(view, branch->author))
return TRUE;
- draw_text(view, type, branch->ref->name, TRUE);
+ draw_text(view, type, branch->ref == &branch_all ? "All branches" : branch->ref->name, TRUE);
return TRUE;
}
static enum request
branch_request(struct view *view, enum request request, struct line *line)
{
return TRUE;
}
static enum request
branch_request(struct view *view, enum request request, struct line *line)
{
+ struct branch *branch = line->data;
+
switch (request) {
case REQ_REFRESH:
load_refs();
switch (request) {
case REQ_REFRESH:
load_refs();
return REQ_NONE;
case REQ_ENTER:
return REQ_NONE;
case REQ_ENTER:
- open_view(view, REQ_VIEW_MAIN, OPEN_SPLIT);
+ if (branch->ref == &branch_all) {
+ const char *all_branches_argv[] = {
+ "git", "log", "--no-color", "--pretty=raw", "--parents",
+ "--topo-order", "--all", NULL
+ };
+ struct view *main_view = VIEW(REQ_VIEW_MAIN);
+
+ if (!prepare_update(main_view, all_branches_argv, NULL, FORMAT_NONE)) {
+ report("Failed to load view of all branches");
+ return REQ_NONE;
+ }
+ open_view(view, REQ_VIEW_MAIN, OPEN_PREPARED | OPEN_SPLIT);
+ } else {
+ open_view(view, REQ_VIEW_MAIN, OPEN_SPLIT);
+ }
return REQ_NONE;
default:
return REQ_NONE;
default:
}
static bool
}
static bool
-branch_open_visitor(void *data, struct ref *ref)
+branch_open_visitor(void *data, const struct ref *ref)
{
struct view *view = data;
struct branch *branch;
{
struct view *view = data;
struct branch *branch;
"--simplify-by-decoration", "--all", NULL
};
"--simplify-by-decoration", "--all", NULL
};
- if (!run_io_rd(&view->io, branch_log, FORMAT_NONE)) {
+ if (!run_io_rd(&view->io, branch_log, NULL, FORMAT_NONE)) {
report("Failed to load branch data");
return TRUE;
}
setup_update(view, view->id);
report("Failed to load branch data");
return TRUE;
}
setup_update(view, view->id);
+ branch_open_visitor(view, &branch_all);
foreach_ref(branch_open_visitor, view);
view->p_restore = TRUE;
foreach_ref(branch_open_visitor, view);
view->p_restore = TRUE;
@@ -5152,7 +5310,7 @@ status_run(struct view *view, const char *argv[], char status, enum line_type ty
char *buf;
struct io io = {};
char *buf;
struct io io = {};
- if (!run_io(&io, argv, NULL, IO_RD))
+ if (!run_io(&io, argv, opt_cdup, IO_RD))
return FALSE;
add_line_data(view, NULL, type);
return FALSE;
add_line_data(view, NULL, type);
if (!*opt_head) {
struct io io = {};
if (!*opt_head) {
struct io io = {};
- if (string_format(buf, "%s/rebase-merge/head-name", opt_git_dir) &&
- io_open(&io, buf) &&
+ if (io_open(&io, "%s/rebase-merge/head-name", opt_git_dir) &&
io_read_buf(&io, buf, sizeof(buf))) {
head = buf;
if (!prefixcmp(head, "refs/heads/"))
io_read_buf(&io, buf, sizeof(buf))) {
head = buf;
if (!prefixcmp(head, "refs/heads/"))
return run_io(io, staged_argv, opt_cdup, IO_WR);
case LINE_STAT_UNSTAGED:
return run_io(io, staged_argv, opt_cdup, IO_WR);
case LINE_STAT_UNSTAGED:
- return run_io(io, others_argv, opt_cdup, IO_WR);
-
case LINE_STAT_UNTRACKED:
case LINE_STAT_UNTRACKED:
- return run_io(io, others_argv, NULL, IO_WR);
+ return run_io(io, others_argv, opt_cdup, IO_WR);
default:
die("line type %d not handled in switch", type);
default:
die("line type %d not handled in switch", type);
} else {
report("Cannot revert changes to multiple files");
}
} else {
report("Cannot revert changes to multiple files");
}
- return FALSE;
- } else {
+ } else if (prompt_yesno("Are you sure you want to revert changes?")) {
char mode[10] = "100644";
const char *reset_argv[] = {
"git", "update-index", "--cacheinfo", mode,
char mode[10] = "100644";
const char *reset_argv[] = {
"git", "update-index", "--cacheinfo", mode,
"git", "checkout", "--", status->old.name, NULL
};
"git", "checkout", "--", status->old.name, NULL
};
- if (!prompt_yesno("Are you sure you want to overwrite any changes?"))
- return FALSE;
- string_format(mode, "%o", status->old.mode);
- return (status->status != 'U' || run_io_fg(reset_argv, opt_cdup)) &&
- run_io_fg(checkout_argv, opt_cdup);
+ if (status->status == 'U') {
+ string_format(mode, "%5o", status->old.mode);
+
+ if (status->old.mode == 0 && status->new.mode == 0) {
+ reset_argv[2] = "--force-remove";
+ reset_argv[3] = status->old.name;
+ reset_argv[4] = NULL;
+ }
+
+ if (!run_io_fg(reset_argv, opt_cdup))
+ return FALSE;
+ if (status->old.mode == 0 && status->new.mode == 0)
+ return TRUE;
+ }
+
+ return run_io_fg(checkout_argv, opt_cdup);
}
}
+
+ return FALSE;
}
static enum request
}
static enum request
break;
case REQ_VIEW_BLAME:
break;
case REQ_VIEW_BLAME:
- if (status) {
- string_copy(opt_file, status->new.name);
+ if (status)
opt_ref[0] = 0;
opt_ref[0] = 0;
- }
return request;
case REQ_ENTER:
return request;
case REQ_ENTER:
}
string_format(view->ref, text, key, file);
}
string_format(view->ref, text, key, file);
+ if (status)
+ string_copy(opt_file, status->new.name);
}
static bool
}
static bool
}
static void
}
static void
-foreach_ref(bool (*visitor)(void *data, struct ref *ref), void *data)
+foreach_ref(bool (*visitor)(void *data, const struct ref *ref), void *data)
{
size_t i;
{
size_t i;
@@ -7332,7 +7499,7 @@ read_repo_config_option(char *name, size_t namelen, char *value, size_t valuelen
static int
load_git_config(void)
{
static int
load_git_config(void)
{
- const char *config_list_argv[] = { "git", GIT_CONFIG, "--list", NULL };
+ const char *config_list_argv[] = { "git", "config", "--list", NULL };
return run_io_load(config_list_argv, "=", read_repo_config_option);
}
return run_io_load(config_list_argv, "=", read_repo_config_option);
}
die("command too long");
}
die("command too long");
}
- if (!prepare_update(VIEW(request), custom_argv, NULL, FORMAT_NONE))
- die("Failed to format arguments");
+ if (!prepare_update(VIEW(request), custom_argv, NULL, FORMAT_NONE))
+ die("Failed to format arguments");
return request;
}
return request;
}
if (!opt_git_dir[0] && request != REQ_VIEW_PAGER)
die("Not a git repository");
if (!opt_git_dir[0] && request != REQ_VIEW_PAGER)
die("Not a git repository");
- if (*opt_encoding && strcasecmp(opt_encoding, "UTF-8"))
- opt_utf8 = FALSE;
+ if (*opt_encoding && strcmp(opt_codeset, "UTF-8")) {
+ opt_iconv_in = iconv_open("UTF-8", opt_encoding);
+ if (opt_iconv_in == ICONV_NONE)
+ die("Failed to initialize character set conversion");
+ }
- if (*opt_codeset && strcmp(opt_codeset, opt_encoding)) {
- opt_iconv = iconv_open(opt_codeset, opt_encoding);
- if (opt_iconv == ICONV_NONE)
+ if (*opt_codeset && strcmp(opt_codeset, "UTF-8")) {
+ opt_iconv_out = iconv_open(opt_codeset, "UTF-8");
+ if (opt_iconv_out == ICONV_NONE)
die("Failed to initialize character set conversion");
}
die("Failed to initialize character set conversion");
}