changeset 1266:5ee3e5030a35

Merge with stable.
author Augie Fackler <raf@durin42.com>
date Sat, 15 Nov 2014 12:35:51 -0500
parents 4744b7bfa476 (diff) 85fe080461c6 (current diff)
children 5f86e2ac7659
files hgsubversion/svncommands.py
diffstat 9 files changed, 65 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/layouts/__init__.py
+++ b/hgsubversion/layouts/__init__.py
@@ -13,14 +13,12 @@ from mercurial import util as hgutil
 
 import custom
 import detect
-import persist
 import single
 import standard
 
 __all__ = [
     "detect",
     "layout_from_name",
-    "persist",
     ]
 
 # This is the authoritative store of what layouts are available.
@@ -33,7 +31,7 @@ NAME_TO_CLASS = {
 }
 
 
-def layout_from_name(name, ui):
+def layout_from_name(name, meta):
     """Returns a layout module given the layout name
 
     You should use one of the layout.detect.* functions to get the
@@ -42,5 +40,5 @@ def layout_from_name(name, ui):
     """
 
     if name not in NAME_TO_CLASS:
-        raise hgutil.Abort('Unknown hgsubversion layout: %s' %name)
-    return NAME_TO_CLASS[name](ui)
+        raise hgutil.Abort('Unknown hgsubversion layout: %s' % name)
+    return NAME_TO_CLASS[name](meta)
--- a/hgsubversion/layouts/base.py
+++ b/hgsubversion/layouts/base.py
@@ -9,8 +9,8 @@ from mercurial import util as hgutil
 
 class BaseLayout(object):
 
