mirror of https://github.com/sbt/sbt.git
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.
This commit is contained in:
parent
972acc871a
commit
bc4443b408
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue