[PATCH] Implement git-checkout-cache -u to update stat information in the cache.
[gitweb.git] / diff-files.c
index 28f1b13b384dc122daf2b16574536e944b0f6291..7ffe66361226234f62cd27ba2d8fe22cf79c51f2 100644 (file)
@@ -7,10 +7,11 @@
 #include "diff.h"
 
 static const char *diff_files_usage =
-"diff-files [-p] [-q] [-r] [-z] [paths...]";
+"diff-files [-p] [-q] [-r] [-z] [-M] [paths...]";
 
 static int generate_patch = 0;
 static int line_termination = '\n';
+static int detect_rename = 0;
 static int silent = 0;
 
 static int matches_pathspec(struct cache_entry *ce, char **spec, int cnt)
@@ -48,7 +49,7 @@ static void show_file(int pfx, struct cache_entry *ce)
 }
 
 static void show_modified(int oldmode, int mode,
-                         const char *old_sha1, const char *sha1,
+                         const unsigned char *old_sha1, const unsigned char *sha1,
                          char *path)
 {
        char old_sha1_hex[41];
@@ -64,7 +65,7 @@ static void show_modified(int oldmode, int mode,
 
 int main(int argc, char **argv)
 {
-       static const char null_sha1[20] = { 0, };
+       static const unsigned char null_sha1[20] = { 0, };
        int entries = read_cache();
        int i;
 
@@ -79,6 +80,9 @@ int main(int argc, char **argv)
                        ; /* no-op */
                else if (!strcmp(argv[1], "-z"))
                        line_termination = 0;
+               else if (!strcmp(argv[1], "-M")) {
+                       detect_rename = generate_patch = 1;
+               }
                else
                        usage(diff_files_usage);
                argv++; argc--;
@@ -92,6 +96,9 @@ int main(int argc, char **argv)
                exit(1);
        }
 
+       if (generate_patch)
+               diff_setup(detect_rename, 0, 0, 0, 0);          
+
        for (i = 0; i < entries; i++) {
                struct stat st;
                unsigned int oldmode, mode;
@@ -121,7 +128,7 @@ int main(int argc, char **argv)
                        show_file('-', ce);
                        continue;
                }
-               changed = cache_match_stat(ce, &st);
+               changed = ce_match_stat(ce, &st);
                if (!changed)
                        continue;
 
@@ -132,5 +139,7 @@ int main(int argc, char **argv)
                show_modified(oldmode, mode, ce->sha1, null_sha1,
                              ce->name);
        }
+       if (generate_patch)
+               diff_flush();
        return 0;
 }