# HG changeset patch # User Daniel Tang # Date 1239156922 14400 # Node ID c34abd2448b7d67bb76fb7dd8e85542f645eb773 # Parent 2969a20e0eefe45a3931bf6d7cfbdc4ead1bff95 Issue #60: Add a svn sub-command to list all authors in a Subversion repository diff --git a/tests/test_utility_commands.py b/tests/test_utility_commands.py --- a/tests/test_utility_commands.py +++ b/tests/test_utility_commands.py @@ -169,6 +169,25 @@ class UtilityTests(test_util.TestBase): self.assertEqual(open(os.path.join(self.wc_path, '.hgignore')).read(), '.hgignore\nsyntax:glob\nblah\notherblah\nbaz/magic\n') + def test_list_authors(self): + test_util.load_svndump_fixture(self.repo_path, + 'replace_trunk_with_branch.svndump') + u = ui.ui() + utility_commands.list_authors(u, + args=[test_util.fileurl(self.repo_path)], + authors=None) + self.assertEqual(u.stream.getvalue(), 'Augie\nevil\n') + + + def test_list_authors_map(self): + test_util.load_svndump_fixture(self.repo_path, + 'replace_trunk_with_branch.svndump') + author_path = os.path.join(self.repo_path, 'authors') + utility_commands.list_authors(ui.ui(), + args=[test_util.fileurl(self.repo_path)], + authors=author_path) + self.assertEqual(open(author_path).read(), 'Augie=\nevil=\n') + def suite(): all = [unittest.TestLoader().loadTestsFromTestCase(UtilityTests), diff --git a/utility_commands.py b/utility_commands.py --- a/utility_commands.py +++ b/utility_commands.py @@ -198,6 +198,26 @@ def show_outgoing_to_svn(ui, repo, hg_re show_outgoing_to_svn = util.register_subcommand('outgoing')(show_outgoing_to_svn) +def list_authors(ui, args, authors=None, **opts): + """list all authors in a Subversion repository + """ + if not len(args): + ui.status('No repository specified.\n') + return + svn = svnwrap.SubversionRepo(util.normalize_url(args[0])) + author_set = set() + for rev in svn.revisions(): + author_set.add(str(rev.author)) # So None becomes 'None' + if authors: + authorfile = open(authors, 'w') + authorfile.write('%s=\n' % '=\n'.join(sorted(author_set))) + authorfile.close() + else: + ui.status('%s\n' % '\n'.join(sorted(author_set))) +list_authors = util.register_subcommand('listauthors')(list_authors) +list_authors = util.command_needs_no_url(list_authors) + + def version(ui, **opts): """Show current version of hg and hgsubversion. """