hgext3rd/evolve/obsdiscovery.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Mon, 27 Aug 2018 12:12:49 +0200
branchstable
changeset 4025 971d2e81b5b6
parent 4024 210f8abdfcd7
child 4027 130a60a51fff
permissions -rw-r--r--
obshashrange: rework saving branching to be clearer and safer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     1
# Code dedicated to the discovery of obsolescence marker "over the wire"
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     2
#
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     3
# Copyright 2017 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     4
#
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     7
2124
6665aad2d41b obsdiscovery: document the status of the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2098
diff changeset
     8
# Status: Experiment in progress // open question
6665aad2d41b obsdiscovery: document the status of the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2098
diff changeset
     9
#
6665aad2d41b obsdiscovery: document the status of the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2098
diff changeset
    10
#   The final discovery algorithm and protocol will go into core when we'll be
6665aad2d41b obsdiscovery: document the status of the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2098
diff changeset
    11
#   happy with it.
6665aad2d41b obsdiscovery: document the status of the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2098
diff changeset
    12
#
6665aad2d41b obsdiscovery: document the status of the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2098
diff changeset
    13
#   Some of the code in this module is for compatiblity with older version
6665aad2d41b obsdiscovery: document the status of the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2098
diff changeset
    14
#   of evolve and will be eventually dropped.
6665aad2d41b obsdiscovery: document the status of the module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2098
diff changeset
    15
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    16
from __future__ import absolute_import
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    17
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    18
try:
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    19
    import StringIO as io
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    20
    StringIO = io.StringIO
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    21
except ImportError:
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    22
    import io
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    23
    StringIO = io.StringIO
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    24
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
    25
import hashlib
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
    26
import heapq
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
    27
import sqlite3
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
    28
import struct
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
    29
import weakref
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
    30
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    31
from mercurial import (
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
    32
    dagutil,
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    33
    error,
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    34
    exchange,
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
    35
    extensions,
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    36
    localrepo,
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    37
    node,
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    38
    obsolete,
2081
010a8af416a0 discovery: adds a function doing revnum independant sorting
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2076
diff changeset
    39
    scmutil,
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
    40
    setdiscovery,
2082
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
    41
    util,
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    42
)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    43
from mercurial.i18n import _
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    44
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    45
from . import (
3524
6d4095e6bdd3 obsdiscovery: add compatibility layer to register wireproto command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3521
diff changeset
    46
    compat,
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    47
    exthelper,
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
    48
    obscache,
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    49
    utility,
2125
e0a25339ff17 stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2124
diff changeset
    50
    stablerange,
3307
a1ab2588a628 stablerange: split pure algorithm part from the on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3248
diff changeset
    51
    stablerangecache,
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    52
)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    53
3708
d7a89d5b3684 wirepeer: try modern module first
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3685
diff changeset
    54
try:
d7a89d5b3684 wirepeer: try modern module first
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3685
diff changeset
    55
    from mercurial import wireprototypes, wireprotov1server
d7a89d5b3684 wirepeer: try modern module first
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3685
diff changeset
    56
    from mercurial.wireprotov1peer import wirepeer
d7a89d5b3684 wirepeer: try modern module first
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3685
diff changeset
    57
    from mercurial.wireprototypes import encodelist, decodelist
d7a89d5b3684 wirepeer: try modern module first
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3685
diff changeset
    58
except (ImportError, AttributeError): # <= hg-4.5
3681
3f90e6c5d140 discovery: handle deletion of 'wireproto' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3669
diff changeset
    59
    from mercurial import wireproto as wireprototypes
3f90e6c5d140 discovery: handle deletion of 'wireproto' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3669
diff changeset
    60
    wireprotov1server = wireprototypes
3669
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
    61
    from mercurial.wireproto import wirepeer, encodelist, decodelist
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
    62
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
    63
_pack = struct.pack
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
    64
_unpack = struct.unpack
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
    65
_calcsize = struct.calcsize
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
    66
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    67
eh = exthelper.exthelper()
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    68
obsexcmsg = utility.obsexcmsg
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    69
3080
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 2551
diff changeset
    70
# Config
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 2551
diff changeset
    71
eh.configitem('experimental', 'evolution.obsdiscovery')
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 2551
diff changeset
    72
eh.configitem('experimental', 'obshashrange')
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 2551
diff changeset
    73
eh.configitem('experimental', 'obshashrange.warm-cache')
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 2551
diff changeset
    74
eh.configitem('experimental', 'obshashrange.max-revs')
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 2551
diff changeset
    75
eh.configitem('experimental', 'obshashrange.lru-size')
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 2551
diff changeset
    76
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
    77
##################################
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
    78
###  Code performing discovery ###
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
    79
##################################
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    80
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    81
def findcommonobsmarkers(ui, local, remote, probeset,
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    82
                         initialsamplesize=100,
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    83
                         fullsamplesize=200):
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    84
    # from discovery
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    85
    roundtrips = 0
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    86
    cl = local.changelog
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    87
    dag = dagutil.revlogdag(cl)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    88
    missing = set()
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    89
    common = set()
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    90
    undecided = set(probeset)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    91
    totalnb = len(undecided)
3521
b738bfbef3a0 obsdiscovery: include units in ui.progress() calls (issue5773)
Anton Shestakov <av6@dwimlabs.net>
parents: 3504
diff changeset
    92
    ui.progress(_("comparing with other"), 0, total=totalnb,
b738bfbef3a0 obsdiscovery: include units in ui.progress() calls (issue5773)
Anton Shestakov <av6@dwimlabs.net>
parents: 3504
diff changeset
    93
                unit=_("changesets"))
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    94
    _takefullsample = setdiscovery._takefullsample
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    95
    if remote.capable('_evoext_obshash_1'):
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    96
        getremotehash = remote.evoext_obshash1
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
    97
        localhash = _obsrelsethashtreefm1(local)
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    98
    else:
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    99
        getremotehash = remote.evoext_obshash
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   100
        localhash = _obsrelsethashtreefm0(local)
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   101
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   102
    while undecided:
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   103
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   104
        ui.note(_("sampling from both directions\n"))
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   105
        if len(undecided) < fullsamplesize:
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   106
            sample = set(undecided)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   107
        else:
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   108
            sample = _takefullsample(dag, undecided, size=fullsamplesize)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   109
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   110
        roundtrips += 1
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   111
        ui.progress(_("comparing with other"), totalnb - len(undecided),
3521
b738bfbef3a0 obsdiscovery: include units in ui.progress() calls (issue5773)
Anton Shestakov <av6@dwimlabs.net>
parents: 3504
diff changeset
   112
                    total=totalnb, unit=_("changesets"))
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   113
        ui.debug("query %i; still undecided: %i, sample size is: %i\n"
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   114
                 % (roundtrips, len(undecided), len(sample)))
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   115
        # indices between sample and externalized version must match
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   116
        sample = list(sample)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   117
        remotehash = getremotehash(dag.externalizeall(sample))
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   118
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   119
        yesno = [localhash[ix][1] == remotehash[si]
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   120
                 for si, ix in enumerate(sample)]
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   121
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   122
        commoninsample = set(n for i, n in enumerate(sample) if yesno[i])
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   123
        common.update(dag.ancestorset(commoninsample, common))
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   124
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   125
        missinginsample = [n for i, n in enumerate(sample) if not yesno[i]]
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   126
        missing.update(dag.descendantset(missinginsample, missing))
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   127
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   128
        undecided.difference_update(missing)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   129
        undecided.difference_update(common)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   130
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   131
    ui.progress(_("comparing with other"), None)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   132
    result = dag.headsetofconnecteds(common)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   133
    ui.debug("%d total queries\n" % roundtrips)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   134
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   135
    if not result:
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   136
        return set([node.nullid])
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   137
    return dag.externalizeall(result)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   138
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   139
def findmissingrange(ui, local, remote, probeset,
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   140
                     initialsamplesize=100,
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   141
                     fullsamplesize=200):
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   142
    missing = set()
3685
bf000d1a525f timer: drop compat layer for time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3681
diff changeset
   143
    starttime = util.timer()
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   144
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   145
    heads = local.revs('heads(%ld)', probeset)
2239
f4f6ff874c40 stablerange: warm cache before using it in findrangemissing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2233
diff changeset
   146
    local.stablerange.warmup(local)
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   147
2164
cc8ae2a66b0f stablerange: use rangelength in findmissingrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2158
diff changeset
   148
    rangelength = local.stablerange.rangelength
