* 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, char *last_symlink)
+static void unlink_entry(struct cache_entry *ce)
{
char *cp, *prev;
+ char *name = ce->name;
- if (has_symlink_leading_path(name, last_symlink))
+ if (has_symlink_leading_path(ce_namelen(ce), ce->name))
return;
if (unlink(name))
return;
}
static struct checkout state;
-static void check_updates(struct unpack_trees_options *o)
+static int check_updates(struct unpack_trees_options *o)
{
unsigned cnt = 0, total = 0;
struct progress *progress = NULL;
- char last_symlink[PATH_MAX];
struct index_state *index = &o->result;
int i;
+ int errs = 0;
if (o->update && o->verbose_update) {
for (total = cnt = 0; cnt < index->cache_nr; cnt++) {
cnt = 0;
}
- *last_symlink = '\0';
for (i = 0; i < index->cache_nr; i++) {
struct cache_entry *ce = index->cache[i];
- if (ce->ce_flags & (CE_UPDATE | CE_REMOVE))
- display_progress(progress, ++cnt);
if (ce->ce_flags & CE_REMOVE) {
+ display_progress(progress, ++cnt);
if (o->update)
- unlink_entry(ce->name, last_symlink);
+ unlink_entry(ce);
remove_index_entry_at(&o->result, i);
i--;
continue;
}
+ }
+
+ for (i = 0; i < index->cache_nr; i++) {
+ struct cache_entry *ce = index->cache[i];
+
if (ce->ce_flags & CE_UPDATE) {
+ display_progress(progress, ++cnt);
ce->ce_flags &= ~CE_UPDATE;
if (o->update) {
- checkout_entry(ce, &state, NULL);
- *last_symlink = '\0';
+ errs |= checkout_entry(ce, &state, NULL);
}
}
}
stop_progress(&progress);
+ return errs != 0;
}
static inline int call_unpack_fn(struct cache_entry **src, struct unpack_trees_options *o)
add_entry(o, ce, 0, 0);
return 0;
}
- return 0;
}
return call_unpack_fn(src, o);
}
int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long df_conflicts, struct name_entry *names, struct traverse_info *info)
{
int i;
- struct tree_desc t[3];
+ struct tree_desc t[MAX_UNPACK_TREES];
struct traverse_info newinfo;
struct name_entry *p;
sha1 = names[i].sha1;
fill_tree_descriptor(t+i, sha1);
}
- traverse_trees(n, t, &newinfo);
- return 0;
+ return traverse_trees(n, t, &newinfo);
}
/*
add_entry(o, ce, 0, 0);
return mask;
}
- continue;
}
src[0] = ce;
}
if (src[0])
conflicts |= 1;
}
- traverse_trees_recursive(n, dirmask, conflicts, names, info);
+ if (traverse_trees_recursive(n, dirmask, conflicts,
+ names, info) < 0)
+ return -1;
return mask;
}
static int unpack_failed(struct unpack_trees_options *o, const char *message)
{
+ discard_index(&o->result);
if (!o->gently) {
if (message)
return error(message);
{
static struct cache_entry *dfc;
- if (len > 4)
- die("unpack_trees takes at most four trees");
+ if (len > MAX_UNPACK_TREES)
+ die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
memset(&state, 0, sizeof(state));
state.base_dir = "";
state.force = 1;
state.refresh_cache = 1;
memset(&o->result, 0, sizeof(o->result));
+ if (o->src_index)
+ o->result.timestamp = o->src_index->timestamp;
o->merge_size = len;
if (!dfc)
return unpack_failed(o, "Merge requires file-level merging");
o->src_index = NULL;
- check_updates(o);
+ if (check_updates(o))
+ return -1;
if (o->dst_index)
*o->dst_index = o->result;
return 0;
return cnt;
}
+/*
+ * This gets called when there was no index entry for the tree entry 'dst',
+ * but we found a file in the working tree that 'lstat()' said was fine,
+ * and we're on a case-insensitive filesystem.
+ *
+ * See if we can find a case-insensitive match in the index that also
+ * matches the stat information, and assume it's that other file!
+ */
+static int icase_exists(struct unpack_trees_options *o, struct cache_entry *dst, struct stat *st)
+{
+ struct cache_entry *src;
+
+ src = index_name_exists(o->src_index, dst->name, ce_namelen(dst), 1);
+ return src && !ie_match_stat(o->src_index, src, st, CE_MATCH_IGNORE_VALID);
+}
+
/*
* We do not want to remove or overwrite a working tree file that
* is not tracked, unless it is ignored.
if (o->index_only || o->reset || !o->update)
return 0;
- if (has_symlink_leading_path(ce->name, NULL))
+ if (has_symlink_leading_path(ce_namelen(ce), ce->name))
return 0;
if (!lstat(ce->name, &st)) {
int cnt;
int dtype = ce_to_dtype(ce);
+ struct cache_entry *result;
+
+ /*
+ * It may be that the 'lstat()' succeeded even though
+ * target 'ce' was absent, because there is an old
+ * entry that is different only in case..
+ *
+ * Ignore that lstat() if it matches.
+ */
+ if (ignore_case && icase_exists(o, ce, &st))
+ return 0;
if (o->dir && excluded(o->dir, ce->name, &dtype))
/*
* delete this path, which is in a subdirectory that
* is being replaced with a blob.
*/
- cnt = index_name_pos(&o->result, ce->name, strlen(ce->name));
- if (0 <= cnt) {
- struct cache_entry *ce = o->result.cache[cnt];
- if (ce->ce_flags & CE_REMOVE)
+ result = index_name_exists(&o->result, ce->name, ce_namelen(ce), 0);
+ if (result) {
+ if (result->ce_flags & CE_REMOVE)
return 0;
}
static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
struct unpack_trees_options *o)
{
+ int update = CE_UPDATE;
+
if (old) {
/*
* See if we can re-use the old CE directly?
* That way we get the uptodate stat info.
*
- * This also removes the UPDATE flag on
- * a match.
+ * This also removes the UPDATE flag on a match; otherwise
+ * we will end up overwriting local changes in the work tree.
*/
if (same(old, merge)) {
copy_cache_entry(merge, old);
+ update = 0;
} else {
if (verify_uptodate(old, o))
return -1;
invalidate_ce_path(merge, o);
}
- add_entry(o, merge, CE_UPDATE, CE_STAGEMASK);
+ add_entry(o, merge, update, CE_STAGEMASK);
return 1;
}