annotate tests/test-arbitraryfilectx.t @ 34932:fd78276948b4 stable

internal-doc: document the config register mechanism This explains the various usage and feature of the config register introduced in Mercurial 4.3 and 4.4.
author Boris Feld <boris.feld@octobus.net>
date Fri, 27 Oct 2017 18:19:07 +0200
parents 14c87708f432
children 9645c2a2bc2a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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)