changeset 417:8630d1ebcdb9

svnmeta: deprivatize a bunch of member functions
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Thu, 11 Jun 2009 18:49:06 +0200
parents cd6317fe70be
children 92beeefeaf93
files hgsubversion/hg_delta_editor.py hgsubversion/stupid.py hgsubversion/svnmeta.py
diffstat 3 files changed, 53 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/hg_delta_editor.py
+++ b/hgsubversion/hg_delta_editor.py
@@ -102,10 +102,10 @@ class HgChangeReceiver(delta.Editor):
         revnum = self.current.rev.revnum
         branches = {}
         for path, entry in self.current.externals.iteritems():
-            if not self.meta._is_path_valid(path):
+            if not self.meta.is_path_valid(path):
                 self.ui.warn('WARNING: Invalid path %s in externals\n' % path)
                 continue
-            p, b, bp = self.meta._split_branch_path(path)
+            p, b, bp = self.meta.split_branch_path(path)
             if bp not in branches:
                 external = svnexternals.externalsfile()
                 parent = self.meta.get_parent_revision(revnum, b)
@@ -146,9 +146,9 @@ class HgChangeReceiver(delta.Editor):
 
         # build up the branches that have files on them
         for f in files_to_commit:
-            if not self.meta._is_path_valid(f):
+            if not self.meta.is_path_valid(f):
                 continue
-            p, b = self.meta._path_and_branch_for_path(f)
+            p, b = self.meta.path_and_branch_for_path(f)
             if b not in branch_batches:
                 branch_batches[b] = []
             branch_batches[b].append((p, f))
@@ -259,14 +259,14 @@ class HgChangeReceiver(delta.Editor):
                 continue
             self.meta.delbranch(branch, parent, rev)
 
-        self.meta._save_metadata()
+        self.meta.save()
         self.current.clear()
 
     # Here come all the actual editor methods
 
     @ieditor
     def delete_entry(self, path, revision_bogus, parent_baton, pool=None):
-        br_path, branch = self.meta._path_and_branch_for_path(path)
+        br_path, branch = self.meta.path_and_branch_for_path(path)
         if br_path == '':
             self.meta.closebranches.add(branch)
         if br_path is not None:
@@ -291,7 +291,7 @@ class HgChangeReceiver(delta.Editor):
     @ieditor
     def open_file(self, path, parent_baton, base_revision, p=None):
         self.current.file = None
-        fpath, branch = self.meta._path_and_branch_for_path(path)
+        fpath, branch = self.meta.path_and_branch_for_path(path)
         if not fpath:
             self.ui.debug('WARNING: Opening non-existant file %s\n' % path)
             return
@@ -312,7 +312,7 @@ class HgChangeReceiver(delta.Editor):
         parent = self.meta.get_parent_revision(baserev + 1, branch)
 
         ctx = self.repo[parent]
-        if not self.meta._is_path_valid(path):
+        if not self.meta.is_path_valid(path):
             return
 
         if fpath not in ctx:
@@ -331,7 +331,7 @@ class HgChangeReceiver(delta.Editor):
         self.current.base = None
         if path in self.current.deleted:
             del self.current.deleted[path]
-        fpath, branch = self.meta._path_and_branch_for_path(path, existing=False)
+        fpath, branch = self.meta.path_and_branch_for_path(path, existing=False)
         if not fpath:
             return
         if branch not in self.meta.branches:
@@ -344,7 +344,7 @@ class HgChangeReceiver(delta.Editor):
             return
         self.ui.note('A+ %s\n' % path)
         (from_file,
-         from_branch) = self.meta._path_and_branch_for_path(copyfrom_path)
+         from_branch) = self.meta.path_and_branch_for_path(copyfrom_path)
         if not from_file:
             self.current.missing.add(path)
             return
@@ -367,7 +367,7 @@ class HgChangeReceiver(delta.Editor):
     def add_directory(self, path, parent_baton, copyfrom_path,
                       copyfrom_revision, dir_pool=None):
         self.current.batons[path] = path
