mercurial/metadata.py
author Augie Fackler <raf@durin42.com>
Mon, 07 Sep 2020 17:13:45 -0400
changeset 45421 0c6b2cc9a7bb
parent 45325 c6eea5804551
child 45506 1f50bcc96595
permissions -rw-r--r--
git: make dirstate status() respect matcher As with other changes in this stack, we appear to have been getting lucky in the past. An upcoming change behaved _very_ oddly without this fix. Differential Revision: https://phab.mercurial-scm.org/D8997
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     1
# metadata.py -- code related to various metadata computation and access.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     2
#
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     3
# Copyright 2019 Google, Inc <martinvonz@google.com>
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     4
# Copyright 2020 Pierre-Yves David <pierre-yves.david@octobus.net>
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     5
#
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     6
# This software may be used and distributed according to the terms of the
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     7
# GNU General Public License version 2 or any later version.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     8
from __future__ import absolute_import, print_function
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     9
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    10
import multiprocessing
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    11
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    12
from . import (
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    13
    error,
44941
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
    14
    node,
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    15
    pycompat,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    16
    util,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    17
)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    18
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    19
from .revlogutils import (
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    20
    flagutil as sidedataflag,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    21
    sidedata as sidedatamod,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    22
)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    23
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    24
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    25
class ChangingFiles(object):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    26
    """A class recording the changes made to a file by a revision
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    27
    """
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    28
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    29
    def __init__(
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    30
        self, touched=(), added=(), removed=(), p1_copies=(), p2_copies=(),
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    31
    ):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    32
        self._added = set(added)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    33
        self._removed = set(removed)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    34
        self._touched = set(touched)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    35
        self._touched.update(self._added)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    36
        self._touched.update(self._removed)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    37
        self._p1_copies = dict(p1_copies)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    38
        self._p2_copies = dict(p2_copies)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    39
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    40
    @property
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    41
    def added(self):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    42
        return frozenset(self._added)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    43
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    44
    def mark_added(self, filename):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    45
        self._added.add(filename)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    46
        self._touched.add(filename)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    47
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    48
    def update_added(self, filenames):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    49
        for f in filenames:
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    50
            self.mark_added(f)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    51
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    52
    @property
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    53
    def removed(self):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    54
        return frozenset(self._removed)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    55
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    56
    def mark_removed(self, filename):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    57
        self._removed.add(filename)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    58
        self._touched.add(filename)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    59
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    60
    def update_removed(self, filenames):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    61
        for f in filenames:
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    62
            self.mark_removed(f)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    63
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    64
    @property
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    65
    def touched(self):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    66
        return frozenset(self._touched)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    67
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    68
    def mark_touched(self, filename):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    69
        self._touched.add(filename)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    70
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    71
    def update_touched(self, filenames):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    72
        for f in filenames:
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    73
            self.mark_touched(f)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    74
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    75
    @property
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    76
    def copied_from_p1(self):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    77
        return self._p1_copies.copy()
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    78
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    79
    def mark_copied_from_p1(self, source, dest):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    80
        self._p1_copies[dest] = source
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    81
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    82
    def update_copies_from_p1(self, copies):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    83
        for dest, source in copies.items():
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    84
            self.mark_copied_from_p1(source, dest)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    85
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    86
    @property
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    87
    def copied_from_p2(self):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    88
        return self._p2_copies.copy()
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    89
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    90
    def mark_copied_from_p2(self, source, dest):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    91
        self._p2_copies[dest] = source
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    92
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    93
    def update_copies_from_p2(self, copies):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    94
        for dest, source in copies.items():
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    95
            self.mark_copied_from_p2(source, dest)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    96
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
    97
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    98
def computechangesetfilesadded(ctx):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    99
    """return the list of files added in a changeset
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   100
    """
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   101
    added = []
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   102
    for f in ctx.files():
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   103
        if not any(f in p for p in ctx.parents()):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   104
            added.append(f)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   105
    return added
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   106
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   107
44941
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   108
def get_removal_filter(ctx, x=None):
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   109
    """return a function to detect files "wrongly" detected as `removed`
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   110
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   111
    When a file is removed relative to p1 in a merge, this
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   112
    function determines whether the absence is due to a
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   113
    deletion from a parent, or whether the merge commit
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   114
    itself deletes the file. We decide this by doing a
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   115
    simplified three way merge of the manifest entry for
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   116
    the file. There are two ways we decide the merge
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   117
    itself didn't delete a file:
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   118
    - neither parent (nor the merge) contain the file
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   119
    - exactly one parent contains the file, and that
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   120
      parent has the same filelog entry as the merge
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   121
      ancestor (or all of them if there two). In other
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   122
      words, that parent left the file unchanged while the
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   123
      other one deleted it.
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   124
    One way to think about this is that deleting a file is
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   125
    similar to emptying it, so the list of changed files
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   126
    should be similar either way. The computation
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   127
    described above is not done directly in _filecommit
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   128
    when creating the list of changed files, however
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   129
    it does something very similar by comparing filelog
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   130
    nodes.
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   131
    """
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   132
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   133
    if x is not None:
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   134
        p1, p2, m1, m2 = x
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   135
    else:
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   136
        p1 = ctx.p1()
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   137
        p2 = ctx.p2()
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   138
        m1 = p1.manifest()
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   139
        m2 = p2.manifest()
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   140
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   141
    @util.cachefunc
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   142
    def mas():
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   143
        p1n = p1.node()
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   144
        p2n = p2.node()
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   145
        cahs = ctx.repo().changelog.commonancestorsheads(p1n, p2n)
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   146
        if not cahs:
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   147
            cahs = [node.nullrev]
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   148
        return [ctx.repo()[r].manifest() for r in cahs]
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   149
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   150
    def deletionfromparent(f):
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   151
        if f in m1:
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   152
            return f not in m2 and all(
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   153
                f in ma and ma.find(f) == m1.find(f) for ma in mas()
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   154
            )
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   155
        elif f in m2:
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   156
            return all(f in ma and ma.find(f) == m2.find(f) for ma in mas())
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   157
        else:
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   158
            return True
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   159
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   160
    return deletionfromparent
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   161
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
   162
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   163
def computechangesetfilesremoved(ctx):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   164
    """return the list of files removed in a changeset
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   165
    """
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   166
    removed = []
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   167
    for f in ctx.files():
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   168
        if f not in ctx:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   169
            removed.append(f)
