Skip to content

Commit

Permalink
Refactoring of 'content' 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 b1b2abb commit e707295
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 32 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export(blame)
export(blob_create)
export(clone)
export(config)
export(content)
export(cred_ssh_key)
export(cred_token)
export(default_signature)
Expand Down Expand Up @@ -76,7 +77,6 @@ exportMethods(bundle_r_package)
exportMethods(checkout)
exportMethods(commit)
exportMethods(commits)
exportMethods(content)
exportMethods(contributions)
exportMethods(cred_env)
exportMethods(cred_user_pass)
Expand Down
34 changes: 10 additions & 24 deletions R/blob.r
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ blob_create <- function(repo = NULL, path = NULL, relative = TRUE) {

##' Content of blob
##'
##' @rdname content-methods
##' @docType methods
##' @param blob The blob \code{object}.
##' @param blob The blob object.
##' @param split Split blob content to text lines. Default TRUE.
##' @return The content of the blob. NA_character_ if the blob is binary.
##' @keywords methods
##' @export
##' @examples
##' \dontrun{
##' ## Initialize a temporary repository
Expand All @@ -81,27 +79,15 @@ blob_create <- function(repo = NULL, path = NULL, relative = TRUE) {
##' ## Display content of blob.
##' content(tree(commits(repo)[[1]])["example.txt"])
##' }
setGeneric("content",
signature = "blob",
function(blob,
split = TRUE)
standardGeneric("content"))

##' @rdname content-methods
##' @export
setMethod("content",
signature(blob = "git_blob"),
function(blob, split)
{
if (is_binary(blob))
return(NA_character_)
content <- function(blob = NULL, split = TRUE) {
if (is_binary(blob))
return(NA_character_)

ret <- .Call(git2r_blob_content, blob)
if (isTRUE(split))
ret <- strsplit(ret, "\n")[[1]]
ret
}
)
ret <- .Call(git2r_blob_content, blob)
if (isTRUE(split))
ret <- strsplit(ret, "\n")[[1]]
ret
}

##' Determine the sha from a blob string
##'
Expand Down
9 changes: 2 additions & 7 deletions man/content-methods.Rd → man/content.Rd

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

0 comments on commit e707295

Please sign in to comment.