changeset 1383:73c76f99ca08

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.
author Sean Farley <sean.michael.farley@gmail.com>
date Mon, 24 Mar 2014 11:20:58 -0500
parents d996850ac4e8
children 2d1d05e6e46c
files hgsubversion/maps.py
diffstat 1 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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.