tests/test-mq-qrename.t
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 23402 2963d5c9d90b
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.


  $ echo "[extensions]" >> $HGRCPATH
  $ echo "mq=" >> $HGRCPATH

  $ hg init a
  $ cd a

  $ echo 'base' > base
  $ hg ci -Ambase
  adding base

  $ hg qnew -mmqbase mqbase

  $ hg qrename mqbase renamed
  $ mkdir .hg/patches/foo
  $ hg qrename renamed foo

  $ hg qseries
  foo/renamed

  $ ls .hg/patches/foo
  renamed

  $ mkdir .hg/patches/bar
  $ hg qrename foo/renamed bar

  $ hg qseries
  bar/renamed

  $ ls .hg/patches/bar
  renamed

  $ hg qrename bar/renamed baz

  $ hg qseries
  baz

  $ ls .hg/patches/baz
  .hg/patches/baz

  $ hg qrename baz new/dir

  $ hg qseries
  new/dir

  $ ls .hg/patches/new/dir
  .hg/patches/new/dir

  $ cd ..

Test patch being renamed before committed:

  $ hg init b
  $ cd b
  $ hg qinit -c
  $ hg qnew x
  $ hg qrename y
  $ hg qcommit -m rename

  $ cd ..

Test overlapping renames (issue2388)

  $ hg init c
  $ cd c
  $ hg qinit -c
  $ echo a > a
  $ hg add
  adding a
  $ hg qnew patcha
  $ echo b > b
  $ hg add
  adding b
  $ hg qnew patchb
  $ hg ci --mq -m c1
  $ hg qrename patchb patchc
  $ hg qrename patcha patchb
  $ hg st --mq
  M patchb
  M series
  A patchc
  R patcha
  $ cd ..

Test renames with mq repo (issue2097)

  $ hg init issue2097
  $ cd issue2097
  $ hg qnew p0
  $ (cd .hg/patches && hg init)
  $ hg qren p0 p1
  $ hg debugstate --mq
  $ hg ci --mq -mq0
  nothing changed
  [1]
  $ cd ..

Test renaming to a folded patch (issue3058)

  $ hg init issue3058
  $ cd issue3058
  $ hg init --mq
  $ echo a > a
  $ hg add a
  $ hg qnew adda
  $ echo b >> a
  $ hg qnew addb
  $ hg qpop
  popping addb
  now at: adda
  $ hg ci --mq -m "save mq"
  $ hg qfold addb
  $ hg qmv addb
  $ cat .hg/patches/addb
  # HG changeset patch
  # Parent  0000000000000000000000000000000000000000
  
  diff -r 000000000000 a
  --- /dev/null	* (glob)
  +++ b/a	* (glob)
  @@ -0,0 +1,2 @@
  +a
  +b
  $ cd ..