Repository navigation
Description
I've been doing some more testing on how to get pkgdepends working with git repos hosted on Azure DevOps.
One problem I've encountered is that unpack_packfile_repo() is sensitive to the order in which the blobs/trees are received from the fetch request. The function is assuming that the root directory is the first tree it encounters.
In the case of Azure DevOps, the list that's received isn't guaranteed to have the root directory as the first tree in the list. The result is that unpack_packfile_repo() puts everything into the root directory of the output folder.
It might be possible to get the git server to provide the components in a particular order? I don't know enough about the protocol to say for sure.
But even if it was, it seems more sensible to get the function to solve for the correct order in which to go through the trees/blobs. Perhaps generating the folder structure first and then writing out the blobs?
Sorry again that I don't have a reprex for you.
Lines 507 to 544 in 9718c02
| unpack_packfile_repo <- function(parsed, output) { | |
| types <- unname(vcapply(parsed, "[[", "type")) | |
| trees <- parsed[types == "tree"] | |
| done <- logical(length(trees)) | |
| idx <- 1L | |
| wd <- character() | |
| mkdirp(output) | |
| process_tree <- function(i) { | |
| if (done[i]) return() | |
| done[i] <<- TRUE | |
| tr <- trees[[i]]$object | |
| for (l in seq_len(nrow(tr))) { | |
| idx <<- idx + 1L | |
| opath <- file.path(output, paste(c(wd, tr$path[l]), collapse = "/")) | |
| if (tr$type[l] == "tree") { | |
| tidx <- which(tr$hash[l] == names(trees))[1] | |
| if (is.na(tidx)) { | |
| throw(new_error( # nocov | |
| "git tree missing from packfile: {.val {tr$hash[i]}}.", # nocov | |
| .class = "git_proto_error_unexpected_response" # nocov | |
| )) # nocov | |
| } | |
| wd <<- c(wd, tr$path[l]) | |
| mkdirp(opath) | |
| process_tree(tidx) | |
| wd <<- utils::head(wd, -1) | |
| } else if (tr$type[l] == "blob") { | |
| writeBin(parsed[[tr$hash[l]]]$raw, opath) | |
| } | |
| } | |
| } | |
| for (i in seq_along(trees)) process_tree(i) | |
| invisible() | |
| } |
Activity
git: list/unpack pack files in the right order