]> rtime.felk.cvut.cz Git - git.git/commitdiff
Merge branch 'cb/maint-unpack-trees-absense'
authorJunio C Hamano <gitster@pobox.com>
Wed, 14 Jan 2009 07:09:20 +0000 (23:09 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Jan 2009 07:09:20 +0000 (23:09 -0800)
* cb/maint-unpack-trees-absense:
  unpack-trees: remove redundant path search in verify_absent
  unpack-trees: fix path search bug in verify_absent
  unpack-trees: handle failure in verify_absent

1  2 
unpack-trees.c

diff --combined unpack-trees.c
index 54f301da67be879c80426bc21776427fdd38c02e,556813eca824b2c88db07df5db96e3c95ac95a56..15c9ef592b393410354496c577a6e8c2dfb39940
@@@ -352,7 -352,7 +352,7 @@@ static int unpack_failed(struct unpack_
        discard_index(&o->result);
        if (!o->gently) {
                if (message)
 -                      return error(message);
 +                      return error("%s", message);
                return -1;
        }
        return -1;
@@@ -376,13 -376,12 +376,13 @@@ int unpack_trees(unsigned len, struct t
        state.refresh_cache = 1;
  
        memset(&o->result, 0, sizeof(o->result));
 +      o->result.initialized = 1;
        if (o->src_index)
                o->result.timestamp = o->src_index->timestamp;
        o->merge_size = len;
  
        if (!dfc)
 -              dfc = xcalloc(1, sizeof(struct cache_entry) + 1);
 +              dfc = xcalloc(1, cache_entry_size(0));
        o->df_conflict_entry = dfc;
  
        if (len) {
@@@ -494,7 -493,7 +494,7 @@@ static int verify_clean_subdirectory(st
         * anything in the existing directory there.
         */
        int namelen;
-       int pos, i;
+       int i;
        struct dir_struct d;
        char *pathbuf;
        int cnt = 0;
         * in that directory.
         */
        namelen = strlen(ce->name);
-       pos = index_name_pos(o->src_index, ce->name, namelen);
-       if (0 <= pos)
-               return cnt; /* we have it as nondirectory */
-       pos = -pos - 1;
-       for (i = pos; i < o->src_index->cache_nr; i++) {
-               struct cache_entry *ce = o->src_index->cache[i];
-               int len = ce_namelen(ce);
+       for (i = o->pos; i < o->src_index->cache_nr; i++) {
+               struct cache_entry *ce2 = o->src_index->cache[i];
+               int len = ce_namelen(ce2);
                if (len < namelen ||
-                   strncmp(ce->name, ce->name, namelen) ||
-                   ce->name[namelen] != '/')
+                   strncmp(ce->name, ce2->name, namelen) ||
+                   ce2->name[namelen] != '/')
                        break;
                /*
-                * ce->name is an entry in the subdirectory.
+                * ce2->name is an entry in the subdirectory.
                 */
-               if (!ce_stage(ce)) {
-                       if (verify_uptodate(ce, o))
+               if (!ce_stage(ce2)) {
+                       if (verify_uptodate(ce2, o))
                                return -1;
-                       add_entry(o, ce, CE_REMOVE, 0);
+                       add_entry(o, ce2, CE_REMOVE, 0);
                }
                cnt++;
        }
@@@ -588,7 -583,7 +584,7 @@@ static int verify_absent(struct cache_e
                return 0;
  
        if (!lstat(ce->name, &st)) {
-               int cnt;
+               int ret;
                int dtype = ce_to_dtype(ce);
                struct cache_entry *result;
  
                         * files that are in "foo/" we would lose
                         * it.
                         */
-                       cnt = verify_clean_subdirectory(ce, action, o);
+                       ret = verify_clean_subdirectory(ce, action, o);
+                       if (ret < 0)
+                               return ret;
  
                        /*
                         * If this removed entries from the index,
                         * what that means is:
                         *
-                        * (1) the caller unpack_trees_rec() saw path/foo
+                        * (1) the caller unpack_callback() saw path/foo
                         * in the index, and it has not removed it because
                         * it thinks it is handling 'path' as blob with
                         * D/F conflict;
                         * We need to increment it by the number of
                         * deleted entries here.
                         */
-                       o->pos += cnt;
+                       o->pos += ret;
                        return 0;
                }
  
@@@ -941,17 -938,8 +939,17 @@@ int twoway_merge(struct cache_entry **s
                        return -1;
                }
        }
 -      else if (newtree)
 +      else if (newtree) {
 +              if (oldtree && !o->initial_checkout) {
 +                      /*
 +                       * deletion of the path was staged;
 +                       */
 +                      if (same(oldtree, newtree))
 +                              return 1;
 +                      return reject_merge(oldtree, o);
 +              }
                return merged_entry(newtree, current, o);
 +      }
        return deleted_entry(oldtree, current, o);
  }