mercurial/revlogutils/debug.py
author Matt Harbison <matt_harbison@yahoo.com>
Fri, 04 Oct 2024 01:40:35 -0400
changeset 51952 f4c038081561
parent 51864 1c5810ce737e
permissions -rw-r--r--
run-tests: bump the default timeout on Windows to 4x the normal value There are a ridiculous number of tests that timeout on Windows with the 360 sec default (~60). And because of the bug where timed out tests still run to completion before the results are thrown away[1], the timeout does nothing but waste time, so there's no reason to try to find a lower value that still works. For reference on my system: # Ran 909 tests, 116 skipped, 119 failed. python hash seed: 2052473208 real 151m44.322s user 0m0.077s sys 0m0.046s [1] I thought that I wrote a bug for this, but search isn't finding it.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49250
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     1
# revlogutils/debug.py - utility used for revlog debuging
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     2
#
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     3
# Copyright 2005-2007 Olivia Mackall <olivia@selenic.com>
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     4
# Copyright 2022 Octobus <contact@octobus.net>
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     5
#
61cf3d39fd9e debugindex: move the logic into its own 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
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     7
# GNU General Public License version 2 or any later version.
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     8
51864
1c5810ce737e typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51087
diff changeset
     9
from __future__ import annotations
1c5810ce737e typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51087
diff changeset
    10
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
    11
import collections
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
    12
import string
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
    13
49250
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    14
from .. import (
49676
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
    15
    mdiff,
49250
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    16
    node as nodemod,
49676
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
    17
    revlogutils,
49250
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    18
)
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    19
49253
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    20
from . import (
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    21
    constants,
49676
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
    22
    deltas as deltautil,
49253
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    23
)
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    24
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    25
INDEX_ENTRY_DEBUG_COLUMN = []
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    26
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    27
NODE_SIZE = object()
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    28
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    29
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    30
class _column_base:
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    31
    """constains the definition of a revlog column
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    32
49254
69983adfed06 debugindex: introduce a concept of "verbose-only" column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49253
diff changeset
    33
    name:         the column header,
69983adfed06 debugindex: introduce a concept of "verbose-only" column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49253
diff changeset
    34
    value_func:   the function called to get a value,
69983adfed06 debugindex: introduce a concept of "verbose-only" column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49253
diff changeset
    35
    size:         the width of the column,
69983adfed06 debugindex: introduce a concept of "verbose-only" column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49253
diff changeset
    36
    verbose_only: only include the column in verbose mode.
49253
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    37
    """
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    38
49254
69983adfed06 debugindex: introduce a concept of "verbose-only" column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49253
diff changeset
    39
    def __init__(self, name, value_func, size=None, verbose=False):
49253
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    40
        self.name = name
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    41
        self.value_func = value_func
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    42
        if size is not NODE_SIZE:
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    43
            if size is None:
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    44
                size = 8  # arbitrary default
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    45
            size = max(len(name), size)
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    46
        self._size = size
49254
69983adfed06 debugindex: introduce a concept of "verbose-only" column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49253
diff changeset
    47
        self.verbose_only = verbose
49253
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    48
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    49
    def get_size(self, node_size):
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    50
        if self._size is NODE_SIZE:
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    51
            return node_size
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    52
        else:
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    53
            return self._size
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    54
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    55
49254
69983adfed06 debugindex: introduce a concept of "verbose-only" column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49253
diff changeset
    56
def debug_column(name, size=None, verbose=False):
49253
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    57
    """decorated function is registered as a column
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    58
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    59
    name: the name of the column,
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    60
    size: the expected size of the column.
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    61
    """
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    62
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    63
    def register(func):
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    64
        entry = _column_base(
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    65
            name=name,
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    66
            value_func=func,
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    67
            size=size,
49254
69983adfed06 debugindex: introduce a concept of "verbose-only" column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49253
diff changeset
    68
            verbose=verbose,
49253
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    69
        )
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    70
        INDEX_ENTRY_DEBUG_COLUMN.append(entry)
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    71
        return entry
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    72
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    73
    return register
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    74
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    75
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    76
@debug_column(b"rev", size=6)
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    77
def _rev(index, rev, entry, hexfn):
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    78
    return b"%d" % rev
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    79
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    80
49266
da3e37ecacde debugindex: add a `rank` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49265
diff changeset
    81
@debug_column(b"rank", size=6, verbose=True)
da3e37ecacde debugindex: add a `rank` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49265
diff changeset
    82
def rank(index, rev, entry, hexfn):
da3e37ecacde debugindex: add a `rank` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49265
diff changeset
    83
    return b"%d" % entry[constants.ENTRY_RANK]
da3e37ecacde debugindex: add a `rank` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49265
diff changeset
    84
da3e37ecacde debugindex: add a `rank` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49265
diff changeset
    85
49253
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    86
@debug_column(b"linkrev", size=6)
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    87
def _linkrev(index, rev, entry, hexfn):
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    88
    return b"%d" % entry[constants.ENTRY_LINK_REV]
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    89
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    90
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    91
@debug_column(b"nodeid", size=NODE_SIZE)
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    92
def _nodeid(index, rev, entry, hexfn):
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    93
    return hexfn(entry[constants.ENTRY_NODE_ID])
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    94
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
    95
49255
251650844331 debugindex: add a `p1-rev` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49254
diff changeset
    96
@debug_column(b"p1-rev", size=6, verbose=True)
251650844331 debugindex: add a `p1-rev` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49254
diff changeset
    97
def _p1_rev(index, rev, entry, hexfn):
251650844331 debugindex: add a `p1-rev` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49254
diff changeset
    98
    return b"%d" % entry[constants.ENTRY_PARENT_1]
251650844331 debugindex: add a `p1-rev` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49254
diff changeset
    99
251650844331 debugindex: add a `p1-rev` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49254
diff changeset
   100
49253
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   101
@debug_column(b"p1-nodeid", size=NODE_SIZE)
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   102
def _p1_node(index, rev, entry, hexfn):
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   103
    parent = entry[constants.ENTRY_PARENT_1]
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   104
    p_entry = index[parent]
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   105
    return hexfn(p_entry[constants.ENTRY_NODE_ID])
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   106
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   107
49256
d910ca4e995b debugindex: add a `p2-rev` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49255
diff changeset
   108
@debug_column(b"p2-rev", size=6, verbose=True)
d910ca4e995b debugindex: add a `p2-rev` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49255
diff changeset
   109
