changeset 236:c34abd2448b7

Issue #60: Add a svn sub-command to list all authors in a Subversion repository
author Daniel Tang <dytang@cs.purdue.edu>
date Tue, 07 Apr 2009 22:15:22 -0400
parents 2969a20e0eef
children c90cfa665b81
files tests/test_utility_commands.py utility_commands.py
diffstat 2 files changed, 39 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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),
--- 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.
     """