read-tree -u one-way merge fix to check out locally modified paths.
[gitweb.git] / read-tree.c
index 1c3b09beffdf347af40b385f632d481c99645a33..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);
@@ -273,10 +270,26 @@ static void unlink_entry(char *name)
 
 static void progress_interval(int signum)
 {
-       signal(SIGALRM, progress_interval);
        progress_update = 1;
 }
 
+static void setup_progress_signal(void)
+{
+       struct sigaction sa;
+       struct itimerval v;
+
+       memset(&sa, 0, sizeof(sa));
+       sa.sa_handler = progress_interval;
+       sigemptyset(&sa.sa_mask);
+       sa.sa_flags = SA_RESTART;
+       sigaction(SIGALRM, &sa, NULL);
+
+       v.it_interval.tv_sec = 1;
+       v.it_interval.tv_usec = 0;
+       v.it_value = v.it_interval;
+       setitimer(ITIMER_REAL, &v, NULL);
+}
+
 static void check_updates(struct cache_entry **src, int nr)
 {
        static struct checkout state = {
@@ -289,8 +302,6 @@ static void check_updates(struct cache_entry **src, int nr)
        unsigned last_percent = 200, cnt = 0, total = 0;
 
        if (update && verbose_update) {
-               struct itimerval v;
-
                for (total = cnt = 0; cnt < nr; cnt++) {
                        struct cache_entry *ce = src[cnt];
                        if (!ce->ce_mode || ce->ce_flags & mask)
@@ -302,12 +313,8 @@ static void check_updates(struct cache_entry **src, int nr)
                        total = 0;
 
                if (total) {
-                       v.it_interval.tv_sec = 1;
-                       v.it_interval.tv_usec = 0;
-                       v.it_value = v.it_interval;
-                       signal(SIGALRM, progress_interval);
-                       setitimer(ITIMER_REAL, &v, NULL);
                        fprintf(stderr, "Checking files out...\n");
+                       setup_progress_signal();
                        progress_update = 1;
                }
                cnt = 0;
@@ -341,8 +348,8 @@ static void check_updates(struct cache_entry **src, int nr)
                }
        }
        if (total) {
-               fputc('\n', stderr);
                signal(SIGALRM, SIG_IGN);
+               fputc('\n', stderr);
        }
 }
 
@@ -677,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);
@@ -717,6 +727,7 @@ int main(int argc, char **argv)
        merge_fn_t fn = NULL;
 
        setup_git_directory();
+       git_config(git_default_config);
 
        newfd = hold_index_file_for_update(&cache_file, get_index_file());
        if (newfd < 0)
@@ -786,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++;