[PATCH 2 of 2 V2] 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 07:25:45 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 d75f6ad947765f5fc7fea941471e6a925a9ab716
# Parent  2a2916633196c7fb29ae667cbdbe86c67bbc5593
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)
+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
+# name and email (local to this repository, optional), e.g.
+# username = Jane Doe <jdoe at example.com>
 """# example repository config (see "hg help config" for more info)

More information about the Mercurial-devel mailing list