mercurial/exchange.py
author Pierre-Yves David <pierre-yves.david@fb.com>
Thu, 25 Sep 2014 02:53:29 -0700
changeset 22625 62ab9ca90b36
parent 22624 eef31f9a4c0f
child 22628 2805d23e1f88
permissions -rw-r--r--
push: perform bookmark export in the push function This part is responsible for adding new bookmarks on the remote. Before that, it was done on its own in `commands.push`. The export is still not integrated with the rest of the push process, but at least it now dwells in the right function.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
     1
# exchange.py - utility to exchange data between repos.
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     2
#
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     3
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     4
#
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     7
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     8
from i18n import _
20469
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
     9
from node import hex, nullid
21141
d8dd19e09ed4 bundle2: advertise bundle2 caps in server capabilities
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21130
diff changeset
    10
import errno, urllib
21184
28d76afa1568 bundle2: fix raising errors during heads checking
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21182
diff changeset
    11
import util, scmutil, changegroup, base85, error
22622
ce6b9edee725 exchange: import bookmarks as bookmod
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22616
diff changeset
    12
import discovery, phases, obsolete, bookmarks as bookmod, bundle2, pushkey
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    13
21064
4d9d490d7bbe bundle2: add a ui argument to readbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21063
diff changeset
    14
def readbundle(ui, fh, fname, vfs=None):
21065
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
    15
    header = changegroup.readexactly(fh, 4)
21063
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
    16
21065
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
    17
    alg = None
21063
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
    18
    if not fname:
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
    19
        fname = "stream"
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
    20
        if not header.startswith('HG') and header.startswith('\0'):
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
    21
            fh = changegroup.headerlessfixup(fh, header)
21065
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
    22
            header = "HG10"
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
    23
            alg = 'UN'
21063
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
    24
    elif vfs:
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
    25
        fname = vfs.join(fname)
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
    26
21065
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
    27
    magic, version = header[0:2], header[2:4]
21063
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
    28
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
    29
    if magic != 'HG':
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
    30
        raise util.Abort(_('%s: not a Mercurial bundle') % fname)
21065
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
    31
    if version == '10':
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
    32
        if alg is None:
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
    33
            alg = changegroup.readexactly(fh, 2)
22390
e2806b8613ca changegroup: rename bundle-related functions and classes
Sune Foldager <cryo@cyanite.org>
parents: 22354
diff changeset
    34
        return changegroup.cg1unpacker(fh, alg)
21144
7a20fe8dc080 bundle2: use HG2X in the header
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21143
diff changeset
    35
    elif version == '2X':
21067
7974aa88868e bundle2: let readbundle return unbundle20
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21065
diff changeset
    36
        return bundle2.unbundle20(ui, fh, header=magic + version)
21065
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
    37
    else:
21063
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
    38
        raise util.Abort(_('%s: unknown bundle version %s') % (fname, version))
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
    39
22346
a76660f85200 exchange: add a `buildobsmarkerpart` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22342
diff changeset
    40
def buildobsmarkerspart(bundler, markers):
a76660f85200 exchange: add a `buildobsmarkerpart` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22342
diff changeset
    41
    """add an obsmarker part to the bundler with <markers>
a76660f85200 exchange: add a `buildobsmarkerpart` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22342
diff changeset
    42
a76660f85200 exchange: add a `buildobsmarkerpart` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22342
diff changeset
    43
    No part is created if markers is empty.
a76660f85200 exchange: add a `buildobsmarkerpart` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22342
diff changeset
    44
    Raises ValueError if the bundler doesn't support any known obsmarker format.
a76660f85200 exchange: add a `buildobsmarkerpart` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22342
diff changeset
    45
    """
a76660f85200 exchange: add a `buildobsmarkerpart` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22342
diff changeset
    46
    if markers:
a76660f85200 exchange: add a `buildobsmarkerpart` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22342
diff changeset
    47
        remoteversions = bundle2.obsmarkersversion(bundler.capabilities)
a76660f85200 exchange: add a `buildobsmarkerpart` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22342
diff changeset
    48
        version = obsolete.commonversion(remoteversions)
a76660f85200 exchange: add a `buildobsmarkerpart` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22342
diff changeset
    49
        if version is None:
a76660f85200 exchange: add a `buildobsmarkerpart` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22342
diff changeset
    50
            raise ValueError('bundler do not support common obsmarker format')
a76660f85200 exchange: add a `buildobsmarkerpart` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22342
diff changeset
    51
        stream = obsolete.encodemarkers(markers, True, version=version)
a76660f85200 exchange: add a `buildobsmarkerpart` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22342
diff changeset
    52
        return bundler.newpart('B2X:OBSMARKERS', data=stream)
a76660f85200 exchange: add a `buildobsmarkerpart` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22342
diff changeset
    53
    return None
20346
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
    54
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
    55
class pushoperation(object):
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
    56
    """A object that represent a single push operation
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
    57
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
    58
    It purpose is to carry push related state and very common operation.
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
    59
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
    60
    A new should be created at the beginning of each push and discarded
20346
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
    61
    afterward.
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
    62
    """
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
    63
22623
cd7e17aa6040 push: pass list of bookmark to `exchange.push`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22622
diff changeset
    64
    def __init__(self, repo, remote, force=False, revs=None, newbranch=False,
cd7e17aa6040 push: pass list of bookmark to `exchange.push`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22622
diff changeset
    65
                 bookmarks=()):
20346
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
    66
        # repo we push from
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
    67
        self.repo = repo
20347
3ec5f833348e push: ease access to current ui object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20346
diff changeset
    68
        self.ui = repo.ui
20348
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
    69
        # repo we push to
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
    70
        self.remote = remote
20349
89f90457979e push: move `force` argument into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20348
diff changeset
    71
        # force option provided
89f90457979e push: move `force` argument into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20348
diff changeset
    72
        self.force = force
20350
8c85d968ee65 push: move `revs` argument into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20349
diff changeset
    73
        # revs to be pushed (None is "all")
8c85d968ee65 push: move `revs` argument into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20349
diff changeset
    74
        self.revs = revs
22623
cd7e17aa6040 push: pass list of bookmark to `exchange.push`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22622
diff changeset
    75
        # bookmark explicitly pushed
cd7e17aa6040 push: pass list of bookmark to `exchange.push`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22622
diff changeset
    76
        self.bookmarks = bookmarks
20351
c05ad450df23 push: move `newbranch` argument into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20350
diff changeset
    77
        # allow push of new branch
c05ad450df23 push: move `newbranch` argument into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20350
diff changeset
    78
        self.newbranch = newbranch
20436
2f2e8d1c4856 push: move local lock logic in pushoperation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20435
diff changeset
    79
        # did a local lock get acquired?
2f2e8d1c4856 push: move local lock logic in pushoperation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20435
diff changeset
    80
        self.locallocked = None
21901
8612c4ab7f54 push: add a ``pushop.stepsdone`` attribute
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21899
diff changeset
    81
        # step already performed
8612c4ab7f54 push: add a ``pushop.stepsdone`` attribute
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21899
diff changeset
    82
        # (used to check what steps have been already performed through bundle2)
8612c4ab7f54 push: add a ``pushop.stepsdone`` attribute
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21899
diff changeset
    83
        self.stepsdone = set()
22615
4f14303e8954 push: rename `pushop.ret` to `pushop.cgresult`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22543
diff changeset
    84
        # Integer version of the changegroup push result
20439
0d3ccf285ff2 push: move push return value in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20438
diff changeset
    85
        # - None means nothing to push
0d3ccf285ff2 push: move push return value in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20438
diff changeset
    86
        # - 0 means HTTP error
0d3ccf285ff2 push: move push return value in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20438
diff changeset
    87
        # - 1 means we pushed and remote head count is unchanged *or*
0d3ccf285ff2 push: move push return value in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20438
diff changeset
    88
        #   we have outgoing changesets but refused to push
0d3ccf285ff2 push: move push return value in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20438
diff changeset
    89
        # - other values as described by addchangegroup()
22615
4f14303e8954 push: rename `pushop.ret` to `pushop.cgresult`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22543
diff changeset
    90
        self.cgresult = None
22624
eef31f9a4c0f push: add `pushoperation.bkresult`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22623
diff changeset
    91
        # Boolean value for the bookmark push
eef31f9a4c0f push: add `pushoperation.bkresult`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22623
diff changeset
    92
        self.bkresult = None
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
    93
        # discover.outgoing object (contains common and outgoing data)
20440
400da8bc7786 push: move outgoing object in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20439
diff changeset
    94
        self.outgoing = None
20462
0031ef5df586 push: move `remoteheads` into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20441
diff changeset
    95
        # all remote heads before the push
0031ef5df586 push: move `remoteheads` into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20441
diff changeset
    96
        self.remoteheads = None
20464
d032417db243 push: move `incoming` into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20463
diff changeset
    97
        # testable as a boolean indicating if any nodes are missing locally.
d032417db243 push: move `incoming` into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20463
diff changeset
    98
        self.incoming = None
22019
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
    99
        # phases changes that must be pushed along side the changesets
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   100
        self.outdatedphases = None
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   101
        # phases changes that must be pushed if changeset push fails
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   102
        self.fallbackoutdatedphases = None
22034
5f57bc77657c push: move the list of obsmarker to push into the push operation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22033
diff changeset
   103
        # outgoing obsmarkers
22035
24bb01f42e82 push: introduce a discovery step for obsmarker
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22034
diff changeset
   104
        self.outobsmarkers = set()
22239
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   105
        # outgoing bookmarks
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   106
        self.outbookmarks = []
20346
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
   107
22014
71083b020b4a push: extract future heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21989
diff changeset
   108
    @util.propertycache
71083b020b4a push: extract future heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21989
diff changeset
   109
    def futureheads(self):
71083b020b4a push: extract future heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21989
diff changeset
   110
        """future remote heads if the changeset push succeeds"""
71083b020b4a push: extract future heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21989
diff changeset
   111
        return self.outgoing.missingheads
71083b020b4a push: extract future heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21989
diff changeset
   112
