[6800] Added revision number output.

* Changed genrevision to use * instead of unknown when some info can not be found
* Added the git_id tool which is used to generate changes to revision_nr.h and the commit message
This commit is contained in:
Wyk3d 2008-11-08 01:50:42 +02:00
parent b681f5ac1a
commit cfd9ccdaaf
12 changed files with 460 additions and 14 deletions

211
contrib/git_id/git_id.cpp Normal file
View file

@ -0,0 +1,211 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <assert.h>
#include <direct.h>
#include "../../src/framework/Platform/CompilerDefs.h"
#if PLATFORM == PLATFORM_WINDOWS
#define popen _popen
#define pclose _pclose
#define snprintf _snprintf
#pragma warning (disable:4996)
#endif
#define NUM_REMOTES 2
char remotes[NUM_REMOTES][256] = {
"git@github.com:mangos/mangos.git",
"git://github.com/mangos/mangos.git"
};
char origins[NUM_REMOTES][256];
int rev;
char head_message[256];
char write_file[2048];
char buffer[256];
FILE *cmd_pipe;
bool allow_replace = false;
bool local = false;
bool find_path()
{
char cur_path[2048], *ptr;
getcwd(cur_path, 2048);
int len = strnlen(cur_path, 2048);
if(cur_path[len-1] == '/' || cur_path[len-1] == '\\')
{
// we're in root, don't bother
return false;
}
// don't count the root
int count_fwd = 0, count_back = 0;
for(ptr = cur_path-1; ptr = strchr(ptr+1, '/'); count_fwd++);
for(ptr = cur_path-1; ptr = strchr(ptr+1, '\\'); count_back++);
int count = std::max(count_fwd, count_back);
char prefix[2048] = "", path[2048];
for(int i = 0; i < count; i++)
{
snprintf(path, 2048, "%s.git", prefix);
if(0 == chdir(path))
{
chdir(cur_path);
snprintf(write_file, 2048, "%ssrc/shared/revision_nr.h", prefix);
return true;
}
strncat(prefix, "../", 2048);
}
return false;
}
bool find_origin()
{
if( (cmd_pipe = popen( "git remote -v", "rt" )) == NULL )
return false;
bool ret = false;
while(fgets(buffer, 256, cmd_pipe))
{
char name[256], remote[256];
sscanf(buffer, "%s %s", name, remote);
for(int i = 0; i < NUM_REMOTES; i++)
{
if(strcmp(remote, remotes[i]) == 0)
{
strncpy(origins[i], name, 256);
ret = true;
}
}
}
pclose(cmd_pipe);
return ret;
}
int get_rev(const char *from_msg)
{
// accept only the rev number format, not the sql update format
char nr_str[256];
if(sscanf(from_msg, "[%[0123456789]]", nr_str) != 1) return 0;
if(buffer[strlen(nr_str)+1] != ']') return 0;
return atoi(nr_str);
}
bool find_rev()
{
// find the highest rev number on either of the remotes
for(int i = 0; i < NUM_REMOTES; i++)
{
if(!origins[i][0]) continue;
char cmd[512];
if(local) sprintf(cmd, "git rev-list HEAD --pretty=\"format:%%s\"");
else sprintf(cmd, "git rev-list %s/master --pretty=\"format:%%s\"", origins[i]);
if( (cmd_pipe = popen( cmd, "rt" )) == NULL )
continue;
int count = 0, nr;
while(fgets(buffer, 256, cmd_pipe))
{
// every second line contains the commit message
if(count++ % 2 == 1)
{
nr = get_rev(buffer);
if(nr >= rev)
rev = nr+1;
}
}
pclose(cmd_pipe);
}
return rev > 0;
}
std::string generateHeader(char const* rev_str)
{
std::ostringstream newData;
newData << "#ifndef __REVISION_NR_H__" << std::endl;
newData << "#define __REVISION_NR_H__" << std::endl;
newData << " #define REVISION_NR \"" << rev_str << "\"" << std::endl;
newData << "#endif // __REVISION_NR_H__" << std::endl;
return newData.str();
}
bool write_rev()
{
char rev_str[256];
sprintf(rev_str, "%d", rev);
std::string header = generateHeader(rev_str);
if(FILE* OutputFile = fopen(write_file,"wb"))
{
fprintf(OutputFile,"%s", header.c_str());
fclose(OutputFile);
return true;
}
return false;
}
bool find_head_msg()
{
if( (cmd_pipe = popen( "git rev-list HEAD --pretty=\"format:%s\"", "rt" )) == NULL )
return false;
if(!fgets(buffer, 256, cmd_pipe)) return false;
if(!fgets(buffer, 256, cmd_pipe)) return false;
int len = (int)strnlen(buffer, 256);
if(len <= 0 || len >= 256) return false;
// clear the terminating newline
buffer[len-1] = '\0';
if(get_rev(buffer))
{
if(!allow_replace) return false;
// skip the rev number in the commit
char *p = strchr(buffer, ']');
assert(p && *(p+1));
strncpy(head_message, p+2, 256 - (p-buffer));
return true;
}
strcpy(head_message, buffer);
return true;
}
bool amend_commit()
{
char cmd[512];
sprintf(cmd, "git commit -a --amend -m \"[%d] %s\"", rev, head_message);
system(cmd);
return true;
}
int main(int argc, char *argv[])
{
for(int i = 1; i < argc; i++)
{
if(argv[i] == NULL) continue;
if(strncmp(argv[i], "-r", 2) == 0)
allow_replace = true;
if(strncmp(argv[i], "-l", 2) == 0)
local = true;
}
if(!find_path()) { printf("ERROR: can't find path\n"); return 1; }
if(!local && !find_origin()) { printf("ERROR: can't find origin\n"); return 1; }
if(!find_rev()) { printf("ERROR: can't find rev\n"); return 1; }
if(!find_head_msg()) { printf("ERROR: can't find head message\n"); return 1; }
if(!write_rev()) { printf("ERROR: can't write revision_nr.h\n"); return 1; }
if(!amend_commit()) { printf("ERROR: can't ammend commit\n"); return 1; }
return 0;
}

