# HG changeset patch # User Sean Farley # Date 1395678048 18000 # Node ID a10a4fc69364e77d1be72569d5fb18b35a6266ef # Parent 572417ad0313ece03b6c11634f6206b654f2992a 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. diff --git a/hgsubversion/maps.py b/hgsubversion/maps.py --- a/hgsubversion/maps.py +++ b/hgsubversion/maps.py @@ -256,7 +256,7 @@ class FileMap(object): VERSION = 1 - def __init__(self, ui, path): + def __init__(self, meta): '''Initialise a new FileMap. The ui argument is used to print diagnostic messages. @@ -264,17 +264,16 @@ class FileMap(object): The path argument is the location of the backing store, typically .hg/svn/filemap. ''' - self.ui = ui - self.path = path + self.meta = meta self.include = {} self.exclude = {} - if os.path.isfile(self.path): + if os.path.isfile(self.meta.filemap_file): self._load() else: self._write() # append file mapping specified from the commandline - clmap = util.configpath(self.ui, 'filemap') + clmap = util.configpath(self.meta.ui, 'filemap') if clmap: self.load(clmap) @@ -316,19 +315,19 @@ class FileMap(object): mapping = getattr(self, m) if path in mapping: msg = 'duplicate %s entry in %s: "%s"\n' - self.ui.status(msg % (m, fn, path)) + self.meta.ui.status(msg % (m, fn, path)) return bits = m.rstrip('e'), path - self.ui.debug('%sing %s\n' % bits) + self.meta.ui.debug('%sing %s\n' % bits) # respect rule order mapping[path] = len(self) - if fn != self.path: - f = open(self.path, 'a') + if fn != self.meta.filemap_file: + f = open(self.meta.filemap_file, 'a') f.write(m + ' ' + path + '\n') f.close() def load(self, fn): - self.ui.debug('reading file map from %s\n' % fn) + self.meta.ui.debug('reading file map from %s\n' % fn) f = open(fn, 'r') self.load_fd(f, fn) f.close() @@ -344,22 +343,22 @@ class FileMap(object): if cmd in ('include', 'exclude'): self.add(fn, cmd, path) continue - self.ui.warn('unknown filemap command %s\n' % cmd) + self.meta.ui.warn('unknown filemap command %s\n' % cmd) except IndexError: msg = 'ignoring bad line in filemap %s: %s\n' - self.ui.warn(msg % (fn, line.rstrip())) + self.meta.ui.warn(msg % (fn, line.rstrip())) def _load(self): - self.ui.debug('reading in-repo file map from %s\n' % self.path) - f = open(self.path) + self.meta.ui.debug('reading in-repo file map from %s\n' % self.meta.filemap_file) + f = open(self.meta.filemap_file) ver = int(f.readline()) if ver != self.VERSION: raise hgutil.Abort('filemap too new -- please upgrade') - self.load_fd(f, self.path) + self.load_fd(f, self.meta.filemap_file) f.close() def _write(self): - f = open(self.path, 'w') + f = open(self.meta.filemap_file, 'w') f.write('%s\n' % self.VERSION) f.close() diff --git a/hgsubversion/svnmeta.py b/hgsubversion/svnmeta.py --- a/hgsubversion/svnmeta.py +++ b/hgsubversion/svnmeta.py @@ -234,7 +234,7 @@ class SVNMeta(object): @property def filemap(self): if self._filemap is None: - self._filemap = maps.FileMap(self.ui, self.filemap_file) + self._filemap = maps.FileMap(self) return self._filemap @property