Skip to content

Commit bab2283

Browse files
pks-tgitster
authored andcommitted
remote-curl: rediscover repository when fetching refs
The reftable format encodes the hash function used by the repository inside of its tables. The reftable backend thus needs to be initialized with the correct hash function right from the start, or otherwise we may end up writing tables with the wrong hash function. But git-clone(1) initializes the reference database before learning about the hash function used by the remote repository, which has never been a problem with the reffiles backend. To fix this, we'll have to change git-clone(1) to be more careful and only create the reference backend once it learned about the remote hash function. This creates a problem for git-remote-curl(1), which will then be spawned at a time where the repository is not yet fully-initialized. Consequentially, git-remote-curl(1) will fail to detect the repository, which eventually causes it to error out once it is asked to fetch remote objects. We can address this issue by trying to re-discover the Git repository in case none was detected at startup time. With this change, the clone will look as following: 1. git-clone(1) sets up the initial repository, excluding the reference database. 2. git-clone(1) spawns git-remote-curl(1), which will be unable to detect the repository due to a missing "HEAD". 3. git-clone(1) asks git-remote-curl(1) to list remote references. This works just fine as this step does not require a local repository 4. git-clone(1) creates the reference database as it has now learned about the hash function. 5. git-clone(1) asks git-remote-curl(1) to fetch the remote packfile. The latter notices that it doesn't have a repository available, but it now knows to try and re-discover it. If the re-discovery succeeds in the last step we can continue with the clone. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 56cd033 commit bab2283

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

remote-curl.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,8 +1564,11 @@ int cmd_main(int argc, const char **argv)
15641564
if (buf.len == 0)
15651565
break;
15661566
if (starts_with(buf.buf, "fetch ")) {
1567-
if (nongit)
1568-
die(_("remote-curl: fetch attempted without a local repo"));
1567+
if (nongit) {
1568+
setup_git_directory_gently(&nongit);
1569+
if (nongit)
1570+
die(_("remote-curl: fetch attempted without a local repo"));
1571+
}
15691572
parse_fetch(&buf);
15701573

15711574
} else if (!strcmp(buf.buf, "list") || starts_with(buf.buf, "list ")) {

0 commit comments

Comments
 (0)