Merge branch 'ew/diff'
authorJunio C Hamano <junkio@cox.net>
Mon, 10 Jul 2006 06:47:39 +0000 (23:47 -0700)
committerJunio C Hamano <junkio@cox.net>
Mon, 10 Jul 2006 06:47:39 +0000 (23:47 -0700)
* ew/diff:
templates/hooks--update: replace diffstat calls with git diff --stat
diff: do not use configuration magic at the core-level
Update diff-options and config documentation.
diff.c: --no-color to defeat diff.color configuration.
diff.c: respect diff.renames config option

Documentation/config.txt
Documentation/diff-options.txt
builtin-diff-files.c
builtin-diff-index.c
builtin-diff-stages.c
builtin-diff-tree.c
builtin-diff.c
builtin-log.c
diff.c
diff.h
templates/hooks--update
index f075f19815f4505068a1ca1aed7a0e5b46025435..0b434c1f1923fb10b2420a3295e59fd9d163f39b 100644 (file)
@@ -110,10 +110,31 @@ 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.<slot>::
+       Use customized color for diff colorization.  `<slot>`
+       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.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].
index 1a936295d8944b3b52ac82aa806c007851ab0176..47ba9a403ae9379b87c54f0103297da9157237cb 100644 (file)
@@ -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
 --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[=<n>]::
        Instead of showing the full 40-byte hexadecimal object
index a655eea91ed5ac38af578e47fe6747a1b6fb968c..81ac2fe64aea23f9db605da181da098dcfca757a 100644 (file)
@@ -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;
 
index b37c9e8ccb30686810ecfdb898ad360b40ca0723..a1fa1b85cf741cd6b5f06afd02abbe618e86f5d1 100644 (file)
@@ -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;
 
index 30931fe0498753ed3a7f68be064027391a82e677..9c62702941569511a149eba89a8be2b478f04b70 100644 (file)
@@ -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] == '-') {
index ae1cde9d005cb64ca2b1a5de45750abff04d444d..b6106685942e3cb3a5db2b3a67123b5bd554d856 100644 (file)
@@ -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;
index d520c7ca294fcd8e619135bfe8932650d850724c..1df531ba28d596a8a8b338cae0c4295fc16892f2 100644 (file)
@@ -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);
index 0aeeaa4e20ceaaad32707749b0aed03bd390c46a..7e5cab15c106f59417804a25d094c94e78d64063 100644 (file)
@@ -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);
@@ -108,7 +108,7 @@ static int git_format_config(const char *var, const char *value)
        if (!strcmp(var, "diff.color")) {
                return 0;
        }
-       return git_diff_config(var, value);
+       return git_diff_ui_config(var, value);
 }
 
 
diff --git a/diff.c b/diff.c
index a00f9d1e5244c8a7d2edfcef55cb92d3d3df252a..e101bfd8c808e832a209d352d677e7d8a666a5ec 100644 (file)
--- 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;
 
@@ -101,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);
@@ -126,6 +133,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);
@@ -1437,6 +1454,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)
@@ -1619,10 +1637,14 @@ 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"))
                options->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE;
+       else if (!strcmp(arg, "--no-renames"))
+               options->detect_rename = 0;
        else
                return 0;
        return 1;
diff --git a/diff.h b/diff.h
index 8ab0448a12e163b0941c05aba4f0a4d9c7a6cfb7..a06f959938d1313e45daa610a1f3eb71b4c3f835 100644 (file)
--- 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 *);
index d7a8f0a849523ebc280e06fe836f3bc448993d0c..76d5ac2477d669aabfef8108cfbb713fbdfef70a 100644 (file)
@@ -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:"
                ;;