diff --git a/NAMESPACE b/NAMESPACE index 211e91adf..81c848728 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) @@ -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) diff --git a/R/blob.r b/R/blob.r index 86192919b..82beecd2d 100644 --- a/R/blob.r +++ b/R/blob.r @@ -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, @@ -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 @@ -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 ##' diff --git a/man/blob_create.Rd b/man/blob_create-methods.Rd similarity index 73% rename from man/blob_create.Rd rename to man/blob_create-methods.Rd index 1c063cf97..80ecb9123 100644 --- a/man/blob_create.Rd +++ b/man/blob_create-methods.Rd @@ -1,27 +1,27 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/blob.r +\docType{methods} \name{blob_create} \alias{blob_create} +\alias{blob_create,git_repository,character-method} \title{Create blob from file on disk} \usage{ -blob_create(repo = NULL, path = NULL, relative = TRUE) +blob_create(repo, path, relative = TRUE) + +\S4method{blob_create}{git_repository,character}(repo, path, relative = TRUE) } \arguments{ \item{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.} \item{path}{The file(s) from which the blob will be created.} \item{relative}{TRUE if the file(s) from which the blob will be -created is relative to the repository's working dir. Default -is TRUE.} +created is relative to the repository's working dir. Default is +TRUE.} } \value{ -list of S4 class \code{\linkS4class{git_blob}} objects. +list of S4 class git_blob \code{objects} } \description{ Read a file from the filesystem and write its content to the @@ -49,3 +49,4 @@ writeLines("test content", temp_file_2) blob_list_2 <- blob_create(repo, c(temp_file_1, temp_file_2), relative = FALSE) } } +\keyword{methods}