summaryrefslogtreecommitdiff
path: root/src/gamelog.cpp
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2019-01-27 16:13:28 +0100
committerNiels Martin Hansen <nielsm@indvikleren.dk>2019-02-03 18:00:16 +0100
commitcd757ecbf4e9f56ff57328436841e3d1abaa6360 (patch)
tree08f0c6ec97e035ee05cba0503ff853e1cd87a690 /src/gamelog.cpp
parentfaee0737e05c0eb42461b51807083ebc7078d2f5 (diff)
downloadopenttd-cd757ecbf4e9f56ff57328436841e3d1abaa6360.tar.xz
Change: Use git revision hash (with "modified" prefix) for gamelog
Diffstat (limited to 'src/gamelog.cpp')
-rw-r--r--src/gamelog.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/gamelog.cpp b/src/gamelog.cpp
index 05653910d..29910d7ad 100644
--- a/src/gamelog.cpp
+++ b/src/gamelog.cpp
@@ -40,6 +40,30 @@ static LoggedAction *_current_action = NULL; ///< current action we are logging,
/**
+ * Return the revision string for the current client version, for use in gamelog.
+ * The string returned is at most GAMELOG_REVISION_LENGTH bytes long.
+ */
+static const char * GetGamelogRevisionString()
+{
+ /* Allocate a buffer larger than necessary (git revision hash is 40 bytes) to avoid truncation later */
+ static char gamelog_revision[48] = { 0 };
+ assert_compile(lengthof(gamelog_revision) > GAMELOG_REVISION_LENGTH);
+
+ if (IsReleasedVersion()) {
+ return _openttd_revision;
+ } else if (gamelog_revision[0] == 0) {
+ /* Prefix character indication revision status */
+ assert(_openttd_revision_modified < 3);
+ gamelog_revision[0] = "gum"[_openttd_revision_modified]; // g = "git", u = "unknown", m = "modified"
+ /* Append the revision hash */
+ strecat(gamelog_revision, _openttd_revision_hash, lastof(gamelog_revision));
+ /* Truncate string to GAMELOG_REVISION_LENGTH bytes */
+ gamelog_revision[GAMELOG_REVISION_LENGTH - 1] = '\0';
+ }
+ return gamelog_revision;
+}
+
+/**
* Stores information about new action, but doesn't allocate it
* Action is allocated only when there is at least one change
* @param at type of action
@@ -415,7 +439,7 @@ void GamelogRevision()
if (lc == NULL) return;
memset(lc->revision.text, 0, sizeof(lc->revision.text));
- strecpy(lc->revision.text, _openttd_revision, lastof(lc->revision.text));
+ strecpy(lc->revision.text, GetGamelogRevisionString(), lastof(lc->revision.text));
lc->revision.slver = SAVEGAME_VERSION;
lc->revision.modified = _openttd_revision_modified;
lc->revision.newgrf = _openttd_newgrf_version;
@@ -484,7 +508,7 @@ void GamelogTestRevision()
}
}
- if (rev == NULL || strcmp(rev->revision.text, _openttd_revision) != 0 ||
+ if (rev == NULL || strcmp(rev->revision.text, GetGamelogRevisionString()) != 0 ||
rev->revision.modified != _openttd_revision_modified ||
rev->revision.newgrf != _openttd_newgrf_version) {
GamelogRevision();