Merge branch 'maint' of git://repo.or.cz/git-gui into maint
[gitweb.git] / unpack-trees.c
index a0b676903ad042bfc1bb199a33f1658cdfd511c9..cac2411b9de7b4889abe6b0b84df25d24a38c7e5 100644 (file)
@@ -4,6 +4,7 @@
 #include "tree-walk.h"
 #include "cache-tree.h"
 #include "unpack-trees.h"
+#include "progress.h"
 
 #define DBRT_DEBUG 1
 
@@ -263,10 +264,12 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
  * directories, in case this unlink is the removal of the
  * last entry in the directory -- empty directories are removed.
  */
-static void unlink_entry(char *name)
+static void unlink_entry(char *name, char *last_symlink)
 {
        char *cp, *prev;
 
+       if (has_symlink_leading_path(name, last_symlink))
+               return;
        if (unlink(name))
                return;
        prev = NULL;
@@ -288,36 +291,14 @@ static void unlink_entry(char *name)
        }
 }
 
-static volatile sig_atomic_t progress_update;
-
-static void progress_interval(int signum)
-{
-       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 struct checkout state;
 static void check_updates(struct cache_entry **src, int nr,
-               struct unpack_trees_options *o)
+                       struct unpack_trees_options *o)
 {
        unsigned short mask = htons(CE_UPDATE);
-       unsigned last_percent = 200, cnt = 0, total = 0;
+       unsigned cnt = 0, total = 0;
+       struct progress progress;
+       char last_symlink[PATH_MAX];
 
        if (o->update && o->verbose_update) {
                for (total = cnt = 0; cnt < nr; cnt++) {
@@ -326,50 +307,33 @@ static void check_updates(struct cache_entry **src, int nr,
                                total++;
                }
 
-               /* Don't bother doing this for very small updates */
-               if (total < 250)
-                       total = 0;
-
-               if (total) {
-                       fprintf(stderr, "Checking files out...\n");
-                       setup_progress_signal();
-                       progress_update = 1;
-               }
+               start_progress_delay(&progress, "Checking %u files out...",
+                                    "", total, 50, 2);
                cnt = 0;
        }
 
+       *last_symlink = '\0';
        while (nr--) {
                struct cache_entry *ce = *src++;
 
-               if (total) {
-                       if (!ce->ce_mode || ce->ce_flags & mask) {
-                               unsigned percent;
-                               cnt++;
-                               percent = (cnt * 100) / total;
-                               if (percent != last_percent ||
-                                   progress_update) {
-                                       fprintf(stderr, "%4u%% (%u/%u) done\r",
-                                               percent, cnt, total);
-                                       last_percent = percent;
-                                       progress_update = 0;
-                               }
-                       }
-               }
+               if (total)
+                       if (!ce->ce_mode || ce->ce_flags & mask)
+                               display_progress(&progress, ++cnt);
                if (!ce->ce_mode) {
                        if (o->update)
-                               unlink_entry(ce->name);
+                               unlink_entry(ce->name, last_symlink);
                        continue;
                }
                if (ce->ce_flags & mask) {
                        ce->ce_flags &= ~mask;
-                       if (o->update)
+                       if (o->update) {
                                checkout_entry(ce, &state, NULL);
+                               *last_symlink = '\0';
+                       }
                }
        }
-       if (total) {
-               signal(SIGALRM, SIG_IGN);
-               fputc('\n', stderr);
-       }
+       if (total)
+               stop_progress(&progress);;
 }
 
 int unpack_trees(struct object_list *trees, struct unpack_trees_options *o)
@@ -450,10 +414,6 @@ static void verify_uptodate(struct cache_entry *ce,
                        return;
                errno = 0;
        }
-       if (o->reset) {
-               ce->ce_flags |= htons(CE_UPDATE);
-               return;
-       }
        if (errno == ENOENT)
                return;
        die("Entry '%s' not uptodate. Cannot merge.", ce->name);
@@ -665,7 +625,6 @@ int threeway_merge(struct cache_entry **stages,
        int count;
        int head_match = 0;
        int remote_match = 0;
-       const char *path = NULL;
 
        int df_conflict_head = 0;
        int df_conflict_remote = 0;
@@ -675,13 +634,10 @@ int threeway_merge(struct cache_entry **stages,
        int i;
 
        for (i = 1; i < o->head_idx; i++) {
-               if (!stages[i])
+               if (!stages[i] || stages[i] == o->df_conflict_entry)
                        any_anc_missing = 1;
-               else {
-                       if (!path)
-                               path = stages[i]->name;
+               else
                        no_anc_exists = 0;
-               }
        }
 
        index = stages[0];
@@ -697,13 +653,6 @@ int threeway_merge(struct cache_entry **stages,
                remote = NULL;
        }
 
-       if (!path && index)
-               path = index->name;
-       if (!path && head)
-               path = head->name;
-       if (!path && remote)
-               path = remote->name;
-
        /* First, if there's a #16 situation, note that to prevent #13
         * and #14.
         */
@@ -755,6 +704,23 @@ int threeway_merge(struct cache_entry **stages,
        if (o->aggressive) {
                int head_deleted = !head && !df_conflict_head;
                int remote_deleted = !remote && !df_conflict_remote;
+               const char *path = NULL;
+
+               if (index)
+                       path = index->name;
+               else if (head)
+                       path = head->name;
+               else if (remote)
+                       path = remote->name;
+               else {
+                       for (i = 1; i < o->head_idx; i++) {
+                               if (stages[i] && stages[i] != o->df_conflict_entry) {
+                                       path = stages[i]->name;
+                                       break;
+                               }
+                       }
+               }
+
                /*
                 * Deleted in both.
                 * Deleted in one and unchanged in the other.
@@ -786,11 +752,11 @@ int threeway_merge(struct cache_entry **stages,
 
        o->nontrivial_merge = 1;
 
-       /* #2, #3, #4, #6, #7, #9, #11. */
+       /* #2, #3, #4, #6, #7, #9, #10, #11. */
        count = 0;
        if (!head_match || !remote_match) {
                for (i = 1; i < o->head_idx; i++) {
-                       if (stages[i]) {
+                       if (stages[i] && stages[i] != o->df_conflict_entry) {
                                keep_entry(stages[i], o);
                                count++;
                                break;