2174
71c518470e2c stablerange: use subranges from the main class in findrangemissing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2171
diff changeset
   149
    subranges = local.stablerange.subranges
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   150
    # size of slice ?
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   151
    heappop = heapq.heappop
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   152
    heappush = heapq.heappush
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   153
    heapify = heapq.heapify
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   154
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   155
    tested = set()
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   156
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   157
    sample = []
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   158
    samplesize = initialsamplesize
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   159
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   160
    def addentry(entry):
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   161
        if entry in tested:
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   162
            return False
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   163
        sample.append(entry)
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   164
        tested.add(entry)
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   165
        return True
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   166
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   167
    for h in heads:
2196
2ecc88baabf9 stablerange: directly use tuple to refer to a stable range
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2195
diff changeset
   168
        entry = (h, 0)
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   169
        addentry(entry)
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   170
2365
4b8b7fd135eb obshashrange: warm cache outside of loops
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2364
diff changeset
   171
    local.obsstore.rangeobshashcache.update(local)
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   172
    querycount = 0
3521
b738bfbef3a0 obsdiscovery: include units in ui.progress() calls (issue5773)
Anton Shestakov <av6@dwimlabs.net>
parents: 3504
diff changeset
   173
    ui.progress(_("comparing obsmarker with other"), querycount,
b738bfbef3a0 obsdiscovery: include units in ui.progress() calls (issue5773)
Anton Shestakov <av6@dwimlabs.net>
parents: 3504
diff changeset
   174
                unit=_("queries"))
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   175
    overflow = []
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   176
    while sample or overflow:
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   177
        if overflow:
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   178
            sample.extend(overflow)
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   179
            overflow = []
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   180
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   181
        if samplesize < len(sample):
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   182
            # too much sample already
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   183
            overflow = sample[samplesize:]
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   184
            sample = sample[:samplesize]
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   185
        elif len(sample) < samplesize:
2242
128923ff68c8 obshashrange: improve message issued during discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2241
diff changeset
   186
            ui.debug("query %i; add more sample (target %i, current %i)\n"
128923ff68c8 obshashrange: improve message issued during discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2241
diff changeset
   187
                     % (querycount, samplesize, len(sample)))
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   188
            # we need more sample !
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   189
            needed = samplesize - len(sample)
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   190
            sliceme = []
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   191
            heapify(sliceme)
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   192
            for entry in sample:
2164
cc8ae2a66b0f stablerange: use rangelength in findmissingrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2158
diff changeset
   193
                if 1 < rangelength(local, entry):
cc8ae2a66b0f stablerange: use rangelength in findmissingrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2158
diff changeset
   194
                    heappush(sliceme, (-rangelength(local, entry), entry))
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   195
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   196
            while sliceme and 0 < needed:
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   197
                _key, target = heappop(sliceme)
2174
71c518470e2c stablerange: use subranges from the main class in findrangemissing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2171
diff changeset
   198
                for new in subranges(local, target):
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   199
                    # XXX we could record hierarchy to optimise drop
2203
8a2e1f6e5443 findmissingrange: properly queue new subrange for slicing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2202
diff changeset
   200
                    if addentry(new):
8a2e1f6e5443 findmissingrange: properly queue new subrange for slicing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2202
diff changeset
   201
                        if 1 < len(new):
8a2e1f6e5443 findmissingrange: properly queue new subrange for slicing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2202
diff changeset
   202
                            heappush(sliceme, (-rangelength(local, new), new))
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   203
                        needed -= 1
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   204
                        if needed <= 0:
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   205
                            break
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   206
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   207
        # no longer the first interation
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   208
        samplesize = fullsamplesize
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   209
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   210
        nbsample = len(sample)
2164
cc8ae2a66b0f stablerange: use rangelength in findmissingrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2158
diff changeset
   211
        maxsize = max([rangelength(local, r) for r in sample])
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   212
        ui.debug("query %i; sample size is %i, largest range %i\n"
2202
5f8a2604bb2b findmissingrange: fix reversed value in debug output
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2196
diff changeset
   213
                 % (querycount, nbsample, maxsize))
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   214
        nbreplies = 0
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   215
        replies = list(_queryrange(ui, local, remote, sample))
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   216
        sample = []
2144
2200f67e1628 stablerange: stop using '.node' in findmissingrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2143
diff changeset
   217
        n = local.changelog.node
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   218
        for entry, remotehash in replies:
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   219
            nbreplies += 1
2139
f80fa478e289 obshashrange: use a small utility function to access the obshash
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2138
diff changeset
   220
            if remotehash == _obshashrange(local, entry):
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   221
                continue
2164
cc8ae2a66b0f stablerange: use rangelength in findmissingrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2158
diff changeset
   222
            elif 1 == rangelength(local, entry):
2144
2200f67e1628 stablerange: stop using '.node' in findmissingrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2143
diff changeset
   223
                missing.add(n(entry[0]))
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   224
            else:
2174
71c518470e2c stablerange: use subranges from the main class in findrangemissing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2171
diff changeset
   225
                for new in subranges(local, entry):
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   226
                    addentry(new)
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   227
        assert nbsample == nbreplies
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   228
        querycount += 1
3521
b738bfbef3a0 obsdiscovery: include units in ui.progress() calls (issue5773)
Anton Shestakov <av6@dwimlabs.net>
parents: 3504
diff changeset
   229
        ui.progress(_("comparing obsmarker with other"), querycount,
b738bfbef3a0 obsdiscovery: include units in ui.progress() calls (issue5773)
Anton Shestakov <av6@dwimlabs.net>
parents: 3504
diff changeset
   230
                    unit=_("queries"))
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   231
    ui.progress(_("comparing obsmarker with other"), None)
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   232
    local.obsstore.rangeobshashcache.save(local)
3685
bf000d1a525f timer: drop compat layer for time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3681
diff changeset
   233
    duration = util.timer() - starttime
2408
0af6bb0bfdc3 discovery: log information about obshashrange
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2399
diff changeset
   234
    logmsg = ('obsdiscovery, %d/%d mismatch'
0af6bb0bfdc3 discovery: log information about obshashrange
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2399
diff changeset
   235
              ' - %d obshashrange queries in %.4f seconds\n')
0af6bb0bfdc3 discovery: log information about obshashrange
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2399
diff changeset
   236
    logmsg %= (len(missing), len(probeset), querycount, duration)
0af6bb0bfdc3 discovery: log information about obshashrange
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2399
diff changeset
   237
    ui.log('evoext-obsdiscovery', logmsg)
2409
2b563a725cdc obsdiscovery: add more debug output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2408
diff changeset
   238
    ui.debug(logmsg)
2085
6d61c5ed3bfa obsdiscovery: simply some of the missing computation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2084
diff changeset
   239
    return sorted(missing)
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   240
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   241
def _queryrange(ui, repo, remote, allentries):
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   242
    #  question are asked with node
2146
4df68eb96adf stablerange: stop using '.node' in _queryrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2145
diff changeset
   243
    n = repo.changelog.node
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   244
    noderanges = [(n(entry[0]), entry[1]) for entry in allentries]
3346
f4e28b781143 stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3307
diff changeset
   245
    replies = remote.evoext_obshashrange_v1(noderanges)
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   246
    result = []
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   247
    for idx, entry in enumerate(allentries):
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   248
        result.append((entry, replies[idx]))
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   249
    return result
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   250
2082
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   251
##############################
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   252
### Range Hash computation ###
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   253
##############################
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   254
2082
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   255
@eh.command(
2229
575561934439 debug: rename 'debugstablerange' to 'debugobshashrange'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2228
diff changeset
   256
    'debugobshashrange',
2082
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   257
    [
2230
a202f3af890c debugobshashrange: add a --subranges option
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2229
diff changeset
   258
        ('', 'rev', [], 'display obshash for all (rev, 0) range in REVS'),
a202f3af890c debugobshashrange: add a --subranges option
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2229
diff changeset
   259
        ('', 'subranges', False, 'display all subranges'),
2082
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   260
    ],
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   261
    _(''))
2229
575561934439 debug: rename 'debugstablerange' to 'debugobshashrange'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2228
diff changeset
   262
def debugobshashrange(ui, repo, **opts):
2082
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   263
    """display the ::REVS set topologically sorted in a stable way
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   264
    """
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   265
    s = node.short
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   266
    revs = scmutil.revrange(repo, opts['rev'])
2087
0c2371542687 depth: update depth to code to reuse ancestors depth
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2086
diff changeset
   267
    # prewarm depth cache
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   268
    if revs:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   269
        repo.stablerange.warmup(repo, max(revs))
2145
4c0c88e51018 stablerange: stop using '.node' in debugstablerange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2144
diff changeset
   270
    cl = repo.changelog
2165
e97e9b0c9711 stablerange: use rangelength in debugstablerange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2164
diff changeset
   271
    rangelength = repo.stablerange.rangelength
2171
3be48332b802 stablerange: use depthrevs in debugstablerange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2166
diff changeset
   272
    depthrev = repo.stablerange.depthrev
