From e765759f504b86a643fd8843e41b0283422f7980 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 1 Jul 2011 22:48:00 +0100 Subject: If OpenSim has been built from a git tree, then include version information automatically by dereferencing .git/HEAD A blank bin/.version file will stop this being displayed. --- OpenSim/Framework/Servers/BaseOpenSimServer.cs | 43 +++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs index 98a92dd..d4c3d08 100644 --- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs +++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs @@ -31,6 +31,7 @@ using System.Diagnostics; using System.IO; using System.Reflection; using System.Text; +using System.Text.RegularExpressions; using System.Threading; using System.Timers; using log4net; @@ -124,7 +125,6 @@ namespace OpenSim.Framework.Servers m_logFileAppender = appender; } } - } /// @@ -458,6 +458,9 @@ namespace OpenSim.Framework.Servers // This allows to make the revision available in simulators not running from the source tree. // FIXME: Making an assumption about the directory we're currently in - we do this all over the place // elsewhere as well + string gitDir = "../.git/"; + string gitRefPointerPath = gitDir + "HEAD"; + string svnRevisionFileName = "svn_revision"; string svnFileName = ".svn/entries"; string manualVersionFileName = ".version"; @@ -466,13 +469,45 @@ namespace OpenSim.Framework.Servers if (File.Exists(manualVersionFileName)) { - StreamReader CommitFile = File.OpenText(manualVersionFileName); - buildVersion = CommitFile.ReadLine(); - CommitFile.Close(); + using (StreamReader CommitFile = File.OpenText(manualVersionFileName)) + buildVersion = CommitFile.ReadLine(); + m_version += buildVersion ?? ""; } + else if (File.Exists(gitRefPointerPath)) + { +// m_log.DebugFormat("[OPENSIM]: Found {0}", gitRefPointerPath); + + string rawPointer = ""; + + using (StreamReader pointerFile = File.OpenText(gitRefPointerPath)) + rawPointer = pointerFile.ReadLine(); + +// m_log.DebugFormat("[OPENSIM]: rawPointer [{0}]", rawPointer); + + Match m = Regex.Match(rawPointer, "^ref: (.+)$"); + + if (m.Success) + { +// m_log.DebugFormat("[OPENSIM]: Matched [{0}]", m.Groups[1].Value); + + string gitRef = m.Groups[1].Value; + string gitRefPath = gitDir + gitRef; + if (File.Exists(gitRefPath)) + { +// m_log.DebugFormat("[OPENSIM]: Found gitRefPath [{0}]", gitRefPath); + + using (StreamReader refFile = File.OpenText(gitRefPath)) + { + string gitHash = refFile.ReadLine(); + m_version += gitHash.Substring(0, 7); + } + } + } + } else { + m_log.DebugFormat("[OPENSIM]: Looking for SVN"); // Remove the else logic when subversion mirror is no longer used if (File.Exists(svnRevisionFileName)) { -- cgit v1.1