def _p2_rev(index, rev, entry, hexfn):
d910ca4e995b debugindex: add a `p2-rev` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49255
diff changeset
   110
    return b"%d" % entry[constants.ENTRY_PARENT_2]
d910ca4e995b debugindex: add a `p2-rev` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49255
diff changeset
   111
d910ca4e995b debugindex: add a `p2-rev` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49255
diff changeset
   112
49253
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   113
@debug_column(b"p2-nodeid", size=NODE_SIZE)
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   114
def _p2_node(index, rev, entry, hexfn):
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   115
    parent = entry[constants.ENTRY_PARENT_2]
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   116
    p_entry = index[parent]
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   117
    return hexfn(p_entry[constants.ENTRY_NODE_ID])
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   118
49250
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   119
49257
b0238fc496af debugindex: add a `full-size` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49256
diff changeset
   120
@debug_column(b"full-size", size=20, verbose=True)
b0238fc496af debugindex: add a `full-size` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49256
diff changeset
   121
def full_size(index, rev, entry, hexfn):
b0238fc496af debugindex: add a `full-size` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49256
diff changeset
   122
    return b"%d" % entry[constants.ENTRY_DATA_UNCOMPRESSED_LENGTH]
b0238fc496af debugindex: add a `full-size` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49256
diff changeset
   123
b0238fc496af debugindex: add a `full-size` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49256
diff changeset
   124
49258
f6ef18be36e1 debugindex: add a `delta-base` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49257
diff changeset
   125
@debug_column(b"delta-base", size=6, verbose=True)
f6ef18be36e1 debugindex: add a `delta-base` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49257
diff changeset
   126
def delta_base(index, rev, entry, hexfn):
f6ef18be36e1 debugindex: add a `delta-base` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49257
diff changeset
   127
    return b"%d" % entry[constants.ENTRY_DELTA_BASE]
f6ef18be36e1 debugindex: add a `delta-base` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49257
diff changeset
   128
f6ef18be36e1 debugindex: add a `delta-base` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49257
diff changeset
   129
49259
fbb2477298a6 debugindex: add a `flags` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49258
diff changeset
   130
@debug_column(b"flags", size=2, verbose=True)
fbb2477298a6 debugindex: add a `flags` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49258
diff changeset
   131
def flags(index, rev, entry, hexfn):
fbb2477298a6 debugindex: add a `flags` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49258
diff changeset
   132
    field = entry[constants.ENTRY_DATA_OFFSET]
fbb2477298a6 debugindex: add a `flags` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49258
diff changeset
   133
    field &= 0xFFFF
fbb2477298a6 debugindex: add a `flags` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49258
diff changeset
   134
    return b"%d" % field
fbb2477298a6 debugindex: add a `flags` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49258
diff changeset
   135
fbb2477298a6 debugindex: add a `flags` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49258
diff changeset
   136
49260
7a18f6fc7e0c debugindex: add a `comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49259
diff changeset
   137
@debug_column(b"comp-mode", size=4, verbose=True)
7a18f6fc7e0c debugindex: add a `comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49259
diff changeset
   138
def compression_mode(index, rev, entry, hexfn):
7a18f6fc7e0c debugindex: add a `comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49259
diff changeset
   139
    return b"%d" % entry[constants.ENTRY_DATA_COMPRESSION_MODE]
7a18f6fc7e0c debugindex: add a `comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49259
diff changeset
   140
7a18f6fc7e0c debugindex: add a `comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49259
diff changeset
   141
49261
7ba8adced391 debugindex: add a `data-offset` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49260
diff changeset
   142
@debug_column(b"data-offset", size=20, verbose=True)
7ba8adced391 debugindex: add a `data-offset` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49260
diff changeset
   143
def data_offset(index, rev, entry, hexfn):
7ba8adced391 debugindex: add a `data-offset` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49260
diff changeset
   144
    field = entry[constants.ENTRY_DATA_OFFSET]
7ba8adced391 debugindex: add a `data-offset` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49260
diff changeset
   145
    field >>= 16
7ba8adced391 debugindex: add a `data-offset` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49260
diff changeset
   146
    return b"%d" % field
7ba8adced391 debugindex: add a `data-offset` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49260
diff changeset
   147
7ba8adced391 debugindex: add a `data-offset` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49260
diff changeset
   148
49262
4c145006b24a debugindex: add a `chunk-size` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49261
diff changeset
   149
@debug_column(b"chunk-size", size=10, verbose=True)
4c145006b24a debugindex: add a `chunk-size` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49261
diff changeset
   150
def data_chunk_size(index, rev, entry, hexfn):
4c145006b24a debugindex: add a `chunk-size` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49261
diff changeset
   151
    return b"%d" % entry[constants.ENTRY_DATA_COMPRESSED_LENGTH]
4c145006b24a debugindex: add a `chunk-size` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49261
diff changeset
   152
4c145006b24a debugindex: add a `chunk-size` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49261
diff changeset
   153
49263
27583efef74d debugindex: add a `sd-comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49262
diff changeset
   154
@debug_column(b"sd-comp-mode", size=7, verbose=True)
27583efef74d debugindex: add a `sd-comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49262
diff changeset
   155
def sidedata_compression_mode(index, rev, entry, hexfn):
27583efef74d debugindex: add a `sd-comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49262
diff changeset
   156
    compression = entry[constants.ENTRY_SIDEDATA_COMPRESSION_MODE]
27583efef74d debugindex: add a `sd-comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49262
diff changeset
   157
    if compression == constants.COMP_MODE_PLAIN:
27583efef74d debugindex: add a `sd-comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49262
diff changeset
   158
        return b"plain"
27583efef74d debugindex: add a `sd-comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49262
diff changeset
   159
    elif compression == constants.COMP_MODE_DEFAULT:
27583efef74d debugindex: add a `sd-comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49262
diff changeset
   160
        return b"default"
27583efef74d debugindex: add a `sd-comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49262
diff changeset
   161
    elif compression == constants.COMP_MODE_INLINE:
27583efef74d debugindex: add a `sd-comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49262
diff changeset
   162
        return b"inline"
27583efef74d debugindex: add a `sd-comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49262
diff changeset
   163
    else:
27583efef74d debugindex: add a `sd-comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49262
diff changeset
   164
        return b"%d" % compression
