tests/test-custom-filters.t
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 40609 ee9981bc8b44
child 49621 55c6ebd11cb9
permissions -rw-r--r--
procutil: make stream detection in make_line_buffered more correct and strict In make_line_buffered(), we don’t want to wrap the stream if we know that lines get flushed to the underlying raw stream already. Previously, the heuristic was too optimistic. It assumed that any stream which is not an instance of io.BufferedIOBase doesn’t need wrapping. However, there are buffered streams that aren’t instances of io.BufferedIOBase, like Mercurial’s own winstdout. The new logic is different in two ways: First, only for the check, if unwraps any combination of WriteAllWrapper and winstdout. Second, it skips wrapping the stream only if it is an instance of io.RawIOBase (or already wrapped). If it is an instance of io.BufferedIOBase, it gets wrapped. In any other case, the function raises an exception. This ensures that, if an unknown stream is passed or we add another wrapper in the future, we don’t wrap the stream if it’s already line buffered or not wrap the stream if it’s not line buffered. In fact, this was already helpful during development of this change. Without it, I possibly would have forgot that WriteAllWrapper needs to be ignored for the check, leading to unnecessary wrapping if stdout is unbuffered. The alternative would have been to always wrap unknown streams. However, I don’t think that anyone would benefit from being less strict. We can expect streams from the standard library to be subclassing either io.RawIOBase or io.BufferedIOBase, so running Mercurial in the standard way should not regress by this change. Py2exe might replace sys.stdout and sys.stderr, but that currently breaks Mercurial anyway and also these streams don’t claim to be interactive, so this function is not called for them.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
     1
  $ hg init
6066
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
     2
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
     3
  $ cat > .hg/hgrc <<EOF
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
     4
  > [extensions]
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
     5
  > prefixfilter = prefix.py
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
     6
  > [encode]
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
     7
  > *.txt = stripprefix: Copyright 2046, The Masters
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
     8
  > [decode]
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
     9
  > *.txt = insertprefix: Copyright 2046, The Masters
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    10
  > EOF
6066
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    11
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    12
  $ cat > prefix.py <<EOF
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 12316
diff changeset
    13
  > from mercurial import error
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    14
  > def stripprefix(s, cmd, filename, **kwargs):
38071
6e713711331b py3: add b'' prefixes in tests/test-custom-filters.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 26587
diff changeset
    15
  >     header = b'%s\n' % cmd
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    16
  >     if s[:len(header)] != header:
38071
6e713711331b py3: add b'' prefixes in tests/test-custom-filters.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 26587
diff changeset
    17
  >         raise error.Abort(b'missing header "%s" in %s' % (cmd, filename))
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    18
  >     return s[len(header):]
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    19
  > def insertprefix(s, cmd):
38071
6e713711331b py3: add b'' prefixes in tests/test-custom-filters.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 26587
diff changeset
    20
  >     return b'%s\n%s' % (cmd, s)
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    21
  > def reposetup(ui, repo):
38071
6e713711331b py3: add b'' prefixes in tests/test-custom-filters.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 26587
diff changeset
    22
  >     repo.adddatafilter(b'stripprefix:', stripprefix)
6e713711331b py3: add b'' prefixes in tests/test-custom-filters.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 26587
diff changeset
    23
  >     repo.adddatafilter(b'insertprefix:', insertprefix)
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    24
  > EOF
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    25
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    26
  $ cat > .hgignore <<EOF
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    27
  > .hgignore
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    28
  > prefix.py
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    29
  > prefix.pyc
40609
ee9981bc8b44 py3: add __pycache__ to .hgignore
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38071
diff changeset
    30
  > __pycache__/
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    31
  > EOF
6066
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    32
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    33
  $ cat > stuff.txt <<EOF
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    34
  > Copyright 2046, The Masters
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    35
  > Some stuff to ponder very carefully.
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    36
  > EOF
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    37
  $ hg add stuff.txt
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    38
  $ hg ci -m stuff
6066
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    39
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    40
Repository data:
6066
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    41
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    42
  $ hg cat stuff.txt
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    43
  Some stuff to ponder very carefully.
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    44
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    45
Fresh checkout:
6066
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    46
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    47
  $ rm stuff.txt
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    48
  $ hg up -C
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    49
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    50
  $ cat stuff.txt
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    51
  Copyright 2046, The Masters
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    52
  Some stuff to ponder very carefully.
12125
e5ccb9ea8266 test-custom-filter: heredoc is not required for single line operations
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12124
diff changeset
    53
  $ echo "Very very carefully." >> stuff.txt
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    54
  $ hg stat
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    55
  M stuff.txt
6066
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    56
12125
e5ccb9ea8266 test-custom-filter: heredoc is not required for single line operations
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12124
diff changeset
    57
  $ echo "Unauthorized material subject to destruction." > morestuff.txt
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    58
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    59
Problem encoding:
6066
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    60
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    61
  $ hg add morestuff.txt
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    62
  $ hg ci -m morestuff
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    63
  abort: missing header "Copyright 2046, The Masters" in morestuff.txt
12316
4134686b83e1 tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 12125
diff changeset
    64
  [255]
12124
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    65
  $ hg stat
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    66
  M stuff.txt
7edda6c7985d tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8742
diff changeset
    67
  A morestuff.txt