mercurial/discovery.py
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
Sun, 17 Oct 2010 19:25:35 +0200
changeset 12761 11c3c77da62a
parent 12760 b41e8dfee66e
child 12762 8bac8cd43c8d
permissions -rw-r--r--
discovery: use set instead of dict
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 findincoming(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 list of roots of the subsets of missing nodes from remote
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    14
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    15
    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
    16
    or ancestors of these heads.
6750
fb42030d79d6 add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents: 6747
diff changeset
    17
12760
b41e8dfee66e discovery: remove unused "base" argument from find.*incoming()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12759
diff changeset
    18
    All the ancestors of the list returned are in repo and in remote.
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    19
    All the descendants of the list returned are missing in repo.
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    20
    (and so we know that the rest of the nodes are missing in remote, see
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    21
    outgoing)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    22
    """
12760
b41e8dfee66e discovery: remove unused "base" argument from find.*incoming()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12759
diff changeset
    23
    return findcommonincoming(repo, remote, heads, force)[1]
4932
f0c25ed40ec6 tag: handle .hgtags and .hg/localtags with missing final newline (issue 601)
Bryan O'Sullivan <bos@serpentine.com>
parents: 4929
diff changeset
    24
12760
b41e8dfee66e discovery: remove unused "base" argument from find.*incoming()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12759
diff changeset
    25
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
    26
    """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
    27
    missing nodes from remote.
2601
00fc88b0b256 move most of tag code to localrepository class.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2581
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 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
    30
    or ancestors of these heads.
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    31
    """
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    32
    m = repo.changelog.nodemap
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    33
    search = []
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    34
    fetch = set()
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    35
    seen = set()
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    36
    seenbranch = set()
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
    37
    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
    38
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    39
    if not heads:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    40
        heads = remote.heads()
343
d7df759d0e97 rework all code using tags
mpm@selenic.com
parents: 337
diff changeset
    41
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    42
    if repo.changelog.tip() == nullid:
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
    43
        base.add(nullid)
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    44
        if heads != [nullid]:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    45
            return [nullid], [nullid], list(heads)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    46
        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
    47
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    48
    # 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
    49
    # 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
    50
    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
    51
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    52
    unknown = []
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    53
    for h in heads:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    54
        if h not in m:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    55
            unknown.append(h)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    56
        else:
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
    57
            base.add(h)
7654
816b708f23af store all heads of a branch in the branch cache
John Mulligan <phlogistonjohn@asynchrono.us>
parents: 7644
diff changeset
    58
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    59
    heads = unknown
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    60
    if not unknown:
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
    61
        return list(base), [], []
4415
1a63b44f90c9 branch.cache: silently ignore I/O and OS errors
Matt Mackall <mpm@selenic.com>
parents: 4329
diff changeset
    62
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    63
    req = set(unknown)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    64
    reqcnt = 0
3417
028fff46a4ac Add branchtags function with cache
Matt Mackall <mpm@selenic.com>
parents: 3377
diff changeset
    65
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    66
    # search through remote branches
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    67
    # 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
    68
    # 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
    69
    # (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
    70
    unknown = remote.branches(unknown)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    71
    while unknown:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    72
        r = []
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    73
        while unknown:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    74
            n = unknown.pop(0)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    75
            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
    76
                continue
1806
a2c69737e65e Automatic nesting into running transactions in the same repository.
mason@suse.com
parents: 1802
diff changeset
    77
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    78
            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
    79
                          % (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
    80
            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
    81
                pass
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    82
            elif n in seenbranch:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    83
                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
    84
                continue
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    85
            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
    86
                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
    87
                              % (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
    88
                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
    89
                seenbranch.add(n)
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4914
diff changeset
    90
            else:
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    91
                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
    92
                    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
    93
                        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
    94
                                      short(n[1]))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
    95
                        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
    96
                    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
    97
                        if p in m:
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
    98
                            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
    99
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   100
                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
   101
                    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
   102
                        r.append(p)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   103
                        req.add(p)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   104
            seen.add(n[0])
1716
ef8cd889a78b Refactor excessive merge detection, add test
Matt Mackall <mpm@selenic.com>
parents: 1713
diff changeset
   105
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   106
        if r:
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
            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
   110
                        (reqcnt, " ".join(map(short, r))))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   111
            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
   112
                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
   113
                    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
   114
                                  (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
   115
                    unknown.append(b)
8404
a2bc39ade36b commit: move 'nothing changed' test into commit()
Matt Mackall <mpm@selenic.com>
parents: 8403
diff changeset
   116
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   117
    # 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
   118
    while search:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   119
        newsearch = []
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   120
        reqcnt += 1
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   121
        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
   122
        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
   123
            l.append(n[1])
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   124
            p = n[0]
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   125
            f = 1
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   126
            for i in l:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   127
                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
   128
                if i in m:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   129
                    if f <= 2:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   130
                        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
   131
                                          short(p))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   132
                        fetch.add(p)
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
   133
                        base.add(i)
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4914
diff changeset
   134
                    else:
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   135
                        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
   136
                                      % (short(p), short(i)))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   137
                        newsearch.append((p, i))
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   138
                    break
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   139
                p, f = i, f * 2
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   140
            search = newsearch
9150
09a1ee498756 localrepo: add destroyed() method for strip/rollback to use (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
   141
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   142
    # sanity check our fetch list
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   143
    for f in fetch:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   144
        if f in m:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   145
            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
   146
                                  + short(f[:4]))
4912
312c845edef5 simplify dirstate fixups in repo.status()
Matt Mackall <mpm@selenic.com>
parents: 4910
diff changeset
   147
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
   148
    base = list(base)
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
   149
    if base == [nullid]:
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   150
        if force:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   151
            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
   152
        else:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   153
            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
   154
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   155
    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
   156
                 " ".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
   157
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   158
    repo.ui.progress(_('searching'), None)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   159
    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
   160
12761
11c3c77da62a discovery: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12760
diff changeset
   161
    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
   162
11576
98c874a929f1 discovery: simplify findoutgoing(), the updated_head stuff wasn't used
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11574
diff changeset
   163
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
   164
    """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
   165
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   166
    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
   167
    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
   168
    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
   169
    the remote repository.
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   170
    """
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   171
    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
   172
        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
   173
                                  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
   174
    else:
9c5794223340 discovery: do not use the implicit updating of the "base" arg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11578
diff changeset
   175
        base = list(base)
2339
11422943cf72 document and fix findincoming
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2335
diff changeset
   176
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   177
    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
   178
                  + " ".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
   179
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   180
    remain = set(repo.changelog.nodemap)
148
c32286d0a665 Improve pruning of branches in outstanding changeset algorithm
mpm@selenic.com
parents: 146
diff changeset
   181
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   182
    # 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
   183
    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
   184
    remove = base
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   185
    while remove:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   186
        n = remove.pop(0)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   187
        if n in remain:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   188
            remain.remove(n)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   189
            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
   190
                remove.append(p)
65
d40cc5aacc31 Fix up a bunch of bugs in the new merge code
mpm@selenic.com
parents: 64
diff changeset
   191
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   192
    # 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
   193
    subset = []
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   194
    # 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
   195
    for n in remain:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   196
        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
   197
        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
   198
            subset.append(n)
7415
6163ef936a00 protocol: use changegroupsubset() if possible (issue1389)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7377
diff changeset
   199
11576
98c874a929f1 discovery: simplify findoutgoing(), the updated_head stuff wasn't used
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11574
diff changeset
   200
    return subset
3684
975c2469c316 correct remote heads test in prepush
Matt Mackall <mpm@selenic.com>
parents: 3682
diff changeset
   201
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   202
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
   203
    '''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
   204
    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
   205
    on circumstances:
10353
36b6b5ef7820 prepush: rename variables, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10327
diff changeset
   206
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   207
    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
   208
    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
   209
    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
   210
    (e.g. would create new remote heads).
3684
975c2469c316 correct remote heads test in prepush
Matt Mackall <mpm@selenic.com>
parents: 3682
diff changeset
   211
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   212
    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
   213
    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
   214
    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
   215
    remoteheads is the list of remote heads.'''
11577
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   216
    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
   217
    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
   218
                                             force=force)
2439
e8c4f3d3df8c extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2424
diff changeset
   219
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   220
    cl = repo.changelog
11577
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   221
    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
   222
    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
   223
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   224
    if not bases:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   225
        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
   226
        return None, 1
622
e9fe5d5e67f7 Add generic repo commands for pull and push
Matt Mackall <mpm@selenic.com>
parents: 621
diff changeset
   227
11577
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   228
    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
   229
        if remote.capable('branchmap'):
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   230
            # 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
   231
            # 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
   232
            # - unknown locally
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   233
            # - 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
   234
            # - 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
   235
            #   ancestral to an outgoing head
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   236
            #
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   237
            # New named branches cannot be created without --force.
10405
2d30d66a89ad whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 10396
diff changeset
   238
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   239
            # 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
   240
            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
   241
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   242
            # 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
   243
            remotemap = remote.branchmap()
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   244
            newbranches = branches - set(remotemap)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   245
            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
   246
                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
   247
                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
   248
                                   % 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
   249
                                 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
   250
                                        " new remote branches"))
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   251
            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
   252
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   253
            # 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
   254
            # 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
   255
            # after the push, respectively.
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   256
            # 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
   257
            # 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
   258
            # 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
   259
            oldmap = {}
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   260
            newmap = {}
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   261
            unsynced = set()
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   262
            for branch in branches:
11577
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   263
                remotebrheads = remotemap[branch]
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   264
                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
   265
                oldmap[branch] = prunedbrheads
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   266
                newmap[branch] = list(prunedbrheads)
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   267
                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
   268
                    unsynced.add(branch)
635
85e2209d401c Protocol switch from using generators to stream-like objects.
Matt Mackall <mpm@selenic.com>
parents: 634
diff changeset
   269
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   270
            # 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
   271
            # 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
   272
            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
   273
            repo._updatebranchcache(newmap, ctxgen)
1998
65cc17ae9649 fix race in localrepo.addchangegroup.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1995
diff changeset
   274
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   275
        else:
11578
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   276
            # 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
   277
            # 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
   278
            # (code based on _updatebranchcache)
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   279
            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
   280
            newheads = oldheads.union(outg)
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   281
            if len(newheads) > 1:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   282
                for latest in reversed(outg):
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   283
                    if latest not in newheads:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   284
                        continue
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   285
                    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
   286
                    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
   287
                    reachable.remove(latest)
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   288
                    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
   289
            branches = set([None])
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   290
            newmap = {None: newheads}
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   291
            oldmap = {None: oldheads}
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   292
            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
   293
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   294
        # 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
   295
        # 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
   296
        # 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
   297
        for branch in branches:
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   298
            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
   299
                if branch:
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   300
                    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
   301
                            "on branch '%s'!") % branch
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   302
                else:
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   303
                    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
   304
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   305
                if branch in unsynced:
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   306
                    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
   307
                else:
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   308
                    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
   309
                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
   310
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   311
        # 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
   312
        if unsynced:
bb7af1de5e38 discovery: remove duplication for new remote head discovery
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11577
diff changeset
   313
            repo.ui.warn(_("note: unsynced remote changes!\n"))
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 514
diff changeset
   314
11301
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   315
    if revs is None:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   316
        # 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
   317
        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
   318
        cg = repo._changegroup(nodes, 'push')
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   319
    else:
3d0591a66118 move discovery methods from localrepo into new discovery module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11230
diff changeset
   320
        cg = repo.changegroupsubset(update, revs, 'push')
11577
0bc450253312 discovery: better coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11576
diff changeset
   321
    return cg, remoteheads