From 89925960047a8cd62e65647dab6832e28af6bf3b Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 29 Jul 2010 17:36:23 +0000 Subject: Alterations so the sbt build will run under git... Alterations so the sbt build will run under git-svn. Review by moix. --- build.xml | 6 +----- project/build/SVN.scala | 44 +++++++++++++++++++++++++------------------- tools/get-git-svn-rev | 5 +++++ tools/git-get-rev | 5 ----- 4 files changed, 31 insertions(+), 29 deletions(-) create mode 100755 tools/get-git-svn-rev delete mode 100755 tools/git-get-rev diff --git a/build.xml b/build.xml index 62fa2ce01f..d6edf7cab1 100644 --- a/build.xml +++ b/build.xml @@ -231,11 +231,7 @@ INITIALISATION - - + diff --git a/project/build/SVN.scala b/project/build/SVN.scala index 78624f3ba7..e05c949587 100644 --- a/project/build/SVN.scala +++ b/project/build/SVN.scala @@ -6,29 +6,35 @@ import scala.util.matching.{Regex} * @param root the root of an svn repository * @author Moix Grégory */ -class SVN(root:Path){ +class SVN(root: Path) { + /** Location of tool which parses svn revision in git-svn repository. */ + val GitSvnRevTool = root / "tools" / "get-git-svn-rev" /** * Gets the revision number of the repository given through the constructor of the class * It assumes that svn is installed on the running computer. */ - def getRevisionNumber:Int = { - val svnInfo = Process("svn info", root) - var result=0 - val out= new ByteArrayOutputStream - val code:Int = svnInfo.#>(out).! - if(code == 0) { - val r = out.toString - val Pattern = new Regex("""Revision: (\d+)""","version") - val version = Pattern.findFirstMatchIn(r) - version match { - case Some(s)=> result=Integer.parseInt(s.group("version")) - case None => throw new UnableToGetRevisionNumberException - } - } else { - throw new UnableToGetRevisionNumberException - } - result - } + def getRevisionNumber: Int = getSvn orElse getGit getOrElse { + throw new UnableToGetRevisionNumberException + } + def getSvn: Option[Int] = { + val svnInfo = Process("svn info", root) + val out = new ByteArrayOutputStream + val code:Int = svnInfo.#>(out).! + + if (code == 0) { + val r = out.toString + val Pattern = new Regex("""Revision: (\d+)""", "version") + val version = Pattern.findFirstMatchIn(r) + + version map (_.group("version").toInt) + } + else None + } + + def getGit: Option[Int] = + try { Some(Process(GitSvnRevTool.toString, root).!!.trim.toInt) } + catch { case _: Exception => None } } + class UnableToGetRevisionNumberException extends RuntimeException \ No newline at end of file diff --git a/tools/get-git-svn-rev b/tools/get-git-svn-rev new file mode 100755 index 0000000000..283b4141fe --- /dev/null +++ b/tools/get-git-svn-rev @@ -0,0 +1,5 @@ +#!/bin/sh +# + +GIT_PAGER=cat +git log -10 | grep git-svn-id | head -1 | sed 's/[^@]*@\([0-9]*\).*/\1/' \ No newline at end of file diff --git a/tools/git-get-rev b/tools/git-get-rev deleted file mode 100755 index 9adda35ca7..0000000000 --- a/tools/git-get-rev +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -# - -GIT_PAGER=cat -git log -10 | grep git-svn-id | head -1 \ No newline at end of file -- cgit v1.2.3