hgext/children.py
author Siddharth Agarwal <sid0@fb.com>
Wed, 25 Mar 2015 15:55:31 -0700
changeset 24461 05ccfe6763f1
parent 21780 2d3fb8476d7a
child 24482 3eb9045396b0
permissions -rw-r--r--
osutil: use getdirentriesattr on OS X if possible This is a significant win for large repositories on OS X, especially with a cold cache. Unfortunately we need to keep the lstat-based implementation around for two reasons: - Not all filesystems support this call. - There's an edge case in which it's best to fall back to avoid a retry loop. More about this in the comments. The below tests are all performed on a Mac with an SSD running OS X 10.9, on a repository with over 200k files. The results are best of 5 with simulated best-effort conditions. The gains with a hot cache are pretty impressive: 'hg status' goes from 5.18 seconds to 3.79 seconds. However, a repository that large will probably already be using something like hgwatchman [1], which helps much more (for this repo, 'hg status' with hgwatchman is approximately 1 second). Where this really helps is when the cache is cold [2]: hg status goes from 31.0 seconds to 9.66. See http://lists.apple.com/archives/filesystem-dev/2014/Dec/msg00002.html for some more discussion about this function. This is based on a patch by Sean Farley <sean@farley.io>. [1] https://bitbucket.org/facebook/hgwatchman [2] There appears to be no easy way to clear the file cache (aka "vnodes") on OS X short of rebooting. purge(8) purportedly does that but in my testing had little effect. The workaround I came up with was to assume that vnode eviction was LRU, make sure the kern.maxvnodes sysctl is smaller than the size of the repository, then make sure we'd always miss the cache by running 'hg status' in another clone of the repository before running it in the test repository.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     1
# Mercurial extension to provide the 'hg children' command
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     2
#
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     3
# Copyright 2007 by Intevation GmbH <intevation@intevation.de>
8228
eee2319c5895 add blank line after copyright notices and after header
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
     4
#
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     5
# Author(s):
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     6
# Thomas Arendsen Hein <thomas@intevation.de>
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     7
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8076
diff changeset
     8
# 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: 9253
diff changeset
     9
# GNU General Public License version 2 or any later version.
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    10
16668
f393d20fb2ba children: mark extension as deprecated
Augie Fackler <raf@durin42.com>
parents: 11321
diff changeset
    11
'''command to display child changesets (DEPRECATED)
f393d20fb2ba children: mark extension as deprecated
Augie Fackler <raf@durin42.com>
parents: 11321
diff changeset
    12
16670
052047753f7d children: use hg reST role for example
Martin Geisler <mg@lazybytes.net>
parents: 16668
diff changeset
    13
This extension is deprecated. You should use :hg:`log -r
052047753f7d children: use hg reST role for example
Martin Geisler <mg@lazybytes.net>
parents: 16668
diff changeset
    14
"children(REV)"` instead.
16668
f393d20fb2ba children: mark extension as deprecated
Augie Fackler <raf@durin42.com>
parents: 11321
diff changeset
    15
'''
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8277
diff changeset
    16
21780
2d3fb8476d7a children: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21248
diff changeset
    17
from mercurial import cmdutil
6192
cd65a67aff31 Introduce templateopts and logopts to reduce duplicate option definitions.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4785
diff changeset
    18
from mercurial.commands import templateopts
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    19
from mercurial.i18n import _
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    20
21248
48e859e30cbf children: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 17773
diff changeset
    21
cmdtable = {}
48e859e30cbf children: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 17773
diff changeset
    22
command = cmdutil.command(cmdtable)
16743
38caf405d010 hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents: 16670
diff changeset
    23
testedwith = 'internal'
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    24
21248
48e859e30cbf children: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 17773
diff changeset
    25
@command('children',
48e859e30cbf children: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 17773
diff changeset
    26
    [('r', 'rev', '',
48e859e30cbf children: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 17773
diff changeset
    27
     _('show children of the specified revision'), _('REV')),
48e859e30cbf children: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 17773
diff changeset
    28
    ] + templateopts,
21780
2d3fb8476d7a children: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21248
diff changeset
    29
    _('hg children [-r REV] [FILE]'),
2d3fb8476d7a children: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21248
diff changeset
    30
    inferrepo=True)
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    31
def children(ui, repo, file_=None, **opts):
8026
683d8ebcf434 expand "dir" to "directory" in help texts
Martin Geisler <mg@lazybytes.net>
parents: 7986
diff changeset
    32
    """show the children of the given or working directory revision
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    33
9253
d6d811d90976 children: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9055
diff changeset
    34
    Print the children of the working directory's revisions. If a
d6d811d90976 children: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9055
diff changeset
    35
    revision is given via -r/--rev, the children of that revision will
d6d811d90976 children: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9055
diff changeset
    36
    be printed. If a file argument is given, revision in which the
d6d811d90976 children: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9055
diff changeset
    37
    file was last changed (after the working directory revision or the
d6d811d90976 children: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9055
diff changeset
    38
    argument to --rev if given) is printed.
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    39
    """
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    40
    rev = opts.get('rev')
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    41
    if file_:
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    42
        ctx = repo.filectx(file_, changeid=rev)
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    43
    else:
6747
f6c00b17387c use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents: 6192
diff changeset
    44
        ctx = repo[rev]
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    45
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    46
    displayer = cmdutil.show_changeset(ui, repo, opts)
7369
87158be081b8 cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6747
diff changeset
    47
    for cctx in ctx.children():
87158be081b8 cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6747
diff changeset
    48
        displayer.show(cctx)
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 9253
diff changeset
    49
    displayer.close()