Submitter | Jordi Gutiérrez Hermoso |
---|---|
Date | Aug. 13, 2014, 9:14 p.m. |
Message ID | <f9690691301dd804ccc0.1407964492@Iris> |
Download | mbox | patch |
Permalink | /patch/5374/ |
State | Superseded |
Commit | f58b41f6708b5bb5ff43ad7f71881f5b116b2a4b |
Headers | show |
Comments
On 08/13/2014 02:14 PM, Jordi Gutiérrez Hermoso wrote: > # HG changeset patch > # User Jordi Gutiérrez Hermoso <jordigh@octave.org> > # Date 1407963948 14400 > # Wed Aug 13 17:05:48 2014 -0400 > # Node ID f9690691301dd804ccc03d0787112c3e18cb9226 > # Parent e125a4ec265f9207667e82a62754dfd96f17c0a4 > config: give more fine-tuned sample hgrcs to this command > > The hgrc for user config is typically different from the hgrc at the > system-wide or repository level. This patch provides different sample > hgrcs for each level. Sometimes when copying repos around, the copy or > the original don't have a default path yet, so at least for `hg config > -l`, this ought to provide a more reasonable default and suggestions > of what typically goes there. I love the idea. The patch itself needs some rework: 1) you should extract the dictionnary into a module level command (can even be moved in config). Having the dictionnary in the body of the function makes it hard to read (because of the indent) and inflate the body of the function too much. Another option would be to have them as example file as we do for style. I prefers the dictionnary idea as it let extension to play with its content. 2) You should introduce each new config option in a separated patch so they can be discussed independently. > > diff --git a/mercurial/commands.py b/mercurial/commands.py > --- a/mercurial/commands.py > +++ b/mercurial/commands.py > @@ -1520,10 +1520,9 @@ def config(ui, repo, *values, **opts): > if os.path.exists(f): > break > else: > - f = paths[0] > - fp = open(f, "w") > - fp.write( > - '# example config (see "hg help config" for more info)\n' > + samplehgrcs = { > + 'user': > + '# example user config (see "hg help config" for more info)\n' > '\n' > '[ui]\n' > '# name and email, e.g.\n' > @@ -1535,7 +1534,41 @@ def config(ui, repo, *values, **opts): > '# (see "hg help extensions" for more info)\n' > '# pager =\n' > '# progress =\n' > - '# color =\n') > + '# color =\n', > + > + 'local': > + '# example repository config (see "hg help config" for ' > + 'more info)\n' > + '\n' > + '[paths]\n' > + '# Path aliases to other clones of this repo in external ' > + 'URLs or filesystem paths,\n' > + '\n' > + '# default = http://example.com/hg/example-repo\n' > + '# myfork = ssh://jdoe@example.net/hg/jdoes-fork\n' > + '# myclone = /home/jdoe/jdoes-clone\n', Maybe adding a hit about default-push. not sur about the myfork and my clone things. > + > + 'global': > + '# example system-wide hg config (see "hg help config" for ' > + 'more info)\n' > + '\n' > + '[extensions]\n' > + '# Uncomment these lines for some popular extensions\n' > + '# inotify =\n' > + '# win32mbcs =\n' > + '# win32text =\n', > + } inotify is a DEPRECATED extension with no code in it. how can it be a popular extension? > + > + if opts.get('global'): > + samplehgrc = samplehgrcs['global'] > + elif opts.get('local'): > + samplehgrc = samplehgrcs['local'] > + else: > + samplehgrc = samplehgrcs['user'] > + > + f = paths[0] > + fp = open(f, "w") > + fp.write(samplehgrc) > fp.close() > > editor = ui.geteditor() > _______________________________________________ > Mercurial-devel mailing list > Mercurial-devel@selenic.com > http://selenic.com/mailman/listinfo/mercurial-devel >
On Wed, 2014-08-13 at 17:14 -0400, Jordi Gutiérrez Hermoso wrote: > # HG changeset patch > # User Jordi Gutiérrez Hermoso <jordigh@octave.org> > # Date 1407963948 14400 > # Wed Aug 13 17:05:48 2014 -0400 > # Node ID f9690691301dd804ccc03d0787112c3e18cb9226 > # Parent e125a4ec265f9207667e82a62754dfd96f17c0a4 > config: give more fine-tuned sample hgrcs to this command > + '# inotify =\n' A fascinating way to get your patch rejected: sneak in a suggestion to enable a now-non-existent extension that we've been telling people not to use for years. I suggest you start by simply duplicating the config three times, that will be uncontroversial. Then make your changes incrementally from that point on.
Patch
diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1520,10 +1520,9 @@ def config(ui, repo, *values, **opts): if os.path.exists(f): break else: - f = paths[0] - fp = open(f, "w") - fp.write( - '# example config (see "hg help config" for more info)\n' + samplehgrcs = { + 'user': + '# example user config (see "hg help config" for more info)\n' '\n' '[ui]\n' '# name and email, e.g.\n' @@ -1535,7 +1534,41 @@ def config(ui, repo, *values, **opts): '# (see "hg help extensions" for more info)\n' '# pager =\n' '# progress =\n' - '# color =\n') + '# color =\n', + + 'local': + '# example repository config (see "hg help config" for ' + 'more info)\n' + '\n' + '[paths]\n' + '# Path aliases to other clones of this repo in external ' + 'URLs or filesystem paths,\n' + '\n' + '# default = http://example.com/hg/example-repo\n' + '# myfork = ssh://jdoe@example.net/hg/jdoes-fork\n' + '# myclone = /home/jdoe/jdoes-clone\n', + + 'global': + '# example system-wide hg config (see "hg help config" for ' + 'more info)\n' + '\n' + '[extensions]\n' + '# Uncomment these lines for some popular extensions\n' + '# inotify =\n' + '# win32mbcs =\n' + '# win32text =\n', + } + + if opts.get('global'): + samplehgrc = samplehgrcs['global'] + elif opts.get('local'): + samplehgrc = samplehgrcs['local'] + else: + samplehgrc = samplehgrcs['user'] + + f = paths[0] + fp = open(f, "w") + fp.write(samplehgrc) fp.close() editor = ui.geteditor()