summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-02-14 19:13:14 -0200
committershennetsind <ind@henn.et>2013-02-14 19:22:56 -0200
commit82005a99f5b1cca68e9fb1ac6b1614c815e4bd45 (patch)
tree219766035a17c63286c5be2b3699a07868810b21 /src
parentef503ce5ad834d4601d6420bddf85655b6428c24 (diff)
downloadhercules-82005a99f5b1cca68e9fb1ac6b1614c815e4bd45.tar.gz
hercules-82005a99f5b1cca68e9fb1ac6b1614c815e4bd45.tar.bz2
hercules-82005a99f5b1cca68e9fb1ac6b1614c815e4bd45.tar.xz
hercules-82005a99f5b1cca68e9fb1ac6b1614c815e4bd45.zip
Introducing Git Hash
Added 'Git Hash' way to identify where you last updated your working copy (it won't detect your local changes' hash -- intended). Also Implemented HERC_UNKNOWN_VER, a simple way to detect whether get_svn_revision or get_git_hash failed to detect (before you'd need to strncmp for "unknown" or similars) Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src')
-rw-r--r--src/common/core.c40
-rw-r--r--src/common/core.h5
-rw-r--r--src/map/pc.c11
-rw-r--r--src/map/script.c6
4 files changed, 52 insertions, 10 deletions
diff --git a/src/common/core.c b/src/common/core.c
index 42cdfa7cd..d1a374b29 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -254,17 +254,46 @@ const char* get_svn_revision(void)
}
// fallback
- snprintf(svn_version_buffer, sizeof(svn_version_buffer), "Unknown");
+ svn_version_buffer[0] = HERC_UNKNOWN_VER;
return svn_version_buffer;
}
#endif
-
+/* whats our origin */
+#define GIT_ORIGIN "master"
+/* Grabs the hash from the last time the user updated his working copy (last pull) */
+const char *get_git_hash (void) {
+ static char HerculesGitHash[41] = "";//Sha(40) + 1
+ FILE *fp;
+
+ if( HerculesGitHash[0] != '\0' )
+ return HerculesGitHash;
+
+ if ( (fp = fopen (".git/refs/remotes/origin/"GIT_ORIGIN, "r")) != NULL) {
+ char line[64];
+ char *rev = malloc (sizeof (char) * 50);
+
+ if (fgets (line, sizeof (line), fp) && sscanf (line, "%s", rev))
+ snprintf (HerculesGitHash, sizeof (HerculesGitHash), "%s", rev);
+
+ free (rev);
+ fclose (fp);
+ } else {
+ HerculesGitHash[0] = HERC_UNKNOWN_VER;
+ }
+
+ if (! (*HerculesGitHash)) {
+ HerculesGitHash[0] = HERC_UNKNOWN_VER;
+ }
+
+ return HerculesGitHash;
+}
/*======================================
* CORE : Display title
* ASCII By CalciumKid 1/12/2011
*--------------------------------------*/
static void display_title(void) {
- //ClearScreen(); // clear screen and go up/left (0, 0 position in text)
+ const char* svn = get_svn_revision();
+ const char* git = get_git_hash();
ShowMessage("\n");
ShowMessage(""CL_BG_RED" "CL_BT_WHITE" "CL_BG_RED""CL_CLL""CL_NORMAL"\n");
@@ -279,7 +308,10 @@ static void display_title(void) {
ShowMessage(""CL_BG_RED" "CL_BT_WHITE" http://hercules.ws/board/ "CL_BG_RED""CL_CLL""CL_NORMAL"\n");
ShowMessage(""CL_BG_RED" "CL_BT_WHITE" "CL_BG_RED""CL_CLL""CL_NORMAL"\n");
- //ShowInfo("SVN Revision: '"CL_WHITE"%s"CL_RESET"'.\n", get_svn_revision());
+ if( git[0] != HERC_UNKNOWN_VER )
+ ShowInfo("Git Hash: '"CL_WHITE"%s"CL_RESET"'\n", git);
+ else if( svn[0] != HERC_UNKNOWN_VER )
+ ShowInfo("SVN Revision: '"CL_WHITE"%s"CL_RESET"'\n", svn);
}
// Warning if executed as superuser (root)
diff --git a/src/common/core.h b/src/common/core.h
index f619d821f..8007e6036 100644
--- a/src/common/core.h
+++ b/src/common/core.h
@@ -16,6 +16,8 @@ extern char **arg_v;
extern int buildbotflag;
#endif
+#define HERC_UNKNOWN_VER '\x02'
+
/// @see E_CORE_ST
extern int runflag;
extern char *SERVER_NAME;
@@ -31,7 +33,8 @@ enum {
extern char SERVER_TYPE;
extern int parse_console(const char* buf);
-extern const char *get_svn_revision(void);
+const char *get_svn_revision(void);
+const char *get_git_hash (void);
extern int do_init(int,char**);
extern void set_server_type(void);
extern void do_abort(void);
diff --git a/src/map/pc.c b/src/map/pc.c
index 1bc37040e..e544fdd53 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -1058,9 +1058,16 @@ bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_tim
if( !changing_mapservers ) {
- if (battle_config.display_version == 1){
+ if (battle_config.display_version == 1) {
+ const char* svn = get_svn_revision();
+ const char* git = get_git_hash();
char buf[256];
- sprintf(buf, "SVN version: %s", get_svn_revision());
+ if( git[0] != HERC_UNKNOWN_VER )
+ sprintf(buf,"Git Hash: %s", git);
+ else if( svn[0] != HERC_UNKNOWN_VER )
+ sprintf(buf,"SVN Revision: %s", svn);
+ else
+ sprintf(buf,"Unknown Version");
clif_displaymessage(sd->fd, buf);
}
diff --git a/src/map/script.c b/src/map/script.c
index 83b6c1a68..fe00599a6 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -16992,10 +16992,10 @@ BUILDIN_FUNC(is_function) {
* get_revision() -> retrieves the current svn revision (if available)
**/
BUILDIN_FUNC(get_revision) {
- const char * revision;
+ const char *svn = get_svn_revision();
- if ( (revision = get_svn_revision()) != 0 )
- script_pushint(st,atoi(revision));
+ if ( svn[0] != HERC_UNKNOWN_VER )
+ script_pushint(st,atoi(svn));
else
script_pushint(st,-1);//unknown