Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,16 @@ test-address-sanitizer: export TIG_ADDRESS_SANITIZER_ENABLED=yes

TESTS = $(sort $(shell find test -type f -name '*-test'))
TESTS_TODO = $(sort $(shell find test -type f -name '*-test' -exec grep -l '\(test_todo\|-todo=\)' {} \+))
TESTS_TMP = $(patsubst test/%,test/tmp/%,$(TESTS))

clean-test:
$(Q)$(RM) -r test/tmp

test: clean-test $(TESTS)
$(QUIET_SUMMARY)test/tools/show-results.sh

fix-test: $(TESTS_TMP)

ifneq (,$(strip $(V:@=)))
export MAKE_TEST_OPTS = no-indent
else
Expand All @@ -278,6 +281,29 @@ $(TESTS): PATH := $(CURDIR)/test/tools:$(CURDIR)/src:$(PATH)
$(TESTS): $(EXE) test/tools/test-graph
$(QUIET_TEST)$(TEST_SHELL) $@

$(TESTS_TMP):
@ test -z "$$DEBUG" || set -x ; \
if egrep -q '^ *\[FAIL\]+' $@/.test-result 2>/dev/null; then \
name=$(patsubst test/tmp/%,test/%,$@); \
! test -f $$name.expected || name=$$name.expected; \
if git diff --quiet $$name; then \
perm=$$(stat -c %a $$name); \
cat $@/.test-result | { \
sed -r -e 's/\x1b\[.{0,5}m//g' \
-e '/^ *\[(OK|FAIL)\]+ .*/d' \
-e 's/^ $$/ /' \
-e "s# a/expected/\S+# a/$$name#" \
-e "s# b/\S+# b/$$name#" \
-e "s#^(index .*? 100)...#\1$$perm#" | { \
test -n "$$DEBUG" && cat || { \
git apply --verbose --ignore-whitespace --unidiff-zero && \
echo "Updated for $@!" || true; \
}; \
}; \
}; \
fi; \
fi

test-todo: MAKE_TEST_OPTS += todo
test-todo: $(TESTS_TODO)

Expand All @@ -295,7 +321,7 @@ site:
doc-man doc-html dist distclean install install-doc \
install-doc-man install-doc-html install-release-doc-html \
install-release-doc-man rpm spell-check strip test \
test-coverage update-docs update-headers veryclean $(TESTS)
test-coverage update-docs update-headers veryclean $(TESTS) $(TESTS_TMP)

