Skip to content

Commit

Permalink
Refactoring of 'blob_create' function
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Widgren <stefan.widgren@gmail.com>
  • Loading branch information
stewid committed Jan 7, 2018
1 parent 7c44898 commit b1b2abb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 49 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ S3method(print,git_reflog)
S3method(print,git_status)
export(ahead_behind)
export(blame)
export(blob_create)
export(clone)
export(config)
export(cred_ssh_key)
Expand Down Expand Up @@ -62,7 +63,6 @@ exportClasses(git_transfer_progress)
exportClasses(git_tree)
exportMethods("[")
exportMethods(add)
exportMethods(blob_create)
exportMethods(branch_create)
exportMethods(branch_delete)
exportMethods(branch_get_upstream)
Expand Down
53 changes: 15 additions & 38 deletions R/blob.r
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## git2r, R bindings to the libgit2 library.
## Copyright (C) 2013-2015 The git2r contributors
## Copyright (C) 2013-2018 The git2r contributors
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License, version 2,
Expand All @@ -19,16 +19,18 @@
##' Read a file from the filesystem and write its content to the
##' Object Database as a loose blob. The method is vectorized and
##' accepts a vector of files to create blobs from.
##' @rdname blob_create-methods
##' @docType methods
##' @param repo The repository where the blob(s) will be written. Can
##' be a bare repository.
##' be a bare repository. A \code{\linkS4class{git_repository}}
##' object, or a path to a repository, or \code{NULL}. If the
##' \code{repo} argument is \code{NULL}, the repository is
##' searched for with \code{\link{discover_repository}} in the
##' current working directory.
##' @param path The file(s) from which the blob will be created.
##' @param relative TRUE if the file(s) from which the blob will be
##' created is relative to the repository's working dir. Default is
##' TRUE.
##' @return list of S4 class git_blob \code{objects}
##' @keywords methods
##' created is relative to the repository's working dir. Default
##' is TRUE.
##' @return list of S4 class \code{\linkS4class{git_blob}} objects.
##' @export
##' @examples
##' \dontrun{
##' ## Initialize a temporary repository
Expand All @@ -49,36 +51,11 @@
##' writeLines("test content", temp_file_2)
##' blob_list_2 <- blob_create(repo, c(temp_file_1, temp_file_2), relative = FALSE)
##' }
setGeneric("blob_create",
signature = c("repo", "path"),
function(repo, path, relative = TRUE)
standardGeneric("blob_create"))

##' @rdname blob_create-methods
##' @export
setMethod("blob_create",
signature(repo = "git_repository",
path = "character"),
function(repo, path, relative)
{
## Argument checking
stopifnot(is.logical(relative),
identical(length(relative), 1L))

if (relative) {
result <- .Call(git2r_blob_create_fromworkdir,
repo,
path)
} else {
path <- normalizePath(path, mustWork = TRUE)
result <- .Call(git2r_blob_create_fromdisk,
repo,
path)
}

result
}
)
blob_create <- function(repo = NULL, path = NULL, relative = TRUE) {
if (!isTRUE(relative))
path <- normalizePath(path, mustWork = TRUE)
.Call(git2r_blob_create_fromworkdir, lookup_repository(repo), path)
}

##' Content of blob
##'
Expand Down
19 changes: 9 additions & 10 deletions man/blob_create-methods.Rd → man/blob_create.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b1b2abb

Please sign in to comment.