read-tree -u one-way merge fix to check out locally modified paths.
[gitweb.git] / read-tree.c
index 4422dbf424a5f4fd491811648acd3273aba529f3..59b6a6bff9bc0b2dc7c922bf8e8b16cf36573fc7 100644 (file)
@@ -133,11 +133,9 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
                pathlen = strlen(first);
                ce_size = cache_entry_size(baselen + pathlen);
 
-               src = xmalloc(sizeof(struct cache_entry *) * src_size);
-               memset(src, 0, sizeof(struct cache_entry *) * src_size);
+               src = xcalloc(src_size, sizeof(struct cache_entry *));
 
-               subposns = xmalloc(sizeof(struct tree_list_entry *) * len);
-               memset(subposns, 0, sizeof(struct tree_list_entry *) * len);
+               subposns = xcalloc(len, sizeof(struct tree_list_entry *));
 
                if (cache_name && !strcmp(cache_name, first)) {
                        any_files = 1;
@@ -177,8 +175,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
                        else
                                ce_stage = 2;
 
-                       ce = xmalloc(ce_size);
-                       memset(ce, 0, ce_size);
+                       ce = xcalloc(1, ce_size);
                        ce->ce_mode = create_ce_mode(posns[i]->mode);
                        ce->ce_flags = create_ce_flags(baselen + pathlen,
                                                       ce_stage);
@@ -687,8 +684,11 @@ static int oneway_merge(struct cache_entry **src)
                             merge_size);
 
        if (!a)
-               return 0;
+               return deleted_entry(old, NULL);
        if (old && same(old, a)) {
+               struct stat st;
+               if (lstat(old->name, &st) || ce_match_stat(old, &st, 1))
+                       old->ce_flags |= htons(CE_UPDATE);
                return keep_entry(old);
        }
        return merged_entry(a, NULL);
@@ -797,8 +797,8 @@ int main(int argc, char **argv)
                if (1 < index_only + update)
                        usage(read_tree_usage);
 
-               if (get_sha1(arg, sha1) < 0)
-                       usage(read_tree_usage);
+               if (get_sha1(arg, sha1))
+                       die("Not a valid object name %s", arg);
                if (list_tree(sha1) < 0)
                        die("failed to unpack tree object %s", arg);
                stage++;