changeset 4809:c2d529f288a1

convert: move some code into common init function
author Brendan Cully <brendan@kublai.com>
date Thu, 05 Jul 2007 12:08:48 -0700
parents 4582c28e2874
children f7c8222920ee
files hgext/convert/common.py hgext/convert/cvs.py hgext/convert/git.py hgext/convert/subversion.py
diffstat 4 files changed, 13 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/common.py
+++ b/hgext/convert/common.py
@@ -17,7 +17,11 @@ class converter_source(object):
     def __init__(self, ui, path, rev=None):
         """Initialize conversion source (or raise NoRepo("message")
         exception if path is not a valid repository)"""
-        pass
+        self.ui = ui
+        self.path = path
+        self.rev = rev
+
+        self.encoding = 'utf-8'
 
     def getheads(self):
         """Return a list of this repository's heads"""
@@ -48,7 +52,7 @@ class converter_source(object):
 
     def recode(self, s, encoding=None):
         if not encoding:
-            encoding = hasattr(self, 'encoding') and self.encoding or 'utf-8'
+            encoding = self.encoding or 'utf-8'
             
         try:
             return s.decode(encoding).encode("utf-8")
--- a/hgext/convert/cvs.py
+++ b/hgext/convert/cvs.py
@@ -9,9 +9,6 @@ class convert_cvs(converter_source):
     def __init__(self, ui, path, rev=None):
         super(convert_cvs, self).__init__(ui, path, rev=rev)
 
-        self.path = path
-        self.ui = ui
-        self.rev = rev
         cvs = os.path.join(path, "CVS")
         if not os.path.exists(cvs):
             raise NoRepo("couldn't open CVS repo %s" % path)
--- a/hgext/convert/git.py
+++ b/hgext/convert/git.py
@@ -15,11 +15,7 @@ class convert_git(converter_source):
             path += "/.git"
         if not os.path.exists(path + "/objects"):
             raise NoRepo("couldn't open GIT repo %s" % path)
-
         self.path = path
-        self.ui = ui
-        self.rev = rev
-        self.encoding = 'utf-8'
 
     def getheads(self):
         if not self.rev:
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -86,7 +86,6 @@ class convert_svn(converter_source):
             ui.warn(msg)
             raise NoRepo(msg)
 
-        self.ui = ui
         self.encoding = locale.getpreferredencoding()
         latest = None
         if rev:
@@ -123,9 +122,9 @@ class convert_svn(converter_source):
 
         self.last_changed = self.latest(self.module, latest)
 
-        self.head = self.rev(self.last_changed)
+        self.head = self.revid(self.last_changed)
 
-    def rev(self, revnum, module=None):
+    def revid(self, revnum, module=None):
         if not module:
             module = self.module
         return (u"svn:%s%s@%s" % (self.uuid, module, revnum)).decode(self.encoding)
@@ -227,7 +226,7 @@ class convert_svn(converter_source):
             copyfrom = {} # Map of entrypath, revision for finding source of deleted revisions.
             copies = {}
             entries = []
-            rev = self.rev(revnum)
+            rev = self.revid(revnum)
             parents = []
             try:
                 branch = self.module.split("/")[-1]
@@ -245,7 +244,7 @@ class convert_svn(converter_source):
                             # ent.copyfrom_rev may not be the actual last revision
                             prev = self.latest(ent.copyfrom_path, ent.copyfrom_rev)
                             self.modulemap[prev] = ent.copyfrom_path
-                            parents = [self.rev(prev, ent.copyfrom_path)]
+                            parents = [self.revid(prev, ent.copyfrom_path)]
                             self.ui.note('found parent of branch %s at %d: %s\n' % \
                                          (self.module, prev, ent.copyfrom_path))
                         else:
@@ -465,13 +464,13 @@ class convert_svn(converter_source):
         if 'branches' in paths and 'trunk' in paths:
             self.module += '/trunk'
             lt = self.latest(self.module, self.last_changed)
-            self.head = self.rev(lt)
+            self.head = self.revid(lt)
             self.heads = [self.head]
             branches = svn.client.ls(rpath + '/branches', optrev, False, self.ctx)
             for branch in branches.keys():
                 module = '/branches/' + branch
                 brevnum = self.latest(module, self.last_changed)
-                brev = self.rev(brevnum, module)
+                brev = self.revid(brevnum, module)
                 self.ui.note('found branch %s at %d\n' % (branch, brevnum))
                 self.heads.append(brev)
         else:
@@ -540,7 +539,7 @@ class convert_svn(converter_source):
                 source = ent.copyfrom_path
                 rev = ent.copyfrom_rev
                 tag = path.split('/', 2)[2]
-                tags[tag] = self.rev(rev, module=source)
+                tags[tag] = self.revid(rev, module=source)
 
         start = self.revnum(self.head)
         try: