mercurial/discovery.py
author Javi Merino <cibervicho@gmail.com>
Tue, 01 Feb 2011 07:29:11 +0000
branchstable
changeset 13330 551856dea9a6
parent 12762 8bac8cd43c8d
child 12997 a50606327538
permissions -rw-r--r--
win32mbcs: Fix typo in documentation extention -> extension
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11313
0bb14798cd07 discovery: fix description line
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11301
diff changeset
     1
# discovery.py - protocol changeset discovery functions
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     2
#
11313
0bb14798cd07 discovery: fix description line
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11301
diff changeset
     3
# Copyright 2010 Matt Mackall <mpm@selenic.com>
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8210
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9954
diff changeset
     6
# GNU General Public License version 2 or any later version.
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     7
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
     8
from node import nullid, short
3891
6b4127c7d52a Simplify i18n imports
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
     9
from i18n import _
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    10
import util, error
8109
496ae1ea4698 switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 8108
diff changeset
    11
12760
b41e8dfee66e discovery: remove unused "base" argument from find.*incoming()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12759
diff changeset
    12
def findcommonincoming(repo, remote, heads=None, force=False):
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    13
    """Return a tuple (common, missing roots, heads) used to identify
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    14
    missing nodes from remote.
2601
00fc88b0b256 move most of tag code to localrepository class.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2581
diff changeset
    15
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    16
    If a list of heads is specified, return only nodes which are heads
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    17
    or ancestors of these heads.
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    18
    """
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    19
    m = repo.changelog.nodemap
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    20
    search = []
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    21
    fetch = set()
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    22
    seen = set()
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    23
    seenbranch = set()
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
    24
    base = set()
5657
47915bf68c44 Properly check tag's existence as a local/global tag when removing it.
Osku Salerma <osku@iki.fi>
parents: 5637
diff changeset
    25
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    26
    if not heads:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    27
        heads = remote.heads()
343
d7df759d0e97 rework all code using tags
mpm@selenic.com
parents: 337
diff changeset
    28
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    29
    if repo.changelog.tip() == nullid:
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
    30
        base.add(nullid)
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    31
        if heads != [nullid]:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    32
            return [nullid], [nullid], list(heads)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    33
        return [nullid], [], []
3826
b3b868113d24 fix encoding conversion of branch names when mq is loaded
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3803
diff changeset
    34
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    35
    # assume we're closer to the tip than the root
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    36
    # and start by examining the heads
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    37
    repo.ui.status(_("searching for changes\n"))
6121
7336aeff1a1d automatically update the branch cache when tip changes
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 6120
diff changeset
    38
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    39
    unknown = []
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    40
    for h in heads:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    41
        if h not in m:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    42
            unknown.append(h)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    43
        else:
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
    44
            base.add(h)
7654
816b708f23af store all heads of a branch in the branch cache
John Mulligan <phlogistonjohn@asynchrono.us>
parents: 7644
diff changeset
    45
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    46
    heads = unknown
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    47
    if not unknown:
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
    48
        return list(base), [], []
4415
1a63b44f90c9 branch.cache: silently ignore I/O and OS errors
Matt Mackall <mpm@selenic.com>
parents: 4329
diff changeset
    49
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    50
    req = set(unknown)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    51
    reqcnt = 0
3417
028fff46a4ac Add branchtags function with cache
Matt Mackall <mpm@selenic.com>
parents: 3377
diff changeset
    52
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    53
    # search through remote branches
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    54
    # a 'branch' here is a linear segment of history, with four parts:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    55
    # head, root, first parent, second parent
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    56
    # (a branch always has two parents (or none) by definition)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    57
    unknown = remote.branches(unknown)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    58
    while unknown:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    59
        r = []
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    60
        while unknown:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    61
            n = unknown.pop(0)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    62
            if n[0] in seen:
8954
e67e5b60e55f Branch heads should not include "heads" that are ancestors of other heads.
Brendan Cully <brendan@kublai.com>
parents: 8916
diff changeset
    63
                continue
1806
a2c69737e65e Automatic nesting into running transactions in the same repository.
mason@suse.com
parents: 1802
diff changeset
    64
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    65
            repo.ui.debug("examining %s:%s\n"
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    66
                          % (short(n[0]), short(n[1])))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    67
            if n[0] == nullid: # found the end of the branch
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    68
                pass
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    69
            elif n in seenbranch:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    70
                repo.ui.debug("branch already found\n")
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    71
                continue
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    72
            elif n[1] and n[1] in m: # do we know the base?
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    73
                repo.ui.debug("found incomplete branch %s:%s\n"
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    74
                              % (short(n[0]), short(n[1])))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    75
                search.append(n[0:2]) # schedule branch range for scanning
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    76
                seenbranch.add(n)
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4914
diff changeset
    77
            else:
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    78
                if n[1] not in seen and n[1] not in fetch:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    79
                    if n[2] in m and n[3] in m:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    80
                        repo.ui.debug("found new changeset %s\n" %
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    81
                                      short(n[1]))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    82
                        fetch.add(n[1]) # earliest unknown
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    83
                    for p in n[2:4]:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    84
                        if p in m:
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
    85
                            base.add(p) # latest known
