Code

get_author_initials: various fixes
[tig.git] / tig.c
diff --git a/tig.c b/tig.c
index dd9437f5f39f29d3da373c80e9df443571d68adc..b0032ea67a9fd869b658fa3e984c38007a6250d6 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -158,19 +158,27 @@ get_author_initials(const char *author)
                unsigned char bytes;
                size_t i;
 
-               while (is_initial_sep(*author))
+               while (author < end && is_initial_sep(*author))
                        author++;
 
                bytes = utf8_char_length(author, end);
-               if (bytes < sizeof(initials) - 1 - pos) {
-                       while (bytes--) {
-                               initials[pos++] = *author++;
-                       }
+               if (bytes >= sizeof(initials) - 1 - pos)
+                       break;
+               while (bytes--) {
+                       initials[pos++] = *author++;
                }
 
-               for (i = pos; author < end && !is_initial_sep(*author); author++) {
-                       if (i < sizeof(initials) - 1)
-                               initials[i++] = *author;
+               i = pos;
+               while (author < end && !is_initial_sep(*author)) {
+                       bytes = utf8_char_length(author, end);
+                       if (bytes >= sizeof(initials) - 1 - i) {
+                               while (author < end && !is_initial_sep(*author))
+                                       author++;
+                               break;
+                       }
+                       while (bytes--) {
+                               initials[i++] = *author++;
+                       }
                }
 
                initials[i++] = 0;
@@ -187,7 +195,7 @@ mkauthor(const char *text, int cols, enum author author)
        bool trim = author_trim(cols);
        bool abbreviate = author == AUTHOR_ABBREVIATED || !trim;
 
-       if (!author)
+       if (author == AUTHOR_NO)
                return "";
        if (abbreviate && text)
                return get_author_initials(text);
@@ -1651,6 +1659,9 @@ draw_author(struct view *view, const char *author)
        bool trim = author_trim(opt_author_cols);
        const char *text = mkauthor(author, opt_author_cols, opt_author);
 
+       if (opt_author == AUTHOR_NO)
+               return FALSE;
+
        return draw_field(view, LINE_AUTHOR, text, opt_author_cols, trim);
 }
 
@@ -2717,6 +2728,7 @@ load_view(struct view *view, enum open_flags flags)
 }
 
 #define refresh_view(view) load_view(view, OPEN_REFRESH)
+#define reload_view(view) load_view(view, OPEN_RELOAD)
 
 static void
 split_view(struct view *prev, struct view *view)
@@ -3975,7 +3987,7 @@ tree_grep(struct view *view, struct line *line)
        struct tree_entry *entry = line->data;
        const char *text[] = {
                entry->name,
-               opt_author ? entry->author : "",
+               mkauthor(entry->author, opt_author_cols, opt_author),
                mkdate(&entry->time, opt_date),
                NULL
        };
@@ -4121,11 +4133,10 @@ blame_open(struct view *view, enum open_flags flags)
 
        if (*opt_ref || !begin_update(view, opt_cdup, file_argv, flags)) {
                const char *blame_cat_file_argv[] = {
-                       "git", "cat-file", "blob", path, NULL
+                       "git", "cat-file", "blob", "%(ref):%(file)", NULL
                };
 
-               if (!string_format(path, "%s:%s", opt_ref, opt_file) ||
-                   !begin_update(view, opt_cdup, blame_cat_file_argv, flags))
+               if (!begin_update(view, opt_cdup, blame_cat_file_argv, flags))
                        return FALSE;
        }
 
@@ -4147,7 +4158,7 @@ blame_open(struct view *view, enum open_flags flags)
                        free(blame->commit);
        }
 
-       string_format(view->vid, "%s:%s", opt_ref, opt_file);
+       string_format(view->vid, "%s", opt_file);
        string_format(view->ref, "%s ...", opt_file);
 
        return TRUE;
@@ -4424,7 +4435,7 @@ blame_request(struct view *view, enum request request, struct line *line)
                        string_copy(opt_file, blame->commit->filename);
                        if (blame->lineno)
                                view->lineno = blame->lineno;
-                       refresh_view(view);
+                       reload_view(view);
                }
                break;
 
@@ -4437,7 +4448,7 @@ blame_request(struct view *view, enum request request, struct line *line)
                        string_copy_rev(opt_ref, blame->commit->parent_id);
                        string_copy(opt_file, blame->commit->parent_filename);
                        setup_blame_parent_line(view, blame);
-                       refresh_view(view);
+                       reload_view(view);
                }
                break;
 
@@ -4690,7 +4701,7 @@ branch_grep(struct view *view, struct line *line)
        struct branch *branch = line->data;
        const char *text[] = {
                branch->ref->name,
-               branch->author,
+               mkauthor(branch->author, opt_author_cols, opt_author),
                NULL
        };
 
@@ -5944,7 +5955,7 @@ main_grep(struct view *view, struct line *line)
        struct commit *commit = line->data;
        const char *text[] = {
                commit->title,
-               opt_author ? commit->author : "",
+               mkauthor(commit->author, opt_author_cols, opt_author),
                mkdate(&commit->time, opt_date),
                NULL
        };