changeset 4590:80fb4ec512b5

convert: fix various authormap handling bugs
author Brendan Cully <brendan@kublai.com>
date Thu, 14 Jun 2007 16:12:08 -0700
parents 451e91ed535e
children 9ec0a3b6a18a
files hgext/convert/__init__.py hgext/convert/common.py
diffstat 2 files changed, 28 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/__init__.py	Thu Jun 14 23:25:55 2007 +0200
+++ b/hgext/convert/__init__.py	Thu Jun 14 16:12:08 2007 -0700
@@ -38,7 +38,7 @@
         self.mapfile = mapfile
         self.mapfilefd = None
         self.authors = {}
-        self.writeauthors = False
+        self.authorfile = None
 
         self.map = {}
         try:
@@ -51,12 +51,15 @@
             pass
 
         # Read first the dst author map if any
-        if  hasattr(self.dest, 'authorfile'):
-            self.readauthormap(self.dest.authorfile())
+        authorfile = self.dest.authorfile()
+        if authorfile and os.path.exists(authorfile):
+            self.readauthormap(authorfile)
         # Extend/Override with new author map if necessary
-        if 'authors' in opts:
+        if opts.get('authors'):
+            import pdb
+            pdb.set_trace()
             self.readauthormap(opts.get('authors'))
-            self.writeauthors = True
+            self.authorfile = self.dest.authorfile()
 
     def walktree(self, heads):
         visit = heads
@@ -142,8 +145,8 @@
         self.mapfilefd.flush()
 
     def writeauthormap(self):
-        if self.writeauthors == True and len(self.authors) > 0 and hasattr(self.dest, 'authorfile'):
-           authorfile = self.dest.authorfile()
+        authorfile = self.authorfile
+        if authorfile:
            self.ui.status('Writing author map file %s\n' % authorfile)
            ofile = open(authorfile, 'w+')
            for author in self.authors:
@@ -151,28 +154,24 @@
            ofile.close()
 
     def readauthormap(self, authorfile):
-        try:
-            afile = open(authorfile, 'r')
-            for line in afile:
-                try:
-                    srcauthor = line.split('=')[0].strip()
-                    dstauthor = line.split('=')[1].strip()
-                    if srcauthor in self.authors and dstauthor != self.authors[srcauthor]:
-                        self.ui.status(
-                            'Overriding mapping for author %s, was %s, will be %s\n'
-                            % (srcauthor, self.authors[srcauthor], dstauthor))
-                    else:
-                        self.ui.debug('Mapping author %s to %s\n'
-			    % (srcauthor, dstauthor))
+        afile = open(authorfile, 'r')
+        for line in afile:
+            try:
+                srcauthor = line.split('=')[0].strip()
+                dstauthor = line.split('=')[1].strip()
+                if srcauthor in self.authors and dstauthor != self.authors[srcauthor]:
+                    self.ui.status(
+                        'Overriding mapping for author %s, was %s, will be %s\n'
+                        % (srcauthor, self.authors[srcauthor], dstauthor))
+                else:
+                    self.ui.debug('Mapping author %s to %s\n'
+                                  % (srcauthor, dstauthor))
                     self.authors[srcauthor] = dstauthor
-		    
-                except IndexError:
-                    self.ui.warn(
-                        'Ignoring bad line in author file map %s: %s\n'
-                        % (authorfile, line))
-            afile.close()
-        except IOError:
-            self.ui.warn('Error reading author file map %s.\n' % authorfile)
+            except IndexError:
+                self.ui.warn(
+                    'Ignoring bad line in author file map %s: %s\n'
+                    % (authorfile, line))
+        afile.close()
 
     def copy(self, rev):
         c = self.commitcache[rev]
--- a/hgext/convert/common.py	Thu Jun 14 23:25:55 2007 +0200
+++ b/hgext/convert/common.py	Thu Jun 14 16:12:08 2007 -0700
@@ -66,7 +66,7 @@
         """Path to a file that will contain lines
         srcauthor=dstauthor
         mapping equivalent authors identifiers for each system."""
-        raise NotImplementedError()
+        return None
 
     def putfile(self, f, e, data):
         """Put file for next putcommit().