2230
a202f3af890c debugobshashrange: add a --subranges option
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2229
diff changeset
   273
    if opts['subranges']:
3248
07c9b6f445bf stablerange: rework the debug command to allow for multiple method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3247
diff changeset
   274
        ranges = stablerange.subrangesclosure(repo, repo.stablerange, revs)
2230
a202f3af890c debugobshashrange: add a --subranges option
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2229
diff changeset
   275
    else:
a202f3af890c debugobshashrange: add a --subranges option
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2229
diff changeset
   276
        ranges = [(r, 0) for r in revs]
2228
3b18440cca74 debugstablerange: improve output spacing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2203
diff changeset
   277
    headers = ('rev', 'node', 'index', 'size', 'depth', 'obshash')
3b18440cca74 debugstablerange: improve output spacing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2203
diff changeset
   278
    linetemplate = '%12d %12s %12d %12d %12d %12s\n'
3b18440cca74 debugstablerange: improve output spacing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2203
diff changeset
   279
    headertemplate = linetemplate.replace('d', 's')
3b18440cca74 debugstablerange: improve output spacing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2203
diff changeset
   280
    ui.status(headertemplate % headers)
2365
4b8b7fd135eb obshashrange: warm cache outside of loops
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2364
diff changeset
   281
    repo.obsstore.rangeobshashcache.update(repo)
2082
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   282
    for r in ranges:
2150
0a95e8518941 stablerange: stop using '.head' in debugstablerange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2146
diff changeset
   283
        d = (r[0],
2145
4c0c88e51018 stablerange: stop using '.node' in debugstablerange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2144
diff changeset
   284
             s(cl.node(r[0])),
2157
e3b75a5d6b38 stablerange: stop using '.index' in debugstablerange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2150
diff changeset
   285
             r[1],
2165
e97e9b0c9711 stablerange: use rangelength in debugstablerange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2164
diff changeset
   286
             rangelength(repo, r),
2171
3be48332b802 stablerange: use depthrevs in debugstablerange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2166
diff changeset
   287
             depthrev(repo, r[0]),
2139
f80fa478e289 obshashrange: use a small utility function to access the obshash
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2138
diff changeset
   288
             node.short(_obshashrange(repo, r)))
2228
3b18440cca74 debugstablerange: improve output spacing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2203
diff changeset
   289
        ui.status(linetemplate % d)
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   290
    repo.obsstore.rangeobshashcache.save(repo)
2082
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   291
2139
f80fa478e289 obshashrange: use a small utility function to access the obshash
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2138
diff changeset
   292
def _obshashrange(repo, rangeid):
f80fa478e289 obshashrange: use a small utility function to access the obshash
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2138
diff changeset
   293
    """return the obsolete hash associated to a range"""
2140
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   294
    cache = repo.obsstore.rangeobshashcache
2143
99cf2784e2a6 stablerange: stop using '.node' in obshashrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2140
diff changeset
   295
    cl = repo.changelog
2140
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   296
    obshash = cache.get(rangeid)
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   297
    if obshash is not None:
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   298
        return obshash
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   299
    pieces = []
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   300
    nullid = node.nullid
2166
d4ff8708eb66 stablerange: use rangelength in _obshashrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2165
diff changeset
   301
    if repo.stablerange.rangelength(repo, rangeid) == 1:
2143
99cf2784e2a6 stablerange: stop using '.node' in obshashrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2140
diff changeset
   302
        rangenode = cl.node(rangeid[0])
99cf2784e2a6 stablerange: stop using '.node' in obshashrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2140
diff changeset
   303
        tmarkers = repo.obsstore.relevantmarkers([rangenode])
2140
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   304
        pieces = []
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   305
        for m in tmarkers:
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   306
            mbin = obsolete._fm1encodeonemarker(m)
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   307
            pieces.append(mbin)
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   308
        pieces.sort()
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   309
    else:
2175
4162dbe7ff5c stablerange: use subranges from the main class in _obshashrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2174
diff changeset
   310
        for subrange in repo.stablerange.subranges(repo, rangeid):
2140
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   311
            obshash = _obshashrange(repo, subrange)
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   312
            if obshash != nullid:
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   313
                pieces.append(obshash)
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   314
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   315
    sha = hashlib.sha1()
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   316
    # note: if there is only one subrange with actual data, we'll just
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   317
    # reuse the same hash.
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   318
    if not pieces:
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   319
        obshash = node.nullid
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   320
    elif len(pieces) != 1 or obshash is None:
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   321
        sha = hashlib.sha1()
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   322
        for p in pieces:
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   323
            sha.update(p)
2195
bd3d35047181 obshash: properly cache obshash value
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2175
diff changeset
   324
        obshash = sha.digest()
bd3d35047181 obshash: properly cache obshash value
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2175
diff changeset
   325
    cache[rangeid] = obshash
2140
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   326
    return obshash
2139
f80fa478e289 obshashrange: use a small utility function to access the obshash
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2138
diff changeset
   327
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   328
### sqlite caching
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   329
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   330
_sqliteschema = [
4022
082b59126099 sqlcache: initialize meta table last
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4021
diff changeset
   331
    """CREATE TABLE obshashrange(rev     INTEGER NOT NULL,
082b59126099 sqlcache: initialize meta table last
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4021
diff changeset
   332
                                 idx     INTEGER NOT NULL,
082b59126099 sqlcache: initialize meta table last
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4021
diff changeset
   333
                                 obshash BLOB    NOT NULL,
082b59126099 sqlcache: initialize meta table last
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4021
diff changeset
   334
                                 PRIMARY KEY(rev, idx));""",
082b59126099 sqlcache: initialize meta table last
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4021
diff changeset
   335
    "CREATE INDEX range_index ON obshashrange(rev, idx);",
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   336
    """CREATE TABLE meta(schemaversion INTEGER NOT NULL,
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   337
                         tiprev        INTEGER NOT NULL,
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   338
                         tipnode       BLOB    NOT NULL,
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   339
                         nbobsmarker   INTEGER NOT NULL,
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   340
                         obssize       BLOB    NOT NULL,
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   341
                         obskey        BLOB    NOT NULL
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   342
                        );""",
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   343
]
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   344
_queryexist = "SELECT name FROM sqlite_master WHERE type='table' AND name='meta';"
2391
80d6a2ad7b11 obshashcache: purge the meta line before writing a new one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2390
diff changeset
   345
_clearmeta = """DELETE FROM meta;"""
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   346
_newmeta = """INSERT INTO meta (schemaversion, tiprev, tipnode, nbobsmarker, obssize, obskey)
2390
caddf846ca1e obshashrange: drop spurious whitespace
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2389
diff changeset
   347
            VALUES (?,?,?,?,?,?);"""
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   348
_updateobshash = "INSERT INTO obshashrange(rev, idx, obshash) VALUES (?,?,?);"
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   349
_querymeta = "SELECT schemaversion, tiprev, tipnode, nbobsmarker, obssize, obskey FROM meta;"
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   350
_queryobshash = "SELECT obshash FROM obshashrange WHERE (rev = ? AND idx = ?);"
3955
0174737af4fc obshashrange: do not search for affected ranges above the highest we have
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3954
diff changeset
   351
_query_max_stored = "SELECT MAX(rev) FROM obshashrange"
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   352
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   353
_reset = "DELETE FROM obshashrange;"
3355
c261eece1eab obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3354
diff changeset
   354
_delete = "DELETE FROM obshashrange WHERE (rev = ? AND idx = ?);"
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   355
3958
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   356
def _affectedby(repo, markers):
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   357
    """return all nodes whose relevant set is affected by this changeset
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   358
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   359
    This is a reversed version of obsstore.relevantmarkers
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   360
    """
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   361
    affected_nodes = set()
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   362
    known_markers = set(markers)
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   363
    node_to_proceed = set()
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   364
    marker_to_proceed = set(known_markers)
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   365
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   366
    obsstore = repo.obsstore
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   367
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   368
    while node_to_proceed or marker_to_proceed:
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   369
        while marker_to_proceed:
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   370
            m = marker_to_proceed.pop()
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   371
            # check successors and parent
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   372
            if m[1]:
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   373
                relevant = (m[1], )
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   374
            else: # prune case
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   375
                relevant = ((m[0], ), m[5])
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   376
            for l in relevant:
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   377
                if l is None:
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   378
                    continue
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   379
                for n in l:
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   380
                    if n not in affected_nodes:
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   381
                        node_to_proceed.add(n)
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   382
                    affected_nodes.add(n)
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   383
        # marker_to_proceed is now empty:
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   384
        if node_to_proceed:
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   385
            n = node_to_proceed.pop()
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   386
            markers = set()
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   387
            markers.update(obsstore.successors.get(n, ()))
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   388
            markers.update(obsstore.predecessors.get(n, ()))
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   389
            markers -= known_markers
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   390
            marker_to_proceed.update(markers)
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   391
            known_markers.update(markers)
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   392
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   393
    return affected_nodes
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   394
2373
2a1aad0fd8bf obshashrange: stop inheriting from 'dict'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2371
diff changeset
   395
