updaterevision/updaterevision.py

branch
protocol5
changeset 131
4996c8684b93
parent 124
c5ff5a4704dd
child 201
1bfa1cdffb02
equal deleted inserted replaced
130:9f54db6f9922 131:4996c8684b93
34 34
35 if len (sys.argv) != 2: 35 if len (sys.argv) != 2:
36 print 'usage: %s <output>' % sys.argv[0] 36 print 'usage: %s <output>' % sys.argv[0]
37 quit (1) 37 quit (1)
38 38
39 oldrev = '' 39 oldcompare = ''
40 40
41 try: 41 try:
42 with open (sys.argv[1]) as fp: 42 with open (sys.argv[1]) as fp:
43 oldrev = fp.readline().replace ('\n', '').replace ('// ', '') 43 oldcompare = fp.readline().replace ('\n', '').replace ('// ', '')
44 except IOError: 44 except IOError:
45 pass 45 pass
46 46
47 delim='@'*10 47 delim='@'*10
48 rev, branch, timestampstr, tags = subprocess.check_output (['hg', 'log', '-r.', '--template', 48 rev, branch, timestampstr, tags = subprocess.check_output (['hg', 'log', '-r.', '--template',
50 50
51 timestamp = int (timestampstr.split(' ')[0]) 51 timestamp = int (timestampstr.split(' ')[0])
52 date = datetime.utcfromtimestamp (timestamp) 52 date = datetime.utcfromtimestamp (timestamp)
53 datestring = date.strftime ('%y%m%d-%H%M') if date.year >= 2000 else '000000-0000' 53 datestring = date.strftime ('%y%m%d-%H%M') if date.year >= 2000 else '000000-0000'
54 54
55 if tags and tags != 'tip':
56 tag = tags.split(' ')[0]
57 else:
58 tag = None
59
55 if len(rev) > 7: 60 if len(rev) > 7:
56 rev = rev[0:7] 61 rev = rev[0:7]
57 62
58 if subprocess.check_output (['hg', 'id', '-n']).replace ('\n', '')[-1] == '+': 63 if subprocess.check_output (['hg', 'id', '-n']).replace ('\n', '')[-1] == '+':
59 rev += '+' 64 rev += '+'
60 65
61 if rev == oldrev: 66 compare = tag or rev
62 print "%s is up to date at %s" % (sys.argv[1], rev) 67
68 if compare == oldcompare:
69 print "%s is up to date at %s" % (sys.argv[1], compare)
63 quit (0) 70 quit (0)
64 71
65 with open (sys.argv[1], 'w') as fp: 72 with open (sys.argv[1], 'w') as fp:
66 fp.write ('// %s\n' % rev) 73 fp.write ('// %s\n' % compare)
67 fp.write ('#define HG_NODE "%s"\n' % rev) 74 fp.write ('#define HG_NODE "%s"\n' % rev)
68 fp.write ('#define HG_BRANCH "%s"\n' % branch) 75 fp.write ('#define HG_BRANCH "%s"\n' % branch)
69 fp.write ('#define HG_DATE_VERSION "%s"\n' % datestring) 76 fp.write ('#define HG_DATE_VERSION "%s"\n' % datestring)
70 fp.write ('#define HG_DATE_STRING "%s"\n' % date.strftime ('%d %b %Y')) 77 fp.write ('#define HG_DATE_STRING "%s"\n' % date.strftime ('%d %b %Y'))
71 fp.write ('#define HG_DATE_TIME %d\n' % int (timestamp)) 78 fp.write ('#define HG_DATE_TIME %d\n' % int (timestamp))
72 79
73 if tags and tags != 'tip': 80 if tag:
74 fp.write ('#define HG_TAG "%s"\n' % tags.split(' ')[0]) 81 fp.write ('#define HG_TAG "%s"\n' % tags.split(' ')[0])
75 82
76 print '%s updated to %s' % (sys.argv[1], rev) 83 print '%s updated to %s' % (sys.argv[1], compare)

mercurial