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.
bulletsim
Justin Clark-Casey (justincc) 2011-07-01 22:48:00 +01:00
parent 759e855566
commit e765759f50
1 changed files with 39 additions and 4 deletions

View File

@ -31,6 +31,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using System.Timers; using System.Timers;
using log4net; using log4net;
@ -124,7 +125,6 @@ namespace OpenSim.Framework.Servers
m_logFileAppender = appender; m_logFileAppender = appender;
} }
} }
} }
/// <summary> /// <summary>
@ -458,6 +458,9 @@ namespace OpenSim.Framework.Servers
// This allows to make the revision available in simulators not running from the source tree. // 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 // FIXME: Making an assumption about the directory we're currently in - we do this all over the place
// elsewhere as well // elsewhere as well
string gitDir = "../.git/";
string gitRefPointerPath = gitDir + "HEAD";
string svnRevisionFileName = "svn_revision"; string svnRevisionFileName = "svn_revision";
string svnFileName = ".svn/entries"; string svnFileName = ".svn/entries";
string manualVersionFileName = ".version"; string manualVersionFileName = ".version";
@ -466,13 +469,45 @@ namespace OpenSim.Framework.Servers
if (File.Exists(manualVersionFileName)) if (File.Exists(manualVersionFileName))
{ {
StreamReader CommitFile = File.OpenText(manualVersionFileName); using (StreamReader CommitFile = File.OpenText(manualVersionFileName))
buildVersion = CommitFile.ReadLine(); buildVersion = CommitFile.ReadLine();
CommitFile.Close();
m_version += buildVersion ?? ""; 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 else
{ {
m_log.DebugFormat("[OPENSIM]: Looking for SVN");
// Remove the else logic when subversion mirror is no longer used // Remove the else logic when subversion mirror is no longer used
if (File.Exists(svnRevisionFileName)) if (File.Exists(svnRevisionFileName))
{ {