-        br_path, branch = self.meta._path_and_branch_for_path(path)
+        br_path, branch = self.meta.path_and_branch_for_path(path)
         if br_path is not None:
             if not copyfrom_path and not br_path:
                 self.current.emptybranches[branch] = True
@@ -376,10 +376,10 @@ class HgChangeReceiver(delta.Editor):
         if br_path is None or not copyfrom_path:
             return path
         if copyfrom_path:
-            tag = self.meta._is_path_tag(copyfrom_path)
+            tag = self.meta.is_path_tag(copyfrom_path)
             if tag not in self.meta.tags:
                 tag = None
-            if not self.meta._is_path_valid(copyfrom_path) and not tag:
+            if not self.meta.is_path_valid(copyfrom_path) and not tag:
                 self.current.missing.add('%s/' % path)
                 return path
         if tag:
@@ -387,7 +387,7 @@ class HgChangeReceiver(delta.Editor):
             cp_f = ''
         else:
             source_rev = copyfrom_revision
-            cp_f, source_branch = self.meta._path_and_branch_for_path(copyfrom_path)
+            cp_f, source_branch = self.meta.path_and_branch_for_path(copyfrom_path)
             if cp_f == '' and br_path == '':
                 assert br_path is not None
                 tmp = source_branch, source_rev, self.current.rev.revnum
@@ -441,7 +441,7 @@ class HgChangeReceiver(delta.Editor):
     @ieditor
     def open_directory(self, path, parent_baton, base_revision, dir_pool=None):
         self.current.batons[path] = path
-        p_, branch = self.meta._path_and_branch_for_path(path)
+        p_, branch = self.meta.path_and_branch_for_path(path)
         if p_ == '':
             self.current.emptybranches[branch] = False
         return path
@@ -458,7 +458,7 @@ class HgChangeReceiver(delta.Editor):
         # 2) Missing a base text (bail quick since we have to fetch a full plaintext)
         # 3) Has a base text in self.current.files, apply deltas
         base = ''
-        if not self.meta._is_path_valid(self.current.file):
+        if not self.meta.is_path_valid(self.current.file):
             return lambda x: None
         assert self.current.file not in self.current.deleted, (
             'Cannot apply_textdelta to a deleted file: %s' % self.current.file)
@@ -477,7 +477,7 @@ class HgChangeReceiver(delta.Editor):
                                'cannot call handler!')
         def txdelt_window(window):
             try:
-                if not self.meta._is_path_valid(self.current.file):
+                if not self.meta.is_path_valid(self.current.file):
                     return
                 handler(window, baton)
                 # window being None means commit this file
