[PATCH 1 of 2] hg: share supports subrepos (issue3518)

Matt Harbison matt_harbison at yahoo.com
Thu Nov 8 21:38:33 CST 2012


Simon Heimberg <simohe <at> besonet.ch> writes:

> 
> # HG changeset patch
> # User simon <at> laptop-tosh
> # Date 1351334339 -7200
> # Branch stable
> # Node ID 7425c0c92b2ee79e4e9271c3307d44290bc0977b
> # Parent  fac6d36d04cb1838cd10bdcecd487567787fb853
> hg: share supports subrepos (issue3518)
> 
> set the default path in any case because creating subrepo looks this up.
> Subrepos are cloned, not shared.

I just started playing with share myself so this may be a naive question, but
wouldn't it be better to share the subrepos too instead of cloning them?
Subrepos seem to hinge on the working directory in order to update them, which
is what share provides a distinct copy of.  (I realize your changes just enable
its existing desire to clone to work, but maybe sharing would be more in line
with user expectation?)

> diff -r fac6d36d04cb -r 7425c0c92b2e mercurial/hg.py
> --- a/mercurial/hg.py	Don Nov 01 16:09:21 2012 -0500
> +++ b/mercurial/hg.py	Sam Okt 27 12:38:59 2012 +0200
> @@ -171,11 +171,14 @@
>      r = repository(ui, root)
> 
>      default = srcrepo.ui.config('paths', 'default')
> -    if default:
> -        fp = r.opener("hgrc", "w", text=True)
> -        fp.write("[paths]\n")
> -        fp.write("default = %s\n" % default)
> -        fp.close()
> +    if not default:
> +        # set default to source for being able to clone subrepos
> +        default = os.path.abspath(util.urllocalpath(origsource))
> +    fp = r.opener("hgrc", "w", text=True)
> +    fp.write("[paths]\n")
> +    fp.write("default = %s\n" % default)
> +    fp.close()
> +    r.ui.setconfig('paths', 'default', default)

With this unconditional creation of hgrc in the share dest, it ends up with
sharedpath redirecting commits to the parent, and 'hg push' wanting to
essentially push from the parent, to the parent.  This results in the cryptic
lock message [1].

It looks like writing the file conditionally like it was, but the
r.ui.setconfig unconditionally works (assuming clone is the way to go).  Like
so:

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -176,6 +176,10 @@
         fp.write("[paths]\n")
         fp.write("default = %s\n" % default)
         fp.close()
+        r.ui.setconfig('paths', 'default', default)
+    else:
+        r.ui.setconfig('paths', 'default',
+                       os.path.abspath(util.urllocalpath(origsource)))

     if update:
         r.ui.status(_("updating working directory\n"))

I didn't try committing things to the subrepo in the share and pushing back to
the original, or messing around with repos that already had a default path set,
so there could be issues with this.

--Matt

[1] http://bz.selenic.com/show_bug.cgi?id=3657






More information about the Mercurial-devel mailing list