Skip to content

Commit

Permalink
Add version stuff for mac, and shorten version display in-game to a 7…
Browse files Browse the repository at this point in the history
… char hash.

(cherry picked from commit 9b9d178)
  • Loading branch information
Cyp authored and cybersphinx committed Nov 8, 2010
1 parent fa3abb7 commit 2eb5491
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
38 changes: 35 additions & 3 deletions build_tools/autorevision/autorevision.cpp
Expand Up @@ -62,6 +62,11 @@ class assign_once : public T
_assigned(false)
{}

const assign_once<T>& operator=(const assign_once<T>& data)
{
return *this = static_cast<const T&>(data);
}

const assign_once<T>& operator=(const T& data)
{
if (!_assigned)
Expand Down Expand Up @@ -94,6 +99,9 @@ struct RevisionInformation

assign_once<std::string> low_revision;
assign_once<std::string> revision;
assign_once<std::string> low_revisionCount;
assign_once<std::string> revisionCount;
assign_once<std::string> tag;

assign_once<std::string> date;

Expand Down Expand Up @@ -321,6 +329,9 @@ int main(int argc, char** argv)
if (rev_info.date == "")
rev_info.date = "0000-00-00 00:00:00";

rev_info.low_revisionCount = rev_info.low_revision;
rev_info.revisionCount = rev_info.revision;

WriteOutput(outputFile, rev_info);

return 0;
Expand Down Expand Up @@ -651,10 +662,27 @@ bool RevGitQuery::extractRevision(RevisionInformation& rev_info)
rev_info.wc_modified = system("git diff --quiet HEAD");
}
}
std::string tag = runCommand("git describe --exact-match --tags");
if (!tag.empty())
{
rev_info.tag = tag;
}
std::string branch = runCommand("git symbolic-ref HEAD");
if (!branch.empty())
{
rev_info.wc_uri = branch;
rev_info.tag = branch;
}
std::string revCount = runCommand("git rev-list --count HEAD");
if (!revCount.empty())
{
rev_info.low_revisionCount = revCount;
rev_info.revisionCount = revCount;
}
std::string date = runCommand("git log -1 --pretty=format:%ci");
if (!date.empty())
{
rev_info.date = date;
}

// The working copy URI still needs to be extracted. "svnversion" cannot
Expand Down Expand Up @@ -804,12 +832,16 @@ bool WriteOutput(const string& outputFile, const RevisionInformation& rev_info)
if(do_wx)
header << "#include <wx/string.h>\n";

header << "\n#define SVN_LOW_REV " << integerOnly(rev_info.low_revision.empty() ? rev_info.revision : rev_info.low_revision)
header << "\n#define SVN_LOW_REV " << (rev_info.low_revisionCount.empty() ? rev_info.revisionCount : rev_info.low_revisionCount)
<< "\n#define SVN_LOW_REV_STR \"" << (rev_info.low_revision.empty() ? rev_info.revision : rev_info.low_revision) << "\""
<< "\n#define SVN_REV " << integerOnly(rev_info.revision)
<< "\n#define SVN_REV " << rev_info.revisionCount
<< "\n#define SVN_REV_STR \"" << rev_info.revision << "\""
<< "\n#define SVN_DATE \"" << rev_info.date << "\""
<< "\n#define SVN_URI \"" << rev_info.wc_uri << "\"\n";
<< "\n#define SVN_URI \"" << rev_info.wc_uri << "\""
<< "\n#define SVN_TAG \"" << rev_info.tag << "\"\n"
<< "\n#define SVN_SHORT_HASH \"" << rev_info.revision.substr(0, 7) << "\""
<< "\n#define SVN_SHORT_HASH_WITHOUT_QUOTES " << rev_info.revision.substr(0, 7)
<< "\n";

header << "\n#define SVN_WC_MODIFIED " << rev_info.wc_modified
<< "\n#define SVN_WC_SWITCHED " << rev_info.wc_switched << "\n\n";
Expand Down
6 changes: 5 additions & 1 deletion src/version.c
Expand Up @@ -31,7 +31,7 @@
#if (SVN_LOW_REV < SVN_REV)
# define SVN_FULL_REV_STR "r" SVN_LOW_REV_STR ":" SVN_REV_STR
#else
# define SVN_FULL_REV_STR "r" SVN_REV_STR
# define SVN_FULL_REV_STR "r" SVN_SHORT_HASH
#endif

unsigned int version_getLowRevision()
Expand Down Expand Up @@ -62,6 +62,10 @@ const char* version_getVersionString()
{
version_string = (SVN_URI " branch " SVN_FULL_REV_STR) + strlen("branches/");
}
else if (strncmp(svn_uri_cstr, "refs/heads/", strlen("refs/heads/")) == 0)
{
version_string = (SVN_URI " branch " SVN_FULL_REV_STR) + strlen("refs/heads/");
}
else if (SVN_REV != 0)
{
version_string = SVN_URI " " SVN_FULL_REV_STR;
Expand Down

0 comments on commit 2eb5491

Please sign in to comment.