[PATCH stable] subrepo: fix cloning of repos from urls without slash after host (issue2970)

Brodie Rao brodie at bitheap.org
Fri Aug 26 15:29:54 CDT 2011


On Fri, Aug 26, 2011 at 7:24 AM, Mads Kiilerich <mads at kiilerich.com> wrote:
> # HG changeset patch
> # User Mads Kiilerich <mads at kiilerich.com>
> # Date 1314368615 -7200
> # Branch stable
> # Node ID d629f1e89021103f1753addcef6b310e4435b184
> # Parent  17ffb30d917475050c3d27c9e058d76629903647
> subrepo: fix cloning of repos from urls without slash after host (issue2970)
>
> This fixes a regression introduced with the new url handling in 1.9.
>
> This should perhaps be fixed in the url class instead, but that might be too
> invasive for a stable bugfix.

I think this fix is good enough to put in right away as is.

After grepping around for url.path usage, I noticed the following:

- When hgwebdir_mod sets SCRIPT_NAME based on web.baseurl, it could
run into this same issue, but it already does the path-or-empty-string
thing.

- The only place I see that actually checks if url.path is None is in
sshrepository.__init__(). If it sees that it's None, it aborts saying
it couldn't parse the URL (among other checks).

If we change url.path so it's '' when a path isn't present in the URL,
sshrepository will start allowing URLs like "ssh://foo", and it'll
interpret them in the same way as "ssh://foo/" -- it'll be interpreted
as the current working directory after SSHing into the server.

> diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
> --- a/mercurial/subrepo.py
> +++ b/mercurial/subrepo.py
> @@ -204,7 +204,7 @@
>         parent = _abssource(repo._subparent, push, abort=False)
>         if parent:
>             parent = util.url(parent)
> -            parent.path = posixpath.join(parent.path, source.path)
> +            parent.path = posixpath.join(parent.path or '', source.path)
>             parent.path = posixpath.normpath(parent.path)
>             return str(parent)
>     else: # recursion reached top repo
> diff --git a/tests/test-http.t b/tests/test-http.t
> --- a/tests/test-http.t
> +++ b/tests/test-http.t
> @@ -159,6 +159,32 @@
>
>   $ cd ..
>
> +clone of serve with repo in root and unserved subrepo (issue2970)
> +
> +  $ hg --cwd test init sub
> +  $ hg --cwd test/sub tag something
> +  $ echo sub = sub > test/.hgsub
> +  $ hg --cwd test add .hgsub
> +  $ hg --cwd test commit -qm 'add subrepo'
> +  $ hg clone http://localhost:$HGPORT noslash-clone
> +  requesting all changes
> +  adding changesets
> +  adding manifests
> +  adding file changes
> +  added 3 changesets with 7 changes to 7 files
> +  updating to branch default
> +  abort: HTTP Error 404: Not Found
> +  [255]
> +  $ hg clone http://localhost:$HGPORT/ slash-clone
> +  requesting all changes
> +  adding changesets
> +  adding manifests
> +  adding file changes
> +  added 3 changesets with 7 changes to 7 files
> +  updating to branch default
> +  abort: HTTP Error 404: Not Found
> +  [255]
> +
>  check error log
>
>   $ cat error.log
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>


More information about the Mercurial-devel mailing list