Skip to content

Commit

Permalink
Show committer date by default in the date column
Browse files Browse the repository at this point in the history
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
  • Loading branch information
koutcher committed Oct 3, 2024
1 parent 921c001 commit 7351f17
Show file tree
Hide file tree
Showing 26 changed files with 102 additions and 58 deletions.
1 change: 1 addition & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down
6 changes: 3 additions & 3 deletions doc/manual.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion doc/tigrc.5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion include/tig/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion include/tig/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]> 1138474660 +0100
Expand Down
4 changes: 3 additions & 1 deletion src/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
12 changes: 8 additions & 4 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] == ' ') {
Expand Down Expand Up @@ -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));
Expand All @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/reflog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 12 additions & 4 deletions src/refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion src/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/blame/default-test
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
tigrc <<EOF
set vertical-split = no
set line-graphics = ascii
set blame-view-date-use-author = yes
EOF

steps '
Expand Down
48 changes: 24 additions & 24 deletions test/blame/start-on-line-test
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,33 @@ EOF
test_tig blame deltablue/src/main/scala/org/scalajs/benchmark/deltablue/DeltaBlue.scala +42

assert_equals 'position.screen' <<EOF
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 28| // Dart by Google 2008-2010.
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 29| // Translated to Scala.js by Jonas Fonseca 2013
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 30|
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 28| // Dart by Google 2008-2010.
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 29| // Translated to Scala.js by Jonas Fonseca 2013
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 30|
296fc90 deltablue/src/main/scala/org/scalajs/benchmark/deltablue/DeltaBlue.scala Jonas Fonseca 2014-01-16 22:51 -0500 31| package org.scalajs.benchmark.deltablue
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 32|
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 33| /**
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 34| * A Scala implementation of the DeltaBlue constraint-solving
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 35| * algorithm, as described in:
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 36| *
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 37| * "The DeltaBlue Algorithm: An Incremental Constraint Hierarchy Solver"
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 38| * Bjorn N. Freeman-Benson and John Maloney
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 39| * January 1990 Communications of the ACM,
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 40| * also available as University of Washington TR 89-08-06.
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 41| *
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 42| * Beware: this benchmark is written in a grotesque style where
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 43| * the constraint model is built by side-effects from constructors.
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 44| * I've kept it this way to avoid deviating too much from the original
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 45| * implementation.
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 46| */
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 47|
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 48| import scala.collection.mutable.ArrayBuffer
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 32|
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 33| /**
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 34| * A Scala implementation of the DeltaBlue constraint-solving
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 35| * algorithm, as described in:
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 36| *
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 37| * "The DeltaBlue Algorithm: An Incremental Constraint Hierarchy Solver"
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 38| * Bjorn N. Freeman-Benson and John Maloney
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 39| * January 1990 Communications of the ACM,
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 40| * also available as University of Washington TR 89-08-06.
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 41| *
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 42| * Beware: this benchmark is written in a grotesque style where
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 43| * the constraint model is built by side-effects from constructors.
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 44| * I've kept it this way to avoid deviating too much from the original
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 45| * implementation.
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 46| */
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 47|
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 48| import scala.collection.mutable.ArrayBuffer
ee91287 deltablue/src/main/scala/org/scalajs/benchmark/deltablue/DeltaBlue.scala Jonas Fonseca 2014-03-01 17:26 -0500 49| import scala.scalajs.js.annotation.JSExport
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 50|
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 50|
ee91287 deltablue/src/main/scala/org/scalajs/benchmark/deltablue/DeltaBlue.scala Jonas Fonseca 2014-03-01 17:26 -0500 51| @JSExport
296fc90 deltablue/src/main/scala/org/scalajs/benchmark/deltablue/DeltaBlue.scala Jonas Fonseca 2014-01-16 22:51 -0500 52| object DeltaBlue extends org.scalajs.benchmark.Benchmark {
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 53|
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 54| override def prefix = "DeltaBlue"
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-18 18:00 -0400 55|
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 53|
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 54| override def prefix = "DeltaBlue"
b103989 deltablue/DeltaBlue.scala Jonas Fonseca 2013-10-20 00:23 -0700 55|
[blame] b103989d59edab3adc312ff5408fa3d344ea0201 changed deltablue/DeltaBlue.scala - line 42 of 711 7%
EOF
1 change: 1 addition & 0 deletions test/diff/diff-stat-split-test
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ steps '

tigrc <<EOF
set line-graphics = utf-8
set main-view-date-use-author = yes
EOF

in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz"
Expand Down
4 changes: 4 additions & 0 deletions test/main/filter-args-test
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ test_setup_work_dir()
git commit -a -m "Feature X"
}

tigrc <<EOF
set main-view-date-use-author = yes
EOF

steps '
:save-display filtered.screen
'
Expand Down
2 changes: 1 addition & 1 deletion test/main/graph-argument-test
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ touch stderr

tigrc <<EOF
set line-graphics = utf-8
set main-view = date:default author:abbreviated commit-title:yes,graph,refs=no,overflow=no
set main-view = date:default,use-author=yes author:abbreviated commit-title:yes,graph,refs=no,overflow=no
EOF

in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz"
Expand Down
4 changes: 4 additions & 0 deletions test/main/jump-ends-test
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ last_line_content=\
[main] 90286e0752016a6bca30dfa7ca236d1f99345eb8 - commit 48 of 48 100%'

tigrc <<EOF
set main-view-date-use-author = yes
EOF

in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz"

test_case main-goto-1 \
Expand Down
4 changes: 4 additions & 0 deletions test/main/no-merges-test
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

export LINES=16

tigrc <<EOF
set main-view-date-use-author = yes
EOF

in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz"

steps '
Expand Down
Loading

0 comments on commit 7351f17

Please sign in to comment.