20
contrib/git_id/git_id.sln Normal file
View file

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "git_id", "git_id.vcproj", "{AD81BF86-050B-4605-8AF2-03C01967D784}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AD81BF86-050B-4605-8AF2-03C01967D784}.Debug|Win32.ActiveCfg = Debug|Win32
{AD81BF86-050B-4605-8AF2-03C01967D784}.Debug|Win32.Build.0 = Debug|Win32
{AD81BF86-050B-4605-8AF2-03C01967D784}.Release|Win32.ActiveCfg = Release|Win32
{AD81BF86-050B-4605-8AF2-03C01967D784}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,197 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="git_id"
ProjectGUID="{AD81BF86-050B-4605-8AF2-03C01967D784}"
RootNamespace="git_id"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\git_id.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View file

@ -30,6 +30,7 @@
#include "AccountMgr.h"
#include "SystemConfig.h"
#include "revision.h"
#include "revision_nr.h"
#include "Util.h"
bool ChatHandler::HandleHelpCommand(const char* args)
@ -95,9 +96,9 @@ bool ChatHandler::HandleServerInfoCommand(const char* /*args*/)
char const* full;
if(m_session)
full = _FULLVERSION(REVISION_DATE,REVISION_TIME,"|cffffffff|Hurl:" REVISION_ID "|h" REVISION_ID "|h|r");
full = _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,"|cffffffff|Hurl:" REVISION_ID "|h" REVISION_ID "|h|r");
else
full = _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_ID);
full = _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID);
SendSysMessage(full);
PSendSysMessage(LANG_USING_SCRIPT_LIB,sWorld.GetScriptsVersion());

View file

