Patchwork [2,of,2] archive: add an experimental config to control the metadata file template

login
register
mail settings
Submitter Matt Harbison
Date July 17, 2017, 4:57 a.m.
Message ID <a85b7c754630cb4ac49b.1500267459@Envy>
Download mbox | patch
Permalink /patch/22444/
State Accepted
Headers show

Comments

Matt Harbison - July 17, 2017, 4:57 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1500266969 14400
#      Mon Jul 17 00:49:29 2017 -0400
# Node ID a85b7c754630cb4ac49b2cebea0ceca3d2f2eaaa
# Parent  4d37def90ad5e0196dadb9bc2c9e62effad63691
archive: add an experimental config to control the metadata file template

Experimental because given the possible complexity, it may be worth figuring out
how to load this from a file, similar to the style files for the log command,
instead of trying to stuff it on the command line.
Yuya Nishihara - July 17, 2017, 1:56 p.m.
On Mon, 17 Jul 2017 00:57:39 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1500266969 14400
> #      Mon Jul 17 00:49:29 2017 -0400
> # Node ID a85b7c754630cb4ac49b2cebea0ceca3d2f2eaaa
> # Parent  4d37def90ad5e0196dadb9bc2c9e62effad63691
> archive: add an experimental config to control the metadata file template
> 
> Experimental because given the possible complexity, it may be worth figuring out
> how to load this from a file, similar to the style files for the log command,
> instead of trying to stuff it on the command line.