class _obshashcache(obscache.dualsourcecache):
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   396
2525
5adb8bdb935e compatibility: backport mercurial 176d1a0ce385
Boris Feld <boris.feld@octobus.net>
parents: 2521
diff changeset
   397
    _schemaversion = 2
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   398
2376
12386f7f5056 dualsourcecache: add a cache name
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2374
diff changeset
   399
    _cachename = 'evo-ext-obshashrange' # used for error message
3346
f4e28b781143 stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3307
diff changeset
   400
    _filename = 'cache/evoext_obshashrange_v2.sqlite'
2376
12386f7f5056 dualsourcecache: add a cache name
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2374
diff changeset
   401
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   402
    def __init__(self, repo):
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   403
        super(_obshashcache, self).__init__()
2399
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   404
        self._vfs = repo.vfs
3346
f4e28b781143 stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3307
diff changeset
   405
        self._path = repo.vfs.join(self._filename)
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   406
        self._new = set()
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   407
        self._valid = True
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   408
        self._repo = weakref.ref(repo.unfiltered())
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   409
        # cache status
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   410
        self._ondiskcachekey = None
2373
2a1aad0fd8bf obshashrange: stop inheriting from 'dict'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2371
diff changeset
   411
        self._data = {}
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   412
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   413
    def clear(self, reset=False):
2362
22c35d07ddb3 obshashrange: properly drop the current connection on clear
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2361
diff changeset
   414
        super(_obshashcache, self).clear(reset=reset)
2373
2a1aad0fd8bf obshashrange: stop inheriting from 'dict'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2371
diff changeset
   415
        self._data.clear()
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   416
        self._new.clear()
2394
1b3a797c4586 obshashrange: cleanup 'valid' life cycle
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2393
diff changeset
   417
        if reset:
1b3a797c4586 obshashrange: cleanup 'valid' life cycle
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2393
diff changeset
   418
            self._valid = False
1b3a797c4586 obshashrange: cleanup 'valid' life cycle
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2393
diff changeset
   419
        if '_con' in vars(self):
2362
22c35d07ddb3 obshashrange: properly drop the current connection on clear
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2361
diff changeset
   420
            del self._con
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   421
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   422
    def get(self, rangeid):
2393
2a194fe1a557 obsrangecache: raise programming error when using an unwarmed cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2392
diff changeset
   423
        # revision should be covered by the tiprev
2366
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   424
        #
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   425
        # XXX there are issue with cache warming, we hack around it for now
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   426
        if not getattr(self, '_updating', False):
2393
2a194fe1a557 obsrangecache: raise programming error when using an unwarmed cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2392
diff changeset
   427
            if self._cachekey[0] < rangeid[0]:
2a194fe1a557 obsrangecache: raise programming error when using an unwarmed cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2392
diff changeset
   428
                msg = ('using unwarmed obshashrangecache (%s %s)'
2a194fe1a557 obsrangecache: raise programming error when using an unwarmed cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2392
diff changeset
   429
                       % (rangeid[0], self._cachekey[0]))
2a194fe1a557 obsrangecache: raise programming error when using an unwarmed cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2392
diff changeset
   430
                raise error.ProgrammingError(msg)
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   431
2373
2a1aad0fd8bf obshashrange: stop inheriting from 'dict'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2371
diff changeset
   432
        value = self._data.get(rangeid)
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   433
        if value is None and self._con is not None:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   434
            nrange = (rangeid[0], rangeid[1])
4024
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   435
            try:
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   436
                obshash = self._con.execute(_queryobshash, nrange).fetchone()
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   437
                if obshash is not None:
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   438
                    value = obshash[0]
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   439
                self._data[rangeid] = value
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   440
            except sqlite3.OperationalError:
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   441
                # something is wrong with the sqlite db
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   442
                # Since this is a cache, we ignore it.
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   443
                if '_con' in vars(self):
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   444
                    del self._con
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   445
                self._new.clear()
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   446
        return value
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   447
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   448
    def __setitem__(self, rangeid, obshash):
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   449
        self._new.add(rangeid)
2373
2a1aad0fd8bf obshashrange: stop inheriting from 'dict'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2371
diff changeset
   450
        self._data[rangeid] = obshash
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   451
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   452
    def _updatefrom(self, repo, revs, obsmarkers):
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   453
        """override this method to update your cache data incrementally
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   454
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   455
        revs:      list of new revision in the changelog
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   456
        obsmarker: list of new obsmarkers in the obsstore
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   457
        """
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   458
        # XXX for now, we'll not actually update the cache, but we'll be
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   459
        # smarter at invalidating it.
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   460
        #
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   461
        # 1) new revisions does not get their entry updated (not update)
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   462
        # 2) if we detect markers affecting non-new revision we reset the cache
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   463
2366
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   464
        self._updating = True
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   465
3958
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   466
        con = self._con
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   467
        if con is not None:
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   468
            max_stored = con.execute(_query_max_stored).fetchall()[0][0]
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   469
            affected_nodes = _affectedby(repo, obsmarkers)
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   470
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   471
            rev = repo.changelog.nodemap.get
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   472
            affected = [rev(n) for n in affected_nodes]
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   473
            affected = [r for r in affected
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   474
                        if r is not None and r <= max_stored]
2412
8df32538f662 obshashrangecache: precisely track affected revs when adding new markers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2409
diff changeset
   475
3958
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   476
            if affected:
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   477
                repo.ui.log('evoext-cache', 'obshashcache clean - '
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   478
                            'new markers affect %d changeset and cached ranges\n'
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   479
                            % len(affected))
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   480
                if con is not None:
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   481
                    # always reset for now, the code detecting affect is buggy
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   482
                    # so we need to reset more broadly than we would like.
4024
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   483
                    try:
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   484
                        if repo.stablerange._con is None:
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   485
                            con.execute(_reset)
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   486
                            self._data.clear()
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   487
                        else:
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   488
                            ranges = repo.stablerange.contains(repo, affected)
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   489
                            con.executemany(_delete, ranges)
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   490
                            for r in ranges:
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   491
                                self._data.pop(r, None)
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   492
                    except sqlite3.OperationalError as exc:
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   493
                        repo.ui.log('evoext-cache', 'error while updating obshashrange cache: %s' % exc)
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   494
                        del self._updating
210f8abdfcd7 sqlcache: protect read query too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4023
diff changeset
   495
                        return
3955
0174737af4fc obshashrange: do not search for affected ranges above the highest we have
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3954
diff changeset
   496
3958
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   497
                # rewarm key revisions
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   498
                #
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   499
                # (The current invalidation is too wide, but rewarming every
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   500
                # single revision is quite costly)
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   501
                newrevs = []
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   502
                stop = self._cachekey[0] # tiprev
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   503
                for h in repo.filtered('immutable').changelog.headrevs():
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   504
                    if h <= stop and h in affected:
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   505
                        newrevs.append(h)
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   506
                newrevs.extend(revs)
926c8e2f5400 obshashrange: fix computation of affected ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3956
diff changeset
   507
                revs = newrevs
2366
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   508
3247
d8e6c5338053 deptcache: make sure we warm the dept cache before warming the obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3171
diff changeset
   509
        repo.depthcache.update(repo)
3357
6020f2c9dbd9 obshashrange: add a progressbar to upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3355
diff changeset
   510
        total = len(revs)
6020f2c9dbd9 obshashrange: add a progressbar to upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3355
diff changeset
   511
6020f2c9dbd9 obshashrange: add a progressbar to upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3355
diff changeset
   512
        def progress(pos, rev):
6020f2c9dbd9 obshashrange: add a progressbar to upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3355
diff changeset
   513
            repo.ui.progress('updating obshashrange cache',
6020f2c9dbd9 obshashrange: add a progressbar to upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3355
diff changeset
   514
                             pos, 'rev %s' % rev, unit='revision', total=total)
2366
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   515
        # warm the cache for the new revs
3357
6020f2c9dbd9 obshashrange: add a progressbar to upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3355
diff changeset
   516
        progress(0, '')
6020f2c9dbd9 obshashrange: add a progressbar to upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3355
diff changeset
   517
        for idx, r in enumerate(revs):
2366
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   518
            _obshashrange(repo, (r, 0))
3357
6020f2c9dbd9 obshashrange: add a progressbar to upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3355
diff changeset
   519
            progress(idx, r)