22015
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   113
    @util.propertycache
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   114
    def fallbackheads(self):
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   115
        """future remote heads if the changeset push fails"""
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   116
        if self.revs is None:
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   117
            # not target to push, all common are relevant
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   118
            return self.outgoing.commonheads
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   119
        unfi = self.repo.unfiltered()
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   120
        # I want cheads = heads(::missingheads and ::commonheads)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   121
        # (missingheads is revs with secret changeset filtered out)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   122
        #
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   123
        # This can be expressed as:
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   124
        #     cheads = ( (missingheads and ::commonheads)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   125
        #              + (commonheads and ::missingheads))"
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   126
        #              )
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   127
        #
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   128
        # while trying to push we already computed the following:
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   129
        #     common = (::commonheads)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   130
        #     missing = ((commonheads::missingheads) - commonheads)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   131
        #
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   132
        # We can pick:
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   133
        # * missingheads part of common (::commonheads)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   134
        common = set(self.outgoing.common)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   135
        nm = self.repo.changelog.nodemap
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   136
        cheads = [node for node in self.revs if nm[node] in common]
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   137
        # and
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   138
        # * commonheads parents on missing
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   139
        revset = unfi.set('%ln and parents(roots(%ln))',
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   140
                         self.outgoing.commonheads,
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   141
                         self.outgoing.missing)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   142
        cheads.extend(c.node() for c in revset)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   143
        return cheads
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   144
22016
7d976d71684c push: move common heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22015
diff changeset
   145
    @property
7d976d71684c push: move common heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22015
diff changeset
   146
    def commonheads(self):
7d976d71684c push: move common heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22015
diff changeset
   147
        """set of all common heads after changeset bundle push"""
22615
4f14303e8954 push: rename `pushop.ret` to `pushop.cgresult`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22543
diff changeset
   148
        if self.cgresult:
22016
7d976d71684c push: move common heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22015
diff changeset
   149
            return self.futureheads
7d976d71684c push: move common heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22015
diff changeset
   150
        else:
7d976d71684c push: move common heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22015
diff changeset
   151
            return self.fallbackheads
22015
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
   152
22623
cd7e17aa6040 push: pass list of bookmark to `exchange.push`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22622
diff changeset
   153
def push(repo, remote, force=False, revs=None, newbranch=False, bookmarks=()):
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   154
    '''Push outgoing changesets (limited by revs) from a local
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   155
    repository to remote. Return an integer:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   156
      - None means nothing to push
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   157
      - 0 means HTTP error
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   158
      - 1 means we pushed and remote head count is unchanged *or*
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   159
        we have outgoing changesets but refused to push
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   160
      - other values as described by addchangegroup()
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   161
    '''
22623
cd7e17aa6040 push: pass list of bookmark to `exchange.push`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22622
diff changeset
   162
    pushop = pushoperation(repo, remote, force, revs, newbranch, bookmarks)
20348
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
   163
    if pushop.remote.local():
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
   164
        missing = (set(pushop.repo.requirements)
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
   165
                   - pushop.remote.local().supported)
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   166
        if missing:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   167
            msg = _("required features are not"
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   168
                    " supported in the destination:"
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   169
                    " %s") % (', '.join(sorted(missing)))
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   170
            raise util.Abort(msg)
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   171
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   172
    # there are two ways to push to remote repo:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   173
    #
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   174
    # addchangegroup assumes local user can lock remote
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   175
    # repo (local filesystem, old ssh servers).
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   176
    #
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   177
    # unbundle assumes local user cannot lock remote repo (new ssh
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   178
    # servers, http servers).
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   179
20348
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
   180
    if not pushop.remote.canpush():
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   181
        raise util.Abort(_("destination does not support push"))
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   182
    # get local lock as we might write phase data
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   183
    locallock = None
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   184
    try:
20346
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
   185
        locallock = pushop.repo.lock()
20436
2f2e8d1c4856 push: move local lock logic in pushoperation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20435
diff changeset
   186
        pushop.locallocked = True
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   187
    except IOError, err:
20436
2f2e8d1c4856 push: move local lock logic in pushoperation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20435
diff changeset
   188
        pushop.locallocked = False
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   189
        if err.errno != errno.EACCES:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   190
            raise
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   191
        # source repo cannot be locked.
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   192
        # We do not abort the push, but just disable the local phase
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   193
        # synchronisation.
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   194
        msg = 'cannot lock source repository: %s\n' % err
20347
3ec5f833348e push: ease access to current ui object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20346
diff changeset
   195
        pushop.ui.debug(msg)
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   196
    try:
20924
e10000369b47 push: pass a `pushoperation` object to localrepo.checkpush
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20901
diff changeset
   197
        pushop.repo.checkpush(pushop)
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   198
        lock = None
20348
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
   199
        unbundle = pushop.remote.capable('unbundle')
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   200
        if not unbundle:
20348
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
   201
            lock = pushop.remote.lock()
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   202
        try:
20466
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
   203
            _pushdiscovery(pushop)
21903
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   204
            if (pushop.repo.ui.configbool('experimental', 'bundle2-exp',
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   205
                                          False)
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   206
                and pushop.remote.capable('bundle2-exp')):
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   207
                _pushbundle2(pushop)
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   208
            _pushchangeset(pushop)
20441
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   209
            _pushsyncphase(pushop)
20433
6af248474224 push: feed pushoperation object to _pushobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20432
diff changeset
   210
            _pushobsolete(pushop)
22224
f713de1d3916 push: update bookmarks within the remote lock
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22069
diff changeset
   211
            _pushbookmark(pushop)
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   212
        finally:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   213
            if lock is not None:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   214
                lock.release()
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   215
    finally:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   216
        if locallock is not None:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   217
            locallock.release()
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   218
22625
62ab9ca90b36 push: perform bookmark export in the push function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22624
diff changeset
   219
    if pushop.bookmarks:
62ab9ca90b36 push: perform bookmark export in the push function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22624
diff changeset
   220
        pushop.bkresult = bookmod.pushtoremote(repo.ui, repo, remote,
62ab9ca90b36 push: perform bookmark export in the push function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22624
diff changeset
   221
                                               pushop.bookmarks)
62ab9ca90b36 push: perform bookmark export in the push function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22624
diff changeset
   222
22616
cda85cfc8252 push: `exchange.push` now returns the `pushoperation` object
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22615
diff changeset
   223
    return pushop
20352
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
   224
22018
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   225
# list of steps to perform discovery before push
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   226
pushdiscoveryorder = []
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   227
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   228
# Mapping between step name and function
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   229
#
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   230
# This exists to help extensions wrap steps if necessary
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   231
pushdiscoverymapping = {}
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   232
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   233
def pushdiscovery(stepname):
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   234
    """decorator for function performing discovery before push
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   235
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   236
    The function is added to the step -> function mapping and appended to the
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   237
    list of steps.  Beware that decorated function will be added in order (this
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   238
    may matter).
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   239
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   240
    You can only use this decorator for a new step, if you want to wrap a step
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   241
    from an extension, change the pushdiscovery dictionary directly."""
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   242
    def dec(func):
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   243
        assert stepname not in pushdiscoverymapping
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   244
        pushdiscoverymapping[stepname] = func
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   245
        pushdiscoveryorder.append(stepname)
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   246
        return func
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   247
    return dec
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   248
20466
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
   249
def _pushdiscovery(pushop):
22018
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   250
    """Run all discovery steps"""
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   251
    for stepname in pushdiscoveryorder:
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   252
        step = pushdiscoverymapping[stepname]
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   253
        step(pushop)
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   254
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   255
@pushdiscovery('changeset')
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   256
def _pushdiscoverychangeset(pushop):
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
   257
    """discover the changeset that need to be pushed"""
20466
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
   258
    unfi = pushop.repo.unfiltered()
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
   259
    fci = discovery.findcommonincoming
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
   260
    commoninc = fci(unfi, pushop.remote, force=pushop.force)
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
   261
    common, inc, remoteheads = commoninc
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
   262
    fco = discovery.findcommonoutgoing
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
   263
    outgoing = fco(unfi, pushop.remote, onlyheads=pushop.revs,
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
   264
                   commoninc=commoninc, force=pushop.force)
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
   265
    pushop.outgoing = outgoing
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
   266
    pushop.remoteheads = remoteheads
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
   267
    pushop.incoming = inc
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
   268
22019
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   269
@pushdiscovery('phase')
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   270
def _pushdiscoveryphase(pushop):
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   271
    """discover the phase that needs to be pushed
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   272
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   273
    (computed for both success and failure case for changesets push)"""
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   274
    outgoing = pushop.outgoing
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   275
    unfi = pushop.repo.unfiltered()
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   276
    remotephases = pushop.remote.listkeys('phases')
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   277
    publishing = remotephases.get('publishing', False)
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   278
    ana = phases.analyzeremotephases(pushop.repo,
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   279
                                     pushop.fallbackheads,
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   280
                                     remotephases)
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   281
    pheads, droots = ana
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   282
    extracond = ''
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   283
    if not publishing:
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   284
        extracond = ' and public()'
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   285
    revset = 'heads((%%ln::%%ln) %s)' % extracond
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   286
    # Get the list of all revs draft on remote by public here.
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   287
    # XXX Beware that revset break if droots is not strictly
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   288
    # XXX root we may want to ensure it is but it is costly
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   289
    fallback = list(unfi.set(revset, droots, pushop.fallbackheads))
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   290
    if not outgoing.missing:
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   291
        future = fallback
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   292
    else:
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   293
        # adds changeset we are going to push as draft
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   294
        #
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   295
        # should not be necessary for pushblishing server, but because of an
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   296
        # issue fixed in xxxxx we have to do it anyway.
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   297
        fdroots = list(unfi.set('roots(%ln  + %ln::)',
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   298
                       outgoing.missing, droots))
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   299
        fdroots = [f.node() for f in fdroots]
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   300
        future = list(unfi.set(revset, fdroots, pushop.futureheads))
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   301
    pushop.outdatedphases = future
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   302
    pushop.fallbackoutdatedphases = fallback
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   303
22035
24bb01f42e82 push: introduce a discovery step for obsmarker
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22034
diff changeset
   304
