From 7351f170b0e4e6f7675ccff9167b4892ed9f426b Mon Sep 17 00:00:00 2001 From: Thomas Koutcher Date: Thu, 3 Oct 2024 22:55:17 +0200 Subject: [PATCH] Show committer date by default in the date column Although the author name is generally of more interest than the committer name, the committer date is more significant as it shows when the change was actually added to the commit history. Make it the default for the date column. The author date can be restored on a per-view basis using the `use-author` option of the `date` column in the view settings of ~/.tigrc. See tigrc(5). Note: to have both author date and committer date shown in the log view, add `--pretty=fuller` to `log-options`. Closes #294 --- NEWS.adoc | 1 + doc/manual.adoc | 6 ++--- doc/tigrc.5.adoc | 4 ++- include/tig/options.h | 3 ++- include/tig/parse.h | 2 +- src/blame.c | 4 ++- src/diff.c | 2 +- src/main.c | 4 ++- src/options.c | 12 ++++++--- src/parse.c | 9 ++++--- src/reflog.c | 2 +- src/refs.c | 16 +++++++++--- src/tree.c | 8 +++++- test/blame/default-test | 1 + test/blame/start-on-line-test | 48 +++++++++++++++++----------------- test/diff/diff-stat-split-test | 1 + test/main/filter-args-test | 4 +++ test/main/graph-argument-test | 2 +- test/main/jump-ends-test | 4 +++ test/main/no-merges-test | 4 +++ test/main/start-on-line-test | 12 ++++----- test/refs/start-on-line-test | 6 ++--- test/tigrc/width-test | 1 + test/tree/chdir-test | 2 +- test/tree/default-test | 1 + tigrc | 1 + 26 files changed, 102 insertions(+), 58 deletions(-) diff --git a/NEWS.adoc b/NEWS.adoc index d01d8d7d1..8ed5e41f5 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -17,6 +17,7 @@ Improvements: - Make errors visible in views showing Git output. (#1346) - Allow different colors for all references types. - Enable search in sections titles. (#1043) + - Show committer date by default in the date column. (#294) tig-2.5.10 ---------- diff --git a/doc/manual.adoc b/doc/manual.adoc index bb4d65064..eb06b0186 100644 --- a/doc/manual.adoc +++ b/doc/manual.adoc @@ -88,9 +88,9 @@ from an external command, most often 'git log', 'git diff', or 'git show'. The main view:: Is the default view, and it shows a one line summary of each commit - in the chosen list of revisions. The summary includes author date, - author, and the first line of the log message. Additionally, any - repository references, such as tags, will be shown. + in the chosen list of revisions. The summary includes committer date + or author date, author, and the first line of the log message. + Additionally, any repository references, such as tags, will be shown. The log view:: Presents a more rich view of the revision log showing the whole log diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc index b0b351fce..cdc4d55b8 100644 --- a/doc/tigrc.5.adoc +++ b/doc/tigrc.5.adoc @@ -509,6 +509,8 @@ date:: relative date will be used, e.g. "2 minutes ago" or "2m". If set to "custom", the strftime(3) string format specified in the "format" option is used. + - 'use-author' (bool): Whether to show author date instead of committer + date. - 'local' (bool): If true, use localtime(3) to convert to local timezone. Note that relative dates always use local offsets. - 'format' (string): format string to pass to strftime(3) when 'custom' @@ -1068,7 +1070,7 @@ setting the *default* color option. sections in the help view. |line-number |Line numbers. |id |The commit ID. -|date |The author date. +|date |The committer date or author date. |author |The commit author. |mode |The file mode holding the permissions and type. |overflow |Title text overflow. diff --git a/include/tig/options.h b/include/tig/options.h index 22a9d93c8..3d6563247 100644 --- a/include/tig/options.h +++ b/include/tig/options.h @@ -110,6 +110,7 @@ OPTION_INFO(DEFINE_OPTION_EXTERNS) #define DATE_COLUMN_OPTIONS(_) \ _(display, enum date, VIEW_NO_FLAGS) \ + _(use_author, bool, VIEW_NO_FLAGS) \ _(local, bool, VIEW_NO_FLAGS) \ _(format, const char *, VIEW_NO_FLAGS) \ _(width, int, VIEW_NO_FLAGS) \ @@ -196,7 +197,7 @@ void update_options_from_argv(const char *argv[]); const char *ignore_space_arg(); const char *commit_order_arg(); const char *commit_order_arg_with_graph(enum graph_display graph_display); -const char *log_custom_pretty_arg(); +const char *log_custom_pretty_arg(bool use_author_date); const char *use_mailmap_arg(); const char *diff_context_arg(); const char *diff_prefix_arg(); diff --git a/include/tig/parse.h b/include/tig/parse.h index c17d8b462..b4817e7fe 100644 --- a/include/tig/parse.h +++ b/include/tig/parse.h @@ -48,7 +48,7 @@ struct blame_header { }; bool parse_blame_header(struct blame_header *header, const char *text); -bool parse_blame_info(struct blame_commit *commit, char author[SIZEOF_STR], char *line); +bool parse_blame_info(struct blame_commit *commit, char author[SIZEOF_STR], char *line, bool use_author_date); /* Parse author lines where the name may be empty: * author 1138474660 +0100 diff --git a/src/blame.c b/src/blame.c index 9c187fbcc..5009aeb1f 100644 --- a/src/blame.c +++ b/src/blame.c @@ -219,6 +219,8 @@ static bool blame_read(struct view *view, struct buffer *buf, bool force_stop) { struct blame_state *state = view->private; + struct view_column *column = get_view_column(view, VIEW_COLUMN_DATE); + bool use_author_date = column && column->opt.date.use_author; if (!buf) { if (failed_to_load_initial_view(view)) @@ -256,7 +258,7 @@ blame_read(struct view *view, struct buffer *buf, bool force_stop) state->commit = NULL; - } else if (parse_blame_info(state->commit, state->author, buf->data)) { + } else if (parse_blame_info(state->commit, state->author, buf->data, use_author_date)) { if (!state->commit->filename) return false; diff --git a/src/diff.c b/src/diff.c index 280751cda..0b8a51d75 100644 --- a/src/diff.c +++ b/src/diff.c @@ -588,7 +588,7 @@ diff_blame_line(const char *ref, const char *file, unsigned long lineno, break; header = NULL; - } else if (parse_blame_info(commit, author, buf.data)) { + } else if (parse_blame_info(commit, author, buf.data, false)) { ok = commit->filename != NULL; break; } diff --git a/src/main.c b/src/main.c index fadd656c9..277f6892a 100644 --- a/src/main.c +++ b/src/main.c @@ -276,10 +276,12 @@ main_open(struct view *view, enum open_flags flags) { struct view_column *commit_title_column = get_view_column(view, VIEW_COLUMN_COMMIT_TITLE); enum graph_display graph_display = main_with_graph(view, commit_title_column, flags); + struct view_column *column = get_view_column(view, VIEW_COLUMN_DATE); + bool use_author_date = column && column->opt.date.use_author; const char *pretty_custom_argv[] = { GIT_MAIN_LOG(encoding_arg, commit_order_arg_with_graph(graph_display), "%(mainargs)", "%(cmdlineargs)", "%(revargs)", "%(fileargs)", - show_notes_arg(), log_custom_pretty_arg()) + show_notes_arg(), log_custom_pretty_arg(use_author_date)) }; const char *pretty_raw_argv[] = { GIT_MAIN_LOG_RAW(encoding_arg, commit_order_arg_with_graph(graph_display), diff --git a/src/options.c b/src/options.c index db72e29ab..1d897c39e 100644 --- a/src/options.c +++ b/src/options.c @@ -159,11 +159,15 @@ use_mailmap_arg() } const char * -log_custom_pretty_arg(void) +log_custom_pretty_arg(bool use_author_date) { - return opt_mailmap - ? "--pretty=format:commit %m %H %P%x00%aN <%aE> %ad%x00%s%x00%N" - : "--pretty=format:commit %m %H %P%x00%an <%ae> %ad%x00%s%x00%N"; + return use_author_date + ? opt_mailmap + ? "--pretty=format:commit %m %H %P%x00%aN <%aE> %ad%x00%s%x00%N" + : "--pretty=format:commit %m %H %P%x00%an <%ae> %ad%x00%s%x00%N" + : opt_mailmap + ? "--pretty=format:commit %m %H %P%x00%aN <%aE> %cd%x00%s%x00%N" + : "--pretty=format:commit %m %H %P%x00%an <%ae> %cd%x00%s%x00%N"; } #define ENUM_ARG(enum_name, arg_string) ENUM_MAP_ENTRY(arg_string, enum_name) diff --git a/src/parse.c b/src/parse.c index 20e98a72e..ae8e45e73 100644 --- a/src/parse.c +++ b/src/parse.c @@ -73,7 +73,8 @@ parse_author_line(char *ident, const struct ident **author, struct time *time) if (!*email) email = *name ? name : unknown_ident.email; - *author = get_author(name, email); + if (author) + *author = get_author(name, email); /* Parse epoch and timezone */ if (time && emailend && emailend[1] == ' ') { @@ -138,7 +139,7 @@ match_blame_header(const char *name, char **line) } bool -parse_blame_info(struct blame_commit *commit, char author[SIZEOF_STR], char *line) +parse_blame_info(struct blame_commit *commit, char author[SIZEOF_STR], char *line, bool use_author_date) { if (match_blame_header("author ", &line)) { string_ncopy_do(author, SIZEOF_STR, line, strlen(line)); @@ -153,10 +154,10 @@ parse_blame_info(struct blame_commit *commit, char author[SIZEOF_STR], char *lin commit->author = get_author(author, line); author[0] = 0; - } else if (match_blame_header("author-time ", &line)) { + } else if (match_blame_header(use_author_date ? "author-time " : "committer-time ", &line)) { parse_timesec(&commit->time, line); - } else if (match_blame_header("author-tz ", &line)) { + } else if (match_blame_header(use_author_date ? "author-tz " : "committer-tz ", &line)) { parse_timezone(&commit->time, line); } else if (match_blame_header("summary ", &line)) { diff --git a/src/reflog.c b/src/reflog.c index 9f4ffde13..9ee09a123 100644 --- a/src/reflog.c +++ b/src/reflog.c @@ -44,7 +44,7 @@ reflog_request(struct view *view, enum request request, struct line *line) const char *main_argv[] = { GIT_MAIN_LOG(encoding_arg, commit_order_arg(), "%(mainargs)", "", commit->id, "", - show_notes_arg(), log_custom_pretty_arg()) + show_notes_arg(), log_custom_pretty_arg(false)) }; enum open_flags flags = view_is_displayed(view) ? OPEN_SPLIT : OPEN_DEFAULT; diff --git a/src/refs.c b/src/refs.c index dab556a25..5be8cea71 100644 --- a/src/refs.c +++ b/src/refs.c @@ -73,11 +73,13 @@ refs_request(struct view *view, enum request request, struct line *line) case REQ_ENTER: { const struct ref *ref = reference->ref; + struct view_column *column = get_view_column(view, VIEW_COLUMN_DATE); + bool use_author_date = column && column->opt.date.use_author; const char *all_references_argv[] = { GIT_MAIN_LOG(encoding_arg, commit_order_arg(), "%(mainargs)", "", refs_is_all(reference) ? "--all" : ref->id, "", - show_notes_arg(), log_custom_pretty_arg()) + show_notes_arg(), log_custom_pretty_arg(use_author_date)) }; enum open_flags flags = view_is_displayed(view) ? OPEN_SPLIT : OPEN_DEFAULT; @@ -173,10 +175,16 @@ static const char **refs_argv; static enum status_code refs_open(struct view *view, enum open_flags flags) { + struct view_column *column = get_view_column(view, VIEW_COLUMN_DATE); + bool use_author_date = column && column->opt.date.use_author; const char *refs_log[] = { - "git", "log", encoding_arg, "--no-color", "--date=raw", - opt_mailmap ? "--pretty=format:%H%x00%aN <%aE> %ad%x00%s" - : "--pretty=format:%H%x00%an <%ae> %ad%x00%s", + "git", "log", encoding_arg, "--no-color", "--date=raw", use_author_date + ? opt_mailmap + ? "--pretty=format:%H%x00%aN <%aE> %ad%x00%s" + : "--pretty=format:%H%x00%an <%ae> %ad%x00%s" + : opt_mailmap + ? "--pretty=format:%H%x00%aN <%aE> %cd%x00%s" + : "--pretty=format:%H%x00%an <%ae> %cd%x00%s", "--all", "--simplify-by-decoration", NULL }; enum status_code code; diff --git a/src/tree.c b/src/tree.c index e18e57bf4..94ee0f9de 100644 --- a/src/tree.c +++ b/src/tree.c @@ -135,6 +135,8 @@ static bool tree_read_date(struct view *view, struct buffer *buf, struct tree_state *state) { char *text = buf ? buf->data : NULL; + struct view_column *column = get_view_column(view, VIEW_COLUMN_DATE); + bool use_author_date = column && column->opt.date.use_author; if (!text && state->read_date) { state->read_date = false; @@ -167,7 +169,11 @@ tree_read_date(struct view *view, struct buffer *buf, struct tree_state *state) } else if (*text == 'a' && get_line_type(text) == LINE_AUTHOR) { parse_author_line(text + STRING_SIZE("author "), - &state->author, &state->author_time); + &state->author, use_author_date ? &state->author_time : NULL); + + } else if (*text == 'c' && get_line_type(text) == LINE_COMMITTER) { + parse_author_line(text + STRING_SIZE("committer "), + NULL, use_author_date ? NULL : &state->author_time); } else if (*text == ':') { char *pos; diff --git a/test/blame/default-test b/test/blame/default-test index 1c113449c..8a5bc8de0 100755 --- a/test/blame/default-test +++ b/test/blame/default-test @@ -6,6 +6,7 @@ tigrc <