Merge branch 'bk/refresh-missing-ok-in-merge-recursive'

Allow "merge-recursive" to work in an empty (temporary) working
tree again when there are renames involved, correcting an old
regression in 1.7.7 era.

* bk/refresh-missing-ok-in-merge-recursive:
  merge-recursive.c: tolerate missing files while refreshing index
  read-cache.c: extend make_cache_entry refresh flag with options
  read-cache.c: refactor --ignore-missing implementation
  t3030-merge-recursive: test known breakage with empty work tree
This commit is contained in:
Junio C Hamano
2014-02-27 14:01:14 -08:00
4 changed files with 70 additions and 14 deletions

View File

@ -15,7 +15,8 @@
#include "strbuf.h"
#include "varint.h"
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really);
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
unsigned int options);
/* Mask for the name length in ce_flags in the on-disk index */
@ -700,7 +701,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags)
struct cache_entry *make_cache_entry(unsigned int mode,
const unsigned char *sha1, const char *path, int stage,
int refresh)
unsigned int refresh_options)
{
int size, len;
struct cache_entry *ce;
@ -720,10 +721,7 @@ struct cache_entry *make_cache_entry(unsigned int mode,
ce->ce_namelen = len;
ce->ce_mode = create_ce_mode(mode);
if (refresh)
return refresh_cache_entry(ce, 0);
return ce;
return refresh_cache_entry(ce, refresh_options);
}
int ce_same_name(const struct cache_entry *a, const struct cache_entry *b)
@ -1033,10 +1031,12 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
struct stat st;
struct cache_entry *updated;
int changed, size;
int refresh = options & CE_MATCH_REFRESH;
int ignore_valid = options & CE_MATCH_IGNORE_VALID;
int ignore_skip_worktree = options & CE_MATCH_IGNORE_SKIP_WORKTREE;
int ignore_missing = options & CE_MATCH_IGNORE_MISSING;
if (ce_uptodate(ce))
if (!refresh || ce_uptodate(ce))
return ce;
/*
@ -1054,6 +1054,8 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
}
if (lstat(ce->name, &st) < 0) {
if (ignore_missing && errno == ENOENT)
return ce;
if (err)
*err = errno;
return NULL;
@ -1131,7 +1133,9 @@ int refresh_index(struct index_state *istate, unsigned int flags,
int ignore_submodules = (flags & REFRESH_IGNORE_SUBMODULES) != 0;
int first = 1;
int in_porcelain = (flags & REFRESH_IN_PORCELAIN);
unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0;
unsigned int options = (CE_MATCH_REFRESH |
(really ? CE_MATCH_IGNORE_VALID : 0) |
(not_new ? CE_MATCH_IGNORE_MISSING : 0));
const char *modified_fmt;
const char *deleted_fmt;
const char *typechange_fmt;
@ -1180,8 +1184,6 @@ int refresh_index(struct index_state *istate, unsigned int flags,
if (!new) {
const char *fmt;
if (not_new && cache_errno == ENOENT)
continue;
if (really && cache_errno == EINVAL) {
/* If we are doing --really-refresh that
* means the index is not valid anymore.
@ -1211,9 +1213,10 @@ int refresh_index(struct index_state *istate, unsigned int flags,
return has_errors;
}
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really)
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
unsigned int options)
{
return refresh_cache_ent(&the_index, ce, really, NULL, NULL);
return refresh_cache_ent(&the_index, ce, options, NULL, NULL);
}