@pushdiscovery('obsmarker')
24bb01f42e82 push: introduce a discovery step for obsmarker
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22034
diff changeset
   305
def _pushdiscoveryobsmarkers(pushop):
22269
03cc81a28228 push: check if local and remote support evolution during discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22244
diff changeset
   306
    if (obsolete._enabled
03cc81a28228 push: check if local and remote support evolution during discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22244
diff changeset
   307
        and pushop.repo.obsstore
03cc81a28228 push: check if local and remote support evolution during discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22244
diff changeset
   308
        and 'obsolete' in pushop.remote.listkeys('namespaces')):
22350
6d113cc7a31a push: only push obsmarkers relevant to the "pushed subset"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22347
diff changeset
   309
        repo = pushop.repo
6d113cc7a31a push: only push obsmarkers relevant to the "pushed subset"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22347
diff changeset
   310
        # very naive computation, that can be quite expensive on big repo.
6d113cc7a31a push: only push obsmarkers relevant to the "pushed subset"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22347
diff changeset
   311
        # However: evolution is currently slow on them anyway.
6d113cc7a31a push: only push obsmarkers relevant to the "pushed subset"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22347
diff changeset
   312
        nodes = (c.node() for c in repo.set('::%ln', pushop.futureheads))
6d113cc7a31a push: only push obsmarkers relevant to the "pushed subset"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22347
diff changeset
   313
        pushop.outobsmarkers = pushop.repo.obsstore.relevantmarkers(nodes)
22035
24bb01f42e82 push: introduce a discovery step for obsmarker
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22034
diff changeset
   314
22239
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   315
@pushdiscovery('bookmarks')
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   316
def _pushdiscoverybookmarks(pushop):
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   317
    ui = pushop.ui
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   318
    repo = pushop.repo.unfiltered()
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   319
    remote = pushop.remote
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   320
    ui.debug("checking for updated bookmarks\n")
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   321
    ancestors = ()
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   322
    if pushop.revs:
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   323
        revnums = map(repo.changelog.rev, pushop.revs)
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   324
        ancestors = repo.changelog.ancestors(revnums, inclusive=True)
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   325
    remotebookmark = remote.listkeys('bookmarks')
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   326
22622
ce6b9edee725 exchange: import bookmarks as bookmod
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22616
diff changeset
   327
    comp = bookmod.compare(repo, repo._bookmarks, remotebookmark, srchex=hex)
22243
728669a41947 exchange: drop superfluous parens
Augie Fackler <raf@durin42.com>
parents: 22242
diff changeset
   328
    addsrc, adddst, advsrc, advdst, diverge, differ, invalid = comp
22239
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   329
    for b, scid, dcid in advsrc:
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   330
        if not ancestors or repo[scid].rev() in ancestors:
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   331
            pushop.outbookmarks.append((b, dcid, scid))
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   332
20465
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   333
def _pushcheckoutgoing(pushop):
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   334
    outgoing = pushop.outgoing
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   335
    unfi = pushop.repo.unfiltered()
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   336
    if not outgoing.missing:
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   337
        # nothing to push
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   338
        scmutil.nochangesfound(unfi.ui, unfi, outgoing.excluded)
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   339
        return False
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   340
    # something to push
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   341
    if not pushop.force:
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   342
        # if repo.obsstore == False --> no obsolete
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   343
        # then, save the iteration
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   344
        if unfi.obsstore:
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   345
            # this message are here for 80 char limit reason
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   346
            mso = _("push includes obsolete changeset: %s!")
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   347
            mst = "push includes %s changeset: %s!"
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   348
            # plain versions for i18n tool to detect them
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   349
            _("push includes unstable changeset: %s!")
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   350
            _("push includes bumped changeset: %s!")
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   351
            _("push includes divergent changeset: %s!")
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   352
            # If we are to push if there is at least one
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   353
            # obsolete or unstable changeset in missing, at
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   354
            # least one of the missinghead will be obsolete or
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   355
            # unstable. So checking heads only is ok
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   356
            for node in outgoing.missingheads:
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   357
                ctx = unfi[node]
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   358
                if ctx.obsolete():
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   359
                    raise util.Abort(mso % ctx)
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   360
                elif ctx.troubled():
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   361
                    raise util.Abort(_(mst)
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   362
                                     % (ctx.troubles()[0],
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   363
                                        ctx))
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   364
        newbm = pushop.ui.configlist('bookmarks', 'pushing')
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   365
        discovery.checkheads(unfi, pushop.remote, outgoing,
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   366
                             pushop.remoteheads,
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   367
                             pushop.newbranch,
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   368
                             bool(pushop.incoming),
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   369
                             newbm)
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   370
    return True
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
   371
22017
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   372
# List of names of steps to perform for an outgoing bundle2, order matters.
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   373
b2partsgenorder = []
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   374
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   375
# Mapping between step name and function
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   376
#
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   377
# This exists to help extensions wrap steps if necessary
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   378
b2partsgenmapping = {}
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   379
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   380
def b2partsgenerator(stepname):
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   381
    """decorator for function generating bundle2 part
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   382
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   383
    The function is added to the step -> function mapping and appended to the
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   384
    list of steps.  Beware that decorated functions will be added in order
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   385
    (this may matter).
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   386
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   387
    You can only use this decorator for new steps, if you want to wrap a step
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   388
    from an extension, attack the b2partsgenmapping dictionary directly."""
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   389
    def dec(func):
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   390
        assert stepname not in b2partsgenmapping
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   391
        b2partsgenmapping[stepname] = func
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   392
        b2partsgenorder.append(stepname)
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   393
        return func
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   394
    return dec
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   395
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   396
@b2partsgenerator('changeset')
21899
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
   397
def _pushb2ctx(pushop, bundler):
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
   398
    """handle changegroup push through bundle2
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
   399
22615
4f14303e8954 push: rename `pushop.ret` to `pushop.cgresult`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22543
diff changeset
   400
    addchangegroup result is stored in the ``pushop.cgresult`` attribute.
21899
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
   401
    """
21902
7a7def851ba0 push: use `stepsdone` to control changegroup push through bundle10 or bundle20
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21901
diff changeset
   402
    if 'changesets' in pushop.stepsdone:
7a7def851ba0 push: use `stepsdone` to control changegroup push through bundle10 or bundle20
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21901
diff changeset
   403
        return
7a7def851ba0 push: use `stepsdone` to control changegroup push through bundle10 or bundle20
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21901
diff changeset
   404
    pushop.stepsdone.add('changesets')
21899
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
   405
    # Send known heads to the server for race detection.
21903
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   406
    if not _pushcheckoutgoing(pushop):
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   407
        return
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   408
    pushop.repo.prepushoutgoinghooks(pushop.repo,
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   409
                                     pushop.remote,
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   410
                                     pushop.outgoing)
21899
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
   411
    if not pushop.force:
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
   412
        bundler.newpart('B2X:CHECK:HEADS', data=iter(pushop.remoteheads))
22390
e2806b8613ca changegroup: rename bundle-related functions and classes
Sune Foldager <cryo@cyanite.org>
parents: 22354
diff changeset
   413
    cg = changegroup.getlocalchangegroup(pushop.repo, 'push', pushop.outgoing)
21899
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
   414
    cgpart = bundler.newpart('B2X:CHANGEGROUP', data=cg.getchunks())
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
   415
    def handlereply(op):
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
   416
        """extract addchangroup returns from server reply"""
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
   417
        cgreplies = op.records.getreplies(cgpart.id)
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
   418
        assert len(cgreplies['changegroup']) == 1
22615
4f14303e8954 push: rename `pushop.ret` to `pushop.cgresult`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22543
diff changeset
   419
        pushop.cgresult = cgreplies['changegroup'][0]['return']
21899
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
   420
    return handlereply
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
   421
22020
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   422
@b2partsgenerator('phase')
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   423
def _pushb2phases(pushop, bundler):
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   424
    """handle phase push through bundle2"""
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   425
    if 'phases' in pushop.stepsdone:
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   426
        return
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   427
    b2caps = bundle2.bundle2caps(pushop.remote)
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   428
    if not 'b2x:pushkey' in b2caps:
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   429
        return
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   430
    pushop.stepsdone.add('phases')
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   431
    part2node = []
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   432
    enc = pushkey.encode
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   433
    for newremotehead in pushop.outdatedphases:
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   434
        part = bundler.newpart('b2x:pushkey')
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   435
        part.addparam('namespace', enc('phases'))
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   436
        part.addparam('key', enc(newremotehead.hex()))
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   437
        part.addparam('old', enc(str(phases.draft)))
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   438
        part.addparam('new', enc(str(phases.public)))
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   439
        part2node.append((part.id, newremotehead))
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   440
    def handlereply(op):
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   441
        for partid, node in part2node:
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   442
            partrep = op.records.getreplies(partid)
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   443
            results = partrep['pushkey']
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   444
            assert len(results) <= 1
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   445
            msg = None
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   446
            if not results:
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   447
                msg = _('server ignored update of %s to public!\n') % node
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   448
            elif not int(results[0]['return']):
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   449
                msg = _('updating %s to public failed!\n') % node
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   450
            if msg is not None:
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   451
                pushop.ui.warn(msg)
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   452
    return handlereply
21904
5fbccbcc07ea bundle2-push: introduce a list of part generating functions
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21903
diff changeset
   453
22347
7198cb9b56b9 push: use bundle2 to push obsmarkers when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22346
diff changeset
   454
@b2partsgenerator('obsmarkers')
7198cb9b56b9 push: use bundle2 to push obsmarkers when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22346
diff changeset
   455
def _pushb2obsmarkers(pushop, bundler):
7198cb9b56b9 push: use bundle2 to push obsmarkers when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22346
diff changeset
   456
    if 'obsmarkers' in pushop.stepsdone:
7198cb9b56b9 push: use bundle2 to push obsmarkers when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22346
diff changeset
   457
        return
