Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 6d011b8

Browse files
committed
Merge branch 'bk/refresh-missing-ok-in-merge-recursive' into maint
"merge-recursive" was broken in 1.7.7 era and stopped working in an empty (temporary) working tree, when there are renames involved. This has been corrected. * 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
2 parents c7b3173 + 6e2068a commit 6d011b8

File tree

4 files changed

+70
-14
lines changed

4 files changed

+70
-14
lines changed

cache.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ extern int remove_file_from_index(struct index_state *, const char *path);
487487
#define ADD_CACHE_IMPLICIT_DOT 32 /* internal to "git add -u/-A" */
488488
extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
489489
extern int add_file_to_index(struct index_state *, const char *path, int flags);
490-
extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh);
490+
extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, unsigned int refresh_options);
491491
extern int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
492492
extern int index_name_is_other(const struct index_state *, const char *, int);
493493
extern void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *);
@@ -498,6 +498,10 @@ extern void *read_blob_data_from_index(struct index_state *, const char *, unsig
498498
#define CE_MATCH_RACY_IS_DIRTY 02
499499
/* do stat comparison even if CE_SKIP_WORKTREE is true */
500500
#define CE_MATCH_IGNORE_SKIP_WORKTREE 04
501+
/* ignore non-existent files during stat update */
502+
#define CE_MATCH_IGNORE_MISSING 0x08
503+
/* enable stat refresh */
504+
#define CE_MATCH_REFRESH 0x10
501505
extern int ie_match_stat(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
502506
extern int ie_modified(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
503507

merge-recursive.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
201201
const char *path, int stage, int refresh, int options)
202202
{
203203
struct cache_entry *ce;
204-
ce = make_cache_entry(mode, sha1 ? sha1 : null_sha1, path, stage, refresh);
204+
ce = make_cache_entry(mode, sha1 ? sha1 : null_sha1, path, stage,
205+
(refresh ? (CE_MATCH_REFRESH |
206+
CE_MATCH_IGNORE_MISSING) : 0 ));
205207
if (!ce)
206208
return error(_("addinfo_cache failed for path '%s'"), path);
207209
return add_cache_entry(ce, options);

read-cache.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
#include "strbuf.h"
1616
#include "varint.h"
1717

18-
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really);
18+
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
19+
unsigned int options);
1920

2021
/* Mask for the name length in ce_flags in the on-disk index */
2122

@@ -696,7 +697,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags)
696697

697698
struct cache_entry *make_cache_entry(unsigned int mode,
698699
const unsigned char *sha1, const char *path, int stage,
699-
int refresh)
700+
unsigned int refresh_options)
700701
{
701702
int size, len;
702703
struct cache_entry *ce;
@@ -716,10 +717,7 @@ struct cache_entry *make_cache_entry(unsigned int mode,
716717
ce->ce_namelen = len;
717718
ce->ce_mode = create_ce_mode(mode);
718719

719-
if (refresh)
720-
return refresh_cache_entry(ce, 0);
721-
722-
return ce;
720+
return refresh_cache_entry(ce, refresh_options);
723721
}
724722

725723
int ce_same_name(const struct cache_entry *a, const struct cache_entry *b)
@@ -1024,10 +1022,12 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
10241022
struct stat st;
10251023
struct cache_entry *updated;
10261024
int changed, size;
1025+
int refresh = options & CE_MATCH_REFRESH;
10271026
int ignore_valid = options & CE_MATCH_IGNORE_VALID;
10281027
int ignore_skip_worktree = options & CE_MATCH_IGNORE_SKIP_WORKTREE;
1028+
int ignore_missing = options & CE_MATCH_IGNORE_MISSING;
10291029

1030-
if (ce_uptodate(ce))
1030+
if (!refresh || ce_uptodate(ce))
10311031
return ce;
10321032

10331033
/*
@@ -1045,6 +1045,8 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
10451045
}
10461046

10471047
if (lstat(ce->name, &st) < 0) {
1048+
if (ignore_missing && errno == ENOENT)
1049+
return ce;
10481050
if (err)
10491051
*err = errno;
10501052
return NULL;
@@ -1122,7 +1124,9 @@ int refresh_index(struct index_state *istate, unsigned int flags,
11221124
int ignore_submodules = (flags & REFRESH_IGNORE_SUBMODULES) != 0;
11231125
int first = 1;
11241126
int in_porcelain = (flags & REFRESH_IN_PORCELAIN);
1125-
unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0;
1127+
unsigned int options = (CE_MATCH_REFRESH |
1128+
(really ? CE_MATCH_IGNORE_VALID : 0) |
1129+
(not_new ? CE_MATCH_IGNORE_MISSING : 0));
11261130
const char *modified_fmt;
11271131
const char *deleted_fmt;
11281132
const char *typechange_fmt;
@@ -1170,8 +1174,6 @@ int refresh_index(struct index_state *istate, unsigned int flags,
11701174
if (!new) {
11711175
const char *fmt;
11721176

1173-
if (not_new && cache_errno == ENOENT)
1174-
continue;
11751177
if (really && cache_errno == EINVAL) {
11761178
/* If we are doing --really-refresh that
11771179
* means the index is not valid anymore.
@@ -1201,9 +1203,10 @@ int refresh_index(struct index_state *istate, unsigned int flags,
12011203
return has_errors;
12021204
}
12031205

1204-
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really)
1206+
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
1207+
unsigned int options)
12051208
{
1206-
return refresh_cache_ent(&the_index, ce, really, NULL, NULL);
1209+
return refresh_cache_ent(&the_index, ce, options, NULL, NULL);
12071210
}
12081211

12091212

t/t3030-merge-recursive.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ test_expect_success 'setup 8' '
257257
git add e &&
258258
test_tick &&
259259
git commit -m "rename a->e" &&
260+
c7=$(git rev-parse --verify HEAD) &&
260261
git checkout rename-ln &&
261262
git mv a e &&
262263
test_ln_s_add e a &&
@@ -517,6 +518,52 @@ test_expect_success 'reset and bind merge' '
517518
518519
'
519520

521+
test_expect_success 'merge-recursive w/ empty work tree - ours has rename' '
522+
(
523+
GIT_WORK_TREE="$PWD/ours-has-rename-work" &&
524+
export GIT_WORK_TREE &&
525+
GIT_INDEX_FILE="$PWD/ours-has-rename-index" &&
526+
export GIT_INDEX_FILE &&
527+
mkdir "$GIT_WORK_TREE" &&
528+
git read-tree -i -m $c7 &&
529+
git update-index --ignore-missing --refresh &&
530+
git merge-recursive $c0 -- $c7 $c3 &&
531+
git ls-files -s >actual-files
532+
) 2>actual-err &&
533+
>expected-err &&
534+
cat >expected-files <<-EOF &&
535+
100644 $o3 0 b/c
536+
100644 $o0 0 c
537+
100644 $o0 0 d/e
538+
100644 $o0 0 e
539+
EOF
540+
test_cmp expected-files actual-files &&
541+
test_cmp expected-err actual-err
542+
'
543+
544+
test_expect_success 'merge-recursive w/ empty work tree - theirs has rename' '
545+
(
546+
GIT_WORK_TREE="$PWD/theirs-has-rename-work" &&
547+
export GIT_WORK_TREE &&
548+
GIT_INDEX_FILE="$PWD/theirs-has-rename-index" &&
549+
export GIT_INDEX_FILE &&
550+
mkdir "$GIT_WORK_TREE" &&
551+
git read-tree -i -m $c3 &&
552+
git update-index --ignore-missing --refresh &&
553+
git merge-recursive $c0 -- $c3 $c7 &&
554+
git ls-files -s >actual-files
555+
) 2>actual-err &&
556+
>expected-err &&
557+
cat >expected-files <<-EOF &&
558+
100644 $o3 0 b/c
559+
100644 $o0 0 c
560+
100644 $o0 0 d/e
561+
100644 $o0 0 e
562+
EOF
563+
test_cmp expected-files actual-files &&
564+
test_cmp expected-err actual-err
565+
'
566+
520567
test_expect_success 'merge removes empty directories' '
521568
522569
git reset --hard master &&

0 commit comments

Comments
 (0)