Skip to content

Commit

Permalink
clone: fall back to copying when linking does not work
Browse files Browse the repository at this point in the history
We use heuristics to make a decent guess at when we can save time and
space by linking object files during a clone. Unfortunately checking the
device id isn't enough, as those would be the same during e.g. a bind-mount,
but the OS still does not allow us to link between mounts of the same
filesystem.

If we fail to perform the links, fall back to copying the contents into
a new file as a last attempt.
  • Loading branch information
carlosmn committed Jun 22, 2015
1 parent fd8b7cf commit b494e76
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/clone.c
Expand Up @@ -547,8 +547,21 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
if (can_link(git_repository_path(src), git_repository_path(repo), link))
flags |= GIT_CPDIR_LINK_FILES;

if ((error = git_futils_cp_r(git_buf_cstr(&src_odb), git_buf_cstr(&dst_odb),
flags, GIT_OBJECT_DIR_MODE)) < 0)
error = git_futils_cp_r(git_buf_cstr(&src_odb), git_buf_cstr(&dst_odb),
flags, GIT_OBJECT_DIR_MODE);

/*
* can_link() doesn't catch all variations, so if we hit an
* error and did want to link, let's try again without trying
* to link.
*/
if (error < 0 && link) {
flags &= ~GIT_CPDIR_LINK_FILES;
error = git_futils_cp_r(git_buf_cstr(&src_odb), git_buf_cstr(&dst_odb),
flags, GIT_OBJECT_DIR_MODE);
}

if (error < 0)
goto cleanup;

git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
Expand Down

0 comments on commit b494e76

Please sign in to comment.