-    def __init__(self, ui):
-        self.ui = ui
+    def __init__(self, meta):
+        self.meta = meta
 
     def __unimplemented(self, method_name):
         raise NotImplementedError(
--- a/hgsubversion/layouts/custom.py
+++ b/hgsubversion/layouts/custom.py
@@ -12,13 +12,13 @@ import base
 
 class CustomLayout(base.BaseLayout):
 
-    def __init__(self, ui):
-        base.BaseLayout.__init__(self, ui)
+    def __init__(self, meta):
+        base.BaseLayout.__init__(self, meta)
 
         self.svn_to_hg = {}
         self.hg_to_svn = {}
 
-        for hg_branch, svn_path in ui.configitems('hgsubversionbranch'):
+        for hg_branch, svn_path in meta.ui.configitems('hgsubversionbranch'):
 
             hg_branch = hg_branch.strip()
             if hg_branch == 'default' or not hg_branch:
--- a/hgsubversion/layouts/detect.py
+++ b/hgsubversion/layouts/detect.py
@@ -12,7 +12,7 @@ from mercurial import util as hgutil
 
 import __init__ as layouts
 
-def layout_from_subversion(svn, revision=None, ui=None):
+def layout_from_subversion(svn, revision=None, meta=None):
     """ Guess what layout to use based on directories under the svn root.
 
     This is intended for use during bootstrapping.  It guesses which
@@ -39,10 +39,10 @@ def layout_from_subversion(svn, revision
         layout = 'standard'
     else:
         layout = 'single'
-    ui.setconfig('hgsubversion', 'layout', layout)
+    meta.ui.setconfig('hgsubversion', 'layout', layout)
     return layout
 
-def layout_from_config(ui, allow_auto=False):
+def layout_from_config(meta, allow_auto=False):
     """ Load the layout we are using based on config
 
     We will read the config from the ui object.  Pass allow_auto=True
@@ -51,32 +51,29 @@ def layout_from_config(ui, allow_auto=Fa
     detect the layout as auto.
     """
 
-    layout = ui.config('hgsubversion', 'layout', default='auto')
+    layout = meta.ui.config('hgsubversion', 'layout', default='auto')
     if layout == 'auto' and not allow_auto:
         raise hgutil.Abort('layout not yet determined')
     elif layout not in layouts.NAME_TO_CLASS and layout != 'auto':
         raise hgutil.Abort("unknown layout '%s'" % layout)
     return layout
 
-def layout_from_file(metapath, ui=None):
+def layout_from_file(meta):
     """ Load the layout in use from the metadata file.
-
-    If you pass the ui arg, we will also write the layout to the
-    config for that ui.
-
     """
 
-    layout = None
-    layoutfile = os.path.join(metapath, 'layout')
-    if os.path.exists(layoutfile):
-        f = open(layoutfile)
-        layout = f.read().strip()
-        f.close()
-        if ui:
-            ui.setconfig('hgsubversion', 'layout', layout)
+    # import late to avoid trouble when running the test suite
+    try:
+        from hgext_hgsubversion import util
+    except ImportError:
+        from hgsubversion import util
+
+    layout = util.load(meta.layout_file)
+    if layout:
+        meta.ui.setconfig('hgsubversion', 'layout', layout)
     return layout
 
-def layout_from_commit(subdir, revpath, branch, ui):
+def layout_from_commit(subdir, revpath, branch, meta):
     """ Guess what the layout is based existing commit info
 
     Specifically, this compares the subdir for the repository and the
@@ -93,7 +90,7 @@ def layout_from_commit(subdir, revpath, 
 
     candidates = set()
     for layout in layouts.NAME_TO_CLASS:
-        layoutobj = layouts.layout_from_name(layout, ui)
+        layoutobj = layouts.layout_from_name(layout, meta)
         try:
             remotepath = layoutobj.remotepath(branch, subdir)
         except KeyError:
@@ -104,7 +101,7 @@ def layout_from_commit(subdir, revpath, 
     if len(candidates) == 1:
         return candidates.pop()
     elif candidates:
-        config_layout = layout_from_config(ui, allow_auto=True)
+        config_layout = layout_from_config(meta, allow_auto=True)
         if config_layout in candidates:
             return config_layout
 
deleted file mode 100644
--- a/hgsubversion/layouts/persist.py
+++ /dev/null
@@ -1,16 +0,0 @@
-"""Code for persisting the layout config in various locations.
-
-Basically, if you want to save the layout, this is where you should go
-to do it.
-
-"""
-
-import os.path
-
-def layout_to_file(metapath, layout):
-    """Save the given layout to a file under the given metapath"""
-
-    layoutfile = os.path.join(metapath, 'layout')
-    f = open(layoutfile, 'w')
-    f.write(layout)
-    f.close()
--- a/hgsubversion/layouts/standard.py
+++ b/hgsubversion/layouts/standard.py
@@ -5,18 +5,18 @@ import base
 class StandardLayout(base.BaseLayout):
     """The standard trunk, branches, tags layout"""
 
-    def __init__(self, ui):
-        base.BaseLayout.__init__(self, ui)
+    def __init__(self, meta):
+        base.BaseLayout.__init__(self, meta)
 
         self._tag_locations = None
 
-        self._branch_dir = ui.config('hgsubversion', 'branchdir', 'branches')
+        self._branch_dir = self.meta.ui.config('hgsubversion', 'branchdir', 'branches')
         if self._branch_dir[0] == '/':
             self._branch_dir = self._branch_dir[1:]
         if self._branch_dir[-1] != '/':
             self._branch_dir += '/'
 
-        self._infix = ui.config('hgsubversion', 'infix', '').strip('/')
+        self._infix = self.meta.ui.config('hgsubversion', 'infix', '').strip('/')
         if self._infix:
             self._infix = '/' + self._infix
 
@@ -69,9 +69,9 @@ class StandardLayout(base.BaseLayout):
             self._tag_locations = util.load(tag_locations_file)
 
             if not self._tag_locations:
-                self._tag_locations = self.ui.configlist('hgsubversion',
-                                                        'tagpaths',
-                                                        ['tags'])
+                self._tag_locations = self.meta.ui.configlist('hgsubversion',
+                                                              'tagpaths',
+                                                              ['tags'])
             util.dump(self._tag_locations, tag_locations_file)
 
             # ensure nested paths are handled properly
--- a/hgsubversion/svncommands.py
+++ b/hgsubversion/svncommands.py
@@ -189,11 +189,11 @@ def _buildmeta(ui, repo, args, partial=F
 
         if layout is None:
             layout = layouts.detect.layout_from_commit(subdir, revpath,
-                                                       ctx.branch(), ui)
-            existing_layout = layouts.detect.layout_from_file(meta.metapath)
+                                                       ctx.branch(), meta)
+            existing_layout = layouts.detect.layout_from_file(meta)
             if layout != existing_layout:
-                layouts.persist.layout_to_file(meta.metapath, layout)
-            layoutobj = layouts.layout_from_name(layout, ui)
+                util.dump(layout, meta.layout_file)
+            layoutobj = layouts.layout_from_name(layout, meta)
         elif layout == 'single':
             assert (subdir or '/') == revpath, ('Possible layout detection'
                                                 ' defect in replay')
--- a/hgsubversion/svnmeta.py
+++ b/hgsubversion/svnmeta.py
@@ -22,42 +22,44 @@ class SVNMeta(object):
         subdir is the subdirectory of the edits *on the svn server*.
         It is needed for stripping paths off in certain cases.
         """
+        # simple and public variables
         self.ui = repo.ui
         self.repo = repo
         self.path = os.path.normpath(repo.join('..'))
+        self.firstpulled = 0
+        self.lastdate = '1970-01-01 00:00:00 -0000'
+        self.addedtags = {}
+        self.deletedtags = {}
+
+        # private variables
         self._skiperror = skiperrorcheck
+        self._tags = None
+        self._layoutobj = None
+        self._revmap = None
+        self._authors = None
+        self._branchmap = None
+        self._tagmap = None
+        self._filemap = None
 
+        # create .hg/svn folder if it doesn't exist
         if not os.path.isdir(self.metapath):
             os.makedirs(self.metapath)
+
+        # properties that need .hg/svn to exist
         self.uuid = uuid
         self.subdir = subdir
-        self._revmap = None
-        self.firstpulled = 0
 
+        # generated properties that have a persistent file stored on disk
         self._gen_cachedconfig('lastpulled', 0, configname=False)
         self._gen_cachedconfig('defaultauthors', True)
         self._gen_cachedconfig('caseignoreauthors', False)
         self._gen_cachedconfig('defaulthost', self.uuid)
         self._gen_cachedconfig('usebranchnames', True)
 
+        # misc
         self.branches = util.load(self.branch_info_file) or {}
         self.prevbranches = dict(self.branches)
-        self._tags = None
-        self._layout = layouts.detect.layout_from_file(self.metapath,
-                                                       ui=self.repo.ui)
-        self._layoutobj = None
-
-        self._authors = None
-
-        self._branchmap = None
-
-        self._tagmap = None
-
-        self._filemap = None
-
-        self.lastdate = '1970-01-01 00:00:00 -0000'
-        self.addedtags = {}
-        self.deletedtags = {}
+        self._layout = layouts.detect.layout_from_file(self)
 
     def _get_cachedconfig(self, name, filename, configname, default):
         """Return a cached value for a config option. If the cache is uninitialized
@@ -134,20 +136,24 @@ class SVNMeta(object):
                                                          filename))
         setattr(SVNMeta, name, prop)
 
+    @property
+    def layout_file(self):
+        return os.path.join(self.metapath, 'layout')
+
     @property
     def layout(self):
         # this method can't determine the layout, but it needs to be
         # resolved into something other than auto before this ever
         # gets called
         if not self._layout or self._layout == 'auto':
-            self._layout = layouts.detect.layout_from_config(self.repo.ui)
-            layouts.persist.layout_to_file(self.metapath, self._layout)
+            self._layout = layouts.detect.layout_from_config(self)
+            util.dump(self._layout, self.layout_file)
         return self._layout
 
     @property
     def layoutobj(self):
         if not self._layoutobj:
-            self._layoutobj = layouts.layout_from_name(self.layout, self.ui)
+            self._layoutobj = layouts.layout_from_name(self.layout, self)
         return self._layoutobj
 
     @property
--- a/hgsubversion/wrappers.py
+++ b/hgsubversion/wrappers.py
@@ -398,11 +398,11 @@ def pull(repo, source, heads=[], force=F
 
         stopat_rev = util.parse_revnum(svn, checkout)
 
-        layout = layouts.detect.layout_from_config(repo.ui, allow_auto=True)
+        layout = layouts.detect.layout_from_config(meta, allow_auto=True)
         if layout == 'auto':
             layout = layouts.detect.layout_from_subversion(svn,
                                                            (stopat_rev or None),
-                                                           repo.ui)
+                                                           meta)
             repo.ui.note('using %s layout\n' % layout)
 
         branch = repo.ui.config('hgsubversion', 'branch')