提交 4727f640 编写于 作者: J Junio C Hamano 提交者: Linus Torvalds

[PATCH] Make -C less eager.

Like diff-tree, this patch makes -C option for diff-* brothers
to use only pre-image of modified files as rename/copy detection
by default.  Give --find-copies-harder to use unmodified files
to find copies from as well.

This also fixes "diff-files -C" problem earlier noticed by
Linus.  It was feeding the null sha1 even when the file in the
work tree was known to match what is in the index file.  This
resulted in diff-files showing everything in the project.
Signed-off-by: NJunio C Hamano <junkio@cox.net>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 170241b7
......@@ -5,6 +5,7 @@ static int cached_only = 0;
static int diff_output_format = DIFF_FORMAT_HUMAN;
static int match_nonexisting = 0;
static int detect_rename = 0;
static int find_copies_harder = 0;
static int diff_setup_opt = 0;
static int diff_score_opt = 0;
static const char *pickaxe = NULL;
......@@ -75,7 +76,7 @@ static int show_modified(struct cache_entry *old,
oldmode = old->ce_mode;
if (mode == oldmode && !memcmp(sha1, old->sha1, 20) &&
detect_rename < DIFF_DETECT_COPY)
!find_copies_harder)
return 0;
mode = ntohl(mode);
......@@ -158,7 +159,7 @@ static void mark_merge_entries(void)
}
static char *diff_cache_usage =
"git-diff-cache [-p] [-r] [-z] [-m] [-M] [-C] [-R] [-S<string>] [-O<orderfile>] [--cached] <tree-ish> [<path>...]";
"git-diff-cache [-p] [-r] [-z] [-m] [--cached] [-R] [-B] [-M] [-C] [--find-copies-harder] [-O<orderfile>] [-S<string>] [--pickaxe-all] <tree-ish> [<path>...]";
int main(int argc, const char **argv)
{
......@@ -213,6 +214,10 @@ int main(int argc, const char **argv)
usage(diff_cache_usage);
continue;
}
if (!strcmp(arg, "--find-copies-harder")) {
find_copies_harder = 1;
continue;
}
if (!strcmp(arg, "-z")) {
diff_output_format = DIFF_FORMAT_MACHINE;
continue;
......@@ -248,6 +253,9 @@ int main(int argc, const char **argv)
usage(diff_cache_usage);
}
if (find_copies_harder && detect_rename != DIFF_DETECT_COPY)
usage(diff_cache_usage);
if (!tree_name || get_sha1(tree_name, sha1))
usage(diff_cache_usage);
......
......@@ -7,10 +7,11 @@
#include "diff.h"
static const char *diff_files_usage =
"git-diff-files [-p] [-q] [-r] [-z] [-M] [-C] [-R] [-S<string>] [-O<orderfile>] [paths...]";
"git-diff-files [-p] [-q] [-r] [-z] [-R] [-B] [-M] [-C] [--find-copies-harder] [-O<orderfile>] [-S<string>] [--pickaxe-all] [<path>...]";
static int diff_output_format = DIFF_FORMAT_HUMAN;
static int detect_rename = 0;
static int find_copies_harder = 0;
static int diff_setup_opt = 0;
static int diff_score_opt = 0;
static const char *pickaxe = NULL;
......@@ -81,11 +82,16 @@ int main(int argc, const char **argv)
usage(diff_files_usage);
detect_rename = DIFF_DETECT_COPY;
}
else if (!strcmp(argv[1], "--find-copies-harder"))
find_copies_harder = 1;
else
usage(diff_files_usage);
argv++; argc--;
}
if (find_copies_harder && detect_rename != DIFF_DETECT_COPY)
usage(diff_files_usage);
/* At this point, if argc == 1, then we are doing everything.
* Otherwise argv[1] .. argv[argc-1] have the explicit paths.
*/
......@@ -122,12 +128,11 @@ int main(int argc, const char **argv)
continue;
}
changed = ce_match_stat(ce, &st);
if (!changed && detect_rename < DIFF_DETECT_COPY)
if (!changed && !find_copies_harder)
continue;
oldmode = ntohl(ce->ce_mode);
show_modified(oldmode, DIFF_FILE_CANON_MODE(st.st_mode),
ce->sha1, null_sha1,
ce->sha1, (changed ? null_sha1 : ce->sha1),
ce->name);
}
diffcore_std((1 < argc) ? argv + 1 : NULL,
......
......@@ -7,6 +7,7 @@
static int diff_output_format = DIFF_FORMAT_HUMAN;
static int detect_rename = 0;
static int find_copies_harder = 0;
static int diff_setup_opt = 0;
static int diff_score_opt = 0;
static const char *pickaxe = NULL;
......@@ -16,7 +17,7 @@ static const char *orderfile = NULL;
static const char *diff_filter = NULL;
static char *diff_stages_usage =
"git-diff-stages [-p] [-r] [-z] [-M] [-C] [-R] [-S<string>] [-O<orderfile>] <stage1> <stage2> [<path>...]";
"git-diff-stages [-p] [-r] [-z] [-R] [-B] [-M] [-C] [--find-copies-harder] [-O<orderfile>] [-S<string>] [--pickaxe-all] <stage1> <stage2> [<path>...]";
static void diff_stages(int stage1, int stage2)
{
......@@ -50,9 +51,10 @@ static void diff_stages(int stage1, int stage2)
diff_addremove('-', ntohl(one->ce_mode),
one->sha1, name, NULL);
else if (memcmp(one->sha1, two->sha1, 20) ||
(one->ce_mode != two->ce_mode))
diff_change(ntohl(one->ce_mode), ntohl(two->ce_mode),
one->sha1, two->sha1, name, NULL);
(one->ce_mode != two->ce_mode) ||
find_copies_harder)
diff_change(ntohl(one->ce_mode), ntohl(two->ce_mode),
one->sha1, two->sha1, name, NULL);
}
}
......@@ -81,6 +83,8 @@ int main(int ac, const char **av)
if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1)
usage(diff_stages_usage);
}
else if (!strcmp(arg, "--find-copies-harder"))
find_copies_harder = 1;
else if (!strcmp(arg, "-z"))
diff_output_format = DIFF_FORMAT_MACHINE;
else if (!strcmp(arg, "-R"))
......@@ -102,7 +106,8 @@ int main(int ac, const char **av)
sscanf(av[1], "%d", &stage1) != 1 ||
! (0 <= stage1 && stage1 <= 3) ||
sscanf(av[2], "%d", &stage2) != 1 ||
! (0 <= stage2 && stage2 <= 3))
! (0 <= stage2 && stage2 <= 3) ||
find_copies_harder && detect_rename != DIFF_DETECT_COPY)
usage(diff_stages_usage);
av += 3; /* The rest from av[0] are for paths restriction. */
......
......@@ -201,7 +201,7 @@ static int interesting(void *tree, unsigned long size, const char *base)
static void show_tree(const char *prefix, void *tree, unsigned long size, const char *base)
{
while (size) {
if (find_copies_harder || interesting(tree, size, base))
if (interesting(tree, size, base))
show_file(prefix, tree, size, base);
update_tree_entry(&tree, &size);
}
......@@ -269,7 +269,7 @@ static void call_diff_setup(void)
static int call_diff_flush(void)
{
diffcore_std(find_copies_harder ? paths : 0,
diffcore_std(NULL,
detect_rename, diff_score_opt,
pickaxe, pickaxe_opts,
diff_break_opt,
......@@ -401,7 +401,7 @@ static int diff_tree_stdin(char *line)
}
static char *diff_tree_usage =
"git-diff-tree [-p] [-r] [-z] [--stdin] [-M] [-C] [-R] [-S<string>] [-O<orderfile>] [-m] [-s] [-v] [--pretty] [-t] <tree-ish> <tree-ish>";
"git-diff-tree [-p] [-r] [-z] [--stdin] [-m] [-s] [-v] [--pretty] [-t] [-R] [-B] [-M] [-C] [--find-copies-header] [-O<orderfile>] [-S<string>] [--pickaxe-all] <tree-ish> <tree-ish>";
static enum cmit_fmt get_commit_format(const char *arg)
{
......
......@@ -108,7 +108,8 @@ test_expect_success \
# the diff-core. Unchanged rezrov, although being fed to
# git-diff-cache as well, should not be mentioned.
GIT_DIFF_OPTS=--unified=0 git-diff-cache -C -p $tree >current
GIT_DIFF_OPTS=--unified=0 \
git-diff-cache -C --find-copies-harder -p $tree >current
cat >expected <<\EOF
diff --git a/COPYING b/COPYING.1
copy from COPYING
......
......@@ -136,7 +136,7 @@ test_expect_success \
'cat ../../COPYING >COPYING &&
git-update-cache --add --remove COPYING COPYING.1'
git-diff-cache -C $tree >current
git-diff-cache -C --find-copies-harder $tree >current
cat >expected <<\EOF
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
EOF
......
......@@ -26,7 +26,7 @@ test_expect_success \
# path1 both have COPYING and the latter is a copy of path0/COPYING.
# Comparing the full tree with cache should tell us so.
git-diff-cache -C $tree >current
git-diff-cache -C --find-copies-harder $tree >current
cat >expected <<\EOF
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 C100 path0/COPYING path1/COPYING
......
......@@ -143,7 +143,7 @@ test_expect_success \
'cat ../../COPYING >COPYING &&
git-update-cache --add --remove COPYING COPYING.1'
git-diff-cache -z -C $tree >current
git-diff-cache -z -C --find-copies-harder $tree >current
cat >expected <<\EOF
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234
COPYING
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册