Skip to content

Commit

Permalink
Increase global timeouts for slow clones
Browse files Browse the repository at this point in the history
Remove --recommend-shallow as it is the default and only works if submodule is set to shallow=true.
See r-universe-org/help#550
  • Loading branch information
jeroen committed Dec 16, 2024
1 parent 9848b74 commit 9a83f47
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
14 changes: 10 additions & 4 deletions R/monorepos.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ sync_from_registry <- function(monorepo_url = Sys.getenv('MONOREPO_URL')){
}

# Sync with the user registry file (currently libgit2 does not support shallow clones, sadly)
res <- sys::exec_wait("git", c("submodule", "update", "--init", "--recommend-shallow", "--remote", '.registry'))
res <- sys::exec_wait("git", c("submodule", "update", "--init", "--remote", '.registry'))

# If this fails, check if the personal registry still exists
if(res != 0 || !file.exists('.registry/packages.json')){
Expand All @@ -74,7 +74,7 @@ sync_from_registry <- function(monorepo_url = Sys.getenv('MONOREPO_URL')){
if(is.null(newrepo)){
switch_to_registry('r-universe-org/cran-to-git', validate = FALSE)
}
sys::exec_wait("git", c("submodule", "update", "--init", "--recommend-shallow", "--remote", '.registry'))
sys::exec_wait("git", c("submodule", "update", "--init", "--remote", '.registry'))
} else {
stop("Failure cloning .registry repository")
}
Expand Down Expand Up @@ -254,7 +254,8 @@ update_one_package <- function(x, update_pkg_remotes = FALSE, cleanup_after = FA
}
print_message("Updating package '%s' from: %s", pkg_dir, pkg_url)
git_cmd_assert("update-index", "--cacheinfo", "160000", remote_head, pkg_dir)
git_cmd_assert("submodule", "update", "--init", "--recommend-shallow", pkg_dir)

git_cmd_assert("submodule", "update", "--init", pkg_dir)
}
gert::git_add(pkg_dir)
if(!any(gert::git_status()$staged)){
Expand Down Expand Up @@ -647,6 +648,11 @@ set_release_version <- function(pkg, value){
gert::git_add(".gitmodules")
}

set_submodule_shallow <- function(pkg){
field <- sprintf("submodule.%s.shallow", pkg)
sys::exec_internal('git', c("config", "-f", ".gitmodules", field, 'true'))
}

update_release_branch <- function(pkg_dir, pkg_url){
pkg_branch <- if(grepl('gitlab.com', pkg_url)){
lookup_gitlab_release(pkg_url)
Expand Down Expand Up @@ -710,7 +716,7 @@ switch_to_registry <- function(repo_name, validate = TRUE){
sys::exec_wait("git", c("submodule", "deinit", "--force", ".registry"), std_err = FALSE)
unlink(".git/modules/.registry", recursive = TRUE)
sys::exec_wait("git", c("submodule", "set-url", ".registry", regrepo))
sys::exec_wait("git", c("submodule", "update", "--init", "--recommend-shallow", "--remote", '.registry'))
sys::exec_wait("git", c("submodule", "update", "--init", "--remote", '.registry'))
if(isTRUE(validate)){
pkgdf <- jsonlite::fromJSON('.registry/packages.json')
if(!is.data.frame(pkgdf))
Expand Down
8 changes: 4 additions & 4 deletions R/registry.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ update_registry <- function(path = '.'){
submodules <- gert::git_submodule_list(repo = repo)

# Update .registry submodule (libgit2 does not support shallow clones)
git_cmd("submodule", "update", "--init", "--remote", "--recommend-shallow", "-f", '.registry')
git_cmd("submodule", "update", "--init", "--remote", "-f", '.registry')
registry_commit <- gert::git_log(repo = I('.registry'), max = 1)

# read registry
Expand Down Expand Up @@ -87,12 +87,12 @@ remove_submodule <- function(pkg){
unlink(pkg, recursive = TRUE)
}

git_cmd <- function(..., std_err = TRUE, timeout = 60){
git_cmd <- function(..., std_err = TRUE, timeout = 600){
# Timeout is mostly in case of unexpected password prompts
sys::exec_wait('git', args = c(...), std_err = std_err, timeout = timeout)
}

git_cmd_assert <- function(..., timeout = 60){
git_cmd_assert <- function(..., timeout = 600){
args <- c(...)
res <- sys::exec_internal('git', args = args, timeout = timeout, error = FALSE)
errtxt <- sys::as_text(res$stderr)
Expand Down Expand Up @@ -122,7 +122,7 @@ git_clone <- function(url, dest = NULL){

git_submodule_shallow <- function(dest){
for(i in 1:3){
if(!git_cmd("submodule", "update", "--init", "--remote", "--recommend-shallow", "-f", dest)){
if(!git_cmd("submodule", "update", "--init", "--remote", "-f", dest)){
return(TRUE)
}
message("Retrying to submodule: ", dest)
Expand Down
2 changes: 1 addition & 1 deletion R/update.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ submodules_up_to_date <- function(skip_broken = TRUE, path = '.'){
update_and_push <- function(info){
pkg_dir <- info$path
gert::git_submodule_set_to(pkg_dir, info$upstream, checkout = FALSE, repo = dirname(pkg_dir))
git_cmd('submodule', 'update', '--init', '--recommend-shallow', pkg_dir)
git_cmd('submodule', 'update', '--init', pkg_dir)
subdir <- get_module_config(pkg_dir, 'subdir')
r_pkg_dir <- ifelse(length(subdir), file.path(pkg_dir, subdir), pkg_dir)
desc <- get_description_data(r_pkg_dir)
Expand Down

0 comments on commit 9a83f47

Please sign in to comment.