[PATCH 2 of 2 V3] config: use the same hgrc for a cloned repo as for an uninitted repo

Jordi Gutiérrez Hermoso jordigh at octave.org
Wed Oct 8 16:42:02 CDT 2014


# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh at octave.org>
# Date 1412627702 14400
#      Mon Oct 06 16:35:02 2014 -0400
# Node ID ac56ac72a4f34fc8ceef9d2b300e96028bf5feff
# Parent  8b24e30d30e8f9b95ef1284da81746a1f3e0ee64
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.

I also add ui as an import to hg.py, but with demandimport, this
should not be a noticeable performance hit.

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -9,9 +9,10 @@
 from i18n import _
 from lock import release
 from node import nullid
+
 import localrepo, bundlerepo, unionrepo, httppeer, sshpeer, statichttprepo
 import bookmarks, lock, util, extensions, error, node, scmutil, phases, url
-import cmdutil, discovery, repoview, exchange
+import cmdutil, discovery, repoview, exchange, ui
 import merge as mergemod
 import verify as verifymod
 import errno, os, shutil
@@ -422,18 +423,7 @@ 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 at example.com>\n'
-                '[paths]\n'
-                'default = %s\n'
-                )
+            template = ui.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 at example.com>
+""",
+
     'local':
 """# example repository config (see "hg help config" for more info)
 [paths]


More information about the Mercurial-devel mailing list