7198cb9b56b9 push: use bundle2 to push obsmarkers when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22346
diff changeset
   458
    remoteversions = bundle2.obsmarkersversion(bundler.capabilities)
7198cb9b56b9 push: use bundle2 to push obsmarkers when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22346
diff changeset
   459
    if obsolete.commonversion(remoteversions) is None:
7198cb9b56b9 push: use bundle2 to push obsmarkers when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22346
diff changeset
   460
        return
7198cb9b56b9 push: use bundle2 to push obsmarkers when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22346
diff changeset
   461
    pushop.stepsdone.add('obsmarkers')
7198cb9b56b9 push: use bundle2 to push obsmarkers when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22346
diff changeset
   462
    if pushop.outobsmarkers:
7198cb9b56b9 push: use bundle2 to push obsmarkers when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22346
diff changeset
   463
        buildobsmarkerspart(bundler, pushop.outobsmarkers)
7198cb9b56b9 push: use bundle2 to push obsmarkers when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22346
diff changeset
   464
22242
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   465
@b2partsgenerator('bookmarks')
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   466
def _pushb2bookmarks(pushop, bundler):
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   467
    """handle phase push through bundle2"""
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   468
    if 'bookmarks' in pushop.stepsdone:
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   469
        return
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   470
    b2caps = bundle2.bundle2caps(pushop.remote)
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   471
    if 'b2x:pushkey' not in b2caps:
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   472
        return
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   473
    pushop.stepsdone.add('bookmarks')
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   474
    part2book = []
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   475
    enc = pushkey.encode
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   476
    for book, old, new in pushop.outbookmarks:
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   477
        part = bundler.newpart('b2x:pushkey')
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   478
        part.addparam('namespace', enc('bookmarks'))
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   479
        part.addparam('key', enc(book))
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   480
        part.addparam('old', enc(old))
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   481
        part.addparam('new', enc(new))
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   482
        part2book.append((part.id, book))
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   483
    def handlereply(op):
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   484
        for partid, book in part2book:
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   485
            partrep = op.records.getreplies(partid)
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   486
            results = partrep['pushkey']
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   487
            assert len(results) <= 1
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   488
            if not results:
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   489
                pushop.ui.warn(_('server ignored bookmark %s update\n') % book)
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   490
            else:
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   491
                ret = int(results[0]['return'])
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   492
                if ret:
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   493
                    pushop.ui.status(_("updating bookmark %s\n") % book)
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   494
                else:
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   495
                    pushop.ui.warn(_('updating bookmark %s failed!\n') % book)
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   496
    return handlereply
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   497
ed222ebd61be push: add bookmarks to the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22240
diff changeset
   498
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
   499
def _pushbundle2(pushop):
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
   500
    """push data to the remote using bundle2
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
   501
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
   502
    The only currently supported type of data is changegroup but this will
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
   503
    evolve in the future."""
21644
17755dd8c509 bundle2: introduce a bundle2caps function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21643
diff changeset
   504
    bundler = bundle2.bundle20(pushop.ui, bundle2.bundle2caps(pushop.remote))
21142
15039ce3e4a3 bundle2: include client capabilities in the pushed bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21141
diff changeset
   505
    # create reply capability
22342
262c5cc126c1 bundle2: introduce a `getrepocaps` to retrieve the bundle2 caps of a repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22341
diff changeset
   506
    capsblob = bundle2.encodecaps(bundle2.getrepocaps(pushop.repo))
21600
5e08f3b65510 bundle2: update all ``addpart`` callers to ``newpart``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21555
diff changeset
   507
    bundler.newpart('b2x:replycaps', data=capsblob)
21904
5fbccbcc07ea bundle2-push: introduce a list of part generating functions
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21903
diff changeset
   508
    replyhandlers = []
22017
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   509
    for partgenname in b2partsgenorder:
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
   510
        partgen = b2partsgenmapping[partgenname]
21904
5fbccbcc07ea bundle2-push: introduce a list of part generating functions
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21903
diff changeset
   511
        ret = partgen(pushop, bundler)
21941
dab31290c7eb bundle2: only use callable return as reply handler
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21906
diff changeset
   512
        if callable(ret):
dab31290c7eb bundle2: only use callable return as reply handler
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21906
diff changeset
   513
            replyhandlers.append(ret)
21904
5fbccbcc07ea bundle2-push: introduce a list of part generating functions
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21903
diff changeset
   514
    # do not push if nothing to push
21903
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   515
    if bundler.nbparts <= 1:
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   516
        return
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
   517
    stream = util.chunkbuffer(bundler.getchunks())
21182
08c84fd99aac bundle2: catch UnknownPartError during local push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21181
diff changeset
   518
    try:
08c84fd99aac bundle2: catch UnknownPartError during local push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21181
diff changeset
   519
        reply = pushop.remote.unbundle(stream, ['force'], 'push')
21618
7568f5c1c801 bundle2: move exception classes into the error module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21617
diff changeset
   520
    except error.BundleValueError, exc:
21182
08c84fd99aac bundle2: catch UnknownPartError during local push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21181
diff changeset
   521
        raise util.Abort('missing support for %s' % exc)
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
   522
    try:
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
   523
        op = bundle2.processbundle(pushop.repo, reply)
21618
7568f5c1c801 bundle2: move exception classes into the error module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21617
diff changeset
   524
    except error.BundleValueError, exc:
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
   525
        raise util.Abort('missing support for %s' % exc)
21904
5fbccbcc07ea bundle2-push: introduce a list of part generating functions
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21903
diff changeset
   526
    for rephand in replyhandlers:
5fbccbcc07ea bundle2-push: introduce a list of part generating functions
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21903
diff changeset
   527
        rephand(op)
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
   528
20463
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   529
def _pushchangeset(pushop):
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   530
    """Make the actual push of changeset bundle to remote repo"""
21902
7a7def851ba0 push: use `stepsdone` to control changegroup push through bundle10 or bundle20
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21901
diff changeset
   531
    if 'changesets' in pushop.stepsdone:
7a7def851ba0 push: use `stepsdone` to control changegroup push through bundle10 or bundle20
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21901
diff changeset
   532
        return
7a7def851ba0 push: use `stepsdone` to control changegroup push through bundle10 or bundle20
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21901
diff changeset
   533
    pushop.stepsdone.add('changesets')
21903
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   534
    if not _pushcheckoutgoing(pushop):
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   535
        return
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   536
    pushop.repo.prepushoutgoinghooks(pushop.repo,
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   537
                                     pushop.remote,
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
   538
                                     pushop.outgoing)
20463
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   539
    outgoing = pushop.outgoing
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   540
    unbundle = pushop.remote.capable('unbundle')
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   541
    # TODO: get bundlecaps from remote
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   542
    bundlecaps = None
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   543
    # create a changegroup from local
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   544
    if pushop.revs is None and not (outgoing.excluded
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   545
                            or pushop.repo.changelog.filteredrevs):
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   546
        # push everything,
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   547
        # use the fast path, no race possible on push
22390
e2806b8613ca changegroup: rename bundle-related functions and classes
Sune Foldager <cryo@cyanite.org>
parents: 22354
diff changeset
   548
        bundler = changegroup.cg1packer(pushop.repo, bundlecaps)
20925
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20924
diff changeset
   549
        cg = changegroup.getsubset(pushop.repo,
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20924
diff changeset
   550
                                   outgoing,
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20924
diff changeset
   551
                                   bundler,
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20924
diff changeset
   552
                                   'push',
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20924
diff changeset
   553
                                   fastpath=True)
20463
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   554
    else:
22390
e2806b8613ca changegroup: rename bundle-related functions and classes
Sune Foldager <cryo@cyanite.org>
parents: 22354
diff changeset
   555
        cg = changegroup.getlocalchangegroup(pushop.repo, 'push', outgoing,
20928
91b47139d0cb localrepo: move the getlocalbundle method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20925
diff changeset
   556
                                        bundlecaps)
20463
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   557
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   558
    # apply changegroup to remote
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   559
    if unbundle:
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   560
        # local repo finds heads on server, finds out what
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   561
        # revs it must push. once revs transferred, if server
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   562
        # finds it has different heads (someone else won
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   563
        # commit/push race), server aborts.
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   564
        if pushop.force:
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   565
            remoteheads = ['force']
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   566
        else:
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   567
            remoteheads = pushop.remoteheads
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   568
        # ssh: return remote's addchangegroup()
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   569
        # http: return remote's addchangegroup() or 0 for error
22615
4f14303e8954 push: rename `pushop.ret` to `pushop.cgresult`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22543
diff changeset
   570
        pushop.cgresult = pushop.remote.unbundle(cg, remoteheads,
21761
b2dc026a9bd2 push: restore contents of HG_URL for hooks (issue4268)
Matt Mackall <mpm@selenic.com>
parents: 21259
diff changeset
   571
                                            pushop.repo.url())
20463
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   572
    else:
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   573
        # we return an integer indicating remote head count
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   574
        # change
22615
4f14303e8954 push: rename `pushop.ret` to `pushop.cgresult`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22543
diff changeset
   575
        pushop.cgresult = pushop.remote.addchangegroup(cg, 'push',
4f14303e8954 push: rename `pushop.ret` to `pushop.cgresult`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22543
diff changeset
   576
                                                       pushop.repo.url())
20463
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
   577
20441
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   578
def _pushsyncphase(pushop):
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
   579
    """synchronise phase information locally and remotely"""
20468
7d0bbb6dd730 push: extract new common set computation from phase synchronisation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20467
diff changeset
   580
    cheads = pushop.commonheads
20441
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   581
    # even when we don't push, exchanging phase data is useful
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   582
    remotephases = pushop.remote.listkeys('phases')
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   583
    if (pushop.ui.configbool('ui', '_usedassubrepo', False)
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   584
        and remotephases    # server supports phases
22615
4f14303e8954 push: rename `pushop.ret` to `pushop.cgresult`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22543
diff changeset
   585
        and pushop.cgresult is None # nothing was pushed
20441
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   586
        and remotephases.get('publishing', False)):
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   587
        # When:
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   588
        # - this is a subrepo push
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   589
        # - and remote support phase
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   590
        # - and no changeset was pushed
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   591
        # - and remote is publishing
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   592
        # We may be in issue 3871 case!
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   593
        # We drop the possible phase synchronisation done by
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   594
        # courtesy to publish changesets possibly locally draft
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   595
        # on the remote.
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   596
        remotephases = {'publishing': 'True'}