27583efef74d debugindex: add a `sd-comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49262
diff changeset
   165
27583efef74d debugindex: add a `sd-comp-mode` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49262
diff changeset
   166
49264
e3a267a93711 debugindex: add a `sidedata-offset` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49263
diff changeset
   167
@debug_column(b"sidedata-offset", size=20, verbose=True)
e3a267a93711 debugindex: add a `sidedata-offset` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49263
diff changeset
   168
def sidedata_offset(index, rev, entry, hexfn):
e3a267a93711 debugindex: add a `sidedata-offset` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49263
diff changeset
   169
    return b"%d" % entry[constants.ENTRY_SIDEDATA_OFFSET]
e3a267a93711 debugindex: add a `sidedata-offset` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49263
diff changeset
   170
e3a267a93711 debugindex: add a `sidedata-offset` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49263
diff changeset
   171
49265
30d2beab8163 debugindex: add a `sd-chunk-size` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49264
diff changeset
   172
@debug_column(b"sd-chunk-size", size=10, verbose=True)
30d2beab8163 debugindex: add a `sd-chunk-size` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49264
diff changeset
   173
def sidedata_chunk_size(index, rev, entry, hexfn):
30d2beab8163 debugindex: add a `sd-chunk-size` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49264
diff changeset
   174
    return b"%d" % entry[constants.ENTRY_SIDEDATA_COMPRESSED_LENGTH]
30d2beab8163 debugindex: add a `sd-chunk-size` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49264
diff changeset
   175
30d2beab8163 debugindex: add a `sd-chunk-size` column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49264
diff changeset
   176
49250
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   177
def debug_index(
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   178
    ui,
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   179
    repo,
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   180
    formatter,
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   181
    revlog,
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   182
    full_node,
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   183
):
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   184
    """display index data for a revlog"""
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   185
    if full_node:
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   186
        hexfn = nodemod.hex
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   187
    else:
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   188
        hexfn = nodemod.short
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   189
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   190
    idlen = 12
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   191
    for i in revlog:
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   192
        idlen = len(hexfn(revlog.node(i)))
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   193
        break
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   194
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   195
    fm = formatter
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   196
49253
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   197
    header_pieces = []
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   198
    for column in INDEX_ENTRY_DEBUG_COLUMN:
49254
69983adfed06 debugindex: introduce a concept of "verbose-only" column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49253
diff changeset
   199
        if column.verbose_only and not ui.verbose:
69983adfed06 debugindex: introduce a concept of "verbose-only" column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49253
diff changeset
   200
            continue
49253
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   201
        size = column.get_size(idlen)
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   202
        name = column.name
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   203
        header_pieces.append(name.rjust(size))
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   204
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   205
    fm.plain(b' '.join(header_pieces) + b'\n')
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   206
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   207
    index = revlog.index
49250
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   208
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   209
    for rev in revlog:
49253
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   210
        fm.startitem()
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   211
        entry = index[rev]
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   212
        first = True
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   213
        for column in INDEX_ENTRY_DEBUG_COLUMN:
49254
69983adfed06 debugindex: introduce a concept of "verbose-only" column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49253
diff changeset
   214
            if column.verbose_only and not ui.verbose:
69983adfed06 debugindex: introduce a concept of "verbose-only" column
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49253
diff changeset
   215
                continue
49253
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   216
            if not first:
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   217
                fm.plain(b' ')
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   218
            first = False
49250
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   219
49253
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   220
            size = column.get_size(idlen)
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   221
            value = column.value_func(index, rev, entry, hexfn)
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   222
            display = b"%%%ds" % size
a321304269cf debugindex: move to a flexible column
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49252
diff changeset
   223
            fm.write(column.name, display, value)
49250
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   224
        fm.plain(b'\n')
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   225
61cf3d39fd9e debugindex: move the logic into its own module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   226
    fm.end()
49659
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   227
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   228
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   229
def dump(ui, revlog):
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   230
    """perform the work for `hg debugrevlog --dump"""
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   231
    # XXX seems redundant with debug index ?
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   232
    r = revlog
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   233
    numrevs = len(r)
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   234
    ui.write(
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   235
        (
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   236
            b"# rev p1rev p2rev start   end deltastart base   p1   p2"
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   237
            b" rawsize totalsize compression heads chainlen\n"
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   238
        )
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   239
    )
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   240
    ts = 0
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   241
    heads = set()
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   242
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   243
    for rev in range(numrevs):
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   244
        dbase = r.deltaparent(rev)
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   245
        if dbase == -1:
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   246
            dbase = rev
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   247
        cbase = r.chainbase(rev)
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   248
        clen = r.chainlen(rev)
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   249
        p1, p2 = r.parentrevs(rev)
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   250
        rs = r.rawsize(rev)
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   251
        ts = ts + rs
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   252
        heads -= set(r.parentrevs(rev))
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   253
        heads.add(rev)
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   254
        try:
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   255
            compression = ts / r.end(rev)
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   256
        except ZeroDivisionError:
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   257
            compression = 0
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   258
        ui.write(
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   259
            b"%5d %5d %5d %5d %5d %10d %4d %4d %4d %7d %9d "
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   260
            b"%11d %5d %8d\n"
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   261
            % (
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   262
                rev,
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   263
                p1,
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   264
                p2,
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   265
                r.start(rev),
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   266
                r.end(rev),
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   267
                r.start(dbase),
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   268
                r.start(cbase),
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   269
                r.start(p1),
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   270
                r.start(p2),
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   271
                rs,
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   272
                ts,
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   273
                compression,
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   274
                len(heads),
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   275
                clen,
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   276
            )
7c0a383849a8 debug-revlog: move the --dump code in `revlogutils` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49266
diff changeset
   277
        )
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   278
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   279
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   280
def debug_revlog(ui, revlog):
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   281
    """code for `hg debugrevlog`"""
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   282
    r = revlog
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   283
    format = r._format_version
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   284
    v = r._format_flags
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   285
    flags = []
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   286
    gdelta = False
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   287
    if v & constants.FLAG_INLINE_DATA:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   288
        flags.append(b'inline')
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   289
    if v & constants.FLAG_GENERALDELTA:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   290
        gdelta = True
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   291
        flags.append(b'generaldelta')
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   292
    if not flags:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   293
        flags = [b'(none)']
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   294
49662
7aea9babac5d debugrevlog: display total stored information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49661
diff changeset
   295
    ### the total size of stored content if incompressed.
7aea9babac5d debugrevlog: display total stored information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49661
diff changeset
   296
    full_text_total_size = 0
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   297
    ### tracks merge vs single parent
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   298
    nummerges = 0
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   299
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   300
    ### tracks ways the "delta" are build
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   301
    # nodelta
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   302
    numempty = 0
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   303
    numemptytext = 0
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   304
    numemptydelta = 0
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   305
    # full file content
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   306
    numfull = 0
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   307
    # intermediate snapshot against a prior snapshot
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   308
    numsemi = 0
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   309
    # snapshot count per depth
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   310
    numsnapdepth = collections.defaultdict(lambda: 0)
49661
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   311
    # number of snapshots with a non-ancestor delta
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   312
    numsnapdepth_nad = collections.defaultdict(lambda: 0)
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   313
    # delta against previous revision
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   314
    numprev = 0
49661
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   315
    # delta against prev, where prev is a non-ancestor
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   316
    numprev_nad = 0
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   317
    # delta against first or second parent (not prev)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   318
    nump1 = 0
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   319
    nump2 = 0
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   320
    # delta against neither prev nor parents
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   321
    numother = 0
49661
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   322
    # delta against other that is a non-ancestor
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   323
    numother_nad = 0
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   324
    # delta against prev that are also first or second parent
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   325
    # (details of `numprev`)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   326
    nump1prev = 0
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   327
    nump2prev = 0
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   328
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   329
    # data about delta chain of each revs
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   330
    chainlengths = []
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   331
    chainbases = []
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   332
    chainspans = []
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   333
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   334
    # data about each revision
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   335
    datasize = [None, 0, 0]
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   336
    fullsize = [None, 0, 0]
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   337
    semisize = [None, 0, 0]
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   338
    # snapshot count per depth
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   339
    snapsizedepth = collections.defaultdict(lambda: [None, 0, 0])
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   340
    deltasize = [None, 0, 0]
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   341
    chunktypecounts = {}
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   342
    chunktypesizes = {}
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   343
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   344
    def addsize(size, l):
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   345
        if l[0] is None or size < l[0]:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   346
            l[0] = size
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   347
        if size > l[1]:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   348
            l[1] = size
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   349
        l[2] += size
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   350
51017
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   351
    with r.reading():
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   352
        numrevs = len(r)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   353
        for rev in range(numrevs):
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   354
            p1, p2 = r.parentrevs(rev)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   355
            delta = r.deltaparent(rev)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   356
            if format > 0:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   357
                s = r.rawsize(rev)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   358
                full_text_total_size += s
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   359
                addsize(s, datasize)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   360
            if p2 != nodemod.nullrev:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   361
                nummerges += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   362
            size = r.length(rev)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   363
            if delta == nodemod.nullrev:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   364
                chainlengths.append(0)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   365
                chainbases.append(r.start(rev))
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   366
                chainspans.append(size)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   367
                if size == 0:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   368
                    numempty += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   369
                    numemptytext += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   370
                else:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   371
                    numfull += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   372
                    numsnapdepth[0] += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   373
                    addsize(size, fullsize)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   374
                    addsize(size, snapsizedepth[0])
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   375
            else:
51017
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   376
                nad = (
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   377
                    delta != p1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   378
                    and delta != p2
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   379
                    and not r.isancestorrev(delta, rev)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   380
                )
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   381
                chainlengths.append(chainlengths[delta] + 1)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   382
                baseaddr = chainbases[delta]
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   383
                revaddr = r.start(rev)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   384
                chainbases.append(baseaddr)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   385
                chainspans.append((revaddr - baseaddr) + size)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   386
                if size == 0:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   387
                    numempty += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   388
                    numemptydelta += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   389
                elif r.issnapshot(rev):
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   390
                    addsize(size, semisize)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   391
                    numsemi += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   392
                    depth = r.snapshotdepth(rev)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   393
                    numsnapdepth[depth] += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   394
                    if nad:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   395
                        numsnapdepth_nad[depth] += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   396
                    addsize(size, snapsizedepth[depth])
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   397
                else:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   398
                    addsize(size, deltasize)
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   399
                    if delta == rev - 1:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   400
                        numprev += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   401
                        if delta == p1:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   402
                            nump1prev += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   403
                        elif delta == p2:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   404
                            nump2prev += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   405
                        elif nad:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   406
                            numprev_nad += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   407
                    elif delta == p1:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   408
                        nump1 += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   409
                    elif delta == p2:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   410
                        nump2 += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   411
                    elif delta != nodemod.nullrev:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   412
                        numother += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   413
                        numother_nad += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   414
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   415
            # Obtain data on the raw chunks in the revlog.
51087
df50a1592e0c revlog: move _getsegmentforrevs on the internal object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51074
diff changeset
   416
            if hasattr(r, '_inner'):
df50a1592e0c revlog: move _getsegmentforrevs on the internal object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51074
diff changeset
   417
                segment = r._inner.get_segment_for_revs(rev, rev)[1]
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   418
            else:
51017
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   419
                segment = r._revlog._getsegmentforrevs(rev, rev)[1]
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   420
            if segment:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   421
                chunktype = bytes(segment[0:1])
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   422
            else:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   423
                chunktype = b'empty'
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   424
51017
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   425
            if chunktype not in chunktypecounts:
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   426
                chunktypecounts[chunktype] = 0
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   427
                chunktypesizes[chunktype] = 0
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   428
51017
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   429
            chunktypecounts[chunktype] += 1
edc44ab7437a debug-revlog: keep the revlog open for the analysis duration
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
   430
            chunktypesizes[chunktype] += size
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   431
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   432
    # Adjust size min value for empty cases
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   433
    for size in (datasize, fullsize, semisize, deltasize):
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   434
        if size[0] is None:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   435
            size[0] = 0
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   436
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   437
    numdeltas = numrevs - numfull - numempty - numsemi
49661
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   438
    numoprev = numprev - nump1prev - nump2prev - numprev_nad
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   439
    num_other_ancestors = numother - numother_nad
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   440
    totalrawsize = datasize[2]
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   441
    datasize[2] /= numrevs
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   442
    fulltotal = fullsize[2]
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   443
    if numfull == 0:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   444
        fullsize[2] = 0
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   445
    else:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   446
        fullsize[2] /= numfull
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   447
    semitotal = semisize[2]
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   448
    snaptotal = {}
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   449
    if numsemi > 0:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   450
        semisize[2] /= numsemi
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   451
    for depth in snapsizedepth:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   452
        snaptotal[depth] = snapsizedepth[depth][2]
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   453
        snapsizedepth[depth][2] /= numsnapdepth[depth]
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   454
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   455
    deltatotal = deltasize[2]
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   456
    if numdeltas > 0:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   457
        deltasize[2] /= numdeltas
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   458
    totalsize = fulltotal + semitotal + deltatotal
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   459
    avgchainlen = sum(chainlengths) / numrevs
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   460
    maxchainlen = max(chainlengths)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   461
    maxchainspan = max(chainspans)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   462
    compratio = 1
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   463
    if totalsize:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   464
        compratio = totalrawsize / totalsize
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   465
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   466
    basedfmtstr = b'%%%dd\n'
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   467
    basepcfmtstr = b'%%%dd %s(%%5.2f%%%%)\n'
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   468
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   469
    def dfmtstr(max):
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   470
        return basedfmtstr % len(str(max))
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   471
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   472
    def pcfmtstr(max, padding=0):
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   473
        return basepcfmtstr % (len(str(max)), b' ' * padding)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   474
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   475
    def pcfmt(value, total):
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   476
        if total:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   477
            return (value, 100 * float(value) / total)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   478
        else:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   479
            return value, 100.0
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   480
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   481
    ui.writenoi18n(b'format : %d\n' % format)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   482
    ui.writenoi18n(b'flags  : %s\n' % b', '.join(flags))
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   483
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   484
    ui.write(b'\n')
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   485
    fmt = pcfmtstr(totalsize)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   486
    fmt2 = dfmtstr(totalsize)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   487
    ui.writenoi18n(b'revisions     : ' + fmt2 % numrevs)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   488
    ui.writenoi18n(b'    merges    : ' + fmt % pcfmt(nummerges, numrevs))
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   489
    ui.writenoi18n(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   490
        b'    normal    : ' + fmt % pcfmt(numrevs - nummerges, numrevs)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   491
    )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   492
    ui.writenoi18n(b'revisions     : ' + fmt2 % numrevs)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   493
    ui.writenoi18n(b'    empty     : ' + fmt % pcfmt(numempty, numrevs))
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   494
    ui.writenoi18n(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   495
        b'                   text  : '
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   496
        + fmt % pcfmt(numemptytext, numemptytext + numemptydelta)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   497
    )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   498
    ui.writenoi18n(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   499
        b'                   delta : '
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   500
        + fmt % pcfmt(numemptydelta, numemptytext + numemptydelta)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   501
    )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   502
    ui.writenoi18n(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   503
        b'    snapshot  : ' + fmt % pcfmt(numfull + numsemi, numrevs)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   504
    )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   505
    for depth in sorted(numsnapdepth):
49661
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   506
        base = b'      lvl-%-3d :       ' % depth
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   507
        count = fmt % pcfmt(numsnapdepth[depth], numrevs)
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   508
        pieces = [base, count]
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   509
        if numsnapdepth_nad[depth]:
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   510
            pieces[-1] = count = count[:-1]  # drop the final '\n'
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   511
            more = b'  non-ancestor-bases: '
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   512
            anc_count = fmt
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   513
            anc_count %= pcfmt(numsnapdepth_nad[depth], numsnapdepth[depth])
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   514
            pieces.append(more)
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   515
            pieces.append(anc_count)
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   516
        ui.write(b''.join(pieces))
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   517
    ui.writenoi18n(b'    deltas    : ' + fmt % pcfmt(numdeltas, numrevs))
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   518
    ui.writenoi18n(b'revision size : ' + fmt2 % totalsize)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   519
    ui.writenoi18n(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   520
        b'    snapshot  : ' + fmt % pcfmt(fulltotal + semitotal, totalsize)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   521
    )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   522
    for depth in sorted(numsnapdepth):
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   523
        ui.write(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   524
            (b'      lvl-%-3d :       ' % depth)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   525
            + fmt % pcfmt(snaptotal[depth], totalsize)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   526
        )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   527
    ui.writenoi18n(b'    deltas    : ' + fmt % pcfmt(deltatotal, totalsize))
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   528
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   529
    letters = string.ascii_letters.encode('ascii')
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   530
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   531
    def fmtchunktype(chunktype):
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   532
        if chunktype == b'empty':
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   533
            return b'    %s     : ' % chunktype
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   534
        elif chunktype in letters:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   535
            return b'    0x%s (%s)  : ' % (nodemod.hex(chunktype), chunktype)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   536
        else:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   537
            return b'    0x%s      : ' % nodemod.hex(chunktype)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   538
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   539
    ui.write(b'\n')
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   540
    ui.writenoi18n(b'chunks        : ' + fmt2 % numrevs)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   541
    for chunktype in sorted(chunktypecounts):
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   542
        ui.write(fmtchunktype(chunktype))
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   543
        ui.write(fmt % pcfmt(chunktypecounts[chunktype], numrevs))
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   544
    ui.writenoi18n(b'chunks size   : ' + fmt2 % totalsize)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   545
    for chunktype in sorted(chunktypecounts):
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   546
        ui.write(fmtchunktype(chunktype))
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   547
        ui.write(fmt % pcfmt(chunktypesizes[chunktype], totalsize))
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   548
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   549
    ui.write(b'\n')
49662
7aea9babac5d debugrevlog: display total stored information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49661
diff changeset
   550
    b_total = b"%d" % full_text_total_size
7aea9babac5d debugrevlog: display total stored information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49661
diff changeset
   551
    p_total = []
7aea9babac5d debugrevlog: display total stored information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49661
diff changeset
   552
    while len(b_total) > 3:
7aea9babac5d debugrevlog: display total stored information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49661
diff changeset
   553
        p_total.append(b_total[-3:])
7aea9babac5d debugrevlog: display total stored information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49661
diff changeset
   554
        b_total = b_total[:-3]
7aea9babac5d debugrevlog: display total stored information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49661
diff changeset
   555
    p_total.append(b_total)
7aea9babac5d debugrevlog: display total stored information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49661
diff changeset
   556
    p_total.reverse()
7aea9babac5d debugrevlog: display total stored information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49661
diff changeset
   557
    b_total = b' '.join(p_total)
7aea9babac5d debugrevlog: display total stored information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49661
diff changeset
   558
7aea9babac5d debugrevlog: display total stored information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49661
diff changeset
   559
    ui.write(b'\n')
7aea9babac5d debugrevlog: display total stored information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49661
diff changeset
   560
    ui.writenoi18n(b'total-stored-content: %s bytes\n' % b_total)
7aea9babac5d debugrevlog: display total stored information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49661
diff changeset
   561
    ui.write(b'\n')
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   562
    fmt = dfmtstr(max(avgchainlen, maxchainlen, maxchainspan, compratio))
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   563
    ui.writenoi18n(b'avg chain length  : ' + fmt % avgchainlen)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   564
    ui.writenoi18n(b'max chain length  : ' + fmt % maxchainlen)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   565
    ui.writenoi18n(b'max chain reach   : ' + fmt % maxchainspan)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   566
    ui.writenoi18n(b'compression ratio : ' + fmt % compratio)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   567
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   568
    if format > 0:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   569
        ui.write(b'\n')
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   570
        ui.writenoi18n(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   571
            b'uncompressed data size (min/max/avg) : %d / %d / %d\n'
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   572
            % tuple(datasize)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   573
        )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   574
    ui.writenoi18n(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   575
        b'full revision size (min/max/avg)     : %d / %d / %d\n'
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   576
        % tuple(fullsize)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   577
    )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   578
    ui.writenoi18n(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   579
        b'inter-snapshot size (min/max/avg)    : %d / %d / %d\n'
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   580
        % tuple(semisize)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   581
    )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   582
    for depth in sorted(snapsizedepth):
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   583
        if depth == 0:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   584
            continue
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   585
        ui.writenoi18n(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   586
            b'    level-%-3d (min/max/avg)          : %d / %d / %d\n'
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   587
            % ((depth,) + tuple(snapsizedepth[depth]))
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   588
        )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   589
    ui.writenoi18n(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   590
        b'delta size (min/max/avg)             : %d / %d / %d\n'
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   591
        % tuple(deltasize)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   592
    )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   593
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   594
    if numdeltas > 0:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   595
        ui.write(b'\n')
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   596
        fmt = pcfmtstr(numdeltas)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   597
        fmt2 = pcfmtstr(numdeltas, 4)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   598
        ui.writenoi18n(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   599
            b'deltas against prev  : ' + fmt % pcfmt(numprev, numdeltas)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   600
        )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   601
        if numprev > 0:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   602
            ui.writenoi18n(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   603
                b'    where prev = p1  : ' + fmt2 % pcfmt(nump1prev, numprev)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   604
            )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   605
            ui.writenoi18n(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   606
                b'    where prev = p2  : ' + fmt2 % pcfmt(nump2prev, numprev)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   607
            )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   608
            ui.writenoi18n(
49661
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   609
                b'    other-ancestor   : ' + fmt2 % pcfmt(numoprev, numprev)
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   610
            )
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   611
            ui.writenoi18n(
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   612
                b'    unrelated        : ' + fmt2 % pcfmt(numoprev, numprev)
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   613
            )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   614
        if gdelta:
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   615
            ui.writenoi18n(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   616
                b'deltas against p1    : ' + fmt % pcfmt(nump1, numdeltas)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   617
            )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   618
            ui.writenoi18n(
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   619
                b'deltas against p2    : ' + fmt % pcfmt(nump2, numdeltas)
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   620
            )
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   621
            ui.writenoi18n(
49661
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   622
                b'deltas against ancs  : '
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   623
                + fmt % pcfmt(num_other_ancestors, numdeltas)
49660
bd3b6f363fb9 debug-revlog: move the code in revlogutils module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49659
diff changeset
   624
            )
49661
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   625
            ui.writenoi18n(
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   626
                b'deltas against other : '
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   627
                + fmt % pcfmt(numother_nad, numdeltas)
511106bcb16c debug-revlog: details about non-ancestors delta-bases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49660
diff changeset
   628
            )
49676
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   629
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   630
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   631
def debug_delta_find(ui, revlog, rev, base_rev=nodemod.nullrev):
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   632
    """display the search process for a delta"""
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   633
    deltacomputer = deltautil.deltacomputer(
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   634
        revlog,
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   635
        write_debug=ui.write,
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   636
        debug_search=not ui.quiet,
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   637
    )
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   638
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   639
    node = revlog.node(rev)
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   640
    p1r, p2r = revlog.parentrevs(rev)
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   641
    p1 = revlog.node(p1r)
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   642
    p2 = revlog.node(p2r)
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   643
    full_text = revlog.revision(rev)
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   644
    btext = [full_text]
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   645
    textlen = len(btext[0])
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   646
    cachedelta = None
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   647
    flags = revlog.flags(rev)
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   648
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   649
    if base_rev != nodemod.nullrev:
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   650
        base_text = revlog.revision(base_rev)
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   651
        delta = mdiff.textdiff(base_text, full_text)
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   652
49677
05db41701ece find-delta: pass the cache-delta usage policy alongside the cache-delta
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49676
diff changeset
   653
        cachedelta = (base_rev, delta, constants.DELTA_BASE_REUSE_TRY)
49676
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   654
        btext = [None]
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   655
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   656
    revinfo = revlogutils.revisioninfo(
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   657
        node,
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   658
        p1,
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   659
        p2,
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   660
        btext,
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   661
        textlen,
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   662
        cachedelta,
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   663
        flags,
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   664
    )
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   665
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   666
    fh = revlog._datafp()
4302db0f54c8 find-delta: move most of the debug-find-delta code in the debug module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49662
diff changeset
   667
    deltacomputer.finddeltainfo(revinfo, fh, target_rev=rev)
49819
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   668
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   669
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   670
def debug_revlog_stats(
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   671
    repo, fm, changelog: bool, manifest: bool, filelogs: bool
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   672
):
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   673
    """Format revlog statistics for debugging purposes
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   674
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   675
    fm: the output formatter.
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   676
    """
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   677
    fm.plain(b'rev-count   data-size inl type      target \n')
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   678
50681
47b44d80d836 debug-revlog-stats: make it use the new store entry API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49819
diff changeset
   679
    revlog_entries = [e for e in repo.store.walk() if e.is_revlog]
47b44d80d836 debug-revlog-stats: make it use the new store entry API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49819
diff changeset
   680
    revlog_entries.sort(key=lambda e: (e.revlog_type, e.target_id))
47b44d80d836 debug-revlog-stats: make it use the new store entry API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49819
diff changeset
   681
47b44d80d836 debug-revlog-stats: make it use the new store entry API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49819
diff changeset
   682
    for entry in revlog_entries:
47b44d80d836 debug-revlog-stats: make it use the new store entry API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49819
diff changeset
   683
        if not changelog and entry.is_changelog:
47b44d80d836 debug-revlog-stats: make it use the new store entry API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49819
diff changeset
   684
            continue
47b44d80d836 debug-revlog-stats: make it use the new store entry API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49819
diff changeset
   685
        elif not manifest and entry.is_manifestlog:
47b44d80d836 debug-revlog-stats: make it use the new store entry API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49819
diff changeset
   686
            continue
47b44d80d836 debug-revlog-stats: make it use the new store entry API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49819
diff changeset
   687
        elif not filelogs and entry.is_filelog:
47b44d80d836 debug-revlog-stats: make it use the new store entry API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49819
diff changeset
   688
            continue
47b44d80d836 debug-revlog-stats: make it use the new store entry API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49819
diff changeset
   689
        rlog = entry.get_revlog_instance(repo).get_revlog()
49819
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   690
        fm.startitem()
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   691
        nb_rev = len(rlog)
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   692
        inline = rlog._inline
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   693
        data_size = rlog._get_data_offset(nb_rev - 1)
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   694
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   695
        target = rlog.target
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   696
        revlog_type = b'unknown'
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   697
        revlog_target = b''
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   698
        if target[0] == constants.KIND_CHANGELOG:
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   699
            revlog_type = b'changelog'
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   700
        elif target[0] == constants.KIND_MANIFESTLOG:
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   701
            revlog_type = b'manifest'
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   702
            revlog_target = target[1]
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   703
        elif target[0] == constants.KIND_FILELOG:
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   704
            revlog_type = b'file'
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   705
            revlog_target = target[1]
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   706
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   707
        fm.write(b'revlog.rev-count', b'%9d', nb_rev)
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   708
        fm.write(b'revlog.data-size', b'%12d', data_size)
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   709
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   710
        fm.write(b'revlog.inline', b' %-3s', b'yes' if inline else b'no')
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   711
        fm.write(b'revlog.type', b' %-9s', revlog_type)
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   712
        fm.write(b'revlog.target', b' %s', revlog_target)
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   713
b1e4c74beb6f debug: add debug-revlog-stats command
Franck Bret <franck.bret@octobus.net>
parents: 49677
diff changeset
   714
        fm.plain(b'\n')
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   715
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   716
51071
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   717
class DeltaChainAuditor:
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   718
    def __init__(self, revlog):
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   719
        self._revlog = revlog
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   720
        self._index = self._revlog.index
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   721
        self._generaldelta = revlog.delta_config.general_delta
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   722
        self._chain_size_cache = {}
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   723
        # security to avoid crash on corrupted revlogs
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   724
        self._total_revs = len(self._index)
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   725
51074
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   726
    def revinfo(self, rev, size_info=True, dist_info=True, sparse_info=True):
51071
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   727
        e = self._index[rev]
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   728
        compsize = e[constants.ENTRY_DATA_COMPRESSED_LENGTH]
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   729
        uncompsize = e[constants.ENTRY_DATA_UNCOMPRESSED_LENGTH]
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   730
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   731
        base = e[constants.ENTRY_DELTA_BASE]
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   732
        p1 = e[constants.ENTRY_PARENT_1]
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   733
        p2 = e[constants.ENTRY_PARENT_2]
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   734
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   735
        # If the parents of a revision has an empty delta, we never try to
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   736
        # delta against that parent, but directly against the delta base of
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   737
        # that parent (recursively). It avoids adding a useless entry in the
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   738
        # chain.
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   739
        #
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   740
        # However we need to detect that as a special case for delta-type, that
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   741
        # is not simply "other".
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   742
        p1_base = p1
51071
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   743
        if p1 != nodemod.nullrev and p1 < self._total_revs:
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   744
            e1 = self._index[p1]
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   745
            while e1[constants.ENTRY_DATA_COMPRESSED_LENGTH] == 0:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   746
                new_base = e1[constants.ENTRY_DELTA_BASE]
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   747
                if (
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   748
                    new_base == p1_base
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   749
                    or new_base == nodemod.nullrev
51071
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   750
                    or new_base >= self._total_revs
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   751
                ):
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   752
                    break
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   753
                p1_base = new_base
51071
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   754
                e1 = self._index[p1_base]
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   755
        p2_base = p2
51071
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   756
        if p2 != nodemod.nullrev and p2 < self._total_revs:
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   757
            e2 = self._index[p2]
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   758
            while e2[constants.ENTRY_DATA_COMPRESSED_LENGTH] == 0:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   759
                new_base = e2[constants.ENTRY_DELTA_BASE]
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   760
                if (
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   761
                    new_base == p2_base
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   762
                    or new_base == nodemod.nullrev
51071
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   763
                    or new_base >= self._total_revs
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   764
                ):
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   765
                    break
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   766
                p2_base = new_base
51071
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   767
                e2 = self._index[p2_base]
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   768
51071
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   769
        if self._generaldelta:
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   770
            if base == p1:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   771
                deltatype = b'p1'
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   772
            elif base == p2:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   773
                deltatype = b'p2'
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   774
            elif base == rev:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   775
                deltatype = b'base'
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   776
            elif base == p1_base:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   777
                deltatype = b'skip1'
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   778
            elif base == p2_base:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   779
                deltatype = b'skip2'
51071
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   780
            elif self._revlog.issnapshot(rev):
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   781
                deltatype = b'snap'
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   782
            elif base == rev - 1:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   783
                deltatype = b'prev'
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   784
            else:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   785
                deltatype = b'other'
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   786
        else:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   787
            if base == rev:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   788
                deltatype = b'base'
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   789
            else:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   790
                deltatype = b'prev'
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   791
51071
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   792
        chain = self._revlog._deltachain(rev)[0]
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   793
51074
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   794
        data = {
51073
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   795
            'p1': p1,
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   796
            'p2': p2,
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   797
            'compressed_size': compsize,
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   798
            'uncompressed_size': uncompsize,
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   799
            'deltatype': deltatype,
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   800
            'chain': chain,
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   801
        }
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   802
51074
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   803
        if size_info or dist_info or sparse_info:
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   804
            chain_size = 0
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   805
            for iter_rev in reversed(chain):
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   806
                cached = self._chain_size_cache.get(iter_rev)
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   807
                if cached is not None:
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   808
                    chain_size += cached
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   809
                    break
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   810
                e = self._index[iter_rev]
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   811
                chain_size += e[constants.ENTRY_DATA_COMPRESSED_LENGTH]
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   812
            self._chain_size_cache[rev] = chain_size
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   813
            data['chain_size'] = chain_size
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   814
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   815
        return data
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   816
51071
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   817
51073
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   818
def debug_delta_chain(
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   819
    revlog,
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   820
    revs=None,
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   821
    size_info=True,
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   822
    dist_info=True,
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   823
    sparse_info=True,
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   824
):
51071
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   825
    auditor = DeltaChainAuditor(revlog)
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   826
    r = revlog
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   827
    start = r.start
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   828
    length = r.length
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   829
    withsparseread = revlog.data_config.with_sparse_read
793a058f64bd delta-chain: extract some debugdeltachain logic is object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51070
diff changeset
   830
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   831
    header = (
51073
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   832
        b'    rev'
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   833
        b'      p1'
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   834
        b'      p2'
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   835
        b'  chain#'
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   836
        b' chainlen'
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   837
        b'     prev'
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   838
        b'   delta'
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   839
    )
51073
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   840
    if size_info:
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   841
        header += b'       size' b'    rawsize' b'  chainsize' b'     ratio'
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   842
    if dist_info:
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   843
        header += b'   lindist' b' extradist' b' extraratio'
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   844
    if withsparseread and sparse_info:
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   845
        header += b'   readsize' b' largestblk' b' rddensity' b' srchunks'
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   846
    header += b'\n'
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   847
    yield header
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   848
51072
810446d2d5ef debug-delta-chaing: add a parameter to select revision to look at
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51071
diff changeset
   849
    if revs is None:
810446d2d5ef debug-delta-chaing: add a parameter to select revision to look at
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51071
diff changeset
   850
        all_revs = iter(r)
810446d2d5ef debug-delta-chaing: add a parameter to select revision to look at
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51071
diff changeset
   851
    else:
810446d2d5ef debug-delta-chaing: add a parameter to select revision to look at
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51071
diff changeset
   852
        revlog_size = len(r)
810446d2d5ef debug-delta-chaing: add a parameter to select revision to look at
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51071
diff changeset
   853
        all_revs = sorted(rev for rev in revs if rev < revlog_size)
810446d2d5ef debug-delta-chaing: add a parameter to select revision to look at
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51071
diff changeset
   854
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   855
    chainbases = {}
51072
810446d2d5ef debug-delta-chaing: add a parameter to select revision to look at
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51071
diff changeset
   856
    for rev in all_revs:
51074
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   857
        info = auditor.revinfo(
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   858
            rev,
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   859
            size_info=size_info,
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   860
            dist_info=dist_info,
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   861
            sparse_info=sparse_info,
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   862
        )
51073
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   863
        comp = info['compressed_size']
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   864
        uncomp = info['uncompressed_size']
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   865
        chain = info['chain']
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   866
        chainbase = chain[0]
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   867
        chainid = chainbases.setdefault(chainbase, len(chainbases) + 1)
51074
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   868
        if dist_info:
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   869
            basestart = start(chainbase)
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   870
            revstart = start(rev)
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   871
            lineardist = revstart + comp - basestart
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   872
            extradist = lineardist - info['chain_size']
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   873
        try:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   874
            prevrev = chain[-2]
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   875
        except IndexError:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   876
            prevrev = -1
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   877
51074
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   878
        if size_info:
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   879
            chainsize = info['chain_size']
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   880
            if uncomp != 0:
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   881
                chainratio = float(chainsize) / float(uncomp)
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   882
            else:
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   883
                chainratio = chainsize
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   884
51074
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   885
        if dist_info:
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   886
            if chainsize != 0:
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   887
                extraratio = float(extradist) / float(chainsize)
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   888
            else:
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   889
                extraratio = extradist
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   890
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   891
        # label, display-format, data-key, value
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   892
        entry = [
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   893
            (b'rev', b'%7d', 'rev', rev),
51073
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   894
            (b'p1', b'%7d', 'p1', info['p1']),
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   895
            (b'p2', b'%7d', 'p2', info['p2']),
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   896
            (b'chainid', b'%7d', 'chainid', chainid),
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   897
            (b'chainlen', b'%8d', 'chainlen', len(chain)),
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   898
            (b'prevrev', b'%8d', 'prevrev', prevrev),
51073
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   899
            (b'deltatype', b'%7s', 'deltatype', info['deltatype']),
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   900
        ]
51073
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   901
        if size_info:
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   902
            entry.extend(
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   903
                [
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   904
                    (b'compsize', b'%10d', 'compsize', comp),
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   905
                    (b'uncompsize', b'%10d', 'uncompsize', uncomp),
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   906
                    (b'chainsize', b'%10d', 'chainsize', chainsize),
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   907
                    (b'chainratio', b'%9.5f', 'chainratio', chainratio),
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   908
                ]
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   909
            )
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   910
        if dist_info:
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   911
            entry.extend(
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   912
                [
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   913
                    (b'lindist', b'%9d', 'lindist', lineardist),
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   914
                    (b'extradist', b'%9d', 'extradist', extradist),
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   915
                    (b'extraratio', b'%10.5f', 'extraratio', extraratio),
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   916
                ]
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   917
            )
752e380c5702 debug-delta-chain: add options to control what we compute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51072
diff changeset
   918
        if withsparseread and sparse_info:
51074
5b5cb6b833b0 debug-delta-chain: actually skip unrequested computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51073
diff changeset
   919
            chainsize = info['chain_size']
51070
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   920
            readsize = 0
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   921
            largestblock = 0
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   922
            srchunks = 0
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   923
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   924
            for revschunk in deltautil.slicechunk(r, chain):
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   925
                srchunks += 1
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   926
                blkend = start(revschunk[-1]) + length(revschunk[-1])
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   927
                blksize = blkend - start(revschunk[0])
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   928
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   929
                readsize += blksize
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   930
                if largestblock < blksize:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   931
                    largestblock = blksize
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   932
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   933
            if readsize:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   934
                readdensity = float(chainsize) / float(readsize)
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   935
            else:
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   936
                readdensity = 1
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   937
            entry.extend(
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   938
                [
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   939
                    (b'readsize', b'%10d', 'readsize', readsize),
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   940
                    (b'largestblock', b'%10d', 'largestblock', largestblock),
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   941
                    (b'readdensity', b'%9.5f', 'readdensity', readdensity),
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   942
                    (b'srchunks', b'%8d', 'srchunks', srchunks),
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   943
                ]
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   944
            )
d7f975e49f20 delta-chain: move the debugdeltachain command in revlogutils
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51017
diff changeset
   945
        yield entry