Maybe we'll want to save it in [templates] section, and specify it in a similar
way to -T option?
via Mercurial-devel - July 17, 2017, 5:54 p.m.
On Sun, Jul 16, 2017 at 9:57 PM, Matt Harbison <mharbison72@gmail.com> wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1500266969 14400
> #      Mon Jul 17 00:49:29 2017 -0400
> # Node ID a85b7c754630cb4ac49b2cebea0ceca3d2f2eaaa
> # Parent  4d37def90ad5e0196dadb9bc2c9e62effad63691
> archive: add an experimental config to control the metadata file template
>
> Experimental because given the possible complexity, it may be worth figuring out
> how to load this from a file, similar to the style files for the log command,
> instead of trying to stuff it on the command line.
>
> diff --git a/mercurial/archival.py b/mercurial/archival.py
> --- a/mercurial/archival.py
> +++ b/mercurial/archival.py
> @@ -99,7 +99,8 @@
>      )
>
>      opts = {
> -        'template': default
> +        'template': repo.ui.config('experimental', 'archivemetatemplate',
> +                                   default)

I think this should be registered with the new coreconfigitem() method
(other experimental options are).
Matt Harbison - July 18, 2017, 3:10 a.m.
On Mon, 17 Jul 2017 09:56:25 -0400, Yuya Nishihara <yuya@tcha.org> wrote:

> On Mon, 17 Jul 2017 00:57:39 -0400, Matt Harbison wrote:
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison@yahoo.com>
>> # Date 1500266969 14400
>> #      Mon Jul 17 00:49:29 2017 -0400
>> # Node ID a85b7c754630cb4ac49b2cebea0ceca3d2f2eaaa
>> # Parent  4d37def90ad5e0196dadb9bc2c9e62effad63691
>> archive: add an experimental config to control the metadata file  
>> template
>>
>> Experimental because given the possible complexity, it may be worth  
>> figuring out
>> how to load this from a file, similar to the style files for the log  
>> command,
>> instead of trying to stuff it on the command line.
>
> Maybe we'll want to save it in [templates] section, and specify it in a  
> similar
> way to -T option?

Yes.  I didn't realize [templates] could hold a filename like that.  I'll  
follow up next cycle.
Matt Harbison - July 18, 2017, 3:29 a.m.
On Mon, 17 Jul 2017 13:54:29 -0400, Martin von Zweigbergk  
<martinvonz@google.com> wrote:

> On Sun, Jul 16, 2017 at 9:57 PM, Matt Harbison <mharbison72@gmail.com>  
> wrote:
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison@yahoo.com>
>> # Date 1500266969 14400
>> #      Mon Jul 17 00:49:29 2017 -0400
>> # Node ID a85b7c754630cb4ac49b2cebea0ceca3d2f2eaaa
>> # Parent  4d37def90ad5e0196dadb9bc2c9e62effad63691
>> archive: add an experimental config to control the metadata file  
>> template
>>
>> Experimental because given the possible complexity, it may be worth  
>> figuring out
>> how to load this from a file, similar to the style files for the log  
>> command,
>> instead of trying to stuff it on the command line.
>>
>> diff --git a/mercurial/archival.py b/mercurial/archival.py
>> --- a/mercurial/archival.py
>> +++ b/mercurial/archival.py
>> @@ -99,7 +99,8 @@
>>      )
>>
>>      opts = {
>> -        'template': default
>> +        'template': repo.ui.config('experimental',  
>> 'archivemetatemplate',
>> +                                   default)
>
> I think this should be registered with the new coreconfigitem() method
> (other experimental options are).

I actually started out that way, but given how cryptic the default value  
is, I wasn't sure it was a good idea.  I've only been skimming the  
configitem patches, but I could see maybe adding the registered default to  
the help text automatically.  I don't think we want to display this one  
for simplicity.  I also didn't see anything nearly this complex.

Alternately, we could move this string out to a template file, and the  
default is the filename (but I wonder if there will be platform  
differences when listing it).  Or we could set the default to None, and  
document that the default is the legacy content.  But I guess that  
undermines having the defaults in one place, and isn't much different than  
this.

Thoughts?
via Mercurial-devel - July 18, 2017, 4:29 a.m.
On Mon, Jul 17, 2017 at 8:29 PM, Matt Harbison <mharbison72@gmail.com> wrote:
> On Mon, 17 Jul 2017 13:54:29 -0400, Martin von Zweigbergk
> <martinvonz@google.com> wrote:
>
>> On Sun, Jul 16, 2017 at 9:57 PM, Matt Harbison <mharbison72@gmail.com>
>> wrote:
>>>
>>> # HG changeset patch
>>> # User Matt Harbison <matt_harbison@yahoo.com>
>>> # Date 1500266969 14400
>>> #      Mon Jul 17 00:49:29 2017 -0400
>>> # Node ID a85b7c754630cb4ac49b2cebea0ceca3d2f2eaaa
>>> # Parent  4d37def90ad5e0196dadb9bc2c9e62effad63691
>>> archive: add an experimental config to control the metadata file template
>>>
>>> Experimental because given the possible complexity, it may be worth
>>> figuring out
>>> how to load this from a file, similar to the style files for the log
>>> command,
>>> instead of trying to stuff it on the command line.
>>>
>>> diff --git a/mercurial/archival.py b/mercurial/archival.py
>>> --- a/mercurial/archival.py
>>> +++ b/mercurial/archival.py
>>> @@ -99,7 +99,8 @@
>>>      )
>>>
>>>      opts = {
>>> -        'template': default
>>> +        'template': repo.ui.config('experimental',
>>> 'archivemetatemplate',
>>> +                                   default)
>>
>>
>> I think this should be registered with the new coreconfigitem() method
>> (other experimental options are).
>
>
> I actually started out that way, but given how cryptic the default value is,
> I wasn't sure it was a good idea.

You mean because the it's nice to have the default value close to the
code that uses it? Yeah, I've felt that too.

> I've only been skimming the configitem
> patches, but I could see maybe adding the registered default to the help
> text automatically.  I don't think we want to display this one for
> simplicity.  I also didn't see anything nearly this complex.

You could perhaps use (abuse?) the "dynamicdefault" for this.

>
> Alternately, we could move this string out to a template file, and the
> default is the filename (but I wonder if there will be platform differences
> when listing it).  Or we could set the default to None, and document that
> the default is the legacy content.  But I guess that undermines having the
> defaults in one place, and isn't much different than this.
>
> Thoughts?

I'd just leave it as is for now.
Yuya Nishihara - July 18, 2017, 12:31 p.m.
On Mon, 17 Jul 2017 23:10:22 -0400, Matt Harbison wrote:
> On Mon, 17 Jul 2017 09:56:25 -0400, Yuya Nishihara <yuya@tcha.org> wrote:
> > On Mon, 17 Jul 2017 00:57:39 -0400, Matt Harbison wrote:
> >> # HG changeset patch
> >> # User Matt Harbison <matt_harbison@yahoo.com>
> >> # Date 1500266969 14400
> >> #      Mon Jul 17 00:49:29 2017 -0400
> >> # Node ID a85b7c754630cb4ac49b2cebea0ceca3d2f2eaaa
> >> # Parent  4d37def90ad5e0196dadb9bc2c9e62effad63691
> >> archive: add an experimental config to control the metadata file  
> >> template
> >>
> >> Experimental because given the possible complexity, it may be worth  
> >> figuring out
> >> how to load this from a file, similar to the style files for the log  
> >> command,
> >> instead of trying to stuff it on the command line.
> >
> > Maybe we'll want to save it in [templates] section, and specify it in a  
> > similar
> > way to -T option?
> 
> Yes.  I didn't realize [templates] could hold a filename like that.  I'll  
> follow up next cycle.

No, [templates] can't be external files. I meant it could be a template stock
for archive.

  [templates]
  foo = "archived {node|short}\n"

  $ hg archive -T-like-option foo
Yuya Nishihara - July 18, 2017, 12:35 p.m.
On Mon, 17 Jul 2017 21:29:15 -0700, Martin von Zweigbergk wrote:
> On Mon, Jul 17, 2017 at 8:29 PM, Matt Harbison <mharbison72@gmail.com> wrote:
> > On Mon, 17 Jul 2017 13:54:29 -0400, Martin von Zweigbergk
> > <martinvonz@google.com> wrote:
> >> On Sun, Jul 16, 2017 at 9:57 PM, Matt Harbison <mharbison72@gmail.com>
> >> wrote:
> >>> # HG changeset patch
> >>> # User Matt Harbison <matt_harbison@yahoo.com>
> >>> # Date 1500266969 14400
> >>> #      Mon Jul 17 00:49:29 2017 -0400
> >>> # Node ID a85b7c754630cb4ac49b2cebea0ceca3d2f2eaaa
> >>> # Parent  4d37def90ad5e0196dadb9bc2c9e62effad63691
> >>> archive: add an experimental config to control the metadata file template
> >>>
> >>> Experimental because given the possible complexity, it may be worth
> >>> figuring out
> >>> how to load this from a file, similar to the style files for the log
> >>> command,
> >>> instead of trying to stuff it on the command line.
> >>>
> >>> diff --git a/mercurial/archival.py b/mercurial/archival.py
> >>> --- a/mercurial/archival.py
> >>> +++ b/mercurial/archival.py
> >>> @@ -99,7 +99,8 @@
> >>>      )
> >>>
> >>>      opts = {
> >>> -        'template': default
> >>> +        'template': repo.ui.config('experimental',
> >>> 'archivemetatemplate',
> >>> +                                   default)
> >>
> >>
> >> I think this should be registered with the new coreconfigitem() method
> >> (other experimental options are).
> >
> >
> > I actually started out that way, but given how cryptic the default value is,
> > I wasn't sure it was a good idea.
> 
> You mean because the it's nice to have the default value close to the
> code that uses it? Yeah, I've felt that too.
> 
> > I've only been skimming the configitem
> > patches, but I could see maybe adding the registered default to the help
> > text automatically.  I don't think we want to display this one for
> > simplicity.  I also didn't see anything nearly this complex.
> 
> You could perhaps use (abuse?) the "dynamicdefault" for this.

Perhaps the default should be None or '', and use the default template if
config value is empty. formatter(..., {'template': ''}) wouldn't do what
you want.

Patch

diff --git a/mercurial/archival.py b/mercurial/archival.py
--- a/mercurial/archival.py
+++ b/mercurial/archival.py
@@ -99,7 +99,8 @@ 
     )
 
     opts = {
-        'template': default
+        'template': repo.ui.config('experimental', 'archivemetatemplate',
+                                   default)
     }
 
     out = util.stringio()
diff --git a/tests/test-subrepo-deep-nested-change.t b/tests/test-subrepo-deep-nested-change.t
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -263,6 +263,12 @@ 
   $ hg update -Cq .
   $ rm -r ../wdir
 
+  $ hg archive -S -qr 'wdir()' ../wdir \
+  >            --config 'experimental.archivemetatemplate=archived {node|short}\n'
+  $ cat ../wdir/.hg_archival.txt
+  archived ffffffffffff
+  $ rm -r ../wdir
+
 .. but first take a detour through some deep removal testing
 
   $ hg remove -S -I 're:.*.txt' .