index 0f9ff04cbfe37e7564ffcb88405a134300a23d14..bd30997c00ede3035271484f5cb18326fe64c34c 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -114,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 {
}
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)
-{
- return init_io_rd(io, argv, NULL, flags) && start_io(io);
-}
-
-static bool
-run_io_rd_dir(struct io *io, const char **argv, const char *dir, 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, dir, flags) && start_io(io);
}
{
return init_io_rd(io, argv, dir, flags) && start_io(io);
}
{
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
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;
{
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 (!refresh) {
if (view->ops->prepare) {
if (!view->ops->prepare(view))
return FALSE;
if (view->ops->prepare) {
if (!view->ops->prepare(view))
return FALSE;
- } else if (!run_io_rd(&view->io, view->ops->argv, FORMAT_ALL)) {
+ } else if (!init_io_rd(&view->io, view->ops->argv, NULL, FORMAT_ALL)) {
return FALSE;
}
return FALSE;
}
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;
return TRUE;
}
return TRUE;
}
- if (!run_io_rd_dir(&io, log_file, opt_cdup, 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;
}
opt_path[0] = 0;
}
opt_path[0] = 0;
}
- return run_io_rd_dir(&view->io, view->ops->argv, opt_cdup, FORMAT_ALL);
+ return init_io_rd(&view->io, view->ops->argv, opt_cdup, FORMAT_ALL);
}
static const char *tree_argv[SIZEOF_ARG] = {
}
static const char *tree_argv[SIZEOF_ARG] = {
return FALSE;
}
return FALSE;
}
- if (!string_format(path, "%s%s", opt_cdup, opt_file))
- return FALSE;
-
- if (*opt_ref || !io_open(&view->io, path)) {
- if (!run_io_rd_dir(&view->io, blame_cat_file_argv, opt_cdup, FORMAT_ALL))
+ 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_dir(&io, argv, opt_cdup, 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 enum sort_field branch_sort_fields[] = {
};
static const enum sort_field branch_sort_fields[] = {
}
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;
}
report("Failed to load branch data");
return TRUE;
}
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/"))
} 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;
@@ -7467,7 +7478,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);
}