Code

[PATCH] Make -C less eager.
authorJunio C Hamano <junkio@cox.net>
Sun, 19 Jun 2005 20:14:05 +0000 (13:14 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Mon, 20 Jun 2005 03:13:18 +0000 (20:13 -0700)
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: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
diff-cache.c
diff-files.c
diff-stages.c
diff-tree.c
t/t4003-diff-rename-1.sh
t/t4005-diff-rename-2.sh
t/t4007-rename-3.sh
t/t4009-diff-rename-4.sh

index 13baaa37217fd6e1c9313b2989071835c63dbfbd..603a6b7774e6de19bc2b80299e30fb801d8fd773 100644 (file)
@@ -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);
 
index b6d972e06284f4a2b68204003321d9d8bcd42739..4d60017e46b1aa54ea07a85b478592408dc34233 100644 (file)
@@ -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,
index 4b87c8ef7b17b19ca4f018dbb77b2e78aa7902af..f0998149cf1adba825413e15e4279db4da5f71eb 100644 (file)
@@ -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. */
index 20757153500064a7868142d53d4933abfd444f5a..7446e09af4f4b7a5f7475a42bb60c9818e6cc9d5 100644 (file)
@@ -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)
 {
index 63a3103b4b372dd663249beb38d92592fb9a00af..8e3091abb603f9d9a7a456459fac31d4f02e54e7 100644 (file)
@@ -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
index 1921299fbcb55be26f299dade3ddc85b396e1db6..cee06e4c5dd2530c2147baa09434356b020b7933 100644 (file)
@@ -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
index a55d6b65d191b338194e945408c4f8b807cfba52..ab83ea3b8abdc7228455c9dd326c1f179a02b5f5 100644 (file)
@@ -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
index 318915f4477b9ff6ad62c99718a841d0c2d046e2..6229a5bf1a9b82a2e64510d3ec9f9817d0dd0e0e 100644 (file)
@@ -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