6020f2c9dbd9 obshashrange: add a progressbar to upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3355
diff changeset
   520
        progress(None, '')
2366
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   521
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   522
        del self._updating
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   523
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   524
    @property
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   525
    def _fullcachekey(self):
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   526
        return (self._schemaversion, ) + self._cachekey
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   527
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   528
    def load(self, repo):
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   529
        if self._con is None:
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   530
            self._cachekey = self.emptykey
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   531
            self._ondiskcachekey = self.emptykey
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   532
        assert self._cachekey is not None
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   533
2399
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   534
    def _db(self):
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   535
        try:
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   536
            util.makedirs(self._vfs.dirname(self._path))
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   537
        except OSError:
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   538
            return None
4017
c307ce1d9009 sqlcache: passe better connection option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3963
diff changeset
   539
        con = sqlite3.connect(self._path, timeout=30, isolation_level="IMMEDIATE")
2399
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   540
        con.text_factory = str
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   541
        return con
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   542
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   543
    @util.propertycache
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   544
    def _con(self):
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   545
        if not self._valid:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   546
            return None
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   547
        repo = self._repo()
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   548
        if repo is None:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   549
            return None
2399
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   550
        con = self._db()
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   551
        if con is None:
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   552
            return None
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   553
        cur = con.execute(_queryexist)
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   554
        if cur.fetchone() is None:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   555
            self._valid = False
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   556
            return None
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   557
        meta = con.execute(_querymeta).fetchone()
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   558
        if meta is None or meta[0] != self._schemaversion:
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   559
            self._valid = False
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   560
            return None
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   561
        self._cachekey = self._ondiskcachekey = meta[1:]
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   562
        return con
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   563
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   564
    def save(self, repo):
2361
5c5f982b98f7 obshashrange: exit early if nothing to write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2360
diff changeset
   565
        if self._cachekey is None:
5c5f982b98f7 obshashrange: exit early if nothing to write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2360
diff changeset
   566
            return
5c5f982b98f7 obshashrange: exit early if nothing to write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2360
diff changeset
   567
        if self._cachekey == self._ondiskcachekey and not self._new:
5c5f982b98f7 obshashrange: exit early if nothing to write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2360
diff changeset
   568
            return
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   569
        repo = repo.unfiltered()
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   570
        try:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   571
            with repo.lock():
3963
d2e9a03fb3f7 obshashrange: always save stable range cache alongside the obshashrange one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3962
diff changeset
   572
                if 'stablerange' in vars(repo):
d2e9a03fb3f7 obshashrange: always save stable range cache alongside the obshashrange one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3962
diff changeset
   573
                    repo.stablerange.save(repo)
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   574
                self._save(repo)
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   575
        except error.LockError:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   576
            # Exceptionnally we are noisy about it since performance impact
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   577
            # is large We should address that before using this more
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   578
            # widely.
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   579
            msg = _('obshashrange cache: skipping save unable to lock repo\n')
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   580
            repo.ui.warn(msg)
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   581
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   582
    def _save(self, repo):
4023
f59b262400fb sqlite: fast path when nothing to save
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4022
diff changeset
   583
        if not self._new:
f59b262400fb sqlite: fast path when nothing to save
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4022
diff changeset
   584
            return
4018
b3517f834f83 sqlcache: cache OperationError when saving
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4017
diff changeset
   585
        try:
b3517f834f83 sqlcache: cache OperationError when saving
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4017
diff changeset
   586
            return self._trysave(repo)
4019
8a6a2c37c0fa sqlcache: also ignore integrity error
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4018
diff changeset
   587
        except (sqlite3.OperationalError, sqlite3.IntegrityError) as exc:
8a6a2c37c0fa sqlcache: also ignore integrity error
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4018
diff changeset
   588
            # Catch error that may arise under stress
8a6a2c37c0fa sqlcache: also ignore integrity error
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4018
diff changeset
   589
            #
8a6a2c37c0fa sqlcache: also ignore integrity error
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4018
diff changeset
   590
            # operational error catch read-only and locked database
8a6a2c37c0fa sqlcache: also ignore integrity error
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4018
diff changeset
   591
            # IntegrityError catch Unique constraint error that may arise
8a6a2c37c0fa sqlcache: also ignore integrity error
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4018
diff changeset
   592
            if '_con' in vars(self):
8a6a2c37c0fa sqlcache: also ignore integrity error
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4018
diff changeset
   593
                del self._con
8a6a2c37c0fa sqlcache: also ignore integrity error
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4018
diff changeset
   594
            self._new.clear()
4018
b3517f834f83 sqlcache: cache OperationError when saving
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4017
diff changeset
   595
            repo.ui.log('evoext-cache', 'error while saving new data: %s' % exc)
b3517f834f83 sqlcache: cache OperationError when saving
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4017
diff changeset
   596
b3517f834f83 sqlcache: cache OperationError when saving
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4017
diff changeset
   597
    def _trysave(self, repo):
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   598
        if self._con is None:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   599
            util.unlinkpath(self._path, ignoremissing=True)
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   600
            if '_con' in vars(self):
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   601
                del self._con
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   602
2399
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   603
            con = self._db()
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   604
            if con is None:
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   605
                repo.ui.log('evoext-cache', 'unable to write obshashrange cache'
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   606
                            ' - cannot create database')
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   607
                return
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   608
            with con:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   609
                for req in _sqliteschema:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   610
                    con.execute(req)
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   611
4025
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   612
                meta = [self._schemaversion] + list(self.emptykey)
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   613
                con.execute(_newmeta, meta)
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   614
                self._ondiskcachekey = self.emptykey
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   615
        else:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   616
            con = self._con
4025
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   617
        with con:
4021
bebba5a5c82d obshashrange: always check in base cachekey against the recorded one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4019
diff changeset
   618
            meta = con.execute(_querymeta).fetchone()
bebba5a5c82d obshashrange: always check in base cachekey against the recorded one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4019
diff changeset
   619
            if meta[1:] != self._ondiskcachekey:
bebba5a5c82d obshashrange: always check in base cachekey against the recorded one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4019
diff changeset
   620
                # drifting is currently an issue because this means another
bebba5a5c82d obshashrange: always check in base cachekey against the recorded one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4019
diff changeset
   621
                # process might have already added the cache line we are about
bebba5a5c82d obshashrange: always check in base cachekey against the recorded one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4019
diff changeset
   622
                # to add. This will confuse sqlite
bebba5a5c82d obshashrange: always check in base cachekey against the recorded one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4019
diff changeset
   623
                msg = _('obshashrange cache: skipping write, '
bebba5a5c82d obshashrange: always check in base cachekey against the recorded one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4019
diff changeset
   624
                        'database drifted under my feet\n')
bebba5a5c82d obshashrange: always check in base cachekey against the recorded one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4019
diff changeset
   625
                repo.ui.warn(msg)
4025
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   626
                self._new.clear()
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   627
                self._valid = False
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   628
                if '_con' in vars(self):
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   629
                    del self._con
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   630
                self._valid = False
4021
bebba5a5c82d obshashrange: always check in base cachekey against the recorded one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4019
diff changeset
   631
                return
4025
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   632
            data = ((rangeid[0], rangeid[1], self.get(rangeid)) for rangeid in self._new)
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   633
            con.executemany(_updateobshash, data)
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   634
            cachekey = self._fullcachekey
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   635
            con.execute(_clearmeta) # remove the older entry
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   636
            con.execute(_newmeta, cachekey)
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   637
            self._new.clear()
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   638
            self._valid = True
971d2e81b5b6 obshashrange: rework saving branching to be clearer and safer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4024
diff changeset
   639
            self._ondiskcachekey = self._cachekey
2083
778afb036245 discovery: introduce a official 'obshash associated to a range
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2082
diff changeset
   640
@eh.wrapfunction(obsolete.obsstore, '_addmarkers')
778afb036245 discovery: introduce a official 'obshash associated to a range
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2082
diff changeset
   641
def _addmarkers(orig, obsstore, *args, **kwargs):
778afb036245 discovery: introduce a official 'obshash associated to a range
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2082
diff changeset
   642
    obsstore.rangeobshashcache.clear()
778afb036245 discovery: introduce a official 'obshash associated to a range
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2082
diff changeset
   643
    return orig(obsstore, *args, **kwargs)
778afb036245 discovery: introduce a official 'obshash associated to a range
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2082
diff changeset
   644
3144
6f10c94a2114 compat: stop working around 3.8 file cache limitation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   645
obsstorefilecache = localrepo.localrepository.obsstore
2244
c7da63d48f80 compat: work around some filecache bug in 3.8
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2243
diff changeset
   646
c7da63d48f80 compat: work around some filecache bug in 3.8
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2243
diff changeset
   647
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   648
# obsstore is a filecache so we have do to some spacial dancing
2244
c7da63d48f80 compat: work around some filecache bug in 3.8
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2243
diff changeset
   649
