tests/test-arbitraryfilectx.t
author Paul Morelle <paul.morelle@octobus.net>
Wed, 18 Oct 2017 09:07:48 +0200
changeset 34881 8c9b08a0c48c
parent 34835 14c87708f432
child 34936 9645c2a2bc2a
permissions -rw-r--r--
sparse-read: skip gaps too small to be worth splitting Splitting at too small gaps might not be worthwhile. With this changeset, we stop considering splitting on too small gaps. The threshold is configurable. We arbitrarily pick 256K as a default value because it seems "okay". Further testing on various repositories and setups will be needed to tune it. The option name is 'experimental.sparse-read.min-gap-size`, and replaces `experimental.sparse-read.min-block-size` which is not used any more.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34835
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
     1
Setup:
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
     2
  $ cat > eval.py <<EOF
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
     3
  > from __future__ import absolute_import
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
     4
  > import filecmp
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
     5
  > from mercurial import commands, context, registrar
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
     6
  > cmdtable = {}
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
     7
  > command = registrar.command(cmdtable)
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
     8
  > @command(b'eval', [], 'hg eval CMD')
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
     9
  > def eval_(ui, repo, *cmds, **opts):
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    10
  >     cmd = " ".join(cmds)
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    11
  >     res = str(eval(cmd, globals(), locals()))
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    12
  >     ui.warn("%s" % res)
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    13
  > EOF
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    14
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    15
  $ echo "[extensions]" >> $HGRCPATH
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    16
  $ echo "eval=`pwd`/eval.py" >> $HGRCPATH
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    17
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    18
Arbitraryfilectx.cmp does not follow symlinks:
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    19
  $ mkdir case1
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    20
  $ cd case1
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    21
  $ hg init
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    22
  $ printf "A" > real_A
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    23
  $ printf "foo" > A
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    24
  $ printf "foo" > B
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    25
  $ ln -s A sym_A
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    26
  $ hg add .
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    27
  adding A
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    28
  adding B
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    29
  adding real_A
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    30
  adding sym_A
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    31
  $ hg commit -m "base"
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    32
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    33
These files are different and should return True (different):
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    34
(Note that filecmp.cmp's return semantics are inverted from ours, so we invert
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    35
for simplicity):
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    36
  $ hg eval "context.arbitraryfilectx('A', repo).cmp(repo[None]['real_A'])"
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    37
  True (no-eol)
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    38
  $ hg eval "not filecmp.cmp('A', 'real_A')"
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    39
  True (no-eol)
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    40
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    41
These files are identical and should return False (same):
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    42
  $ hg eval "context.arbitraryfilectx('A', repo).cmp(repo[None]['A'])"
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    43
  False (no-eol)
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    44
  $ hg eval "context.arbitraryfilectx('A', repo).cmp(repo[None]['B'])"
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    45
  False (no-eol)
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    46
  $ hg eval "not filecmp.cmp('A', 'B')"
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    47
  False (no-eol)
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    48
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    49
This comparison should also return False, since A and sym_A are substantially
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    50
the same in the eyes of ``filectx.cmp``, which looks at data only.
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    51
  $ hg eval "context.arbitraryfilectx('real_A', repo).cmp(repo[None]['sym_A'])"
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    52
  False (no-eol)
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    53
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    54
A naive use of filecmp on those two would wrongly return True, since it follows
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    55
the symlink to "A", which has different contents.
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    56
  $ hg eval "not filecmp.cmp('real_A', 'sym_A')"
14c87708f432 arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff changeset
    57
  True (no-eol)