Skip to content

Commit

Permalink
Merge pull request #297 from bfgray3/idiomacy
Browse files Browse the repository at this point in the history
small changes for idiomacy
  • Loading branch information
stewid committed Nov 4, 2017
2 parents e289c23 + d5ea6e8 commit e5ed6d0
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 47 deletions.
6 changes: 3 additions & 3 deletions R/S4_classes.r
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ setClass("git_repository",
errors <- character()

can_open <- .Call(git2r_repository_can_open, object@path)
if (!identical(can_open, TRUE))
if (!isTRUE(can_open))
errors <- c(errors, "Unable to open repository at 'path'")

if (length(errors) == 0) TRUE else errors
Expand Down Expand Up @@ -111,7 +111,7 @@ setClass("git_signature",
{
errors <- validObject(object@when)

if (identical(errors, TRUE))
if (isTRUE(errors))
errors <- character()

if (!identical(length(object@name), 1L))
Expand Down Expand Up @@ -673,7 +673,7 @@ setClass("git_tag",
{
errors <- validObject(object@tagger)

if (identical(errors, TRUE))
if (isTRUE(errors))
errors <- character()

if (!identical(length(object@sha), 1L))
Expand Down
2 changes: 1 addition & 1 deletion R/blob.r
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ setMethod("content",
return(NA_character_)

ret <- .Call(git2r_blob_content, blob)
if (identical(split, TRUE))
if (isTRUE(split))
ret <- strsplit(ret, "\n")[[1]]
ret
}
Expand Down
4 changes: 2 additions & 2 deletions R/bundle_r_package.r
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ setMethod("bundle_r_package",
{
## Check for 'inst' folder
inst <- paste0(workdir(repo), "inst", sep = "")
if (!identical(file.info(inst)$isdir, TRUE))
if (!isTRUE(file.info(inst)$isdir))
dir.create(inst)

## Check for 'pkg.git' folder
local_path <- paste0(basename(workdir(repo)), ".git", sep = "")
local_path <- file.path(inst, local_path)
if (file.exists(local_path))
stop(paste0("Repo already exists:", local_path))
stop("Repo already exists:", local_path)
invisible(clone(workdir(repo), local_path, bare = TRUE))
}
)
15 changes: 8 additions & 7 deletions R/checkout.r
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ previous_branch_name <- function(repo)
branch <- sapply(references(repo), function(x) {
ifelse(x@sha == branch, x@shorthand, NA_character_)
})
branch <- branch[!sapply(branch, is.na)]
branch <- branch[vapply(branch, Negate(is.na), logical(1))]

branch <- sapply(branches(repo, "local"), function(x) {
ifelse(x@name %in% branch, x@name, NA_character_)
})
branch <- branch[!sapply(branch, is.na)]
branch <- branch[vapply(branch, Negate(is.na), logical(1))]

if (any(!is.character(branch), !identical(length(branch), 1L))) {
stop("'branch' must be a character vector of length one")
Expand Down Expand Up @@ -142,7 +142,7 @@ setMethod("checkout",
stop("'branch' must be a character vector of length one")

if (is_empty(object)) {
if (!identical(create, TRUE))
if (!isTRUE(create))
stop(sprintf("'%s' did not match any branch", branch))
ref_name <- paste0("refs/heads/", branch)
.Call(git2r_repository_set_head, object, ref_name)
Expand All @@ -152,7 +152,7 @@ setMethod("checkout",

## Check if branch exists in a local branch
lb <- branches(object, "local")
lb <- lb[sapply(lb, slot, "name") == branch]
lb <- lb[vapply(lb, slot, character(1), "name") == branch]
if (length(lb)) {
checkout(lb[[1]], force = force)
} else {
Expand All @@ -161,10 +161,11 @@ setMethod("checkout",
rb <- branches(object, "remote")

## Split remote/name to check for a unique name
name <- sapply(rb, function(x) {
name <- vapply(rb, function(x) {
remote <- strsplit(x@name, "/")[[1]][1]
sub(paste0("^", remote, "/"), "", x@name)
})
},
character(1))
i <- which(name == branch)
if (identical(length(i), 1L)) {
## Create branch and track remote
Expand All @@ -173,7 +174,7 @@ setMethod("checkout",
branch_set_upstream(branch, rb[[i]]@name)
checkout(branch, force = force)
} else {
if (!identical(create, TRUE))
if (!isTRUE(create))
stop(sprintf("'%s' did not match any branch", branch))

## Create branch
Expand Down
6 changes: 3 additions & 3 deletions R/commit.r
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ setMethod("summary",
cat(sprintf("Commit: %s\n", object@sha))

if (is_merge_commit) {
sha <- sapply(po, slot, "sha")
sha <- vapply(po, slot, character(1), "sha")
cat(sprintf("Merge: %s\n", sha[1]))
cat(paste0(" ", sha[-1]), sep="\n")
}
Expand Down Expand Up @@ -625,8 +625,8 @@ setMethod("summary",
}

cat(sprintf("%i insertions, %i deletions\n",
sum(sapply(lines_per_file(df), "[[", "add")),
sum(sapply(lines_per_file(df), "[[", "del"))))
sum(vapply(lines_per_file(df), "[[", numeric(1), "add")),
sum(vapply(lines_per_file(df), "[[", numeric(1), "del"))))

plpf <- print_lines_per_file(df)
hpf <- hunks_per_file(df)
Expand Down
6 changes: 2 additions & 4 deletions R/config.r
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,12 @@ config <- function(repo = NULL, global = FALSE, user.name, user.email, ...)
for (i in seq_len(length(variables))) {
if (!is.null(variables[[i]])) {
if (!is.character(variables[[i]])) {
stop(paste0("'",
names(variables)[i],
"' must be a character vector"))
stop("'", names(variables)[i], "' must be a character vector")
}
}
}

if (identical(global, TRUE)) {
if (isTRUE(global)) {
repo <- NULL
} else if (is.null(repo)) {
stop("Unable to locate local repository")
Expand Down
8 changes: 4 additions & 4 deletions R/diff.r
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ lines_per_file <- function(diff) {

print_lines_per_file <- function(diff) {
lpf <- lines_per_file(diff)
files <- sapply(lpf, function(x) x$file)
del <- sapply(lpf, function(x) x$del)
add <- sapply(lpf, function(x) x$add)
files <- vapply(lpf, function(x) x$file, character(1))
del <- vapply(lpf, function(x) x$del, numeric(1))
add <- vapply(lpf, function(x) x$add, numeric(1))
paste0(format(files), " | ", "-", format(del), " +", format(add))
}

hunks_per_file <- function(diff) {
sapply(diff@files, function(x) length(x@hunks))
vapply(diff@files, function(x) length(x@hunks), numeric(1))
}

##' Show the summary of a diff
Expand Down
5 changes: 3 additions & 2 deletions R/index.r
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ setMethod("add",
if (!length(grep("/$", repo_wd)))
repo_wd <- paste0(repo_wd, "/")

path <- sapply(path, function(p) {
path <- vapply(path, function(p) {
np <- suppressWarnings(normalizePath(p, winslash = "/"))

## Check if the normalized path is a non-file e.g. a
Expand All @@ -132,7 +132,8 @@ setMethod("add",
## Change the path to be relative to the repository's
## working directory. Substitute common prefix with ""
sub(paste0("^", repo_wd), "", np)
})
},
character(1))

.Call(git2r_index_add_all, repo, path, force)

Expand Down
8 changes: 4 additions & 4 deletions R/merge.r
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ merge_named_branch <- function(repo, branch, commit_on_success, merger)
stop("'branch' must be a character vector of length one")

b <- branches(repo)
b <- b[sapply(b, slot, "name") == branch][[1]]
b <- b[vapply(b, slot, character(1), "name") == branch][[1]]

merge_branch(b, commit_on_success, merger)
}
Expand Down Expand Up @@ -259,11 +259,11 @@ setMethod("show",
signature(object = "git_merge_result"),
function(object)
{
if (identical(object@up_to_date, TRUE)) {
if (isTRUE(object@up_to_date)) {
cat("Already up-to-date")
} else if (identical(object@conflicts, TRUE)) {
} else if (isTRUE(object@conflicts)) {
cat("Merge: Conflicts")
} else if (identical(object@fast_forward, TRUE)) {
} else if (isTRUE(object@fast_forward)) {
cat("Merge: Fast-forward")
} else {
cat("Merge")
Expand Down
2 changes: 1 addition & 1 deletion R/pull.r
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ setMethod("pull",

## fetch heads marked for merge
fh <- fetch_heads(repo)
fh <- fh[sapply(fh, slot, "is_merge")]
fh <- fh[vapply(fh, slot, logical(1), "is_merge")]

if (identical(length(fh), 0L))
stop("Remote ref was not feteched")
Expand Down
10 changes: 5 additions & 5 deletions R/push.r
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ setMethod("push",
{
upstream <- branch_get_upstream(object)
if (is.null(upstream)) {
stop(paste0("The branch '", object@name, "' that you are ",
"trying to push does not track an upstream branch."))
stop("The branch '", object@name, "' that you are ",
"trying to push does not track an upstream branch.")
}

src <- .Call(git2r_branch_canonical_name, object)
Expand Down Expand Up @@ -114,16 +114,16 @@ setMethod("push",
b <- head(object)
upstream <- branch_get_upstream(b)
if (is.null(upstream)) {
stop(paste0("The branch '", b@name, "' that you are ",
"trying to push does not track an upstream branch."))
stop("The branch '", b@name, "' that you are ",
"trying to push does not track an upstream branch.")
}

src <- .Call(git2r_branch_canonical_name, b)
dst <- .Call(git2r_branch_upstream_canonical_name, b)
name <- branch_remote_name(upstream)
refspec <- paste0(src, ":", dst)

if (identical(force, TRUE))
if (isTRUE(force))
refspec <- paste0("+", refspec)
} else {
opts <- list(force = force)
Expand Down
4 changes: 2 additions & 2 deletions R/refspec.r
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ get_refspec <- function(repo = NULL, remote = NULL, spec = NULL, opts = NULL)
## configuration is missing, it defaults to origin.
if (!is.null(remote)) {
stopifnot(is.character(remote), identical(length(remote), 1L))
remote <- sub("^[[:space:]]*", "", sub("[[:space:]]*$", "", remote))
remote <- trimws(remote)
if (identical(nchar(remote), 0L))
remote <- NULL
}
Expand All @@ -60,7 +60,7 @@ get_refspec <- function(repo = NULL, remote = NULL, spec = NULL, opts = NULL)
## Refspec:
stopifnot(is.character(spec))

if (identical(opts$force, TRUE))
if (isTRUE(opts$force))
spec <- paste0("+", spec)

list(remote = remote, refspec = spec)
Expand Down
11 changes: 6 additions & 5 deletions R/repository.r
Original file line number Diff line number Diff line change
Expand Up @@ -900,12 +900,12 @@ setMethod("summary",

n_branches <- sum(!is.na(unique(sapply(branches(object),
branch_target))))
n_tags <- sum(!is.na(unique(sapply(tags(object), slot, "sha"))))
n_tags <- sum(!is.na(unique(vapply(tags(object), slot, character(1), "sha"))))

work <- commits(object)
n_commits <- length(work)
n_authors <- length(unique(sapply(lapply(work, slot, "author"),
slot, "name")))
n_authors <- length(unique(vapply(lapply(work, slot, "author"),
slot, character(1), "name")))

s <- .Call(git2r_status_list, object, TRUE, TRUE, TRUE, FALSE, TRUE)
n_ignored <- length(s$ignored)
Expand All @@ -916,10 +916,11 @@ setMethod("summary",
n_stashes <- length(stash_list(object))

## Determine max characters needed to display numbers
n <- max(sapply(c(n_branches, n_tags, n_commits, n_authors,
n <- max(vapply(c(n_branches, n_tags, n_commits, n_authors,
n_stashes, n_ignored, n_untracked,
n_unstaged, n_staged),
nchar))
nchar,
numeric(1)))

fmt <- paste0("Branches: %", n, "i\n",
"Tags: %", n, "i\n",
Expand Down
2 changes: 1 addition & 1 deletion R/stash.r
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ setMethod("stash_drop",
function(object)
{
## Determine the index of the stash in the stash list
i <- match(object@sha, sapply(stash_list(object@repo), slot, "sha"))
i <- match(object@sha, vapply(stash_list(object@repo), slot, character(1), "sha"))

## The stash list is zero-based
.Call(git2r_stash_drop, object@repo, i - 1L)
Expand Down
2 changes: 1 addition & 1 deletion R/status.r
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ print.git_status <- function(x, ...)
invisible(NULL)
}

if (max(vapply(x, length, integer(1))) == 0L)
if (max(lengths(x)) == 0L)
cat("working directory clean\n")

if (length(x$ignored)) {
Expand Down
4 changes: 2 additions & 2 deletions R/tree.r
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ setMethod("summary",
##' tree_object[1:3]
##'
##' ## Select all blobs in tree
##' tree_object[sapply(as(tree_object, 'list'), is_blob)]
##' tree_object[vapply(as(tree_object, 'list'), is_blob, logical(1))]
##' }
setMethod("[",
signature(x = "git_tree", i = "integer", j = "missing"),
Expand Down Expand Up @@ -310,7 +310,7 @@ setMethod("[",
signature(x = "git_tree", i = "logical", j = "missing"),
function(x, i)
{
x[seq_len(length(x))[i]]
x[seq_along(x)[i]]
}
)

Expand Down

0 comments on commit e5ed6d0

Please sign in to comment.