diff --git a/contrib/git_id/git_id.cpp b/contrib/git_id/git_id.cpp new file mode 100644 index 000000000..573cd40fd --- /dev/null +++ b/contrib/git_id/git_id.cpp @@ -0,0 +1,211 @@ +#include +#include +#include +#include +#include +#include +#include +#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; +} \ No newline at end of file diff --git a/contrib/git_id/git_id.sln b/contrib/git_id/git_id.sln new file mode 100644 index 000000000..2decdb34c --- /dev/null +++ b/contrib/git_id/git_id.sln @@ -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 diff --git a/contrib/git_id/git_id.vcproj b/contrib/git_id/git_id.vcproj new file mode 100644 index 000000000..345c69f08 --- /dev/null +++ b/contrib/git_id/git_id.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/game/Level0.cpp b/src/game/Level0.cpp index 23d0ae052..b6012d47c 100644 --- a/src/game/Level0.cpp +++ b/src/game/Level0.cpp @@ -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()); diff --git a/src/mangosd/Master.cpp b/src/mangosd/Master.cpp index 6435d8dfc..cc8ab7381 100644 --- a/src/mangosd/Master.cpp +++ b/src/mangosd/Master.cpp @@ -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( " to stop.\n\n" ); sLog.outTitle( "MM MM MM MM MMMMM MMMM MMMMM"); diff --git a/src/shared/Makefile.am b/src/shared/Makefile.am index 915076a15..c393e6826 100644 --- a/src/shared/Makefile.am +++ b/src/shared/Makefile.am @@ -46,6 +46,7 @@ libmangosshared_a_SOURCES = \ Util.cpp \ Util.h \ WorldPacket.h \ + revision_nr.h \ revision.h # Get revision (git or svn) diff --git a/src/shared/SystemConfig.h.in b/src/shared/SystemConfig.h.in index 863fab1e5..f2bf66d06 100644 --- a/src/shared/SystemConfig.h.in +++ b/src/shared/SystemConfig.h.in @@ -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 diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h new file mode 100644 index 000000000..a81b584d4 --- /dev/null +++ b/src/shared/revision_nr.h @@ -0,0 +1,4 @@ +#ifndef __REVISION_NR_H__ +#define __REVISION_NR_H__ + #define REVISION_NR "6800" +#endif // __REVISION_NR_H__ diff --git a/src/tools/genrevision/genrevision.cpp b/src/tools/genrevision/genrevision.cpp index 9367addc1..a9e39d93c 100644 --- a/src/tools/genrevision/genrevision.cpp +++ b/src/tools/genrevision/genrevision.cpp @@ -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 diff --git a/win/VC71/shared.vcproj b/win/VC71/shared.vcproj index 924ccdb91..5321788cb 100644 --- a/win/VC71/shared.vcproj +++ b/win/VC71/shared.vcproj @@ -447,6 +447,9 @@ Outputs="revision.h"/> + + diff --git a/win/VC80/shared.vcproj b/win/VC80/shared.vcproj index 9ca9a66ec..291b4e9c6 100644 --- a/win/VC80/shared.vcproj +++ b/win/VC80/shared.vcproj @@ -809,6 +809,10 @@ /> + + diff --git a/win/VC90/shared.vcproj b/win/VC90/shared.vcproj index de3fa88df..f6ad561c0 100644 --- a/win/VC90/shared.vcproj +++ b/win/VC90/shared.vcproj @@ -805,6 +805,10 @@ /> + +