tests/test-mq-qdelete.t
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 48116 5ced12cfa41b
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 -d '1 0'
  adding base

  $ hg qnew -d '1 0' pa
  $ hg qnew -d '1 0' pb
  $ hg qnew -d '1 0' pc

  $ hg qdel
  abort: qdelete requires at least one revision or patch name
  [255]

  $ hg qdel pc
  abort: cannot delete applied patch pc
  [255]

  $ hg qpop
  popping pc
  now at: pb

Delete the same patch twice in one command (issue2427)

  $ hg qdel pc pc

  $ hg qseries
  pa
  pb

  $ ls .hg/patches
  pa
  pb
  series
  status

  $ hg qpop
  popping pb
  now at: pa

  $ hg qdel -k 1

  $ ls .hg/patches
  pa
  pb
  series
  status

  $ hg qdel -r pa
  patch pa finalized without changeset message

  $ hg qapplied

  $ hg log --template '{rev} {desc}\n'
  1 [mq]: pa
  0 base

  $ hg qnew pd
  $ hg qnew pe
  $ hg qnew pf

  $ hg qdel -r pe
  abort: cannot delete revision 3 above applied patches
  [255]

  $ hg qdel -r qbase:pe
  patch pd finalized without changeset message
  patch pe finalized without changeset message

  $ hg qapplied
  pf

  $ hg log --template '{rev} {desc}\n'
  4 [mq]: pf
  3 [mq]: pe
  2 [mq]: pd
  1 [mq]: pa
  0 base

  $ cd ..

  $ hg init b
  $ cd b

  $ echo 'base' > base
  $ hg ci -Ambase -d '1 0'
  adding base

  $ hg qfinish
  abort: no revisions specified
  [255]

  $ hg qfinish -a
  no patches applied

  $ hg qnew -d '1 0' pa
  $ hg qnew -d '1 0' pb
  $ hg qnew pc # XXX fails to apply by /usr/bin/patch if we put a date

  $ hg qfinish 0
  abort: revision 0 is not managed
  [255]

  $ hg qfinish pb
  abort: cannot delete revision 2 above applied patches
  [255]

  $ hg qpop
  popping pc
  now at: pb

  $ hg qfinish -a pc
  abort: unknown revision 'pc'
  [10]

  $ hg qpush
  applying pc
  patch pc is empty
  now at: pc

  $ hg qfinish qbase:pb
  patch pa finalized without changeset message
  patch pb finalized without changeset message

  $ hg qapplied
  pc

  $ hg log --template '{rev} {desc}\n'
  3 imported patch pc
  2 [mq]: pb
  1 [mq]: pa
  0 base

  $ hg qfinish -a pc
  patch pc finalized without changeset message

  $ hg qapplied

  $ hg log --template '{rev} {desc}\n'
  3 imported patch pc
  2 [mq]: pb
  1 [mq]: pa
  0 base

  $ ls .hg/patches
  series
  status

qdel -k X && hg qimp -e X used to trigger spurious output with versioned queues

  $ hg init --mq
  $ hg qimport -r 3
  $ hg qpop
  popping imported_patch_pc
  patch queue now empty
  $ hg qdel -k imported_patch_pc
  $ hg qimp -e imported_patch_pc
  adding imported_patch_pc to series file
  $ hg qfinish -a
  no patches applied


resilience to inconsistency: qfinish -a with applied patches not in series

  $ hg qser
  imported_patch_pc
  $ hg qapplied
  $ hg qpush
  applying imported_patch_pc
  patch imported_patch_pc is empty
  now at: imported_patch_pc
  $ echo next >>  base
  $ hg qrefresh -d '1 0'
  $ echo > .hg/patches/series # remove 3.diff from series to confuse mq
  $ hg qfinish -a
  revision 47dfa8501675 refers to unknown patches: imported_patch_pc

more complex state 'both known and unknown patches

  $ echo hip >>  base
  $ hg qnew -f -d '1 0' -m 4 4.diff
  $ echo hop >>  base
  $ hg qnew -f -d '1 0' -m 5 5.diff
  $ echo > .hg/patches/series # remove 4.diff and 5.diff from series to confuse mq
  $ echo hup >>  base
  $ hg qnew -f -d '1 0' -m 6 6.diff
  $ echo pup > base
  $ hg qfinish -a
  warning: uncommitted changes in the working directory
  revision 2b1c98802260 refers to unknown patches: 5.diff
  revision 33a6861311c0 refers to unknown patches: 4.diff

  $ cd ..