Code

Refactor mkauthor from draw_author
authorJonas Fonseca <fonseca@diku.dk>
Sun, 10 Apr 2011 03:39:01 +0000 (23:39 -0400)
committerJonas Fonseca <fonseca@diku.dk>
Sun, 10 Apr 2011 03:39:01 +0000 (23:39 -0400)
tig.c

diff --git a/tig.c b/tig.c
index 65973d2bcb4ea659170d73ee25f9782b6082953d..7de7f8603f510cb4e487be33b1c09abbc92c3ff8 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -207,6 +207,20 @@ get_author_initials(const char *author)
        return initials;
 }
 
+#define author_trim(cols) (cols == 0 || cols > 5)
+
+static const char *
+mkauthor(const char *text, int cols, enum author author)
+{
+       bool trim = author_trim(cols);
+       bool abbreviate = author == AUTHOR_ABBREVIATED || !trim;
+
+       if (!author)
+               return "";
+       if (abbreviate && text)
+               return get_author_initials(text);
+       return text;
+}
 
 /*
  * User requests
@@ -1654,16 +1668,10 @@ draw_date(struct view *view, struct time *time)
 static bool
 draw_author(struct view *view, const char *author)
 {
-       bool trim = opt_author_cols == 0 || opt_author_cols > 5;
-       bool abbreviate = opt_author == AUTHOR_ABBREVIATED || !trim;
-
-       if (opt_author == AUTHOR_NO)
-               return FALSE;
-
-       if (abbreviate && author)
-               author = get_author_initials(author);
+       bool trim = author_trim(opt_author_cols);
+       const char *text = mkauthor(author, opt_author_cols, opt_author);
 
-       return draw_field(view, LINE_AUTHOR, author, opt_author_cols, trim);
+       return draw_field(view, LINE_AUTHOR, text, opt_author_cols, trim);
 }
 
 static bool