* [PATCH v3] log: add log.follow config option
@ 2015-07-07 22:12 David Turner
2015-07-08 7:40 ` Matthieu Moy
0 siblings, 1 reply; 3+ messages in thread
From: David Turner @ 2015-07-07 22:12 UTC (permalink / raw)
To: git; +Cc: David Turner
Many users prefer to always use --follow with logs. Rather than
aliasing the command, an option might be more convenient for some.
Signed-off-by: David Turner <dturner@twopensource.com>
---
Documentation/git-log.txt | 6 ++++++
builtin/log.c | 7 +++++++
diff.c | 5 +++--
diff.h | 1 +
revision.c | 14 +++++++++++---
t/t4202-log.sh | 23 +++++++++++++++++++++++
6 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index 5692945..79bf4d4 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -184,6 +184,12 @@ log.date::
`--date` option.) Defaults to "default", which means to write
dates like `Sat May 8 19:35:34 2010 -0500`.
+log.follow::
+ If a single file argument is given to git log, it will act as
+ if the `--follow` option was also used. This has the same
+ limitations as `--follow`, i.e. it cannot be used to follow
+ multiple files and does not work well on non-linear history.
+
log.showRoot::
If `false`, `git log` and related commands will not treat the
initial commit as a big creation event. Any root commits in
diff --git a/builtin/log.c b/builtin/log.c
index 8781049..6a068f7 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -31,6 +31,7 @@ static const char *default_date_mode = NULL;
static int default_abbrev_commit;
static int default_show_root = 1;
+static int default_follow;
static int decoration_style;
static int decoration_given;
static int use_mailmap_config;
@@ -102,6 +103,8 @@ static void cmd_log_init_defaults(struct rev_info *rev)
{
if (fmt_pretty)
get_commit_format(fmt_pretty, rev);
+ if (default_follow)
+ DIFF_OPT_SET(&rev->diffopt, DEFAULT_FOLLOW_RENAMES);
rev->verbose_header = 1;
DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
rev->diffopt.stat_width = -1; /* use full terminal width */
@@ -390,6 +393,10 @@ static int git_log_config(const char *var, const char *value, void *cb)
default_show_root = git_config_bool(var, value);
return 0;
}
+ if (!strcmp(var, "log.follow")) {
+ default_follow = git_config_bool(var, value);
+ return 0;
+ }
if (skip_prefix(var, "color.decorate.", &slot_name))
return parse_decorate_color_config(var, slot_name, value);
if (!strcmp(var, "log.mailmap")) {
diff --git a/diff.c b/diff.c
index 87b16d5..135b222 100644
--- a/diff.c
+++ b/diff.c
@@ -3815,9 +3815,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
DIFF_OPT_SET(options, FIND_COPIES_HARDER);
else if (!strcmp(arg, "--follow"))
DIFF_OPT_SET(options, FOLLOW_RENAMES);
- else if (!strcmp(arg, "--no-follow"))
+ else if (!strcmp(arg, "--no-follow")) {
DIFF_OPT_CLR(options, FOLLOW_RENAMES);
- else if (!strcmp(arg, "--color"))
+ DIFF_OPT_CLR(options, DEFAULT_FOLLOW_RENAMES);
+ } else if (!strcmp(arg, "--color"))
options->use_color = 1;
else if (skip_prefix(arg, "--color=", &arg)) {
int value = git_config_colorbool(NULL, arg);
diff --git a/diff.h b/diff.h
index c7ad42a..f7208ad 100644
--- a/diff.h
+++ b/diff.h
@@ -91,6 +91,7 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
#define DIFF_OPT_DIRSTAT_BY_LINE (1 << 28)
#define DIFF_OPT_FUNCCONTEXT (1 << 29)
#define DIFF_OPT_PICKAXE_IGNORE_CASE (1 << 30)
+#define DIFF_OPT_DEFAULT_FOLLOW_RENAMES (1 << 31)
#define DIFF_OPT_TST(opts, flag) ((opts)->flags & DIFF_OPT_##flag)
#define DIFF_OPT_TOUCHED(opts, flag) ((opts)->touched_flags & DIFF_OPT_##flag)
diff --git a/revision.c b/revision.c
index 3ff8723..5b0c2be 100644
--- a/revision.c
+++ b/revision.c
@@ -2322,12 +2322,20 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
if (revs->prune_data.nr) {
copy_pathspec(&revs->pruning.pathspec, &revs->prune_data);
- /* Can't prune commits with rename following: the paths change.. */
- if (!DIFF_OPT_TST(&revs->diffopt, FOLLOW_RENAMES))
- revs->prune = 1;
+
if (!revs->full_diff)
copy_pathspec(&revs->diffopt.pathspec,
&revs->prune_data);
+
+ if (DIFF_OPT_TST(&revs->diffopt, DEFAULT_FOLLOW_RENAMES) &&
+ revs->diffopt.pathspec.nr == 1)
+ DIFF_OPT_SET(&revs->diffopt, FOLLOW_RENAMES);
+
+ /* Can't prune commits with rename following: the paths change.. */
+ if (!DIFF_OPT_TST(&revs->diffopt, FOLLOW_RENAMES))
+ revs->prune = 1;
+ else
+ revs->diff = 1;
}
if (revs->combine_merges)
revs->ignore_merges = 0;
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 1b2e981..dbabbc3 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -146,7 +146,30 @@ test_expect_success 'git log --follow' '
actual=$(git log --follow --pretty="format:%s" ichi) &&
expect=$(echo third ; echo second ; echo initial) &&
verbose test "$actual" = "$expect"
+'
+
+test_expect_success 'git config log.follow works like --follow' '
+ test_config log.follow true &&
+ actual=$(git log --pretty="format:%s" ichi) &&
+ expect=$(echo third ; echo second ; echo initial) &&
+ verbose test "$actual" = "$expect"
+'
+test_expect_success 'git config log.follow does not die with multiple paths' '
+ test_config log.follow true &&
+ git log --pretty="format:%s" ichi ein
+'
+
+test_expect_success 'git config log.follow does not die with no paths' '
+ test_config log.follow true &&
+ git log --
+'
+
+test_expect_success 'git config log.follow is overridden by --no-follow' '
+ test_config log.follow true &&
+ actual=$(git log --no-follow --pretty="format:%s" ichi) &&
+ expect="third" &&
+ verbose test "$actual" = "$expect"
'
cat > expect << EOF
--
2.0.5.499.g01f6352.dirty-twtrsrc
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v3] log: add log.follow config option
@ 2015-07-08 1:29 David Turner
0 siblings, 0 replies; 3+ messages in thread
From: David Turner @ 2015-07-08 1:29 UTC (permalink / raw)
To: git; +Cc: David Turner
Many users prefer to always use --follow with logs. Rather than
aliasing the command, an option might be more convenient for some.
Signed-off-by: David Turner <dturner@twopensource.com>
---
Documentation/git-log.txt | 6 ++++++
builtin/log.c | 7 +++++++
diff.c | 5 +++--
diff.h | 1 +
revision.c | 17 +++++++++++------
t/t4202-log.sh | 23 +++++++++++++++++++++++
6 files changed, 51 insertions(+), 8 deletions(-)
diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index 5692945..79bf4d4 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -184,6 +184,12 @@ log.date::
`--date` option.) Defaults to "default", which means to write
dates like `Sat May 8 19:35:34 2010 -0500`.
+log.follow::
+ If a single file argument is given to git log, it will act as
+ if the `--follow` option was also used. This has the same
+ limitations as `--follow`, i.e. it cannot be used to follow
+ multiple files and does not work well on non-linear history.
+
log.showRoot::
If `false`, `git log` and related commands will not treat the
initial commit as a big creation event. Any root commits in
diff --git a/builtin/log.c b/builtin/log.c
index 8781049..6a068f7 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -31,6 +31,7 @@ static const char *default_date_mode = NULL;
static int default_abbrev_commit;
static int default_show_root = 1;
+static int default_follow;
static int decoration_style;
static int decoration_given;
static int use_mailmap_config;
@@ -102,6 +103,8 @@ static void cmd_log_init_defaults(struct rev_info *rev)
{
if (fmt_pretty)
get_commit_format(fmt_pretty, rev);
+ if (default_follow)
+ DIFF_OPT_SET(&rev->diffopt, DEFAULT_FOLLOW_RENAMES);
rev->verbose_header = 1;
DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
rev->diffopt.stat_width = -1; /* use full terminal width */
@@ -390,6 +393,10 @@ static int git_log_config(const char *var, const char *value, void *cb)
default_show_root = git_config_bool(var, value);
return 0;
}
+ if (!strcmp(var, "log.follow")) {
+ default_follow = git_config_bool(var, value);
+ return 0;
+ }
if (skip_prefix(var, "color.decorate.", &slot_name))
return parse_decorate_color_config(var, slot_name, value);
if (!strcmp(var, "log.mailmap")) {
diff --git a/diff.c b/diff.c
index 87b16d5..135b222 100644
--- a/diff.c
+++ b/diff.c
@@ -3815,9 +3815,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
DIFF_OPT_SET(options, FIND_COPIES_HARDER);
else if (!strcmp(arg, "--follow"))
DIFF_OPT_SET(options, FOLLOW_RENAMES);
- else if (!strcmp(arg, "--no-follow"))
+ else if (!strcmp(arg, "--no-follow")) {
DIFF_OPT_CLR(options, FOLLOW_RENAMES);
- else if (!strcmp(arg, "--color"))
+ DIFF_OPT_CLR(options, DEFAULT_FOLLOW_RENAMES);
+ } else if (!strcmp(arg, "--color"))
options->use_color = 1;
else if (skip_prefix(arg, "--color=", &arg)) {
int value = git_config_colorbool(NULL, arg);
diff --git a/diff.h b/diff.h
index c7ad42a..f7208ad 100644
--- a/diff.h
+++ b/diff.h
@@ -91,6 +91,7 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
#define DIFF_OPT_DIRSTAT_BY_LINE (1 << 28)
#define DIFF_OPT_FUNCCONTEXT (1 << 29)
#define DIFF_OPT_PICKAXE_IGNORE_CASE (1 << 30)
+#define DIFF_OPT_DEFAULT_FOLLOW_RENAMES (1 << 31)
#define DIFF_OPT_TST(opts, flag) ((opts)->flags & DIFF_OPT_##flag)
#define DIFF_OPT_TOUCHED(opts, flag) ((opts)->touched_flags & DIFF_OPT_##flag)
diff --git a/revision.c b/revision.c
index 3ff8723..7c1931b 100644
--- a/revision.c
+++ b/revision.c
@@ -2311,15 +2311,13 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
if (revs->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT)
revs->diff = 1;
- /* Pickaxe, diff-filter and rename following need diffs */
- if (revs->diffopt.pickaxe ||
- revs->diffopt.filter ||
- DIFF_OPT_TST(&revs->diffopt, FOLLOW_RENAMES))
- revs->diff = 1;
-
if (revs->topo_order)
revs->limited = 1;
+ if (DIFF_OPT_TST(&revs->diffopt, DEFAULT_FOLLOW_RENAMES) &&
+ revs->prune_data.nr == 1)
+ DIFF_OPT_SET(&revs->diffopt, FOLLOW_RENAMES);
+
if (revs->prune_data.nr) {
copy_pathspec(&revs->pruning.pathspec, &revs->prune_data);
/* Can't prune commits with rename following: the paths change.. */
@@ -2329,6 +2327,13 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
copy_pathspec(&revs->diffopt.pathspec,
&revs->prune_data);
}
+
+ /* Pickaxe, diff-filter and rename following need diffs */
+ if (revs->diffopt.pickaxe ||
+ revs->diffopt.filter ||
+ DIFF_OPT_TST(&revs->diffopt, FOLLOW_RENAMES))
+ revs->diff = 1;
+
if (revs->combine_merges)
revs->ignore_merges = 0;
revs->diffopt.abbrev = revs->abbrev;
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 1b2e981..dbabbc3 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -146,7 +146,30 @@ test_expect_success 'git log --follow' '
actual=$(git log --follow --pretty="format:%s" ichi) &&
expect=$(echo third ; echo second ; echo initial) &&
verbose test "$actual" = "$expect"
+'
+
+test_expect_success 'git config log.follow works like --follow' '
+ test_config log.follow true &&
+ actual=$(git log --pretty="format:%s" ichi) &&
+ expect=$(echo third ; echo second ; echo initial) &&
+ verbose test "$actual" = "$expect"
+'
+test_expect_success 'git config log.follow does not die with multiple paths' '
+ test_config log.follow true &&
+ git log --pretty="format:%s" ichi ein
+'
+
+test_expect_success 'git config log.follow does not die with no paths' '
+ test_config log.follow true &&
+ git log --
+'
+
+test_expect_success 'git config log.follow is overridden by --no-follow' '
+ test_config log.follow true &&
+ actual=$(git log --no-follow --pretty="format:%s" ichi) &&
+ expect="third" &&
+ verbose test "$actual" = "$expect"
'
cat > expect << EOF
--
2.0.5.499.g01f6352.dirty-twtrsrc
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] log: add log.follow config option
2015-07-07 22:12 David Turner
@ 2015-07-08 7:40 ` Matthieu Moy
0 siblings, 0 replies; 3+ messages in thread
From: Matthieu Moy @ 2015-07-08 7:40 UTC (permalink / raw)
To: David Turner; +Cc: git
[ Note: as much as possible, Cc the reviewers of the previous rounds
when you send a new version ]
David Turner <dturner@twopensource.com> writes:
> +test_expect_success 'git config log.follow is overridden by --no-follow' '
nitpick: two spaces after test_expect_success.
With or without the whitespace fix, the patch looks good to me. I'm not
sure it fully addresses Junio's concern about v2 though.
Thanks,
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-07-08 7:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-08 1:29 [PATCH v3] log: add log.follow config option David Turner
-- strict thread matches above, loose matches on Subject: below --
2015-07-07 22:12 David Turner
2015-07-08 7:40 ` Matthieu Moy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).