21012
c827a0028e6f exchange: restore truncated comment
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21005
diff changeset
   597
    if not remotephases: # old server or public only reply from non-publishing
20441
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   598
        _localphasemove(pushop, cheads)
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   599
        # don't push any phase data as there is nothing to push
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   600
    else:
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   601
        ana = phases.analyzeremotephases(pushop.repo, cheads,
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   602
                                         remotephases)
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   603
        pheads, droots = ana
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   604
        ### Apply remote phase on local
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   605
        if remotephases.get('publishing', False):
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   606
            _localphasemove(pushop, cheads)
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   607
        else: # publish = False
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   608
            _localphasemove(pushop, pheads)
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   609
            _localphasemove(pushop, cheads, phases.draft)
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   610
        ### Apply local phase on remote
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   611
22615
4f14303e8954 push: rename `pushop.ret` to `pushop.cgresult`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22543
diff changeset
   612
        if pushop.cgresult:
22020
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   613
            if 'phases' in pushop.stepsdone:
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   614
                # phases already pushed though bundle2
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   615
                return
22019
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   616
            outdated = pushop.outdatedphases
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   617
        else:
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   618
            outdated = pushop.fallbackoutdatedphases
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   619
22020
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   620
        pushop.stepsdone.add('phases')
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
   621
22019
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   622
        # filter heads already turned public by the push
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
   623
        outdated = [c for c in outdated if c.node() not in pheads]
21662
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   624
        b2caps = bundle2.bundle2caps(pushop.remote)
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   625
        if 'b2x:pushkey' in b2caps:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   626
            # server supports bundle2, let's do a batched push through it
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   627
            #
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   628
            # This will eventually be unified with the changesets bundle2 push
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   629
            bundler = bundle2.bundle20(pushop.ui, b2caps)
22342
262c5cc126c1 bundle2: introduce a `getrepocaps` to retrieve the bundle2 caps of a repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22341
diff changeset
   630
            capsblob = bundle2.encodecaps(bundle2.getrepocaps(pushop.repo))
21662
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   631
            bundler.newpart('b2x:replycaps', data=capsblob)
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   632
            part2node = []
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   633
            enc = pushkey.encode
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   634
            for newremotehead in outdated:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   635
                part = bundler.newpart('b2x:pushkey')
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   636
                part.addparam('namespace', enc('phases'))
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   637
                part.addparam('key', enc(newremotehead.hex()))
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   638
                part.addparam('old', enc(str(phases.draft)))
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   639
                part.addparam('new', enc(str(phases.public)))
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   640
                part2node.append((part.id, newremotehead))
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   641
            stream = util.chunkbuffer(bundler.getchunks())
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   642
            try:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   643
                reply = pushop.remote.unbundle(stream, ['force'], 'push')
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   644
                op = bundle2.processbundle(pushop.repo, reply)
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   645
            except error.BundleValueError, exc:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   646
                raise util.Abort('missing support for %s' % exc)
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   647
            for partid, node in part2node:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   648
                partrep = op.records.getreplies(partid)
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   649
                results = partrep['pushkey']
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   650
                assert len(results) <= 1
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   651
                msg = None
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   652
                if not results:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   653
                    msg = _('server ignored update of %s to public!\n') % node
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   654
                elif not int(results[0]['return']):
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   655
                    msg = _('updating %s to public failed!\n') % node
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   656
                if msg is not None:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   657
                    pushop.ui.warn(msg)
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   658
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   659
        else:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   660
            # fallback to independant pushkey command
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   661
            for newremotehead in outdated:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   662
                r = pushop.remote.pushkey('phases',
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   663
                                          newremotehead.hex(),
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   664
                                          str(phases.draft),
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   665
                                          str(phases.public))
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   666
                if not r:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   667
                    pushop.ui.warn(_('updating %s to public failed!\n')
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
   668
                                   % newremotehead)
20441
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
   669
20438
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
   670
def _localphasemove(pushop, nodes, phase=phases.public):
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
   671
    """move <nodes> to <phase> in the local source repo"""
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
   672
    if pushop.locallocked:
22051
e894de232f35 push: wrap local phase movement in a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22036
diff changeset
   673
        tr = pushop.repo.transaction('push-phase-sync')
e894de232f35 push: wrap local phase movement in a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22036
diff changeset
   674
        try:
22069
616a455b02ca phase: add a transaction argument to advanceboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22068
diff changeset
   675
            phases.advanceboundary(pushop.repo, tr, phase, nodes)
22051
e894de232f35 push: wrap local phase movement in a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22036
diff changeset
   676
            tr.close()
e894de232f35 push: wrap local phase movement in a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22036
diff changeset
   677
        finally:
e894de232f35 push: wrap local phase movement in a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22036
diff changeset
   678
            tr.release()
20438
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
   679
    else:
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
   680
        # repo is not locked, do not change any phases!
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
   681
        # Informs the user that phases should have been moved when
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
   682
        # applicable.
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
   683
        actualmoves = [n for n in nodes if phase < pushop.repo[n].phase()]
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
   684
        phasestr = phases.phasenames[phase]
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
   685
        if actualmoves:
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
   686
            pushop.ui.status(_('cannot lock source repo, skipping '
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
   687
                               'local %s phase update\n') % phasestr)
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
   688
20433
6af248474224 push: feed pushoperation object to _pushobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20432
diff changeset
   689
def _pushobsolete(pushop):
20434
e009e59e4566 push: drop now outdated comment
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20433
diff changeset
   690
    """utility function to push obsolete markers to a remote"""
22036
f1528ef123f4 push: use stepsdone for obsmarkers push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22035
diff changeset
   691
    if 'obsmarkers' in pushop.stepsdone:
f1528ef123f4 push: use stepsdone for obsmarkers push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22035
diff changeset
   692
        return
20435
46ede894d5a4 push: move obsolescence related message into _pushobsolescence function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20434
diff changeset
   693
    pushop.ui.debug('try to push obsolete markers to remote\n')
20433
6af248474224 push: feed pushoperation object to _pushobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20432
diff changeset
   694
    repo = pushop.repo
6af248474224 push: feed pushoperation object to _pushobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20432
diff changeset
   695
    remote = pushop.remote
22036
f1528ef123f4 push: use stepsdone for obsmarkers push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22035
diff changeset
   696
    pushop.stepsdone.add('obsmarkers')
22350
6d113cc7a31a push: only push obsmarkers relevant to the "pushed subset"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22347
diff changeset
   697
    if pushop.outobsmarkers:
20432
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
   698
        rslts = []
22034
5f57bc77657c push: move the list of obsmarker to push into the push operation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22033
diff changeset
   699
        remotedata = obsolete._pushkeyescape(pushop.outobsmarkers)
20432
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
   700
        for key in sorted(remotedata, reverse=True):
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
   701
            # reverse sort to ensure we end with dump0
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
   702
            data = remotedata[key]
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
   703
            rslts.append(remote.pushkey('obsolete', key, '', data))
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
   704
        if [r for r in rslts if not r]:
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
   705
            msg = _('failed to push some obsolete markers!\n')
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
   706
            repo.ui.warn(msg)
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
   707
20431
bebf8b8479f3 push: feed pushoperation object to _pushbookmark function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20352
diff changeset
   708
def _pushbookmark(pushop):
20352
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
   709
    """Update bookmark position on remote"""
22615
4f14303e8954 push: rename `pushop.ret` to `pushop.cgresult`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22543
diff changeset
   710
    if pushop.cgresult == 0 or 'bookmarks' in pushop.stepsdone:
22228
a3dc2d385490 pushbookmark: do not attempt to update bookmarks if the push failed (BC)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22227
diff changeset
   711
        return
22240
d092f4b68fb6 push: use stepsdone to control bookmark push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22239
diff changeset
   712
    pushop.stepsdone.add('bookmarks')
20431
bebf8b8479f3 push: feed pushoperation object to _pushbookmark function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20352
diff changeset
   713
    ui = pushop.ui
bebf8b8479f3 push: feed pushoperation object to _pushbookmark function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20352
diff changeset
   714
    remote = pushop.remote
22239
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   715
    for b, old, new in pushop.outbookmarks:
0688010ee38f push: move bookmark discovery with other discovery steps
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22238
diff changeset
   716
        if remote.pushkey('bookmarks', b, old, new):
20352
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
   717
            ui.status(_("updating bookmark %s\n") % b)
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
   718
        else:
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
   719
            ui.warn(_('updating bookmark %s failed!\n') % b)
20469
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
   720
20472
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
   721
class pulloperation(object):
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
   722
    """A object that represent a single pull operation
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
   723
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
   724
    It purpose is to carry push related state and very common operation.
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
   725
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
   726
    A new should be created at the beginning of each pull and discarded
20472
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
   727
    afterward.
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
   728
    """
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
   729
20475
b79b405583af pull: move `force` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20474
diff changeset
   730
    def __init__(self, repo, remote, heads=None, force=False):
20596
004a1744088d exchange: fix docs for pulloperation
Siddharth Agarwal <sid0@fb.com>
parents: 20489
diff changeset
   731
        # repo we pull into
20472
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
   732
        self.repo = repo
20596
004a1744088d exchange: fix docs for pulloperation
Siddharth Agarwal <sid0@fb.com>
parents: 20489
diff changeset
   733
        # repo we pull from
20473
1516daaca632 pull: move `remote` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20472
diff changeset
   734
        self.remote = remote
20474
c9bceafc61be pull: move `heads` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20473
diff changeset
   735
        # revision we try to pull (None is "all")
c9bceafc61be pull: move `heads` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20473
diff changeset
   736
        self.heads = heads
20475
b79b405583af pull: move `force` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20474
diff changeset
   737
        # do we force pull?
