# HG changeset patch # User Dirkjan Ochtman # Date 1266941811 -3600 # Node ID 00393e9abff8e22707b88e948a8c141ca0cab891 # Parent 7f0e8fd6ee22c698d3d127af46368575a72c75ed svncommands: make repo optional (useful for things like listauthors) diff --git a/hgsubversion/__init__.py b/hgsubversion/__init__.py --- a/hgsubversion/__init__.py +++ b/hgsubversion/__init__.py @@ -124,10 +124,9 @@ def svn(ui, repo, subcommand, *args, **o if key in opts: ui.setconfig('hgsubversion', key, opts[key]) - path = os.path.dirname(repo.path) try: commandfunc = svncommands.table[subcommand] - return commandfunc(ui, args=args, hg_repo_path=path, repo=repo, **opts) + return commandfunc(ui, args=args, repo=repo, **opts) except core.SubversionException, e: if e.apr_err == core.SVN_ERR_RA_SERF_SSL_CERT_UNTRUSTED: raise hgutil.Abort('It appears svn does not trust the ssl cert for this site.\n' @@ -162,6 +161,8 @@ hg.schemes.update({ 'file': _lookup, 'ht 'svn': svnrepo, 'svn+ssh': svnrepo, 'svn+http': svnrepo, 'svn+https': svnrepo}) +commands.optionalrepo += ' svn' + cmdtable = { "svn": (svn, diff --git a/hgsubversion/maps.py b/hgsubversion/maps.py --- a/hgsubversion/maps.py +++ b/hgsubversion/maps.py @@ -125,7 +125,7 @@ class TagMap(dict): repo.ui.warn('tag map outdated, running rebuildmeta...\n') f.close() os.unlink(self.path) - svncommands.rebuildmeta(repo.ui, repo, os.path.dirname(repo.path), ()) + svncommands.rebuildmeta(repo.ui, repo, ()) return elif ver != self.VERSION: print 'tagmap too new -- please upgrade' diff --git a/hgsubversion/svncommands.py b/hgsubversion/svncommands.py --- a/hgsubversion/svncommands.py +++ b/hgsubversion/svncommands.py @@ -5,6 +5,7 @@ import cPickle as pickle from mercurial import hg from mercurial import node from mercurial import util as hgutil +from mercurial import error import maps import svnwrap @@ -13,10 +14,14 @@ import util import utility_commands import svnexternals - def verify(ui, repo, *args, **opts): '''verify current revision against Subversion repository ''' + + if repo is None: + raise error.RepoError("There is no Mercurial repository" + " here (.hg not found)") + ctx = repo[opts.get('rev', '.')] if 'close' in ctx.extra(): ui.write('cannot verify closed branch') @@ -67,9 +72,14 @@ def verify(ui, repo, *args, **opts): return result -def rebuildmeta(ui, repo, hg_repo_path, args, **opts): +def rebuildmeta(ui, repo, args, **opts): """rebuild hgsubversion metadata using values stored in revisions """ + + if repo is None: + raise error.RepoError("There is no Mercurial repository" + " here (.hg not found)") + dest = None if len(args) == 1: dest = args[0] diff --git a/hgsubversion/utility_commands.py b/hgsubversion/utility_commands.py --- a/hgsubversion/utility_commands.py +++ b/hgsubversion/utility_commands.py @@ -1,6 +1,7 @@ import os from mercurial import util as hgutil +from mercurial import error import svnwrap import svnrepo @@ -9,6 +10,11 @@ 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?') @@ -35,9 +41,14 @@ def genignore(ui, repo, force=False, **o repo.wopener('.hgignore', 'w').write('\n'.join(ignorelines) + '\n') -def info(ui, repo, hg_repo_path, **opts): +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() diff --git a/tests/test_rebuildmeta.py b/tests/test_rebuildmeta.py --- a/tests/test_rebuildmeta.py +++ b/tests/test_rebuildmeta.py @@ -22,7 +22,6 @@ def _do_case(self, name, stupid, single) src, dest = hg.clone(u, self.wc_path, wc2_path, update=False) svncommands.rebuildmeta(u, dest, - os.path.dirname(dest.path), args=[test_util.fileurl(self.repo_path + subdir), ]) self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')), diff --git a/tests/test_tags.py b/tests/test_tags.py --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -116,7 +116,6 @@ rename a tag src, dest = hg.clone(repo.ui, self.wc_path, wc2_path, update=False) svncommands.rebuildmeta(repo.ui, dest, - os.path.dirname(dest.path), args=[test_util.fileurl(self.repo_path), ]) commands.pull(self.repo.ui, self.repo, stupid=stupid) dtags, srctags = dest.tags(), self.repo.tags() 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 @@ -34,7 +34,7 @@ class UtilityTests(test_util.TestBase): hg.update(self.repo, 'the_branch') u = ui.ui() u.pushbuffer() - utility_commands.info(u, self.repo, self.wc_path) + utility_commands.info(u, self.repo) actual = u.popbuffer() expected = (expected_info_output % {'date': '2008-10-08 01:39:05 +0000 (Wed, 08 Oct 2008)', @@ -45,7 +45,7 @@ class UtilityTests(test_util.TestBase): self.assertEqual(actual, expected) hg.update(self.repo, 'default') u.pushbuffer() - utility_commands.info(u, self.repo, self.wc_path) + utility_commands.info(u, self.repo) actual = u.popbuffer() expected = (expected_info_output % {'date': '2008-10-08 01:39:29 +0000 (Wed, 08 Oct 2008)', @@ -56,7 +56,7 @@ class UtilityTests(test_util.TestBase): self.assertEqual(actual, expected) hg.update(self.repo, 'default') u.pushbuffer() - utility_commands.info(u, self.repo, self.wc_path, rev=3) + utility_commands.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)', @@ -71,7 +71,7 @@ class UtilityTests(test_util.TestBase): hg.update(self.repo, 'tip') u = ui.ui() u.pushbuffer() - utility_commands.info(u, self.repo, self.wc_path) + utility_commands.info(u, self.repo) actual = u.popbuffer() expected = (expected_info_output % {'date': '2008-10-08 01:39:29 +0000 (Wed, 08 Oct 2008)',