Patchwork [2,of,2] root: add template variables pointing to repository directories

login
register
mail settings
Submitter Yuya Nishihara
Date June 4, 2019, 11:30 p.m.
Message ID <671a49973d8b12fe223b.1559691048@mimosa>
Download mbox | patch
Permalink /patch/40319/
State New
Headers show

Comments

Yuya Nishihara - June 4, 2019, 11:30 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1559650415 -32400
#      Tue Jun 04 21:13:35 2019 +0900
# Node ID 671a49973d8b12fe223b6f81022f02061c4ddb01
# Parent  7182320ee57475303eb677a41dde142b7f87fc9b
root: add template variables pointing to repository directories

These paths are useful for GUI applications to detect changes. A GUI process
typically monitors .hg and .hg/store directories so that it will be notified
on lock/wlock deletion.

Alternatively, maybe we can add debugpaths command if we don't want to extend
the root command. I'm not sure which will be nicer.
Boris Feld - June 5, 2019, 12:24 p.m.
Looks good to me, queue thanks

On 05/06/2019 01:30, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1559650415 -32400
> #      Tue Jun 04 21:13:35 2019 +0900
> # Node ID 671a49973d8b12fe223b6f81022f02061c4ddb01
> # Parent  7182320ee57475303eb677a41dde142b7f87fc9b
> root: add template variables pointing to repository directories
>
> These paths are useful for GUI applications to detect changes. A GUI process
> typically monitors .hg and .hg/store directories so that it will be notified
> on lock/wlock deletion.
>
> Alternatively, maybe we can add debugpaths command if we don't want to extend
> the root command. I'm not sure which will be nicer.
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -5232,12 +5232,23 @@ def root(ui, repo, **opts):
>  
>      Print the root directory of the current repository.
>  
> +    .. container:: verbose
> +
> +      Template:
> +
> +      The following keywords are supported in addition to the common template
> +      keywords and functions. See also :hg:`help templates`.
> +
> +      :hgpath:    String. Path to the .hg directory.
> +      :storepath: String. Path to the directory holding versioned data.
> +
>      Returns 0 on success.
>      """
>      opts = pycompat.byteskwargs(opts)
>      with ui.formatter('root', opts) as fm:
>          fm.startitem()
>          fm.write('reporoot', '%s\n', repo.root)
> +        fm.data(hgpath=repo.path, storepath=repo.spath)
>  
>  @command('serve',
>      [('A', 'accesslog', '', _('name of access log file to write to'),
> diff --git a/tests/test-basic.t b/tests/test-basic.t
> --- a/tests/test-basic.t
> +++ b/tests/test-basic.t
> @@ -101,7 +101,9 @@ Repository root:
>    $ hg root -Tjson | sed 's|\\\\|\\|g'
>    [
>     {
> -    "reporoot": "$TESTTMP/t"
> +    "hgpath": "$TESTTMP/t/.hg",
> +    "reporoot": "$TESTTMP/t",
> +    "storepath": "$TESTTMP/t/.hg/store"
>     }
>    ]
>  
> diff --git a/tests/test-clone.t b/tests/test-clone.t
> --- a/tests/test-clone.t
> +++ b/tests/test-clone.t
> @@ -719,6 +719,14 @@ Test clone from the repository in (emula
>    $ hg -R src debugrevlog -c | egrep 'format|flags'
>    format : 0
>    flags  : (none)
> +  $ hg root -R src -T json | sed 's|\\\\|\\|g'
> +  [
> +   {
> +    "hgpath": "$TESTTMP/src/.hg",
> +    "reporoot": "$TESTTMP/src",
> +    "storepath": "$TESTTMP/src/.hg"
> +   }
> +  ]
>    $ hg clone -U -q src dst
>    $ hg -R dst log -q
>    0:e1bab28bca43
> diff --git a/tests/test-share.t b/tests/test-share.t
> --- a/tests/test-share.t
> +++ b/tests/test-share.t
> @@ -21,6 +21,14 @@ share shouldn't have a store dir
>    $ cd repo2
>    $ test -d .hg/store
>    [1]
> +  $ hg root -Tjson | sed 's|\\\\|\\|g'
> +  [
> +   {
> +    "hgpath": "$TESTTMP/repo2/.hg",
> +    "reporoot": "$TESTTMP/repo2",
> +    "storepath": "$TESTTMP/repo1/.hg/store"
> +   }
> +  ]
>  
>  share shouldn't have a full cache dir, original repo should
>  
> _______________________________________________
> 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
@@ -5232,12 +5232,23 @@  def root(ui, repo, **opts):
 
     Print the root directory of the current repository.
 
+    .. container:: verbose
+
+      Template:
+
+      The following keywords are supported in addition to the common template
+      keywords and functions. See also :hg:`help templates`.
+
+      :hgpath:    String. Path to the .hg directory.
+      :storepath: String. Path to the directory holding versioned data.
+
     Returns 0 on success.
     """
     opts = pycompat.byteskwargs(opts)
     with ui.formatter('root', opts) as fm:
         fm.startitem()
         fm.write('reporoot', '%s\n', repo.root)
+        fm.data(hgpath=repo.path, storepath=repo.spath)
 
 @command('serve',
     [('A', 'accesslog', '', _('name of access log file to write to'),
diff --git a/tests/test-basic.t b/tests/test-basic.t
--- a/tests/test-basic.t
+++ b/tests/test-basic.t
@@ -101,7 +101,9 @@  Repository root:
   $ hg root -Tjson | sed 's|\\\\|\\|g'
   [
    {
-    "reporoot": "$TESTTMP/t"
+    "hgpath": "$TESTTMP/t/.hg",
+    "reporoot": "$TESTTMP/t",
+    "storepath": "$TESTTMP/t/.hg/store"
    }
   ]
 
diff --git a/tests/test-clone.t b/tests/test-clone.t
--- a/tests/test-clone.t
+++ b/tests/test-clone.t
@@ -719,6 +719,14 @@  Test clone from the repository in (emula
   $ hg -R src debugrevlog -c | egrep 'format|flags'
   format : 0
   flags  : (none)
+  $ hg root -R src -T json | sed 's|\\\\|\\|g'
+  [
+   {
+    "hgpath": "$TESTTMP/src/.hg",
+    "reporoot": "$TESTTMP/src",
+    "storepath": "$TESTTMP/src/.hg"
+   }
+  ]
   $ hg clone -U -q src dst
   $ hg -R dst log -q
   0:e1bab28bca43
diff --git a/tests/test-share.t b/tests/test-share.t
--- a/tests/test-share.t
+++ b/tests/test-share.t
@@ -21,6 +21,14 @@  share shouldn't have a store dir
   $ cd repo2
   $ test -d .hg/store
   [1]
+  $ hg root -Tjson | sed 's|\\\\|\\|g'
+  [
+   {
+    "hgpath": "$TESTTMP/repo2/.hg",
+    "reporoot": "$TESTTMP/repo2",
+    "storepath": "$TESTTMP/repo1/.hg/store"
+   }
+  ]
 
 share shouldn't have a full cache dir, original repo should