Patchwork [3,of,3] version: change "place" field of extension to "bundled" flag

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 30, 2016, 3:10 p.m.
Message ID <88a3a36023ed943455d4.1472569814@mimosa>
Download mbox | patch
Permalink /patch/16482/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 30, 2016, 3:10 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1472222332 -32400
#      Fri Aug 26 23:38:52 2016 +0900
# Node ID 88a3a36023ed943455d4663583531d7f63aa9521
# Parent  8bae198823d55c18e640f22df8c8ef89f50fd998
version: change "place" field of extension to "bundled" flag

The name "place" sounds odd. We can simply expose raw boolean values instead
of switching external/internal literals.
Augie Fackler - Aug. 30, 2016, 9:35 p.m.
On Wed, Aug 31, 2016 at 12:10:14AM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1472222332 -32400
> #      Fri Aug 26 23:38:52 2016 +0900
> # Node ID 88a3a36023ed943455d4663583531d7f63aa9521
> # Parent  8bae198823d55c18e640f22df8c8ef89f50fd998
> version: change "place" field of extension to "bundled" flag

Queued this one too. Thanks!

>
> The name "place" sounds odd. We can simply expose raw boolean values instead
> of switching external/internal literals.
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -7293,14 +7293,13 @@ def version_(ui, **opts):
>      fn = fm.nested("extensions")
>      if names:
>          namefmt = "  %%-%ds  " % max(len(n) for n in names)
> -        if fn:
> -            places = ["external", "internal"]
> -        else:
> -            places = [_("external"), _("internal")]
> +        places = [_("external"), _("internal")]
>          for n, v, p in zip(names, vers, isinternals):
>              fn.startitem()
>              fn.condwrite(ui.verbose, "name", namefmt, n)
> -            fn.condwrite(ui.verbose, "place", "%s  ", places[p])
> +            if ui.verbose:
> +                fn.plain("%s  " % places[p])
> +            fn.data(bundled=p)
>              fn.condwrite(ui.verbose and v, "ver", "%s", v)
>              if ui.verbose:
>                  fn.plain("\n")
> diff --git a/tests/test-extension.t b/tests/test-extension.t
> --- a/tests/test-extension.t
> +++ b/tests/test-extension.t
> @@ -1253,15 +1253,15 @@ Test JSON output of version:
>    $ hg version --config extensions.throw=throw.py -Tjson
>    [
>     {
> -    "extensions": [{"name": "throw", "place": "external", "ver": "1.twentythree"}],
> +    "extensions": [{"bundled": false, "name": "throw", "ver": "1.twentythree"}],
>      "ver": "3.2.2"
>     }
>    ]
>
> -  $ LANGUAGE= LC_ALL=ja_JP.UTF-8 hg version --config extensions.strip= -Tjson
> +  $ hg version --config extensions.strip= -Tjson
>    [
>     {
> -    "extensions": [{"name": "strip", "place": "internal", "ver": null}],
> +    "extensions": [{"bundled": true, "name": "strip", "ver": null}],
>      "ver": "*" (glob)
>     }
>    ]
> @@ -1269,7 +1269,7 @@ Test JSON output of version:
>  Test template output of version:
>
>    $ hg version --config extensions.throw=throw.py --config extensions.strip= \
> -  > -T'{extensions % "{name}  {pad(ver, 16)}  ({place})\n"}'
> +  > -T'{extensions % "{name}  {pad(ver, 16)}  ({if(bundled, "internal", "external")})\n"}'
>    throw  1.twentythree     (external)
>    strip                    (internal)
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -7293,14 +7293,13 @@  def version_(ui, **opts):
     fn = fm.nested("extensions")
     if names:
         namefmt = "  %%-%ds  " % max(len(n) for n in names)
-        if fn:
-            places = ["external", "internal"]
-        else:
-            places = [_("external"), _("internal")]
+        places = [_("external"), _("internal")]
         for n, v, p in zip(names, vers, isinternals):
             fn.startitem()
             fn.condwrite(ui.verbose, "name", namefmt, n)
-            fn.condwrite(ui.verbose, "place", "%s  ", places[p])
+            if ui.verbose:
+                fn.plain("%s  " % places[p])
+            fn.data(bundled=p)
             fn.condwrite(ui.verbose and v, "ver", "%s", v)
             if ui.verbose:
                 fn.plain("\n")
diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -1253,15 +1253,15 @@  Test JSON output of version:
   $ hg version --config extensions.throw=throw.py -Tjson
   [
    {
-    "extensions": [{"name": "throw", "place": "external", "ver": "1.twentythree"}],
+    "extensions": [{"bundled": false, "name": "throw", "ver": "1.twentythree"}],
     "ver": "3.2.2"
    }
   ]
 
-  $ LANGUAGE= LC_ALL=ja_JP.UTF-8 hg version --config extensions.strip= -Tjson
+  $ hg version --config extensions.strip= -Tjson
   [
    {
-    "extensions": [{"name": "strip", "place": "internal", "ver": null}],
+    "extensions": [{"bundled": true, "name": "strip", "ver": null}],
     "ver": "*" (glob)
    }
   ]
@@ -1269,7 +1269,7 @@  Test JSON output of version:
 Test template output of version:
 
   $ hg version --config extensions.throw=throw.py --config extensions.strip= \
-  > -T'{extensions % "{name}  {pad(ver, 16)}  ({place})\n"}'
+  > -T'{extensions % "{name}  {pad(ver, 16)}  ({if(bundled, "internal", "external")})\n"}'
   throw  1.twentythree     (external)
   strip                    (internal)