ifdef NO_MKSTEMPS
COMPAT_CPPFLAGS += -DNO_MKSTEMPS
Expand Down
5 changes: 5 additions & 0 deletions include/tig/line.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ struct ref;
_(PP_REFS, "Refs: "), \
_(PP_REFLOG, "Reflog: "), \
_(PP_REFLOGMSG, "Reflog message: "), \
_(PP_AUTHOR, "Author: " ), \
_(PP_DATE, "Date: "), \
_(PP_AUTHORDATE, "AuthorDate: "), \
_(PP_COMMITTER, "Commit: " ), \
_(PP_COMMITDATE, "CommitDate: "), \
_(COMMIT, "commit "), \
_(PARENT, "parent "), \
_(TREE, "tree "), \
Expand Down
1 change: 1 addition & 0 deletions include/tig/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct commit {
struct main_state {
struct graph *graph;
struct commit current;
struct option_common optcom;
char **reflog;
size_t reflogs;
int reflog_width;
Expand Down
6 changes: 5 additions & 1 deletion include/tig/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ typedef struct view_column *view_settings;
_(vertical_split, enum vertical_split, VIEW_RESET_DISPLAY | VIEW_DIFF_LIKE) \
_(wrap_lines, bool, VIEW_DIFF_LIKE) \
_(wrap_search, bool, VIEW_NO_FLAGS) \
_(date_use_author, bool, VIEW_LOG_LIKE) \
_(author_as_committer, bool, VIEW_LOG_LIKE) \

#define DEFINE_OPTION_EXTERNS(name, type, flags) extern type opt_##name;
OPTION_INFO(DEFINE_OPTION_EXTERNS)
Expand All @@ -102,6 +104,7 @@ OPTION_INFO(DEFINE_OPTION_EXTERNS)
_(display, enum author, VIEW_NO_FLAGS) \
_(width, int, VIEW_NO_FLAGS) \
_(maxwidth, int, VIEW_NO_FLAGS) \
_(as_committer, bool, VIEW_BLAME_LIKE | VIEW_LOG_LIKE) \

#define COMMIT_TITLE_COLUMN_OPTIONS(_) \
_(display, bool, VIEW_NO_FLAGS) \
Expand Down Expand Up @@ -198,7 +201,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(bool use_author_date);
const char *log_custom_pretty_arg(struct option_common *optcom);
const char *use_mailmap_arg();
const char *diff_context_arg();
const char *diff_prefix_arg();
Expand All @@ -222,6 +225,7 @@ struct option_info *find_option_info(struct option_info *option, size_t options,
enum status_code parse_option(struct option_info *option, const char *prefix, const char *arg);
struct option_info *find_column_option_info(enum view_column_type type, union view_column_options *opts,
const char *option, struct option_info *column_info, const char **column_name);
void read_option_common(void *view, struct option_common *optcom);
enum status_code parse_int(int *opt, const char *arg, int min, int max);
enum status_code parse_step(double *opt, const char *arg);
enum status_code set_option(const char *opt, int argc, const char *argv[]);
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 use_author_date);
bool parse_blame_info(struct blame_commit *commit, char author[SIZEOF_STR], char *line, struct option_common *optcom);

/* Parse author lines where the name may be empty:
* author <email@address.tld> 1138474660 +0100
Expand Down
9 changes: 9 additions & 0 deletions include/tig/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,14 @@ name(type **mem, size_t size, size_t increase) \

void sigsegv_handler(int sig);

/*
* Common structures
*/

struct option_common {
bool author_as_committer;
bool use_author_date;
};

#endif
/* vim: set ts=8 sw=8 noexpandtab: */
7 changes: 4 additions & 3 deletions src/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct blame {
struct blame_state {
struct blame_commit *commit;
struct blame_header header;
struct option_common optcom;
char author[SIZEOF_STR];
bool auto_filename_display;
const char *filename;
Expand Down Expand Up @@ -77,6 +78,8 @@ blame_open(struct view *view, enum open_flags flags)
enum status_code code;
size_t i;

read_option_common(view, &state->optcom);

if (is_initial_view(view)) {
/* Finish validating and setting up blame options */
if (!opt_file_args || opt_file_args[1])
Expand Down Expand Up @@ -216,8 +219,6 @@ 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 @@ -255,7 +256,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, use_author_date)) {
} else if (parse_blame_info(state->commit, state->author, buf->data, &state->optcom)) {
if (!state->commit->filename)
return false;

Expand Down
6 changes: 5 additions & 1 deletion src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ diff_blame_line(const char *ref, const char *file, unsigned long lineno,
struct io io;
bool ok = false;
struct buffer buf;
struct option_common optcom = {
.author_as_committer = false,
.use_author_date = false,
};

if (!string_format(line_arg, "-L%lu,+1", lineno))
return false;
Expand All @@ -604,7 +608,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, false)) {
} else if (parse_blame_info(commit, author, buf.data, &optcom)) {
ok = commit->filename != NULL;
break;
}
Expand Down
89 changes: 88 additions & 1 deletion src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ struct log_state {
* up/down in the log view. */
int last_lineno;
size_t graph_indent;
struct option_common optcom;
enum line_type last_type;
bool commit_title_read;
bool after_commit_header;
bool reading_diff_stat;
bool external_format;
};

static inline void
Expand Down Expand Up @@ -63,16 +65,39 @@ log_select(struct view *view, struct line *line)
state->last_type = line->type;
}

static bool
log_check_external_formatter()
{
/* check if any formatter arugments in "%(logargs)", "%(cmdlineargs)" */
const char ** opt_list[] = {
opt_log_options,
opt_cmdline_args,
};
for (int i=0; i<ARRAY_SIZE(opt_list); i++) {
if (opt_list[i] &&
(argv_containsn(opt_list[i], "--pretty", STRING_SIZE("--pretty")) ||
argv_containsn(opt_list[i], "--format", STRING_SIZE("--format"))))
return true;
}
return false;
}

static enum status_code
log_open(struct view *view, enum open_flags flags)
{
struct log_state *state = view->private;
bool external_format = log_check_external_formatter();
const char *log_argv[] = {
"git", "log", encoding_arg, commit_order_arg(),
use_mailmap_arg(), "%(logargs)", "%(cmdlineargs)",
"%(revargs)", "--no-color", "--", "%(fileargs)", NULL
"%(revargs)", "--no-color",
external_format ? "" : "--pretty=fuller",
"--", "%(fileargs)", NULL
};
enum status_code code;

read_option_common(view, &state->optcom);
state->external_format = external_format;
code = begin_update(view, NULL, log_argv, flags | OPEN_WITH_STDERR);
if (code != SUCCESS)
return code;
Expand Down Expand Up @@ -115,6 +140,7 @@ log_read(struct view *view, struct buffer *buf, bool force_stop)
size_t len;
char *commit;
char *data;
bool swap_lines = false;

if (!buf)
return true;
Expand Down Expand Up @@ -148,10 +174,71 @@ log_read(struct view *view, struct buffer *buf, bool force_stop)
state->reading_diff_stat = false;
}

if (!state->external_format) {
switch (type)
{
case LINE_PP_AUTHOR:
if (state->optcom.author_as_committer)
return true;
break;
case LINE_PP_COMMITTER:
if (!state->optcom.author_as_committer)
return true;
swap_lines = state->optcom.use_author_date;
break;
case LINE_PP_AUTHORDATE:
case LINE_PP_DATE:
if (!state->optcom.use_author_date)
return true;
break;
case LINE_PP_COMMITDATE:
if (state->optcom.use_author_date)
return true;
break;
default:
break;
}
/* remove 4 spaces after Commit:/Author:, or
* convert CommitDate:/AuthorDate: to Date: */
switch (type)
{
case LINE_PP_AUTHOR:
case LINE_PP_COMMITTER:
{
char *p = strchr(data, ':');
if (p && p[5]==' ')
memmove(p+1, p+5, strlen(p+5)+1);
break;
}
case LINE_PP_AUTHORDATE:
case LINE_PP_COMMITDATE:
{
char *p = strchr(data, ':');
if (p && p[1]==' ' && (p - data) >= 10) {
memcpy(p - 10, "Date: ", STRING_SIZE("Date: "));
memmove(p - 10 + STRING_SIZE("Date: "), p+2, strlen(p+2)+1);
}
break;
}
default:
break;
}
}

if (!pager_common_read(view, data, type, &line))
return false;
if (line && state->graph_indent)
line->graph_indent = 1;
if (swap_lines && view->lines >= 2) {
size_t last_idx = view->lines - 1;
struct line *line1 = &view->line[last_idx];
struct line *line2 = &view->line[last_idx - 1];
struct line buf = *line1;
*line1 = *line2;
*line2 = buf;
line1->lineno--;
line2->lineno++;
}
return true;
}

Expand Down
26 changes: 12 additions & 14 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,20 @@ main_with_graph(struct view *view, struct view_column *column, enum open_flags f
static enum status_code
main_open(struct view *view, enum open_flags flags)
{
struct main_state *state = view->private;
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;
read_option_common(view, &state->optcom);
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(use_author_date))
show_notes_arg(), log_custom_pretty_arg(&state->optcom))
};
const char *pretty_raw_argv[] = {
GIT_MAIN_LOG_RAW(encoding_arg, commit_order_arg_with_graph(graph_display),
"%(mainargs)", "%(cmdlineargs)", "%(revargs)", "%(fileargs)",
show_notes_arg())
};
struct main_state *state = view->private;
const char **main_argv = pretty_custom_argv;
enum watch_trigger changes_triggers = WATCH_NONE;

