Skip to content

Instantly share code, notes, and snippets.

@hadley
Created August 28, 2012 02:51
Show Gist options
  • Save hadley/3494506 to your computer and use it in GitHub Desktop.
Save hadley/3494506 to your computer and use it in GitHub Desktop.
# try_con("svn://svn.r-forge.r-project.org/svnroot/depmix/")
# try_con("svn://svn.rforge.net/Rserve/trunk")
# try_con("svn://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks")
try_con <- function(url, debug = TRUE) {
pieces <- httr::parse_url(url)
s <- make.socket(pieces$hostname, 3690)
on.exit(close.socket(s))
read <- function() {
out <- read.socket(s, 1e5)
if (out == "") stop("Connection terminated", call. = FALSE)
if (debug) cat("<<<", out, "\n")
invisible(out)
}
write <- function(value) {
if (debug) cat(">>>", value, "\n")
write.socket(s, value)
read()
}
write_command <- function(...) {
write(make_command(...))
}
read()
write_command(
version = 2L,
cap = list("edit-pipeline", "svndiff1"),
url = string(url)
)
write_command("ANONYMOUS", list())
write_command("get-latest-rev", list())
browser()
write_command("get-dir", list(
path = string("/www"),
rev = list(),
want_props = F,
want_contents = T))
write_command("get-file", list(
path = string("/www/index.php"),
rev = list(),
want_props = F,
want_contents = T
)
invisible()
}
string <- function(x) structure(x, class = "string")
make_command <- function(...) command(list(...))
command <- function(x) UseMethod("command")
command.list <- function(x) {
contents <- vapply(x, command, character(1))
paste("( ", paste(contents, collapse = ""), ") ", sep = "")
}
command.numeric <- function(x) stop("No support for real numbers")
command.integer <- function(x) paste(as.character(x), " ", sep = "")
command.string <- function(x) {
stopifnot(length(x) == 1)
paste(nchar(x, "byte"), ":", x, " ", sep = "")
}
command.character <- function(x) paste(x, " ", collapse = " ", sep = "")
command.logical <- function(x) {
paste(tolower(x), " ", collapse = " ", sep = "")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment