comparison util.py @ 34:50d55c3e0d85

Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
author Augie Fackler <durin42@gmail.com>
date Fri, 17 Oct 2008 11:03:52 -0500
parents 1267b1944cd7
children b3c7b844b782
comparison
equal deleted inserted replaced
33:a9c15cae50e5 34:50d55c3e0d85
1 import os 1 import os
2 import pickle
2 import shutil 3 import shutil
4
5 from mercurial import node
3 6
4 svn_subcommands = { } 7 svn_subcommands = { }
5 8
6 def register_subcommand(name): 9 def register_subcommand(name):
7 def inner(fn): 10 def inner(fn):
16 f = os.path.join(hg_wc_path, f) 19 f = os.path.join(hg_wc_path, f)
17 if os.path.isdir(f): 20 if os.path.isdir(f):
18 shutil.rmtree(f) 21 shutil.rmtree(f)
19 else: 22 else:
20 os.remove(f) 23 os.remove(f)
24
25 REVMAP_FILE_VERSION = 1
26 def parse_revmap(revmap_filename):
27 revmap = {}
28 f = open(revmap_filename)
29 try:
30 # Remove compat code after March of 2009. That should be more than long
31 # enough.
32 revmap = pickle.load(f)
33 f.close()
34 f = open(revmap_filename, 'w')
35 f.write('1\n')
36 for key, value in sorted(revmap.items()):
37 f.write('%s %s %s\n' % (str(key[0]), node.hex(value), key[1] or ''))
38 f.close()
39 except:
40 f.close()
41 f = open(revmap_filename)
42 ver = int(f.readline())
43 if ver == 1:
44 for l in f:
45 revnum, node_hash, branch = l.split(' ', 2)
46 if branch == '\n':
47 branch = None
48 else:
49 branch = branch[:-1]
50 revmap[int(revnum), branch] = node.bin(node_hash)
51 f.close()
52 else:
53 print ('Your revmap was made by a newer version of hgsubversion.'
54 ' Please upgrade.')
55 raise NotImplementedError
56 return revmap
57