hgext/pager.py
author Paul Morelle <paul.morelle@octobus.net>
Tue, 05 Jun 2018 08:19:35 +0200
changeset 38718 f8762ea73e0d
parent 34669 03f7db5f8e71
child 43076 2372284d9457
permissions -rw-r--r--
sparse-revlog: implement algorithm to write sparse delta chains (issue5480) The classic behavior of revlog._isgooddeltainfo is to consider the span size of the whole delta chain, and limit it to 4 * textlen. Once sparse-revlog writing is allowed (and enforced with a requirement), revlog._isgooddeltainfo considers the span of the largest chunk as the distance used in the verification, instead of using the span of the whole delta chain. In order to compute the span of the largest chunk, we need to slice into chunks a chain with the new revision at the top of the revlog, and take the maximal span of these chunks. The sparse read density is a parameter to the slicing, as it will stop when the global read density reaches this threshold. For instance, a density of 50% means that 2 of 4 read bytes are actually used for the reconstruction of the revision (the others are part of other chains). This allows a new revision to be potentially stored with a diff against another revision anywhere in the history, instead of forcing it in the last 4 * textlen. The result is a much better compression on repositories that have many concurrent branches. Here are a comparison between using deltas from current upstream (aggressive-merge-deltas on by default) and deltas from a sparse-revlog Comparison of `.hg/store/` size: mercurial (6.74% merges): before: 46,831,873 bytes after: 46,795,992 bytes (no relevant change) pypy (8.30% merges): before: 333,524,651 bytes after: 308,417,511 bytes -8% netbeans (34.21% merges): before: 1,141,847,554 bytes after: 1,131,093,161 bytes -1% mozilla-central (4.84% merges): before: 2,344,248,850 bytes after: 2,328,459,258 bytes -1% large-private-repo-A (merge 19.73%) before: 41,510,550,163 bytes after: 8,121,763,428 bytes -80% large-private-repo-B (23.77%) before: 58,702,221,709 bytes after: 8,351,588,828 bytes -76% Comparison of `00manifest.d` size: mercurial (6.74% merges): before: 6,143,044 bytes after: 6,107,163 bytes pypy (8.30% merges): before: 52,941,780 bytes after: 27,834,082 bytes -48% netbeans (34.21% merges): before: 130,088,982 bytes after: 119,337,636 bytes -10% mozilla-central (4.84% merges): before: 215,096,339 bytes after: 199,496,863 bytes -8% large-private-repo-A (merge 19.73%) before: 33,725,285,081 bytes after: 390,302,545 bytes -99% large-private-repo-B (23.77%) before: 49,457,701,645 bytes after: 1,366,752,187 bytes -97% The better delta chains provide a performance boost in relevant repositories: pypy, bundling 1000 revisions: before: 1.670s after: 1.149s -31% Unbundling got a bit slower. probably because the sparse algorithm is still pure python. pypy, unbundling 1000 revisions: before: 4.062s after: 4.507s +10% Performance of bundle/unbundle in repository with few concurrent branches (eg: mercurial) are unaffected. No significant differences have been noticed then timing `hg push` and `hg pull` locally. More state timings are being gathered. Same as for aggressive-merge-delta, better delta comes with longer delta chains. Longer chains have a performance impact. For example. The length of the chain needed to get the manifest of pypy's tip moves from 82 item to 1929 items. This moves the restore time from 3.88ms to 11.3ms. Delta chain length is an independent issue that affects repository without this changes. It will be dealt with independently. No significant differences have been observed on repositories where `sparse-revlog` have not much effect (mercurial, unity, netbeans). On pypy, small differences have been observed on some operation affected by delta chain building and retrieval. pypy, perfmanifest before: 0.006162s after: 0.017899s +190% pypy, commit: before: 0.382 after: 0.376 -1% pypy, status: before: 0.157 after: 0.168 +7% More comprehensive and stable timing comparisons are in progress.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
     1
# pager.py - display output using a pager
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
     2
#
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
     3
# Copyright 2008 David Soria Parra <dsp@php.net>
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 7995
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 10112
diff changeset
     6
# GNU General Public License version 2 or any later version.
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
     7
#
12083
ebfc46929f3e help: refer to user configuration file more consistently
Brodie Rao <brodie@bitheap.org>
parents: 11414
diff changeset
     8
# To load the extension, add it to your configuration file:
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
     9
#
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    10
#   [extension]
10112
703db37d186b hgext: enable extensions without "hgext." prefix in help texts
Martin Geisler <mg@lazybytes.net>
parents: 9841
diff changeset
    11
#   pager =
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    12
#
29967
bd55d98027ee pager: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29841
diff changeset
    13
# Run 'hg help pager' to get info on configuration.
6462
6c4e12682fb9 pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents: 6457
diff changeset
    14
