changeset 196:77812f98e250

Add a naive hg svn version command that works as long as hgsubversion is run from a checkout.
author Augie Fackler <durin42@gmail.com>
date Tue, 10 Feb 2009 14:52:26 -0600
parents 906d3f302b45
children 43d56e973c3c
files rebuildmeta.py svncommand.py svnwrap/svn_swig_wrapper.py util.py utility_commands.py
diffstat 5 files changed, 38 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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'):
--- 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:
--- 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.'
 
--- 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 ...', '',
--- 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)