updaterevision/updaterevision.py

changeset 124
c5ff5a4704dd
parent 77
32ef969adeed
child 201
1bfa1cdffb02
--- a/updaterevision/updaterevision.py	Mon Jan 11 16:30:19 2016 +0200
+++ b/updaterevision/updaterevision.py	Mon Jan 11 16:27:53 2016 +0200
@@ -36,11 +36,11 @@
 	print 'usage: %s <output>' % sys.argv[0]
 	quit (1)
 
-oldrev = ''
+oldcompare = ''
 
 try:
 	with open (sys.argv[1]) as fp:
-		oldrev = fp.readline().replace ('\n', '').replace ('// ', '')
+		oldcompare = fp.readline().replace ('\n', '').replace ('// ', '')
 except IOError:
     pass
 
@@ -52,25 +52,32 @@
 date = datetime.utcfromtimestamp (timestamp)
 datestring = date.strftime ('%y%m%d-%H%M') if date.year >= 2000 else '000000-0000'
 
+if tags and tags != 'tip':
+	tag = tags.split(' ')[0]
+else:
+	tag = None
+
 if len(rev) > 7:
 	rev = rev[0:7]
 
 if subprocess.check_output (['hg', 'id', '-n']).replace ('\n', '')[-1] == '+':
 	rev += '+'
 
-if rev == oldrev:
-	print "%s is up to date at %s" % (sys.argv[1], rev)
+compare = tag or rev
+
+if compare == oldcompare:
+	print "%s is up to date at %s" % (sys.argv[1], compare)
 	quit (0)
 
 with open (sys.argv[1], 'w') as fp:
-	fp.write ('// %s\n' % rev)
+	fp.write ('// %s\n' % compare)
 	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':
+	if tag:
 		fp.write ('#define HG_TAG "%s"\n' % tags.split(' ')[0])
 
-	print '%s updated to %s' % (sys.argv[1], rev)
+	print '%s updated to %s' % (sys.argv[1], compare)

mercurial