зеркало из https://github.com/microsoft/git.git
Merge branch 'so/log-m-implies-p'
The "-m" option in "git log -m" that does not specify which format, if any, of diff is desired did not have any visible effect; it now implies some form of diff (by default "--patch") is produced. * so/log-m-implies-p: diff-merges: let "-m" imply "-p" diff-merges: rename "combined_imply_patch" to "merges_imply_patch" stash list: stop passing "-m" to "git log" git-svn: stop passing "-m" to "git rev-list" diff-merges: move specific diff-index "-m" handling to diff-index t4013: test "git diff-index -m" t4013: test "git diff-tree -m" t4013: test "git log -m --stat" t4013: test "git log -m --raw" t4013: test that "-m" alone has no effect in "git log"
This commit is contained in:
Коммит
8e444e66df
|
@ -49,10 +49,9 @@ ifdef::git-log[]
|
|||
--diff-merges=m:::
|
||||
-m:::
|
||||
This option makes diff output for merge commits to be shown in
|
||||
the default format. `-m` will produce the output only if `-p`
|
||||
is given as well. The default format could be changed using
|
||||
the default format. The default format could be changed using
|
||||
`log.diffMerges` configuration parameter, which default value
|
||||
is `separate`.
|
||||
is `separate`. `-m` implies `-p`.
|
||||
+
|
||||
--diff-merges=first-parent:::
|
||||
--diff-merges=1:::
|
||||
|
@ -62,7 +61,8 @@ ifdef::git-log[]
|
|||
--diff-merges=separate:::
|
||||
This makes merge commits show the full diff with respect to
|
||||
each of the parents. Separate log entry and diff is generated
|
||||
for each parent.
|
||||
for each parent. This is the format that `-m` produced
|
||||
historically.
|
||||
+
|
||||
--diff-merges=combined:::
|
||||
--diff-merges=c:::
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "cache.h"
|
||||
#include "config.h"
|
||||
#include "diff.h"
|
||||
#include "diff-merges.h"
|
||||
#include "commit.h"
|
||||
#include "revision.h"
|
||||
#include "builtin.h"
|
||||
|
@ -27,6 +28,12 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
|
|||
rev.abbrev = 0;
|
||||
prefix = precompose_argv_prefix(argc, argv, prefix);
|
||||
|
||||
/*
|
||||
* We need no diff for merges options, and we need to avoid conflict
|
||||
* with our own meaning of "-m".
|
||||
*/
|
||||
diff_merges_suppress_options_parsing();
|
||||
|
||||
argc = setup_revisions(argc, argv, &rev, NULL);
|
||||
for (i = 1; i < argc; i++) {
|
||||
const char *arg = argv[i];
|
||||
|
@ -35,6 +42,8 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
|
|||
option |= DIFF_INDEX_CACHED;
|
||||
else if (!strcmp(arg, "--merge-base"))
|
||||
option |= DIFF_INDEX_MERGE_BASE;
|
||||
else if (!strcmp(arg, "-m"))
|
||||
rev.match_missing = 1;
|
||||
else
|
||||
usage(diff_cache_usage);
|
||||
}
|
||||
|
|
|
@ -761,7 +761,7 @@ static int list_stash(int argc, const char **argv, const char *prefix)
|
|||
|
||||
cp.git_cmd = 1;
|
||||
strvec_pushl(&cp.args, "log", "--format=%gd: %gs", "-g",
|
||||
"--first-parent", "-m", NULL);
|
||||
"--first-parent", NULL);
|
||||
strvec_pushv(&cp.args, argv);
|
||||
strvec_push(&cp.args, ref_stash);
|
||||
strvec_push(&cp.args, "--");
|
||||
|
|
|
@ -6,6 +6,7 @@ typedef void (*diff_merges_setup_func_t)(struct rev_info *);
|
|||
static void set_separate(struct rev_info *revs);
|
||||
|
||||
static diff_merges_setup_func_t set_to_default = set_separate;
|
||||
static int suppress_parsing;
|
||||
|
||||
static void suppress(struct rev_info *revs)
|
||||
{
|
||||
|
@ -14,7 +15,7 @@ static void suppress(struct rev_info *revs)
|
|||
revs->combine_merges = 0;
|
||||
revs->dense_combined_merges = 0;
|
||||
revs->combined_all_paths = 0;
|
||||
revs->combined_imply_patch = 0;
|
||||
revs->merges_imply_patch = 0;
|
||||
revs->merges_need_diff = 0;
|
||||
}
|
||||
|
||||
|
@ -30,17 +31,6 @@ static void set_first_parent(struct rev_info *revs)
|
|||
revs->first_parent_merges = 1;
|
||||
}
|
||||
|
||||
static void set_m(struct rev_info *revs)
|
||||
{
|
||||
/*
|
||||
* To "diff-index", "-m" means "match missing", and to the "log"
|
||||
* family of commands, it means "show default diff for merges". Set
|
||||
* both fields appropriately.
|
||||
*/
|
||||
set_to_default(revs);
|
||||
revs->match_missing = 1;
|
||||
}
|
||||
|
||||
static void set_combined(struct rev_info *revs)
|
||||
{
|
||||
suppress(revs);
|
||||
|
@ -101,20 +91,29 @@ int diff_merges_config(const char *value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void diff_merges_suppress_options_parsing(void)
|
||||
{
|
||||
suppress_parsing = 1;
|
||||
}
|
||||
|
||||
int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
|
||||
{
|
||||
int argcount = 1;
|
||||
const char *optarg;
|
||||
const char *arg = argv[0];
|
||||
|
||||
if (suppress_parsing)
|
||||
return 0;
|
||||
|
||||
if (!strcmp(arg, "-m")) {
|
||||
set_m(revs);
|
||||
set_to_default(revs);
|
||||
revs->merges_imply_patch = 1;
|
||||
} else if (!strcmp(arg, "-c")) {
|
||||
set_combined(revs);
|
||||
revs->combined_imply_patch = 1;
|
||||
revs->merges_imply_patch = 1;
|
||||
} else if (!strcmp(arg, "--cc")) {
|
||||
set_dense_combined(revs);
|
||||
revs->combined_imply_patch = 1;
|
||||
revs->merges_imply_patch = 1;
|
||||
} else if (!strcmp(arg, "--no-diff-merges")) {
|
||||
suppress(revs);
|
||||
} else if (!strcmp(arg, "--combined-all-paths")) {
|
||||
|
@ -155,15 +154,18 @@ void diff_merges_set_dense_combined_if_unset(struct rev_info *revs)
|
|||
|
||||
void diff_merges_setup_revs(struct rev_info *revs)
|
||||
{
|
||||
if (suppress_parsing)
|
||||
return;
|
||||
|
||||
if (revs->combine_merges == 0)
|
||||
revs->dense_combined_merges = 0;
|
||||
if (revs->separate_merges == 0)
|
||||
revs->first_parent_merges = 0;
|
||||
if (revs->combined_all_paths && !revs->combine_merges)
|
||||
die("--combined-all-paths makes no sense without -c or --cc");
|
||||
if (revs->combined_imply_patch)
|
||||
if (revs->merges_imply_patch)
|
||||
revs->diff = 1;
|
||||
if (revs->combined_imply_patch || revs->merges_need_diff) {
|
||||
if (revs->merges_imply_patch || revs->merges_need_diff) {
|
||||
if (!revs->diffopt.output_format)
|
||||
revs->diffopt.output_format = DIFF_FORMAT_PATCH;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ struct rev_info;
|
|||
|
||||
int diff_merges_config(const char *value);
|
||||
|
||||
void diff_merges_suppress_options_parsing(void);
|
||||
|
||||
int diff_merges_parse_opts(struct rev_info *revs, const char **argv);
|
||||
|
||||
void diff_merges_suppress(struct rev_info *revs);
|
||||
|
|
|
@ -1636,7 +1636,7 @@ sub has_no_changes {
|
|||
my $commit = shift;
|
||||
|
||||
my @revs = split / /, command_oneline(
|
||||
qw(rev-list --parents -1 -m), $commit);
|
||||
qw(rev-list --parents -1), $commit);
|
||||
|
||||
# Commits with no parents, e.g. the start of a partial branch,
|
||||
# have changes by definition.
|
||||
|
|
|
@ -193,10 +193,10 @@ struct rev_info {
|
|||
/* Diff-merge flags */
|
||||
explicit_diff_merges: 1,
|
||||
merges_need_diff: 1,
|
||||
merges_imply_patch:1,
|
||||
separate_merges: 1,
|
||||
combine_merges:1,
|
||||
combined_all_paths:1,
|
||||
combined_imply_patch:1,
|
||||
dense_combined_merges:1,
|
||||
first_parent_merges:1;
|
||||
|
||||
|
|
|
@ -859,7 +859,7 @@ test_expect_success 'setup stash with index and worktree changes' '
|
|||
git stash
|
||||
'
|
||||
|
||||
test_expect_success 'stash list implies --first-parent -m' '
|
||||
test_expect_success 'stash list -p shows simple diff' '
|
||||
cat >expect <<-EOF &&
|
||||
stash@{0}
|
||||
|
||||
|
|
|
@ -293,6 +293,7 @@ diff-tree --stat initial mode
|
|||
diff-tree --summary initial mode
|
||||
|
||||
diff-tree master
|
||||
diff-tree -m master
|
||||
diff-tree -p master
|
||||
diff-tree -p -m master
|
||||
diff-tree -c master
|
||||
|
@ -337,6 +338,8 @@ log -m -p --first-parent master
|
|||
log -m -p master
|
||||
log --cc -m -p master
|
||||
log -c -m -p master
|
||||
log -m --raw master
|
||||
log -m --stat master
|
||||
log -SF master
|
||||
log -S F master
|
||||
log -SF -p master
|
||||
|
@ -452,6 +455,14 @@ diff-tree --stat --compact-summary initial mode
|
|||
diff-tree -R --stat --compact-summary initial mode
|
||||
EOF
|
||||
|
||||
test_expect_success 'log -m matches log -m -p' '
|
||||
git log -m -p master >result &&
|
||||
process_diffs result >expected &&
|
||||
git log -m >result &&
|
||||
process_diffs result >actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success 'log --diff-merges=on matches --diff-merges=separate' '
|
||||
git log -p --diff-merges=separate master >result &&
|
||||
process_diffs result >expected &&
|
||||
|
@ -483,6 +494,19 @@ test_expect_success 'git config log.diffMerges first-parent vs -m' '
|
|||
test_cmp expected actual
|
||||
'
|
||||
|
||||
# -m in "git diff-index" means "match missing", that differs
|
||||
# from its meaning in "git diff". Let's check it in diff-index.
|
||||
# The line in the output for removed file should disappear when
|
||||
# we provide -m in diff-index.
|
||||
test_expect_success 'git diff-index -m' '
|
||||
rm -f file1 &&
|
||||
git diff-index HEAD >without-m &&
|
||||
lines_count=$(wc -l <without-m) &&
|
||||
git diff-index -m HEAD >with-m &&
|
||||
git restore file1 &&
|
||||
test_line_count = $((lines_count - 1)) with-m
|
||||
'
|
||||
|
||||
test_expect_success 'log -S requires an argument' '
|
||||
test_must_fail git log -S
|
||||
'
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
$ git diff-tree -m master
|
||||
59d314ad6f356dd08601a4cd5e530381da3e3c64
|
||||
:040000 040000 65f5c9dd60ce3b2b3324b618ac7accf8d912c113 0564e026437809817a64fff393079714b6dd4628 M dir
|
||||
:100644 100644 b414108e81e5091fe0974a1858b4d0d22b107f70 10a8a9f3657f91a156b9f0184ed79a20adef9f7f M file0
|
||||
59d314ad6f356dd08601a4cd5e530381da3e3c64
|
||||
:040000 040000 f977ed46ae6873c1c30ab878e15a4accedc3618b 0564e026437809817a64fff393079714b6dd4628 M dir
|
||||
:100644 100644 f4615da674c09df322d6ba8d6b21ecfb1b1ba510 10a8a9f3657f91a156b9f0184ed79a20adef9f7f M file0
|
||||
:000000 100644 0000000000000000000000000000000000000000 b1e67221afe8461efd244b487afca22d46b95eb8 A file1
|
||||
:100644 000000 01e79c32a8c99c557f0757da7cb6d65b3414466d 0000000000000000000000000000000000000000 D file2
|
||||
:100644 000000 7289e35bff32727c08dda207511bec138fdb9ea5 0000000000000000000000000000000000000000 D file3
|
||||
$
|
|
@ -0,0 +1,61 @@
|
|||
$ git log -m --raw master
|
||||
commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (from 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0)
|
||||
Merge: 9a6d494 c7a2ab9
|
||||
Author: A U Thor <author@example.com>
|
||||
Date: Mon Jun 26 00:04:00 2006 +0000
|
||||
|
||||
Merge branch 'side'
|
||||
|
||||
:100644 100644 cead32e... 992913c... M dir/sub
|
||||
:100644 100644 b414108... 10a8a9f... M file0
|
||||
|
||||
commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (from c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a)
|
||||
Merge: 9a6d494 c7a2ab9
|
||||
Author: A U Thor <author@example.com>
|
||||
Date: Mon Jun 26 00:04:00 2006 +0000
|
||||
|
||||
Merge branch 'side'
|
||||
|
||||
:100644 100644 7289e35... 992913c... M dir/sub
|
||||
:100644 100644 f4615da... 10a8a9f... M file0
|
||||
:000000 100644 0000000... b1e6722... A file1
|
||||
:100644 000000 01e79c3... 0000000... D file2
|
||||
:100644 000000 7289e35... 0000000... D file3
|
||||
|
||||
commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a
|
||||
Author: A U Thor <author@example.com>
|
||||
Date: Mon Jun 26 00:03:00 2006 +0000
|
||||
|
||||
Side
|
||||
|
||||
:100644 100644 35d242b... 7289e35... M dir/sub
|
||||
:100644 100644 01e79c3... f4615da... M file0
|
||||
:000000 100644 0000000... 7289e35... A file3
|
||||
|
||||
commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
|
||||
Author: A U Thor <author@example.com>
|
||||
Date: Mon Jun 26 00:02:00 2006 +0000
|
||||
|
||||
Third
|
||||
|
||||
:100644 100644 8422d40... cead32e... M dir/sub
|
||||
:000000 100644 0000000... b1e6722... A file1
|
||||
|
||||
commit 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44
|
||||
Author: A U Thor <author@example.com>
|
||||
Date: Mon Jun 26 00:01:00 2006 +0000
|
||||
|
||||
Second
|
||||
|
||||
This is the second commit.
|
||||
|
||||
:100644 100644 35d242b... 8422d40... M dir/sub
|
||||
:100644 100644 01e79c3... b414108... M file0
|
||||
:100644 000000 01e79c3... 0000000... D file2
|
||||
|
||||
commit 444ac553ac7612cc88969031b02b3767fb8a353a
|
||||
Author: A U Thor <author@example.com>
|
||||
Date: Mon Jun 26 00:00:00 2006 +0000
|
||||
|
||||
Initial
|
||||
$
|
|
@ -0,0 +1,66 @@
|
|||
$ git log -m --stat master
|
||||
commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (from 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0)
|
||||
Merge: 9a6d494 c7a2ab9
|
||||
Author: A U Thor <author@example.com>
|
||||
Date: Mon Jun 26 00:04:00 2006 +0000
|
||||
|
||||
Merge branch 'side'
|
||||
|
||||
dir/sub | 2 ++
|
||||
file0 | 3 +++
|
||||
2 files changed, 5 insertions(+)
|
||||
|
||||
commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (from c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a)
|
||||
Merge: 9a6d494 c7a2ab9
|
||||
Author: A U Thor <author@example.com>
|
||||
Date: Mon Jun 26 00:04:00 2006 +0000
|
||||
|
||||
Merge branch 'side'
|
||||
|
||||
dir/sub | 4 ++++
|
||||
file0 | 3 +++
|
||||
file1 | 3 +++
|
||||
file2 | 3 ---
|
||||
file3 | 4 ----
|
||||
5 files changed, 10 insertions(+), 7 deletions(-)
|
||||
|
||||
commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a
|
||||
Author: A U Thor <author@example.com>
|
||||
Date: Mon Jun 26 00:03:00 2006 +0000
|
||||
|
||||
Side
|
||||
|
||||
dir/sub | 2 ++
|
||||
file0 | 3 +++
|
||||
file3 | 4 ++++
|
||||
3 files changed, 9 insertions(+)
|
||||
|
||||
commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
|
||||
Author: A U Thor <author@example.com>
|
||||
Date: Mon Jun 26 00:02:00 2006 +0000
|
||||
|
||||
Third
|
||||
|
||||
dir/sub | 2 ++
|
||||
file1 | 3 +++
|
||||
2 files changed, 5 insertions(+)
|
||||
|
||||
commit 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44
|
||||
Author: A U Thor <author@example.com>
|
||||
Date: Mon Jun 26 00:01:00 2006 +0000
|
||||
|
||||
Second
|
||||
|
||||
This is the second commit.
|
||||
|
||||
dir/sub | 2 ++
|
||||
file0 | 3 +++
|
||||
file2 | 3 ---
|
||||
3 files changed, 5 insertions(+), 3 deletions(-)
|
||||
|
||||
commit 444ac553ac7612cc88969031b02b3767fb8a353a
|
||||
Author: A U Thor <author@example.com>
|
||||
Date: Mon Jun 26 00:00:00 2006 +0000
|
||||
|
||||
Initial
|
||||
$
|
Загрузка…
Ссылка в новой задаче