comparison 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
comparison
equal deleted inserted replaced
306:e6853c7fa3af 307:1d48d9a34c19
14 from svn import delta 14 from svn import delta
15 from svn import core 15 from svn import core
16 16
17 import svnexternals 17 import svnexternals
18 import util 18 import util
19 from maps import *
19 20
20 def pickle_atomic(data, file_path, dir=None): 21 def pickle_atomic(data, file_path, dir=None):
21 """pickle some data to a path atomically. 22 """pickle some data to a path atomically.
22 23
23 This is present because I kept corrupting my revmap by managing to hit ^C 24 This is present because I kept corrupting my revmap by managing to hit ^C
122 # ensure nested paths are handled properly 123 # ensure nested paths are handled properly
123 self.tag_locations.sort() 124 self.tag_locations.sort()
124 self.tag_locations.reverse() 125 self.tag_locations.reverse()
125 126
126 self.clear_current_info() 127 self.clear_current_info()
127 self.author_host = author_host 128 self.authors = AuthorMap(self.ui, self.authors_file,
128 self.authors = {} 129 defaulthost=author_host)
129 if os.path.exists(self.authors_file): 130 if authors: self.authors.load(authors)
130 self.readauthors(self.authors_file)
131 if authors and os.path.exists(authors):
132 self.readauthors(authors)
133 if self.authors:
134 self.writeauthors()
135 131
136 self.lastdate = '1970-01-01 00:00:00 -0000' 132 self.lastdate = '1970-01-01 00:00:00 -0000'
137 self.includepaths = {} 133 self.includepaths = {}
138 self.excludepaths = {} 134 self.excludepaths = {}
139 if filemap and os.path.exists(filemap): 135 if filemap and os.path.exists(filemap):
630 current_ctx = context.memctx(self.repo, 626 current_ctx = context.memctx(self.repo,
631 parents, 627 parents,
632 rev.message or ' ', 628 rev.message or ' ',
633 files, 629 files,
634 del_all_files, 630 del_all_files,
635 self.authorforsvnauthor(rev.author), 631 self.authors[rev.author],
636 date, 632 date,
637 {'branch': 'closed-branches'}) 633 {'branch': 'closed-branches'})
638 new_hash = self.repo.commitctx(current_ctx) 634 new_hash = self.repo.commitctx(current_ctx)
639 self.ui.status('Marked branch %s as closed.\n' % (branch or 635 self.ui.status('Marked branch %s as closed.\n' % (branch or
640 'default')) 636 'default'))
683 current_ctx = context.memctx(self.repo, 679 current_ctx = context.memctx(self.repo,
684 parents, 680 parents,
685 rev.message or '...', 681 rev.message or '...',
686 files.keys(), 682 files.keys(),
687 filectxfn, 683 filectxfn,
688 self.authorforsvnauthor(rev.author), 684 self.authors[rev.author],
689 date, 685 date,
690 extra) 686 extra)
691 new_hash = self.repo.commitctx(current_ctx) 687 new_hash = self.repo.commitctx(current_ctx)
692 util.describe_commit(self.ui, new_hash, branch) 688 util.describe_commit(self.ui, new_hash, branch)
693 if (rev.revnum, branch) not in self.revmap: 689 if (rev.revnum, branch) not in self.revmap:
710 current_ctx = context.memctx(self.repo, 706 current_ctx = context.memctx(self.repo,
711 (ha, node.nullid), 707 (ha, node.nullid),
712 rev.message or ' ', 708 rev.message or ' ',
713 [], 709 [],
714 del_all_files, 710 del_all_files,
715 self.authorforsvnauthor(rev.author), 711 self.authors[rev.author],
716 date, 712 date,
717 extra) 713 extra)
718 new_hash = self.repo.commitctx(current_ctx) 714 new_hash = self.repo.commitctx(current_ctx)
719 util.describe_commit(self.ui, new_hash, branch) 715 util.describe_commit(self.ui, new_hash, branch)
720 if (rev.revnum, branch) not in self.revmap: 716 if (rev.revnum, branch) not in self.revmap:
721 self.add_to_revmap(rev.revnum, branch, new_hash) 717 self.add_to_revmap(rev.revnum, branch, new_hash)
722 self._save_metadata() 718 self._save_metadata()
723 self.clear_current_info() 719 self.clear_current_info()
724
725 def authorforsvnauthor(self, author):
726 if author in self.authors:
727 return self.authors[author]
728 return '%s%s' % (author, self.author_host)
729
730 def svnauthorforauthor(self, author):
731 for svnauthor, hgauthor in self.authors.iteritems():
732 if author == hgauthor:
733 return svnauthor
734 else:
735 # return the original svn-side author
736 return author.rsplit('@', 1)[0]
737
738 def readauthors(self, authorfile):
739 self.ui.note(('Reading authormap from %s\n') % authorfile)
740 f = open(authorfile, 'r')
741 for line in f:
742 if not line.strip():
743 continue
744 try:
745 srcauth, dstauth = line.split('=', 1)
746 srcauth = srcauth.strip()
747 dstauth = dstauth.strip()
748 if srcauth in self.authors and dstauth != self.authors[srcauth]:
749 self.ui.status(('Overriding author mapping for "%s" ' +
750 'from "%s" to "%s"\n')
751 % (srcauth, self.authors[srcauth], dstauth))
752 else:
753 self.ui.debug(('Mapping author "%s" to "%s"\n')
754 % (srcauth, dstauth))
755 self.authors[srcauth] = dstauth
756 except IndexError:
757 self.ui.warn(
758 ('Ignoring bad line in author map file %s: %s\n')
759 % (authorfile, line.rstrip()))
760 f.close()
761
762 def writeauthors(self):
763 self.ui.debug(('Writing author map to %s\n') % self.authors_file)
764 f = open(self.authors_file, 'w+')
765 for author in self.authors:
766 f.write("%s=%s\n" % (author, self.authors[author]))
767 f.close()
768 720
769 def readfilemap(self, filemapfile): 721 def readfilemap(self, filemapfile):
770 self.ui.note( 722 self.ui.note(
771 ('Reading file map from %s\n') 723 ('Reading file map from %s\n')
772 % filemapfile) 724 % filemapfile)