--- a/hgsubversion/stupid.py
+++ b/hgsubversion/stupid.py
@@ -396,7 +396,7 @@ def fetch_branchrev(svn, meta, branch, b
         for path, e in r.paths.iteritems():
             if not path.startswith(branchprefix):
                 continue
-            if not meta._is_path_valid(path):
+            if not meta.is_path_valid(path):
                 continue
             kind = svn.checkpath(path, r.revnum)
             path = path[len(branchprefix):]
@@ -448,11 +448,11 @@ def branches_in_paths(meta, tbdelta, pat
     branches = {}
     paths_need_discovery = []
     for p in paths:
-        relpath, branch, branchpath = meta._split_branch_path(p)
+        relpath, branch, branchpath = meta.split_branch_path(p)
         if relpath is not None:
             branches[branch] = branchpath
-        elif paths[p].action == 'D' and not meta._is_path_tag(p):
-            ln = meta._localname(p)
+        elif paths[p].action == 'D' and not meta.is_path_tag(p):
+            ln = meta.localname(p)
             # must check in branches_to_delete as well, because this runs after we
             # already updated the branch map
             if ln in meta.branches or ln in tbdelta['branches'][1]:
@@ -497,12 +497,12 @@ def branches_in_paths(meta, tbdelta, pat
             path = filepaths.pop(0)
             parentdir = '/'.join(path[:-1])
             filepaths = [p for p in filepaths if not '/'.join(p).startswith(parentdir)]
-            branchpath = meta._normalize_path(parentdir)
+            branchpath = meta.normalize(parentdir)
             if branchpath.startswith('tags/'):
                 continue
-            branchname = meta._localname(branchpath)
+            branchname = meta.localname(branchpath)
             if branchpath.startswith('trunk/'):
-                branches[meta._localname('trunk')] = 'trunk'
+                branches[meta.localname('trunk')] = 'trunk'
                 continue
             if branchname and branchname.startswith('../'):
                 continue
@@ -530,15 +530,15 @@ def convert_rev(ui, meta, svn, r, tbdelt
         # We've go a branch that contains other branches. We have to be careful to
         # get results similar to real replay in this case.
         for existingbr in meta.branches:
-            bad = meta._remotename(existingbr)
+            bad = meta.remotename(existingbr)
             if bad.startswith(bp) and len(bad) > len(bp):
                 bad_branch_paths[br].append(bad[len(bp)+1:])
 
     deleted_branches = {}
     for p in r.paths:
-        if meta._is_path_tag(p):
+        if meta.is_path_tag(p):
             continue
-        branch = meta._localname(p)
+        branch = meta.localname(p)
         if not (r.paths[p].action == 'R' and branch in meta.branches):
             continue
         closed = checkbranch(meta, r, branch)
@@ -635,4 +635,4 @@ def convert_rev(ui, meta, svn, r, tbdelt
         meta.delbranch(b, parent, r)
 
     # save the changed metadata
-    meta._save_metadata()
+    meta.save()
--- a/hgsubversion/svnmeta.py
+++ b/hgsubversion/svnmeta.py
@@ -136,13 +136,13 @@ class SVNMeta(object):
             date = self.lastdate
         return date
 
-    def _save_metadata(self):
+    def save(self):
         '''Save the Subversion metadata. This should really be called after
         every revision is created.
         '''
         pickle_atomic(self.branches, self.branch_info_file, self.meta_data_dir)
 
-    def _localname(self, path):
+    def localname(self, path):
         """Compute the local name for a branch located at path.
         """
         assert not path.startswith('tags/')
@@ -152,14 +152,14 @@ class SVNMeta(object):
             return path[len('branches/'):]
         return  '../%s' % path
 
-    def _remotename(self, branch):
+    def remotename(self, branch):
         if branch == 'default' or branch is None:
             return 'trunk'
         elif branch.startswith('../'):
             return branch[3:]
         return 'branches/%s' % branch
 
-    def _normalize_path(self, path):
+    def normalize(self, path):
         '''Normalize a path to strip of leading slashes and our subdir if we
         have one.
         '''
@@ -171,14 +171,14 @@ class SVNMeta(object):
             path = path[1:]
         return path
 
-    def _is_path_tag(self, path):
+    def is_path_tag(self, path):
         """If path could represent the path to a tag, returns the potential tag
         name. Otherwise, returns False.
 
         Note that it's only a tag if it was copied from the path '' in a branch
         (or tag) we have, for our purposes.
         """
-        path = self._normalize_path(path)
+        path = self.normalize(path)
         for tagspath in self.tag_locations:
             onpath = path.startswith(tagspath)
             longer = len(path) > len('%s/' % tagspath)
@@ -187,7 +187,7 @@ class SVNMeta(object):
                 return tag
         return False
 
-    def _split_branch_path(self, path, existing=True):
+    def split_branch_path(self, path, existing=True):
         """Figure out which branch inside our repo this path represents, and
         also figure out which path inside that branch it is.
 
@@ -197,18 +197,18 @@ class SVNMeta(object):
         branch. If existing=False, then it will guess what the branch would be if it were
         known.
         """
-        path = self._normalize_path(path)
+        path = self.normalize(path)
         if path.startswith('tags/'):
             return None, None, None
         test = ''
         path_comps = path.split('/')
-        while self._localname(test) not in self.branches and len(path_comps):
+        while self.localname(test) not in self.branches and len(path_comps):
             if not test:
                 test = path_comps.pop(0)
             else:
                 test += '/%s' % path_comps.pop(0)
-        if self._localname(test) in self.branches:
-            return path[len(test)+1:], self._localname(test), test
+        if self.localname(test) in self.branches:
+            return path[len(test)+1:], self.localname(test), test
         if existing:
             return None, None, None
         if path == 'trunk' or path.startswith('trunk/'):
@@ -221,29 +221,29 @@ class SVNMeta(object):
         else:
             path = test.split('/')[-1]
             test = '/'.join(test.split('/')[:-1])
-        ln =  self._localname(test)
+        ln =  self.localname(test)
         if ln and ln.startswith('../'):
             return None, None, None
         return path, ln, test
 
-    def _path_and_branch_for_path(self, path, existing=True):
-        return self._split_branch_path(path, existing=existing)[:2]
+    def path_and_branch_for_path(self, path, existing=True):
+        return self.split_branch_path(path, existing=existing)[:2]
 
     def _determine_parent_branch(self, p, src_path, src_rev, revnum):
         if src_path is not None:
-            src_file, src_branch = self._path_and_branch_for_path(src_path)
-            src_tag = self._is_path_tag(src_path)
+            src_file, src_branch = self.path_and_branch_for_path(src_path)
+            src_tag = self.is_path_tag(src_path)
             if src_tag != False or src_file == '': # case 2
-                ln = self._localname(p)
+                ln = self.localname(p)
                 if src_tag != False:
                     src_branch, src_rev = self.tags[src_tag]
                 return {ln: (src_branch, src_rev, revnum)}
         return {}
 
-    def _is_path_valid(self, path):
+    def is_path_valid(self, path):
         if path is None:
             return False
-        subpath = self._split_branch_path(path)[0]
+        subpath = self.split_branch_path(path)[0]
         if subpath is None:
             return False
         return subpath in self.filemap
@@ -294,17 +294,17 @@ class SVNMeta(object):
         self.closebranches = set()
         tags_to_delete = set()
         for p in sorted(paths):
-            t_name = self._is_path_tag(p)
+            t_name = self.is_path_tag(p)
             if t_name != False:
                 src_p, src_rev = paths[p].copyfrom_path, paths[p].copyfrom_rev
                 # if you commit to a tag, I'm calling you stupid and ignoring
                 # you.
                 if src_p is not None and src_rev is not None:
-                    file, branch = self._path_and_branch_for_path(src_p)
+                    file, branch = self.path_and_branch_for_path(src_p)
                     if file is None:
                         # some crazy people make tags from other tags
                         file = ''
-                        from_tag = self._is_path_tag(src_p)
+                        from_tag = self.is_path_tag(src_p)
                         if not from_tag:
                             continue
                         branch, src_rev = self.tags[from_tag]
@@ -340,7 +340,7 @@ class SVNMeta(object):
             #    already-known branches, so we mark them as deleted.
             # 6. It's a branch being replaced by another branch - the
             #    action will be 'R'.
-            fi, br = self._path_and_branch_for_path(p)
+            fi, br = self.path_and_branch_for_path(p)
             if fi is not None:
                 if fi == '':
                     if paths[p].action == 'D':
@@ -353,12 +353,12 @@ class SVNMeta(object):
                 continue # case 1
             if paths[p].action == 'D':
                 for known in self.branches:
-                    if self._remotename(known).startswith(p):
+                    if self.remotename(known).startswith(p):
                         self.current.closebranches.add(known) # case 5
             parent = self._determine_parent_branch(
                 p, paths[p].copyfrom_path, paths[p].copyfrom_rev, revision.revnum)
             if not parent and paths[p].copyfrom_path:
-                bpath, branch = self._path_and_branch_for_path(p, False)
+                bpath, branch = self.path_and_branch_for_path(p, False)
                 if (bpath is not None
                     and branch not in self.branches
                     and branch not in added_branches):