44942
25512a65cefd metadata: filter the `removed` set to only contains relevant data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44941
diff changeset
   170
    if removed:
25512a65cefd metadata: filter the `removed` set to only contains relevant data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44941
diff changeset
   171
        rf = get_removal_filter(ctx)
25512a65cefd metadata: filter the `removed` set to only contains relevant data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44941
diff changeset
   172
        removed = [r for r in removed if not rf(r)]
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   173
    return removed
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   174
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   175
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   176
def computechangesetcopies(ctx):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   177
    """return the copies data for a changeset
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   178
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   179
    The copies data are returned as a pair of dictionnary (p1copies, p2copies).
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   180
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   181
    Each dictionnary are in the form: `{newname: oldname}`
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   182
    """
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   183
    p1copies = {}
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   184
    p2copies = {}
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   185
    p1 = ctx.p1()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   186
    p2 = ctx.p2()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   187
    narrowmatch = ctx._repo.narrowmatch()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   188
    for dst in ctx.files():
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   189
        if not narrowmatch(dst) or dst not in ctx:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   190
            continue
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   191
        copied = ctx[dst].renamed()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   192
        if not copied:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   193
            continue
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   194
        src, srcnode = copied
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   195
        if src in p1 and p1[src].filenode() == srcnode:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   196
            p1copies[dst] = src
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   197
        elif src in p2 and p2[src].filenode() == srcnode:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   198
            p2copies[dst] = src
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   199
    return p1copies, p2copies
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   200
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   201
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   202
def encodecopies(files, copies):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   203
    items = []
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   204
    for i, dst in enumerate(files):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   205
        if dst in copies:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   206
            items.append(b'%d\0%s' % (i, copies[dst]))
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   207
    if len(items) != len(copies):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   208
        raise error.ProgrammingError(
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   209
            b'some copy targets missing from file list'
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   210
        )
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   211
    return b"\n".join(items)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   212
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   213
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   214
def decodecopies(files, data):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   215
    try:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   216
        copies = {}
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   217
        if not data:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   218
            return copies
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   219
        for l in data.split(b'\n'):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   220
            strindex, src = l.split(b'\0')
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   221
            i = int(strindex)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   222
            dst = files[i]
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   223
            copies[dst] = src
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   224
        return copies
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   225
    except (ValueError, IndexError):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   226
        # Perhaps someone had chosen the same key name (e.g. "p1copies") and
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   227
        # used different syntax for the value.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   228
        return None
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   229
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   230
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   231
def encodefileindices(files, subset):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   232
    subset = set(subset)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   233
    indices = []
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   234
    for i, f in enumerate(files):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   235
        if f in subset:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   236
            indices.append(b'%d' % i)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   237
    return b'\n'.join(indices)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   238
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   239
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   240
def decodefileindices(files, data):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   241
    try:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   242
        subset = []
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   243
        if not data:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   244
            return subset
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   245
        for strindex in data.split(b'\n'):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   246
            i = int(strindex)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   247
            if i < 0 or i >= len(files):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   248
                return None
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   249
            subset.append(files[i])
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   250
        return subset
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   251
    except (ValueError, IndexError):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   252
        # Perhaps someone had chosen the same key name (e.g. "added") and
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   253
        # used different syntax for the value.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   254
        return None
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   255
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   256
45325
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   257
def encode_copies_sidedata(files):
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   258
    sortedfiles = sorted(files.touched)
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   259
    sidedata = {}
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   260
    p1copies = files.copied_from_p1
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   261
    if p1copies:
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   262
        p1copies = encodecopies(sortedfiles, p1copies)
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   263
        sidedata[sidedatamod.SD_P1COPIES] = p1copies
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   264
    p2copies = files.copied_from_p2
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   265
    if p2copies:
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   266
        p2copies = encodecopies(sortedfiles, p2copies)
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   267
        sidedata[sidedatamod.SD_P2COPIES] = p2copies
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   268
    filesadded = files.added
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   269
    if filesadded:
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   270
        filesadded = encodefileindices(sortedfiles, filesadded)
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   271
        sidedata[sidedatamod.SD_FILESADDED] = filesadded
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   272
    filesremoved = files.removed
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   273
    if filesremoved:
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   274
        filesremoved = encodefileindices(sortedfiles, filesremoved)
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   275
        sidedata[sidedatamod.SD_FILESREMOVED] = filesremoved
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   276
    if not sidedata:
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   277
        sidedata = None
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   278
    return sidedata
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   279
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
   280
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   281
def _getsidedata(srcrepo, rev):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   282
    ctx = srcrepo[rev]
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   283
    filescopies = computechangesetcopies(ctx)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   284
    filesadded = computechangesetfilesadded(ctx)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   285
    filesremoved = computechangesetfilesremoved(ctx)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   286
    sidedata = {}
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   287
    if any([filescopies, filesadded, filesremoved]):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   288
        sortedfiles = sorted(ctx.files())
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   289
        p1copies, p2copies = filescopies
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   290
        p1copies = encodecopies(sortedfiles, p1copies)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   291
        p2copies = encodecopies(sortedfiles, p2copies)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   292
        filesadded = encodefileindices(sortedfiles, filesadded)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   293
        filesremoved = encodefileindices(sortedfiles, filesremoved)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   294
        if p1copies:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   295
            sidedata[sidedatamod.SD_P1COPIES] = p1copies
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   296
        if p2copies:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   297
            sidedata[sidedatamod.SD_P2COPIES] = p2copies
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   298
        if filesadded:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   299
            sidedata[sidedatamod.SD_FILESADDED] = filesadded
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   300
        if filesremoved:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   301
            sidedata[sidedatamod.SD_FILESREMOVED] = filesremoved
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   302
    return sidedata
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   303
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   304
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   305
def getsidedataadder(srcrepo, destrepo):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   306
    use_w = srcrepo.ui.configbool(b'experimental', b'worker.repository-upgrade')
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   307
    if pycompat.iswindows or not use_w:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   308
        return _get_simple_sidedata_adder(srcrepo, destrepo)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   309
    else:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   310
        return _get_worker_sidedata_adder(srcrepo, destrepo)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   311
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   312
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   313
def _sidedata_worker(srcrepo, revs_queue, sidedata_queue, tokens):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   314
    """The function used by worker precomputing sidedata
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   315
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   316
    It read an input queue containing revision numbers
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   317
    It write in an output queue containing (rev, <sidedata-map>)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   318
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   319
    The `None` input value is used as a stop signal.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   320
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   321
    The `tokens` semaphore is user to avoid having too many unprocessed
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   322
    entries. The workers needs to acquire one token before fetching a task.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   323
    They will be released by the consumer of the produced data.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   324
    """
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   325
    tokens.acquire()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   326
    rev = revs_queue.get()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   327
    while rev is not None:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   328
        data = _getsidedata(srcrepo, rev)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   329
        sidedata_queue.put((rev, data))
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   330
        tokens.acquire()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   331
        rev = revs_queue.get()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   332
    # processing of `None` is completed, release the token.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   333
    tokens.release()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   334
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   335
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   336
BUFF_PER_WORKER = 50
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   337
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   338
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   339
def _get_worker_sidedata_adder(srcrepo, destrepo):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   340
    """The parallel version of the sidedata computation
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   341
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   342
    This code spawn a pool of worker that precompute a buffer of sidedata
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   343
    before we actually need them"""
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   344
    # avoid circular import copies -> scmutil -> worker -> copies
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   345
    from . import worker
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   346
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   347
    nbworkers = worker._numworkers(srcrepo.ui)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   348
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   349
    tokens = multiprocessing.BoundedSemaphore(nbworkers * BUFF_PER_WORKER)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   350
    revsq = multiprocessing.Queue()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   351
    sidedataq = multiprocessing.Queue()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   352
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   353
    assert srcrepo.filtername is None
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   354
    # queue all tasks beforehand, revision numbers are small and it make
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   355
    # synchronisation simpler
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   356
    #
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   357
    # Since the computation for each node can be quite expensive, the overhead
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   358
    # of using a single queue is not revelant. In practice, most computation
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   359
    # are fast but some are very expensive and dominate all the other smaller
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   360
    # cost.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   361
    for r in srcrepo.changelog.revs():
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   362
        revsq.put(r)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   363
    # queue the "no more tasks" markers
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   364
    for i in range(nbworkers):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   365
        revsq.put(None)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   366
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   367
    allworkers = []
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   368
    for i in range(nbworkers):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   369
        args = (srcrepo, revsq, sidedataq, tokens)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   370
        w = multiprocessing.Process(target=_sidedata_worker, args=args)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   371
        allworkers.append(w)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   372
        w.start()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   373
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   374
    # dictionnary to store results for revision higher than we one we are
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   375
    # looking for. For example, if we need the sidedatamap for 42, and 43 is
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   376
    # received, when shelve 43 for later use.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   377
    staging = {}
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   378
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   379
    def sidedata_companion(revlog, rev):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   380
        sidedata = {}
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   381
        if util.safehasattr(revlog, b'filteredrevs'):  # this is a changelog
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   382
            # Is the data previously shelved ?
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   383
            sidedata = staging.pop(rev, None)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   384
            if sidedata is None:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   385
                # look at the queued result until we find the one we are lookig
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   386
                # for (shelve the other ones)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   387
                r, sidedata = sidedataq.get()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   388
                while r != rev:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   389
                    staging[r] = sidedata
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   390
                    r, sidedata = sidedataq.get()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   391
            tokens.release()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   392
        return False, (), sidedata
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   393
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   394
    return sidedata_companion
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   395
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   396
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   397
def _get_simple_sidedata_adder(srcrepo, destrepo):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   398
    """The simple version of the sidedata computation
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   399
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   400
    It just compute it in the same thread on request"""
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   401
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   402
    def sidedatacompanion(revlog, rev):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   403
        sidedata = {}
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   404
        if util.safehasattr(revlog, 'filteredrevs'):  # this is a changelog
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   405
            sidedata = _getsidedata(srcrepo, rev)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   406
        return False, (), sidedata
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   407
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   408
    return sidedatacompanion
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   409
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   410
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   411
def getsidedataremover(srcrepo, destrepo):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   412
    def sidedatacompanion(revlog, rev):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   413
        f = ()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   414
        if util.safehasattr(revlog, 'filteredrevs'):  # this is a changelog
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   415
            if revlog.flags(rev) & sidedataflag.REVIDX_SIDEDATA:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   416
                f = (
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   417
                    sidedatamod.SD_P1COPIES,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   418
                    sidedatamod.SD_P2COPIES,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   419
                    sidedatamod.SD_FILESADDED,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   420
                    sidedatamod.SD_FILESREMOVED,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   421
                )
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   422
        return False, f, {}
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   423
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   424
    return sidedatacompanion