tests/printenv.py
author Patrick Mezard <patrick@mezard.eu>
Sat, 19 May 2012 17:18:29 +0200
branchstable
changeset 16771 2f3317d53d51
parent 13405 682edefe7dbb
child 16963 c19113e842d3
permissions -rw-r--r--
revset: explicitely tag alias arguments for expansion The current revset alias expansion code works like: 1- Get the replacement tree 2- Substitute the variables in the replacement tree 3- Expand the replacement tree It makes it easy to substitute alias arguments because the placeholders are always replaced before the updated replacement tree is expanded again. Unfortunately, to fix other alias expansion issues, we need to reorder the sequence and delay the argument substitution. To solve this, a new "virtual" construct called _aliasarg() is introduced and injected when parsing the aliases definitions. Only _aliasarg() will be substituted in the argument expansion phase instead of all regular matching string. We also check user inputs do not contain unexpected _aliasarg() instances to avoid argument injections.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4285
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     1
# simple script to be used in hooks
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     2
#
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     3
# 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
     4
#
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     5
#     [hooks]
13405
682edefe7dbb tests: use printenv.py where it is - don't copy it around
Mads Kiilerich <mads@kiilerich.com>
parents: 13404
diff changeset
     6
#     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
     7
#
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     8
#   - <hookname> is a mandatory argument (e.g. "changegroup")
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     9
#   - [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
    10
#   - [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
    11
#              the file will be opened in append mode.
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    12
#
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    13
import os
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    14
import sys
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    15
7080
a6477aa893b8 tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents: 4659
diff changeset
    16
try:
a6477aa893b8 tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents: 4659
diff changeset
    17
    import msvcrt
a6477aa893b8 tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents: 4659
diff changeset
    18
    msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
a6477aa893b8 tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents: 4659
diff changeset
    19
    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
    20
    msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
7080
a6477aa893b8 tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents: 4659
diff changeset
    21
except ImportError:
a6477aa893b8 tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents: 4659
diff changeset
    22
    pass
a6477aa893b8 tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents: 4659
diff changeset
    23
4285
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    24
exitcode = 0
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    25
out = sys.stdout
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    26
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    27
name = sys.argv[1]
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    28
if len(sys.argv) > 2:
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    29
    exitcode = int(sys.argv[2])
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    30
    if len(sys.argv) > 3:
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    31
        out = open(sys.argv[3], "ab")
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    32
4643
a39cec1d5cb8 printenv: filter empty environment variables for portability.
Patrick Mezard <pmezard@gmail.com>
parents: 4285
diff changeset
    33
# 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
    34
# them now for portability sake.
4659
7a7d4937272b Kill trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4643
diff changeset
    35
env = [k for k, v in os.environ.iteritems()
4643
a39cec1d5cb8 printenv: filter empty environment variables for portability.
Patrick Mezard <pmezard@gmail.com>
parents: 4285
diff changeset
    36
       if k.startswith("HG_") and v]
4285
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    37
env.sort()
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    38
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    39
out.write("%s hook: " % name)
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    40
for v in env:
12642
bb35840e965c tests: remove the last traces of $HGTMP
Mads Kiilerich <mads@kiilerich.com>
parents: 10282
diff changeset
    41
    out.write("%s=%s " % (v, os.environ[v]))
4285
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    42
out.write("\n")
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    43
out.close()
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    44
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    45
sys.exit(exitcode)