comparison hg_delta_editor.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 a9c15cae50e5
children 9ee7ce0505eb
comparison
equal deleted inserted replaced
33:a9c15cae50e5 34:50d55c3e0d85
11 from mercurial import util 11 from mercurial import util
12 from mercurial import revlog 12 from mercurial import revlog
13 from mercurial import node 13 from mercurial import node
14 from svn import delta 14 from svn import delta
15 from svn import core 15 from svn import core
16
17 import util as our_util
16 18
17 def pickle_atomic(data, file_path, dir=None): 19 def pickle_atomic(data, file_path, dir=None):
18 """pickle some data to a path atomically. 20 """pickle some data to a path atomically.
19 21
20 This is present because I kept corrupting my revmap by managing to hit ^C 22 This is present because I kept corrupting my revmap by managing to hit ^C
71 self.subdir = subdir 73 self.subdir = subdir
72 if self.subdir and self.subdir[0] == '/': 74 if self.subdir and self.subdir[0] == '/':
73 self.subdir = self.subdir[1:] 75 self.subdir = self.subdir[1:]
74 self.revmap = {} 76 self.revmap = {}
75 if os.path.exists(self.revmap_file): 77 if os.path.exists(self.revmap_file):
76 f = open(self.revmap_file) 78 self.revmap = our_util.parse_revmap(self.revmap_file)
77 for l in f:
78 revnum, node_hash, branch = l.split(' ', 2)
79 if branch == '\n':
80 branch = None
81 else:
82 branch = branch[:-1]
83 self.revmap[int(revnum), branch] = node.bin(node_hash)
84 f.close()
85 self.branches = {} 79 self.branches = {}
86 if os.path.exists(self.branch_info_file): 80 if os.path.exists(self.branch_info_file):
87 f = open(self.branch_info_file) 81 f = open(self.branch_info_file)
88 self.branches = pickle.load(f) 82 self.branches = pickle.load(f)
89 f.close() 83 f.close()
117 assert os.path.isfile(self.uuid_file) 111 assert os.path.isfile(self.uuid_file)
118 assert os.path.isfile(self.last_revision_handled_file) 112 assert os.path.isfile(self.last_revision_handled_file)
119 else: 113 else:
120 self.repo = hg.repository(self.ui, repo_path, create=True) 114 self.repo = hg.repository(self.ui, repo_path, create=True)
121 os.makedirs(os.path.dirname(self.uuid_file)) 115 os.makedirs(os.path.dirname(self.uuid_file))
122 open(self.revmap_file, 'w') # make empty file 116 f = open(self.revmap_file, 'w')
117 f.write('%s\n' % our_util.REVMAP_FILE_VERSION)
118 f.flush()
119 f.close()
123 120
124 def clear_current_info(self): 121 def clear_current_info(self):
125 '''Clear the info relevant to a replayed revision so that the next 122 '''Clear the info relevant to a replayed revision so that the next
126 revision can be replayed. 123 revision can be replayed.
127 ''' 124 '''