Skip to content

Commit 41585d5

Browse files
committed
Toggle name and date between committer and author
1. One global option for all views. 2. Work dynamically in views: main, log, refs, blame and tree. tig command : set committer = yes|no toggle key seq. : o, m 3. Remove column option date-use-author which * works only with static config (tigrc) * cannot show author name
1 parent 9fb7aa3 commit 41585d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+303
-175
lines changed

include/tig/line.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ struct ref;
4343
_(PP_REFS, "Refs: "), \
4444
_(PP_REFLOG, "Reflog: "), \
4545
_(PP_REFLOGMSG, "Reflog message: "), \
46+
_(PP_AUTHOR, "Author: " ), \
47+
_(PP_DATE, "Date: "), \
48+
_(PP_AUTHORDATE, "AuthorDate: "), \
49+
_(PP_COMMITTER, "Commit: " ), \
50+
_(PP_COMMITDATE, "CommitDate: "), \
4651
_(COMMIT, "commit "), \
4752
_(PARENT, "parent "), \
4853
_(TREE, "tree "), \

include/tig/options.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ typedef struct view_column *view_settings;
9090
_(vertical_split, enum vertical_split, VIEW_RESET_DISPLAY | VIEW_DIFF_LIKE) \
9191
_(wrap_lines, bool, VIEW_DIFF_LIKE) \
9292
_(wrap_search, bool, VIEW_NO_FLAGS) \
93+
_(committer, bool, VIEW_LOG_LIKE | VIEW_BLAME_LIKE) \
9394

9495
#define DEFINE_OPTION_EXTERNS(name, type, flags) extern type opt_##name;
9596
OPTION_INFO(DEFINE_OPTION_EXTERNS)
@@ -111,7 +112,6 @@ OPTION_INFO(DEFINE_OPTION_EXTERNS)
111112

112113
#define DATE_COLUMN_OPTIONS(_) \
113114
_(display, enum date, VIEW_NO_FLAGS) \
114-
_(use_author, bool, VIEW_BLAME_LIKE | VIEW_LOG_LIKE) \
115115
_(local, bool, VIEW_NO_FLAGS) \
116116
_(format, const char *, VIEW_NO_FLAGS) \
117117
_(width, int, VIEW_NO_FLAGS) \
@@ -198,7 +198,7 @@ void update_options_from_argv(const char *argv[]);
198198
const char *ignore_space_arg();
199199
const char *commit_order_arg();
200200
const char *commit_order_arg_with_graph(enum graph_display graph_display);
201-
const char *log_custom_pretty_arg(bool use_author_date);
201+
const char *log_custom_pretty_arg();
202202
const char *use_mailmap_arg();
203203
const char *diff_context_arg();
204204
const char *diff_prefix_arg();

include/tig/parse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct blame_header {
4848
};
4949

5050
bool parse_blame_header(struct blame_header *header, const char *text);
51-
bool parse_blame_info(struct blame_commit *commit, char author[SIZEOF_STR], char *line, bool use_author_date);
51+
bool parse_blame_info(struct blame_commit *commit, char author[SIZEOF_STR], char *line);
5252

