Mercurial > hgsubversion
diff hg_delta_editor.py @ 307:1d48d9a34c19
Put authormap into a separate file, and make it much better too.
See the doc-strings in maps.py for details.
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Sun, 03 May 2009 15:28:43 +0200 |
parents | e6853c7fa3af |
children | c3c647aff97c |
line wrap: on
line diff
--- a/hg_delta_editor.py +++ b/hg_delta_editor.py @@ -16,6 +16,7 @@ from svn import core import svnexternals import util +from maps import * def pickle_atomic(data, file_path, dir=None): """pickle some data to a path atomically. @@ -124,14 +125,9 @@ class HgChangeReceiver(delta.Editor): self.tag_locations.reverse() self.clear_current_info() - self.author_host = author_host - self.authors = {} - if os.path.exists(self.authors_file): - self.readauthors(self.authors_file) - if authors and os.path.exists(authors): - self.readauthors(authors) - if self.authors: - self.writeauthors() + self.authors = AuthorMap(self.ui, self.authors_file, + defaulthost=author_host) + if authors: self.authors.load(authors) self.lastdate = '1970-01-01 00:00:00 -0000' self.includepaths = {} @@ -632,7 +628,7 @@ class HgChangeReceiver(delta.Editor): rev.message or ' ', files, del_all_files, - self.authorforsvnauthor(rev.author), + self.authors[rev.author], date, {'branch': 'closed-branches'}) new_hash = self.repo.commitctx(current_ctx) @@ -685,7 +681,7 @@ class HgChangeReceiver(delta.Editor): rev.message or '...', files.keys(), filectxfn, - self.authorforsvnauthor(rev.author), + self.authors[rev.author], date, extra) new_hash = self.repo.commitctx(current_ctx) @@ -712,7 +708,7 @@ class HgChangeReceiver(delta.Editor): rev.message or ' ', [], del_all_files, - self.authorforsvnauthor(rev.author), + self.authors[rev.author], date, extra) new_hash = self.repo.commitctx(current_ctx) @@ -722,50 +718,6 @@ class HgChangeReceiver(delta.Editor): self._save_metadata() self.clear_current_info() - def authorforsvnauthor(self, author): - if author in self.authors: - return self.authors[author] - return '%s%s' % (author, self.author_host) - - def svnauthorforauthor(self, author): - for svnauthor, hgauthor in self.authors.iteritems(): - if author == hgauthor: - return svnauthor - else: - # return the original svn-side author - return author.rsplit('@', 1)[0] - - def readauthors(self, authorfile): - self.ui.note(('Reading authormap from %s\n') % authorfile) - f = open(authorfile, 'r') - for line in f: - if not line.strip(): - continue - try: - srcauth, dstauth = line.split('=', 1) - srcauth = srcauth.strip() - dstauth = dstauth.strip() - if srcauth in self.authors and dstauth != self.authors[srcauth]: - self.ui.status(('Overriding author mapping for "%s" ' + - 'from "%s" to "%s"\n') - % (srcauth, self.authors[srcauth], dstauth)) - else: - self.ui.debug(('Mapping author "%s" to "%s"\n') - % (srcauth, dstauth)) - self.authors[srcauth] = dstauth - except IndexError: - self.ui.warn( - ('Ignoring bad line in author map file %s: %s\n') - % (authorfile, line.rstrip())) - f.close() - - def writeauthors(self): - self.ui.debug(('Writing author map to %s\n') % self.authors_file) - f = open(self.authors_file, 'w+') - for author in self.authors: - f.write("%s=%s\n" % (author, self.authors[author])) - f.close() - def readfilemap(self, filemapfile): self.ui.note( ('Reading file map from %s\n')