@eh.wrapfunction(obsstorefilecache, 'func')
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   650
def obsstorewithcache(orig, repo):
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   651
    obsstore = orig(repo)
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   652
    obsstore.rangeobshashcache = _obshashcache(repo.unfiltered())
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   653
    return obsstore
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   654
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   655
@eh.reposetup
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   656
def setupcache(ui, repo):
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   657
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   658
    class obshashrepo(repo.__class__):
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   659
        @localrepo.unfilteredmethod
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   660
        def destroyed(self):
2363
2ceb122fcc33 obshashrange: properly invalidate the cache on destroyed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2362
diff changeset
   661
            if 'obsstore' in vars(self):
2ceb122fcc33 obshashrange: properly invalidate the cache on destroyed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2362
diff changeset
   662
                self.obsstore.rangeobshashcache.clear()
2287
18b8dc058f75 repo: properly progate "destroyed" call to super class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2244
diff changeset
   663
            super(obshashrepo, self).destroyed()
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   664
3354
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   665
        if util.safehasattr(repo, 'updatecaches'):
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   666
            @localrepo.unfilteredmethod
3504
5dc34b857114 updatecaches: handle any new parameters to the method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3500
diff changeset
   667
            def updatecaches(self, tr=None, **kwargs):
3366
83b372eceb81 caches: pass the transaction to the "shouldwarncache" logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3357
diff changeset
   668
                if utility.shouldwarmcache(self, tr):
3354
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   669
                    self.obsstore.rangeobshashcache.update(self)
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   670
                    self.obsstore.rangeobshashcache.save(self)
3504
5dc34b857114 updatecaches: handle any new parameters to the method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3500
diff changeset
   671
                super(obshashrepo, self).updatecaches(tr, **kwargs)
2364
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   672
3354
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   673
        else:
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   674
            def transaction(self, *args, **kwargs):
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   675
                tr = super(obshashrepo, self).transaction(*args, **kwargs)
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   676
                reporef = weakref.ref(self)
2364
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   677
3354
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   678
                def _warmcache(tr):
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   679
                    repo = reporef()
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   680
                    if repo is None:
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   681
                        return
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   682
                    repo = repo.unfiltered()
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   683
                    repo.obsstore.rangeobshashcache.update(repo)
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   684
                    repo.obsstore.rangeobshashcache.save(repo)
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   685
3366
83b372eceb81 caches: pass the transaction to the "shouldwarncache" logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3357
diff changeset
   686
                if utility.shouldwarmcache(self, tr):
3354
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   687
                    tr.addpostclose('warmcache-20obshashrange', _warmcache)
32e7ceaf1d82 obshashrange: update the cache updating logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3346
diff changeset
   688
                return tr
2364
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   689
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   690
    repo.__class__ = obshashrepo
2083
778afb036245 discovery: introduce a official 'obshash associated to a range
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2082
diff changeset
   691
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   692
### wire protocol commands
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   693
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   694
def _obshashrange_v0(repo, ranges):
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   695
    """return a list of hash from a list of range
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   696
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   697
    The range have the id encoded as a node
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   698
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   699
    return 'wdirid' for unknown range"""
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   700
    nm = repo.changelog.nodemap
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   701
    ranges = [(nm.get(n), idx) for n, idx in ranges]
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   702
    if ranges:
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   703
        maxrev = max(r for r, i in ranges)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   704
        if maxrev is not None:
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   705
            repo.stablerange.warmup(repo, upto=maxrev)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   706
    result = []
2365
4b8b7fd135eb obshashrange: warm cache outside of loops
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2364
diff changeset
   707
    repo.obsstore.rangeobshashcache.update(repo)
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   708
    for r in ranges:
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   709
        if r[0] is None:
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   710
            result.append(node.wdirid)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   711
        else:
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   712
            result.append(_obshashrange(repo, r))
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   713
    repo.obsstore.rangeobshashcache.save(repo)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   714
    return result
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   715
3346
f4e28b781143 stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3307
diff changeset
   716
@eh.addattr(localrepo.localpeer, 'evoext_obshashrange_v1')
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   717
def local_obshashrange_v0(peer, ranges):
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   718
    return _obshashrange_v0(peer._repo, ranges)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   719
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   720
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   721
_indexformat = '>I'
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   722
_indexsize = _calcsize(_indexformat)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   723
def _encrange(node_rangeid):
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   724
    """encode a (node) range"""
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   725
    headnode, index = node_rangeid
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   726
    return headnode + _pack(_indexformat, index)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   727
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   728
def _decrange(data):
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   729
    """encode a (node) range"""
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   730
    assert _indexsize < len(data), len(data)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   731
    headnode = data[:-_indexsize]
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   732
    index = _unpack(_indexformat, data[-_indexsize:])[0]
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   733
    return (headnode, index)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   734
3669
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
   735
@eh.addattr(wirepeer, 'evoext_obshashrange_v1')
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   736
def peer_obshashrange_v0(self, ranges):
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   737
    binranges = [_encrange(r) for r in ranges]
3669
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
   738
    encranges = encodelist(binranges)
3346
f4e28b781143 stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3307
diff changeset
   739
    d = self._call("evoext_obshashrange_v1", ranges=encranges)
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   740
    try:
3669
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
   741
        return decodelist(d)
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   742
    except ValueError:
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   743
        self._abort(error.ResponseError(_("unexpected response:"), d))
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   744
3524
6d4095e6bdd3 obsdiscovery: add compatibility layer to register wireproto command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3521
diff changeset
   745
@compat.wireprotocommand(eh, 'evoext_obshashrange_v1', 'ranges')
3346
f4e28b781143 stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3307
diff changeset
   746
def srv_obshashrange_v1(repo, proto, ranges):
3669
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
   747
    ranges = decodelist(ranges)
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   748
    ranges = [_decrange(r) for r in ranges]
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   749
    hashes = _obshashrange_v0(repo, ranges)
3669
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
   750
    return encodelist(hashes)
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   751
2551
ecd47c63b6de obshashrange: add an option to protect from accidental activation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2525
diff changeset
   752
def _useobshashrange(repo):
ecd47c63b6de obshashrange: add an option to protect from accidental activation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2525
diff changeset
   753
    base = repo.ui.configbool('experimental', 'obshashrange', False)
ecd47c63b6de obshashrange: add an option to protect from accidental activation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2525
diff changeset
   754
    if base:
ecd47c63b6de obshashrange: add an option to protect from accidental activation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2525
diff changeset
   755
        maxrevs = repo.ui.configint('experimental', 'obshashrange.max-revs', None)
ecd47c63b6de obshashrange: add an option to protect from accidental activation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2525
diff changeset
   756
        if maxrevs is not None and maxrevs < len(repo.unfiltered()):
ecd47c63b6de obshashrange: add an option to protect from accidental activation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2525
diff changeset
   757
            base = False
ecd47c63b6de obshashrange: add an option to protect from accidental activation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2525
diff changeset
   758
    return base
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   759
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   760
def _canobshashrange(local, remote):
2551
ecd47c63b6de obshashrange: add an option to protect from accidental activation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2525
diff changeset
   761
    return (_useobshashrange(local)
3346
f4e28b781143 stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3307
diff changeset
   762
            and remote.capable('_evoext_obshashrange_v1'))
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   763
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   764
def _obshashrange_capabilities(orig, repo, proto):
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   765
    """wrapper to advertise new capability"""
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   766
    caps = orig(repo, proto)
2551
ecd47c63b6de obshashrange: add an option to protect from accidental activation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2525
diff changeset
   767
    enabled = _useobshashrange(repo)
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   768
    if obsolete.isenabled(repo, obsolete.exchangeopt) and enabled:
3500
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   769
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   770
        # Compat hg 4.6+ (2f7290555c96)
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   771
        bytesresponse = False
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   772
        if util.safehasattr(caps, 'data'):
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   773
            bytesresponse = True
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   774
            caps = caps.data
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   775
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   776
        caps = caps.split()
3500
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   777
        caps.append(b'_evoext_obshashrange_v1')
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   778
        caps.sort()
3500
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   779
        caps = b' '.join(caps)
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   780
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   781
        # Compat hg 4.6+ (2f7290555c96)
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   782
        if bytesresponse:
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   783
            caps = wireprototypes.bytesresponse(caps)
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   784
    return caps
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   785
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   786
@eh.extsetup
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   787
def obshashrange_extsetup(ui):
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   788
    ###
3681
3f90e6c5d140 discovery: handle deletion of 'wireproto' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3669
diff changeset
   789
    extensions.wrapfunction(wireprotov1server, 'capabilities',
3f90e6c5d140 discovery: handle deletion of 'wireproto' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3669
diff changeset
   790
                            _obshashrange_capabilities)
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   791
    # wrap command content
