hgext3rd/evolve/obsdiscovery.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Fri, 16 Jun 2017 19:48:24 +0200
branchmercurial-3.8
changeset 2618 d8bd722f4be7
parent 2551 ecd47c63b6de
child 3080 461c9d940519
permissions -rw-r--r--
test-compat: merge with mercurial-3.9
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
2424
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2413
diff changeset
    27
import os
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
    28
import sqlite3
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
    29
import struct
2424
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2413
diff changeset
    30
import time
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
    31
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
    32
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    33
from mercurial import (
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
    34
    dagutil,
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    35
    error,
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    36
    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
    37
    extensions,
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    38
    localrepo,
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    39
    node,
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    40
    obsolete,
2424
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2413
diff changeset
    41
    pycompat,
2081
010a8af416a0 discovery: adds a function doing revnum independant sorting
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2076
diff changeset
    42
    scmutil,
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
    43
    setdiscovery,
2082
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
    44
    util,
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    45
    wireproto,
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    46
)
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
    47
from mercurial.hgweb import hgweb_mod
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    48
from mercurial.i18n import _
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    49
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    50
from . import (
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    51
    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
    52
    obscache,
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    53
    utility,
2125
e0a25339ff17 stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2124
diff changeset
    54
    stablerange,
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    55
)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    56
2424
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2413
diff changeset
    57
# prior to hg-4.2 there are not util.timer
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2413
diff changeset
    58
if util.safehasattr(util, 'timer'):
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2413
diff changeset
    59
    timer = util.timer
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2413
diff changeset
    60
elif util.safehasattr(time, "perf_counter"):
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2413
diff changeset
    61
    timer = time.perf_counter
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2413
diff changeset
    62
elif getattr(pycompat, 'osname', os.name) == 'nt':
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2413
diff changeset
    63
    timer = time.clock
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2413
diff changeset
    64
else:
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2413
diff changeset
    65
    timer = time.time
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2413
diff changeset
    66
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
    67
_pack = struct.pack
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
    68
_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
    69
_calcsize = struct.calcsize
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
    70
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    71
eh = exthelper.exthelper()
2125
e0a25339ff17 stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2124
diff changeset
    72
eh.merge(stablerange.eh)
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    73
obsexcmsg = utility.obsexcmsg
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    74
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
    75
##################################
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
    76
###  Code performing discovery ###
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
    77
##################################
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    78
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    79
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
    80
                         initialsamplesize=100,
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    81
                         fullsamplesize=200):
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    82
    # from discovery
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    83
    roundtrips = 0
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    84
    cl = local.changelog
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    85
    dag = dagutil.revlogdag(cl)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    86
    missing = set()
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    87
    common = set()
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    88
    undecided = set(probeset)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    89
    totalnb = len(undecided)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    90
    ui.progress(_("comparing with other"), 0, total=totalnb)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    91
    _takefullsample = setdiscovery._takefullsample
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    92
    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
    93
        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
    94
        localhash = _obsrelsethashtreefm1(local)
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    95
    else:
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    96
        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
    97
        localhash = _obsrelsethashtreefm0(local)
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    98
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    99
    while undecided:
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   100
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   101
        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
   102
        if len(undecided) < fullsamplesize:
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   103
            sample = set(undecided)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   104
        else:
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   105
            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
   106
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   107
        roundtrips += 1
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   108
        ui.progress(_("comparing with other"), totalnb - len(undecided),
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   109
                    total=totalnb)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   110
        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
   111
                 % (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
   112
        # 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
   113
        sample = list(sample)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   114
        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
   115
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   116
        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
   117
                 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
   118
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   119
        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
   120
        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
   121
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   122
        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
   123
        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
   124
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   125
        undecided.difference_update(missing)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   126
        undecided.difference_update(common)
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
    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
   129
    result = dag.headsetofconnecteds(common)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   130
    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
   131
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   132
    if not result:
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   133
        return set([node.nullid])
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   134
    return dag.externalizeall(result)
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   135
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   136
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
   137
                     initialsamplesize=100,
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   138
                     fullsamplesize=200):
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   139
    missing = set()
2424
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2413
diff changeset
   140
    starttime = timer()
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   141
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   142
    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
   143
    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
   144
