summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 32962c9)
raw | patch | inline | side by side (parent: 32962c9)
author | Junio C Hamano <gitster@pobox.com> | |
Tue, 9 Mar 2010 07:27:25 +0000 (23:27 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 9 Mar 2010 09:11:18 +0000 (01:11 -0800) |
Traditionally, "show" defaulted to "show --cc" (dense combined patch), but
asking for combined patch with "show -c" didn't turn the patch output
format on; the placement of this logic in setup_revisions() dates back to
cd2bdc5 (Common option parsing for "git log --diff" and friends,
2006-04-14).
This unfortunately cannot be done as a trivial change of "if dense
combined is asked, default to patch format" done in setup_revisions() to
"if any combined is asked, default to patch format", as "diff-tree -c"
needs to default to raw, while "diff-tree --cc" needs to default to patch,
and they share the codepath. These command specific defaults are now
handled in the new "tweak" callback that can be customized by individual
command implementations.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
asking for combined patch with "show -c" didn't turn the patch output
format on; the placement of this logic in setup_revisions() dates back to
cd2bdc5 (Common option parsing for "git log --diff" and friends,
2006-04-14).
This unfortunately cannot be done as a trivial change of "if dense
combined is asked, default to patch format" done in setup_revisions() to
"if any combined is asked, default to patch format", as "diff-tree -c"
needs to default to raw, while "diff-tree --cc" needs to default to patch,
and they share the codepath. These command specific defaults are now
handled in the new "tweak" callback that can be customized by individual
command implementations.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-diff-tree.c | patch | blob | history | |
builtin-log.c | patch | blob | history | |
revision.c | patch | blob | history | |
revision.h | patch | blob | history | |
t/t4013-diff-various.sh | patch | blob | history | |
t/t4013/diff.show_-c_master | [new file with mode: 0644] | patch | blob |
diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c
index 2380c21951fb5fb8050ab1acf0e7f01f36ea5520..3c78bda5664e20086bcd500105b039d6241e3782 100644 (file)
--- a/builtin-diff-tree.c
+++ b/builtin-diff-tree.c
" --root include the initial commit as diff against /dev/null\n"
COMMON_DIFF_OPTIONS_HELP;
+static void diff_tree_tweak_rev(struct rev_info *rev, struct setup_revision_opt *opt)
+{
+ if (!rev->diffopt.output_format) {
+ if (rev->dense_combined_merges)
+ rev->diffopt.output_format = DIFF_FORMAT_PATCH;
+ else
+ rev->diffopt.output_format = DIFF_FORMAT_RAW;
+ }
+}
+
int cmd_diff_tree(int argc, const char **argv, const char *prefix)
{
int nr_sha1;
char line[1000];
struct object *tree1, *tree2;
static struct rev_info *opt = &log_tree_opt;
+ struct setup_revision_opt s_r_opt;
int read_stdin = 0;
init_revisions(opt, prefix);
opt->abbrev = 0;
opt->diff = 1;
opt->disable_stdin = 1;
- argc = setup_revisions(argc, argv, opt, NULL);
+ memset(&s_r_opt, 0, sizeof(s_r_opt));
+ s_r_opt.tweak = diff_tree_tweak_rev;
+ argc = setup_revisions(argc, argv, opt, &s_r_opt);
while (--argc > 0) {
const char *arg = *++argv;
usage(diff_tree_usage);
}
- if (!opt->diffopt.output_format)
- opt->diffopt.output_format = DIFF_FORMAT_RAW;
-
/*
* NOTE! We expect "a ^b" to be equal to "a..b", so we
* reverse the order of the objects if the second one
diff --git a/builtin-log.c b/builtin-log.c
index dfbf6f22d0b8dec9416988dfc7be4a2d6e7b748a..ab5f60c9e260a7377ce1b32efba79bcb23954fb0 100644 (file)
--- a/builtin-log.c
+++ b/builtin-log.c
return 0;
}
+static void show_rev_tweak_rev(struct rev_info *rev, struct setup_revision_opt *opt)
+{
+ if (!rev->diffopt.output_format)
+ rev->diffopt.output_format = DIFF_FORMAT_PATCH;
+}
+
int cmd_show(int argc, const char **argv, const char *prefix)
{
struct rev_info rev;
rev.no_walk = 1;
memset(&opt, 0, sizeof(opt));
opt.def = "HEAD";
+ opt.tweak = show_rev_tweak_rev;
cmd_log_init(argc, argv, prefix, &rev, &opt);
count = rev.pending.nr;
diff --git a/revision.c b/revision.c
index 25c1bbb9a6146accf30b555434a3eaefcef6f7be..2ddbb5086806a5b832caa9e14ffb1f326cd77c38 100644 (file)
--- a/revision.c
+++ b/revision.c
@@ -1463,6 +1463,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
if (revs->def == NULL)
revs->def = opt ? opt->def : NULL;
+ if (opt && opt->tweak)
+ opt->tweak(revs, opt);
if (revs->show_merge)
prepare_show_merge(revs);
if (revs->def && !revs->pending.nr) {
@@ -1496,11 +1498,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
if (!revs->full_diff)
diff_tree_setup_paths(revs->prune_data, &revs->diffopt);
}
- if (revs->combine_merges) {
+ if (revs->combine_merges)
revs->ignore_merges = 0;
- if (revs->dense_combined_merges && !revs->diffopt.output_format)
- revs->diffopt.output_format = DIFF_FORMAT_PATCH;
- }
revs->diffopt.abbrev = revs->abbrev;
if (diff_setup_done(&revs->diffopt) < 0)
die("diff_setup_done failed");
diff --git a/revision.h b/revision.h
index fcc0de8eea9e0b6c14966b8a10f35e9c4be35de9..ceae4cae74da38860ab3adcea39385e7f3f6a1fd 100644 (file)
--- a/revision.h
+++ b/revision.h
struct setup_revision_opt {
const char *def;
+ void (*tweak)(struct rev_info *, struct setup_revision_opt *);
};
extern void init_revisions(struct rev_info *revs, const char *prefix);
index 68cb651645fd5b867d08ccd93e5db8755411eb10..8dd93d9a19234e67f1a995f54cb221462923cb4d 100755 (executable)
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
show --root initial
show side
show master
+show -c master
show --stat side
show --stat --summary side
show --patch-with-stat side
diff --git a/t/t4013/diff.show_-c_master b/t/t4013/diff.show_-c_master
--- /dev/null
@@ -0,0 +1,36 @@
+$ git show -c master
+commit 59d314ad6f356dd08601a4cd5e530381da3e3c64
+Merge: 9a6d494 c7a2ab9
+Author: A U Thor <author@example.com>
+Date: Mon Jun 26 00:04:00 2006 +0000
+
+ Merge branch 'side'
+
+diff --combined dir/sub
+index cead32e,7289e35..992913c
+--- a/dir/sub
++++ b/dir/sub
+@@@ -1,6 -1,4 +1,8 @@@
+ A
+ B
+ +C
+ +D
+ +E
+ +F
++ 1
++ 2
+diff --combined file0
+index b414108,f4615da..10a8a9f
+--- a/file0
++++ b/file0
+@@@ -1,6 -1,6 +1,9 @@@
+ 1
+ 2
+ 3
+ +4
+ +5
+ +6
++ A
++ B
++ C
+$