@ -33,6 +33,7 @@
#include "Policies/SingletonImp.h"
#include "SystemConfig.h"
#include "revision.h"
#include "revision_nr.h"
#include "Config/ConfigEnv.h"
#include "Database/DatabaseEnv.h"
#include "CliRunnable.h"
@ -196,7 +197,7 @@ Master::~Master()
/// Main function
int Master::Run()
{
sLog.outString( "%s [world-daemon]", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_ID) );
sLog.outString( "%s [world-daemon]", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID) );
sLog.outString( "<Ctrl-C> to stop.\n\n" );
sLog.outTitle( "MM MM MM MM MMMMM MMMM MMMMM");

View file

@ -46,6 +46,7 @@ libmangosshared_a_SOURCES = \
Util.cpp \
Util.h \
WorldPacket.h \
revision_nr.h \
revision.h
# Get revision (git or svn)

View file

@ -27,9 +27,9 @@
#ifndef _VERSION
#if PLATFORM == PLATFORM_WINDOWS
# define _VERSION(REVD,REVT,REV) "0.12.0-DEV" " (" REVD " " REVT " Revision " REV ")"
# define _VERSION(REVD,REVT,REVN,REVH) "0.12.0-DEV" " (" REVD " " REVT " Revision " REVN " - " REVH ")"
#else
# define _VERSION(REVD,REVT,REV) "@VERSION@" " (" REVD " " REVT " Revision " REV ")"
# define _VERSION(REVD,REVT,REVN,REVH) "@VERSION@" " (" REVD " " REVT " Revision " REVN " - " REVH ")"
#endif
#endif
@ -67,7 +67,7 @@
# define _REALMD_CONFIG SYSCONFDIR"realmd.conf"
#endif
#define _FULLVERSION(REVD,REVT,REV) _PACKAGENAME "/" _VERSION(REVD,REVT,REV) " for " _ENDIAN_PLATFORM
#define _FULLVERSION(REVD,REVT,REVN,REVH) _PACKAGENAME "/" _VERSION(REVD,REVT,REVN,REVH) " for " _ENDIAN_PLATFORM
#define DEFAULT_PLAYER_LIMIT 100
#define DEFAULT_WORLDSERVER_PORT 8085 //8129

4
src/shared/revision_nr.h Normal file
View file

@ -0,0 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "6800"
#endif // __REVISION_NR_H__

View file

@ -75,9 +75,9 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData&
if(!found)
{
strcpy(data.rev_str,"Unknown");
strcpy(data.date_str,"Unknown");
strcpy(data.time_str,"Unknown");
strcpy(data.rev_str,"*");
strcpy(data.date_str,"*");
strcpy(data.time_str,"*");
return;
}
@ -154,14 +154,14 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData&
}
else
{
strcpy(data.date_str,"Unknown");
strcpy(data.time_str,"Unknown");
strcpy(data.date_str,"*");
strcpy(data.time_str,"*");
}
}
else
{
strcpy(data.date_str,"Unknown");
strcpy(data.time_str,"Unknown");
strcpy(data.date_str,"*");
strcpy(data.time_str,"*");
}
}
@ -275,7 +275,7 @@ int main(int argc, char **argv)
if(res)
newData = generateHeader(data.rev_str,data.date_str,data.time_str);
else
newData = generateHeader("Unknown", "Unknown", "Unknown");
newData = generateHeader("*", "*", "*");
}
/// get existed header data for compare

View file

@ -447,6 +447,9 @@
Outputs="revision.h"/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\shared\revision_nr.h">
</File>
<File
RelativePath="..\..\src\shared\ServiceWin32.cpp">
</File>

View file

@ -809,6 +809,10 @@
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\shared\revision_nr.h"
>
</File>
<File
RelativePath="..\..\src\shared\SystemConfig.h.in"
>

View file

@ -805,6 +805,10 @@
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\shared\revision_nr.h"
>
</File>
<File
RelativePath="..\..\src\shared\ServiceWin32.cpp"
>