Merge branch 'jc/fix-tree-walk'
authorJunio C Hamano <gitster@pobox.com>
Mon, 25 Jan 2010 01:35:58 +0000 (17:35 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 Jan 2010 01:35:58 +0000 (17:35 -0800)
* jc/fix-tree-walk:
  read-tree --debug-unpack
  unpack-trees.c: look ahead in the index
  unpack-trees.c: prepare for looking ahead in the index
  Aggressive three-way merge: fix D/F case
  traverse_trees(): handle D/F conflict case sanely
  more D/F conflict tests
  tests: move convenience regexp to match object names to test-lib.sh

Conflicts:
builtin-read-tree.c
unpack-trees.c
unpack-trees.h

1  2 
builtin-read-tree.c
cache.h
diff-lib.c
diff.c
diff.h
t/test-lib.sh
unpack-trees.c
unpack-trees.h

index 5fda9905fcfa5ccbc0f28578cd371314a8a7e5a7,0c1f40d10d1846bb187f691ad16d6ed24cc7aa8d..8bdcab11389e8b4facab355f27f0e1926134b86f
@@@ -99,8 -126,8 +127,10 @@@ int cmd_read_tree(int argc, const char 
                  PARSE_OPT_NONEG, exclude_per_directory_cb },
                OPT_SET_INT('i', NULL, &opts.index_only,
                            "don't check the working tree after merging", 1),
 +              OPT_SET_INT(0, "no-sparse-checkout", &opts.skip_sparse_checkout,
 +                          "skip applying sparse checkout filter", 1),
+               OPT_SET_INT(0, "debug-unpack", &opts.debug_unpack,
+                           "debug unpack-trees", 1),
                OPT_END()
        };
  
diff --cc cache.h
index 7d5c21e3f1e737504a7f4f8c76781b1552cb77e3,9a9596386d704742ee3f381edd893515f179bcf8..b3370eb41e500b59bdf9d03679e7c17dde59e911
+++ b/cache.h
@@@ -177,11 -177,9 +177,13 @@@ struct cache_entry 
  
  #define CE_HASHED    (0x100000)
  #define CE_UNHASHED  (0x200000)
 +#define CE_CONFLICTED (0x800000)
 +
 +/* Only remove in work directory, not index */
 +#define CE_WT_REMOVE (0x400000)
  
+ #define CE_UNPACKED  (0x1000000)
  /*
   * Extended on-disk flags
   */
diff --cc diff-lib.c
Simple merge
diff --cc diff.c
Simple merge
diff --cc diff.h
Simple merge
diff --cc t/test-lib.sh
Simple merge
diff --cc unpack-trees.c
index 0ddbef3e6355da40a1293a6a7c49b4bc5d75b842,10e8871a747b0a9519b2397f150517ec671e7ee6..75f54cac97f62ddaad736c2cd582cc6cdeaaebfa
@@@ -453,23 -647,12 +720,22 @@@ int unpack_trees(unsigned len, struct t
        state.quiet = 1;
        state.refresh_cache = 1;
  
 +      memset(&el, 0, sizeof(el));
 +      if (!core_apply_sparse_checkout || !o->update)
 +              o->skip_sparse_checkout = 1;
 +      if (!o->skip_sparse_checkout) {
 +              if (add_excludes_from_file_to_list(git_path("info/sparse-checkout"), "", 0, NULL, &el, 0) < 0)
 +                      o->skip_sparse_checkout = 1;
 +              else
 +                      o->el = &el;
 +      }
 +
        memset(&o->result, 0, sizeof(o->result));
        o->result.initialized = 1;
-       if (o->src_index) {
-               o->result.timestamp.sec = o->src_index->timestamp.sec;
-               o->result.timestamp.nsec = o->src_index->timestamp.nsec;
-       }
+       o->result.timestamp.sec = o->src_index->timestamp.sec;
+       o->result.timestamp.nsec = o->src_index->timestamp.nsec;
        o->merge_size = len;
+       mark_all_ce_unused(o->src_index);
  
        if (!dfc)
                dfc = xcalloc(1, cache_entry_size(0));
  
        /* Any left-over entries in the index? */
        if (o->merge) {
-               while (o->pos < o->src_index->cache_nr) {
-                       struct cache_entry *ce = o->src_index->cache[o->pos];
-                       if (unpack_index_entry(ce, o) < 0) {
-                               ret = unpack_failed(o, NULL);
-                               goto done;
-                       }
+               while (1) {
+                       struct cache_entry *ce = next_cache_entry(o);
+                       if (!ce)
+                               break;
+                       if (unpack_index_entry(ce, o) < 0)
+                               goto return_failed;
                }
        }
+       mark_all_ce_unused(o->src_index);
  
 -      if (o->trivial_merges_only && o->nontrivial_merge)
 -              return unpack_failed(o, "Merge requires file-level merging");
 +      if (o->trivial_merges_only && o->nontrivial_merge) {
 +              ret = unpack_failed(o, "Merge requires file-level merging");
 +              goto done;
 +      }
 +
 +      if (!o->skip_sparse_checkout) {
 +              int empty_worktree = 1;
 +              for (i = 0;i < o->result.cache_nr;i++) {
 +                      struct cache_entry *ce = o->result.cache[i];
 +
 +                      if (apply_sparse_checkout(ce, o)) {
 +                              ret = -1;
 +                              goto done;
 +                      }
 +                      /*
 +                       * Merge strategies may set CE_UPDATE|CE_REMOVE outside checkout
 +                       * area as a result of ce_skip_worktree() shortcuts in
 +                       * verify_absent() and verify_uptodate(). Clear them.
 +                       */
 +                      if (ce_skip_worktree(ce))
 +                              ce->ce_flags &= ~(CE_UPDATE | CE_REMOVE);
 +                      else
 +                              empty_worktree = 0;
 +
 +              }
 +              if (o->result.cache_nr && empty_worktree) {
 +                      ret = unpack_failed(o, "Sparse checkout leaves no entry on working directory");
 +                      goto done;
 +              }
 +      }
  
        o->src_index = NULL;
        ret = check_updates(o) ? (-2) : 0;
        if (o->dst_index)
                *o->dst_index = o->result;
 +
 +done:
 +      for (i = 0;i < el.nr;i++)
 +              free(el.excludes[i]);
 +      if (el.excludes)
 +              free(el.excludes);
 +
        return ret;
 -      return unpack_failed(o, NULL);
+ return_failed:
+       mark_all_ce_unused(o->src_index);
++      ret = unpack_failed(o, NULL);
++      goto done;
  }
  
  /* Here come the merge functions */
diff --cc unpack-trees.h
index 95ff36c824a14a24234459ad552306fb1b5dabf1,701dca59a8e828cae78c394783ff8d6f8404a5f1..ef70eab39025fcdaccda059692ae447a13fa0aeb
@@@ -31,10 -28,10 +31,11 @@@ struct unpack_trees_options 
                     skip_unmerged,
                     initial_checkout,
                     diff_index_cached,
+                    debug_unpack,
 +                   skip_sparse_checkout,
                     gently;
        const char *prefix;
-       int pos;
+       int cache_bottom;
        struct dir_struct *dir;
        merge_fn_t fn;
        struct unpack_trees_error_msgs msgs;