3681
3f90e6c5d140 discovery: handle deletion of 'wireproto' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3669
diff changeset
   792
    oldcap, args = wireprotov1server.commands['capabilities']
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   793
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   794
    def newcap(repo, proto):
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   795
        return _obshashrange_capabilities(oldcap, repo, proto)
3681
3f90e6c5d140 discovery: handle deletion of 'wireproto' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3669
diff changeset
   796
    wireprotov1server.commands['capabilities'] = (newcap, args)
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   797
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   798
#############################
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   799
### Tree Hash computation ###
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   800
#############################
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   801
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   802
# Dash computed from a given changesets using all markers relevant to it and
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   803
# the obshash of its parents.  This is similar to what happend for changeset
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   804
# node where the parent is used in the computation
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   805
2510
b99b83728ea3 obsdiscovery: extract '_canobshashtree'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2509
diff changeset
   806
def _canobshashtree(repo, remote):
b99b83728ea3 obsdiscovery: extract '_canobshashtree'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2509
diff changeset
   807
    return remote.capable('_evoext_obshash_0')
b99b83728ea3 obsdiscovery: extract '_canobshashtree'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2509
diff changeset
   808
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   809
@eh.command(
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   810
    'debugobsrelsethashtree',
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   811
    [('', 'v0', None, 'hash on marker format "0"'),
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   812
     ('', 'v1', None, 'hash on marker format "1" (default)')], _(''))
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   813
def debugobsrelsethashtree(ui, repo, v0=False, v1=False):
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   814
    """display Obsolete markers, Relevant Set, Hash Tree
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   815
    changeset-node obsrelsethashtree-node
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   816
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   817
    It computed form the "orsht" of its parent and markers
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   818
    relevant to the changeset itself."""
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   819
    if v0 and v1:
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   820
        raise error.Abort('cannot only specify one format')
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   821
    elif v0:
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   822
        treefunc = _obsrelsethashtreefm0
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   823
    else:
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   824
        treefunc = _obsrelsethashtreefm1
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   825
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   826
    for chg, obs in treefunc(repo):
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   827
        ui.status('%s %s\n' % (node.hex(chg), node.hex(obs)))
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   828
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   829
def _obsrelsethashtreefm0(repo):
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   830
    return _obsrelsethashtree(repo, obsolete._fm0encodeonemarker)
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   831
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   832
def _obsrelsethashtreefm1(repo):
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   833
    return _obsrelsethashtree(repo, obsolete._fm1encodeonemarker)
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   834
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   835
def _obsrelsethashtree(repo, encodeonemarker):
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   836
    cache = []
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   837
    unfi = repo.unfiltered()
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   838
    markercache = {}
3521
b738bfbef3a0 obsdiscovery: include units in ui.progress() calls (issue5773)
Anton Shestakov <av6@dwimlabs.net>
parents: 3504
diff changeset
   839
    repo.ui.progress(_("preparing locally"), 0, total=len(unfi),
b738bfbef3a0 obsdiscovery: include units in ui.progress() calls (issue5773)
Anton Shestakov <av6@dwimlabs.net>
parents: 3504
diff changeset
   840
                     unit=_("changesets"))
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   841
    for i in unfi:
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   842
        ctx = unfi[i]
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   843
        entry = 0
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   844
        sha = hashlib.sha1()
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   845
        # add data from p1
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   846
        for p in ctx.parents():
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   847
            p = p.rev()
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   848
            if p < 0:
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   849
                p = node.nullid
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   850
            else:
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   851
                p = cache[p][1]
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   852
            if p != node.nullid:
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   853
                entry += 1
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   854
                sha.update(p)
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   855
        tmarkers = repo.obsstore.relevantmarkers([ctx.node()])
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   856
        if tmarkers:
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   857
            bmarkers = []
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   858
            for m in tmarkers:
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   859
                if m not in markercache:
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   860
                    markercache[m] = encodeonemarker(m)
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   861
                bmarkers.append(markercache[m])
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   862
            bmarkers.sort()
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   863
            for m in bmarkers:
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   864
                entry += 1
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   865
                sha.update(m)
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   866
        if entry:
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   867
            cache.append((ctx.node(), sha.digest()))
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   868
        else:
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   869
            cache.append((ctx.node(), node.nullid))
3521
b738bfbef3a0 obsdiscovery: include units in ui.progress() calls (issue5773)
Anton Shestakov <av6@dwimlabs.net>
parents: 3504
diff changeset
   870
        repo.ui.progress(_("preparing locally"), i, total=len(unfi),
b738bfbef3a0 obsdiscovery: include units in ui.progress() calls (issue5773)
Anton Shestakov <av6@dwimlabs.net>
parents: 3504
diff changeset
   871
                         unit=_("changesets"))
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   872
    repo.ui.progress(_("preparing locally"), None)
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   873
    return cache
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   874
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   875
def _obshash(repo, nodes, version=0):
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   876
    if version == 0:
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   877
        hashs = _obsrelsethashtreefm0(repo)
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   878
    elif version == 1:
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   879
        hashs = _obsrelsethashtreefm1(repo)
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   880
    else:
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   881
        assert False
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   882
    nm = repo.changelog.nodemap
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   883
    revs = [nm.get(n) for n in nodes]
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   884
    return [r is None and node.nullid or hashs[r][1] for r in revs]
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   885
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   886
@eh.addattr(localrepo.localpeer, 'evoext_obshash')
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   887
def local_obshash(peer, nodes):
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   888
    return _obshash(peer._repo, nodes)
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   889
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   890
@eh.addattr(localrepo.localpeer, 'evoext_obshash1')
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   891
def local_obshash1(peer, nodes):
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   892
    return _obshash(peer._repo, nodes, version=1)
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   893
3669
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
   894
@eh.addattr(wirepeer, 'evoext_obshash')
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   895
def peer_obshash(self, nodes):
3669
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
   896
    d = self._call("evoext_obshash", nodes=encodelist(nodes))
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   897
    try:
3669
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
   898
        return decodelist(d)
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   899
    except ValueError:
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   900
        self._abort(error.ResponseError(_("unexpected response:"), d))
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   901
3669
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
   902
@eh.addattr(wirepeer, 'evoext_obshash1')
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   903
def peer_obshash1(self, nodes):
3669
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
   904
    d = self._call("evoext_obshash1", nodes=encodelist(nodes))
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   905
    try:
3669
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
   906
        return decodelist(d)
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   907
    except ValueError:
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   908
        self._abort(error.ResponseError(_("unexpected response:"), d))
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   909
3524
6d4095e6bdd3 obsdiscovery: add compatibility layer to register wireproto command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3521
diff changeset
   910
@compat.wireprotocommand(eh, 'evoext_obshash', 'nodes')
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   911
def srv_obshash(repo, proto, nodes):
3669
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
   912
    return encodelist(_obshash(repo, decodelist(nodes)))
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   913
3524
6d4095e6bdd3 obsdiscovery: add compatibility layer to register wireproto command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3521
diff changeset
   914
@compat.wireprotocommand(eh, 'evoext_obshash1', 'nodes')
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   915
def srv_obshash1(repo, proto, nodes):
3669
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
   916
    return encodelist(_obshash(repo, decodelist(nodes),
0407965ae79e compat: deal with change in the wireproto module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3524
diff changeset
   917
                      version=1))
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   918
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   919
def _obshash_capabilities(orig, repo, proto):
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   920
    """wrapper to advertise new capability"""
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   921
    caps = orig(repo, proto)
3171
dbd340eafcb0 obsdiscovery: enforce the config on the server too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3144
diff changeset
   922
    if (obsolete.isenabled(repo, obsolete.exchangeopt)
dbd340eafcb0 obsdiscovery: enforce the config on the server too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3144
diff changeset
   923
        and repo.ui.configbool('experimental', 'evolution.obsdiscovery', True)):
3500
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   924
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   925
        # Compat hg 4.6+ (2f7290555c96)
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   926
        bytesresponse = False
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   927
        if util.safehasattr(caps, 'data'):
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   928
            bytesresponse = True
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   929
            caps = caps.data
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   930
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   931
        caps = caps.split()
3500
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   932
        caps.append(b'_evoext_obshash_0')
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   933
        caps.append(b'_evoext_obshash_1')
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   934
        caps.sort()
3500
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   935
        caps = b' '.join(caps)
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   936
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   937
        # Compat hg 4.6+ (2f7290555c96)
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   938
        if bytesresponse:
