diff mercurial/exchange.py @ 28977:740156eedf2c stable 3.8-rc

merge default into stable for 3.8 code freeze
author Matt Mackall <mpm@selenic.com>
date Sat, 16 Apr 2016 18:06:48 -0500
parents 032c4c2f802a
children 9dc27a334fb1
line wrap: on
line diff
--- a/mercurial/exchange.py	Tue Mar 29 11:54:46 2016 -0500
+++ b/mercurial/exchange.py	Sat Apr 16 18:06:48 2016 -0500
@@ -8,8 +8,6 @@
 from __future__ import absolute_import
 
 import errno
-import urllib
-import urllib2
 
 from .i18n import _
 from .node import (
@@ -35,6 +33,9 @@
     util,
 )
 
+urlerr = util.urlerr
+urlreq = util.urlreq
+
 # Maps bundle compression human names to internal representation.
 _bundlespeccompressions = {'none': None,
                            'bzip2': 'BZ',
@@ -97,8 +98,8 @@
                       'missing "=" in parameter: %s') % p)
 
             key, value = p.split('=', 1)
-            key = urllib.unquote(key)
-            value = urllib.unquote(value)
+            key = urlreq.unquote(key)
+            value = urlreq.unquote(value)
             params[key] = value
 
         return version, params
@@ -236,7 +237,7 @@
     elif isinstance(b, streamclone.streamcloneapplier):
         requirements = streamclone.readbundle1header(fh)[2]
         params = 'requirements=%s' % ','.join(sorted(requirements))
-        return 'none-packed1;%s' % urllib.quote(params)
+        return 'none-packed1;%s' % urlreq.quote(params)
     else:
         raise error.Abort(_('unknown bundle type: %s') % b)
 
@@ -266,10 +267,10 @@
 class pushoperation(object):
     """A object that represent a single push operation
 
-    It purpose is to carry push related state and very common operation.
+    Its purpose is to carry push related state and very common operations.
 
-    A new should be created at the beginning of each push and discarded
-    afterward.
+    A new pushoperation should be created at the beginning of each push and
+    discarded afterward.
     """
 
     def __init__(self, repo, remote, force=False, revs=None, newbranch=False,
@@ -576,7 +577,8 @@
         ancestors = repo.changelog.ancestors(revnums, inclusive=True)
     remotebookmark = remote.listkeys('bookmarks')
 
-    explicit = set(pushop.bookmarks)
+    explicit = set([repo._bookmarks.expandname(bookmark)
+                    for bookmark in pushop.bookmarks])
 
     comp = bookmod.compare(repo, repo._bookmarks, remotebookmark, srchex=hex)
     addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = comp
@@ -693,30 +695,25 @@
     # Send known heads to the server for race detection.
     if not _pushcheckoutgoing(pushop):
         return
-    pushop.repo.prepushoutgoinghooks(pushop.repo,
-                                     pushop.remote,
-                                     pushop.outgoing)
+    pushop.repo.prepushoutgoinghooks(pushop)
 
     _pushb2ctxcheckheads(pushop, bundler)
 
     b2caps = bundle2.bundle2caps(pushop.remote)
-    version = None
+    version = '01'
     cgversions = b2caps.get('changegroup')
-    if not cgversions:  # 3.1 and 3.2 ship with an empty value
-        cg = changegroup.getlocalchangegroupraw(pushop.repo, 'push',
-                                                pushop.outgoing)
-    else:
+    if cgversions:  # 3.1 and 3.2 ship with an empty value
         cgversions = [v for v in cgversions
                       if v in changegroup.supportedoutgoingversions(
                           pushop.repo)]
         if not cgversions:
             raise ValueError(_('no common changegroup version'))
         version = max(cgversions)
-        cg = changegroup.getlocalchangegroupraw(pushop.repo, 'push',
-                                                pushop.outgoing,
-                                                version=version)
+    cg = changegroup.getlocalchangegroupraw(pushop.repo, 'push',
+                                            pushop.outgoing,
+                                            version=version)
     cgpart = bundler.newpart('changegroup', data=cg)
-    if version is not None:
+    if cgversions:
         cgpart.addparam('version', version)
     if 'treemanifest' in pushop.repo.requirements:
         cgpart.addparam('treemanifest', '1')
@@ -886,9 +883,7 @@
     pushop.stepsdone.add('changesets')
     if not _pushcheckoutgoing(pushop):
         return
-    pushop.repo.prepushoutgoinghooks(pushop.repo,
-                                     pushop.remote,
-                                     pushop.outgoing)
+    pushop.repo.prepushoutgoinghooks(pushop)
     outgoing = pushop.outgoing
     unbundle = pushop.remote.capable('unbundle')
     # TODO: get bundlecaps from remote
@@ -1471,7 +1466,7 @@
     """return a set with appropriate options to use bundle20 during getbundle"""
     caps = set(['HG20'])
     capsblob = bundle2.encodecaps(bundle2.getrepocaps(repo))
-    caps.add('bundle2=' + urllib.quote(capsblob))
+    caps.add('bundle2=' + urlreq.quote(capsblob))
     return caps
 
 # List of names of steps to perform for a bundle2 for getbundle, order matters.
@@ -1537,7 +1532,7 @@
     b2caps = {}
     for bcaps in bundlecaps:
         if bcaps.startswith('bundle2='):
-            blob = urllib.unquote(bcaps[len('bundle2='):])
+            blob = urlreq.unquote(bcaps[len('bundle2='):])
             b2caps.update(bundle2.decodecaps(blob))
     bundler = bundle2.bundle20(repo.ui, b2caps)
 
@@ -1558,23 +1553,22 @@
     cg = None
     if kwargs.get('cg', True):
         # build changegroup bundle here.
-        version = None
+        version = '01'
         cgversions = b2caps.get('changegroup')
-        getcgkwargs = {}
         if cgversions:  # 3.1 and 3.2 ship with an empty value
             cgversions = [v for v in cgversions
                           if v in changegroup.supportedoutgoingversions(repo)]
             if not cgversions:
                 raise ValueError(_('no common changegroup version'))
-            version = getcgkwargs['version'] = max(cgversions)
+            version = max(cgversions)
         outgoing = changegroup.computeoutgoing(repo, heads, common)
         cg = changegroup.getlocalchangegroupraw(repo, source, outgoing,
                                                 bundlecaps=bundlecaps,
-                                                **getcgkwargs)
+                                                version=version)
 
     if cg:
         part = bundler.newpart('changegroup', data=cg)
-        if version is not None:
+        if cgversions:
             part.addparam('version', version)
         part.addparam('nbchanges', str(len(outgoing.missing)), mandatory=False)
         if 'treemanifest' in repo.requirements:
@@ -1807,8 +1801,8 @@
         attrs = {'URL': fields[0]}
         for rawattr in fields[1:]:
             key, value = rawattr.split('=', 1)
-            key = urllib.unquote(key)
-            value = urllib.unquote(value)
+            key = urlreq.unquote(key)
+            value = urlreq.unquote(value)
             attrs[key] = value
 
             # Parse BUNDLESPEC into components. This makes client-side
@@ -1924,9 +1918,9 @@
                     cg.apply(repo, 'clonebundles', url)
                 tr.close()
                 return True
-            except urllib2.HTTPError as e:
+            except urlerr.httperror as e:
                 ui.warn(_('HTTP error fetching bundle: %s\n') % str(e))
-            except urllib2.URLError as e:
+            except urlerr.urlerror as e:
                 ui.warn(_('error fetching bundle: %s\n') % e.reason[1])
 
             return False