comparison hgsubversion/maps.py @ 415:b17b2969861c

svnmeta: move revmap methods, make last_known_revision() more efficient
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Thu, 11 Jun 2009 10:32:32 +0200
parents d4615986e1db
children 2851b81c65ce
comparison
equal deleted inserted replaced
414:343da842dbe6 415:b17b2969861c
99 VERSION = 1 99 VERSION = 1
100 100
101 def __init__(self, repo): 101 def __init__(self, repo):
102 dict.__init__(self) 102 dict.__init__(self)
103 self.path = os.path.join(repo.path, 'svn', 'rev_map') 103 self.path = os.path.join(repo.path, 'svn', 'rev_map')
104 self.seen = 0
104 if os.path.isfile(self.path): 105 if os.path.isfile(self.path):
105 self._load() 106 self._load()
106 else: 107 else:
107 self._write() 108 self._write()
109
110 def hashes(self):
111 return dict((v, k) for (k, v) in self.iteritems())
112
113 def branchedits(self, branch, rev):
114 check = lambda x: x[0][1] == branch and x[0][0] < rev.revnum
115 return sorted(filter(check, self.iteritems()), reverse=True)
108 116
109 def _load(self): 117 def _load(self):
110 f = open(self.path) 118 f = open(self.path)
111 ver = int(f.readline()) 119 ver = int(f.readline())
112 if ver != self.VERSION: 120 if ver != self.VERSION:
116 revnum, hash, branch = l.split(' ', 2) 124 revnum, hash, branch = l.split(' ', 2)
117 if branch == '\n': 125 if branch == '\n':
118 branch = None 126 branch = None
119 else: 127 else:
120 branch = branch[:-1] 128 branch = branch[:-1]
121 dict.__setitem__(self, (int(revnum), branch), node.bin(hash)) 129 revnum = int(revnum)
130 self.seen = max(self.seen, revnum)
131 dict.__setitem__(self, (revnum, branch), node.bin(hash))
122 f.close() 132 f.close()
123 133
124 def _write(self): 134 def _write(self):
125 f = open(self.path, 'w') 135 f = open(self.path, 'w')
126 f.write('%s\n' % self.VERSION) 136 f.write('%s\n' % self.VERSION)
132 f = open(self.path, 'a') 142 f = open(self.path, 'a')
133 b = branch or '' 143 b = branch or ''
134 f.write(str(revnum) + ' ' + node.hex(hash) + ' ' + b + '\n') 144 f.write(str(revnum) + ' ' + node.hex(hash) + ' ' + b + '\n')
135 f.flush() 145 f.flush()
136 f.close() 146 f.close()
147 self.seen = max(self.seen, revnum)
137 dict.__setitem__(self, (revnum, branch), hash) 148 dict.__setitem__(self, (revnum, branch), hash)
138 149
139 150
140 class FileMap(object): 151 class FileMap(object):
141 152