verify-pack: check integrity in a saner order.
[git.git] / update-index.c
index 767fd49..1efac27 100644 (file)
@@ -114,8 +114,7 @@ static int add_file_to_cache(const char *path)
 
        namelen = strlen(path);
        size = cache_entry_size(namelen);
-       ce = xmalloc(size);
-       memset(ce, 0, size);
+       ce = xcalloc(1, size);
        memcpy(ce->name, path, namelen);
        ce->ce_flags = htons(namelen);
        fill_stat_cache_info(ce, &st);
@@ -161,8 +160,13 @@ static struct cache_entry *refresh_entry(struct cache_entry *ce, int really)
                return ERR_PTR(-errno);
 
        changed = ce_match_stat(ce, &st, really);
-       if (!changed)
-               return NULL;
+       if (!changed) {
+               if (really && assume_unchanged &&
+                   !(ce->ce_flags & htons(CE_VALID)))
+                       ; /* mark this one VALID again */
+               else
+                       return NULL;
+       }
 
        if (ce_modified(ce, &st, really))
                return ERR_PTR(-EINVAL);
@@ -172,6 +176,15 @@ static struct cache_entry *refresh_entry(struct cache_entry *ce, int really)
        memcpy(updated, ce, size);
        fill_stat_cache_info(updated, &st);
 
+       /* In this case, if really is not set, we should leave
+        * CE_VALID bit alone.  Otherwise, paths marked with
+        * --no-assume-unchanged (i.e. things to be edited) will
+        * reacquire CE_VALID bit automatically, which is not
+        * really what we want.
+        */
+       if (!really && assume_unchanged && !(ce->ce_flags & htons(CE_VALID)))
+               updated->ce_flags &= ~htons(CE_VALID);
+
        return updated;
 }
 
@@ -298,8 +311,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
 
        len = strlen(path);
        size = cache_entry_size(len);
-       ce = xmalloc(size);
-       memset(ce, 0, size);
+       ce = xcalloc(1, size);
 
        memcpy(ce->sha1, sha1, 20);
        memcpy(ce->name, path, len);
@@ -563,9 +575,11 @@ int main(int argc, const char **argv)
                                break;
                        }
                        if (!strcmp(path, "--index-info")) {
+                               if (i != argc - 1)
+                                       die("--index-info must be at the end");
                                allow_add = allow_replace = allow_remove = 1;
                                read_index_info(line_termination);
-                               continue;
+                               break;
                        }
                        if (!strcmp(path, "--ignore-missing")) {
                                not_new = 1;