From bc334f1ecc401b2753927a808fd36ef76ee00691 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 9 Apr 2011 23:39:01 -0400 Subject: [PATCH] Refactor mkauthor from draw_author --- tig.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tig.c b/tig.c index 65973d2..7de7f86 100644 --- 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 -- 2.30.2