[PATCH] Implement git-checkout-cache -u to update stat information in the cache.
[gitweb.git] / diff-cache.c
index 7e87d28f3a358710b9f11a4b76e4235926f438ee..2bdea9cc3aecb3bf75c0a0e56fe6b54640390e18 100644 (file)
@@ -5,6 +5,7 @@ static int cached_only = 0;
 static int generate_patch = 0;
 static int match_nonexisting = 0;
 static int line_termination = '\n';
+static int detect_rename = 0;
 
 /* A file entry went away or appeared */
 static void show_file(const char *prefix, struct cache_entry *ce, unsigned char *sha1, unsigned int mode)
@@ -33,7 +34,7 @@ static int get_stat_data(struct cache_entry *ce, unsigned char **sha1p, unsigned
                        }
                        return -1;
                }
-               changed = cache_match_stat(ce, &st);
+               changed = ce_match_stat(ce, &st);
                if (changed) {
                        mode = create_ce_mode(st.st_mode);
                        sha1 = no_sha1;
@@ -63,7 +64,7 @@ static int show_modified(struct cache_entry *old,
 {
        unsigned int mode, oldmode;
        unsigned char *sha1;
-       unsigned char old_sha1_hex[60];
+       char old_sha1_hex[60];
 
        if (get_stat_data(new, &sha1, &mode) < 0) {
                if (report_missing)
@@ -94,7 +95,7 @@ static int diff_cache(struct cache_entry **ac, int entries)
 {
        while (entries) {
                struct cache_entry *ce = *ac;
-               int same = (entries > 1) && same_name(ce, ac[1]);
+               int same = (entries > 1) && ce_same_name(ce, ac[1]);
 
                switch (ce_stage(ce)) {
                case 0:
@@ -143,7 +144,7 @@ static int diff_cache(struct cache_entry **ac, int entries)
                do {
                        ac++;
                        entries--;
-               } while (entries && same_name(ce, ac[0]));
+               } while (entries && ce_same_name(ce, ac[0]));
        }
        return 0;
 }
@@ -165,13 +166,14 @@ static void mark_merge_entries(void)
 }
 
 static char *diff_cache_usage =
-"diff-cache [-r] [-z] [-p] [-i] [--cached] <tree sha1>";
+"git-diff-cache [-p] [-r] [-z] [-m] [-M] [--cached] <tree-ish>";
 
 int main(int argc, char **argv)
 {
        unsigned char tree_sha1[20];
        void *tree;
        unsigned long size;
+       int ret;
 
        read_cache();
        while (argc > 2) {
@@ -186,6 +188,10 @@ int main(int argc, char **argv)
                        generate_patch = 1;
                        continue;
                }
+               if (!strcmp(arg, "-M")) {
+                       generate_patch = detect_rename = 1;
+                       continue;
+               }
                if (!strcmp(arg, "-z")) {
                        line_termination = '\0';
                        continue;
@@ -204,6 +210,9 @@ int main(int argc, char **argv)
        if (argc != 2 || get_sha1(argv[1], tree_sha1))
                usage(diff_cache_usage);
 
+       if (generate_patch)
+               diff_setup(detect_rename, 0, 0, 0, 0);
+
        mark_merge_entries();
 
        tree = read_object_with_reference(tree_sha1, "tree", &size, 0);
@@ -212,5 +221,8 @@ int main(int argc, char **argv)
        if (read_tree(tree, size, 1))
                die("unable to read tree object %s", argv[1]);
 
-       return diff_cache(active_cache, active_nr);
+       ret = diff_cache(active_cache, active_nr);
+       if (generate_patch)
+               diff_flush();
+       return ret;
 }