1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-26 01:16:36 +02:00

Merge branch 'ew/diff'

* 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
This commit is contained in:
Junio C Hamano 2006-07-09 23:47:39 -07:00
commit fc93dbbfc9
11 changed files with 78 additions and 17 deletions

View 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].

View 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
@ -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[=<n>]::
Instead of showing the full 40-byte hexadecimal object

View 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;

View 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;

View 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] == '-') {

View 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;

View 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);

View 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);
}

24
diff.c
View File

@ -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;

2
diff.h
View File

@ -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 *);

View 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:"
;;