Skip to content

Commit e80480a

Browse files
committed
Refactoring git versioning
Added print about version ReGameDLL
1 parent 2085f00 commit e80480a

File tree

11 files changed

+175
-172
lines changed

11 files changed

+175
-172
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
**/.gradle
33
.idea
44
*.iml
5+
*.bat
6+
*.log
7+
*.lnk
58
**/msvc/Debug*
69
**/msvc/Release*
710
**/msvc/Tests
811
**/msvc/*.sdf
912
**/msvc/*.opensdf
1013
**/msvc/*.user
1114
**/msvc/*.suo
15+
**/msvc/*.txt
1216
**/msvc/ipch
1317

1418
regamedll/version/appversion.h

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ if (gitInfo.tag && gitInfo.tag[0] == 'v') {
2929
majorVersion: m.group(1) as int,
3030
minorVersion: m.group(2) as int,
3131
maintenanceVersion: m.group(4) ? (m.group(4) as int) : null,
32+
countCommit: gitInfo.countCommit,
3233
lastCommitDate: gitInfo.lastCommitDate
3334
)
3435
} else {
3536
versionInfo = new RegamedllVersionInfo(
3637
majorVersion: project.majorVersion as int,
3738
minorVersion: project.minorVersion as int,
3839
suffix: 'SNAPSHOT',
40+
countCommit: gitInfo.countCommit,
3941
lastCommitDate: gitInfo.lastCommitDate
4042
)
4143
}

buildSrc/build.gradle

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
apply plugin: 'groovy'
22

33
repositories {
4-
//mavenLocal()
5-
mavenCentral()
6-
maven {
7-
url 'http://nexus.rehlds.org/nexus/content/repositories/regamedll-releases/'
8-
}
9-
maven {
10-
url 'http://nexus.rehlds.org/nexus/content/repositories/regamedll-snapshots/'
11-
}
4+
//mavenLocal()
5+
mavenCentral()
6+
maven {
7+
url 'http://nexus.rehlds.org/nexus/content/repositories/regamedll-releases/'
8+
}
9+
maven {
10+
url 'http://nexus.rehlds.org/nexus/content/repositories/regamedll-snapshots/'
11+
}
1212

1313
}
1414

1515
dependencies {
1616
compile gradleApi()
17-
compile localGroovy()
18-
compile 'commons-io:commons-io:2.4'
19-
compile 'commons-lang:commons-lang:2.6'
20-
compile 'joda-time:joda-time:2.7'
17+
compile localGroovy()
18+
compile 'commons-io:commons-io:2.4'
19+
compile 'commons-lang:commons-lang:2.6'
20+
compile 'joda-time:joda-time:2.7'
2121

22-
compile 'org.doomedsociety.gradlecpp:gradle-cpp-plugin:1.2'
23-
compile 'org.eclipse.jgit:org.eclipse.jgit:3.7.0.201502260915-r'
22+
compile 'org.doomedsociety.gradlecpp:gradle-cpp-plugin:1.2'
23+
compile 'org.eclipse.jgit:org.eclipse.jgit:3.7.0.201502260915-r'
2424

25-
compile 'org.apache.commons:commons-compress:1.9'
26-
compile 'org.apache.ant:ant-compress:1.2'
27-
compile 'org.apache.ant:ant:1.9.6'
25+
compile 'org.apache.commons:commons-compress:1.9'
26+
compile 'org.apache.ant:ant-compress:1.2'
27+
compile 'org.apache.ant:ant:1.9.6'
2828

29-
//compile 'org.tmatesoft.svnkit:svnkit:1.8.5'
30-
//compile 'org.apache.velocity:velocity-tools:2.0'
31-
32-
compile 'org.apache.velocity:velocity:1.7'
29+
compile 'org.apache.velocity:velocity:1.7'
3330
}

buildSrc/src/main/groovy/versioning/GitInfo.groovy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import org.joda.time.DateTime
66

