tests/test-context-metadata.t
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 48876 42d2b31cee0b
child 50725 7e5be4a7cda7
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:
33999
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     1
Tests about metadataonlyctx
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     2
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     3
  $ hg init
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     4
  $ echo A > A
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     5
  $ hg commit -A A -m 'Add A'
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     6
  $ echo B > B
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     7
  $ hg commit -A B -m 'Add B'
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     8
  $ hg rm A
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     9
  $ echo C > C
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    10
  $ echo B2 > B
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    11
  $ hg add C -q
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    12
  $ hg commit -m 'Remove A'
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    13
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    14
  $ cat > metaedit.py <<EOF
36048
194463554ba5 py3: port metaedit extension to Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34061
diff changeset
    15
  > from mercurial import context, pycompat, registrar
33999
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    16
  > cmdtable = {}
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    17
  > command = registrar.command(cmdtable)
36048
194463554ba5 py3: port metaedit extension to Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34061
diff changeset
    18
  > @command(b'metaedit')
33999
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    19
  > def metaedit(ui, repo, arg):
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    20
  >     # Modify commit message to "FOO"
36048
194463554ba5 py3: port metaedit extension to Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34061
diff changeset
    21
  >     with repo.wlock(), repo.lock(), repo.transaction(b'metaedit'):
194463554ba5 py3: port metaedit extension to Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34061
diff changeset
    22
  >         old = repo[b'.']
194463554ba5 py3: port metaedit extension to Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34061
diff changeset
    23
  >         kwargs = dict(s.split(b'=', 1) for s in arg.split(b';'))
40303
b8db53f786f0 tests: add missing b prefix in test-context-metadata.t
Augie Fackler <augie@google.com>
parents: 37851
diff changeset
    24
  >         if b'parents' in kwargs:
37851
8327fd79adf8 tests: pass parent revision as integer to repo[x] in test-context-metadata.t
Martin von Zweigbergk <martinvonz@google.com>
parents: 36048
diff changeset
    25
  >             kwargs[b'parents'] = map(int, kwargs[b'parents'].split(b','))
36048
194463554ba5 py3: port metaedit extension to Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34061
diff changeset
    26
  >         new = context.metadataonlyctx(repo, old,
194463554ba5 py3: port metaedit extension to Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34061
diff changeset
    27
  >                                       **pycompat.strkwargs(kwargs))
33999
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    28
  >         new.commit()
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    29
  > EOF
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    30
  $ hg --config extensions.metaedit=$TESTTMP/metaedit.py metaedit 'text=Changed'
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    31
  $ hg log -r tip
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    32
  changeset:   3:ad83e9e00ec9
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    33
  tag:         tip
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    34
  parent:      1:3afb7afe6632
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    35
  user:        test
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    36
  date:        Thu Jan 01 00:00:00 1970 +0000
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    37
  summary:     Changed
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    38
  
34061
11499bad0359 check-code: forbid "\S" in egrep regular expression
Jun Wu <quark@fb.com>
parents: 33999
diff changeset
    39
  $ hg --config extensions.metaedit=$TESTTMP/metaedit.py metaedit 'parents=0' 2>&1 | egrep '^RuntimeError'
33999
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    40
  RuntimeError: can't reuse the manifest: its p1 doesn't match the new ctx p1
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    41
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    42
  $ hg --config extensions.metaedit=$TESTTMP/metaedit.py metaedit 'user=foo <foo@example.com>'
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    43
  $ hg log -r tip
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    44
  changeset:   4:1f86eaeca92b
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    45
  tag:         tip
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    46
  parent:      1:3afb7afe6632
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    47
  user:        foo <foo@example.com>
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    48
  date:        Thu Jan 01 00:00:00 1970 +0000
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    49
  summary:     Remove A
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    50