summaryrefslogtreecommitdiff
path: root/unpack-trees.c
diff options
context:
space:
mode:
Diffstat (limited to 'unpack-trees.c')
-rw-r--r--unpack-trees.c95
1 files changed, 55 insertions, 40 deletions
diff --git a/unpack-trees.c b/unpack-trees.c
index 1ca41b1..07f8364 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -16,7 +16,7 @@
* situation better. See how "git checkout" and "git merge" replaces
* them using setup_unpack_trees_porcelain(), for example.
*/
-const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
+static const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
/* ERROR_WOULD_OVERWRITE */
"Entry '%s' would be overwritten by merge. Cannot merge.",
@@ -203,7 +203,7 @@ static int check_updates(struct unpack_trees_options *o)
if (ce->ce_flags & CE_WT_REMOVE) {
display_progress(progress, ++cnt);
- if (o->update)
+ if (o->update && !o->dry_run)
unlink_entry(ce);
continue;
}
@@ -217,7 +217,7 @@ static int check_updates(struct unpack_trees_options *o)
if (ce->ce_flags & CE_UPDATE) {
display_progress(progress, ++cnt);
ce->ce_flags &= ~CE_UPDATE;
- if (o->update) {
+ if (o->update && !o->dry_run) {
errs |= checkout_entry(ce, &state, NULL);
}
}
@@ -381,7 +381,7 @@ static void add_same_unmerged(struct cache_entry *ce,
static int unpack_index_entry(struct cache_entry *ce,
struct unpack_trees_options *o)
{
- struct cache_entry *src[5] = { NULL };
+ struct cache_entry *src[MAX_UNPACK_TREES + 1] = { NULL, };
int ret;
src[0] = ce;
@@ -427,7 +427,10 @@ static int switch_cache_bottom(struct traverse_info *info)
return ret;
}
-static int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long df_conflicts, struct name_entry *names, struct traverse_info *info)
+static int traverse_trees_recursive(int n, unsigned long dirmask,
+ unsigned long df_conflicts,
+ struct name_entry *names,
+ struct traverse_info *info)
{
int i, ret, bottom;
struct tree_desc t[MAX_UNPACK_TREES];
@@ -811,43 +814,45 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
return mask;
}
+static int clear_ce_flags_1(struct cache_entry **cache, int nr,
+ char *prefix, int prefix_len,
+ int select_mask, int clear_mask,
+ struct exclude_list *el, int defval);
+
/* Whole directory matching */
static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
char *prefix, int prefix_len,
char *basename,
int select_mask, int clear_mask,
- struct exclude_list *el)
+ struct exclude_list *el, int defval)
{
- struct cache_entry **cache_end = cache + nr;
+ struct cache_entry **cache_end;
int dtype = DT_DIR;
int ret = excluded_from_list(prefix, prefix_len, basename, &dtype, el);
prefix[prefix_len++] = '/';
- /* included, no clearing for any entries under this directory */
- if (!ret) {
- for (; cache != cache_end; cache++) {
- struct cache_entry *ce = *cache;
- if (strncmp(ce->name, prefix, prefix_len))
- break;
- }
- return nr - (cache_end - cache);
- }
+ /* If undecided, use matching result of parent dir in defval */
+ if (ret < 0)
+ ret = defval;
- /* excluded, clear all selected entries under this directory. */
- if (ret == 1) {
- for (; cache != cache_end; cache++) {
- struct cache_entry *ce = *cache;
- if (select_mask && !(ce->ce_flags & select_mask))
- continue;
- if (strncmp(ce->name, prefix, prefix_len))
- break;
- ce->ce_flags &= ~clear_mask;
- }
- return nr - (cache_end - cache);
+ for (cache_end = cache; cache_end != cache + nr; cache_end++) {
+ struct cache_entry *ce = *cache_end;
+ if (strncmp(ce->name, prefix, prefix_len))
+ break;
}
- return 0;
+ /*
+ * TODO: check el, if there are no patterns that may conflict
+ * with ret (iow, we know in advance the incl/excl
+ * decision for the entire directory), clear flag here without
+ * calling clear_ce_flags_1(). That function will call
+ * the expensive excluded_from_list() on every entry.
+ */
+ return clear_ce_flags_1(cache, cache_end - cache,
+ prefix, prefix_len,
+ select_mask, clear_mask,
+ el, ret);
}
/*
@@ -868,7 +873,7 @@ static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
static int clear_ce_flags_1(struct cache_entry **cache, int nr,
char *prefix, int prefix_len,
int select_mask, int clear_mask,
- struct exclude_list *el)
+ struct exclude_list *el, int defval)
{
struct cache_entry **cache_end = cache + nr;
@@ -879,7 +884,7 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
while(cache != cache_end) {
struct cache_entry *ce = *cache;
const char *name, *slash;
- int len, dtype;
+ int len, dtype, ret;
if (select_mask && !(ce->ce_flags & select_mask)) {
cache++;
@@ -908,7 +913,7 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
prefix, prefix_len + len,
prefix + prefix_len,
select_mask, clear_mask,
- el);
+ el, defval);
/* clear_c_f_dir eats a whole dir already? */
if (processed) {
@@ -919,13 +924,16 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
prefix[prefix_len + len++] = '/';
cache += clear_ce_flags_1(cache, cache_end - cache,
prefix, prefix_len + len,
- select_mask, clear_mask, el);
+ select_mask, clear_mask, el, defval);
continue;
}
/* Non-directory */
dtype = ce_to_dtype(ce);
- if (excluded_from_list(ce->name, ce_namelen(ce), name, &dtype, el) > 0)
+ ret = excluded_from_list(ce->name, ce_namelen(ce), name, &dtype, el);
+ if (ret < 0)
+ ret = defval;
+ if (ret > 0)
ce->ce_flags &= ~clear_mask;
cache++;
}
@@ -940,7 +948,7 @@ static int clear_ce_flags(struct cache_entry **cache, int nr,
return clear_ce_flags_1(cache, nr,
prefix, 0,
select_mask, clear_mask,
- el);
+ el, 0);
}
/*
@@ -1105,6 +1113,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
}
if (o->result.cache_nr && empty_worktree) {
+ /* dubious---why should this fail??? */
ret = unpack_failed(o, "Sparse checkout leaves no entry on working directory");
goto done;
}
@@ -1374,16 +1383,22 @@ static int verify_absent_1(struct cache_entry *ce,
char path[PATH_MAX + 1];
memcpy(path, ce->name, len);
path[len] = 0;
- lstat(path, &st);
+ if (lstat(path, &st))
+ return error("cannot stat '%s': %s", path,
+ strerror(errno));
return check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st,
error_type, o);
- } else if (!lstat(ce->name, &st))
+ } else if (lstat(ce->name, &st)) {
+ if (errno != ENOENT)
+ return error("cannot stat '%s': %s", ce->name,
+ strerror(errno));
+ return 0;
+ } else {
return check_ok_to_remove(ce->name, ce_namelen(ce),
- ce_to_dtype(ce), ce, &st,
- error_type, o);
-
- return 0;
+ ce_to_dtype(ce), ce, &st,
+ error_type, o);
+ }
}
static int verify_absent(struct cache_entry *ce,