mq: let qimport read patches from URLs
authorBrendan Cully <brendan@kublai.com>
Sat, 18 Oct 2008 16:40:01 -0700
changeset 7158 d1d011accf94
parent 7157 fd3cba5e73ae
child 7159 a634e0065295
mq: let qimport read patches from URLs
hgext/mq.py
tests/test-mq-qimport
tests/test-mq-qimport.out
--- a/hgext/mq.py	Sat Oct 18 16:33:10 2008 -0700
+++ b/hgext/mq.py	Sat Oct 18 16:40:01 2008 -0700
@@ -34,7 +34,7 @@
 from mercurial.repo import RepoError
 from mercurial import commands, cmdutil, hg, patch, revlog, util
 from mercurial import repair
-import os, sys, re, errno
+import os, sys, re, errno, urllib
 
 commands.norepo += " qclone"
 
@@ -1499,7 +1499,10 @@
                             raise util.Abort(_('need --name to import a patch from -'))
                         text = sys.stdin.read()
                     else:
-                        text = file(filename, 'rb').read()
+                        if os.path.exists(filename):
+                            text = file(filename, 'rb').read()
+                        else:
+                            text = urllib.urlopen(filename).read()
                 except IOError:
                     raise util.Abort(_("unable to read %s") % filename)
                 if not patchname:
--- a/tests/test-mq-qimport	Sat Oct 18 16:33:10 2008 -0700
+++ b/tests/test-mq-qimport	Sat Oct 18 16:40:01 2008 -0700
@@ -27,6 +27,15 @@
 echo % qimport non-existing-file
 hg qimport non-existing-file
 
+echo % import URL
+echo foo >> foo
+hg add foo
+hg diff > $HGTMP/url.diff
+hg revert --no-backup foo
+rm foo
+hg qimport file://$HGTMP/url.diff
+hg qun
+
 echo % build diff with CRLF
 python ../writelines.py b 5 'a\n' 5 'a\r\n'
 hg ci -Am addb
--- a/tests/test-mq-qimport.out	Sat Oct 18 16:33:10 2008 -0700
+++ b/tests/test-mq-qimport.out	Sat Oct 18 16:40:01 2008 -0700
@@ -1,5 +1,8 @@
 % qimport non-existing-file
 abort: unable to read non-existing-file
+% import URL
+adding url.diff to series file
+url.diff
 % build diff with CRLF
 adding b
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved