mq: strip all leading slashes from url when importing
authorIdan Kamara <idankk86@gmail.com>
Fri, 20 May 2011 21:20:24 +0300
changeset 14396 170747a3e139
parent 14395 dc961471efde
child 14397 0368ad7963be
mq: strip all leading slashes from url when importing When trying to import a url that ends with a slash os.path.basename() would return an empty string. So when seeing a leading slash, remove it and infer the patch name from the remaining url. e.g. `hg qimport http://paste.pocoo.org/raw/xxx/` deduced '.' to be the patch name. Now we'll deduce 'xxx'.
hgext/mq.py
tests/test-mq-qimport.t
--- a/hgext/mq.py	Fri May 20 21:19:33 2011 +0300
+++ b/hgext/mq.py	Fri May 20 21:20:24 2011 +0300
@@ -1832,7 +1832,7 @@
                 if filename == '-' and not patchname:
                     raise util.Abort(_('need --name to import a patch from -'))
                 elif not patchname:
-                    patchname = normname(os.path.basename(filename))
+                    patchname = normname(os.path.basename(filename.rstrip('/')))
                 self.check_reserved_name(patchname)
                 checkfile(patchname)
                 try:
--- a/tests/test-mq-qimport.t	Fri May 20 21:19:33 2011 +0300
+++ b/tests/test-mq-qimport.t	Fri May 20 21:20:24 2011 +0300
@@ -208,3 +208,20 @@
   $ hg qimport non-existant-file --name .hg
   abort: patch name cannot begin with ".hg"
   [255]
+
+qimport http:// patch with leading slashes in url
+
+set up hgweb
+
+  $ cd ..
+  $ hg init served
+  $ cd served
+  $ echo a > a
+  $ hg ci -Am patch
+  adding a
+  $ hg serve -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log
+  $ cat hg.pid >> $DAEMON_PIDS
+
+  $ cd ../repo
+  $ hg qimport http://localhost:$HGPORT/raw-rev/0///
+  adding 0 to series file