index 25fb237c6b1d39a2563bcf072ebcdd73614920ce..d2bc2dd46555008a03b6aa903fea78ea304ecfbf 100644 (file)
--- a/tig.c
+++ b/tig.c
static void set_nonblocking_input(bool loading);
static size_t utf8_length(const char *string, int *width, size_t max_width, int *trimmed, bool reserve);
static bool prompt_yesno(const char *prompt);
static void set_nonblocking_input(bool loading);
static size_t utf8_length(const char *string, int *width, size_t max_width, int *trimmed, bool reserve);
static bool prompt_yesno(const char *prompt);
+static int load_refs(void);
#define ABS(x) ((x) >= 0 ? (x) : -(x))
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define ABS(x) ((x) >= 0 ? (x) : -(x))
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define SIZEOF_STR 1024 /* Default string size. */
#define SIZEOF_REF 256 /* Size of symbolic or SHA1 ID. */
#define SIZEOF_STR 1024 /* Default string size. */
#define SIZEOF_REF 256 /* Size of symbolic or SHA1 ID. */
-#define SIZEOF_REV 41 /* Holds a SHA-1 and an ending NUL */
+#define SIZEOF_REV 41 /* Holds a SHA-1 and an ending NUL. */
+#define SIZEOF_ARG 32 /* Default argument array size. */
/* Revision graph */
/* Revision graph */
unsigned int next:1; /* For ref lists: are there more refs? */
};
unsigned int next:1; /* For ref lists: are there more refs? */
};
-static struct ref **get_refs(char *id);
+static struct ref **get_refs(const char *id);
struct int_map {
const char *name;
struct int_map {
const char *name;
return 0;
}
return 0;
}
+#define prefixcmp(str1, str2) \
+ strncmp(str1, str2, STRING_SIZE(str2))
+
+static inline int
+suffixcmp(const char *str, int slen, const char *suffix)
+{
+ size_t len = slen >= 0 ? slen : strlen(str);
+ size_t suffixlen = strlen(suffix);
+
+ return suffixlen < len ? strcmp(str + len - suffixlen, suffix) : -1;
+}
+
/* Shell quoting
*
* NOTE: The following is a slightly modified copy of the git project's shell
/* Shell quoting
*
* NOTE: The following is a slightly modified copy of the git project's shell
REQ_(VIEW_CLOSE, "Close the current view"), \
REQ_(QUIT, "Close all views and quit"), \
\
REQ_(VIEW_CLOSE, "Close the current view"), \
REQ_(QUIT, "Close all views and quit"), \
\
+ REQ_GROUP("View specific requests") \
+ REQ_(STATUS_UPDATE, "Update file status"), \
+ REQ_(STATUS_REVERT, "Revert file changes"), \
+ REQ_(STATUS_MERGE, "Merge file using external tool"), \
+ REQ_(STAGE_NEXT, "Find next chunk to stage"), \
+ REQ_(TREE_PARENT, "Switch to parent directory in tree view"), \
+ \
REQ_GROUP("Cursor navigation") \
REQ_(MOVE_UP, "Move cursor one line up"), \
REQ_(MOVE_DOWN, "Move cursor one line down"), \
REQ_GROUP("Cursor navigation") \
REQ_(MOVE_UP, "Move cursor one line up"), \
REQ_(MOVE_DOWN, "Move cursor one line down"), \
REQ_(FIND_NEXT, "Find next search match"), \
REQ_(FIND_PREV, "Find previous search match"), \
\
REQ_(FIND_NEXT, "Find next search match"), \
REQ_(FIND_PREV, "Find previous search match"), \
\
+ REQ_GROUP("Option manipulation") \
+ REQ_(TOGGLE_LINENO, "Toggle line numbers"), \
+ REQ_(TOGGLE_DATE, "Toggle date display"), \
+ REQ_(TOGGLE_AUTHOR, "Toggle author display"), \
+ REQ_(TOGGLE_REV_GRAPH, "Toggle revision graph visualization"), \
+ REQ_(TOGGLE_REFS, "Toggle reference display (tags/branches)"), \
+ \
REQ_GROUP("Misc") \
REQ_(PROMPT, "Bring up the prompt"), \
REQ_(SCREEN_REDRAW, "Redraw the screen"), \
REQ_(SCREEN_RESIZE, "Resize the screen"), \
REQ_(SHOW_VERSION, "Show version information"), \
REQ_(STOP_LOADING, "Stop all loading views"), \
REQ_GROUP("Misc") \
REQ_(PROMPT, "Bring up the prompt"), \
REQ_(SCREEN_REDRAW, "Redraw the screen"), \
REQ_(SCREEN_RESIZE, "Resize the screen"), \
REQ_(SHOW_VERSION, "Show version information"), \
REQ_(STOP_LOADING, "Stop all loading views"), \
- REQ_(TOGGLE_LINENO, "Toggle line numbers"), \
- REQ_(TOGGLE_DATE, "Toggle date display"), \
- REQ_(TOGGLE_AUTHOR, "Toggle author display"), \
- REQ_(TOGGLE_REV_GRAPH, "Toggle revision graph visualization"), \
- REQ_(TOGGLE_REFS, "Toggle reference display (tags/branches)"), \
- REQ_(STATUS_UPDATE, "Update file status"), \
- REQ_(STATUS_CHECKOUT, "Checkout file"), \
- REQ_(STATUS_MERGE, "Merge file using external tool"), \
- REQ_(STAGE_NEXT, "Find next chunk to stage"), \
- REQ_(TREE_PARENT, "Switch to parent directory in tree view"), \
REQ_(EDIT, "Open in editor"), \
REQ_(NONE, "Do nothing")
REQ_(EDIT, "Open in editor"), \
REQ_(NONE, "Do nothing")
struct request_info {
enum request request;
struct request_info {
enum request request;
- char *name;
+ const char *name;
int namelen;
int namelen;
- char *help;
+ const char *help;
};
static struct request_info req_info[] = {
};
static struct request_info req_info[] = {
static char opt_file[SIZEOF_STR] = "";
static char opt_ref[SIZEOF_REF] = "";
static char opt_head[SIZEOF_REF] = "";
static char opt_file[SIZEOF_STR] = "";
static char opt_ref[SIZEOF_REF] = "";
static char opt_head[SIZEOF_REF] = "";
+static char opt_head_rev[SIZEOF_REV] = "";
static char opt_remote[SIZEOF_REF] = "";
static char opt_remote[SIZEOF_REF] = "";
-static bool opt_no_head = TRUE;
static FILE *opt_pipe = NULL;
static char opt_encoding[20] = "UTF-8";
static bool opt_utf8 = TRUE;
static FILE *opt_pipe = NULL;
static char opt_encoding[20] = "UTF-8";
static bool opt_utf8 = TRUE;
static char opt_git_dir[SIZEOF_STR] = "";
static signed char opt_is_inside_work_tree = -1; /* set to TRUE or FALSE */
static char opt_editor[SIZEOF_STR] = "";
static char opt_git_dir[SIZEOF_STR] = "";
static signed char opt_is_inside_work_tree = -1; /* set to TRUE or FALSE */
static char opt_editor[SIZEOF_STR] = "";
+static FILE *opt_tty = NULL;
+
+#define is_initial_commit() (!*opt_head_rev)
+#define is_head_commit(rev) (!strcmp((rev), "HEAD") || !strcmp(opt_head_rev, (rev)))
static enum request
static enum request
-parse_options(int argc, char *argv[])
+parse_options(int argc, const char *argv[])
{
enum request request = REQ_VIEW_MAIN;
size_t buf_size;
{
enum request request = REQ_VIEW_MAIN;
size_t buf_size;
- char *subcommand;
+ const char *subcommand;
bool seen_dashdash = FALSE;
int i;
bool seen_dashdash = FALSE;
int i;
buf_size = strlen(opt_cmd);
for (i = 1 + !!subcommand; i < argc; i++) {
buf_size = strlen(opt_cmd);
for (i = 1 + !!subcommand; i < argc; i++) {
- char *opt = argv[i];
+ const char *opt = argv[i];
if (seen_dashdash || !strcmp(opt, "--")) {
seen_dashdash = TRUE;
if (seen_dashdash || !strcmp(opt, "--")) {
seen_dashdash = TRUE;
};
static enum line_type
};
static enum line_type
-get_line_type(char *line)
+get_line_type(const char *line)
{
int linelen = strlen(line);
enum line_type type;
{
int linelen = strlen(line);
enum line_type type;
}
static struct line_info *
}
static struct line_info *
-get_line_info(char *name)
+get_line_info(const char *name)
{
size_t namelen = strlen(name);
enum line_type type;
{
size_t namelen = strlen(name);
enum line_type type;
{ 'F', REQ_TOGGLE_REFS },
{ ':', REQ_PROMPT },
{ 'u', REQ_STATUS_UPDATE },
{ 'F', REQ_TOGGLE_REFS },
{ ':', REQ_PROMPT },
{ 'u', REQ_STATUS_UPDATE },
- { '!', REQ_STATUS_CHECKOUT },
+ { '!', REQ_STATUS_REVERT },
{ 'M', REQ_STATUS_MERGE },
{ '@', REQ_STAGE_NEXT },
{ ',', REQ_TREE_PARENT },
{ 'M', REQ_STATUS_MERGE },
{ '@', REQ_STAGE_NEXT },
{ ',', REQ_TREE_PARENT },
struct key {
struct key {
- char *name;
+ const char *name;
int value;
};
int value;
};
return ERR;
}
return ERR;
}
-static char *
+static const char *
get_key_name(int key_value)
{
static char key_char[] = "'X'";
get_key_name(int key_value)
{
static char key_char[] = "'X'";
- char *seq = NULL;
+ const char *seq = NULL;
int key;
for (key = 0; key < ARRAY_SIZE(key_table); key++)
int key;
for (key = 0; key < ARRAY_SIZE(key_table); key++)
seq = key_char;
}
seq = key_char;
}
- return seq ? seq : "'?'";
+ return seq ? seq : "(no key)";
}
}
-static char *
+static const char *
get_key(enum request request)
{
static char buf[BUFSIZ];
get_key(enum request request)
{
static char buf[BUFSIZ];
static size_t run_requests;
static enum request
static size_t run_requests;
static enum request
-add_run_request(enum keymap keymap, int key, int argc, char **argv)
+add_run_request(enum keymap keymap, int key, int argc, const char **argv)
{
struct run_request *req;
char cmd[SIZEOF_STR];
{
struct run_request *req;
char cmd[SIZEOF_STR];
struct {
enum keymap keymap;
int key;
struct {
enum keymap keymap;
int key;
- char *argv[1];
+ const char *argv[1];
} reqs[] = {
{ KEYMAP_MAIN, 'C', { "git cherry-pick %(commit)" } },
{ KEYMAP_GENERIC, 'G', { "git gc" } },
} reqs[] = {
{ KEYMAP_MAIN, 'C', { "git cherry-pick %(commit)" } },
{ KEYMAP_GENERIC, 'G', { "git gc" } },
static int config_lineno;
static bool config_errors;
static int config_lineno;
static bool config_errors;
-static char *config_msg;
+static const char *config_msg;
/* Wants: object fgcolor bgcolor [attr] */
static int
/* Wants: object fgcolor bgcolor [attr] */
static int
-option_color_command(int argc, char *argv[])
+option_color_command(int argc, const char *argv[])
{
struct line_info *info;
{
struct line_info *info;
/* Wants: name = value */
static int
/* Wants: name = value */
static int
-option_set_command(int argc, char *argv[])
+option_set_command(int argc, const char *argv[])
{
if (argc != 3) {
config_msg = "Wrong number of arguments given to set command";
{
if (argc != 3) {
config_msg = "Wrong number of arguments given to set command";
}
if (!strcmp(argv[0], "commit-encoding")) {
}
if (!strcmp(argv[0], "commit-encoding")) {
- char *arg = argv[2];
- int delimiter = *arg;
- int i;
+ const char *arg = argv[2];
+ int arglen = strlen(arg);
- switch (delimiter) {
+ switch (arg[0]) {
case '"':
case '\'':
case '"':
case '\'':
- for (arg++, i = 0; arg[i]; i++)
- if (arg[i] == delimiter) {
- arg[i] = 0;
- break;
- }
+ if (arglen == 1 || arg[arglen - 1] != arg[0]) {
+ config_msg = "Unmatched quotation";
+ return ERR;
+ }
+ arg += 1; arglen -= 2;
default:
string_ncopy(opt_encoding, arg, strlen(arg));
return OK;
default:
string_ncopy(opt_encoding, arg, strlen(arg));
return OK;
/* Wants: mode request key */
static int
/* Wants: mode request key */
static int
-option_bind_command(int argc, char *argv[])
+option_bind_command(int argc, const char *argv[])
{
enum request request;
int keymap;
{
enum request request;
int keymap;
}
static int
}
static int
-set_option(char *opt, char *value)
+set_option(const char *opt, char *value)
{
{
- char *argv[16];
+ const char *argv[SIZEOF_ARG];
int valuelen;
int argc = 0;
int valuelen;
int argc = 0;
static int
load_options(void)
{
static int
load_options(void)
{
- char *home = getenv("HOME");
- char *tigrc_user = getenv("TIGRC_USER");
- char *tigrc_system = getenv("TIGRC_SYSTEM");
+ const char *home = getenv("HOME");
+ const char *tigrc_user = getenv("TIGRC_USER");
+ const char *tigrc_system = getenv("TIGRC_SYSTEM");
char buf[SIZEOF_STR];
add_builtin_run_requests();
char buf[SIZEOF_STR];
add_builtin_run_requests();
void (*select)(struct view *view, struct line *line);
};
void (*select)(struct view *view, struct line *line);
};
-static struct view_ops pager_ops;
-static struct view_ops main_ops;
-static struct view_ops tree_ops;
-static struct view_ops blob_ops;
static struct view_ops blame_ops;
static struct view_ops blame_ops;
+static struct view_ops blob_ops;
static struct view_ops help_ops;
static struct view_ops help_ops;
-static struct view_ops status_ops;
+static struct view_ops log_ops;
+static struct view_ops main_ops;
+static struct view_ops pager_ops;
static struct view_ops stage_ops;
static struct view_ops stage_ops;
+static struct view_ops status_ops;
+static struct view_ops tree_ops;
#define VIEW_STR(name, cmd, env, ref, ops, map, git) \
{ name, cmd, #env, ref, ops, map, git }
#define VIEW_STR(name, cmd, env, ref, ops, map, git) \
{ name, cmd, #env, ref, ops, map, git }
static struct view views[] = {
VIEW_(MAIN, "main", &main_ops, TRUE, ref_head),
VIEW_(DIFF, "diff", &pager_ops, TRUE, ref_commit),
static struct view views[] = {
VIEW_(MAIN, "main", &main_ops, TRUE, ref_head),
VIEW_(DIFF, "diff", &pager_ops, TRUE, ref_commit),
- VIEW_(LOG, "log", &pager_ops, TRUE, ref_head),
+ VIEW_(LOG, "log", &log_ops, TRUE, ref_head),
VIEW_(TREE, "tree", &tree_ops, TRUE, ref_commit),
VIEW_(BLOB, "blob", &blob_ops, TRUE, ref_blob),
VIEW_(BLAME, "blame", &blame_ops, TRUE, ref_commit),
VIEW_(TREE, "tree", &tree_ops, TRUE, ref_commit),
VIEW_(BLOB, "blob", &blob_ops, TRUE, ref_blob),
VIEW_(BLAME, "blame", &blame_ops, TRUE, ref_commit),
@@ -1633,7 +1655,7 @@ draw_graphic(struct view *view, enum line_type type, chtype graphic[], size_t si
}
static bool
}
static bool
-draw_field(struct view *view, enum line_type type, char *text, int len, bool trim)
+draw_field(struct view *view, enum line_type type, const char *text, int len, bool trim)
{
int max = MIN(view->width - view->col, len);
int col;
{
int max = MIN(view->width - view->col, len);
int col;
* Incremental updating
*/
* Incremental updating
*/
+static void
+reset_view(struct view *view)
+{
+ int i;
+
+ for (i = 0; i < view->lines; i++)
+ free(view->line[i].data);
+ free(view->line);
+
+ view->line = NULL;
+ view->offset = 0;
+ view->lines = 0;
+ view->lineno = 0;
+ view->line_size = 0;
+ view->line_alloc = 0;
+ view->vid[0] = 0;
+}
+
static void
end_update(struct view *view, bool force)
{
static void
end_update(struct view *view, bool force)
{
}
static bool
}
static bool
-begin_update(struct view *view)
+begin_update(struct view *view, bool refresh)
{
if (opt_cmd[0]) {
string_copy(view->cmd, opt_cmd);
{
if (opt_cmd[0]) {
string_copy(view->cmd, opt_cmd);
if (!string_format(view->cmd, format, view->id, path))
return FALSE;
if (!string_format(view->cmd, format, view->id, path))
return FALSE;
- } else {
+ } else if (!refresh) {
const char *format = view->cmd_env ? view->cmd_env : view->cmd_fmt;
const char *id = view->id;
const char *format = view->cmd_env ? view->cmd_env : view->cmd_fmt;
const char *id = view->id;
return FALSE;
set_nonblocking_input(TRUE);
return FALSE;
set_nonblocking_input(TRUE);
-
- view->offset = 0;
- view->lines = 0;
- view->lineno = 0;
+ reset_view(view);
string_copy_rev(view->vid, view->id);
string_copy_rev(view->vid, view->id);
- if (view->line) {
- int i;
-
- for (i = 0; i < view->lines; i++)
- if (view->line[i].data)
- free(view->line[i].data);
-
- free(view->line);
- view->line = NULL;
- }
-
view->start_time = time(NULL);
return TRUE;
view->start_time = time(NULL);
return TRUE;
}
}
}
}
+ if (ferror(view->pipe) && errno != 0) {
+ report("Failed to read: %s", strerror(errno));
+ end_update(view, TRUE);
+
+ } else if (feof(view->pipe)) {
+ report("");
+ end_update(view, FALSE);
+ }
+
if (!view_is_displayed(view))
if (!view_is_displayed(view))
- goto check_pipe;
+ return TRUE;
if (view == VIEW(REQ_VIEW_TREE)) {
/* Clear the view and redraw everything since the tree sorting
if (view == VIEW(REQ_VIEW_TREE)) {
/* Clear the view and redraw everything since the tree sorting
/* Update the title _after_ the redraw so that if the redraw picks up a
* commit reference in view->ref it'll be available here. */
update_view_title(view);
/* Update the title _after_ the redraw so that if the redraw picks up a
* commit reference in view->ref it'll be available here. */
update_view_title(view);
-
-check_pipe:
- if (ferror(view->pipe) && errno != 0) {
- report("Failed to read: %s", strerror(errno));
- end_update(view, TRUE);
-
- } else if (feof(view->pipe)) {
- report("");
- end_update(view, FALSE);
- }
-
return TRUE;
alloc_error:
return TRUE;
alloc_error:
}
static struct line *
}
static struct line *
-add_line_text(struct view *view, char *data, enum line_type type)
+add_line_text(struct view *view, const char *text, enum line_type type)
{
{
- if (data)
- data = strdup(data);
+ char *data = text ? strdup(text) : NULL;
return data ? add_line_data(view, data, type) : NULL;
}
return data ? add_line_data(view, data, type) : NULL;
}
OPEN_SPLIT = 1, /* Split current view. */
OPEN_BACKGROUNDED = 2, /* Backgrounded. */
OPEN_RELOAD = 4, /* Reload view even if it is the current. */
OPEN_SPLIT = 1, /* Split current view. */
OPEN_BACKGROUNDED = 2, /* Backgrounded. */
OPEN_RELOAD = 4, /* Reload view even if it is the current. */
- OPEN_NOMAXIMIZE = 8 /* Do not maximize the current view. */
+ OPEN_NOMAXIMIZE = 8, /* Do not maximize the current view. */
+ OPEN_REFRESH = 16, /* Refresh view using previous command. */
};
static void
};
static void
{
bool backgrounded = !!(flags & OPEN_BACKGROUNDED);
bool split = !!(flags & OPEN_SPLIT);
{
bool backgrounded = !!(flags & OPEN_BACKGROUNDED);
bool split = !!(flags & OPEN_SPLIT);
- bool reload = !!(flags & OPEN_RELOAD);
- bool nomaximize = !!(flags & OPEN_NOMAXIMIZE);
+ bool reload = !!(flags & (OPEN_RELOAD | OPEN_REFRESH));
+ bool nomaximize = !!(flags & (OPEN_NOMAXIMIZE | OPEN_REFRESH));
struct view *view = VIEW(request);
int nviews = displayed_views();
struct view *base_view = display[0];
struct view *view = VIEW(request);
int nviews = displayed_views();
struct view *base_view = display[0];
}
} else if ((reload || strcmp(view->vid, view->id)) &&
}
} else if ((reload || strcmp(view->vid, view->id)) &&
- !begin_update(view)) {
+ !begin_update(view, flags & OPEN_REFRESH)) {
report("Failed to load %s view", view->name);
return;
}
report("Failed to load %s view", view->name);
return;
}
* the screen. */
werase(view->win);
report("");
* the screen. */
werase(view->win);
report("");
- } else {
+ } else if (view_is_displayed(view)) {
redraw_view(view);
report("");
}
redraw_view(view);
report("");
}
endwin(); /* restore original tty modes */
system(cmd);
fprintf(stderr, "Press Enter to continue");
endwin(); /* restore original tty modes */
system(cmd);
fprintf(stderr, "Press Enter to continue");
- getc(stdin);
+ getc(opt_tty);
reset_prog_mode();
redraw_display();
}
reset_prog_mode();
redraw_display();
}
{
char cmd[SIZEOF_STR];
char file_sq[SIZEOF_STR];
{
char cmd[SIZEOF_STR];
char file_sq[SIZEOF_STR];
- char *editor;
+ const char *editor;
char *prefix = from_root ? opt_cdup : "";
editor = getenv("GIT_EDITOR");
char *prefix = from_root ? opt_cdup : "";
editor = getenv("GIT_EDITOR");
/* FIXME: When all views can refresh always do this. */
if (view == VIEW(REQ_VIEW_STATUS) ||
view == VIEW(REQ_VIEW_MAIN) ||
/* FIXME: When all views can refresh always do this. */
if (view == VIEW(REQ_VIEW_STATUS) ||
view == VIEW(REQ_VIEW_MAIN) ||
+ view == VIEW(REQ_VIEW_LOG) ||
view == VIEW(REQ_VIEW_STAGE))
request = REQ_REFRESH;
else
view == VIEW(REQ_VIEW_STAGE))
request = REQ_REFRESH;
else
view->parent = view;
resize_display();
redraw_display();
view->parent = view;
resize_display();
redraw_display();
+ report("");
break;
}
/* Fall-through */
break;
}
/* Fall-through */
return FALSE;
default:
return FALSE;
default:
- /* An unknown key will show most commonly used commands. */
report("Unknown key, press 'h' for help");
return TRUE;
}
report("Unknown key, press 'h' for help");
return TRUE;
}
}
static bool
}
static bool
-add_describe_ref(char *buf, size_t *bufpos, char *commit_id, const char *sep)
+add_describe_ref(char *buf, size_t *bufpos, const char *commit_id, const char *sep)
{
char refbuf[SIZEOF_STR];
char *ref = NULL;
{
char refbuf[SIZEOF_STR];
char *ref = NULL;
do {
struct ref *ref = refs[refpos];
do {
struct ref *ref = refs[refpos];
- char *fmt = ref->tag ? "%s[%s]" :
- ref->remote ? "%s<%s>" : "%s%s";
+ const char *fmt = ref->tag ? "%s[%s]" :
+ ref->remote ? "%s<%s>" : "%s%s";
if (!string_format_from(buf, &bufpos, fmt, sep, ref->name))
return;
if (!string_format_from(buf, &bufpos, fmt, sep, ref->name))
return;
pager_select,
};
pager_select,
};
+static enum request
+log_request(struct view *view, enum request request, struct line *line)
+{
+ switch (request) {
+ case REQ_REFRESH:
+ load_refs();
+ open_view(view, REQ_VIEW_LOG, OPEN_REFRESH);
+ return REQ_NONE;
+ default:
+ return pager_request(view, request, line);
+ }
+}
+
+static struct view_ops log_ops = {
+ "line",
+ NULL,
+ pager_read,
+ pager_draw,
+ log_request,
+ pager_grep,
+ pager_select,
+};
+
/*
* Help backend
/*
* Help backend
add_line_text(view, "Quick reference for tig keybindings:", LINE_DEFAULT);
for (i = 0; i < ARRAY_SIZE(req_info); i++) {
add_line_text(view, "Quick reference for tig keybindings:", LINE_DEFAULT);
for (i = 0; i < ARRAY_SIZE(req_info); i++) {
- char *key;
+ const char *key;
if (req_info[i].request == REQ_NONE)
continue;
if (req_info[i].request == REQ_NONE)
continue;
for (i = 0; i < run_requests; i++) {
struct run_request *req = get_run_request(REQ_NONE + i + 1);
for (i = 0; i < run_requests; i++) {
struct run_request *req = get_run_request(REQ_NONE + i + 1);
- char *key;
+ const char *key;
if (!req)
continue;
if (!req)
continue;
}
static void
}
static void
-push_tree_stack_entry(char *name, unsigned long lineno)
+push_tree_stack_entry(const char *name, unsigned long lineno)
{
struct tree_stack_entry *entry = calloc(1, sizeof(*entry));
size_t pathlen = strlen(opt_path);
{
struct tree_stack_entry *entry = calloc(1, sizeof(*entry));
size_t pathlen = strlen(opt_path);
#define TREE_UP_FORMAT "040000 tree %s\t.."
static int
#define TREE_UP_FORMAT "040000 tree %s\t.."
static int
-tree_compare_entry(enum line_type type1, char *name1,
- enum line_type type2, char *name2)
+tree_compare_entry(enum line_type type1, const char *name1,
+ enum line_type type2, const char *name2)
{
if (type1 != type2) {
if (type1 == LINE_TREE_DIR)
{
if (type1 != type2) {
if (type1 == LINE_TREE_DIR)
return strcmp(name1, name2);
}
return strcmp(name1, name2);
}
-static char *
+static const char *
tree_path(struct line *line)
{
tree_path(struct line *line)
{
- char *path = line->data;
+ const char *path = line->data;
return path + SIZEOF_TREE_ATTR;
}
return path + SIZEOF_TREE_ATTR;
}
/* Skip "Directory ..." and ".." line. */
for (pos = 1 + !!*opt_path; pos < view->lines; pos++) {
struct line *line = &view->line[pos];
/* Skip "Directory ..." and ".." line. */
for (pos = 1 + !!*opt_path; pos < view->lines; pos++) {
struct line *line = &view->line[pos];
- char *path1 = tree_path(line);
+ const char *path1 = tree_path(line);
char *path2 = text + SIZEOF_TREE_ATTR;
int cmp = tree_compare_entry(line->type, path1, type, path2);
char *path2 = text + SIZEOF_TREE_ATTR;
int cmp = tree_compare_entry(line->type, path1, type, path2);
{
enum open_flags flags;
{
enum open_flags flags;
- if (request == REQ_VIEW_BLAME) {
- char *filename = tree_path(line);
-
- if (line->type == LINE_TREE_DIR) {
- report("Cannot show blame for directory %s", opt_path);
+ switch (request) {
+ case REQ_VIEW_BLAME:
+ if (line->type != LINE_TREE_FILE) {
+ report("Blame only supported for files");
return REQ_NONE;
}
string_copy(opt_ref, view->vid);
return REQ_NONE;
}
string_copy(opt_ref, view->vid);
- string_format(opt_file, "%s%s", opt_path, filename);
return request;
return request;
- }
- if (request == REQ_TREE_PARENT) {
- if (*opt_path) {
- /* fake 'cd ..' */
- request = REQ_ENTER;
- line = &view->line[1];
+
+ case REQ_EDIT:
+ if (line->type != LINE_TREE_FILE) {
+ report("Edit only supported for files");
+ } else if (!is_head_commit(view->vid)) {
+ report("Edit only supported for files in the current work tree");
} else {
} else {
+ open_editor(TRUE, opt_file);
+ }
+ return REQ_NONE;
+
+ case REQ_TREE_PARENT:
+ if (!*opt_path) {
/* quit view if at top of tree */
return REQ_VIEW_CLOSE;
}
/* quit view if at top of tree */
return REQ_VIEW_CLOSE;
}
- }
- if (request != REQ_ENTER)
+ /* fake 'cd ..' */
+ line = &view->line[1];
+ break;
+
+ case REQ_ENTER:
+ break;
+
+ default:
return request;
return request;
+ }
/* Cleanup the stack if the tree view is at a different tree. */
while (!*opt_path && tree_stack)
/* Cleanup the stack if the tree view is at a different tree. */
while (!*opt_path && tree_stack)
pop_tree_stack_entry();
} else {
pop_tree_stack_entry();
} else {
- char *basename = tree_path(line);
+ const char *basename = tree_path(line);
push_tree_stack_entry(basename, view->lineno);
}
push_tree_stack_entry(basename, view->lineno);
}
if (line->type == LINE_TREE_FILE) {
string_copy_rev(ref_blob, text);
if (line->type == LINE_TREE_FILE) {
string_copy_rev(ref_blob, text);
+ string_format(opt_file, "%s%s", opt_path, tree_path(line));
} else if (line->type != LINE_TREE_DIR) {
return;
} else if (line->type != LINE_TREE_DIR) {
return;
};
#define BLAME_CAT_FILE_CMD "git cat-file blob %s:%s"
};
#define BLAME_CAT_FILE_CMD "git cat-file blob %s:%s"
-#define BLAME_INCREMENTAL_CMD "git blame --incremental %s %s"
+#define BLAME_INCREMENTAL_CMD "git blame --incremental %s -- %s"
static bool
blame_open(struct view *view)
static bool
blame_open(struct view *view)
if (!string_format(view->cmd, BLAME_INCREMENTAL_CMD, ref, path))
return FALSE;
if (!string_format(view->cmd, BLAME_INCREMENTAL_CMD, ref, path))
return FALSE;
+ reset_view(view);
string_format(view->ref, "%s ...", opt_file);
string_copy_rev(view->vid, opt_file);
set_nonblocking_input(TRUE);
string_format(view->ref, "%s ...", opt_file);
string_copy_rev(view->vid, opt_file);
set_nonblocking_input(TRUE);
-
- if (view->line) {
- int i;
-
- for (i = 0; i < view->lines; i++)
- free(view->line[i].data);
- free(view->line);
- }
-
- view->lines = view->line_alloc = view->line_size = view->lineno = 0;
- view->offset = view->lines = view->lineno = 0;
- view->line = NULL;
view->start_time = time(NULL);
return TRUE;
view->start_time = time(NULL);
return TRUE;
}
static bool
}
static bool
-parse_number(char **posref, size_t *number, size_t min, size_t max)
+parse_number(const char **posref, size_t *number, size_t min, size_t max)
{
{
- char *pos = *posref;
+ const char *pos = *posref;
*posref = NULL;
pos = strchr(pos + 1, ' ');
*posref = NULL;
pos = strchr(pos + 1, ' ');
}
static struct blame_commit *
}
static struct blame_commit *
-parse_blame_commit(struct view *view, char *text, int *blamed)
+parse_blame_commit(struct view *view, const char *text, int *blamed)
{
struct blame_commit *commit;
struct blame *blame;
{
struct blame_commit *commit;
struct blame *blame;
- char *pos = text + SIZEOF_REV - 1;
+ const char *pos = text + SIZEOF_REV - 1;
size_t lineno;
size_t group;
size_t lineno;
size_t group;
}
static bool
}
static bool
-blame_read_file(struct view *view, char *line)
+blame_read_file(struct view *view, const char *line)
{
if (!line) {
FILE *pipe = NULL;
{
if (!line) {
FILE *pipe = NULL;
{
struct blame *blame = line->data;
struct tm *time = NULL;
{
struct blame *blame = line->data;
struct tm *time = NULL;
- char *id = NULL, *author = NULL;
+ const char *id = NULL, *author = NULL;
if (blame->commit && *blame->commit->filename) {
id = blame->commit->id;
if (blame->commit && *blame->commit->filename) {
id = blame->commit->id;
* :100644 100644 06a5d6ae9eca55be2e0e585a152e6b1336f2b20e 0000000000000000000000000000000000000000 M
*/
static inline bool
* :100644 100644 06a5d6ae9eca55be2e0e585a152e6b1336f2b20e 0000000000000000000000000000000000000000 M
*/
static inline bool
-status_get_diff(struct status *file, char *buf, size_t bufsize)
+status_get_diff(struct status *file, const char *buf, size_t bufsize)
{
{
- char *old_mode = buf + 1;
- char *new_mode = buf + 8;
- char *old_rev = buf + 15;
- char *new_rev = buf + 56;
- char *status = buf + 97;
+ const char *old_mode = buf + 1;
+ const char *new_mode = buf + 8;
+ const char *old_rev = buf + 15;
+ const char *new_rev = buf + 56;
+ const char *status = buf + 97;
if (bufsize < 99 ||
old_mode[-1] != ':' ||
if (bufsize < 99 ||
old_mode[-1] != ':' ||
status_open(struct view *view)
{
unsigned long prev_lineno = view->lineno;
status_open(struct view *view)
{
unsigned long prev_lineno = view->lineno;
- size_t i;
- for (i = 0; i < view->lines; i++)
- free(view->line[i].data);
- free(view->line);
- view->lines = view->line_alloc = view->line_size = view->lineno = 0;
- view->line = NULL;
+ reset_view(view);
if (!realloc_lines(view, view->line_size + 7))
return FALSE;
add_line_data(view, NULL, LINE_STAT_HEAD);
if (!realloc_lines(view, view->line_size + 7))
return FALSE;
add_line_data(view, NULL, LINE_STAT_HEAD);
- if (opt_no_head)
+ if (is_initial_commit())
string_copy(status_onbranch, "Initial commit");
else if (!*opt_head)
string_copy(status_onbranch, "Not currently on any branch");
string_copy(status_onbranch, "Initial commit");
else if (!*opt_head)
string_copy(status_onbranch, "Not currently on any branch");
system("git update-index -q --refresh >/dev/null 2>/dev/null");
system("git update-index -q --refresh >/dev/null 2>/dev/null");
- if (opt_no_head &&
- !status_run(view, STATUS_LIST_NO_HEAD_CMD, 'A', LINE_STAT_STAGED))
- return FALSE;
- else if (!status_run(view, STATUS_DIFF_INDEX_CMD, 0, LINE_STAT_STAGED))
+ if (is_initial_commit()) {
+ if (!status_run(view, STATUS_LIST_NO_HEAD_CMD, 'A', LINE_STAT_STAGED))
+ return FALSE;
+ } else if (!status_run(view, STATUS_DIFF_INDEX_CMD, 0, LINE_STAT_STAGED)) {
return FALSE;
return FALSE;
+ }
if (!status_run(view, STATUS_DIFF_FILES_CMD, 0, LINE_STAT_UNSTAGED) ||
!status_run(view, STATUS_LIST_OTHER_CMD, '?', LINE_STAT_UNTRACKED))
if (!status_run(view, STATUS_DIFF_FILES_CMD, 0, LINE_STAT_UNSTAGED) ||
!status_run(view, STATUS_LIST_OTHER_CMD, '?', LINE_STAT_UNTRACKED))
{
struct status *status = line->data;
enum line_type type;
{
struct status *status = line->data;
enum line_type type;
- char *text;
+ const char *text;
if (!status) {
switch (line->type) {
if (!status) {
switch (line->type) {
struct status *status = line->data;
char oldpath[SIZEOF_STR] = "";
char newpath[SIZEOF_STR] = "";
struct status *status = line->data;
char oldpath[SIZEOF_STR] = "";
char newpath[SIZEOF_STR] = "";
- char *info;
+ const char *info;
size_t cmdsize = 0;
enum open_flags split;
size_t cmdsize = 0;
enum open_flags split;
switch (line->type) {
case LINE_STAT_STAGED:
switch (line->type) {
case LINE_STAT_STAGED:
- if (opt_no_head) {
+ if (is_initial_commit()) {
if (!string_format_from(opt_cmd, &cmdsize,
STATUS_DIFF_NO_HEAD_SHOW_CMD,
newpath))
if (!string_format_from(opt_cmd, &cmdsize,
STATUS_DIFF_NO_HEAD_SHOW_CMD,
newpath))
return REQ_NONE;
}
return REQ_NONE;
}
+ if (!suffixcmp(status->new.name, -1, "/")) {
+ report("Cannot display a directory");
+ return REQ_NONE;
+ }
+
opt_pipe = fopen(status->new.name, "r");
info = "Untracked file %s";
break;
opt_pipe = fopen(status->new.name, "r");
info = "Untracked file %s";
break;
}
static bool
}
static bool
-status_checkout(struct status *status, enum line_type type, bool has_next)
+status_revert(struct status *status, enum line_type type, bool has_none)
{
if (!status || type != LINE_STAT_UNSTAGED) {
{
if (!status || type != LINE_STAT_UNSTAGED) {
- if (has_next) {
- report("Nothing to checkout");
+ if (type == LINE_STAT_STAGED) {
+ report("Cannot revert changes to staged files");
} else if (type == LINE_STAT_UNTRACKED) {
} else if (type == LINE_STAT_UNTRACKED) {
- report("Cannot checkout untracked files");
- } else if (type == LINE_STAT_STAGED) {
- report("Cannot checkout staged files");
+ report("Cannot revert changes to untracked files");
+ } else if (has_none) {
+ report("Nothing to revert");
} else {
} else {
- report("Cannot checkout multiple files");
+ report("Cannot revert changes to multiple files");
}
return FALSE;
}
return FALSE;
char file_sq[SIZEOF_STR];
if (sq_quote(file_sq, 0, status->old.name) >= sizeof(file_sq) ||
char file_sq[SIZEOF_STR];
if (sq_quote(file_sq, 0, status->old.name) >= sizeof(file_sq) ||
- !string_format(cmd, "git checkout %s%s", opt_cdup, file_sq))
+ !string_format(cmd, "git checkout -- %s%s", opt_cdup, file_sq))
return FALSE;
return run_confirm(cmd, "Are you sure you want to overwrite any changes?");
return FALSE;
return run_confirm(cmd, "Are you sure you want to overwrite any changes?");
return REQ_NONE;
break;
return REQ_NONE;
break;
- case REQ_STATUS_CHECKOUT:
- if (!status_checkout(status, line->type, status_has_none(view, line)))
+ case REQ_STATUS_REVERT:
+ if (!status_revert(status, line->type, status_has_none(view, line)))
return REQ_NONE;
break;
return REQ_NONE;
break;
case REQ_EDIT:
if (!status)
return request;
case REQ_EDIT:
if (!status)
return request;
+ if (status->status == 'D') {
+ report("File has been deleted.");
+ return REQ_NONE;
+ }
open_editor(status->status != '?', status->new.name);
break;
open_editor(status->status != '?', status->new.name);
break;
{
struct status *status = line->data;
char file[SIZEOF_STR] = "all files";
{
struct status *status = line->data;
char file[SIZEOF_STR] = "all files";
- char *text;
- char *key;
+ const char *text;
+ const char *key;
if (status && !string_format(file, "'%s'", status->new.name))
return;
if (status && !string_format(file, "'%s'", status->new.name))
return;
return FALSE;
for (state = S_STATUS; state < S_END; state++) {
return FALSE;
for (state = S_STATUS; state < S_END; state++) {
- char *text;
+ const char *text;
switch (state) {
case S_NAME: text = status->new.name; break;
switch (state) {
case S_NAME: text = status->new.name; break;
static bool
stage_diff_line(FILE *pipe, struct line *line)
{
static bool
stage_diff_line(FILE *pipe, struct line *line)
{
- char *buf = line->data;
+ const char *buf = line->data;
size_t bufsize = strlen(buf);
size_t written = 0;
size_t bufsize = strlen(buf);
size_t written = 0;
}
static bool
}
static bool
-stage_update_chunk(struct view *view, struct line *chunk)
+stage_apply_chunk(struct view *view, struct line *chunk, bool revert)
{
char cmd[SIZEOF_STR];
size_t cmdsize = 0;
{
char cmd[SIZEOF_STR];
size_t cmdsize = 0;
return FALSE;
if (!string_format_from(cmd, &cmdsize,
return FALSE;
if (!string_format_from(cmd, &cmdsize,
- "git apply --whitespace=nowarn --cached %s - && "
+ "git apply --whitespace=nowarn %s %s - && "
"git update-index -q --unmerged --refresh 2>/dev/null",
"git update-index -q --unmerged --refresh 2>/dev/null",
- stage_line_type == LINE_STAT_STAGED ? "-R" : ""))
+ revert ? "" : "--cached",
+ revert || stage_line_type == LINE_STAT_STAGED ? "-R" : ""))
return FALSE;
pipe = popen(cmd, "w");
return FALSE;
pipe = popen(cmd, "w");
{
struct line *chunk = NULL;
{
struct line *chunk = NULL;
- if (!opt_no_head && stage_line_type != LINE_STAT_UNTRACKED)
+ if (!is_initial_commit() && stage_line_type != LINE_STAT_UNTRACKED)
chunk = stage_diff_find(view, line, LINE_DIFF_CHUNK);
if (chunk) {
chunk = stage_diff_find(view, line, LINE_DIFF_CHUNK);
if (chunk) {
- if (!stage_update_chunk(view, chunk)) {
+ if (!stage_apply_chunk(view, chunk, FALSE)) {
report("Failed to apply chunk");
return FALSE;
}
report("Failed to apply chunk");
return FALSE;
}
return TRUE;
}
return TRUE;
}
+static bool
+stage_revert(struct view *view, struct line *line)
+{
+ struct line *chunk = NULL;
+
+ if (!is_initial_commit() && stage_line_type == LINE_STAT_UNSTAGED)
+ chunk = stage_diff_find(view, line, LINE_DIFF_CHUNK);
+
+ if (chunk) {
+ if (!prompt_yesno("Are you sure you want to revert changes?"))
+ return FALSE;
+
+ if (!stage_apply_chunk(view, chunk, TRUE)) {
+ report("Failed to revert chunk");
+ return FALSE;
+ }
+ return TRUE;
+
+ } else {
+ return status_revert(stage_status.status ? &stage_status : NULL,
+ stage_line_type, FALSE);
+ }
+}
+
+
static void
stage_next(struct view *view, struct line *line)
{
static void
stage_next(struct view *view, struct line *line)
{
return REQ_NONE;
break;
return REQ_NONE;
break;
- case REQ_STATUS_CHECKOUT:
- if (!status_checkout(&stage_status, stage_line_type, FALSE))
+ case REQ_STATUS_REVERT:
+ if (!stage_revert(view, line))
return REQ_NONE;
break;
return REQ_NONE;
break;
case REQ_EDIT:
if (!stage_status.new.name[0])
return request;
case REQ_EDIT:
if (!stage_status.new.name[0])
return request;
+ if (stage_status.status == 'D') {
+ report("File has been deleted.");
+ return REQ_NONE;
+ }
open_editor(stage_status.status != '?', stage_status.new.name);
break;
open_editor(stage_status.status != '?', stage_status.new.name);
break;
if (!status_exists(&stage_status, stage_line_type))
return REQ_VIEW_CLOSE;
if (!status_exists(&stage_status, stage_line_type))
return REQ_VIEW_CLOSE;
- if (stage_line_type == LINE_STAT_UNTRACKED)
+ if (stage_line_type == LINE_STAT_UNTRACKED) {
+ if (!suffixcmp(stage_status.new.name, -1, "/")) {
+ report("Cannot display a directory");
+ return REQ_NONE;
+ }
+
opt_pipe = fopen(stage_status.new.name, "r");
opt_pipe = fopen(stage_status.new.name, "r");
- else
- string_copy(opt_cmd, view->cmd);
- open_view(view, REQ_VIEW_STAGE, OPEN_RELOAD | OPEN_NOMAXIMIZE);
+ }
+ open_view(view, REQ_VIEW_STAGE, OPEN_REFRESH);
return REQ_NONE;
}
return REQ_NONE;
}
}
static void
}
static void
-push_rev_graph(struct rev_graph *graph, char *parent)
+push_rev_graph(struct rev_graph *graph, const char *parent)
{
int i;
{
int i;
* Main view backend
*/
* Main view backend
*/
-static int load_refs(void);
-
static bool
main_draw(struct view *view, struct line *line, unsigned int lineno)
{
static bool
main_draw(struct view *view, struct line *line, unsigned int lineno)
{
break;
case REQ_REFRESH:
load_refs();
break;
case REQ_REFRESH:
load_refs();
- string_copy(opt_cmd, view->cmd);
- open_view(view, REQ_VIEW_MAIN, OPEN_RELOAD);
+ open_view(view, REQ_VIEW_MAIN, OPEN_REFRESH);
break;
default:
return request;
break;
default:
return request;
/* Initialize the curses library */
if (isatty(STDIN_FILENO)) {
cursed = !!initscr();
/* Initialize the curses library */
if (isatty(STDIN_FILENO)) {
cursed = !!initscr();
+ opt_tty = stdin;
} else {
/* Leave stdin and stdout alone when acting as a pager. */
} else {
/* Leave stdin and stdout alone when acting as a pager. */
- FILE *io = fopen("/dev/tty", "r+");
-
- if (!io)
+ opt_tty = fopen("/dev/tty", "r+");
+ if (!opt_tty)
die("Failed to open /dev/tty");
die("Failed to open /dev/tty");
- cursed = !!newterm(NULL, io, io);
+ cursed = !!newterm(NULL, opt_tty, opt_tty);
}
if (!cursed)
}
if (!cursed)
static size_t id_refs_alloc = 0;
static size_t id_refs_size = 0;
static size_t id_refs_alloc = 0;
static size_t id_refs_size = 0;
+static int
+compare_refs(const void *ref1_, const void *ref2_)
+{
+ const struct ref *ref1 = *(const struct ref **)ref1_;
+ const struct ref *ref2 = *(const struct ref **)ref2_;
+
+ if (ref1->tag != ref2->tag)
+ return ref2->tag - ref1->tag;
+ if (ref1->ltag != ref2->ltag)
+ return ref2->ltag - ref2->ltag;
+ if (ref1->head != ref2->head)
+ return ref2->head - ref1->head;
+ if (ref1->tracked != ref2->tracked)
+ return ref2->tracked - ref1->tracked;
+ if (ref1->remote != ref2->remote)
+ return ref2->remote - ref1->remote;
+ return strcmp(ref1->name, ref2->name);
+}
+
static struct ref **
static struct ref **
-get_refs(char *id)
+get_refs(const char *id)
{
struct ref ***tmp_id_refs;
struct ref **ref_list = NULL;
{
struct ref ***tmp_id_refs;
struct ref **ref_list = NULL;
}
ref_list = tmp;
}
ref_list = tmp;
- if (ref_list_size > 0)
- ref_list[ref_list_size - 1]->next = 1;
ref_list[ref_list_size] = &refs[i];
ref_list[ref_list_size] = &refs[i];
-
/* XXX: The properties of the commit chains ensures that we can
* safely modify the shared ref. The repo references will
* always be similar for the same id. */
/* XXX: The properties of the commit chains ensures that we can
* safely modify the shared ref. The repo references will
* always be similar for the same id. */
- ref_list[ref_list_size]->next = 0;
+ ref_list[ref_list_size]->next = 1;
+
ref_list_size++;
}
ref_list_size++;
}
- if (ref_list)
+ if (ref_list) {
+ qsort(ref_list, ref_list_size, sizeof(*ref_list), compare_refs);
+ ref_list[ref_list_size - 1]->next = 0;
id_refs[id_refs_size++] = ref_list;
id_refs[id_refs_size++] = ref_list;
+ }
return ref_list;
}
return ref_list;
}
bool check_replace = FALSE;
bool head = FALSE;
bool check_replace = FALSE;
bool head = FALSE;
- if (!strncmp(name, "refs/tags/", STRING_SIZE("refs/tags/"))) {
- if (!strcmp(name + namelen - 3, "^{}")) {
+ if (!prefixcmp(name, "refs/tags/")) {
+ if (!suffixcmp(name, namelen, "^{}")) {
namelen -= 3;
name[namelen] = 0;
if (refs_size > 0 && refs[refs_size - 1].ltag == TRUE)
namelen -= 3;
name[namelen] = 0;
if (refs_size > 0 && refs[refs_size - 1].ltag == TRUE)
namelen -= STRING_SIZE("refs/tags/");
name += STRING_SIZE("refs/tags/");
namelen -= STRING_SIZE("refs/tags/");
name += STRING_SIZE("refs/tags/");
- } else if (!strncmp(name, "refs/remotes/", STRING_SIZE("refs/remotes/"))) {
+ } else if (!prefixcmp(name, "refs/remotes/")) {
remote = TRUE;
namelen -= STRING_SIZE("refs/remotes/");
name += STRING_SIZE("refs/remotes/");
tracked = !strcmp(opt_remote, name);
remote = TRUE;
namelen -= STRING_SIZE("refs/remotes/");
name += STRING_SIZE("refs/remotes/");
tracked = !strcmp(opt_remote, name);
- } else if (!strncmp(name, "refs/heads/", STRING_SIZE("refs/heads/"))) {
+ } else if (!prefixcmp(name, "refs/heads/")) {
namelen -= STRING_SIZE("refs/heads/");
name += STRING_SIZE("refs/heads/");
head = !strncmp(opt_head, name, namelen);
} else if (!strcmp(name, "HEAD")) {
namelen -= STRING_SIZE("refs/heads/");
name += STRING_SIZE("refs/heads/");
head = !strncmp(opt_head, name, namelen);
} else if (!strcmp(name, "HEAD")) {
- opt_no_head = FALSE;
+ string_ncopy(opt_head_rev, id, idlen);
return OK;
}
if (check_replace && !strcmp(name, refs[refs_size - 1].name)) {
/* it's an annotated tag, replace the previous sha1 with the
* resolved commit id; relies on the fact git-ls-remote lists
return OK;
}
if (check_replace && !strcmp(name, refs[refs_size - 1].name)) {
/* it's an annotated tag, replace the previous sha1 with the
* resolved commit id; relies on the fact git-ls-remote lists
- * the commit id of an annotated tag right beofre the commit id
+ * the commit id of an annotated tag right before the commit id
* it points to. */
refs[refs_size - 1].ltag = ltag;
string_copy_rev(refs[refs_size - 1].id, id);
* it points to. */
refs[refs_size - 1].ltag = ltag;
string_copy_rev(refs[refs_size - 1].id, id);
@@ -5819,7 +5924,7 @@ read_repo_config_option(char *name, size_t namelen, char *value, size_t valuelen
!strcmp(name + 7 + strlen(opt_head), ".merge")) {
size_t from = strlen(opt_remote);
!strcmp(name + 7 + strlen(opt_head), ".merge")) {
size_t from = strlen(opt_remote);
- if (!strncmp(value, "refs/heads/", STRING_SIZE("refs/heads/"))) {
+ if (!prefixcmp(value, "refs/heads/")) {
value += STRING_SIZE("refs/heads/");
valuelen -= STRING_SIZE("refs/heads/");
}
value += STRING_SIZE("refs/heads/");
valuelen -= STRING_SIZE("refs/heads/");
}
} else if (opt_cdup[0] == ' ') {
string_ncopy(opt_cdup, name, namelen);
} else {
} else if (opt_cdup[0] == ' ') {
string_ncopy(opt_cdup, name, namelen);
} else {
- if (!strncmp(name, "refs/heads/", STRING_SIZE("refs/heads/"))) {
+ if (!prefixcmp(name, "refs/heads/")) {
namelen -= STRING_SIZE("refs/heads/");
name += STRING_SIZE("refs/heads/");
string_ncopy(opt_head, name, namelen);
namelen -= STRING_SIZE("refs/heads/");
name += STRING_SIZE("refs/heads/");
string_ncopy(opt_head, name, namelen);
}
int
}
int
-main(int argc, char *argv[])
+main(int argc, const char *argv[])
{
struct view *view;
enum request request;
{
struct view *view;
enum request request;
if (load_refs() == ERR)
die("Failed to load refs.");
if (load_refs() == ERR)
die("Failed to load refs.");
- for (i = 0; i < ARRAY_SIZE(views) && (view = &views[i]); i++)
+ foreach_view (view, i)
view->cmd_env = getenv(view->cmd_env);
init_display();
view->cmd_env = getenv(view->cmd_env);
init_display();
foreach_view (view, i)
update_view(view);
foreach_view (view, i)
update_view(view);
+ view = display[current_view];
/* Refresh, accept single keystroke of input */
key = wgetch(status_win);
/* Refresh, accept single keystroke of input */
key = wgetch(status_win);
continue;
}
continue;
}
- request = get_keybinding(display[current_view]->keymap, key);
+ request = get_keybinding(view->keymap, key);
/* Some low-level request handling. This keeps access to
* status_win restricted. */
/* Some low-level request handling. This keeps access to
* status_win restricted. */
case REQ_SEARCH:
case REQ_SEARCH_BACK:
{
case REQ_SEARCH:
case REQ_SEARCH_BACK:
{
- const char *prompt = request == REQ_SEARCH
- ? "/" : "?";
+ const char *prompt = request == REQ_SEARCH ? "/" : "?";
char *search = read_prompt(prompt);
if (search)
char *search = read_prompt(prompt);
if (search)