# HG changeset patch # User Augie Fackler # Date 1234299146 21600 # Node ID 77812f98e250e67ba1928bbe5c49fa53e9ba3fde # Parent 906d3f302b454886292d85124a2c5ea2781706c4 Add a naive hg svn version command that works as long as hgsubversion is run from a checkout. diff --git a/rebuildmeta.py b/rebuildmeta.py --- a/rebuildmeta.py +++ b/rebuildmeta.py @@ -108,7 +108,7 @@ def rebuildmeta(ui, repo, hg_repo_path, pickle.dump(tagsinfo, tagsinfofile) tagsinfofile.close() rebuildmeta = util.register_subcommand('rebuildmeta')(rebuildmeta) - +rebuildmeta = util.command_needs_no_url(rebuildmeta) def determinebranch(branch): if branch.startswith('branches'): diff --git a/svncommand.py b/svncommand.py --- a/svncommand.py +++ b/svncommand.py @@ -9,7 +9,7 @@ from mercurial import util as merc_util import svnwrap import util -from util import register_subcommand, svn_subcommands, generate_help +from util import register_subcommand, svn_subcommands, generate_help, svn_commands_nourl # dirty trick to force demandimport to run my decorator anyway. from utility_commands import print_wc_url from fetch_command import fetch_revisions @@ -34,12 +34,13 @@ def svncmd(ui, repo, subcommand, *args, subcommand = candidates[0] path = os.path.dirname(repo.path) try: - if subcommand != 'rebuildmeta': + commandfunc = svn_subcommands[subcommand] + if commandfunc not in svn_commands_nourl: opts['svn_url'] = open(os.path.join(repo.path, 'svn', 'url')).read() - return svn_subcommands[subcommand](ui, args=args, - hg_repo_path=path, - repo=repo, - **opts) + return commandfunc(ui, args=args, + hg_repo_path=path, + repo=repo, + **opts) except TypeError: tb = traceback.extract_tb(sys.exc_info()[2]) if len(tb) == 1: diff --git a/svnwrap/svn_swig_wrapper.py b/svnwrap/svn_swig_wrapper.py --- a/svnwrap/svn_swig_wrapper.py +++ b/svnwrap/svn_swig_wrapper.py @@ -11,6 +11,9 @@ from svn import core from svn import delta from svn import ra +def version(): + return '%d.%d.%d' % (core.SVN_VER_MAJOR, core.SVN_VER_MINOR, core.SVN_VER_MICRO) + if (core.SVN_VER_MAJOR, core.SVN_VER_MINOR, core.SVN_VER_MICRO) < (1, 5, 0): #pragma: no cover raise ImportError, 'You must have Subversion 1.5.0 or newer and matching SWIG bindings.' diff --git a/util.py b/util.py --- a/util.py +++ b/util.py @@ -1,16 +1,30 @@ import os import shutil +from mercurial import hg from mercurial import node svn_subcommands = { } - def register_subcommand(name): def inner(fn): svn_subcommands[name] = fn return fn return inner +svn_commands_nourl = set() +def command_needs_no_url(fn): + svn_commands_nourl.add(fn) + return fn + + +def version(ui): + """Guess the version of hgsubversion. + """ + # TODO make this say something other than "unknown" for installed hgsubversion + repo = hg.repository(ui, os.path.dirname(__file__)) + ver = repo.dirstate.parents()[0] + return node.hex(ver)[:12] + def generate_help(): ret = ['hg svn ...', '', diff --git a/utility_commands.py b/utility_commands.py --- a/utility_commands.py +++ b/utility_commands.py @@ -1,8 +1,10 @@ +import mercurial from mercurial import cmdutil from mercurial import node from mercurial import util as mutil from hgext import rebase +import svnwrap import util import hg_delta_editor @@ -145,3 +147,13 @@ def show_outgoing_to_svn(ui, repo, hg_re for node in reversed(o_r): displayer.show(repo[node]) show_outgoing_to_svn = util.register_subcommand('outgoing')(show_outgoing_to_svn) + + +def version(ui, **opts): + """Show current version of hg and hgsubversion. + """ + ui.status('hg: %s\n' % mutil.version()) + ui.status('svn bindings: %s\n' % svnwrap.version()) + ui.status('hgsubversion: %s\n' % util.version(ui)) +version = util.register_subcommand('version')(version) +version = util.command_needs_no_url(version)