# HG changeset patch # User Augie Fackler # Date 1230689643 21600 # Node ID 4f26fa0494528da7204e43fa33a67197effeafef # Parent 3cd6a735420781353fca937429e1a2037483df9c authormap: Add tests, fix in stupid mode. diff --git a/fetch_command.py b/fetch_command.py --- a/fetch_command.py +++ b/fetch_command.py @@ -514,8 +514,7 @@ def stupid_svn_server_pull_rev(ui, svn, r.message or '...', files_touched, filectxfn, - '%s%s' % (r.author, - hg_editor.author_host), + hg_editor.authorforsvnauthor(r.author), date, extra) ha = hg_editor.repo.commitctx(current_ctx) @@ -553,8 +552,7 @@ def stupid_svn_server_pull_rev(ui, svn, r.message or '...', files_touched, filectxfn, - '%s%s' % (r.author, - hg_editor.author_host), + hg_editor.authorforsvnauthor(r.author), date, {'branch': 'closed-branches'}) ha = hg_editor.repo.commitctx(current_ctx) diff --git a/hg_delta_editor.py b/hg_delta_editor.py --- a/hg_delta_editor.py +++ b/hg_delta_editor.py @@ -482,9 +482,9 @@ class HgChangeReceiver(delta.Editor): self.clear_current_info() def authorforsvnauthor(self, author): - if(author in self.authors): - return self.authors[author] - return '%s%s' %(author, self.author_host) + if(author in self.authors): + return self.authors[author] + return '%s%s' %(author, self.author_host) def readauthors(self, authorfile): self.ui.status( @@ -492,7 +492,7 @@ class HgChangeReceiver(delta.Editor): % authorfile) f = open(authorfile, 'r') for line in f: - if line.strip() == '': + if not line.strip(): continue try: srcauth, dstauth = line.split('=', 1) @@ -511,7 +511,7 @@ class HgChangeReceiver(delta.Editor): ('Ignoring bad line in author map file %s: %s\n') % (authorfile, line.rstrip())) f.close() - + def writeauthors(self): f = open(self.authors_file, 'w+') self.ui.status( @@ -563,7 +563,7 @@ class HgChangeReceiver(delta.Editor): @property def authors_file(self): return self.meta_file_named('authors') - + @stash_exception_on_self def delete_entry(self, path, revision_bogus, parent_baton, pool=None): br_path, branch = self._path_and_branch_for_path(path) diff --git a/tests/run.py b/tests/run.py --- a/tests/run.py +++ b/tests/run.py @@ -9,6 +9,7 @@ import test_fetch_branches import test_fetch_command import test_fetch_command_regexes import test_fetch_exec +import test_fetch_mappings import test_fetch_renames import test_fetch_symlinks import test_fetch_truncated @@ -26,6 +27,7 @@ def suite(): test_fetch_command.suite(), test_fetch_command_regexes.suite(), test_fetch_exec.suite(), + test_fetch_mappings.suite(), test_fetch_renames.suite(), test_fetch_symlinks.suite(), test_fetch_truncated.suite(), diff --git a/tests/test_fetch_mappings.py b/tests/test_fetch_mappings.py new file mode 100644 --- /dev/null +++ b/tests/test_fetch_mappings.py @@ -0,0 +1,58 @@ +"""Tests for author maps and file maps. +""" +import os +import unittest + +from mercurial import ui + +import test_util +import fetch_command + +class MapTests(test_util.TestBase): + @property + def authors(self): + return os.path.join(self.tmpdir, 'authormap') + + @property + def filemap(self): + return os.path.join(self.tmpdir, 'filemap') + + def test_author_map(self, stupid=False): + test_util.load_svndump_fixture(self.repo_path, 'replace_trunk_with_branch.svndump') + authormap = open(self.authors, 'w') + authormap.write("Augie=Augie Fackler \n") + authormap.close() + fetch_command.fetch_revisions(ui.ui(), + svn_url=test_util.fileurl(self.repo_path), + hg_repo_path=self.wc_path, + stupid=stupid, + authors=self.authors) + self.assertEqual(self.repo[0].user(), + 'Augie Fackler ') + self.assertEqual(self.repo['tip'].user(), + 'evil@5b65bade-98f3-4993-a01f-b7a6710da339') + + def test_author_map_stupid(self): + self.test_author_map(True) + + def test_author_map_closing_author(self, stupid=False): + test_util.load_svndump_fixture(self.repo_path, 'replace_trunk_with_branch.svndump') + authormap = open(self.authors, 'w') + authormap.write("evil=Testy ") + authormap.close() + fetch_command.fetch_revisions(ui.ui(), + svn_url=test_util.fileurl(self.repo_path), + hg_repo_path=self.wc_path, + stupid=stupid, + authors=self.authors) + self.assertEqual(self.repo[0].user(), + 'Augie@5b65bade-98f3-4993-a01f-b7a6710da339') + self.assertEqual(self.repo['tip'].user(), + 'Testy ') + + def test_author_map_closing_author_stupid(self): + self.test_author_map_closing_author(True) + + +def suite(): + return unittest.TestLoader().loadTestsFromTestCase(MapTests)