tests/printenv.py
author Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
Tue, 02 Jul 2019 12:59:58 -0400
changeset 42621 99ebde4fec99
parent 41039 73da729ccfef
child 43076 2372284d9457
permissions -rwxr-xr-x
commit: improve the files field of changelog for merges Currently, the files list of merge commits repeats all the deletions (either actual deletions, or files that got renamed) that happened between base and p2 of the merge. If p2 is the main branch, the list can easily be much bigger than the change being merged. This results in various problems worth improving: - changelog is bigger than necessary - `hg log directory` lists many unrelated merge commits, and `hg log -v -r commit` frequently fills multiple screens worth of files - it possibly slows down adjustlinkrev, by forcing it to read more manifests, and that function can certainly be a bottleneck - the server side of pulls can waste a lot of time simply opening the filelogs for pointless files (the constant factors for opening even a tiny filelog is apparently pretty bad) So stop listing such files as described in the code. Impacted merge commits and their descendants get a different hash than they would have without this. This doesn't seem problematic, except for convert. The previous commit helped with that in the hg->hg case (but if you do svn->hg twice from scratch, hashes can still change). The rest of the description is numbers. I don't have much to report, because recreating the files list of existing repositories is not easy: - debugupgradeformat and bundle/unbundle don't recreate the list - export/import tends to choke quickly applying patches or on description that contain diffs, - merge commits from the convert extension don't have the right files list for reasons orthogonal to the current commit - replaying the merge with hg update/hg merge/hg revert --all/hg commit can end up failing in hg revert - I wasn't sure that using debugsetparents + debugrebuilddirstate would really build the right thing I measured commit time before and after this change, in a case with no files filtered out, several files filtered out (no difference) and 5k files filtered out (+1% time). Recreating the 100 more recent merges in a private repo, the concatenated uncompressed files lists goes from 1.12MB to 0.52MB. Excluding 3 merges that are not representative, then the size goes from 570k to 15k. I converted part of mozilla-central, and observed file list shrinking quite a bit too, starting at the very first merge, 733641d9feaf, going from 550 files to 10 files (although they have relatively few merges, so they probably wouldn't care). Differential Revision: https://phab.mercurial-scm.org/D6613
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25477
a372f7b4463b tests: make printenv executable
Matt Mackall <mpm@selenic.com>
parents: 17018
diff changeset
     1
#!/usr/bin/env python
a372f7b4463b tests: make printenv executable
Matt Mackall <mpm@selenic.com>
parents: 17018
diff changeset
     2
#
4285
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     3
# simple script to be used in hooks
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     4
#
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     5
# put something like this in the repo .hg/hgrc:
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     6
#
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     7
#     [hooks]
17018
e7fdfc702d9f tests: consistently use printenv.py the same MSYS/Windows-compatible way
Mads Kiilerich <mads@kiilerich.com>
parents: 16982
diff changeset
     8
#     changegroup = python "$TESTDIR/printenv.py" <hookname> [exit] [output]
4285
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     9
#
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    10
#   - <hookname> is a mandatory argument (e.g. "changegroup")
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    11
#   - [exit] is the exit code of the hook (default: 0)
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    12
#   - [output] is the name of the output file (default: use sys.stdout)
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    13
#              the file will be opened in append mode.
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    14
#
28944
036787c10b16 py3: use absolute_import in printenv.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 25477
diff changeset
    15
from __future__ import absolute_import
41028
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    16
import argparse
4285
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    17
import os
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    18
import sys
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    19
7080
a6477aa893b8 tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents: 4659
diff changeset
    20
try:
a6477aa893b8 tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents: 4659
diff changeset
    21
    import msvcrt
a6477aa893b8 tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents: 4659
diff changeset
    22
    msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
a6477aa893b8 tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents: 4659
diff changeset
    23
    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
7186
f77c8d8331ca clean up trailing spaces, leading spaces in C
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7080
diff changeset
    24
    msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
7080
a6477aa893b8 tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents: 4659
diff changeset
    25
except ImportError:
a6477aa893b8 tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents: 4659
diff changeset
    26
    pass
a6477aa893b8 tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents: 4659
diff changeset
    27
41028
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    28
parser = argparse.ArgumentParser()
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    29
parser.add_argument("name", help="the hook name, used for display")
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    30
parser.add_argument(
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    31
    "exitcode",
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    32
    nargs="?",
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    33
    default=0,
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    34
    type=int,
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    35
    help="the exit code for the hook",
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    36
)
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    37
parser.add_argument(
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    38
    "out", nargs="?", default=None, help="where to write the output"
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    39
)
41039
73da729ccfef test: introduce a new flag to display env variable line per line
Boris Feld <boris.feld@octobus.net>
parents: 41028
diff changeset
    40
