Patchwork [2,of,2,v5] schemes: add expand-scheme command, resolving a scheme to its canonical form

login
register
mail settings
Submitter Jason R. Coombs
Date Feb. 4, 2016, 3:21 p.m.
Message ID <1f230eaf43771f580253.1454599269@waste.org>
Download mbox | patch
Permalink /patch/12979/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Jason R. Coombs - Feb. 4, 2016, 3:21 p.m.
# HG changeset patch
# User Jason R. Coombs <jaraco@jaraco.com>
# Date 1454097224 18000
#      Fri Jan 29 14:53:44 2016 -0500
# Node ID 1f230eaf43771f58025301af1ee88486305867ab
# Parent  b494927d0e972f03b7b9e7d4c203cc35516ebd8f
schemes: add expand-scheme command, resolving a scheme to its canonical form
Yuya Nishihara - Feb. 5, 2016, 2:44 p.m.
On Thu, 04 Feb 2016 09:21:09 -0600, Jason R. Coombs wrote:
> # HG changeset patch
> # User Jason R. Coombs <jaraco@jaraco.com>
> # Date 1454097224 18000
> #      Fri Jan 29 14:53:44 2016 -0500
> # Node ID 1f230eaf43771f58025301af1ee88486305867ab
> # Parent  b494927d0e972f03b7b9e7d4c203cc35516ebd8f
> schemes: add expand-scheme command, resolving a scheme to its canonical form
               ^^^^^^^^^^^^^

Old name. Fixed in flight and pushed to the clowncopter.
Congratulations on your first Mercurial patch!

> +cmdtable = {}
> +command = cmdutil.command(cmdtable)

Also moved these lines next to imports, which seems our convention.

Patch

diff --git a/hgext/schemes.py b/hgext/schemes.py
--- a/hgext/schemes.py
+++ b/hgext/schemes.py
@@ -41,7 +41,7 @@ 
 """
 
 import os, re
-from mercurial import extensions, hg, templater, util, error
+from mercurial import extensions, hg, templater, util, error, cmdutil
 from mercurial.i18n import _
 
 # Note for extension authors: ONLY specify testedwith = 'internal' for
@@ -109,3 +109,15 @@ 
         hg.schemes[scheme] = ShortRepository(url, scheme, t)
 
     extensions.wrapfunction(util, 'hasdriveletter', hasdriveletter)
+
+cmdtable = {}
+command = cmdutil.command(cmdtable)
+
+@command('debugexpandscheme', norepo=True)
+def expandscheme(ui, url, **opts):
+    """given a repo path, provide the scheme-expanded path
+    """
+    repo = hg._peerlookup(url)
+    if isinstance(repo, ShortRepository):
+        url = repo.resolve(url)
+    ui.write(url + '\n')
diff --git a/tests/test-schemes.t b/tests/test-schemes.t
--- a/tests/test-schemes.t
+++ b/tests/test-schemes.t
@@ -52,6 +52,21 @@ 
   no changes found
   [1]
 
+check that expand-scheme outputs the canonical form
+
+  $ hg debugexpandscheme bb://user/repo
+  https://bitbucket.org/user/repo
+
+expanding an unknown scheme emits the input
+
+  $ hg debugexpandscheme foobar://this/that
+  foobar://this/that
+
+expanding a canonical URL emits the input
+
+  $ hg debugexpandscheme https://bitbucket.org/user/repo
+  https://bitbucket.org/user/repo
+
 errors
 
   $ cat errors.log