1531
2ba8bf7defda add localrepo.wlock for protecting the dirstate
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1516
diff changeset
    86
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    87
                for p in n[2:4]:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    88
                    if p not in req and p not in m:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    89
                        r.append(p)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    90
                        req.add(p)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    91
            seen.add(n[0])
1716
ef8cd889a78b Refactor excessive merge detection, add test
Matt Mackall <mpm@selenic.com>
parents: 1713
diff changeset
    92
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    93
        if r:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    94
            reqcnt += 1
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    95
            repo.ui.progress(_('searching'), reqcnt, unit=_('queries'))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    96
            repo.ui.debug("request %d: %s\n" %
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    97
                        (reqcnt, " ".join(map(short, r))))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    98
            for p in xrange(0, len(r), 10):
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    99
                for b in remote.branches(r[p:p + 10]):
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   100
                    repo.ui.debug("received %s:%s\n" %
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   101
                                  (short(b[0]), short(b[1])))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   102
                    unknown.append(b)
8404
a2bc39ade36b commit: move 'nothing changed' test into commit()
Matt Mackall <mpm@selenic.com>
parents: 8403
diff changeset
   103
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   104
    # do binary search on the branches we found
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   105
    while search:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   106
        newsearch = []
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   107
        reqcnt += 1
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   108
        repo.ui.progress(_('searching'), reqcnt, unit=_('queries'))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   109
        for n, l in zip(search, remote.between(search)):
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   110
            l.append(n[1])
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   111
            p = n[0]
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   112
            f = 1
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   113
            for i in l:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   114
                repo.ui.debug("narrowing %d:%d %s\n" % (f, len(l), short(i)))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   115
                if i in m:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   116
                    if f <= 2:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   117
                        repo.ui.debug("found new branch changeset %s\n" %
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   118
                                          short(p))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   119
                        fetch.add(p)
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
   120
                        base.add(i)
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4914
diff changeset
   121
                    else:
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   122
                        repo.ui.debug("narrowed branch search to %s:%s\n"
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   123
                                      % (short(p), short(i)))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   124
                        newsearch.append((p, i))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   125
                    break
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   126
                p, f = i, f * 2
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   127
            search = newsearch