77
@CompileStatic @TypeChecked
88
class GitInfo {
9-
DateTime lastCommitDate
10-
String branch
11-
String tag
9+
DateTime lastCommitDate
10+
String branch
11+
String tag
12+
Integer countCommit
1213
}

buildSrc/src/main/groovy/versioning/GitVersioner.groovy

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package versioning
22

33
import groovy.transform.CompileStatic
44
import groovy.transform.TypeChecked
5+
import org.eclipse.jgit.api.Git
56
import org.eclipse.jgit.lib.ObjectId
67
import org.eclipse.jgit.lib.Repository
8+
import org.eclipse.jgit.revwalk.RevCommit
79
import org.eclipse.jgit.revwalk.RevWalk
810
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
911
import org.joda.time.DateTime
@@ -12,30 +14,41 @@ import org.joda.time.DateTimeZone
1214
@CompileStatic @TypeChecked
1315
class GitVersioner {
1416

15-
static GitInfo versionForDir(String dir) {
16-
versionForDir(new File(dir))
17-
}
18-
19-
static GitInfo versionForDir(File dir) {
20-
FileRepositoryBuilder builder = new FileRepositoryBuilder()
21-
Repository repo = builder.setWorkTree(dir)
22-
.findGitDir()
23-
.build()
24-
25-
ObjectId head = repo.resolve('HEAD')
26-
if (!head) {
27-
return null
28-
}
29-
30-
def commit = new RevWalk(repo).parseCommit(head)
31-
def branch = repo.getBranch()
32-
def commitDate = new DateTime(1000L * commit.commitTime, DateTimeZone.UTC)
33-
String tag = repo.tags.find { kv -> kv.value.objectId == commit.id }?.key
34-
35-
return new GitInfo(
36-
lastCommitDate: commitDate,
37-
branch: branch,
38-
tag: tag
39-
)
40-
}
17+
static GitInfo versionForDir(String dir) {
18+
versionForDir(new File(dir))
19+
}
20+
static int getCountCommit(Repository repo) {
21+
Iterable<RevCommit> commits = Git.wrap(repo).log().call()
22+
int count = 0;
23+
commits.each {
24+
count++;
25+
}
26+
27+
return count;
28+
}
29+
static GitInfo versionForDir(File dir) {
30+
FileRepositoryBuilder builder = new FileRepositoryBuilder()
31+
Repository repo = builder.setWorkTree(dir)
32+
.findGitDir()
33+
.build()
34+
35+
ObjectId head = repo.resolve('HEAD')
36+
if (!head) {
37+
return null
38+
}
39+
40+
def commit = new RevWalk(repo).parseCommit(head)
41+
def branch = repo.getBranch()
42+
def commitDate = new DateTime(1000L * commit.commitTime, DateTimeZone.UTC)
43+
int commitCount = getCountCommit(repo);
44+
45+
String tag = repo.tags.find { kv -> kv.value.objectId == commit.id }?.key
46+
47+
return new GitInfo(
48+
lastCommitDate: commitDate,
49+
branch: branch,
50+
tag: tag,
51+
countCommit: commitCount
52+
)
53+
}
4154
}

