[PATCH] subrepo: allow remapping subpaths using the "final" path
Matt Mackall
mpm at selenic.com
Wed Aug 10 11:39:46 CDT 2011
On Wed, 2011-08-10 at 16:59 +0200, Martin Geisler wrote:
> # HG changeset patch
> # User Martin Geisler <mg at aragost.com>
> # Date 1312988370 -7200
> # Node ID 4cfdb06e702888cbd4cbe97cf0aec0cb01368456
> # Parent 0cb27eda3a1e0ea47a9a0bd5d44f5d21ec4509e1
> subrepo: allow remapping subpaths using the "final" path
>
> The way subpath remapping happens now, the right-hand side of a .hgsub
> entry is used, as is, to match the left-hand side of a subpaths entry.
> The new idea is to expand the .hgsub entry by prefixing the parent
> repo path *before* the match occurs - i.e. to operate on the final
> path including the parent. For example,
>
> .hgsub entry: src/foo = src/foo
> parent repo path: http://example.net/parent
> expansion: http://example.net/parent/src/foo
Ok, so before we'd try remapping src/foo, now with this option enabled,
we'll try remapping the whole URL.
Seems to me that it should be sufficiently safe to try both and avoid a
confusing new option.
> The rewriting proceeds like normal on the expanded path. The advantage
> of this is more context is available for the rewriting when the
> recommended trivial subrepo paths are used in the .hgsub file.
>
> A new option named ui.subpaths-remapping controls this. It has two
> values so far:
>
> * "use-intermediate-path", which is the old behavior that applies the
> remapping rules before the expansion with the parent path occurs.
> This is the default.
>
> * "use-final-path", which triggers the new behavior.
Eek! It's bad enough that we can't choose between 'foobar' and 'foo_bar'
naming. Also, this should probably just be a bool.
> diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
> --- a/mercurial/help/config.txt
> +++ b/mercurial/help/config.txt
> @@ -1080,6 +1080,17 @@
> ``style``
> Name of style to use for command output.
>
> +``subpaths-remaping``
> + Controls remapping of relative subrepository paths as per the
> + ``[subpaths]`` section. Relative paths are turned into absolute
> + paths, this setting controls if the rewrite rules are applied
> + before or after this expansion.
> +
> + Set to ``use-intermediate-path`` to apply the remapping rules
> + before the expansion with the parent path occurs. This is the
> + default. Set it to ``use-final-path`` to rewrite the final expaned
> + path.
> +
> ``timeout``
> The timeout used when a lock is held (in seconds), a negative value
> means no timeout. Default is 600.
> diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
> --- a/mercurial/subrepo.py
> +++ b/mercurial/subrepo.py
> @@ -59,6 +59,12 @@
> kind, src = src.split(']', 1)
> kind = kind[1:]
>
> + if ui.config('ui', 'subpaths-remapping') == 'use-final-path':
> + if not util.url(src).isabs():
> + parent = _abssource(ctx._repo, abort=False)
> + if parent:
> + src = posixpath.join(parent, src)
> +
> for pattern, repl in p.items('subpaths'):
> # Turn r'C:\foo\bar' into r'C:\\foo\\bar' since re.sub
> # does a string decode.
> diff --git a/tests/test-subrepo-paths.t b/tests/test-subrepo-paths.t
> --- a/tests/test-subrepo-paths.t
> +++ b/tests/test-subrepo-paths.t
> @@ -1,23 +1,28 @@
> $ hg init outer
> $ cd outer
>
> + $ echo '[paths]' >> .hg/hgrc
> + $ echo 'default = http://example.net/' >> .hg/hgrc
> + $ echo '[ui]' >> .hg/hgrc
> + $ echo 'subpaths-remapping = use-final-path' >> .hg/hgrc
> +
> hg debugsub with no remapping
>
> - $ echo 'sub = http://example.net/libfoo' > .hgsub
> + $ echo 'libfoo = libfoo' > .hgsub
> $ hg add .hgsub
>
> $ hg debugsub
> - path sub
> + path libfoo
> source http://example.net/libfoo
> revision
>
> hg debugsub with remapping
>
> - $ echo '[subpaths]' > .hg/hgrc
> + $ echo '[subpaths]' >> .hg/hgrc
> $ printf 'http://example.net/lib(.*) = C:\\libs\\\\1-lib\\\n' >> .hg/hgrc
>
> $ hg debugsub
> - path sub
> + path libfoo
> source C:\libs\foo-lib\
> revision
>
> @@ -26,10 +31,25 @@
> $ echo '[subpaths]' >> $HGRCPATH
> $ echo 'libfoo = libbar' >> $HGRCPATH
> $ hg debugsub
> - path sub
> + path libfoo
> source C:\libs\bar-lib\
> revision
>
> +test absolute source path -- testing with a URL is important since
> +standard os.path.join wont treat that as an absolute path
> +
> + $ echo 'abs = http://example.net/abs' > .hgsub
> + $ hg debugsub
> + path abs
> + source http://example.net/abs
> + revision
> +
> + $ echo 'abs = /abs' > .hgsub
> + $ hg debugsub
> + path abs
> + source /abs
> + revision
> +
> test bad subpaths pattern
>
> $ cat > .hg/hgrc <<EOF
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list