X-Git-Url: https://git.distorted.org.uk/~mdw/tig/blobdiff_plain/251acae219225cb1b6e5cfef73e1720b6dd2d528..1e61580b7bdf4f60e4b222f9aeb9421a50c27eb2:/tig.c diff --git a/tig.c b/tig.c index c41f2b2..0ceeb80 100644 --- a/tig.c +++ b/tig.c @@ -586,6 +586,7 @@ LINE(DEFAULT, "", COLOR_DEFAULT, COLOR_DEFAULT, A_NORMAL), \ LINE(CURSOR, "", COLOR_WHITE, COLOR_GREEN, A_BOLD), \ LINE(STATUS, "", COLOR_GREEN, COLOR_DEFAULT, 0), \ LINE(DELIMITER, "", COLOR_MAGENTA, COLOR_DEFAULT, 0), \ +LINE(LINE_NUMBER, "", COLOR_CYAN, COLOR_DEFAULT, 0), \ LINE(TITLE_BLUR, "", COLOR_WHITE, COLOR_BLUE, 0), \ LINE(TITLE_FOCUS, "", COLOR_WHITE, COLOR_BLUE, A_BOLD), \ LINE(MAIN_DATE, "", COLOR_BLUE, COLOR_DEFAULT, 0), \ @@ -609,8 +610,7 @@ LINE(STAT_UNTRACKED,"", COLOR_MAGENTA, COLOR_DEFAULT, 0), \ LINE(BLAME_DATE, "", COLOR_BLUE, COLOR_DEFAULT, 0), \ LINE(BLAME_AUTHOR, "", COLOR_GREEN, COLOR_DEFAULT, 0), \ LINE(BLAME_COMMIT, "", COLOR_DEFAULT, COLOR_DEFAULT, 0), \ -LINE(BLAME_ID, "", COLOR_MAGENTA, COLOR_DEFAULT, 0), \ -LINE(BLAME_LINENO, "", COLOR_CYAN, COLOR_DEFAULT, 0) +LINE(BLAME_ID, "", COLOR_MAGENTA, COLOR_DEFAULT, 0) enum line_type { #define LINE(type, line, fg, bg, attr) \ @@ -1507,6 +1507,8 @@ draw_lineno(struct view *view, unsigned int lineno, int max, bool selected) if (max < max_number) max_number = max; + if (!selected) + wattrset(view->win, get_line_attr(LINE_LINE_NUMBER)); col = draw_text(view, number, max_number, showtrimmed, selected); if (col < max) { if (!selected) @@ -2305,6 +2307,7 @@ enum open_flags { 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. */ }; static void @@ -2313,6 +2316,7 @@ open_view(struct view *prev, enum request request, enum open_flags flags) bool backgrounded = !!(flags & OPEN_BACKGROUNDED); bool split = !!(flags & OPEN_SPLIT); bool reload = !!(flags & OPEN_RELOAD); + bool nomaximize = !!(flags & OPEN_NOMAXIMIZE); struct view *view = VIEW(request); int nviews = displayed_views(); struct view *base_view = display[0]; @@ -2331,7 +2335,7 @@ open_view(struct view *prev, enum request request, enum open_flags flags) display[1] = view; if (!backgrounded) current_view = 1; - } else { + } else if (!nomaximize) { /* Maximize the current view. */ memset(display, 0, sizeof(display)); current_view = 0; @@ -2377,7 +2381,7 @@ open_view(struct view *prev, enum request request, enum open_flags flags) if (view->pipe && view->lines == 0) { /* Clear the old view and let the incremental updating refill * the screen. */ - wclear(view->win); + werase(view->win); report(""); } else { redraw_view(view); @@ -2504,7 +2508,12 @@ view_driver(struct view *view, enum request request) if (request > REQ_NONE) { open_run_request(request); - return TRUE; + /* FIXME: When all views can refresh always do this. */ + if (view == VIEW(REQ_VIEW_STATUS) || + view == VIEW(REQ_VIEW_STAGE)) + request = REQ_REFRESH; + else + return TRUE; } if (view && view->lines) { @@ -2637,27 +2646,27 @@ view_driver(struct view *view, enum request request) case REQ_TOGGLE_LINENO: opt_line_number = !opt_line_number; - redraw_display(); + redraw_view(view); break; case REQ_TOGGLE_DATE: opt_date = !opt_date; - redraw_display(); + redraw_view(view); break; case REQ_TOGGLE_AUTHOR: opt_author = !opt_author; - redraw_display(); + redraw_view(view); break; case REQ_TOGGLE_REV_GRAPH: opt_rev_graph = !opt_rev_graph; - redraw_display(); + redraw_view(view); break; case REQ_TOGGLE_REFS: opt_show_refs = !opt_show_refs; - redraw_display(); + redraw_view(view); break; case REQ_PROMPT: @@ -3635,8 +3644,6 @@ blame_draw(struct view *view, struct line *line, unsigned int lineno, bool selec } { - if (!selected) - wattrset(view->win, get_line_attr(LINE_BLAME_LINENO)); col += draw_lineno(view, lineno, view->width - col, selected); if (col >= view->width) return TRUE; @@ -4159,6 +4166,23 @@ status_enter(struct view *view, struct line *line) return REQ_NONE; } +static bool +status_exists(struct status *status, enum line_type type) +{ + struct view *view = VIEW(REQ_VIEW_STATUS); + struct line *line; + + for (line = view->line; line < view->line + view->lines; line++) { + struct status *pos = line->data; + + if (line->type == type && pos && + !strcmp(status->new.name, pos->new.name)) + return TRUE; + } + + return FALSE; +} + static FILE * status_update_prepare(enum line_type type) @@ -4539,26 +4563,22 @@ stage_update_chunk(struct view *view, struct line *line) return TRUE; } -static void +static bool stage_update(struct view *view, struct line *line) { if (!opt_no_head && stage_line_type != LINE_STAT_UNTRACKED && (line->type == LINE_DIFF_CHUNK || !stage_status.status)) { if (!stage_update_chunk(view, line)) { report("Failed to apply chunk"); - return; + return FALSE; } } else if (!status_update_file(&stage_status, stage_line_type)) { report("Failed to update file"); - return; + return FALSE; } - open_view(view, REQ_VIEW_STATUS, OPEN_RELOAD); - - view = VIEW(REQ_VIEW_STATUS); - if (view_is_displayed(view)) - status_enter(view, &view->line[view->lineno]); + return TRUE; } static enum request @@ -4576,6 +4596,10 @@ stage_request(struct view *view, enum request request, struct line *line) open_editor(stage_status.status != '?', stage_status.new.name); break; + case REQ_REFRESH: + /* Reload everything ... */ + break; + case REQ_VIEW_BLAME: if (stage_status.new.name[0]) { string_copy(opt_file, stage_status.new.name); @@ -4584,13 +4608,25 @@ stage_request(struct view *view, enum request request, struct line *line) return request; case REQ_ENTER: - pager_request(view, request, line); - break; + return pager_request(view, request, line); default: return request; } + open_view(view, REQ_VIEW_STATUS, OPEN_RELOAD | OPEN_NOMAXIMIZE); + + /* Check whether the staged entry still exists, and close the + * stage view if it doesn't. */ + if (!status_exists(&stage_status, stage_line_type)) + return REQ_VIEW_CLOSE; + + if (stage_line_type == LINE_STAT_UNTRACKED) + 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); + return REQ_NONE; } @@ -5621,7 +5657,7 @@ read_repo_config_option(char *name, size_t namelen, char *value, size_t valuelen } static int -load_repo_config(void) +load_git_config(void) { return read_properties(popen(GIT_CONFIG " --list", "r"), "=", read_repo_config_option); @@ -5776,9 +5812,7 @@ main(int argc, char *argv[]) if (load_options() == ERR) die("Failed to load user config."); - /* Load the repo config file so options can be overwritten from - * the command line. */ - if (load_repo_config() == ERR) + if (load_git_config() == ERR) die("Failed to load repo config."); if (!parse_options(argc, argv)) @@ -5797,7 +5831,7 @@ main(int argc, char *argv[]) die("Failed to initialize character set conversion"); } - if (load_refs() == ERR) + if (*opt_git_dir && load_refs() == ERR) die("Failed to load refs."); for (i = 0; i < ARRAY_SIZE(views) && (view = &views[i]); i++)