changeset 758:76ebfc41f490

svnexternals: hide .hgsvnexternals parsing in parse()
author Patrick Mezard <pmezard@gmail.com>
date Fri, 19 Nov 2010 17:07:13 +0100
parents 6e18d9ab6557
children 864b5b67a5f0
files hgsubversion/pushmod.py hgsubversion/replay.py hgsubversion/stupid.py hgsubversion/svnexternals.py
diffstat 4 files changed, 14 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/pushmod.py
+++ b/hgsubversion/pushmod.py
@@ -84,13 +84,6 @@ def _getdirchanges(svn, branchpath, pare
     return added, deleted
 
 
-def _externals(ctx):
-    ext = svnexternals.externalsfile()
-    if '.hgsvnexternals' in ctx:
-        ext.read(ctx['.hgsvnexternals'].data())
-    return ext
-
-
 def commit(ui, repo, rev_ctx, meta, base_revision, svn):
     """Build and send a commit from Mercurial to Subversion.
     """
@@ -104,8 +97,8 @@ def commit(ui, repo, rev_ctx, meta, base
     elif parent_branch and parent_branch != 'default':
         branch_path = 'branches/%s' % parent_branch
 
-    extchanges = list(svnexternals.diff(_externals(parent),
-                                        _externals(rev_ctx)))
+    extchanges = list(svnexternals.diff(svnexternals.parse(parent),
+                                        svnexternals.parse(rev_ctx)))
     addeddirs, deleteddirs = _getdirchanges(svn, branch_path, parent, rev_ctx,
                                             rev_ctx.files(), extchanges)
     deleteddirs = set(deleteddirs)
--- a/hgsubversion/replay.py
+++ b/hgsubversion/replay.py
@@ -35,16 +35,10 @@ def updateexternals(ui, meta, current):
 
         p, b, bp = meta.split_branch_path(path)
         if bp not in branches:
-            external = svnexternals.externalsfile()
             parent = meta.get_parent_revision(revnum, b)
             pctx = meta.repo[parent]
-            if '.hgsvnexternals' in pctx:
-                external.read(pctx['.hgsvnexternals'].data())
-            branches[bp] = (external, pctx)
-        else:
-            external = branches[bp][0]
-
-        external[p] = entry
+            branches[bp] = (svnexternals.parse(pctx), pctx)
+        branches[bp][0][p] = entry
 
     # register externals file changes
     for bp, (external, pctx) in branches.iteritems():
--- a/hgsubversion/stupid.py
+++ b/hgsubversion/stupid.py
@@ -349,9 +349,7 @@ def fetch_externals(svn, branchpath, r, 
     Return an externalsfile instance or None if there are no externals
     to convert and never were.
     """
-    externals = svnexternals.externalsfile()
-    if '.hgsvnexternals' in parentctx:
-        externals.read(parentctx['.hgsvnexternals'].data())
+    externals = svnexternals.parse(parentctx)
     # Detect property additions only, changes are handled by checking
     # existing entries individually. Projects are unlikely to store
     # externals on many different root directories, so we trade code
--- a/hgsubversion/svnexternals.py
+++ b/hgsubversion/svnexternals.py
@@ -310,3 +310,12 @@ def getchanges(ui, repo, parentctx, exts
             if fn in parentctx:
                 updates[fn] = None
     return updates
+
+def parse(ctx):
+    """Return the externals definitions stored in ctx as a (possibly empty)
+    externalsfile().
+    """
+    external = externalsfile()
+    if '.hgsvnexternals' in ctx:
+        external.read(ctx['.hgsvnexternals'].data())
+    return external