2164
cc8ae2a66b0f stablerange: use rangelength in findmissingrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2158
diff changeset
   145
    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
   146
    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
   147
    # size of slice ?
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   148
    heappop = heapq.heappop
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   149
    heappush = heapq.heappush
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   150
    heapify = heapq.heapify
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   151
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   152
    tested = set()
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   153
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   154
    sample = []
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   155
    samplesize = initialsamplesize
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
    def addentry(entry):
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   158
        if entry in tested:
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   159
            return False
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   160
        sample.append(entry)
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   161
        tested.add(entry)
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   162
        return True
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   163
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   164
    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
   165
        entry = (h, 0)
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   166
        addentry(entry)
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   167
2365
4b8b7fd135eb obshashrange: warm cache outside of loops
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2364
diff changeset
   168
    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
   169
    querycount = 0
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   170
    ui.progress(_("comparing obsmarker with other"), querycount)
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   171
    overflow = []
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   172
    while sample or overflow:
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   173
        if overflow:
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   174
            sample.extend(overflow)
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
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   177
        if samplesize < len(sample):
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   178
            # too much sample already
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   179
            overflow = sample[samplesize:]
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   180
            sample = sample[:samplesize]
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   181
        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
   182
            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
   183
                     % (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
   184
            # we need more sample !
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   185
            needed = samplesize - len(sample)
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   186
            sliceme = []
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   187
            heapify(sliceme)
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   188
            for entry in sample:
2164
cc8ae2a66b0f stablerange: use rangelength in findmissingrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2158
diff changeset
   189
                if 1 < rangelength(local, entry):
cc8ae2a66b0f stablerange: use rangelength in findmissingrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2158
diff changeset
   190
                    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
   191
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   192
            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
   193
                _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
   194
                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
   195
                    # 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
   196
                    if addentry(new):
8a2e1f6e5443 findmissingrange: properly queue new subrange for slicing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2202
diff changeset
   197
                        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
   198
                            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
   199
                        needed -= 1
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   200
                        if needed <= 0:
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   201
                            break
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   202
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   203
        # 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
   204
        samplesize = fullsamplesize
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   205
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   206
        nbsample = len(sample)
2164
cc8ae2a66b0f stablerange: use rangelength in findmissingrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2158
diff changeset
   207
        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
   208
        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
   209
                 % (querycount, nbsample, maxsize))
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   210
        nbreplies = 0
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   211
        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
   212
        sample = []
2144
2200f67e1628 stablerange: stop using '.node' in findmissingrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2143
diff changeset
   213
        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
   214
        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
   215
            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
   216
            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
   217
                continue
2164
cc8ae2a66b0f stablerange: use rangelength in findmissingrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2158
diff changeset
   218
            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
   219
                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
   220
            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
   221
                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
   222
                    addentry(new)
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   223
        assert nbsample == nbreplies
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   224
        querycount += 1
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   225
        ui.progress(_("comparing obsmarker with other"), querycount)
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   226
    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
   227
    local.obsstore.rangeobshashcache.save(local)
2424
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2413
diff changeset
   228
    duration = timer() - starttime
