Skip to content

Commit

Permalink
Merge pull request #61 from muschellij2/sha
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi authored Dec 4, 2021
2 parents 473bbf2 + 249d4fc commit 071f38f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

# development version

* The `source` column of the output data frame of `package_info()` (also
part of `session_info()`), now contains the full SHA for packages installed
from GitHub, instead of only the first seven characters. This makes it
easier to use the SHA programmatically. Note that this does not affect
formatting and printing, which still use the abbreviated SHA.
(@muschellij2, #61).

* RStudio Package Manager (RSPM) and other repository sources are
now shown in the `source` column, if they set the `Repository`
field in `DESCRIPTION`.
Expand Down
10 changes: 7 additions & 3 deletions R/package-info.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pkg_source <- function(desc) {
str <- paste0("Github (",
desc$GithubUsername, "/",
desc$GithubRepo, "@",
substr(desc$GithubSHA1, 1, 7), ")")
desc$GithubSHA1, ")")
} else if (!is.null(desc$RemoteType) && desc$RemoteType == "standard") {
if (!is.null(desc$Repository) && desc$Repository == "CRAN") {
pkg_source_cran(desc)
Expand Down Expand Up @@ -144,7 +144,7 @@ pkg_source <- function(desc) {
}

if (!is.null(desc$RemoteSha)) {
sha <- paste0("@", substr(desc$RemoteSha, 1, 7))
sha <- paste0("@", desc$RemoteSha)
} else {
sha <- NULL
}
Expand Down Expand Up @@ -220,6 +220,10 @@ pkg_md5_disk <- function(pkgdir) {
order_by_name(structure(unname(md5_files), names = tolower(dll_files)))
}

abbrev_long_sha <- function(x) {
sub("([0-9a-f]{7})[0-9a-f]{33}", "\\1", x)
}

#' @export

format.packages_info <- function(x, ...) {
Expand All @@ -233,7 +237,7 @@ format.packages_info <- function(x, ...) {
version = ifelse(unloaded, x$ondiskversion, x$loadedversion),
"date (UTC)" = x$date,
lib = paste0("[", flib(x$library), "]"),
source = x$source,
source = abbrev_long_sha(x$source),
stringsAsFactors = FALSE,
check.names = FALSE
)
Expand Down
Binary file modified tests/testthat/fixtures/devtools-info-unix.rda
Binary file not shown.
Binary file modified tests/testthat/fixtures/devtools-info-windows.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/testthat/test-package-info.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test_that("pkg_source", {

expect_identical(
pkg_source(descs$debugme),
"Github (gaborcsardi/debugme@df8295a)"
"Github (gaborcsardi/debugme@df8295a75f8e26bec90386beb1c82b529427029f)"
)

expect_identical(pkg_source(descs$curl), "CRAN (R 3.3.3)")
Expand Down

0 comments on commit 071f38f

Please sign in to comment.