buildSrc/src/main/groovy/versioning/RegamedllVersionInfo.groovy

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,30 @@ import org.joda.time.DateTime
88
@CompileStatic @TypeChecked
99
@ToString(includeNames = true)
1010
class RegamedllVersionInfo {
11-
int majorVersion
12-
int minorVersion
13-
Integer maintenanceVersion
14-
String suffix
11+
int majorVersion
12+
int minorVersion
13+
Integer maintenanceVersion
14+
String suffix
15+
Integer countCommit
16+
DateTime lastCommitDate
1517

16-
DateTime lastCommitDate
18+
String format(String versionSeparator, String suffixSeparator, boolean includeSuffix) {
19+
StringBuilder sb = new StringBuilder()
20+
sb.append(majorVersion).append(versionSeparator).append(minorVersion)
21+
if (maintenanceVersion != null) {
22+
sb.append(versionSeparator).append(maintenanceVersion)
23+
}
1724

18-
String format(String versionSeparator, String suffixSeparator, boolean includeSuffix) {
19-
StringBuilder sb = new StringBuilder()
20-
sb.append(majorVersion).append(versionSeparator).append(minorVersion)
21-
if (maintenanceVersion != null) {
22-
sb.append(versionSeparator).append(maintenanceVersion)
23-
}
25+
if (suffix && includeSuffix) {
26+
sb.append(suffixSeparator).append(suffix)
27+
}
2428

25-
if (suffix && includeSuffix) {
26-
sb.append(suffixSeparator).append(suffix)
27-
}
28-
29-
return sb.toString()
30-
}
31-
32-
String asMavenVersion() {
33-
format('.', '-', true)
34-
}
29+
return sb.toString()
30+
}
31+
String asVersion() {
32+
sprintf("%i.%i.%i", majorVersion, minorVersion, countCommit)
33+
}
34+
String asMavenVersion() {
35+
format('.', '-', true)
36+
}
3537
}

regamedll/dlls/bot/states/cs_bot_investigate_noise.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "precompiled.h"
22

3+
// Move towards currently heard noise
4+
35
/* <5b3114> ../cstrike/dlls/bot/states/cs_bot_investigate_noise.cpp:17 */
46
NOBODY void InvestigateNoiseState::AttendCurrentNoise(CCSBot *me)
57
{

regamedll/dlls/game.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,22 @@ cvar_t sk_scientist_heal3;
405405

406406
#ifdef REGAMEDLL_ADD
407407

408+
cvar_t game_version = { "game_version", APP_VERSION_STRD, FCVAR_SERVER, 0.0f, NULL };
408409
cvar_t maxmoney = { "mp_maxmoney", "16000", FCVAR_SERVER, 0.0f, NULL };
409-
cvar_t minmoney = { "mp_minmoney", "800", FCVAR_SERVER, 0.0f, NULL };
410410
cvar_t round_infinite = { "mp_round_infinite", "0", FCVAR_SERVER, 0.0f, NULL };
411411

412412
#endif // REGAMEDLL_ADD
413413

414+
void GameDLL_Version_f(void)
415+
{
416+
if (Q_stricmp(CMD_ARGV(1), "version") != 0)
417+
return;
418+
419+
// print version
420+
CONSOLE_ECHO("ReGameDLL build: " __TIME__ " " __DATE__ " (" APP_VERSION_STRD ")\n");
421+
CONSOLE_ECHO("ReGameDLL API version %i.%i\n", REGAMEDLL_API_VERSION_MAJOR, REGAMEDLL_API_VERSION_MINOR);
422+
}
423+
414424
/* <9c900> ../cstrike/dlls/game.cpp:500 */
415425
void EXT_FUNC GameDLLInit(void)
416426
{
@@ -503,10 +513,16 @@ void EXT_FUNC GameDLLInit(void)
503513

504514
#ifdef REGAMEDLL_ADD
505515

516+
ADD_SERVER_COMMAND("game", GameDLL_Version_f);
517+
518+
CVAR_REGISTER(&game_version);
506519
CVAR_REGISTER(&maxmoney);
507-
CVAR_REGISTER(&minmoney);
508520
CVAR_REGISTER(&round_infinite);
509521

522+
// print version
523+
CONSOLE_ECHO("ReGameDLL build: " __TIME__ " " __DATE__ " (" APP_VERSION_STRD ")\n");
524+
CONSOLE_ECHO("ReGameDLL API version %i.%i\n", REGAMEDLL_API_VERSION_MAJOR, REGAMEDLL_API_VERSION_MINOR);
525+
510526
#endif // REGAMEDLL_ADD
511527

512528
Bot_RegisterCvars();

0 commit comments

Comments
 (0)