tests/test-rhg-sparse-narrow.t
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 48409 005ae1a343f8
child 49485 ffd4b1f1c9cb
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.

#require rhg

  $ NO_FALLBACK="env RHG_ON_UNSUPPORTED=abort"

Rhg works well when sparse working copy is enabled.

  $ cd "$TESTTMP"
  $ hg init repo-sparse
  $ cd repo-sparse
  $ cat > .hg/hgrc <<EOF
  > [extensions]
  > sparse=
  > EOF

  $ echo a > show
  $ echo x > hide
  $ mkdir dir1 dir2
  $ echo x > dir1/x
  $ echo y > dir1/y
  $ echo z > dir2/z

  $ hg ci -Aqm 'initial'
  $ hg debugsparse --include 'show'
  $ ls -A
  .hg
  show

  $ tip=$(hg log -r . --template '{node}')
  $ $NO_FALLBACK rhg files -r "$tip"
  dir1/x
  dir1/y
  dir2/z
  hide
  show
  $ $NO_FALLBACK rhg files
  show

  $ $NO_FALLBACK rhg cat -r "$tip" hide
  x

  $ cd ..

We support most things when narrow is enabled, too, with a couple of caveats.

  $ . "$TESTDIR/narrow-library.sh"
  $ real_hg=$RHG_FALLBACK_EXECUTABLE

  $ cat >> $HGRCPATH <<EOF
  > [extensions]
  > narrow=
  > EOF

  $ hg clone --narrow  ./repo-sparse repo-narrow --include dir1
  requesting all changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  new changesets 6d714a4a2998
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved

  $ cd repo-narrow

  $ $NO_FALLBACK rhg cat -r "$tip" dir1/x
  x
  $ "$real_hg" cat -r "$tip" dir1/x
  x

TODO: bad error message

  $ $NO_FALLBACK rhg cat -r "$tip" hide
  abort: invalid revision identifier: 6d714a4a2998cbfd0620db44da58b749f6565d63
  [255]
  $ "$real_hg" cat -r "$tip" hide
  [1]

A naive implementation of [rhg files] leaks the paths that are supposed to be
hidden by narrow, so we just fall back to hg.

  $ $NO_FALLBACK rhg files -r "$tip"
  unsupported feature: rhg files -r <rev> is not supported in narrow clones
  [252]
  $ "$real_hg" files -r "$tip"
  dir1/x
  dir1/y

Hg status needs to do some filtering based on narrow spec, so we don't
support it in rhg for narrow clones yet.

  $ mkdir dir2
  $ touch dir2/q
  $ "$real_hg" status
  $ $NO_FALLBACK rhg --config rhg.status=true status
  unsupported feature: rhg status is not supported for sparse checkouts or narrow clones yet
  [252]

Adding "orphaned" index files:

  $ (cd ..; cp repo-sparse/.hg/store/data/hide.i repo-narrow/.hg/store/data/hide.i)
  $ (cd ..; mkdir repo-narrow/.hg/store/data/dir2; cp repo-sparse/.hg/store/data/dir2/z.i repo-narrow/.hg/store/data/dir2/z.i)
  $ "$real_hg" verify
  checking changesets
  checking manifests
  crosschecking files in changesets and manifests
  checking files
  checked 1 changesets with 2 changes to 2 files

  $ "$real_hg" files -r "$tip"
  dir1/x
  dir1/y

# TODO: even though [hg files] hides the orphaned dir2/z, [hg cat] still shows it.
# rhg has the same issue, but at least it's not specific to rhg.
# This is despite [hg verify] succeeding above.

  $ $NO_FALLBACK rhg cat -r "$tip" dir2/z
  z
  $ "$real_hg" cat -r "$tip" dir2/z
  z