[PATCH] url: use open and not url.open for local files (issue3624)
Mads Kiilerich
mads at kiilerich.com
Wed Oct 31 00:38:57 UTC 2012
Siddharth Agarwal wrote, On 10/31/2012 12:59 AM:
> # HG changeset patch
> # User Siddharth Agarwal <sid0 at fb.com>
> # Date 1350534608 25200
> # Node ID ab050e67b95e3cb38d1c941e6232560fa0c785fe
> # Parent 917a37b76845811aaea1dc9b1ad0a8110e8b7439
> url: use open and not url.open for local files (issue3624)
>
> Suggestions on how to test this would be nice.
You could create an extension that monkey patches the Python url / mime
modules in such a way that they will explode if they are used. But the
nature of this patch is probably such that it is ok not to include an
automatic test.
> diff -r 917a37b76845 -r ab050e67b95e contrib/synthrepo.py
> --- a/contrib/synthrepo.py Tue Oct 23 09:28:42 2012 +0200
> +++ b/contrib/synthrepo.py Wed Oct 17 21:30:08 2012 -0700
> @@ -36,7 +36,7 @@
> '''
>
> import bisect, collections, json, os, random, time
> -from mercurial import cmdutil, context, patch, scmutil, url, util
> +from mercurial import cmdutil, context, patch, scmutil, url, util, hg
> from mercurial.i18n import _
> from mercurial.node import nullrev, nullid
>
> @@ -224,7 +224,7 @@
> path to an alternate dictionary to use.
> '''
> try:
> - fp = url.open(ui, descpath)
> + fp = hg.openpath(ui, descpath)
This will leave the url module unused - it should no longer be imported
here. test-check-pyflakes.t should have caught that.
The same problem might be in other modules.
> --- a/hgext/schemes.py Tue Oct 23 09:28:42 2012 +0200
> +++ b/hgext/schemes.py Wed Oct 17 21:30:08 2012 -0700
> @@ -41,7 +41,7 @@
> """
>
> import os, re
> -from mercurial import extensions, hg, templater, util
> +from mercurial import cmdutil, extensions, hg, templater, util
> from mercurial.i18n import _
>
> testedwith = 'internal'
- especially this one.
> diff -r 917a37b76845 -r ab050e67b95e mercurial/hg.py
> --- a/mercurial/hg.py Tue Oct 23 09:28:42 2012 +0200
> +++ b/mercurial/hg.py Wed Oct 17 21:30:08 2012 -0700
> @@ -10,7 +10,7 @@
> from lock import release
> from node import hex, nullid
> import localrepo, bundlerepo, httppeer, sshpeer, statichttprepo, bookmarks
> -import lock, util, extensions, error, node, scmutil, phases
> +import lock, util, extensions, error, node, scmutil, phases, url
> import cmdutil, discovery
> import merge as mergemod
> import verify as verifymod
> @@ -89,6 +89,13 @@
> return False
> return repo.local()
>
> +def openpath(ui, path, *args, **kwargs):
> + '''open path with open if local, url.open if remote'''
> + if islocal(path):
> + return open(util.urllocalpath(path))
> + else:
> + return url.open(ui, path, *args, **kwargs)
(This doesn't look right. Someone should comment on it.)
/Mads
More information about the Mercurial-devel
mailing list