31061
900996da577a pager: move most help to a new help topic and deprecate extension
Augie Fackler <augie@google.com>
parents: 31033
diff changeset
    15
'''browse command output with an external pager (DEPRECATED)
6462
6c4e12682fb9 pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents: 6457
diff changeset
    16
31061
900996da577a pager: move most help to a new help topic and deprecate extension
Augie Fackler <augie@google.com>
parents: 31033
diff changeset
    17
Forcibly enable paging for individual commands that don't typically
900996da577a pager: move most help to a new help topic and deprecate extension
Augie Fackler <augie@google.com>
parents: 31033
diff changeset
    18
request pagination with the attend-<command> option. This setting
900996da577a pager: move most help to a new help topic and deprecate extension
Augie Fackler <augie@google.com>
parents: 31033
diff changeset
    19
takes precedence over ignore options and defaults::
21281
bcddddcf0b54 pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents: 21280
diff changeset
    20
bcddddcf0b54 pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents: 21280
diff changeset
    21
  [pager]
bcddddcf0b54 pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents: 21280
diff changeset
    22
  attend-cat = false
6462
6c4e12682fb9 pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents: 6457
diff changeset
    23
'''
28320
63c2864af25f pager: use absolute_import
Augie Fackler <augie@google.com>
parents: 27128
diff changeset
    24
from __future__ import absolute_import
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    25
28320
63c2864af25f pager: use absolute_import
Augie Fackler <augie@google.com>
parents: 27128
diff changeset
    26
from mercurial import (
63c2864af25f pager: use absolute_import
Augie Fackler <augie@google.com>
parents: 27128
diff changeset
    27
    cmdutil,
63c2864af25f pager: use absolute_import
Augie Fackler <augie@google.com>
parents: 27128
diff changeset
    28
    commands,
63c2864af25f pager: use absolute_import
Augie Fackler <augie@google.com>
parents: 27128
diff changeset
    29
    dispatch,
63c2864af25f pager: use absolute_import
Augie Fackler <augie@google.com>
parents: 27128
diff changeset
    30
    extensions,
34495
6d1b0970f80c configitems: register the 'pager.attend' config
Boris Feld <boris.feld@octobus.net>
parents: 31406
diff changeset
    31
    registrar,
28320
63c2864af25f pager: use absolute_import
Augie Fackler <augie@google.com>
parents: 27128
diff changeset
    32
    )
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    33
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29205
diff changeset
    34
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
25186
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24067
diff changeset
    35
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24067
diff changeset
    36
# be specifying the version(s) of Mercurial they are tested with, or
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24067
diff changeset
    37
# leave the attribute unspecified.
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29205
diff changeset
    38
testedwith = 'ships-with-hg-core'
16743
38caf405d010 hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents: 16652
diff changeset
    39
34495
6d1b0970f80c configitems: register the 'pager.attend' config
Boris Feld <boris.feld@octobus.net>
parents: 31406
diff changeset
    40
configtable = {}
6d1b0970f80c configitems: register the 'pager.attend' config
Boris Feld <boris.feld@octobus.net>
parents: 31406
diff changeset
    41
configitem = registrar.configitem(configtable)
6d1b0970f80c configitems: register the 'pager.attend' config
Boris Feld <boris.feld@octobus.net>
parents: 31406
diff changeset
    42
6d1b0970f80c configitems: register the 'pager.attend' config
Boris Feld <boris.feld@octobus.net>
parents: 31406
diff changeset
    43
configitem('pager', 'attend',
6d1b0970f80c configitems: register the 'pager.attend' config
Boris Feld <boris.feld@octobus.net>
parents: 31406
diff changeset
    44
        default=lambda: attended,
6d1b0970f80c configitems: register the 'pager.attend' config
Boris Feld <boris.feld@octobus.net>
parents: 31406
diff changeset
    45
)
6d1b0970f80c configitems: register the 'pager.attend' config
Boris Feld <boris.feld@octobus.net>
parents: 31406
diff changeset
    46
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
    47
def uisetup(ui):
30722
117e15c30e6c pager: wrap ui._runpager
Jun Wu <quark@fb.com>
parents: 30635
diff changeset
    48
7216
292fb2ad2846 extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents: 6548
diff changeset
    49
    def pagecmd(orig, ui, options, cmd, cmdfunc):
21279
19b8cfe4396f pager: break auto out of command check loop
Matt Mackall <mpm@selenic.com>
parents: 21278
diff changeset
    50
        auto = options['pager'] == 'auto'
30993
9c2977ceaa46 pager: move more behavior into core
Augie Fackler <augie@google.com>
parents: 30992
diff changeset
    51
        if auto and not ui.pageractive:
21279
19b8cfe4396f pager: break auto out of command check loop
Matt Mackall <mpm@selenic.com>
parents: 21278
diff changeset
    52
            usepager = False
