changeset 578:de384e4e0423

merge commands from utility_commands into svncommands
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Fri, 26 Feb 2010 15:00:15 +0100
parents 930bb6df19a0
children 21a389e4d8b5
files hgsubversion/svncommands.py hgsubversion/utility_commands.py tests/test_utility_commands.py
diffstat 3 files changed, 126 insertions(+), 139 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/svncommands.py
+++ b/hgsubversion/svncommands.py
@@ -11,9 +11,9 @@ import maps
 import svnwrap
 import svnrepo
 import util
-import utility_commands
 import svnexternals
 
+
 def verify(ui, repo, *args, **opts):
     '''verify current revision against Subversion repository
     '''
@@ -278,15 +278,111 @@ def update(ui, args, repo, clean=False, 
     return 1
 
 
-table = {
-    'update': update,
-    'help': help,
-    'rebuildmeta': rebuildmeta,
-    'updateexternals': svnexternals.updateexternals,
-    'verify': verify,
-}
+def genignore(ui, repo, force=False, **opts):
+    """generate .hgignore from svn:ignore properties.
+    """
 
-table.update(utility_commands.table)
+    if repo is None:
+        raise error.RepoError("There is no Mercurial repository"
+                              " here (.hg not found)")
+
+    ignpath = repo.wjoin('.hgignore')
+    if not force and os.path.exists(ignpath):
+        raise hgutil.Abort('not overwriting existing .hgignore, try --force?')
+    svn = svnrepo.svnremoterepo(repo.ui).svn
+    meta = repo.svnmeta()
+    hashes = meta.revmap.hashes()
+    parent = util.parentrev(ui, repo, meta, hashes)
+    r, br = hashes[parent.node()]
+    if meta.layout == 'single':
+        branchpath = ''
+    else:
+        branchpath = br and ('branches/%s/' % br) or 'trunk/'
+    ignorelines = ['.hgignore', 'syntax:glob']
+    dirs = [''] + [d[0] for d in svn.list_files(branchpath, r)
+                   if d[1] == 'd']
+    for dir in dirs:
+        path = '%s%s' % (branchpath, dir)
+        props = svn.list_props(path, r)
+        if 'svn:ignore' not in props:
+            continue
+        lines = props['svn:ignore'].strip().split('\n')
+        ignorelines += [dir and (dir + '/' + prop) or prop for prop in lines]
+
+    repo.wopener('.hgignore', 'w').write('\n'.join(ignorelines) + '\n')
+
+
+def info(ui, repo, **opts):
+    """show Subversion details similar to `svn info'
+    """
+
+    if repo is None:
+        raise error.RepoError("There is no Mercurial repository"
+                              " here (.hg not found)")
+
+    meta = repo.svnmeta()
+    hashes = meta.revmap.hashes()
+
+    if opts.get('rev'):
+        parent = repo[opts['rev']]
+    else:
+        parent = util.parentrev(ui, repo, meta, hashes)
+
+    pn = parent.node()
+    if pn not in hashes:
+        ui.status('Not a child of an svn revision.\n')
+        return 0
+    r, br = hashes[pn]
+    subdir = parent.extra()['convert_revision'][40:].split('@')[0]
+    if meta.layout == 'single':
+        branchpath = ''
+    elif br == None:
+        branchpath = '/trunk'
+    elif br.startswith('../'):
+        branchpath = '/%s' % br[3:]
+        subdir = subdir.replace('branches/../', '')
+    else:
+        branchpath = '/branches/%s' % br
+    remoterepo = svnrepo.svnremoterepo(repo.ui)
+    url = '%s%s' % (remoterepo.svnurl, branchpath)
+    author = meta.authors.reverselookup(parent.user())
+    # cleverly figure out repo root w/o actually contacting the server
+    reporoot = url[:len(url)-len(subdir)]
+    ui.write('''URL: %(url)s
+Repository Root: %(reporoot)s
+Repository UUID: %(uuid)s
+Revision: %(revision)s
+Node Kind: directory
+Last Changed Author: %(author)s
+Last Changed Rev: %(revision)s
+Last Changed Date: %(date)s\n''' %
+              {'reporoot': reporoot,
+               'uuid': meta.uuid,
+               'url': url,
+               'author': author,
+               'revision': r,
+               # TODO I'd like to format this to the user's local TZ if possible
+               'date': hgutil.datestr(parent.date(),
+                                      '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)')
+              })
+
+
+def listauthors(ui, args, authors=None, **opts):
+    """list all authors in a Subversion repository
+    """
+    if not len(args):
+        ui.status('No repository specified.\n')
+        return
+    svn = svnrepo.svnremoterepo(ui, args[0]).svn
+    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.write('%s\n' % '\n'.join(sorted(author_set)))
 
 
 def _helpgen():
@@ -300,3 +396,15 @@ def _helpgen():
             short_description = ''
         ret.append(" %-10s  %s" % (name, short_description))
     return '\n'.join(ret) + '\n'
+
+
+table = {
+    'genignore': genignore,
+    'info': info,
+    'listauthors': listauthors,
+    'update': update,
+    'help': help,
+    'rebuildmeta': rebuildmeta,
+    'updateexternals': svnexternals.updateexternals,
+    'verify': verify,
+}
deleted file mode 100644
--- a/hgsubversion/utility_commands.py
+++ /dev/null
@@ -1,121 +0,0 @@
-import os
-
-from mercurial import util as hgutil
-from mercurial import error
-
-import svnwrap
-import svnrepo
-import util
-
-def genignore(ui, repo, force=False, **opts):
-    """generate .hgignore from svn:ignore properties.
-    """
-
-    if repo is None:
-        raise error.RepoError("There is no Mercurial repository"
-                              " here (.hg not found)")
-
-    ignpath = repo.wjoin('.hgignore')
-    if not force and os.path.exists(ignpath):
-        raise hgutil.Abort('not overwriting existing .hgignore, try --force?')
-    svn = svnrepo.svnremoterepo(repo.ui).svn
-    meta = repo.svnmeta()
-    hashes = meta.revmap.hashes()
-    parent = util.parentrev(ui, repo, meta, hashes)
-    r, br = hashes[parent.node()]
-    if meta.layout == 'single':
-        branchpath = ''
-    else:
-        branchpath = br and ('branches/%s/' % br) or 'trunk/'
-    ignorelines = ['.hgignore', 'syntax:glob']
-    dirs = [''] + [d[0] for d in svn.list_files(branchpath, r)
-                   if d[1] == 'd']
-    for dir in dirs:
-        path = '%s%s' % (branchpath, dir)
-        props = svn.list_props(path, r)
-        if 'svn:ignore' not in props:
-            continue
-        lines = props['svn:ignore'].strip().split('\n')
-        ignorelines += [dir and (dir + '/' + prop) or prop for prop in lines]
-
-    repo.wopener('.hgignore', 'w').write('\n'.join(ignorelines) + '\n')
-
-
-def info(ui, repo, **opts):
-    """show Subversion details similar to `svn info'
-    """
-
-    if repo is None:
-        raise error.RepoError("There is no Mercurial repository"
-                              " here (.hg not found)")
-
-    meta = repo.svnmeta()
-    hashes = meta.revmap.hashes()
-
-    if opts.get('rev'):
-        parent = repo[opts['rev']]
-    else:
-        parent = util.parentrev(ui, repo, meta, hashes)
-
-    pn = parent.node()
-    if pn not in hashes:
-        ui.status('Not a child of an svn revision.\n')
-        return 0
-    r, br = hashes[pn]
-    subdir = parent.extra()['convert_revision'][40:].split('@')[0]
-    if meta.layout == 'single':
-        branchpath = ''
-    elif br == None:
-        branchpath = '/trunk'
-    elif br.startswith('../'):
-        branchpath = '/%s' % br[3:]
-        subdir = subdir.replace('branches/../', '')
-    else:
-        branchpath = '/branches/%s' % br
-    remoterepo = svnrepo.svnremoterepo(repo.ui)
-    url = '%s%s' % (remoterepo.svnurl, branchpath)
-    author = meta.authors.reverselookup(parent.user())
-    # cleverly figure out repo root w/o actually contacting the server
-    reporoot = url[:len(url)-len(subdir)]
-    ui.write('''URL: %(url)s
-Repository Root: %(reporoot)s
-Repository UUID: %(uuid)s
-Revision: %(revision)s
-Node Kind: directory
-Last Changed Author: %(author)s
-Last Changed Rev: %(revision)s
-Last Changed Date: %(date)s\n''' %
-              {'reporoot': reporoot,
-               'uuid': meta.uuid,
-               'url': url,
-               'author': author,
-               'revision': r,
-               # TODO I'd like to format this to the user's local TZ if possible
-               'date': hgutil.datestr(parent.date(),
-                                      '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)')
-              })
-
-
-def listauthors(ui, args, authors=None, **opts):
-    """list all authors in a Subversion repository
-    """
-    if not len(args):
-        ui.status('No repository specified.\n')
-        return
-    svn = svnrepo.svnremoterepo(ui, args[0]).svn
-    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.write('%s\n' % '\n'.join(sorted(author_set)))
-
-
-table = {
-    'genignore': genignore,
-    'info': info,
-    'listauthors': listauthors,
-}
--- a/tests/test_utility_commands.py
+++ b/tests/test_utility_commands.py
@@ -9,7 +9,7 @@ from mercurial import node
 from mercurial import commands
 
 from hgsubversion import util
-from hgsubversion import utility_commands
+from hgsubversion import svncommands
 import test_util
 from hgsubversion import wrappers
 
@@ -33,7 +33,7 @@ class UtilityTests(test_util.TestBase):
         hg.update(self.repo, 'the_branch')
         u = self.ui()
         u.pushbuffer()
-        utility_commands.info(u, self.repo)
+        svncommands.info(u, self.repo)
         actual = u.popbuffer()
         expected = (expected_info_output %
                     {'date': '2008-10-08 01:39:05 +0000 (Wed, 08 Oct 2008)',
@@ -44,7 +44,7 @@ class UtilityTests(test_util.TestBase):
         self.assertEqual(actual, expected)
         hg.update(self.repo, 'default')
         u.pushbuffer()
-        utility_commands.info(u, self.repo)
+        svncommands.info(u, self.repo)
         actual = u.popbuffer()
         expected = (expected_info_output %
                     {'date': '2008-10-08 01:39:29 +0000 (Wed, 08 Oct 2008)',
@@ -55,7 +55,7 @@ class UtilityTests(test_util.TestBase):
         self.assertEqual(actual, expected)
         hg.update(self.repo, 'default')
         u.pushbuffer()
-        utility_commands.info(u, self.repo, rev=3)
+        svncommands.info(u, self.repo, rev=3)
         actual = u.popbuffer()
         expected = (expected_info_output %
                     {'date': '2008-10-08 01:39:05 +0000 (Wed, 08 Oct 2008)',
@@ -70,7 +70,7 @@ class UtilityTests(test_util.TestBase):
         hg.update(self.repo, 'tip')
         u = self.ui()
         u.pushbuffer()
-        utility_commands.info(u, self.repo)
+        svncommands.info(u, self.repo)
         actual = u.popbuffer()
         expected = (expected_info_output %
                     {'date': '2008-10-08 01:39:29 +0000 (Wed, 08 Oct 2008)',
@@ -187,7 +187,7 @@ class UtilityTests(test_util.TestBase):
                                          self.wc_path, noupdate=False)
         u = self.ui()
         u.pushbuffer()
-        utility_commands.genignore(u, self.repo, self.wc_path)
+        svncommands.genignore(u, self.repo, self.wc_path)
         self.assertEqual(open(os.path.join(self.wc_path, '.hgignore')).read(),
                          '.hgignore\nsyntax:glob\nblah\notherblah\nbaz/magic\n')
 
@@ -196,7 +196,7 @@ class UtilityTests(test_util.TestBase):
         hg.update(self.repo, 'tip')
         u = self.ui()
         u.pushbuffer()
-        utility_commands.genignore(u, self.repo, self.wc_path)
+        svncommands.genignore(u, self.repo, self.wc_path)
         self.assertStringEqual(open(os.path.join(self.wc_path, '.hgignore')).read(),
                                '.hgignore\nsyntax:glob\nblah\notherblah\nbaz/magic\n')
 
@@ -205,7 +205,7 @@ class UtilityTests(test_util.TestBase):
                                        'replace_trunk_with_branch.svndump')
         u = self.ui()
         u.pushbuffer()
-        utility_commands.listauthors(u,
+        svncommands.listauthors(u,
                                      args=[test_util.fileurl(self.repo_path)],
                                      authors=None)
         actual = u.popbuffer()
@@ -216,7 +216,7 @@ class UtilityTests(test_util.TestBase):
         test_util.load_svndump_fixture(self.repo_path,
                                        'replace_trunk_with_branch.svndump')
         author_path = os.path.join(self.repo_path, 'authors')
-        utility_commands.listauthors(self.ui(),
+        svncommands.listauthors(self.ui(),
                                      args=[test_util.fileurl(self.repo_path)],
                                      authors=author_path)
         self.assertEqual(open(author_path).read(), 'Augie=\nevil=\n')