b79b405583af pull: move `force` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20474
diff changeset
   738
        self.force = force
20477
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   739
        # the name the pull transaction
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   740
        self._trname = 'pull\n' + util.hidepassword(remote.url())
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   741
        # hold the transaction once created
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   742
        self._tr = None
20487
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   743
        # set of common changeset between local and remote before pull
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   744
        self.common = None
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   745
        # set of pulled head
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   746
        self.rheads = None
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
   747
        # list of missing changeset to fetch remotely
20488
76e66654f74e pull: move `fetch` subset into the object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20487
diff changeset
   748
        self.fetch = None
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
   749
        # result of changegroup pulling (used as return code by pull)
20898
f295b2ac3579 pull: move return code in the pull operation object
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20878
diff changeset
   750
        self.cgresult = None
20901
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
   751
        # list of step remaining todo (related to future bundle2 usage)
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
   752
        self.todosteps = set(['changegroup', 'phases', 'obsmarkers'])
20487
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   753
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   754
    @util.propertycache
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   755
    def pulledsubset(self):
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   756
        """heads of the set of changeset target by the pull"""
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   757
        # compute target subset
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   758
        if self.heads is None:
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   759
            # We pulled every thing possible
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   760
            # sync on everything common
20878
09e7118715eb pull: prevent duplicated entry in `op.pulledsubset`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20596
diff changeset
   761
            c = set(self.common)
09e7118715eb pull: prevent duplicated entry in `op.pulledsubset`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20596
diff changeset
   762
            ret = list(self.common)
09e7118715eb pull: prevent duplicated entry in `op.pulledsubset`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20596
diff changeset
   763
            for n in self.rheads:
09e7118715eb pull: prevent duplicated entry in `op.pulledsubset`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20596
diff changeset
   764
                if n not in c:
09e7118715eb pull: prevent duplicated entry in `op.pulledsubset`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20596
diff changeset
   765
                    ret.append(n)
09e7118715eb pull: prevent duplicated entry in `op.pulledsubset`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20596
diff changeset
   766
            return ret
20487
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   767
        else:
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   768
            # We pulled a specific subset
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   769
            # sync on this subset
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
   770
            return self.heads
20477
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   771
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   772
    def gettransaction(self):
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   773
        """get appropriate pull transaction, creating it if needed"""
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   774
        if self._tr is None:
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   775
            self._tr = self.repo.transaction(self._trname)
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   776
        return self._tr
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   777
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   778
    def closetransaction(self):
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   779
        """close transaction if created"""
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   780
        if self._tr is not None:
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   781
            self._tr.close()
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   782
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   783
    def releasetransaction(self):
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   784
        """release transaction if created"""
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   785
        if self._tr is not None:
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   786
            self._tr.release()
20469
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
   787
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
   788
def pull(repo, remote, heads=None, force=False):
20476
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   789
    pullop = pulloperation(repo, remote, heads, force)
20473
1516daaca632 pull: move `remote` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20472
diff changeset
   790
    if pullop.remote.local():
1516daaca632 pull: move `remote` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20472
diff changeset
   791
        missing = set(pullop.remote.requirements) - pullop.repo.supported
20469
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
   792
        if missing:
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
   793
            msg = _("required features are not"
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
   794
                    " supported in the destination:"
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
   795
                    " %s") % (', '.join(sorted(missing)))
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
   796
            raise util.Abort(msg)
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
   797
20472
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
   798
    lock = pullop.repo.lock()
20469
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
   799
    try:
20900
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
   800
        _pulldiscovery(pullop)
21256
750c7c14a637 bundle2: fix configuration name mismatch
Durham Goode <durham@fb.com>
parents: 21192
diff changeset
   801
        if (pullop.repo.ui.configbool('experimental', 'bundle2-exp', False)
21148
468cd774aa22 bundle2: require both client and server to opt in
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21146
diff changeset
   802
            and pullop.remote.capable('bundle2-exp')):
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   803
            _pullbundle2(pullop)
20901
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
   804
        if 'changegroup' in pullop.todosteps:
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
   805
            _pullchangeset(pullop)
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
   806
        if 'phases' in pullop.todosteps:
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
   807
            _pullphase(pullop)
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
   808
        if 'obsmarkers' in pullop.todosteps:
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
   809
            _pullobsolete(pullop)
20477
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   810
        pullop.closetransaction()
20469
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
   811
    finally:
20477
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   812
        pullop.releasetransaction()
20469
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
   813
        lock.release()
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
   814
20898
f295b2ac3579 pull: move return code in the pull operation object
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20878
diff changeset
   815
    return pullop.cgresult
20476
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   816
20900
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
   817
def _pulldiscovery(pullop):
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
   818
    """discovery phase for the pull
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
   819
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
   820
    Current handle changeset discovery only, will change handle all discovery
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
   821
    at some point."""
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
   822
    tmp = discovery.findcommonincoming(pullop.repo.unfiltered(),
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
   823
                                       pullop.remote,
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
   824
                                       heads=pullop.heads,
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
   825
                                       force=pullop.force)
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
   826
    pullop.common, pullop.fetch, pullop.rheads = tmp
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
   827
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   828
def _pullbundle2(pullop):
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   829
    """pull data using bundle2
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   830
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   831
    For now, the only supported data are changegroup."""
21658
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
   832
    remotecaps = bundle2.bundle2caps(pullop.remote)