9150
09a1ee498756 localrepo: add destroyed() method for strip/rollback to use (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
   128
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   129
    # sanity check our fetch list
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   130
    for f in fetch:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   131
        if f in m:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   132
            raise error.RepoError(_("already have changeset ")
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   133
                                  + short(f[:4]))
4912
312c845edef5 simplify dirstate fixups in repo.status()
Matt Mackall <mpm@selenic.com>
parents: 4910
diff changeset
   134
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
   135
    base = list(base)
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
   136
    if base == [nullid]:
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   137
        if force:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   138
            repo.ui.warn(_("warning: repository is unrelated\n"))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   139
        else:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   140
            raise util.Abort(_("repository is unrelated"))
4372
4ddc6d374265 localrepository.status: only acquire wlock if actually needed.
Bryan O'Sullivan <bos@serpentine.com>
parents: 4335
diff changeset
   141
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   142
    repo.ui.debug("found new changesets starting at " +
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   143
                 " ".join([short(f) for f in fetch]) + "\n")
2661
5c10b7ed3411 status: add -c (clean) and -A (all files) options
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2621
diff changeset
   144
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   145
    repo.ui.progress(_('searching'), None)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   146
    repo.ui.debug("%d total queries\n" % reqcnt)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   147
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
   148
    return base, list(fetch), heads
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   149
11576
98c874a929f1 discovery: simplify findoutgoing(), the updated_head stuff wasn't used
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11574
diff changeset
   150
def findoutgoing(repo, remote, base=None, remoteheads=None, force=False):
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   151
    """Return list of nodes that are roots of subsets not in remote
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   152
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   153
    If base dict is specified, assume that these nodes and their parents
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   154
    exist on the remote side.
11576
98c874a929f1 discovery: simplify findoutgoing(), the updated_head stuff wasn't used
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11574
diff changeset
   155
    If remotehead is specified, assume it is the list of the heads from
98c874a929f1 discovery: simplify findoutgoing(), the updated_head stuff wasn't used
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11574
diff changeset
   156
    the remote repository.
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   157
    """
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   158
    if base is None:
12759
9c5794223340 discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11578
diff changeset
   159
        base = findcommonincoming(repo, remote, heads=remoteheads,
9c5794223340 discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11578
diff changeset
   160
                                  force=force)[0]
9c5794223340 discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11578
diff changeset
   161
    else:
9c5794223340 discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11578
diff changeset
   162
        base = list(base)
2339
11422943cf72 document and fix findincoming
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2335
diff changeset
   163
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   164
    repo.ui.debug("common changesets up to "
12759
9c5794223340 discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11578
diff changeset
   165
                  + " ".join(map(short, base)) + "\n")
2108
30c7564f6dfc Move empty local repo logic for pull into findincoming
Matt Mackall <mpm@selenic.com>
parents: 2107
diff changeset
   166
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   167
    remain = set(repo.changelog.nodemap)
148
c32286d0a665 Improve pruning of branches in outstanding changeset algorithm
mpm@selenic.com
parents: 146
diff changeset
   168
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   169
    # prune everything remote has from the tree
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   170
    remain.remove(nullid)
12759
9c5794223340 discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11578
diff changeset
   171
    remove = base
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   172
    while remove:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   173
        n = remove.pop(0)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   174
        if n in remain:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   175
            remain.remove(n)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   176
            for p in repo.changelog.parents(n):
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   177
                remove.append(p)
65
d40cc5aacc31 Fix up a bunch of bugs in the new merge code
mpm@selenic.com
parents: 64
diff changeset
   178
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   179
    # find every node whose parents have been pruned
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   180
    subset = []
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   181
    # find every remote head that will get new children
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   182
    for n in remain:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   183
        p1, p2 = repo.changelog.parents(n)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   184
        if p1 not in remain and p2 not in remain:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   185
            subset.append(n)
7415
6163ef936a00 protocol: use changegroupsubset() if possible (issue1389)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7377
diff changeset
   186
11576
98c874a929f1 discovery: simplify findoutgoing(), the updated_head stuff wasn't used
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11574
diff changeset
   187
    return subset
3684
975c2469c316 correct remote heads test in prepush
Matt Mackall <mpm@selenic.com>
parents: 3682
diff changeset
   188
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   189
def prepush(repo, remote, force, revs, newbranch):
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   190
    '''Analyze the local and remote repositories and determine which
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   191
    changesets need to be pushed to the remote. Return value depends
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   192
    on circumstances:
10353
36b6b5ef7820 prepush: rename variables, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10327
diff changeset
   193
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   194
    If we are not going to push anything, return a tuple (None,
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   195
    outgoing) where outgoing is 0 if there are no outgoing
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   196
    changesets and 1 if there are, but we refuse to push them
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   197
    (e.g. would create new remote heads).
3684
975c2469c316 correct remote heads test in prepush
Matt Mackall <mpm@selenic.com>
parents: 3682
diff changeset
   198
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   199
    Otherwise, return a tuple (changegroup, remoteheads), where
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   200
    changegroup is a readable file-like object whose read() returns
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   201
    successive changegroup chunks ready to be sent over the wire and
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   202
    remoteheads is the list of remote heads.'''
11577
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   203
    remoteheads = remote.heads()
12759
9c5794223340 discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11578
diff changeset
   204
    common, inc, rheads = findcommonincoming(repo, remote, heads=remoteheads,
9c5794223340 discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11578
diff changeset
   205
                                             force=force)
2439
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2424
diff changeset
   206
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   207
    cl = repo.changelog
11577
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   208
    update = findoutgoing(repo, remote, common, remoteheads)
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   209
    outg, bases, heads = cl.nodesbetween(update, revs)
2439
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2424
diff changeset
   210
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   211
    if not bases:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   212
        repo.ui.status(_("no changes found\n"))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   213
        return None, 1
622
e9fe5d5e67f7 Add generic repo commands for pull and push
Matt Mackall <mpm@selenic.com>
parents: 621
diff changeset
   214
11577
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   215
    if not force and remoteheads != [nullid]:
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   216
        if remote.capable('branchmap'):
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   217
            # Check for each named branch if we're creating new remote heads.
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   218
            # To be a remote head after push, node must be either:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   219
            # - unknown locally
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   220
            # - a local outgoing head descended from update
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   221
            # - a remote head that's known locally and not
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   222
            #   ancestral to an outgoing head
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   223
            #
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   224
            # New named branches cannot be created without --force.
10405
2d30d66a89ad whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 10396
diff changeset
   225
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   226
            # 1. Create set of branches involved in the push.
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   227
            branches = set(repo[n].branch() for n in outg)
1466
b6d9ea0bc107 Added a lot of comments to changegroupsubset.
Eric Hopper <hopper@omnifarious.org>
parents: 1464
diff changeset
   228
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   229
            # 2. Check for new branches on the remote.
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   230
            remotemap = remote.branchmap()
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   231
            newbranches = branches - set(remotemap)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   232
            if newbranches and not newbranch: # new branch requires --new-branch
11429
d420ff348c49 discovery: use stable sort order in --new-branch warning
Martin Geisler <mg@aragost.com>
parents: 11313
diff changeset
   233
                branchnames = ', '.join(sorted(newbranches))
11574
6381fa7bfa53 Abort: add a hint argument, printed in the next line inside parenthesis
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11573
diff changeset
   234
                raise util.Abort(_("push creates new remote branches: %s!")
6381fa7bfa53 Abort: add a hint argument, printed in the next line inside parenthesis
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11573
diff changeset
   235
                                   % branchnames,
6381fa7bfa53 Abort: add a hint argument, printed in the next line inside parenthesis
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11573
diff changeset
   236
                                 hint=_("use 'hg push --new-branch' to create"
6381fa7bfa53 Abort: add a hint argument, printed in the next line inside parenthesis
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11573
diff changeset
   237
                                        " new remote branches"))
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   238
            branches.difference_update(newbranches)
1458
1033892bbb87 This changes the revlog.group and re-implements the localrepo.changeroup
Eric Hopper <hopper@omnifarious.org>
parents: 1457
diff changeset
   239
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   240
            # 3. Construct the initial oldmap and newmap dicts.
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   241
            # They contain information about the remote heads before and
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   242
            # after the push, respectively.
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   243
            # Heads not found locally are not included in either dict,
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   244
            # since they won't be affected by the push.
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   245
            # unsynced contains all branches with incoming changesets.
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   246
            oldmap = {}
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   247
            newmap = {}
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   248
            unsynced = set()
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   249
            for branch in branches:
11577
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   250
                remotebrheads = remotemap[branch]
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   251
                prunedbrheads = [h for h in remotebrheads if h in cl.nodemap]
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   252
                oldmap[branch] = prunedbrheads
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   253
                newmap[branch] = list(prunedbrheads)
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   254
                if len(remotebrheads) > len(prunedbrheads):
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   255
                    unsynced.add(branch)
635
85e2209d401c Protocol switch from using generators to stream-like objects.
Matt Mackall <mpm@selenic.com>
parents: 634
diff changeset
   256
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   257
            # 4. Update newmap with outgoing changes.
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   258
            # This will possibly add new heads and remove existing ones.
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   259
            ctxgen = (repo[n] for n in outg)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   260
            repo._updatebranchcache(newmap, ctxgen)
1998
65cc17ae9649 fix race in localrepo.addchangegroup.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1995
diff changeset
   261
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   262
        else:
11578
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   263
            # 1-4b. old servers: Check for new topological heads.
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   264
            # Construct {old,new}map with branch = None (topological branch).
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   265
            # (code based on _updatebranchcache)
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   266
            oldheads = set(h for h in remoteheads if h in cl.nodemap)
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   267
            newheads = oldheads.union(outg)
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   268
            if len(newheads) > 1:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   269
                for latest in reversed(outg):
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   270
                    if latest not in newheads:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   271
                        continue
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   272
                    minhrev = min(cl.rev(h) for h in newheads)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   273
                    reachable = cl.reachable(latest, cl.node(minhrev))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   274
                    reachable.remove(latest)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   275
                    newheads.difference_update(reachable)
11578
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   276
            branches = set([None])
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   277
            newmap = {None: newheads}
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   278
            oldmap = {None: oldheads}
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   279
            unsynced = inc and branches or set()
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   280
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   281
        # 5. Check for new heads.
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   282
        # If there are more heads after the push than before, a suitable
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   283
        # warning, depending on unsynced status, is displayed.
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   284
        for branch in branches:
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   285
            if len(newmap[branch]) > len(oldmap[branch]):
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   286
                if branch:
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   287
                    msg = _("push creates new remote heads "
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   288
                            "on branch '%s'!") % branch
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   289
                else:
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   290
                    msg = _("push creates new remote heads!")
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   291
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   292
                if branch in unsynced:
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   293
                    hint = _("you should pull and merge or use push -f to force")
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   294
                else:
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   295
                    hint = _("did you forget to merge? use push -f to force")
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   296
                raise util.Abort(msg, hint=hint)
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   297
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   298
        # 6. Check for unsynced changes on involved branches.
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   299
        if unsynced:
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   300
            repo.ui.warn(_("note: unsynced remote changes!\n"))
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 514
diff changeset
   301
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   302
    if revs is None:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   303
        # use the fast path, no race possible on push
12759
9c5794223340 discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11578
diff changeset
   304
        nodes = repo.changelog.findmissing(common)
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   305
        cg = repo._changegroup(nodes, 'push')
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   306
    else:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   307
        cg = repo.changegroupsubset(update, revs, 'push')
11577
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   308
    return cg, remoteheads