X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=tig.c;h=54d99a721378cee897c49df99e728b61357dba55;hb=33e10c2599e16ff6690e7b0bbdd7a95e7f97c886;hp=589bc5329c4a0b99d1b93ce435d2a2c78a67b3be;hpb=054e357010a660fd8a261417d215e64655dd8ec2;p=tig.git diff --git a/tig.c b/tig.c index 589bc53..54d99a7 100644 --- a/tig.c +++ b/tig.c @@ -68,7 +68,6 @@ static void __NORETURN die(const char *err, ...); static void warn(const char *msg, ...); static void report(const char *msg, ...); -static void set_nonblocking_input(bool loading); static size_t utf8_length(const char **start, size_t skip, int *width, size_t max_width, int *trimmed, bool reserve, int tab_size); static inline unsigned char utf8_char_length(const char *string, const char *end); @@ -138,6 +137,7 @@ struct ref_list { struct ref **refs; /* References for this ID. */ }; +static struct ref *get_ref_head(); static struct ref_list *get_ref_list(const char *id); static void foreach_ref(bool (*visitor)(void *data, const struct ref *ref), void *data); static int load_refs(void); @@ -1061,7 +1061,6 @@ static char opt_path[SIZEOF_STR] = ""; 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_encoding[20] = "UTF-8"; static iconv_t opt_iconv_in = ICONV_NONE; @@ -1074,8 +1073,8 @@ 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))) +#define is_initial_commit() (!get_ref_head()) +#define is_head_commit(rev) (!strcmp((rev), "HEAD") || (get_ref_head() && !strcmp(rev, get_ref_head()->id))) #define mkdate(time) string_date(time, opt_date) @@ -3041,7 +3040,6 @@ end_update(struct view *view, bool force) while (!view->ops->read(view, NULL)) if (!force) return; - set_nonblocking_input(FALSE); if (force) kill_io(view->pipe); done_io(view->pipe); @@ -3051,7 +3049,6 @@ end_update(struct view *view, bool force) static void setup_update(struct view *view, const char *vid) { - set_nonblocking_input(TRUE); reset_view(view); string_copy_rev(view->vid, vid); view->pipe = &view->io; @@ -6972,17 +6969,6 @@ report(const char *msg, ...) update_view_title(view); } -/* Controls when nodelay should be in effect when polling user input. */ -static void -set_nonblocking_input(bool loading) -{ - static unsigned int loading_views; - - if ((loading == FALSE && loading_views-- == 1) || - (loading == TRUE && loading_views++ == 0)) - nodelay(status_win, loading); -} - static void init_display(void) { @@ -7050,6 +7036,7 @@ get_input(int prompt_position) { struct view *view; int i, key, cursor_y, cursor_x; + bool loading = FALSE; if (prompt_position) input_mode = TRUE; @@ -7061,6 +7048,8 @@ get_input(int prompt_position) use_scroll_redrawwin) redrawwin(view->win); view->has_scrolled = FALSE; + if (view->pipe) + loading = TRUE; } /* Update the cursor position. */ @@ -7077,6 +7066,7 @@ get_input(int prompt_position) /* Refresh, accept single keystroke of input */ doupdate(); + nodelay(status_win, loading); key = wgetch(status_win); /* wgetch() with nodelay() enabled returns ERR when @@ -7259,6 +7249,7 @@ static bool prompt_menu(const char *prompt, const struct menu_item *items, int * static struct ref **refs = NULL; static size_t refs_size = 0; +static struct ref *refs_head = NULL; static struct ref_list **ref_lists = NULL; static size_t ref_lists_size = 0; @@ -7296,6 +7287,12 @@ foreach_ref(bool (*visitor)(void *data, const struct ref *ref), void *data) break; } +static struct ref * +get_ref_head() +{ + return refs_head; +} + static struct ref_list * get_ref_list(const char *id) { @@ -7360,11 +7357,15 @@ read_ref(char *id, size_t idlen, char *name, size_t namelen) } else if (!prefixcmp(name, "refs/heads/")) { namelen -= STRING_SIZE("refs/heads/"); name += STRING_SIZE("refs/heads/"); - head = !strncmp(opt_head, name, namelen); + if (!strncmp(opt_head, name, namelen)) + return OK; } else if (!strcmp(name, "HEAD")) { - string_ncopy(opt_head_rev, id, idlen); - return OK; + head = TRUE; + if (*opt_head) { + namelen = strlen(opt_head); + name = opt_head; + } } /* If we are reloading or it's an annotated tag, replace the @@ -7406,6 +7407,8 @@ read_ref(char *id, size_t idlen, char *name, size_t namelen) ref->tracked = tracked; string_copy_rev(ref->id, id); + if (head) + refs_head = ref; return OK; } @@ -7436,6 +7439,7 @@ load_refs(void) memmove(opt_head, offset, strlen(offset) + 1); } + refs_head = NULL; for (i = 0; i < refs_size; i++) refs[i]->id[0] = 0;