21645
aed14bb165f3 bundle2: introduce a ``caps20to10`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21644
diff changeset
   833
    kwargs = {'bundlecaps': caps20to10(pullop.repo)}
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   834
    # pulling changegroup
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   835
    pullop.todosteps.remove('changegroup')
21259
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
   836
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
   837
    kwargs['common'] = pullop.common
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
   838
    kwargs['heads'] = pullop.heads or pullop.rheads
22352
dc371d1f0de1 pull: use the "cg" argument when pulling a bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22350
diff changeset
   839
    kwargs['cg'] = pullop.fetch
21658
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
   840
    if 'b2x:listkeys' in remotecaps:
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
   841
        kwargs['listkeys'] = ['phase']
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   842
    if not pullop.fetch:
21258
71931b789424 exchange: fix bad indentation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21257
diff changeset
   843
        pullop.repo.ui.status(_("no changes found\n"))
71931b789424 exchange: fix bad indentation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21257
diff changeset
   844
        pullop.cgresult = 0
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   845
    else:
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   846
        if pullop.heads is None and list(pullop.common) == [nullid]:
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   847
            pullop.repo.ui.status(_("requesting all changes\n"))
22354
a89add6c6b2f bundle2: pull obsmarkers relevant to the pulled set through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22353
diff changeset
   848
    if obsolete._enabled:
a89add6c6b2f bundle2: pull obsmarkers relevant to the pulled set through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22353
diff changeset
   849
        remoteversions = bundle2.obsmarkersversion(remotecaps)
a89add6c6b2f bundle2: pull obsmarkers relevant to the pulled set through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22353
diff changeset
   850
        if obsolete.commonversion(remoteversions) is not None:
a89add6c6b2f bundle2: pull obsmarkers relevant to the pulled set through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22353
diff changeset
   851
            kwargs['obsmarkers'] = True
a89add6c6b2f bundle2: pull obsmarkers relevant to the pulled set through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22353
diff changeset
   852
            pullop.todosteps.remove('obsmarkers')
21159
024f38f6d5f6 bundle2: allow extensions to extend the getbundle request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21158
diff changeset
   853
    _pullbundle2extraprepare(pullop, kwargs)
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   854
    if kwargs.keys() == ['format']:
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   855
        return # nothing to pull
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   856
    bundle = pullop.remote.getbundle('pull', **kwargs)
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   857
    try:
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   858
        op = bundle2.processbundle(pullop.repo, bundle, pullop.gettransaction)
21618
7568f5c1c801 bundle2: move exception classes into the error module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21617
diff changeset
   859
    except error.BundleValueError, exc:
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   860
        raise util.Abort('missing support for %s' % exc)
21259
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
   861
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
   862
    if pullop.fetch:
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
   863
        assert len(op.records['changegroup']) == 1
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
   864
        pullop.cgresult = op.records['changegroup'][0]['return']
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
   865
21658
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
   866
    # processing phases change
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
   867
    for namespace, value in op.records['listkeys']:
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
   868
        if namespace == 'phases':
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
   869
            _pullapplyphases(pullop, value)
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
   870
21159
024f38f6d5f6 bundle2: allow extensions to extend the getbundle request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21158
diff changeset
   871
def _pullbundle2extraprepare(pullop, kwargs):
024f38f6d5f6 bundle2: allow extensions to extend the getbundle request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21158
diff changeset
   872
    """hook function so that extensions can extend the getbundle call"""
024f38f6d5f6 bundle2: allow extensions to extend the getbundle request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21158
diff changeset
   873
    pass
024f38f6d5f6 bundle2: allow extensions to extend the getbundle request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21158
diff changeset
   874
20489
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   875
def _pullchangeset(pullop):
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   876
    """pull changeset from unbundle into the local repo"""
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   877
    # We delay the open of the transaction as late as possible so we
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   878
    # don't open transaction for nothing or you break future useful
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   879
    # rollback call
20901
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
   880
    pullop.todosteps.remove('changegroup')
20899
d62319f91cb7 pull: move the cgresult logic in _pullchangeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20898
diff changeset
   881
    if not pullop.fetch:
d62319f91cb7 pull: move the cgresult logic in _pullchangeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20898
diff changeset
   882
            pullop.repo.ui.status(_("no changes found\n"))
d62319f91cb7 pull: move the cgresult logic in _pullchangeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20898
diff changeset
   883
            pullop.cgresult = 0
d62319f91cb7 pull: move the cgresult logic in _pullchangeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20898
diff changeset
   884
            return
20489
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   885
    pullop.gettransaction()
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   886
    if pullop.heads is None and list(pullop.common) == [nullid]:
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   887
        pullop.repo.ui.status(_("requesting all changes\n"))
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   888
    elif pullop.heads is None and pullop.remote.capable('changegroupsubset'):
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   889
        # issue1320, avoid a race if remote changed after discovery
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   890
        pullop.heads = pullop.rheads
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   891
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   892
    if pullop.remote.capable('getbundle'):
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   893
        # TODO: get bundlecaps from remote
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   894
        cg = pullop.remote.getbundle('pull', common=pullop.common,
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   895
                                     heads=pullop.heads or pullop.rheads)
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   896
    elif pullop.heads is None:
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   897
        cg = pullop.remote.changegroup(pullop.fetch, 'pull')
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   898
    elif not pullop.remote.capable('changegroupsubset'):
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   899
        raise util.Abort(_("partial pull cannot be done because "
21554
7bcf4adadd2d exchange: fix indentation level
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21259
diff changeset
   900
                           "other repository doesn't support "
7bcf4adadd2d exchange: fix indentation level
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21259
diff changeset
   901
                           "changegroupsubset."))
20489
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   902
    else:
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   903
        cg = pullop.remote.changegroupsubset(pullop.fetch, pullop.heads, 'pull')
20933
d3775db748a0 localrepo: move the addchangegroup method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20928
diff changeset
   904
    pullop.cgresult = changegroup.addchangegroup(pullop.repo, cg, 'pull',
20899
d62319f91cb7 pull: move the cgresult logic in _pullchangeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20898
diff changeset
   905
                                                 pullop.remote.url())
20489
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
   906
20486
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
   907
def _pullphase(pullop):
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
   908
    # Get remote phases data from remote
21654
ddf9a00c1239 pull: split remote phases retrieval from actual application
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21645
diff changeset
   909
    remotephases = pullop.remote.listkeys('phases')
ddf9a00c1239 pull: split remote phases retrieval from actual application
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21645
diff changeset
   910
    _pullapplyphases(pullop, remotephases)
ddf9a00c1239 pull: split remote phases retrieval from actual application
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21645
diff changeset
   911
ddf9a00c1239 pull: split remote phases retrieval from actual application
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21645
diff changeset
   912
def _pullapplyphases(pullop, remotephases):
ddf9a00c1239 pull: split remote phases retrieval from actual application
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21645
diff changeset
   913
    """apply phase movement from observed remote state"""
20901
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
   914
    pullop.todosteps.remove('phases')
20486
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
   915
    publishing = bool(remotephases.get('publishing', False))
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
   916
    if remotephases and not publishing:
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
   917
        # remote is new and unpublishing
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
   918
        pheads, _dr = phases.analyzeremotephases(pullop.repo,
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
   919
                                                 pullop.pulledsubset,
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
   920
                                                 remotephases)
22068
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   921
        dheads = pullop.pulledsubset
20486
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
   922
    else:
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
   923
        # Remote is old or publishing all common changesets
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
   924
        # should be seen as public
22068
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   925
        pheads = pullop.pulledsubset
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   926
        dheads = []
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   927
    unfi = pullop.repo.unfiltered()
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   928
    phase = unfi._phasecache.phase
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   929
    rev = unfi.changelog.nodemap.get
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   930
    public = phases.public
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   931
    draft = phases.draft
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   932
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   933
    # exclude changesets already public locally and update the others
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   934
    pheads = [pn for pn in pheads if phase(unfi, rev(pn)) > public]
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   935
    if pheads:
22069
616a455b02ca phase: add a transaction argument to advanceboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22068
diff changeset
   936
        tr = pullop.gettransaction()
616a455b02ca phase: add a transaction argument to advanceboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22068
diff changeset
   937
        phases.advanceboundary(pullop.repo, tr, public, pheads)
22068
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   938
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   939
    # exclude changesets already draft locally and update the others
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   940
    dheads = [pn for pn in dheads if phase(unfi, rev(pn)) > draft]
d34058dd3246 pull: pre-filter remote phases before moving local ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   941
    if dheads:
22069
616a455b02ca phase: add a transaction argument to advanceboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22068
diff changeset
   942
        tr = pullop.gettransaction()
616a455b02ca phase: add a transaction argument to advanceboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22068
diff changeset
   943
        phases.advanceboundary(pullop.repo, tr, draft, dheads)
20486
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
   944
20478
80628d4069be push: feed pulloperation object to _pullobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20477
diff changeset
   945
def _pullobsolete(pullop):
20476
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   946
    """utility function to pull obsolete markers from a remote
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   947
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   948
    The `gettransaction` is function that return the pull transaction, creating
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   949
    one if necessary. We return the transaction to inform the calling code that
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   950
    a new transaction have been created (when applicable).
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   951
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   952
    Exists mostly to allow overriding for experimentation purpose"""
20901
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
   953
    pullop.todosteps.remove('obsmarkers')
20476
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   954
    tr = None
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   955
    if obsolete._enabled:
20478
80628d4069be push: feed pulloperation object to _pullobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20477
diff changeset
   956
        pullop.repo.ui.debug('fetching remote obsolete markers\n')
80628d4069be push: feed pulloperation object to _pullobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20477
diff changeset
   957
        remoteobs = pullop.remote.listkeys('obsolete')
20476
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   958
        if 'dump0' in remoteobs:
20478
80628d4069be push: feed pulloperation object to _pullobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20477
diff changeset
   959
            tr = pullop.gettransaction()
20476
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   960
            for key in sorted(remoteobs, reverse=True):
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   961
                if key.startswith('dump'):
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   962
                    data = base85.b85decode(remoteobs[key])
20478
80628d4069be push: feed pulloperation object to _pullobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20477
diff changeset
   963
                    pullop.repo.obsstore.mergemarkers(tr, data)
80628d4069be push: feed pulloperation object to _pullobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20477
diff changeset
   964
            pullop.repo.invalidatevolatilesets()
20476
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   965
    return tr
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
   966
21645
aed14bb165f3 bundle2: introduce a ``caps20to10`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21644
diff changeset
   967
def caps20to10(repo):
aed14bb165f3 bundle2: introduce a ``caps20to10`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21644
diff changeset
   968
    """return a set with appropriate options to use bundle20 during getbundle"""
aed14bb165f3 bundle2: introduce a ``caps20to10`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21644
diff changeset
   969
    caps = set(['HG2X'])
22342
262c5cc126c1 bundle2: introduce a `getrepocaps` to retrieve the bundle2 caps of a repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22341
diff changeset
   970
    capsblob = bundle2.encodecaps(bundle2.getrepocaps(repo))
21645
aed14bb165f3 bundle2: introduce a ``caps20to10`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21644
diff changeset
   971
    caps.add('bundle2=' + urllib.quote(capsblob))
aed14bb165f3 bundle2: introduce a ``caps20to10`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21644
diff changeset
   972
    return caps
