diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -33,8 +33,8 @@ from mercurial.i18n import _ 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" @@ -1521,10 +1521,7 @@ class queue: 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: diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -8,7 +8,7 @@ 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 @@ -1590,13 +1590,11 @@ def import_(ui, repo, patch1, *patches, 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: @@ -2844,10 +2842,7 @@ def unbundle(ui, repo, fname1, *fnames, 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: diff --git a/tests/test-convert-darcs b/tests/test-convert-darcs old mode 100755 new mode 100644 diff --git a/tests/test-mq-qimport b/tests/test-mq-qimport --- a/tests/test-mq-qimport +++ b/tests/test-mq-qimport @@ -25,7 +25,7 @@ hg init repo 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 diff --git a/tests/test-mq-qimport.out b/tests/test-mq-qimport.out --- a/tests/test-mq-qimport.out +++ b/tests/test-mq-qimport.out @@ -1,5 +1,5 @@ % 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