Benoit Boissinot avatar Benoit Boissinot committed 8046f0a

use our urlopener (proxy handling, etc) instead of urllib

Comments (0)

Files changed (5)

 from mercurial.node import bin, hex, short
 from mercurial.repo import RepoError
 from mercurial import commands, cmdutil, hg, patch, revlog, util
-from mercurial import repair, extensions
-import os, sys, re, errno, urllib
+from mercurial import repair, extensions, url
+import os, sys, re, errno
 
 commands.norepo += " qclone"
 
                             raise util.Abort(_('need --name to import a patch from -'))
                         text = sys.stdin.read()
                     else:
-                        if os.path.exists(filename):
-                            text = file(filename, 'rb').read()
-                        else:
-                            text = urllib.urlopen(filename).read()
+                        text = url.open(self.ui, filename).read()
                 except IOError:
                     raise util.Abort(_("unable to read %s") % filename)
                 if not patchname:

mercurial/commands.py

 from node import hex, nullid, nullrev, short
 from repo import RepoError, NoCapability
 from i18n import _, gettext
-import os, re, sys, urllib
+import os, re, sys
 import hg, util, revlog, bundlerepo, extensions, copies
 import difflib, patch, time, help, mdiff, tempfile, url
 import version, socket
 
             if pf == '-':
                 ui.status(_("applying patch from stdin\n"))
-                data = patch.extract(ui, sys.stdin)
+                pf = sys.stdin
             else:
                 ui.status(_("applying %s\n") % p)
-                if os.path.exists(pf):
-                    data = patch.extract(ui, file(pf, 'rb'))
-                else:
-                    data = patch.extract(ui, urllib.urlopen(pf))
+                pf = url.open(ui, pf)
+            data = patch.extract(ui, pf)
             tmpname, message, user, date, branch, nodeid, p1, p2 = data
 
             if tmpname is None:
     try:
         lock = repo.lock()
         for fname in fnames:
-            if os.path.exists(fname):
-                f = open(fname, "rb")
-            else:
-                f = urllib.urlopen(fname)
+            f = url.open(ui, fname)
             gen = changegroup.readbundle(f, fname)
             modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname)
     finally:
Add a comment to this file

tests/test-convert-darcs

File contents unchanged.

tests/test-mq-qimport

 cd repo
 
 echo % qimport non-existing-file
-hg qimport non-existing-file
+hg qimport non-existing-file 2>&1 | sed -e 's/\(No such file or directory:\) .*/\1/'
 
 echo % import URL
 echo foo >> foo

tests/test-mq-qimport.out

 % qimport non-existing-file
-abort: unable to read non-existing-file
+abort: No such file or directory:
 % import URL
 adding url.diff to series file
 url.diff
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.