From b68ea12e305043a7feef085b6ba098f42357af9b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 7 Jul 2006 04:01:23 -0700 Subject: diff.c: respect diff.renames config option diff.renames is mentioned several times in the documentation, but to my surprise it didn't do anything before this patch. Also add the --no-renames option to override this from the command-line. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- Documentation/config.txt | 5 +++++ diff.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index f075f1981..5290a8fd1 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -114,6 +114,11 @@ diff.renameLimit:: The number of files to consider when performing the copy/rename detection; equivalent to the git diff option '-l'. +diff.renames:: + Tells git to detect renames. If set to any boolean value, it + will enable basic rename detection. If set to "copies" or + "copy", it will detect copies, as well. + format.headers:: Additional email headers to include in a patch to be submitted by mail. See gitlink:git-format-patch[1]. diff --git a/diff.c b/diff.c index b423491f6..4bea3066a 100644 --- a/diff.c +++ b/diff.c @@ -13,6 +13,7 @@ static int use_size_cache; +static int diff_detect_rename_default = 0; static int diff_rename_limit_default = -1; static int diff_use_color_default = 0; @@ -120,6 +121,16 @@ int git_diff_config(const char *var, const char *value) diff_use_color_default = git_config_bool(var, value); return 0; } + if (!strcmp(var, "diff.renames")) { + if (!value) + diff_detect_rename_default = DIFF_DETECT_RENAME; + else if (!strcasecmp(value, "copies") || + !strcasecmp(value, "copy")) + diff_detect_rename_default = DIFF_DETECT_COPY; + else if (git_config_bool(var,value)) + diff_detect_rename_default = DIFF_DETECT_RENAME; + return 0; + } if (!strncmp(var, "diff.color.", 11)) { int slot = parse_diff_color_slot(var, 11); diff_colors[slot] = parse_diff_color_value(value, var); @@ -1431,6 +1442,7 @@ void diff_setup(struct diff_options *options) options->change = diff_change; options->add_remove = diff_addremove; options->color_diff = diff_use_color_default; + options->detect_rename = diff_detect_rename_default; } int diff_setup_done(struct diff_options *options) @@ -1617,6 +1629,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) options->xdl_opts |= XDF_IGNORE_WHITESPACE; else if (!strcmp(arg, "-b") || !strcmp(arg, "--ignore-space-change")) options->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE; + else if (!strcmp(arg, "--no-renames")) + options->detect_rename = 0; else return 0; return 1; -- cgit v1.2.1 From fef88bb0134dfd47b4bd17e668bbb860588dcb39 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 7 Jul 2006 05:27:24 -0700 Subject: diff.c: --no-color to defeat diff.color configuration. Signed-off-by: Junio C Hamano --- diff.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diff.c b/diff.c index 4bea3066a..1bf1ed096 100644 --- a/diff.c +++ b/diff.c @@ -1625,6 +1625,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) } else if (!strcmp(arg, "--color")) options->color_diff = 1; + else if (!strcmp(arg, "--no-color")) + options->color_diff = 0; else if (!strcmp(arg, "-w") || !strcmp(arg, "--ignore-all-space")) options->xdl_opts |= XDF_IGNORE_WHITESPACE; else if (!strcmp(arg, "-b") || !strcmp(arg, "--ignore-space-change")) -- cgit v1.2.1 From b53766483ff14f73be954617349b18ea56c3187a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 7 Jul 2006 05:28:05 -0700 Subject: Update diff-options and config documentation. Signed-off-by: Junio C Hamano --- Documentation/config.txt | 16 ++++++++++++++++ Documentation/diff-options.txt | 26 ++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 5290a8fd1..0b434c1f1 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -110,6 +110,22 @@ apply.whitespace:: Tells `git-apply` how to handle whitespaces, in the same way as the '--whitespace' option. See gitlink:git-apply[1]. +diff.color:: + When true (or `always`), always use colors in patch. + When false (or `never`), never. When set to `auto`, use + colors only when the output is to the terminal. + +diff.color.:: + Use customized color for diff colorization. `` + specifies which part of the patch to use the specified + color, and is one of `plain` (context text), `meta` + (metainformation), `frag` (hunk header), `old` (removed + lines), or `new` (added lines). The value for these + configuration variables can be one of: `normal`, `bold`, + `dim`, `ul`, `blink`, `reverse`, `reset`, `black`, + `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, or + `white`. + diff.renameLimit:: The number of files to consider when performing the copy/rename detection; equivalent to the git diff option '-l'. diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index 1a936295d..47ba9a403 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -4,18 +4,21 @@ -u:: Synonym for "-p". +--raw:: + Generate the raw format. + --patch-with-raw:: - Generate patch but keep also the default raw diff output. + Synonym for "-p --raw". --stat:: - Generate a diffstat instead of a patch. + Generate a diffstat. --summary:: Output a condensed summary of extended header information such as creations, renames and mode changes. --patch-with-stat:: - Generate patch and prepend its diffstat. + Synonym for "-p --stat". -z:: \0 line termination on output @@ -26,10 +29,25 @@ --name-status:: Show only names and status of changed files. +--color:: + Show colored diff. + +--no-color:: + Turn off colored diff, even when the configuration file + gives the default to color output. + +--no-renames:: + Turn off rename detection, even when the configuration + file gives the default to do so. + --full-index:: Instead of the first handful characters, show full object name of pre- and post-image blob on the "index" - line when generating a patch format output. + line when generating a patch format output. + +--binary:: + In addition to --full-index, output "binary diff" that + can be applied with "git apply". --abbrev[=]:: Instead of showing the full 40-byte hexadecimal object -- cgit v1.2.1 From 83ad63cfebdf652ff7c7b255d700d8b12c756913 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 8 Jul 2006 01:05:16 -0700 Subject: diff: do not use configuration magic at the core-level The Porcelainish has become so much usable as the UI that there is not much reason people should be using the core programs by hand anymore. At this point we are better off making the behaviour of the core programs predictable by keeping them unaffected by the configuration variables. Otherwise they will become very hard to use as reliable building blocks. For example, "git-commit -a" internally uses git-diff-files to figure out the set of paths that need to be updated in the index, and we should never allow diff.renames that happens to be in the configuration to interfere (or slow down the process). The UI level configuration such as showing renamed diff and coloring are still honored by the Porcelainish ("git log" family and "git diff"), but not by the core anymore. Signed-off-by: Junio C Hamano --- builtin-diff-files.c | 2 +- builtin-diff-index.c | 2 +- builtin-diff-stages.c | 2 +- builtin-diff-tree.c | 2 +- builtin-diff.c | 2 +- builtin-log.c | 8 ++++---- diff.c | 8 +++++++- diff.h | 2 +- 8 files changed, 17 insertions(+), 11 deletions(-) diff --git a/builtin-diff-files.c b/builtin-diff-files.c index a655eea91..81ac2fe64 100644 --- a/builtin-diff-files.c +++ b/builtin-diff-files.c @@ -18,7 +18,7 @@ int cmd_diff_files(int argc, const char **argv, char **envp) struct rev_info rev; int silent = 0; - git_config(git_diff_config); + git_config(git_default_config); /* no "diff" UI options */ init_revisions(&rev); rev.abbrev = 0; diff --git a/builtin-diff-index.c b/builtin-diff-index.c index b37c9e8cc..a1fa1b85c 100644 --- a/builtin-diff-index.c +++ b/builtin-diff-index.c @@ -15,7 +15,7 @@ int cmd_diff_index(int argc, const char **argv, char **envp) int cached = 0; int i; - git_config(git_diff_config); + git_config(git_default_config); /* no "diff" UI options */ init_revisions(&rev); rev.abbrev = 0; diff --git a/builtin-diff-stages.c b/builtin-diff-stages.c index 30931fe04..9c6270294 100644 --- a/builtin-diff-stages.c +++ b/builtin-diff-stages.c @@ -61,7 +61,7 @@ int cmd_diff_stages(int ac, const char **av, char **envp) const char *prefix = setup_git_directory(); const char **pathspec = NULL; - git_config(git_diff_config); + git_config(git_default_config); /* no "diff" UI options */ read_cache(); diff_setup(&diff_options); while (1 < ac && av[1][0] == '-') { diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c index ae1cde9d0..b61066859 100644 --- a/builtin-diff-tree.c +++ b/builtin-diff-tree.c @@ -67,7 +67,7 @@ int cmd_diff_tree(int argc, const char **argv, char **envp) static struct rev_info *opt = &log_tree_opt; int read_stdin = 0; - git_config(git_diff_config); + git_config(git_default_config); /* no "diff" UI options */ nr_sha1 = 0; init_revisions(opt); opt->abbrev = 0; diff --git a/builtin-diff.c b/builtin-diff.c index d520c7ca2..1df531ba2 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -250,7 +250,7 @@ int cmd_diff(int argc, const char **argv, char **envp) * Other cases are errors. */ - git_config(git_diff_config); + git_config(git_diff_ui_config); init_revisions(&rev); argc = setup_revisions(argc, argv, &rev, NULL); diff --git a/builtin-log.c b/builtin-log.c index 698b71ecc..dd5a5a2b1 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -47,7 +47,7 @@ int cmd_whatchanged(int argc, const char **argv, char **envp) { struct rev_info rev; - git_config(git_diff_config); + git_config(git_diff_ui_config); init_revisions(&rev); rev.diff = 1; rev.diffopt.recursive = 1; @@ -62,7 +62,7 @@ int cmd_show(int argc, const char **argv, char **envp) { struct rev_info rev; - git_config(git_diff_config); + git_config(git_diff_ui_config); init_revisions(&rev); rev.diff = 1; rev.diffopt.recursive = 1; @@ -79,7 +79,7 @@ int cmd_log(int argc, const char **argv, char **envp) { struct rev_info rev; - git_config(git_diff_config); + git_config(git_diff_ui_config); init_revisions(&rev); rev.always_show_header = 1; cmd_log_init(argc, argv, envp, &rev); @@ -105,7 +105,7 @@ static int git_format_config(const char *var, const char *value) strcat(extra_headers, value); return 0; } - return git_diff_config(var, value); + return git_diff_ui_config(var, value); } diff --git a/diff.c b/diff.c index 1bf1ed096..493650cc0 100644 --- a/diff.c +++ b/diff.c @@ -102,7 +102,13 @@ static const char *parse_diff_color_value(const char *value, const char *var) die("bad config value '%s' for variable '%s'", value, var); } -int git_diff_config(const char *var, const char *value) +/* + * These are to give UI layer defaults. + * The core-level commands such as git-diff-files should + * never be affected by the setting of diff.renames + * the user happens to have in the configuration file. + */ +int git_diff_ui_config(const char *var, const char *value) { if (!strcmp(var, "diff.renamelimit")) { diff_rename_limit_default = git_config_int(var, value); diff --git a/diff.h b/diff.h index 8ab0448a1..a06f95993 100644 --- a/diff.h +++ b/diff.h @@ -123,7 +123,7 @@ extern int diff_scoreopt_parse(const char *opt); #define DIFF_SETUP_USE_CACHE 2 #define DIFF_SETUP_USE_SIZE_CACHE 4 -extern int git_diff_config(const char *var, const char *value); +extern int git_diff_ui_config(const char *var, const char *value); extern void diff_setup(struct diff_options *); extern int diff_opt_parse(struct diff_options *, const char **, int); extern int diff_setup_done(struct diff_options *); -- cgit v1.2.1 From 3a895e0268537da731f5efe914ece5e7eac35ef3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 8 Jul 2006 01:50:02 -0700 Subject: templates/hooks--update: replace diffstat calls with git diff --stat Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- templates/hooks--update | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/hooks--update b/templates/hooks--update index d7a8f0a84..76d5ac247 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -60,7 +60,7 @@ then echo "Changes since $prev:" git rev-list --pretty $prev..$3 | $short echo --- - git diff $prev..$3 | diffstat -p1 + git diff --stat $prev..$3 echo --- fi ;; @@ -75,7 +75,7 @@ else base=$(git-merge-base "$2" "$3") case "$base" in "$2") - git diff "$3" "^$base" | diffstat -p1 + git diff --stat "$3" "^$base" echo echo "New commits:" ;; -- cgit v1.2.1