a43fdbd6f7eb wireproto: fix *_capabilities for change of API types
Boris Feld <boris.feld@octobus.net>
parents: 3366
diff changeset
   939
            caps = wireprototypes.bytesresponse(caps)
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   940
    return caps
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   941
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   942
@eh.extsetup
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   943
def obshash_extsetup(ui):
3681
3f90e6c5d140 discovery: handle deletion of 'wireproto' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3669
diff changeset
   944
    extensions.wrapfunction(wireprotov1server, 'capabilities',
3f90e6c5d140 discovery: handle deletion of 'wireproto' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3669
diff changeset
   945
                            _obshash_capabilities)
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   946
    # wrap command content
3681
3f90e6c5d140 discovery: handle deletion of 'wireproto' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3669
diff changeset
   947
    oldcap, args = wireprotov1server.commands['capabilities']
2061
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   948
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   949
    def newcap(repo, proto):
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   950
        return _obshash_capabilities(oldcap, repo, proto)
3681
3f90e6c5d140 discovery: handle deletion of 'wireproto' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3669
diff changeset
   951
    wireprotov1server.commands['capabilities'] = (newcap, args)
2509
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   952
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   953
##########################################
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   954
###  trigger discovery during exchange ###
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   955
##########################################
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   956
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   957
def _dopushmarkers(pushop):
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   958
    return (# we have any markers to push
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   959
            pushop.repo.obsstore
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   960
            # exchange of obsmarkers is enabled locally
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   961
            and obsolete.isenabled(pushop.repo, obsolete.exchangeopt)
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   962
            # remote server accept markers
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   963
            and 'obsolete' in pushop.remote.listkeys('namespaces'))
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   964
2512
0e6ae8db9c21 obsdiscovery: extract push-obshashrange discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2511
diff changeset
   965
def _pushobshashrange(pushop, commonrevs):
0e6ae8db9c21 obsdiscovery: extract push-obshashrange discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2511
diff changeset
   966
    repo = pushop.repo.unfiltered()
0e6ae8db9c21 obsdiscovery: extract push-obshashrange discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2511
diff changeset
   967
    remote = pushop.remote
0e6ae8db9c21 obsdiscovery: extract push-obshashrange discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2511
diff changeset
   968
    missing = findmissingrange(pushop.ui, repo, remote, commonrevs)
0e6ae8db9c21 obsdiscovery: extract push-obshashrange discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2511
diff changeset
   969
    missing += pushop.outgoing.missing
0e6ae8db9c21 obsdiscovery: extract push-obshashrange discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2511
diff changeset
   970
    return missing
0e6ae8db9c21 obsdiscovery: extract push-obshashrange discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2511
diff changeset
   971
2514
b9f03002f214 obsdiscovery: extract push-obshashtree discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2513
diff changeset
   972
def _pushobshashtree(pushop, commonrevs):
b9f03002f214 obsdiscovery: extract push-obshashtree discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2513
diff changeset
   973
    repo = pushop.repo.unfiltered()
b9f03002f214 obsdiscovery: extract push-obshashtree discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2513
diff changeset
   974
    remote = pushop.remote
b9f03002f214 obsdiscovery: extract push-obshashtree discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2513
diff changeset
   975
    node = repo.changelog.node
b9f03002f214 obsdiscovery: extract push-obshashtree discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2513
diff changeset
   976
    common = findcommonobsmarkers(pushop.ui, repo, remote, commonrevs)
b9f03002f214 obsdiscovery: extract push-obshashtree discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2513
diff changeset
   977
    revs = list(repo.revs('only(%ln, %ln)', pushop.futureheads, common))
b9f03002f214 obsdiscovery: extract push-obshashtree discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2513
diff changeset
   978
    return [node(r) for r in revs]
b9f03002f214 obsdiscovery: extract push-obshashtree discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2513
diff changeset
   979
2515
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   980
# available discovery method, first valid is used
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   981
# tuple (canuse, perform discovery))
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   982
obsdiscoveries = [
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   983
    (_canobshashrange, _pushobshashrange),
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   984
    (_canobshashtree, _pushobshashtree),
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   985
]
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   986
2521
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   987
obsdiscovery_skip_message = """\
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   988
(skipping discovery of obsolescence markers, will exchange everything)
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   989
(controled by 'experimental.evolution.obsdiscovery' configuration)
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   990
"""
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   991
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   992
def usediscovery(repo):
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   993
    return repo.ui.configbool('experimental', 'evolution.obsdiscovery', True)
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   994
2509
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   995
@eh.wrapfunction(exchange, '_pushdiscoveryobsmarkers')
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   996
def _pushdiscoveryobsmarkers(orig, pushop):
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   997
    if _dopushmarkers(pushop):
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   998
        repo = pushop.repo
2515
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   999
        remote = pushop.remote
2509
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1000
        obsexcmsg(repo.ui, "computing relevant nodes\n")
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1001
        revs = list(repo.revs('::%ln', pushop.futureheads))
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1002
        unfi = repo.unfiltered()
2515
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
  1003
2521
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
  1004
        if not usediscovery(repo):
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
  1005
            # discovery disabled by user
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
  1006
            repo.ui.status(obsdiscovery_skip_message)
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
  1007
            return orig(pushop)
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
  1008
2515
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
  1009
        # look for an obs-discovery protocol we can use
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
  1010
        discovery = None
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
  1011
        for candidate in obsdiscoveries:
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
  1012
            if candidate[0](repo, remote):
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
  1013
                discovery = candidate[1]
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
  1014
                break
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
  1015
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
  1016
        if discovery is None:
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
  1017
            # no discovery available, rely on core to push all relevants
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
  1018
            # obs markers.
2509
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1019
            return orig(pushop)
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1020
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1021
        obsexcmsg(repo.ui, "looking for common markers in %i nodes\n"
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1022
                           % len(revs))
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1023
        commonrevs = list(unfi.revs('::%ln', pushop.outgoing.commonheads))
2515
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
  1024
        # find the nodes where the relevant obsmarkers mismatches
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
  1025
        nodes = discovery(pushop, commonrevs)
2509
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1026
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1027
        if nodes:
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1028
            obsexcmsg(repo.ui, "computing markers relevant to %i nodes\n"
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1029
                               % len(nodes))
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1030
            pushop.outobsmarkers = repo.obsstore.relevantmarkers(nodes)
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1031
        else:
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1032
            obsexcmsg(repo.ui, "markers already in sync\n")
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1033
            pushop.outobsmarkers = []
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1034
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1035
@eh.extsetup
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1036
def _installobsmarkersdiscovery(ui):
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1037
    olddisco = exchange.pushdiscoverymapping['obsmarker']
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1038
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1039
    def newdisco(pushop):
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1040
        _pushdiscoveryobsmarkers(olddisco, pushop)
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1041
    exchange.pushdiscoverymapping['obsmarker'] = newdisco
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1042
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1043
def buildpullobsmarkersboundaries(pullop, bundle2=True):
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1044
    """small function returning the argument for pull markers call
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1045
    may to contains 'heads' and 'common'. skip the key for None.
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1046
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1047
    It is a separed function to play around with strategy for that."""
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1048
    repo = pullop.repo
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1049
    remote = pullop.remote
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1050
    unfi = repo.unfiltered()
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1051
    revs = unfi.revs('::(%ln - null)', pullop.common)
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1052
    boundaries = {'heads': pullop.pulledsubset}
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1053
    if not revs: # nothing common
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1054
        boundaries['common'] = [node.nullid]
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1055
        return boundaries
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1056
2521
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
  1057
    if not usediscovery(repo):
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
  1058
        # discovery disabled by users.
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
  1059
        repo.ui.status(obsdiscovery_skip_message)
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
  1060
        boundaries['common'] = [node.nullid]
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
  1061
        return boundaries
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
  1062
2509
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1063
    if bundle2 and _canobshashrange(repo, remote):
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1064
        obsexcmsg(repo.ui, "looking for common markers in %i nodes\n"
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1065
                  % len(revs))
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1066
        boundaries['missing'] = findmissingrange(repo.ui, repo, pullop.remote,
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1067
                                                 revs)
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1068
    elif remote.capable('_evoext_obshash_0'):
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1069
        obsexcmsg(repo.ui, "looking for common markers in %i nodes\n"
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1070
                           % len(revs))
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1071
        boundaries['common'] = findcommonobsmarkers(repo.ui, repo, remote, revs)
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1072
    else:
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1073
        boundaries['common'] = [node.nullid]
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
  1074
    return boundaries
3952
a7794f5abacd discovery: make sure repository wrapping happens in the right order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3708
diff changeset
  1075
a7794f5abacd discovery: make sure repository wrapping happens in the right order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3708
diff changeset
  1076
# merge later for outer layer wrapping
a7794f5abacd discovery: make sure repository wrapping happens in the right order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3708
diff changeset
  1077
eh.merge(stablerangecache.eh)