34495
6d1b0970f80c configitems: register the 'pager.attend' config
Boris Feld <boris.feld@octobus.net>
parents: 31406
diff changeset
    53
            attend = ui.configlist('pager', 'attend')
21280
71028188970e pager: variable reorder
Matt Mackall <mpm@selenic.com>
parents: 21279
diff changeset
    54
            ignore = ui.configlist('pager', 'ignore')
19940
7d99bff0f77c pager: honour internal aliases
David Soria Parra <dsp@experimentalworks.net>
parents: 18923
diff changeset
    55
            cmds, _ = cmdutil.findcmd(cmd, commands.table)
7d99bff0f77c pager: honour internal aliases
David Soria Parra <dsp@experimentalworks.net>
parents: 18923
diff changeset
    56
7d99bff0f77c pager: honour internal aliases
David Soria Parra <dsp@experimentalworks.net>
parents: 18923
diff changeset
    57
            for cmd in cmds:
21281
bcddddcf0b54 pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents: 21280
diff changeset
    58
                var = 'attend-%s' % cmd
34669
03f7db5f8e71 configitems: register the 'pager.attend-.*' options
Boris Feld <boris.feld@octobus.net>
parents: 34495
diff changeset
    59
                if ui.config('pager', var, None):
03f7db5f8e71 configitems: register the 'pager.attend-.*' options
Boris Feld <boris.feld@octobus.net>
parents: 34495
diff changeset
    60
                    usepager = ui.configbool('pager', var, True)
21281
bcddddcf0b54 pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents: 21280
diff changeset
    61
                    break
21279
19b8cfe4396f pager: break auto out of command check loop
Matt Mackall <mpm@selenic.com>
parents: 21278
diff changeset
    62
                if (cmd in attend or
19b8cfe4396f pager: break auto out of command check loop
Matt Mackall <mpm@selenic.com>
parents: 21278
diff changeset
    63
                     (cmd not in ignore and not attend)):
21277
2bc778e2f9b3 pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents: 20790
diff changeset
    64
                    usepager = True
19940
7d99bff0f77c pager: honour internal aliases
David Soria Parra <dsp@experimentalworks.net>
parents: 18923
diff changeset
    65
                    break
21277
2bc778e2f9b3 pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents: 20790
diff changeset
    66
30993
9c2977ceaa46 pager: move more behavior into core
Augie Fackler <augie@google.com>
parents: 30992
diff changeset
    67
            if usepager:
30995
5e85bab867a7 ui: add ignore-single-command functionality
Augie Fackler <augie@google.com>
parents: 30993
diff changeset
    68
                # Slight hack: the attend list is supposed to override
5e85bab867a7 ui: add ignore-single-command functionality
Augie Fackler <augie@google.com>
parents: 30993
diff changeset
    69
                # the ignore list for the pager extension, but the
5e85bab867a7 ui: add ignore-single-command functionality
Augie Fackler <augie@google.com>
parents: 30993
diff changeset
    70
                # core code doesn't know about attend, so we have to
5e85bab867a7 ui: add ignore-single-command functionality
Augie Fackler <augie@google.com>
parents: 30993
diff changeset
    71
                # lobotomize the ignore list so that the extension's
5e85bab867a7 ui: add ignore-single-command functionality
Augie Fackler <augie@google.com>
parents: 30993
diff changeset
    72
                # behavior is preserved.
5e85bab867a7 ui: add ignore-single-command functionality
Augie Fackler <augie@google.com>
parents: 30993
diff changeset
    73
                ui.setconfig('pager', 'ignore', '', 'pager')
30993
9c2977ceaa46 pager: move more behavior into core
Augie Fackler <augie@google.com>
parents: 30992
diff changeset
    74
                ui.pager('extension-via-attend-' + cmd)
31406
e83302d43748 pager: if old pager extensions is enabled, respect pager.attend
Martin von Zweigbergk <martinvonz@google.com>
parents: 31122
diff changeset
    75
            else:
e83302d43748 pager: if old pager extensions is enabled, respect pager.attend
Martin von Zweigbergk <martinvonz@google.com>
parents: 31122
diff changeset
    76
                ui.disablepager()
7216
292fb2ad2846 extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents: 6548
diff changeset
    77
        return orig(ui, options, cmd, cmdfunc)
6417
13fafd8cc4a1 pager: Add a configuration to enable/disable the pager for certain commands
David Soria Parra <dsp <at> php.net>
parents: 6324
diff changeset
    78
31122
53a60e95f154 pager: drop the 'color' dependant code
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31061
diff changeset
    79
    extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
9841
7cd6dee6fe37 pager: provide a default attend list
Brodie Rao <me+hg@dackz.net>
parents: 9267
diff changeset
    80
31406
e83302d43748 pager: if old pager extensions is enabled, respect pager.attend
Martin von Zweigbergk <martinvonz@google.com>
parents: 31122
diff changeset
    81
attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff']