comparison hgsubversion/maps.py @ 1217:a10a4fc69364

maps: change filemap to initialize with an svnmeta object This refactoring will help us in a future patch have all map objects inherit from a common ancestor.
author Sean Farley <sean.michael.farley@gmail.com>
date Mon, 24 Mar 2014 11:20:48 -0500
parents 572417ad0313
children 46cec117dda2
comparison
equal deleted inserted replaced
1216:572417ad0313 1217:a10a4fc69364
254 254
255 class FileMap(object): 255 class FileMap(object):
256 256
257 VERSION = 1 257 VERSION = 1
258 258
259 def __init__(self, ui, path): 259 def __init__(self, meta):
260 '''Initialise a new FileMap. 260 '''Initialise a new FileMap.
261 261
262 The ui argument is used to print diagnostic messages. 262 The ui argument is used to print diagnostic messages.
263 263
264 The path argument is the location of the backing store, 264 The path argument is the location of the backing store,
265 typically .hg/svn/filemap. 265 typically .hg/svn/filemap.
266 ''' 266 '''
267 self.ui = ui 267 self.meta = meta
268 self.path = path
269 self.include = {} 268 self.include = {}
270 self.exclude = {} 269 self.exclude = {}
271 if os.path.isfile(self.path): 270 if os.path.isfile(self.meta.filemap_file):
272 self._load() 271 self._load()
273 else: 272 else:
274 self._write() 273 self._write()
275 274
276 # append file mapping specified from the commandline 275 # append file mapping specified from the commandline
277 clmap = util.configpath(self.ui, 'filemap') 276 clmap = util.configpath(self.meta.ui, 'filemap')
278 if clmap: 277 if clmap:
279 self.load(clmap) 278 self.load(clmap)
280 279
281 def _rpairs(self, name): 280 def _rpairs(self, name):
282 e = len(name) 281 e = len(name)
314 313
315 def add(self, fn, m, path): 314 def add(self, fn, m, path):
316 mapping = getattr(self, m) 315 mapping = getattr(self, m)
317 if path in mapping: 316 if path in mapping:
318 msg = 'duplicate %s entry in %s: "%s"\n' 317 msg = 'duplicate %s entry in %s: "%s"\n'
319 self.ui.status(msg % (m, fn, path)) 318 self.meta.ui.status(msg % (m, fn, path))
320 return 319 return
321 bits = m.rstrip('e'), path 320 bits = m.rstrip('e'), path
322 self.ui.debug('%sing %s\n' % bits) 321 self.meta.ui.debug('%sing %s\n' % bits)
323 # respect rule order 322 # respect rule order
324 mapping[path] = len(self) 323 mapping[path] = len(self)
325 if fn != self.path: 324 if fn != self.meta.filemap_file:
326 f = open(self.path, 'a') 325 f = open(self.meta.filemap_file, 'a')
327 f.write(m + ' ' + path + '\n') 326 f.write(m + ' ' + path + '\n')
328 f.close() 327 f.close()
329 328
330 def load(self, fn): 329 def load(self, fn):
331 self.ui.debug('reading file map from %s\n' % fn) 330 self.meta.ui.debug('reading file map from %s\n' % fn)
332 f = open(fn, 'r') 331 f = open(fn, 'r')
333 self.load_fd(f, fn) 332 self.load_fd(f, fn)
334 f.close() 333 f.close()
335 334
336 def load_fd(self, f, fn): 335 def load_fd(self, f, fn):
342 cmd = cmd.strip() 341 cmd = cmd.strip()
343 path = path.strip() 342 path = path.strip()
344 if cmd in ('include', 'exclude'): 343 if cmd in ('include', 'exclude'):
345 self.add(fn, cmd, path) 344 self.add(fn, cmd, path)
346 continue 345 continue
347 self.ui.warn('unknown filemap command %s\n' % cmd) 346 self.meta.ui.warn('unknown filemap command %s\n' % cmd)
348 except IndexError: 347 except IndexError:
349 msg = 'ignoring bad line in filemap %s: %s\n' 348 msg = 'ignoring bad line in filemap %s: %s\n'
350 self.ui.warn(msg % (fn, line.rstrip())) 349 self.meta.ui.warn(msg % (fn, line.rstrip()))
351 350
352 def _load(self): 351 def _load(self):
353 self.ui.debug('reading in-repo file map from %s\n' % self.path) 352 self.meta.ui.debug('reading in-repo file map from %s\n' % self.meta.filemap_file)
354 f = open(self.path) 353 f = open(self.meta.filemap_file)
355 ver = int(f.readline()) 354 ver = int(f.readline())
356 if ver != self.VERSION: 355 if ver != self.VERSION:
357 raise hgutil.Abort('filemap too new -- please upgrade') 356 raise hgutil.Abort('filemap too new -- please upgrade')
358 self.load_fd(f, self.path) 357 self.load_fd(f, self.meta.filemap_file)
359 f.close() 358 f.close()
360 359
361 def _write(self): 360 def _write(self):
362 f = open(self.path, 'w') 361 f = open(self.meta.filemap_file, 'w')
363 f.write('%s\n' % self.VERSION) 362 f.write('%s\n' % self.VERSION)
364 f.close() 363 f.close()
365 364
366 class BranchMap(dict): 365 class BranchMap(dict):
367 '''Facility for controlled renaming of branch names. Example: 366 '''Facility for controlled renaming of branch names. Example: