# HG changeset patch # User Sean Farley # Date 1395678058 18000 # Node ID 73c76f99ca089d6bf8b950eb56041b1d441fcd73 # Parent d996850ac4e8ee0c8d665d68baf5b9d3b989d2b7 maps: add a basemap class We add a new class, BaseMap, so that we can factor out common code for all the different type of map classes. diff --git a/hgsubversion/maps.py b/hgsubversion/maps.py --- a/hgsubversion/maps.py +++ b/hgsubversion/maps.py @@ -9,6 +9,25 @@ import subprocess import svncommands import util +class BaseMap(dict): + '''A base class for the different type of mappings: author, branch, and + tags.''' + def __init__(self, meta): + self.meta = meta + super(BaseMap, self).__init__() + + # trickery: all subclasses have the same name as their file and config + # names, e.g. AuthorMap is meta.authormap_file for the filename and + # 'authormap' for the config option + self.mapname = self.__class__.__name__.lower() + self.mapfilename = self.mapname + '_file' + self.load(self.meta.__getattribute__(self.mapfilename)) + + # append mappings specified from the commandline + clmap = util.configpath(self.meta.ui, self.mapname) + if clmap: + self.load(clmap) + class AuthorMap(dict): '''A mapping from Subversion-style authors to Mercurial-style authors, and back. The data is stored persistently on disk.