2408
0af6bb0bfdc3 discovery: log information about obshashrange
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2399
diff changeset
   229
    logmsg = ('obsdiscovery, %d/%d mismatch'
0af6bb0bfdc3 discovery: log information about obshashrange
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2399
diff changeset
   230
              ' - %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
   231
    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
   232
    ui.log('evoext-obsdiscovery', logmsg)
2409
2b563a725cdc obsdiscovery: add more debug output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2408
diff changeset
   233
    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
   234
    return sorted(missing)
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   235
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   236
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
   237
    #  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
   238
    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
   239
    noderanges = [(n(entry[0]), entry[1]) for entry in allentries]
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   240
    replies = remote.evoext_obshashrange_v0(noderanges)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   241
    result = []
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   242
    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
   243
        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
   244
    return result
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   245
2082
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   246
##############################
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   247
### Range Hash computation ###
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   248
##############################
2084
b1f029dcf573 discovery: implement some range based discovery
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2083
diff changeset
   249
2082
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   250
@eh.command(
2229
575561934439 debug: rename 'debugstablerange' to 'debugobshashrange'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2228
diff changeset
   251
    'debugobshashrange',
2082
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   252
    [
2230
a202f3af890c debugobshashrange: add a --subranges option
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2229
diff changeset
   253
        ('', '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
   254
        ('', '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
   255
    ],
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   256
    _(''))
2229
575561934439 debug: rename 'debugstablerange' to 'debugobshashrange'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2228
diff changeset
   257
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
   258
    """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
   259
    """
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   260
    s = node.short
3f787182509f discovery: introduce "stable slicing" methods
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2081
diff changeset
   261
    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
   262
    # prewarm depth cache
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   263
    if revs:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   264
        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
   265
    cl = repo.changelog
2165
e97e9b0c9711 stablerange: use rangelength in debugstablerange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2164
diff changeset
   266
    rangelength = repo.stablerange.rangelength
2171
3be48332b802 stablerange: use depthrevs in debugstablerange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2166
diff changeset
   267
    depthrev = repo.stablerange.depthrev
2230
a202f3af890c debugobshashrange: add a --subranges option
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2229
diff changeset
   268
    if opts['subranges']:
a202f3af890c debugobshashrange: add a --subranges option
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2229
diff changeset
   269
        ranges = stablerange.subrangesclosure(repo, revs)
a202f3af890c debugobshashrange: add a --subranges option
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2229
diff changeset
   270
    else:
a202f3af890c debugobshashrange: add a --subranges option
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2229
diff changeset
   271
        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
   272
    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
   273
    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
   274
    headertemplate = linetemplate.replace('d', 's')
3b18440cca74 debugstablerange: improve output spacing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2203
diff changeset
   275
    ui.status(headertemplate % headers)
2365
4b8b7fd135eb obshashrange: warm cache outside of loops
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2364
diff changeset
   276
    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
   277
    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
   278
        d = (r[0],
2145
4c0c88e51018 stablerange: stop using '.node' in debugstablerange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2144
diff changeset
   279
             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
   280
             r[1],
2165
e97e9b0c9711 stablerange: use rangelength in debugstablerange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2164
diff changeset
   281
             rangelength(repo, r),
2171
3be48332b802 stablerange: use depthrevs in debugstablerange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2166
diff changeset
   282
             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
   283
             node.short(_obshashrange(repo, r)))
2228
3b18440cca74 debugstablerange: improve output spacing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2203
diff changeset
   284
        ui.status(linetemplate % d)
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   285
    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
   286
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
   287
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
   288
    """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
   289
    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
   290
    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
   291
    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
   292
    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
   293
        return obshash
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   294
    pieces = []
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   295
    nullid = node.nullid
2166
d4ff8708eb66 stablerange: use rangelength in _obshashrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2165
diff changeset
   296
    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
   297
        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
   298
        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
   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
        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
   301
            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
   302
            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
   303
        pieces.sort()
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   304
    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
   305
        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
   306
            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
   307
            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
   308
                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
   309
90f8f100dd58 obshashrange: extract computation back into the discovery module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2139
diff changeset
   310
    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
   311
    # 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
   312
    # 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
   313
    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
   314
        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
   315
    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
   316
        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
   317
        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
   318
            sha.update(p)
2195
bd3d35047181 obshash: properly cache obshash value
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2175
diff changeset
   319
        obshash = sha.digest()
bd3d35047181 obshash: properly cache obshash value
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2175
diff changeset
   320
    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
   321
    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
   322
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   323
### sqlite caching
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   324
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   325
_sqliteschema = [
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   326
    """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
   327
                         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
   328
                         tipnode       BLOB    NOT NULL,
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   329
                         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
   330
                         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
   331
                         obskey        BLOB    NOT NULL
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   332
                        );""",
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   333
    """CREATE TABLE obshashrange(rev     INTEGER NOT NULL,
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   334
                                 idx     INTEGER NOT NULL,
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   335
                                 obshash BLOB    NOT NULL,
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   336
                                 PRIMARY KEY(rev, idx));""",
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   337
    "CREATE INDEX range_index ON obshashrange(rev, idx);",
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   338
]
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   339
_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
   340
_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
   341
_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
   342
            VALUES (?,?,?,?,?,?);"""
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   343
_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
   344
_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
   345
_queryobshash = "SELECT obshash FROM obshashrange WHERE (rev = ? AND idx = ?);"
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   346
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   347
_reset = "DELETE FROM obshashrange;"
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   348
2373
2a1aad0fd8bf obshashrange: stop inheriting from 'dict'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2371
diff changeset
   349
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
   350
2525
5adb8bdb935e compatibility: backport mercurial 176d1a0ce385
Boris Feld <boris.feld@octobus.net>
parents: 2521
diff changeset
   351
    _schemaversion = 2
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   352
2376
12386f7f5056 dualsourcecache: add a cache name
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2374
diff changeset
   353
    _cachename = 'evo-ext-obshashrange' # used for error message
12386f7f5056 dualsourcecache: add a cache name
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2374
diff changeset
   354
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   355
    def __init__(self, repo):
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   356
        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
   357
        self._vfs = repo.vfs
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   358
        self._path = repo.vfs.join('cache/evoext_obshashrange_v1.sqlite')
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   359
        self._new = set()
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   360
        self._valid = True
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   361
        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
   362
        # cache status
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   363
        self._ondiskcachekey = None
2373
2a1aad0fd8bf obshashrange: stop inheriting from 'dict'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2371
diff changeset
   364
        self._data = {}
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   365
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   366
    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
   367
        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
   368
        self._data.clear()
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   369
        self._new.clear()
2394
1b3a797c4586 obshashrange: cleanup 'valid' life cycle
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2393
diff changeset
   370
        if reset:
1b3a797c4586 obshashrange: cleanup 'valid' life cycle
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2393
diff changeset
   371
            self._valid = False
1b3a797c4586 obshashrange: cleanup 'valid' life cycle
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2393
diff changeset
   372
        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
   373
            del self._con
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   374
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   375
    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
   376
        # 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
   377
        #
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   378
        # 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
   379
        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
   380
            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
   381
                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
   382
                       % (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
   383
                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
   384
2373
2a1aad0fd8bf obshashrange: stop inheriting from 'dict'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2371
diff changeset
   385
        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
   386
        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
   387
            nrange = (rangeid[0], rangeid[1])
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   388
            obshash = self._con.execute(_queryobshash, nrange).fetchone()
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   389
            if obshash is not None:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   390
                value = obshash[0]
2374
6308a8c04cce obshashrange: keep value fetched from sql in memory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2373
diff changeset
   391
            self._data[rangeid] = value
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   392
        return value
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   393
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   394
    def __setitem__(self, rangeid, obshash):
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   395
        self._new.add(rangeid)
2373
2a1aad0fd8bf obshashrange: stop inheriting from 'dict'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2371
diff changeset
   396
        self._data[rangeid] = obshash
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   397
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   398
    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
   399
        """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
   400
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   401
        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
   402
        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
   403
        """
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   404
        # 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
   405
        # 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
   406
        #
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   407
        # 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
   408
        # 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
   409
2366
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   410
        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
   411
2371
48e879b3f5b6 obshashrange: to not overwrite the list with the set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2370
diff changeset
   412
        setrevs = set(revs)
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
        rev = repo.changelog.nodemap.get
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   414
        # if we have a new markers affecting a node already covered by the
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   415
        # cache, we must abort.
2412
8df32538f662 obshashrangecache: precisely track affected revs when adding new markers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2409
diff changeset
   416
        affected = set()
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   417
        for m in obsmarkers:
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   418
            # check successors and parent
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   419
            for l in (m[1], m[5]):
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   420
                if l 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
   421
                    continue
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   422
                for p in l:
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   423
                    r = rev(p)
2371
48e879b3f5b6 obshashrange: to not overwrite the list with the set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2370
diff changeset
   424
                    if r is not None and r not in setrevs:
2412
8df32538f662 obshashrangecache: precisely track affected revs when adding new markers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2409
diff changeset
   425
                        # XXX should check < min(setrevs) or tiprevs
8df32538f662 obshashrangecache: precisely track affected revs when adding new markers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2409
diff changeset
   426
                        affected.add(r)
8df32538f662 obshashrangecache: precisely track affected revs when adding new markers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2409
diff changeset
   427
8df32538f662 obshashrangecache: precisely track affected revs when adding new markers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2409
diff changeset
   428
        if affected:
8df32538f662 obshashrangecache: precisely track affected revs when adding new markers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2409
diff changeset
   429
            repo.ui.log('evoext-cache', 'obshashcache reset - '
8df32538f662 obshashrangecache: precisely track affected revs when adding new markers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2409
diff changeset
   430
                        'new markers affect cached ranges\n')
2413
22fb71a2d865 obshashrangecache: make sure we re-warm the cache after a reset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2412
diff changeset
   431
            # XXX the current reset is too strong we could just drop the affected range
2412
8df32538f662 obshashrangecache: precisely track affected revs when adding new markers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2409
diff changeset
   432
            con = self._con
8df32538f662 obshashrangecache: precisely track affected revs when adding new markers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2409
diff changeset
   433
            if con is not None:
8df32538f662 obshashrangecache: precisely track affected revs when adding new markers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2409
diff changeset
   434
                con.execute(_reset)
2458
62e4f9ff352b obshashrange: re-warm less revision after reset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
   435
            # rewarm key revisions
62e4f9ff352b obshashrange: re-warm less revision after reset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
   436
            #
62e4f9ff352b obshashrange: re-warm less revision after reset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
   437
            # (The current invalidation is too wide, but rewarming every single
62e4f9ff352b obshashrange: re-warm less revision after reset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
   438
            # revision is quite costly)
62e4f9ff352b obshashrange: re-warm less revision after reset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
   439
            newrevs = []
2413
22fb71a2d865 obshashrangecache: make sure we re-warm the cache after a reset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2412
diff changeset
   440
            stop = self._cachekey[0] # tiprev
2458
62e4f9ff352b obshashrange: re-warm less revision after reset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
   441
            for h in repo.filtered('immutable').changelog.headrevs():
62e4f9ff352b obshashrange: re-warm less revision after reset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
   442
                if h <= stop:
62e4f9ff352b obshashrange: re-warm less revision after reset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
   443
                    newrevs.append(h)
62e4f9ff352b obshashrange: re-warm less revision after reset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
   444
            newrevs.extend(revs)
62e4f9ff352b obshashrange: re-warm less revision after reset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
   445
            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
   446
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   447
        # warm the cache for the new revs
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   448
        for r in revs:
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   449
            _obshashrange(repo, (r, 0))
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   450
2241433a77e5 obshashrange: warm the cache at the end of each transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2365
diff changeset
   451
        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
   452
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   453
    @property
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   454
    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
   455
        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
   456
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   457
    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
   458
        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
   459
            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
   460
            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
   461
        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
   462
2399
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   463
    def _db(self):
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   464
        try:
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   465
            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
   466
        except OSError:
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   467
            return None
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   468
        con = sqlite3.connect(self._path)
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   469
        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
   470
        return con
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   471
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   472
    @util.propertycache
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   473
    def _con(self):
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   474
        if not self._valid:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   475
            return None
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   476
        repo = self._repo()
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   477
        if repo is None:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   478
            return None
2399
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   479
        con = self._db()
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   480
        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
   481
            return None
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   482
        cur = con.execute(_queryexist)
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   483
        if cur.fetchone() is None:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   484
            self._valid = False
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   485
            return None
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   486
        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
   487
        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
   488
            self._valid = False
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   489
            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
   490
        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
   491
        return con
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   492
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   493
    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
   494
        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
   495
            return
5c5f982b98f7 obshashrange: exit early if nothing to write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2360
diff changeset
   496
        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
   497
            return
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   498
        repo = repo.unfiltered()
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   499
        try:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   500
            with repo.lock():
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   501
                self._save(repo)
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   502
        except error.LockError:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   503
            # 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
   504
            # 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
   505
            # widely.
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   506
            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
   507
            repo.ui.warn(msg)
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   508
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   509
    def _save(self, repo):
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   510
        if self._con is None:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   511
            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
   512
            if '_con' in vars(self):
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   513
                del self._con
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   514
2399
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   515
            con = self._db()
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   516
            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
   517
                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
   518
                            ' - cannot create database')
70275407a31e obshashrange: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2394
diff changeset
   519
                return
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   520
            with con:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   521
                for req in _sqliteschema:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   522
                    con.execute(req)
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
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
                con.execute(_newmeta, self._fullcachekey)
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   525
        else:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   526
            con = self._con
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   527
            if self._ondiskcachekey is not None:
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   528
                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
   529
                if meta[1:] != self._ondiskcachekey:
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   530
                    # drifting is currently an issue because this means another
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   531
                    # process might have already added the cache line we are about
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   532
                    # to add. This will confuse sqlite
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   533
                    msg = _('obshashrange cache: skipping write, '
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   534
                            'database drifted under my feet\n')
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   535
                    data = (meta[2], meta[1], self._ondiskcachekey[0], self._ondiskcachekey[1])
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   536
                    repo.ui.warn(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
   537
                    return
2373
2a1aad0fd8bf obshashrange: stop inheriting from 'dict'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2371
diff changeset
   538
        data = ((rangeid[0], rangeid[1], self.get(rangeid)) for rangeid in self._new)
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   539
        con.executemany(_updateobshash, data)
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   540
        cachekey = self._fullcachekey
2391
80d6a2ad7b11 obshashcache: purge the meta line before writing a new one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2390
diff changeset
   541
        con.execute(_clearmeta) # remove the older entry
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   542
        con.execute(_newmeta, cachekey)
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   543
        con.commit()
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   544
        self._new.clear()
2360
89938bebc6f9 obshashrange: use the dualsourcecache as a base for the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2287
diff changeset
   545
        self._ondiskcachekey = self._cachekey
2394
1b3a797c4586 obshashrange: cleanup 'valid' life cycle
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2393
diff changeset
   546
        self._valid = True
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   547
2083
778afb036245 discovery: introduce a official 'obshash associated to a range
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2082
diff changeset
   548
@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
   549
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
   550
    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
   551
    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
   552
2244
c7da63d48f80 compat: work around some filecache bug in 3.8
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2243
diff changeset
   553
try:
c7da63d48f80 compat: work around some filecache bug in 3.8
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2243
diff changeset
   554
    obsstorefilecache = localrepo.localrepository.obsstore
c7da63d48f80 compat: work around some filecache bug in 3.8
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2243
diff changeset
   555
except AttributeError:
c7da63d48f80 compat: work around some filecache bug in 3.8
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2243
diff changeset
   556
    # XXX hg-3.8 compat
c7da63d48f80 compat: work around some filecache bug in 3.8
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2243
diff changeset
   557
    #
c7da63d48f80 compat: work around some filecache bug in 3.8
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2243
diff changeset
   558
    # mercurial 3.8 has issue with accessing file cache property from their
c7da63d48f80 compat: work around some filecache bug in 3.8
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2243
diff changeset
   559
    # cache. This is fix by 36fbd72c2f39fef8ad52d7c559906c2bc388760c in core
c7da63d48f80 compat: work around some filecache bug in 3.8
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2243
diff changeset
   560
    # and shipped in 3.9
c7da63d48f80 compat: work around some filecache bug in 3.8
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2243
diff changeset
   561
    obsstorefilecache = localrepo.localrepository.__dict__['obsstore']
c7da63d48f80 compat: work around some filecache bug in 3.8
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2243
diff changeset
   562
c7da63d48f80 compat: work around some filecache bug in 3.8
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2243
diff changeset
   563
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   564
# 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
   565
@eh.wrapfunction(obsstorefilecache, 'func')
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   566
def obsstorewithcache(orig, repo):
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   567
    obsstore = orig(repo)
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   568
    obsstore.rangeobshashcache = _obshashcache(repo.unfiltered())
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   569
    return obsstore
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   570
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   571
@eh.reposetup
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   572
def setupcache(ui, repo):
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   573
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   574
    class obshashrepo(repo.__class__):
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   575
        @localrepo.unfilteredmethod
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   576
        def destroyed(self):
2363
2ceb122fcc33 obshashrange: properly invalidate the cache on destroyed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2362
diff changeset
   577
            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
   578
                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
   579
            super(obshashrepo, self).destroyed()
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   580
2364
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   581
        def transaction(self, *args, **kwargs):
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   582
            tr = super(obshashrepo, self).transaction(*args, **kwargs)
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   583
            reporef = weakref.ref(self)
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   584
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   585
            def _warmcache(tr):
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   586
                repo = reporef()
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   587
                if repo is None:
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   588
                    return
2551
ecd47c63b6de obshashrange: add an option to protect from accidental activation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2525
diff changeset
   589
                hasobshashrange = _useobshashrange(repo)
2459
5e6fc802bc8a obshashrange: add an option to disable local cache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2458
diff changeset
   590
                hascachewarm = repo.ui.configbool('experimental',
5e6fc802bc8a obshashrange: add an option to disable local cache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2458
diff changeset
   591
                                                  'obshashrange.warm-cache',
5e6fc802bc8a obshashrange: add an option to disable local cache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2458
diff changeset
   592
                                                  True)
5e6fc802bc8a obshashrange: add an option to disable local cache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2458
diff changeset
   593
                if not (hasobshashrange and hascachewarm):
2364
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   594
                    return
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   595
                repo = repo.unfiltered()
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   596
                # As pointed in 'obscache.update', we could have the changelog
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   597
                # and the obsstore in charge of updating the cache when new
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   598
                # items goes it. The tranaction logic would then only be
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   599
                # involved for the 'pending' and final writing on disk.
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   600
                self.obsstore.rangeobshashcache.update(repo)
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   601
                self.obsstore.rangeobshashcache.save(repo)
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   602
2368
b73e1f879646 cache: ensure we warm stablerange cache before the obshashrange cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2366
diff changeset
   603
            tr.addpostclose('warmcache-20-obscacherange', _warmcache)
2364
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   604
            return tr
9b68e65fad4f obshashrange: "update" the cache on each transaction close
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2363
diff changeset
   605
2241
88aace74b190 obshashrange: introduce basic sqlite caching
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2240
diff changeset
   606
    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
   607
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   608
### wire protocol commands
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   609
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   610
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
   611
    """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
   612
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   613
    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
   614
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   615
    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
   616
    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
   617
    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
   618
    if ranges:
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   619
        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
   620
        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
   621
            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
   622
    result = []
2365
4b8b7fd135eb obshashrange: warm cache outside of loops
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2364
diff changeset
   623
    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
   624
    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
   625
        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
   626
            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
   627
        else:
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   628
            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
   629
    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
   630
    return result
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   631
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   632
@eh.addattr(localrepo.localpeer, 'evoext_obshashrange_v0')
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   633
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
   634
    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
   635
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   636
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   637
_indexformat = '>I'
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   638
_indexsize = _calcsize(_indexformat)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   639
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
   640
    """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
   641
    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
   642
    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
   643
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   644
def _decrange(data):
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   645
    """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
   646
    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
   647
    headnode = data[:-_indexsize]
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   648
    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
   649
    return (headnode, index)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   650
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   651
@eh.addattr(wireproto.wirepeer, 'evoext_obshashrange_v0')
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   652
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
   653
    binranges = [_encrange(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
   654
    encranges = wireproto.encodelist(binranges)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   655
    d = self._call("evoext_obshashrange_v0", ranges=encranges)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   656
    try:
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   657
        return wireproto.decodelist(d)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   658
    except ValueError:
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   659
        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
   660
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   661
def srv_obshashrange_v0(repo, proto, ranges):
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   662
    ranges = wireproto.decodelist(ranges)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   663
    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
   664
    hashes = _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
   665
    return wireproto.encodelist(hashes)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   666
2551
ecd47c63b6de obshashrange: add an option to protect from accidental activation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2525
diff changeset
   667
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
   668
    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
   669
    if base:
ecd47c63b6de obshashrange: add an option to protect from accidental activation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2525
diff changeset
   670
        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
   671
        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
   672
            base = False
ecd47c63b6de obshashrange: add an option to protect from accidental activation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2525
diff changeset
   673
    return base
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   674
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   675
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
   676
    return (_useobshashrange(local)
2243
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   677
            and remote.capable('_evoext_obshashrange_v0'))
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   678
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   679
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
   680
    """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
   681
    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
   682
    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
   683
    if obsolete.isenabled(repo, obsolete.exchangeopt) and enabled:
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   684
        caps = caps.split()
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   685
        caps.append('_evoext_obshashrange_v0')
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   686
        caps.sort()
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   687
        caps = ' '.join(caps)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   688
    return caps
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   689
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   690
@eh.extsetup
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   691
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
   692
    hgweb_mod.perms['evoext_obshashrange_v0'] = 'pull'
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
    wireproto.commands['evoext_obshashrange_v0'] = (srv_obshashrange_v0, 'ranges')
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   695
    ###
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   696
    extensions.wrapfunction(wireproto, 'capabilities', _obshashrange_capabilities)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   697
    # wrap command content
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   698
    oldcap, args = wireproto.commands['capabilities']
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   699
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   700
    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
   701
        return _obshashrange_capabilities(oldcap, repo, proto)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   702
    wireproto.commands['capabilities'] = (newcap, args)
d83851f2d375 obshashrange: have an half descent wireprotocol command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2242
diff changeset
   703
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   704
#############################
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   705
### Tree Hash computation ###
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   706
#############################
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   707
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   708
# 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
   709
# 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
   710
# 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
   711
2510
b99b83728ea3 obsdiscovery: extract '_canobshashtree'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2509
diff changeset
   712
def _canobshashtree(repo, remote):
b99b83728ea3 obsdiscovery: extract '_canobshashtree'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2509
diff changeset
   713
    return remote.capable('_evoext_obshash_0')
b99b83728ea3 obsdiscovery: extract '_canobshashtree'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2509
diff changeset
   714
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   715
@eh.command(
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   716
    'debugobsrelsethashtree',
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   717
    [('', '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
   718
     ('', '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
   719
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
   720
    """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
   721
    changeset-node obsrelsethashtree-node
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   722
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   723
    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
   724
    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
   725
    if v0 and v1:
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   726
        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
   727
    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
   728
        treefunc = _obsrelsethashtreefm0
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   729
    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
   730
        treefunc = _obsrelsethashtreefm1
2054
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   731
f9d65d24b9f9 discovery: split discovery related code in 'obsdiscovery'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   732
    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
   733
        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
   734
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   735
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
   736
    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
   737
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   738
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
   739
    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
   740
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   741
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
   742
    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
   743
    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
   744
    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
   745
    repo.ui.progress(_("preparing locally"), 0, total=len(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
   746
    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
   747
        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
   748
        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
   749
        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
   750
        # 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
   751
        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
   752
            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
   753
            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
   754
                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
   755
            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
   756
                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
   757
            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
   758
                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
   759
                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
   760
        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
   761
        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
   762
            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
   763
            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
   764
                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
   765
                    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
   766
                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
   767
            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
   768
            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
   769
                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
   770
                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
   771
        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
   772
            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
   773
        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
   774
            cache.append((ctx.node(), 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
   775
        repo.ui.progress(_("preparing locally"), i, total=len(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
   776
    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
   777
    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
   778
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   779
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
   780
    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
   781
        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
   782
    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
   783
        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
   784
    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
   785
        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
   786
    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
   787
    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
   788
    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
   789
2076
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   790
@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
   791
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
   792
    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
   793
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   794
@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
   795
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
   796
    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
   797
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   798
@eh.addattr(wireproto.wirepeer, 'evoext_obshash')
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   799
def peer_obshash(self, nodes):
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   800
    d = self._call("evoext_obshash", nodes=wireproto.encodelist(nodes))
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   801
    try:
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   802
        return wireproto.decodelist(d)
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   803
    except ValueError:
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   804
        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
   805
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   806
@eh.addattr(wireproto.wirepeer, 'evoext_obshash1')
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   807
def peer_obshash1(self, nodes):
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   808
    d = self._call("evoext_obshash1", nodes=wireproto.encodelist(nodes))
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   809
    try:
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   810
        return wireproto.decodelist(d)
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   811
    except ValueError:
5c6d05c34ba4 obsdiscovery: organize the code by category
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2075
diff changeset
   812
        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
   813
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
   814
def srv_obshash(repo, proto, 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
   815
    return wireproto.encodelist(_obshash(repo, wireproto.decodelist(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
   816
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   817
def srv_obshash1(repo, proto, 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
   818
    return wireproto.encodelist(_obshash(repo, wireproto.decodelist(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
   819
                                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
   820
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   821
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
   822
    """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
   823
    caps = orig(repo, proto)
2075
a7c0685ba6d9 evolution: drop the old __temporary__.advertiseobsolete option
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2061
diff changeset
   824
    if obsolete.isenabled(repo, obsolete.exchangeopt):
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
   825
        caps = caps.split()
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   826
        caps.append('_evoext_obshash_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
   827
        caps.append('_evoext_obshash_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
   828
        caps.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
   829
        caps = ' '.join(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
   830
    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
   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
@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
   833
def obshash_extsetup(ui):
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
    hgweb_mod.perms['evoext_obshash'] = 'pull'
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
    hgweb_mod.perms['evoext_obshash1'] = 'pull'
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
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
    wireproto.commands['evoext_obshash'] = (srv_obshash, '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
   838
    wireproto.commands['evoext_obshash1'] = (srv_obshash1, '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
   839
    extensions.wrapfunction(wireproto, 'capabilities', _obshash_capabilities)
302aa8bbb3af exchange: dispatch all code in 'serveronly' to the appropriate submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2054
diff changeset
   840
    # wrap command content
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
    oldcap, args = wireproto.commands['capabilities']
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
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
    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
   844
        return _obshash_capabilities(oldcap, 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
   845
    wireproto.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
   846
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   847
##########################################
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   848
###  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
   849
##########################################
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   850
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   851
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
   852
    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
   853
            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
   854
            # 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
   855
            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
   856
            # 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
   857
            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
   858
2512
0e6ae8db9c21 obsdiscovery: extract push-obshashrange discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2511
diff changeset
   859
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
   860
    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
   861
    remote = pushop.remote
0e6ae8db9c21 obsdiscovery: extract push-obshashrange discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2511
diff changeset
   862
    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
   863
    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
   864
    return missing
0e6ae8db9c21 obsdiscovery: extract push-obshashrange discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2511
diff changeset
   865
2514
b9f03002f214 obsdiscovery: extract push-obshashtree discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2513
diff changeset
   866
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
   867
    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
   868
    remote = pushop.remote
b9f03002f214 obsdiscovery: extract push-obshashtree discovery in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2513
diff changeset
   869
    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
   870
    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
   871
    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
   872
    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
   873
2515
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   874
# 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
   875
# tuple (canuse, perform discovery))
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   876
obsdiscoveries = [
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   877
    (_canobshashrange, _pushobshashrange),
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   878
    (_canobshashtree, _pushobshashtree),
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   879
]
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   880
2521
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   881
obsdiscovery_skip_message = """\
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   882
(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
   883
(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
   884
"""
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   885
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   886
def usediscovery(repo):
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   887
    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
   888
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
   889
@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
   890
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
   891
    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
   892
        repo = pushop.repo
2515
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   893
        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
   894
        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
   895
        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
   896
        unfi = repo.unfiltered()
2515
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   897
2521
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   898
        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
   899
            # 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
   900
            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
   901
            return orig(pushop)
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   902
2515
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   903
        # 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
   904
        discovery = None
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   905
        for candidate in obsdiscoveries:
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   906
            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
   907
                discovery = candidate[1]
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   908
                break
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   909
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   910
        if discovery is None:
cd8aa99d4f20 obsdiscovery: automatically pick protocol in a list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2514
diff changeset
   911
            # 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
   912
            # 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
   913
            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
   914
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   915
        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
   916
                           % 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
   917
        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
   918
        # 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
   919
        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
   920
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   921
        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
   922
            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
   923
                               % 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
   924
            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
   925
        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
   926
            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
   927
            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
   928
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   929
@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
   930
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
   931
    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
   932
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   933
    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
   934
        _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
   935
    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
   936
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   937
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
   938
    """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
   939
    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
   940
6da129b2b440 obsdiscovery: move code inserting discovery at the end of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2508
diff changeset
   941
    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
   942
    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
   943
    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
   944
    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
   945
    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
   946
    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
   947
    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
   948
        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
   949
        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
   950
2521
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   951
    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
   952
        # 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
   953
        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
   954
        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
   955
        return boundaries
29fc90b0e59c obsdiscovery: add an option to disable all obsdiscovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2515
diff changeset
   956
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
   957
    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
   958
        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
   959
                  % 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
   960
        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
   961
                                                 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
   962
    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
   963
        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
   964
                           % 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
   965
        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
   966
    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
   967
        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
   968
    return boundaries