comparison hgext/convert/__init__.py @ 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
comparison
equal deleted inserted replaced
4589:451e91ed535e 4590:80fb4ec512b5
36 self.opts = opts 36 self.opts = opts
37 self.commitcache = {} 37 self.commitcache = {}
38 self.mapfile = mapfile 38 self.mapfile = mapfile
39 self.mapfilefd = None 39 self.mapfilefd = None
40 self.authors = {} 40 self.authors = {}
41 self.writeauthors = False 41 self.authorfile = None
42 42
43 self.map = {} 43 self.map = {}
44 try: 44 try:
45 origmapfile = open(self.mapfile, 'r') 45 origmapfile = open(self.mapfile, 'r')
46 for l in origmapfile: 46 for l in origmapfile:
49 origmapfile.close() 49 origmapfile.close()
50 except IOError: 50 except IOError:
51 pass 51 pass
52 52
53 # Read first the dst author map if any 53 # Read first the dst author map if any
54 if hasattr(self.dest, 'authorfile'): 54 authorfile = self.dest.authorfile()
55 self.readauthormap(self.dest.authorfile()) 55 if authorfile and os.path.exists(authorfile):
56 self.readauthormap(authorfile)
56 # Extend/Override with new author map if necessary 57 # Extend/Override with new author map if necessary
57 if 'authors' in opts: 58 if opts.get('authors'):
59 import pdb
60 pdb.set_trace()
58 self.readauthormap(opts.get('authors')) 61 self.readauthormap(opts.get('authors'))
59 self.writeauthors = True 62 self.authorfile = self.dest.authorfile()
60 63
61 def walktree(self, heads): 64 def walktree(self, heads):
62 visit = heads 65 visit = heads
63 known = {} 66 known = {}
64 parents = {} 67 parents = {}
140 self.map[src] = dst 143 self.map[src] = dst
141 self.mapfilefd.write("%s %s\n" % (src, dst)) 144 self.mapfilefd.write("%s %s\n" % (src, dst))
142 self.mapfilefd.flush() 145 self.mapfilefd.flush()
143 146
144 def writeauthormap(self): 147 def writeauthormap(self):
145 if self.writeauthors == True and len(self.authors) > 0 and hasattr(self.dest, 'authorfile'): 148 authorfile = self.authorfile
146 authorfile = self.dest.authorfile() 149 if authorfile:
147 self.ui.status('Writing author map file %s\n' % authorfile) 150 self.ui.status('Writing author map file %s\n' % authorfile)
148 ofile = open(authorfile, 'w+') 151 ofile = open(authorfile, 'w+')
149 for author in self.authors: 152 for author in self.authors:
150 ofile.write("%s=%s\n" % (author, self.authors[author])) 153 ofile.write("%s=%s\n" % (author, self.authors[author]))
151 ofile.close() 154 ofile.close()
152 155
153 def readauthormap(self, authorfile): 156 def readauthormap(self, authorfile):
154 try: 157 afile = open(authorfile, 'r')
155 afile = open(authorfile, 'r') 158 for line in afile:
156 for line in afile: 159 try:
157 try: 160 srcauthor = line.split('=')[0].strip()
158 srcauthor = line.split('=')[0].strip() 161 dstauthor = line.split('=')[1].strip()
159 dstauthor = line.split('=')[1].strip() 162 if srcauthor in self.authors and dstauthor != self.authors[srcauthor]:
160 if srcauthor in self.authors and dstauthor != self.authors[srcauthor]: 163 self.ui.status(
161 self.ui.status( 164 'Overriding mapping for author %s, was %s, will be %s\n'
162 'Overriding mapping for author %s, was %s, will be %s\n' 165 % (srcauthor, self.authors[srcauthor], dstauthor))
163 % (srcauthor, self.authors[srcauthor], dstauthor)) 166 else:
164 else: 167 self.ui.debug('Mapping author %s to %s\n'
165 self.ui.debug('Mapping author %s to %s\n' 168 % (srcauthor, dstauthor))
166 % (srcauthor, dstauthor))
167 self.authors[srcauthor] = dstauthor 169 self.authors[srcauthor] = dstauthor
168 170 except IndexError:
169 except IndexError: 171 self.ui.warn(
170 self.ui.warn( 172 'Ignoring bad line in author file map %s: %s\n'
171 'Ignoring bad line in author file map %s: %s\n' 173 % (authorfile, line))
172 % (authorfile, line)) 174 afile.close()
173 afile.close()
174 except IOError:
175 self.ui.warn('Error reading author file map %s.\n' % authorfile)
176 175
177 def copy(self, rev): 176 def copy(self, rev):
178 c = self.commitcache[rev] 177 c = self.commitcache[rev]
179 files = self.source.getchanges(rev) 178 files = self.source.getchanges(rev)
180 179