Skip to content

Commit

Permalink
Revert "Refactoring of 'blob_create' function"
Browse files Browse the repository at this point in the history
This reverts commit b1b2abb.
  • Loading branch information
stewid committed Jan 7, 2018
1 parent e707295 commit bda2daa
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ S3method(print,git_reflog)
S3method(print,git_status)
export(ahead_behind)
export(blame)
export(blob_create)
export(clone)
export(config)
export(content)
Expand Down Expand Up @@ -64,6 +63,7 @@ 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: 38 additions & 15 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-2018 The git2r contributors
## Copyright (C) 2013-2015 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,18 +19,16 @@
##' 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. 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.
##' be a bare repository.
##' @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 \code{\linkS4class{git_blob}} objects.
##' @export
##' created is relative to the repository's working dir. Default is
##' TRUE.
##' @return list of S4 class git_blob \code{objects}
##' @keywords methods
##' @examples
##' \dontrun{
##' ## Initialize a temporary repository
Expand All @@ -51,11 +49,36 @@
##' writeLines("test content", temp_file_2)
##' blob_list_2 <- blob_create(repo, c(temp_file_1, temp_file_2), relative = FALSE)
##' }
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)
}
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
}
)

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

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

0 comments on commit bda2daa

Please sign in to comment.