aed14bb165f3 bundle2: introduce a ``caps20to10`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21644
diff changeset
   973
22542
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   974
# List of names of steps to perform for a bundle2 for getbundle, order matters.
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   975
getbundle2partsorder = []
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   976
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   977
# Mapping between step name and function
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   978
#
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   979
# This exists to help extensions wrap steps if necessary
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   980
getbundle2partsmapping = {}
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   981
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   982
def getbundle2partsgenerator(stepname):
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   983
    """decorator for function generating bundle2 part for getbundle
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   984
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   985
    The function is added to the step -> function mapping and appended to the
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   986
    list of steps.  Beware that decorated functions will be added in order
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   987
    (this may matter).
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   988
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   989
    You can only use this decorator for new steps, if you want to wrap a step
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   990
    from an extension, attack the getbundle2partsmapping dictionary directly."""
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   991
    def dec(func):
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   992
        assert stepname not in getbundle2partsmapping
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   993
        getbundle2partsmapping[stepname] = func
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   994
        getbundle2partsorder.append(stepname)
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   995
        return func
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   996
    return dec
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
   997
21157
60ad2ea5b106 getbundle: pass arbitrary arguments all along the call chain
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21156
diff changeset
   998
def getbundle(repo, source, heads=None, common=None, bundlecaps=None,
60ad2ea5b106 getbundle: pass arbitrary arguments all along the call chain
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21156
diff changeset
   999
              **kwargs):
20954
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
  1000
    """return a full bundle (with potentially multiple kind of parts)
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
  1001
21144
7a20fe8dc080 bundle2: use HG2X in the header
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21143
diff changeset
  1002
    Could be a bundle HG10 or a bundle HG2X depending on bundlecaps
20954
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
  1003
    passed. For now, the bundle can contain only changegroup, but this will
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
  1004
    changes when more part type will be available for bundle2.
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
  1005
22390
e2806b8613ca changegroup: rename bundle-related functions and classes
Sune Foldager <cryo@cyanite.org>
parents: 22354
diff changeset
  1006
    This is different from changegroup.getchangegroup that only returns an HG10
20954
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
  1007
    changegroup bundle. They may eventually get reunited in the future when we
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
  1008
    have a clearer idea of the API we what to query different data.
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
  1009
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
  1010
    The implementation is at a very early stage and will get massive rework
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
  1011
    when the API of bundle is refined.
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
  1012
    """
22542
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1013
    # bundle10 case
21144
7a20fe8dc080 bundle2: use HG2X in the header
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21143
diff changeset
  1014
    if bundlecaps is None or 'HG2X' not in bundlecaps:
22542
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1015
        if bundlecaps and not kwargs.get('cg', True):
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1016
            raise ValueError(_('request for bundle10 must include changegroup'))
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1017
21656
36200dc6b3bd getbundle: raise error if extra arguments are provided for bundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21654
diff changeset
  1018
        if kwargs:
36200dc6b3bd getbundle: raise error if extra arguments are provided for bundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21654
diff changeset
  1019
            raise ValueError(_('unsupported getbundle arguments: %s')
36200dc6b3bd getbundle: raise error if extra arguments are provided for bundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21654
diff changeset
  1020
                             % ', '.join(sorted(kwargs.keys())))
22542
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1021
        return changegroup.getchangegroup(repo, source, heads=heads,
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1022
                                          common=common, bundlecaps=bundlecaps)
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1023
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1024
    # bundle20 case
21143
5bb5d4ba14e5 bundle2: transmit capabilities to getbundle during pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21142
diff changeset
  1025
    b2caps = {}
5bb5d4ba14e5 bundle2: transmit capabilities to getbundle during pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21142
diff changeset
  1026
    for bcaps in bundlecaps:
5bb5d4ba14e5 bundle2: transmit capabilities to getbundle during pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21142
diff changeset
  1027
        if bcaps.startswith('bundle2='):
5bb5d4ba14e5 bundle2: transmit capabilities to getbundle during pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21142
diff changeset
  1028
            blob = urllib.unquote(bcaps[len('bundle2='):])
5bb5d4ba14e5 bundle2: transmit capabilities to getbundle during pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21142
diff changeset
  1029
            b2caps.update(bundle2.decodecaps(blob))
5bb5d4ba14e5 bundle2: transmit capabilities to getbundle during pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21142
diff changeset
  1030
    bundler = bundle2.bundle20(repo.ui, b2caps)
22542
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1031
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1032
    for name in getbundle2partsorder:
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1033
        func = getbundle2partsmapping[name]
22543
6a669d5a62b8 bundle2: remove heads and common arguments to getbundle parts generators
Mike Hommey <mh@glandium.org>
parents: 22542
diff changeset
  1034
        kwargs['heads'] = heads
6a669d5a62b8 bundle2: remove heads and common arguments to getbundle parts generators
Mike Hommey <mh@glandium.org>
parents: 22542
diff changeset
  1035
        kwargs['common'] = common
6a669d5a62b8 bundle2: remove heads and common arguments to getbundle parts generators
Mike Hommey <mh@glandium.org>
parents: 22542
diff changeset
  1036
        func(bundler, repo, source, bundlecaps=bundlecaps, b2caps=b2caps,
6a669d5a62b8 bundle2: remove heads and common arguments to getbundle parts generators
Mike Hommey <mh@glandium.org>
parents: 22542
diff changeset
  1037
             **kwargs)
22542
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1038
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1039
    return util.chunkbuffer(bundler.getchunks())
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1040
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1041
@getbundle2partsgenerator('changegroup')
22543
6a669d5a62b8 bundle2: remove heads and common arguments to getbundle parts generators
Mike Hommey <mh@glandium.org>
parents: 22542
diff changeset
  1042
def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None,
6a669d5a62b8 bundle2: remove heads and common arguments to getbundle parts generators
Mike Hommey <mh@glandium.org>
parents: 22542
diff changeset
  1043
                              b2caps=None, heads=None, common=None, **kwargs):
22542
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1044
    """add a changegroup part to the requested bundle"""
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1045
    cg = None
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1046
    if kwargs.get('cg', True):
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1047
        # build changegroup bundle here.
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1048
        cg = changegroup.getchangegroup(repo, source, heads=heads,
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1049
                                        common=common, bundlecaps=bundlecaps)
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1050
21259
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
  1051
    if cg:
21600
5e08f3b65510 bundle2: update all ``addpart`` callers to ``newpart``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21555
diff changeset
  1052
        bundler.newpart('b2x:changegroup', data=cg.getchunks())
22542
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1053
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1054
@getbundle2partsgenerator('listkeys')
22543
6a669d5a62b8 bundle2: remove heads and common arguments to getbundle parts generators
Mike Hommey <mh@glandium.org>
parents: 22542
diff changeset
  1055
def _getbundlelistkeysparts(bundler, repo, source, bundlecaps=None,
6a669d5a62b8 bundle2: remove heads and common arguments to getbundle parts generators
Mike Hommey <mh@glandium.org>
parents: 22542
diff changeset
  1056
                            b2caps=None, **kwargs):
22542
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1057
    """add parts containing listkeys namespaces to the requested bundle"""
21657
0ff44e06275d getbundle: support of listkeys argument when bundle2 is used
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21656
diff changeset
  1058
    listkeys = kwargs.get('listkeys', ())
0ff44e06275d getbundle: support of listkeys argument when bundle2 is used
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21656
diff changeset
  1059
    for namespace in listkeys:
0ff44e06275d getbundle: support of listkeys argument when bundle2 is used
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21656
diff changeset
  1060
        part = bundler.newpart('b2x:listkeys')
0ff44e06275d getbundle: support of listkeys argument when bundle2 is used
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21656
diff changeset
  1061
        part.addparam('namespace', namespace)
0ff44e06275d getbundle: support of listkeys argument when bundle2 is used
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21656
diff changeset
  1062
        keys = repo.listkeys(namespace).items()
0ff44e06275d getbundle: support of listkeys argument when bundle2 is used
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21656
diff changeset
  1063
        part.data = pushkey.encodekeys(keys)
20967
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
  1064
22542
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1065
@getbundle2partsgenerator('obsmarkers')
22543
6a669d5a62b8 bundle2: remove heads and common arguments to getbundle parts generators
Mike Hommey <mh@glandium.org>
parents: 22542
diff changeset
  1066
def _getbundleobsmarkerpart(bundler, repo, source, bundlecaps=None,
6a669d5a62b8 bundle2: remove heads and common arguments to getbundle parts generators
Mike Hommey <mh@glandium.org>
parents: 22542
diff changeset
  1067
                            b2caps=None, heads=None, **kwargs):
22541
4e1a80c022a4 bundle2: pass b2caps down to functions adding bundle2 parts for getbundle
Mike Hommey <mh@glandium.org>
parents: 22390
diff changeset
  1068
    """add an obsolescence markers part to the requested bundle"""
22353
47e3420ae889 getbundle: add `obsmarkers` argument to getbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22352
diff changeset
  1069
    if kwargs.get('obsmarkers', False):
47e3420ae889 getbundle: add `obsmarkers` argument to getbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22352
diff changeset
  1070
        if heads is None:
47e3420ae889 getbundle: add `obsmarkers` argument to getbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22352
diff changeset
  1071
            heads = repo.heads()
47e3420ae889 getbundle: add `obsmarkers` argument to getbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22352
diff changeset
  1072
        subset = [c.node() for c in repo.set('::%ln', heads)]
47e3420ae889 getbundle: add `obsmarkers` argument to getbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22352
diff changeset
  1073
        markers = repo.obsstore.relevantmarkers(subset)
47e3420ae889 getbundle: add `obsmarkers` argument to getbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22352
diff changeset
  1074
        buildobsmarkerspart(bundler, markers)
47e3420ae889 getbundle: add `obsmarkers` argument to getbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22352
diff changeset
  1075
22542
6b180a0c703e bundle2: separate bundle10 and bundle2 cases in getbundle()
Mike Hommey <mh@glandium.org>
parents: 22541
diff changeset
  1076
@getbundle2partsgenerator('extra')
22543
6a669d5a62b8 bundle2: remove heads and common arguments to getbundle parts generators
Mike Hommey <mh@glandium.org>
parents: 22542
diff changeset
  1077
def _getbundleextrapart(bundler, repo, source, bundlecaps=None,
6a669d5a62b8 bundle2: remove heads and common arguments to getbundle parts generators
Mike Hommey <mh@glandium.org>
parents: 22542
diff changeset
  1078
                        b2caps=None, **kwargs):
21158
8f6530b62177 bundle2: add a way to add parts during a `getbundle` request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21157
diff changeset
  1079
    """hook function to let extensions add parts to the requested bundle"""
8f6530b62177 bundle2: add a way to add parts during a `getbundle` request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21157
diff changeset
  1080
    pass
8f6530b62177 bundle2: add a way to add parts during a `getbundle` request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21157
diff changeset
  1081
20967
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
  1082
def check_heads(repo, their_heads, context):
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
  1083
    """check if the heads of a repo have been modified
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
  1084
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
  1085
    Used by peer for unbundling.
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
  1086
    """
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
  1087
    heads = repo.heads()
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
  1088
    heads_hash = util.sha1(''.join(sorted(heads))).digest()
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
  1089
    if not (their_heads == ['force'] or their_heads == heads or
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
  1090
            their_heads == ['hashed', heads_hash]):
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
  1091
        # someone else committed/pushed/unbundled while we
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
  1092
        # were transferring data
21184
28d76afa1568 bundle2: fix raising errors during heads checking
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21182
diff changeset
  1093
        raise error.PushRaced('repository changed while %s - '
28d76afa1568 bundle2: fix raising errors during heads checking
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21182
diff changeset
  1094
                              'please try again' % context)
20968
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1095
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1096
def unbundle(repo, cg, heads, source, url):
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1097
    """Apply a bundle to a repo.
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1098
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1099
    this function makes sure the repo is locked during the application and have
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
  1100
    mechanism to check that no push race occurred between the creation of the
20968
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1101
    bundle and its application.
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1102
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1103
    If the push was raced as PushRaced exception is raised."""
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1104
    r = 0
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
  1105
    # need a transaction when processing a bundle2 stream
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
  1106
    tr = None
20968
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1107
    lock = repo.lock()
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1108
    try:
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1109
        check_heads(repo, heads, 'uploading changes')
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1110
        # push can proceed
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
  1111
        if util.safehasattr(cg, 'params'):
21187
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
  1112
            try:
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
  1113
                tr = repo.transaction('unbundle')
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
  1114
                tr.hookargs['bundle2-exp'] = '1'
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
  1115
                r = bundle2.processbundle(repo, cg, lambda: tr).reply
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
  1116
                cl = repo.unfiltered().changelog
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
  1117
                p = cl.writepending() and repo.root or ""
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
  1118
                repo.hook('b2x-pretransactionclose', throw=True, source=source,
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
  1119
                          url=url, pending=p, **tr.hookargs)
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
  1120
                tr.close()
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
  1121
                repo.hook('b2x-transactionclose', source=source, url=url,
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
  1122
                          **tr.hookargs)
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
  1123
            except Exception, exc:
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
  1124
                exc.duringunbundle2 = True
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
  1125
                raise
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
  1126
        else:
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
  1127
            r = changegroup.addchangegroup(repo, cg, source, url)
20968
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1128
    finally:
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
  1129
        if tr is not None:
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
  1130
            tr.release()
20968
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1131
        lock.release()
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
  1132
    return r