Use tags as a compare basis for updating the revision if available, so that when a revision gets tagged, hginfo.h gets updated.

Mon, 11 Jan 2016 16:27:53 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 11 Jan 2016 16:27:53 +0200
changeset 124
c5ff5a4704dd
parent 123
79830bf162c0
child 125
d8ecf07a76cf

Use tags as a compare basis for updating the revision if available, so that when a revision gets tagged, hginfo.h gets updated.

.hgtags file | annotate | diff | comparison | revisions
updaterevision/updaterevision.py file | annotate | diff | comparison | revisions
--- a/.hgtags	Mon Jan 11 16:30:19 2016 +0200
+++ b/.hgtags	Mon Jan 11 16:27:53 2016 +0200
@@ -1,2 +1,3 @@
 5e968dc8d552598f5bb5343bd5fa0c24088b6ee9 1.0
 9d640b94ef020c61359bedfd93831c935b904b2b 1.1
+558278b282a08b7563423b399e0d5f2f36004625 test
--- 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