5353
/* Parse author lines where the name may be empty:
5454
* author <[email protected]> 1138474660 +0100

include/tig/view.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ enum view_flag {
7373
VIEW_SORTABLE = 1 << 16,
7474
VIEW_FLEX_WIDTH = 1 << 17,
7575
VIEW_RESET_DISPLAY = 1 << 18,
76+
VIEW_COMMIT_NAMEDATE = 1 << 19,
7677
};
7778

7879
#define view_has_flags(view, flag) ((view)->ops->flags & (flag))

src/blame.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ static bool
216216
blame_read(struct view *view, struct buffer *buf, bool force_stop)
217217
{
218218
struct blame_state *state = view->private;
219-
struct view_column *column = get_view_column(view, VIEW_COLUMN_DATE);
220-
bool use_author_date = column && column->opt.date.use_author;
221219

222220
if (!buf) {
223221
if (failed_to_load_initial_view(view))
@@ -255,7 +253,7 @@ blame_read(struct view *view, struct buffer *buf, bool force_stop)
255253

256254
state->commit = NULL;
257255

258-
} else if (parse_blame_info(state->commit, state->author, buf->data, use_author_date)) {
256+
} else if (parse_blame_info(state->commit, state->author, buf->data)) {
259257
if (!state->commit->filename)
260258
return false;
261259

@@ -504,7 +502,7 @@ blame_select(struct view *view, struct line *line)
504502
static struct view_ops blame_ops = {
505503
"line",
506504
argv_env.commit,
507-
VIEW_SEND_CHILD_ENTER | VIEW_BLAME_LIKE | VIEW_REFRESH,
505+
VIEW_SEND_CHILD_ENTER | VIEW_BLAME_LIKE | VIEW_REFRESH | VIEW_COMMIT_NAMEDATE,
508506
sizeof(struct blame_state),
509507
blame_open,
510508
blame_read,

src/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ diff_blame_line(const char *ref, const char *file, unsigned long lineno,
604604
break;
605605
header = NULL;
606606

607-
} else if (parse_blame_info(commit, author, buf.data, false)) {
607+
} else if (parse_blame_info(commit, author, buf.data)) {
608608
ok = commit->filename != NULL;
609609
break;
610610
}

src/log.c

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct log_state {
2828
bool commit_title_read;
2929
bool after_commit_header;
3030
bool reading_diff_stat;
31+
bool external_format;
3132
};
3233

3334
static inline void
@@ -63,16 +64,38 @@ log_select(struct view *view, struct line *line)
6364
state->last_type = line->type;
6465
}
6566

67+
static bool
68+
log_check_external_formatter()
69+
{
70+
/* check if any formatter arugments in "%(logargs)", "%(cmdlineargs)" */
71+
const char ** opt_list[] = {
72+
opt_log_options,
73+
opt_cmdline_args,
74+
};
75+
for (int i=0; i<ARRAY_SIZE(opt_list); i++) {
76+
if (opt_list[i] &&
77+
(argv_containsn(opt_list[i], "--pretty", STRING_SIZE("--pretty")) ||
78+
argv_containsn(opt_list[i], "--format", STRING_SIZE("--format"))))
79+
return true;
80+
}
81+
return false;
82+
}
83+
6684
static enum status_code
6785
log_open(struct view *view, enum open_flags flags)
6886
{
87+
struct log_state *state = view->private;
88+
bool external_format = log_check_external_formatter();
6989
const char *log_argv[] = {
7090
"git", "log", encoding_arg, commit_order_arg(),
7191
use_mailmap_arg(), "%(logargs)", "%(cmdlineargs)",
72-
"%(revargs)", "--no-color", "--", "%(fileargs)", NULL
92+
"%(revargs)", "--no-color",
93+
external_format ? "" : "--pretty=fuller",
94+
"--", "%(fileargs)", NULL
7395
};
7496
enum status_code code;
7597

98+
state->external_format = external_format;
7699
code = begin_update(view, NULL, log_argv, flags | OPEN_WITH_STDERR);
77100
if (code != SUCCESS)
78101
return code;
@@ -148,6 +171,25 @@ log_read(struct view *view, struct buffer *buf, bool force_stop)
148171
state->reading_diff_stat = false;
149172
}
150173

