mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 15:05:50 +01:00
Initial Import.
This commit is contained in:
21
src/main/scala/util/Directory.scala
Normal file
21
src/main/scala/util/Directory.scala
Normal file
@@ -0,0 +1,21 @@
|
||||
package util
|
||||
|
||||
import java.io.File
|
||||
|
||||
object Directory {
|
||||
|
||||
val GitBucketHome = "C:/Users/takez_000/gitbucket"
|
||||
|
||||
def getRepositories(owner: String): List[String] =
|
||||
new File("%s/%s".format(GitBucketHome, owner)).listFiles.filter(_.isDirectory).map(_.getName).toList
|
||||
|
||||
def getRepositoryDir(owner: String, repository: String): File =
|
||||
new File("%s/%s/%s/repository".format(GitBucketHome, owner, repository))
|
||||
|
||||
def getBranchDir(owner: String, repository: String, branch: String): File =
|
||||
new File("%s/%s/%s/branch/%s".format(GitBucketHome, owner, repository, branch))
|
||||
|
||||
def getTagDir(owner: String, repository: String, tag: String): File =
|
||||
new File("%s/%s/%s/tags/%s".format(GitBucketHome, owner, repository, tag))
|
||||
|
||||
}
|
||||
22
src/main/scala/util/Implicits.scala
Normal file
22
src/main/scala/util/Implicits.scala
Normal file
@@ -0,0 +1,22 @@
|
||||
package util
|
||||
|
||||
object Implicits {
|
||||
implicit def extendsSeq[A](seq: Seq[A]) = new {
|
||||
|
||||
def splitWith(condition: (A, A) => Boolean): Seq[Seq[A]] = split(seq)(condition)
|
||||
|
||||
@scala.annotation.tailrec
|
||||
private def split[A](list: Seq[A], result: Seq[Seq[A]] = Nil)(condition: (A, A) => Boolean): Seq[Seq[A]] = {
|
||||
list match {
|
||||
case x :: xs => {
|
||||
xs.span(condition(x, _)) match {
|
||||
case (matched, remained) => split(remained, result :+ (x :: matched))(condition)
|
||||
}
|
||||
}
|
||||
case Nil => result
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user