Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate

Fri, 15 May 2015 21:43:21 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Fri, 15 May 2015 21:43:21 +0300
changeset 77
32ef969adeed
parent 76
6de6d9a64ebd
child 78
c1d43ade656e
child 81
a18aaf460648

Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate

sources/version.cpp file | annotate | diff | comparison | revisions
updaterevision/updaterevision.py file | annotate | diff | comparison | revisions
--- a/sources/version.cpp	Fri May 15 20:13:36 2015 +0300
+++ b/sources/version.cpp	Fri May 15 21:43:21 2015 +0300
@@ -42,8 +42,8 @@
 //
 const char* full_version_string()
 {
-#ifdef IS_RELEASE
-	return VERSION_STRING;
+#ifdef HG_TAG
+	return HG_TAG;
 #else
 	static char buffer[128] = {0};
 
--- a/updaterevision/updaterevision.py	Fri May 15 20:13:36 2015 +0300
+++ b/updaterevision/updaterevision.py	Fri May 15 21:43:21 2015 +0300
@@ -33,41 +33,44 @@
 from datetime import datetime
 
 if len (sys.argv) != 2:
-    print 'usage: %s <output>' % sys.argv[0]
-    quit (1)
+	print 'usage: %s <output>' % sys.argv[0]
+	quit (1)
 
 oldrev = ''
 
 try:
-    with open (sys.argv[1]) as fp:
-        oldrev = fp.readline().replace ('\n', '').replace ('// ', '')
+	with open (sys.argv[1]) as fp:
+		oldrev = fp.readline().replace ('\n', '').replace ('// ', '')
 except IOError:
     pass
 
-data = subprocess.check_output (['hg', 'log', '-r.', '--template',
-    '{node|short} {branch} {date|hgdate}']).replace ('\n', '').split (' ')
+delim='@'*10
+rev, branch, timestampstr, tags = subprocess.check_output (['hg', 'log', '-r.', '--template',
+	delim.join (['{node|short}', '{branch}', '{date|hgdate}', '{tags}'])]).replace ('\n', '').split (delim)
 
-rev = data[0]
-branch = data[1]
-timestamp = int (data[2])
+timestamp = int (timestampstr.split(' ')[0])
 date = datetime.utcfromtimestamp (timestamp)
 datestring = date.strftime ('%y%m%d-%H%M') if date.year >= 2000 else '000000-0000'
 
 if len(rev) > 7:
-    rev = rev[0:7]
+	rev = rev[0:7]
 
 if subprocess.check_output (['hg', 'id', '-n']).replace ('\n', '')[-1] == '+':
-    rev += '+'
+	rev += '+'
 
 if rev == oldrev:
-    print "%s is up to date at %s" % (sys.argv[1], rev)
-    quit (0)
+	print "%s is up to date at %s" % (sys.argv[1], rev)
+	quit (0)
 
 with open (sys.argv[1], 'w') as fp:
-    fp.write ('// %s\n' % rev)
-    fp.write ('#define HG_NODE "%s"\n' % rev)
-    fp.write ('#define HG_BRANCH "%s"\n' % branch)
-    fp.write ('#define HG_DATE_VERSION "%s"\n' % datestring)
-    fp.write ('#define HG_DATE_STRING "%s"\n' % date.strftime ('%d %b %Y'))
-    fp.write ('#define HG_DATE_TIME %d\n' % int (timestamp))
-    print '%s updated to %s' % (sys.argv[1], rev)
+	fp.write ('// %s\n' % rev)
+	fp.write ('#define HG_NODE "%s"\n' % rev)
+	fp.write ('#define HG_BRANCH "%s"\n' % branch)
+	fp.write ('#define HG_DATE_VERSION "%s"\n' % datestring)
+	fp.write ('#define HG_DATE_STRING "%s"\n' % date.strftime ('%d %b %Y'))
+	fp.write ('#define HG_DATE_TIME %d\n' % int (timestamp))
+
+	if tags and tags != 'tip':
+		fp.write ('#define HG_TAG "%s"\n' % tags.split(' ')[0])
+
+	print '%s updated to %s' % (sys.argv[1], rev)

mercurial