Expand Down Expand Up @@ -415,8 +414,6 @@ main_add_reflog(struct view *view, struct main_state *state, char *reflog)
bool
main_read(struct view *view, struct buffer *buf, bool force_stop)
{
struct view_column *column = get_view_column(view, VIEW_COLUMN_DATE);
bool use_author_date = column && column->opt.date.use_author;
struct main_state *state = view->private;
struct graph *graph = state->graph;
enum line_type type;
Expand Down Expand Up @@ -510,16 +507,17 @@ main_read(struct view *view, struct buffer *buf, bool force_stop)
break;

case LINE_AUTHOR:
parse_author_line(line + STRING_SIZE("author "),
&commit->author, use_author_date ? &commit->time : NULL);
if (state->with_graph)
graph->render_parents(graph, &commit->graph);
break;

case LINE_COMMITTER:
parse_author_line(line + STRING_SIZE("committer "),
NULL, use_author_date ? NULL : &commit->time);
{
bool committer_line = (type == LINE_COMMITTER);
if ((state->optcom.author_as_committer ^ committer_line) == 0)
parse_author_line(line +
(committer_line ? STRING_SIZE("committer ") : STRING_SIZE("author ")),
&commit->author, &commit->time);
if (committer_line && state->with_graph)
graph->render_parents(graph, &commit->graph);
break;
}

default:
/* Fill in the commit title if it has not already been set. */
Expand Down
Loading