Patchwork [2,of,2,V2] config: use the same hgrc for a cloned repo as for an uninitted repo

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date Oct. 6, 2014, 8:41 p.m.
Message ID <d14bc6947adc7229ae46.1412628090@Iris>
Download mbox | patch
Permalink /patch/6149/
State Superseded
Commit 2be7d5ebd4d0552493ce18c509686286ee712010
Headers show

Comments

Jordi Gutiérrez Hermoso - Oct. 6, 2014, 8:41 p.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1412627702 14400
#      Mon Oct 06 16:35:02 2014 -0400
# Node ID d14bc6947adc7229ae464bdb67ff79f2e10f04c2
# Parent  eaf28cae9dedb26c7a78a371b7435589a1482cf3
config: use the same hgrc for a cloned repo as for an uninitted repo

This just copies the same local sample hgrc, except it sets the
default path to the repo it was cloned from.

This is cut-and-paste from the local sample hgrc, but I think it's
acceptable, since the two pieces of code are right next to each other
and they're small. There is danger of them going out of synch, but it
would complicate the code too much to get rid of this C&P.
Augie Fackler - Oct. 7, 2014, 4:40 p.m.
On Mon, Oct 06, 2014 at 04:41:30PM -0400, Jordi Gutiérrez Hermoso wrote:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso <jordigh@octave.org>
> # Date 1412627702 14400
> #      Mon Oct 06 16:35:02 2014 -0400
> # Node ID d14bc6947adc7229ae464bdb67ff79f2e10f04c2
> # Parent  eaf28cae9dedb26c7a78a371b7435589a1482cf3
> config: use the same hgrc for a cloned repo as for an uninitted repo

Overall series LG, a nitpick below.

>
> This just copies the same local sample hgrc, except it sets the
> default path to the repo it was cloned from.
>
> This is cut-and-paste from the local sample hgrc, but I think it's
> acceptable, since the two pieces of code are right next to each other
> and they're small. There is danger of them going out of synch, but it
> would complicate the code too much to get rid of this C&P.
>
> diff --git a/mercurial/hg.py b/mercurial/hg.py
> --- a/mercurial/hg.py
> +++ b/mercurial/hg.py
> @@ -422,18 +422,8 @@ def clone(ui, peeropts, source, dest=Non
>
>          destrepo = destpeer.local()
>          if destrepo:
> -            template = (
> -                '# You may want to set your username here if it is not set\n'
> -                "# globally, or this repository requires a different\n"
> -                '# username from your usual configuration. If you want to\n'
> -                '# set something for all of your repositories on this\n'
> -                '# computer, try running the command\n'
> -                "# 'hg config --edit --global'\n"
> -                '# [ui]\n'
> -                '# username = Jane Doe <jdoe@example.com>\n'
> -                '[paths]\n'
> -                'default = %s\n'
> -                )
> +            from ui import samplehgrcs

Can you do 'import ui' up top, then...

> +            template = samplehgrcs['cloned']

...reference this as ui.samplehgrcs?

hg doesn't import ui, nor does ui import hg (at least not directly),
so the top-level import would be a little more sane and would let
demandimport do the right thing.

>              fp = destrepo.opener("hgrc", "w", text=True)
>              u = util.url(abspath)
>              u.passwd = None
> diff --git a/mercurial/ui.py b/mercurial/ui.py
> --- a/mercurial/ui.py
> +++ b/mercurial/ui.py
> @@ -26,6 +26,23 @@ username =
>  # progress =
>  # color =""",
>
> +    'cloned':
> +"""# example repository config (see "hg help config" for more info)
> +[paths]
> +default = %s
> +
> +# path aliases to other clones of this repo in URLs or filesystem paths
> +# (see "hg help config.paths" for more info)
> +#
> +# default-push = ssh://jdoe@example.net/hg/jdoes-fork
> +# my-fork      = ssh://jdoe@example.net/hg/jdoes-fork
> +# my-clone     = /home/jdoe/jdoes-clone
> +
> +[ui]
> +# name and email (local to this repository, optional), e.g.
> +# username = Jane Doe <jdoe@example.com>
> +""",
> +
>      'local':
>  """# example repository config (see "hg help config" for more info)
>  [paths]
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -422,18 +422,8 @@  def clone(ui, peeropts, source, dest=Non
 
         destrepo = destpeer.local()
         if destrepo:
-            template = (
-                '# You may want to set your username here if it is not set\n'
-                "# globally, or this repository requires a different\n"
-                '# username from your usual configuration. If you want to\n'
-                '# set something for all of your repositories on this\n'
-                '# computer, try running the command\n'
-                "# 'hg config --edit --global'\n"
-                '# [ui]\n'
-                '# username = Jane Doe <jdoe@example.com>\n'
-                '[paths]\n'
-                'default = %s\n'
-                )
+            from ui import samplehgrcs
+            template = samplehgrcs['cloned']
             fp = destrepo.opener("hgrc", "w", text=True)
             u = util.url(abspath)
             u.passwd = None
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -26,6 +26,23 @@  username =
 # progress =
 # color =""",
 
+    'cloned':
+"""# example repository config (see "hg help config" for more info)
+[paths]
+default = %s
+
+# path aliases to other clones of this repo in URLs or filesystem paths
+# (see "hg help config.paths" for more info)
+#
+# default-push = ssh://jdoe@example.net/hg/jdoes-fork
+# my-fork      = ssh://jdoe@example.net/hg/jdoes-fork
+# my-clone     = /home/jdoe/jdoes-clone
+
+[ui]
+# name and email (local to this repository, optional), e.g.
+# username = Jane Doe <jdoe@example.com>
+""",
+
     'local':
 """# example repository config (see "hg help config" for more info)
 [paths]