174+
if (!state->external_format) {
175+
switch (type)
176+
{
177+
case LINE_PP_AUTHOR:
178+
case LINE_PP_AUTHORDATE:
179+
case LINE_PP_DATE:
180+
if (opt_committer)
181+
return true;
182+
break;
183+
case LINE_PP_COMMITTER:
184+
case LINE_PP_COMMITDATE:
185+
if (!opt_committer)
186+
return true;
187+
break;
188+
default:
189+
break;
190+
}
191+
}
192+
151193
if (!pager_common_read(view, data, type, &line))
152194
return false;
153195
if (line && state->graph_indent)
@@ -158,7 +200,8 @@ log_read(struct view *view, struct buffer *buf, bool force_stop)
158200
static struct view_ops log_ops = {
159201
"line",
160202
argv_env.head,
161-
VIEW_ADD_PAGER_REFS | VIEW_OPEN_DIFF | VIEW_SEND_CHILD_ENTER | VIEW_LOG_LIKE | VIEW_REFRESH | VIEW_FLEX_WIDTH,
203+
VIEW_ADD_PAGER_REFS | VIEW_OPEN_DIFF | VIEW_SEND_CHILD_ENTER | VIEW_LOG_LIKE | VIEW_REFRESH | \
204+
VIEW_FLEX_WIDTH | VIEW_COMMIT_NAMEDATE,
162205
sizeof(struct log_state),
163206
log_open,
164207
log_read,

src/main.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,10 @@ main_open(struct view *view, enum open_flags flags)
276276
{
277277
struct view_column *commit_title_column = get_view_column(view, VIEW_COLUMN_COMMIT_TITLE);
278278
enum graph_display graph_display = main_with_graph(view, commit_title_column, flags);
279-
struct view_column *column = get_view_column(view, VIEW_COLUMN_DATE);
280-
bool use_author_date = column && column->opt.date.use_author;
281279
const char *pretty_custom_argv[] = {
282280
GIT_MAIN_LOG(encoding_arg, commit_order_arg_with_graph(graph_display),
283281
"%(mainargs)", "%(cmdlineargs)", "%(revargs)", "%(fileargs)",
284-
show_notes_arg(), log_custom_pretty_arg(use_author_date))
282+
show_notes_arg(), log_custom_pretty_arg())
285283
};
286284
const char *pretty_raw_argv[] = {
287285
GIT_MAIN_LOG_RAW(encoding_arg, commit_order_arg_with_graph(graph_display),
@@ -415,8 +413,6 @@ main_add_reflog(struct view *view, struct main_state *state, char *reflog)
415413
bool
416414
main_read(struct view *view, struct buffer *buf, bool force_stop)
417415
{
418-
struct view_column *column = get_view_column(view, VIEW_COLUMN_DATE);
419-
bool use_author_date = column && column->opt.date.use_author;
420416
struct main_state *state = view->private;
421417
struct graph *graph = state->graph;
422418
enum line_type type;
@@ -510,16 +506,17 @@ main_read(struct view *view, struct buffer *buf, bool force_stop)
510506
break;
511507

512508
case LINE_AUTHOR:
513-
parse_author_line(line + STRING_SIZE("author "),
514-
&commit->author, use_author_date ? &commit->time : NULL);
515-
if (state->with_graph)
516-
graph->render_parents(graph, &commit->graph);
517-
break;
518-
519509
case LINE_COMMITTER:
520-
parse_author_line(line + STRING_SIZE("committer "),
521-
NULL, use_author_date ? NULL : &commit->time);
510+
{
511+
bool committer_line = (type == LINE_COMMITTER);
512+
if ((opt_committer ^ committer_line) == 0)
513+
parse_author_line(line +
514+
(committer_line ? STRING_SIZE("committer ") : STRING_SIZE("author ")),
515+
&commit->author, &commit->time);
516+
if (committer_line && state->with_graph)
517+
graph->render_parents(graph, &commit->graph);
522518
break;
519+
}
523520

524521
default:
525522
/* Fill in the commit title if it has not already been set. */
@@ -661,7 +658,7 @@ main_select(struct view *view, struct line *line)
661658
static struct view_ops main_ops = {
662659
"commit",
663660
argv_env.head,
664-
VIEW_SEND_CHILD_ENTER | VIEW_FILE_FILTER | VIEW_REV_FILTER | VIEW_LOG_LIKE | VIEW_REFRESH,
661+
VIEW_SEND_CHILD_ENTER | VIEW_FILE_FILTER | VIEW_REV_FILTER | VIEW_LOG_LIKE | VIEW_REFRESH | VIEW_COMMIT_NAMEDATE,
665662
sizeof(struct main_state),
666663
main_open,
667664
main_read,

src/options.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,20 @@ use_mailmap_arg()
159159
}
160160

161161
const char *
162-
log_custom_pretty_arg(bool use_author_date)
162+
log_custom_pretty_arg()
163163
{
164-
return use_author_date
165-
? opt_mailmap
166-
? "--pretty=format:commit %m %H %P%x00%aN <%aE> %ad%x00%s%x00%N"
167-
: "--pretty=format:commit %m %H %P%x00%an <%ae> %ad%x00%s%x00%N"
168-
: opt_mailmap
169-
? "--pretty=format:commit %m %H %P%x00%aN <%aE> %cd%x00%s%x00%N"
170-
: "--pretty=format:commit %m %H %P%x00%an <%ae> %cd%x00%s%x00%N";
164+
switch ((opt_committer*2) + opt_mailmap)
165+
{
166+
case 0x3:
167+
return "--pretty=format:commit %m %H %P%x00%cN <%cE> %cd%x00%s%x00%N";
168+
case 0x2:
169+
return "--pretty=format:commit %m %H %P%x00%cn <%ce> %cd%x00%s%x00%N";
170+
case 0x1:
171+
return "--pretty=format:commit %m %H %P%x00%aN <%aE> %ad%x00%s%x00%N";
172+
case 0x0:
173+
default:
174+
return "--pretty=format:commit %m %H %P%x00%an <%ae> %ad%x00%s%x00%N";
175+
}
171176
}
172177

173178
#define ENUM_ARG(enum_name, arg_string) ENUM_MAP_ENTRY(arg_string, enum_name)
@@ -959,6 +964,7 @@ option_bind_command(int argc, const char *argv[])
959964
{ "toggle-title-overflow", "commit-title-overflow" },
960965
{ "toggle-untracked-dirs", "status-show-untracked-dirs" },
961966
{ "toggle-vertical-split", "show-vertical-split" },
967+
{ "toggle-committer", "committer" },
962968
};
963969
int alias;
964970

src/parse.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "tig/tig.h"
1515
#include "tig/parse.h"
1616
#include "tig/map.h"
17+
#include "tig/options.h"
1718

1819
size_t
1920
parse_size(const char *text)
@@ -139,12 +140,12 @@ match_blame_header(const char *name, char **line)
139140
}
140141

141142
bool
142-
parse_blame_info(struct blame_commit *commit, char author[SIZEOF_STR], char *line, bool use_author_date)
143+
parse_blame_info(struct blame_commit *commit, char author[SIZEOF_STR], char *line)
143144
{
144-
if (match_blame_header("author ", &line)) {
145+
if (match_blame_header(opt_committer ? "committer " : "author ", &line)) {
145146
string_ncopy_do(author, SIZEOF_STR, line, strlen(line));
146147

147-
} else if (match_blame_header("author-mail ", &line)) {
148+
} else if (match_blame_header(opt_committer ? "committer-mail " : "author-mail ", &line)) {
148149
char *end = strchr(line, '>');
149150

150151
if (end)
@@ -154,10 +155,10 @@ parse_blame_info(struct blame_commit *commit, char author[SIZEOF_STR], char *lin
154155
commit->author = get_author(author, line);
155156
author[0] = 0;
156157

157-
} else if (match_blame_header(use_author_date ? "author-time " : "committer-time ", &line)) {
158+
} else if (match_blame_header(opt_committer ? "committer-time " : "author-time ", &line)) {
158159
parse_timesec(&commit->time, line);
159160

160-
} else if (match_blame_header(use_author_date ? "author-tz " : "committer-tz ", &line)) {
161+
} else if (match_blame_header(opt_committer ? "committer-tz " : "author-tz ", &line)) {
161162
parse_timezone(&commit->time, line);
162163

163164
} else if (match_blame_header("summary ", &line)) {

0 commit comments

Comments
 (0)