tests/test-relink.t
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 48876 42d2b31cee0b
child 51181 dcaa2df1f688
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 hardlink

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

  $ fix_path() {
  >     tr '\\' /
  > }

  $ cat > arelinked.py <<EOF
  > import os
  > import sys
  > from mercurial import (
  >     pycompat,
  >     util,
  > )
  > path1, path2 = sys.argv[1:3]
  > if util.samefile(pycompat.fsencode(path1), pycompat.fsencode(path2)):
  >     print('%s == %s' % (path1, path2))
  > else:
  >     print('%s != %s' % (path1, path2))
  > EOF


create source repository

  $ hg init repo
  $ cd repo
  $ echo a > a
  $ echo b > b
  $ hg ci -Am addfile
  adding a
  adding b
  $ cat "$TESTDIR/binfile.bin" >> a
  $ cat "$TESTDIR/binfile.bin" >> b
  $ hg ci -Am changefiles

make another commit to create files larger than 1 KB to test
formatting of final byte count

  $ cat "$TESTDIR/binfile.bin" >> a
  $ cat "$TESTDIR/binfile.bin" >> b
  $ hg ci -m anotherchange

don't sit forever trying to double-lock the source repo

  $ hg relink .
  relinking $TESTTMP/repo/.hg/store to $TESTTMP/repo/.hg/store
  there is nothing to relink


Test files are read in binary mode

  $ "$PYTHON" -c "open('.hg/store/data/dummy.i', 'wb').write(b'a\r\nb\n')"
  $ cd ..


clone and pull to break links

  $ hg clone --pull -r0 repo clone
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 2 changes to 2 files
  new changesets 008c0c271c47
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ cd clone
  $ hg pull -q
  $ echo b >> b
  $ hg ci -m changeb
  created new head
  $ "$PYTHON" -c "open('.hg/store/data/dummy.i', 'wb').write(b'a\nb\r\n')"


relink

#if no-reposimplestore

  $ hg relink --debug --config progress.debug=true | fix_path
  relinking $TESTTMP/repo/.hg/store to $TESTTMP/clone/.hg/store
  tip has 2 files, estimated total number of files: 3
  collecting: 00changelog.i 1/3 files (33.33%)
  collecting: 00manifest.i 2/3 files (66.67%)
  collecting: a.i 3/3 files (100.00%)
  collecting: b.i 4/3 files (133.33%)
  collecting: dummy.i 5/3 files (166.67%)
  collected 5 candidate storage files
  not linkable: 00changelog.i
  not linkable: 00manifest.i
  pruning: data/a.i 3/5 files (60.00%)
  not linkable: data/b.i
  pruning: data/dummy.i 5/5 files (100.00%)
  pruned down to 2 probably relinkable files
  relinking: data/a.i 1/2 files (50.00%)
  not linkable: data/dummy.i
  relinked 1 files (1.36 KB reclaimed)
  $ cd ..


check hardlinks

  $ "$PYTHON" arelinked.py repo/.hg/store/data/a.i clone/.hg/store/data/a.i
  repo/.hg/store/data/a.i == clone/.hg/store/data/a.i
  $ "$PYTHON" arelinked.py repo/.hg/store/data/b.i clone/.hg/store/data/b.i
  repo/.hg/store/data/b.i != clone/.hg/store/data/b.i

#endif