parser.add_argument(
73da729ccfef test: introduce a new flag to display env variable line per line
Boris Feld <boris.feld@octobus.net>
parents: 41028
diff changeset
    41
    "--line",
73da729ccfef test: introduce a new flag to display env variable line per line
Boris Feld <boris.feld@octobus.net>
parents: 41028
diff changeset
    42
    action="store_true",
73da729ccfef test: introduce a new flag to display env variable line per line
Boris Feld <boris.feld@octobus.net>
parents: 41028
diff changeset
    43
    help="print environment variables one per line instead of on a single line",
73da729ccfef test: introduce a new flag to display env variable line per line
Boris Feld <boris.feld@octobus.net>
parents: 41028
diff changeset
    44
)
41028
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    45
args = parser.parse_args()
4285
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    46
41028
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    47
if args.out is None:
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    48
    out = sys.stdout
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    49
    out = getattr(out, "buffer", out)
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    50
else:
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    51
    out = open(args.out, "ab")
4285
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    52
4643
a39cec1d5cb8 printenv: filter empty environment variables for portability.
Patrick Mezard <pmezard@gmail.com>
parents: 4285
diff changeset
    53
# variables with empty values may not exist on all platforms, filter
a39cec1d5cb8 printenv: filter empty environment variables for portability.
Patrick Mezard <pmezard@gmail.com>
parents: 4285
diff changeset
    54
# them now for portability sake.
36287
84a6e39bc723 printenv: port to python3
Augie Fackler <augie@google.com>
parents: 28944
diff changeset
    55
env = [(k, v) for k, v in os.environ.items()
4643
a39cec1d5cb8 printenv: filter empty environment variables for portability.
Patrick Mezard <pmezard@gmail.com>
parents: 4285
diff changeset
    56
       if k.startswith("HG_") and v]
4285
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    57
env.sort()
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    58
41028
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    59
out.write(b"%s hook: " % args.name.encode('ascii'))
16982
9c892c830a72 tests/printenv.py: eliminate trailing spaces on output
Adrian Buehlmann <adrian@cadifra.com>
parents: 16963
diff changeset
    60
if os.name == 'nt':
9c892c830a72 tests/printenv.py: eliminate trailing spaces on output
Adrian Buehlmann <adrian@cadifra.com>
parents: 16963
diff changeset
    61
    filter = lambda x: x.replace('\\', '/')
9c892c830a72 tests/printenv.py: eliminate trailing spaces on output
Adrian Buehlmann <adrian@cadifra.com>
parents: 16963
diff changeset
    62
else:
9c892c830a72 tests/printenv.py: eliminate trailing spaces on output
Adrian Buehlmann <adrian@cadifra.com>
parents: 16963
diff changeset
    63
    filter = lambda x: x
41039
73da729ccfef test: introduce a new flag to display env variable line per line
Boris Feld <boris.feld@octobus.net>
parents: 41028
diff changeset
    64
38144
bacbe829c2bf py3: use bytes in tests/printenv.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36287
diff changeset
    65
vars = [b"%s=%s" % (k.encode('ascii'), filter(v).encode('ascii'))
bacbe829c2bf py3: use bytes in tests/printenv.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36287
diff changeset
    66
        for k, v in env]
41039
73da729ccfef test: introduce a new flag to display env variable line per line
Boris Feld <boris.feld@octobus.net>
parents: 41028
diff changeset
    67
73da729ccfef test: introduce a new flag to display env variable line per line
Boris Feld <boris.feld@octobus.net>
parents: 41028
diff changeset
    68
# Print variables on out
73da729ccfef test: introduce a new flag to display env variable line per line
Boris Feld <boris.feld@octobus.net>
parents: 41028
diff changeset
    69
if not args.line:
73da729ccfef test: introduce a new flag to display env variable line per line
Boris Feld <boris.feld@octobus.net>
parents: 41028
diff changeset
    70
    out.write(b" ".join(vars))
73da729ccfef test: introduce a new flag to display env variable line per line
Boris Feld <boris.feld@octobus.net>
parents: 41028
diff changeset
    71
else:
73da729ccfef test: introduce a new flag to display env variable line per line
Boris Feld <boris.feld@octobus.net>
parents: 41028
diff changeset
    72
    for var in vars:
73da729ccfef test: introduce a new flag to display env variable line per line
Boris Feld <boris.feld@octobus.net>
parents: 41028
diff changeset
    73
        out.write(var)
73da729ccfef test: introduce a new flag to display env variable line per line
Boris Feld <boris.feld@octobus.net>
parents: 41028
diff changeset
    74
        out.write(b"\n")
73da729ccfef test: introduce a new flag to display env variable line per line
Boris Feld <boris.feld@octobus.net>
parents: 41028
diff changeset
    75
38144
bacbe829c2bf py3: use bytes in tests/printenv.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36287
diff changeset
    76
out.write(b"\n")
4285
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    77
out.close()
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    78
41028
3c5aaea9638f tests: update printenv.py argument parsing
Boris Feld <boris.feld@octobus.net>
parents: 38307
diff changeset
    79
sys.exit(args.exitcode)