From bc4443b4084baf6c139308bf9330cb6b07b771c8 Mon Sep 17 00:00:00 2001 From: Sanjin Sehic Date: Mon, 19 Dec 2011 14:41:56 +0100 Subject: [PATCH] Implement resolver for mercurial repositories All mercurial URIs have to be prefixed with 'hg:' to separate them from URIs for other resolvers. For example, 'hg:https://server/user/repo' can now be used. --- main/Build.scala | 1 + main/Resolvers.scala | 63 ++++++++++++++++++++++++++++++++------------ 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/main/Build.scala b/main/Build.scala index 44f53c8bf..4ec004a2b 100644 --- a/main/Build.scala +++ b/main/Build.scala @@ -42,6 +42,7 @@ object RetrieveUnit def apply(info: ResolveInfo): Option[() => File] = { info.uri match { + case Scheme("hg") => Resolvers.mercurial(info) case Scheme("git") => Resolvers.git(info) case Path(path) if path.endsWith(".git") => Resolvers.git(info) case Scheme("http") | Scheme("https") | Scheme("ftp") => Resolvers.remote(info) diff --git a/main/Resolvers.scala b/main/Resolvers.scala index 063a1a288..bccc3ec89 100644 --- a/main/Resolvers.scala +++ b/main/Resolvers.scala @@ -40,39 +40,68 @@ object Resolvers } } - val git: Resolver = (info: ResolveInfo) => { - def clone(at: String, into: File) + val mercurial: Resolver = new DistributedVCS + { + override val scheme = "hg" + + override def clone(at: String, into: File) + { + run(None, "hg", "clone", at, into.getAbsolutePath) + } + + override def checkout(branch: String, in: File) + { + run(Some(in), "hg", "-q", "checkout", branch) + } + }.toResolver + + val git: Resolver = new DistributedVCS + { + override val scheme = "git" + + override def clone(at: String, into: File) { run(None, "git", "clone", at, into.getAbsolutePath) } - def checkout(branch: String, in: File) + override def checkout(branch: String, in: File) { run(Some(in), "git", "checkout", "-q", branch) } + }.toResolver - def normalized(uri: URI) = uri.copy(scheme = "git") + abstract class DistributedVCS + { + val scheme: String - def retrieveLocalCopy(at: URI, into: File) = creates(into) {clone(at.withoutFragment.toASCIIString, into)} + def clone(at: String, into: File) - def retrieveBranch(branch: String, from: File, into: File) = + def checkout(branch: String, in: File) + + def toResolver: Resolver = (info: ResolveInfo) => { + val uri = info.uri.withoutMarkerScheme + val staging = info.staging + Some { + () => + val localCopy = retrieveLocalCopy(at = uri, into = uniqueSubdirectoryFor(normalized(uri.withoutFragment), in = staging)) + if (uri.hasFragment) + retrieveBranch(branch = uri.getFragment, from = localCopy, into = uniqueSubdirectoryFor(normalized(uri), in = staging)) + else + localCopy + } + } + + private def normalized(uri: URI) = uri.copy(scheme = scheme) + + private def retrieveLocalCopy(at: URI, into: File) = creates(into) {clone(at.withoutFragment.toASCIIString, into)} + + private def retrieveBranch(branch: String, from: File, into: File) = { creates(into) { clone(at = from.getAbsolutePath, into = into) checkout(branch, in = into) } } - - val uri = info.uri.withoutMarkerScheme - val staging = info.staging - Some { - () => - val localCopy = retrieveLocalCopy(at = uri, into = uniqueSubdirectoryFor(normalized(uri.withoutFragment), in = staging)) - if (uri.hasFragment) - retrieveBranch(branch = uri.getFragment, from = localCopy, into = uniqueSubdirectoryFor(normalized(uri), in = staging)) - else - localCopy - } } private lazy val onWindows = {