Merge branch 'tb/reset-shallow'
Fix in-core inconsistency after fetching into a shallow repository that broke the code to write out commit-graph. * tb/reset-shallow: shallow.c: use '{commit,rollback}_shallow_file' t5537: use test_write_lines and indented heredocs for readability
This commit is contained in:
commit
2b4ff3d3dc
@ -893,12 +893,12 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
|
||||
opt.env = tmp_objdir_env(tmp_objdir);
|
||||
setup_alternate_shallow(&shallow_lock, &opt.shallow_file, &extra);
|
||||
if (check_connected(command_singleton_iterator, cmd, &opt)) {
|
||||
rollback_lock_file(&shallow_lock);
|
||||
rollback_shallow_file(the_repository, &shallow_lock);
|
||||
oid_array_clear(&extra);
|
||||
return -1;
|
||||
}
|
||||
|
||||
commit_lock_file(&shallow_lock);
|
||||
commit_shallow_file(the_repository, &shallow_lock);
|
||||
|
||||
/*
|
||||
* Make sure setup_alternate_shallow() for the next ref does
|
||||
|
2
commit.h
2
commit.h
@ -249,6 +249,8 @@ struct oid_array;
|
||||
struct ref;
|
||||
int register_shallow(struct repository *r, const struct object_id *oid);
|
||||
int unregister_shallow(const struct object_id *oid);
|
||||
int commit_shallow_file(struct repository *r, struct lock_file *lk);
|
||||
void rollback_shallow_file(struct repository *r, struct lock_file *lk);
|
||||
int for_each_commit_graft(each_commit_graft_fn, void *);
|
||||
int is_repository_shallow(struct repository *r);
|
||||
struct commit_list *get_shallow_commits(struct object_array *heads,
|
||||
|
10
fetch-pack.c
10
fetch-pack.c
@ -1629,9 +1629,9 @@ static void update_shallow(struct fetch_pack_args *args,
|
||||
if (args->deepen && alternate_shallow_file) {
|
||||
if (*alternate_shallow_file == '\0') { /* --unshallow */
|
||||
unlink_or_warn(git_path_shallow(the_repository));
|
||||
rollback_lock_file(&shallow_lock);
|
||||
rollback_shallow_file(the_repository, &shallow_lock);
|
||||
} else
|
||||
commit_lock_file(&shallow_lock);
|
||||
commit_shallow_file(the_repository, &shallow_lock);
|
||||
alternate_shallow_file = NULL;
|
||||
return;
|
||||
}
|
||||
@ -1655,7 +1655,7 @@ static void update_shallow(struct fetch_pack_args *args,
|
||||
setup_alternate_shallow(&shallow_lock,
|
||||
&alternate_shallow_file,
|
||||
&extra);
|
||||
commit_lock_file(&shallow_lock);
|
||||
commit_shallow_file(the_repository, &shallow_lock);
|
||||
alternate_shallow_file = NULL;
|
||||
}
|
||||
oid_array_clear(&extra);
|
||||
@ -1693,7 +1693,7 @@ static void update_shallow(struct fetch_pack_args *args,
|
||||
setup_alternate_shallow(&shallow_lock,
|
||||
&alternate_shallow_file,
|
||||
&extra);
|
||||
commit_lock_file(&shallow_lock);
|
||||
commit_shallow_file(the_repository, &shallow_lock);
|
||||
oid_array_clear(&extra);
|
||||
oid_array_clear(&ref);
|
||||
alternate_shallow_file = NULL;
|
||||
@ -1785,7 +1785,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
|
||||
error(_("remote did not send all necessary objects"));
|
||||
free_refs(ref_cpy);
|
||||
ref_cpy = NULL;
|
||||
rollback_lock_file(&shallow_lock);
|
||||
rollback_shallow_file(the_repository, &shallow_lock);
|
||||
goto cleanup;
|
||||
}
|
||||
args->connectivity_checked = 1;
|
||||
|
30
shallow.c
30
shallow.c
@ -40,13 +40,6 @@ int register_shallow(struct repository *r, const struct object_id *oid)
|
||||
|
||||
int is_repository_shallow(struct repository *r)
|
||||
{
|
||||
/*
|
||||
* NEEDSWORK: This function updates
|
||||
* r->parsed_objects->{is_shallow,shallow_stat} as a side effect but
|
||||
* there is no corresponding function to clear them when the shallow
|
||||
* file is updated.
|
||||
*/
|
||||
|
||||
FILE *fp;
|
||||
char buf[1024];
|
||||
const char *path = r->parsed_objects->alternate_shallow_file;
|
||||
@ -79,6 +72,25 @@ int is_repository_shallow(struct repository *r)
|
||||
return r->parsed_objects->is_shallow;
|
||||
}
|
||||
|
||||
static void reset_repository_shallow(struct repository *r)
|
||||
{
|
||||
r->parsed_objects->is_shallow = -1;
|
||||
stat_validity_clear(r->parsed_objects->shallow_stat);
|
||||
}
|
||||
|
||||
int commit_shallow_file(struct repository *r, struct lock_file *lk)
|
||||
{
|
||||
int res = commit_lock_file(lk);
|
||||
reset_repository_shallow(r);
|
||||
return res;
|
||||
}
|
||||
|
||||
void rollback_shallow_file(struct repository *r, struct lock_file *lk)
|
||||
{
|
||||
rollback_lock_file(lk);
|
||||
reset_repository_shallow(r);
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: use "int" elemtype instead of "int *" when/if commit-slab
|
||||
* supports a "valid" flag.
|
||||
@ -410,10 +422,10 @@ void prune_shallow(unsigned options)
|
||||
if (write_in_full(fd, sb.buf, sb.len) < 0)
|
||||
die_errno("failed to write to %s",
|
||||
get_lock_file_path(&shallow_lock));
|
||||
commit_lock_file(&shallow_lock);
|
||||
commit_shallow_file(the_repository, &shallow_lock);
|
||||
} else {
|
||||
unlink(git_path_shallow(the_repository));
|
||||
rollback_lock_file(&shallow_lock);
|
||||
rollback_shallow_file(the_repository, &shallow_lock);
|
||||
}
|
||||
strbuf_release(&sb);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ test_expect_success 'setup' '
|
||||
commit 3 &&
|
||||
commit 4 &&
|
||||
git config --global transfer.fsckObjects true &&
|
||||
test_oid_cache <<-EOF
|
||||
test_oid_cache <<-\EOF
|
||||
perl sha1:s/0034shallow %s/0036unshallow %s/
|
||||
perl sha256:s/004cshallow %s/004eunshallow %s/
|
||||
EOF
|
||||
@ -25,10 +25,7 @@ test_expect_success 'setup' '
|
||||
test_expect_success 'setup shallow clone' '
|
||||
git clone --no-local --depth=2 .git shallow &&
|
||||
git --git-dir=shallow/.git log --format=%s >actual &&
|
||||
cat <<EOF >expect &&
|
||||
4
|
||||
3
|
||||
EOF
|
||||
test_write_lines 4 3 >expect &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
@ -38,10 +35,7 @@ test_expect_success 'clone from shallow clone' '
|
||||
cd shallow2 &&
|
||||
git fsck &&
|
||||
git log --format=%s >actual &&
|
||||
cat <<EOF >expect &&
|
||||
4
|
||||
3
|
||||
EOF
|
||||
test_write_lines 4 3 >expect &&
|
||||
test_cmp expect actual
|
||||
)
|
||||
'
|
||||
@ -56,11 +50,7 @@ test_expect_success 'fetch from shallow clone' '
|
||||
git fetch &&
|
||||
git fsck &&
|
||||
git log --format=%s origin/master >actual &&
|
||||
cat <<EOF >expect &&
|
||||
5
|
||||
4
|
||||
3
|
||||
EOF
|
||||
test_write_lines 5 4 3 >expect &&
|
||||
test_cmp expect actual
|
||||
)
|
||||
'
|
||||
@ -75,10 +65,7 @@ test_expect_success 'fetch --depth from shallow clone' '
|
||||
git fetch --depth=2 &&
|
||||
git fsck &&
|
||||
git log --format=%s origin/master >actual &&
|
||||
cat <<EOF >expect &&
|
||||
6
|
||||
5
|
||||
EOF
|
||||
test_write_lines 6 5 >expect &&
|
||||
test_cmp expect actual
|
||||
)
|
||||
'
|
||||
@ -89,12 +76,7 @@ test_expect_success 'fetch --unshallow from shallow clone' '
|
||||
git fetch --unshallow &&
|
||||
git fsck &&
|
||||
git log --format=%s origin/master >actual &&
|
||||
cat <<EOF >expect &&
|
||||
6
|
||||
5
|
||||
4
|
||||
3
|
||||
EOF
|
||||
test_write_lines 6 5 4 3 >expect &&
|
||||
test_cmp expect actual
|
||||
)
|
||||
'
|
||||
@ -111,15 +93,10 @@ test_expect_success 'fetch something upstream has but hidden by clients shallow
|
||||
git fetch ../.git +refs/heads/master:refs/remotes/top/master &&
|
||||
git fsck &&
|
||||
git log --format=%s top/master >actual &&
|
||||
cat <<EOF >expect &&
|
||||
add-1-back
|
||||
4
|
||||
3
|
||||
EOF
|
||||
test_write_lines add-1-back 4 3 >expect &&
|
||||
test_cmp expect actual
|
||||
) &&
|
||||
git --git-dir=shallow2/.git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null
|
||||
|
||||
'
|
||||
|
||||
test_expect_success 'fetch that requires changes in .git/shallow is filtered' '
|
||||
@ -133,14 +110,10 @@ test_expect_success 'fetch that requires changes in .git/shallow is filtered' '
|
||||
cd notshallow &&
|
||||
git fetch ../shallow/.git refs/heads/*:refs/remotes/shallow/* &&
|
||||
git for-each-ref --format="%(refname)" >actual.refs &&
|
||||
cat <<EOF >expect.refs &&
|
||||
refs/remotes/shallow/no-shallow
|
||||
EOF
|
||||
echo refs/remotes/shallow/no-shallow >expect.refs &&
|
||||
test_cmp expect.refs actual.refs &&
|
||||
git log --format=%s shallow/no-shallow >actual &&
|
||||
cat <<EOF >expect &&
|
||||
no-shallow
|
||||
EOF
|
||||
echo no-shallow >expect &&
|
||||
test_cmp expect actual
|
||||
)
|
||||
'
|
||||
@ -158,21 +131,44 @@ test_expect_success 'fetch --update-shallow' '
|
||||
git fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* &&
|
||||
git fsck &&
|
||||
git for-each-ref --sort=refname --format="%(refname)" >actual.refs &&
|
||||
cat <<EOF >expect.refs &&
|
||||
refs/remotes/shallow/master
|
||||
refs/remotes/shallow/no-shallow
|
||||
refs/tags/heavy-tag
|
||||
refs/tags/light-tag
|
||||
EOF
|
||||
cat <<-\EOF >expect.refs &&
|
||||
refs/remotes/shallow/master
|
||||
refs/remotes/shallow/no-shallow
|
||||
refs/tags/heavy-tag
|
||||
refs/tags/light-tag
|
||||
EOF
|
||||
test_cmp expect.refs actual.refs &&
|
||||
git log --format=%s shallow/master >actual &&
|
||||
cat <<EOF >expect &&
|
||||
7
|
||||
6
|
||||
5
|
||||
4
|
||||
3
|
||||
EOF
|
||||
test_write_lines 7 6 5 4 3 >expect &&
|
||||
test_cmp expect actual
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'fetch --update-shallow (with fetch.writeCommitGraph)' '
|
||||
(
|
||||
cd shallow &&
|
||||
git checkout master &&
|
||||
commit 8 &&
|
||||
git tag -m foo heavy-tag-for-graph HEAD^ &&
|
||||
git tag light-tag-for-graph HEAD^:tracked
|
||||
) &&
|
||||
test_config -C notshallow fetch.writeCommitGraph true &&
|
||||
(
|
||||
cd notshallow &&
|
||||
git fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* &&
|
||||
git fsck &&
|
||||
git for-each-ref --sort=refname --format="%(refname)" >actual.refs &&
|
||||
cat <<-EOF >expect.refs &&
|
||||
refs/remotes/shallow/master
|
||||
refs/remotes/shallow/no-shallow
|
||||
refs/tags/heavy-tag
|
||||
refs/tags/heavy-tag-for-graph
|
||||
refs/tags/light-tag
|
||||
refs/tags/light-tag-for-graph
|
||||
EOF
|
||||
test_cmp expect.refs actual.refs &&
|
||||
git log --format=%s shallow/master >actual &&
|
||||
test_write_lines 8 7 6 5 4 3 >expect &&
|
||||
test_cmp expect actual
|
||||
)
|
||||
'
|
||||
@ -183,10 +179,7 @@ test_expect_success POSIXPERM,SANITY 'shallow fetch from a read-only repo' '
|
||||
find read-only.git -print | xargs chmod -w &&
|
||||
git clone --no-local --depth=2 read-only.git from-read-only &&
|
||||
git --git-dir=from-read-only/.git log --format=%s >actual &&
|
||||
cat >expect <<EOF &&
|
||||
add-1-back
|
||||
4
|
||||
EOF
|
||||
test_write_lines add-1-back 4 >expect &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user