Mercurial > hg
annotate tests/test-arbitraryfilectx.t @ 51274:bec6e9c108fd
matchers: use correct method for finding index in vector
The path matcher has an optimization for when all paths are `rootfilesin:`. This
optimization exists in both Python and Rust. However, the Rust implementation
currently has a bug that makes it fail in most cases. The bug is that it
`rfind()` where it was clearly intended to use `rposition()`. This patch fixes
that and adds a test.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Mon, 18 Dec 2023 14:51:20 -0800 |
parents | 42d2b31cee0b |
children |
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 > import filecmp |
37318
9954d0e2ad00
py3: use pycompat.bytestr() intsead of str
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36382
diff
changeset
|
4 > from mercurial import commands, context, pycompat, registrar |
34835
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
5 > cmdtable = {} |
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
6 > command = registrar.command(cmdtable) |
36382
b4d1c09b754b
py3: add missing b'' in test-arbitraryfilectx.t
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35947
diff
changeset
|
7 > @command(b'eval', [], b'hg eval CMD') |
34835
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
8 > def eval_(ui, repo, *cmds, **opts): |
35947
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34936
diff
changeset
|
9 > cmd = b" ".join(cmds) |
37318
9954d0e2ad00
py3: use pycompat.bytestr() intsead of str
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36382
diff
changeset
|
10 > res = pycompat.bytestr(eval(cmd, globals(), locals())) |
35947
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34936
diff
changeset
|
11 > ui.warn(b"%s" % res) |
34835
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
12 > EOF |
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
13 |
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
14 $ echo "[extensions]" >> $HGRCPATH |
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
15 $ 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
|
16 |
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
17 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
|
18 $ mkdir case1 |
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
19 $ cd case1 |
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
20 $ hg init |
34936
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
21 #if symlink |
34835
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" |
34936
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
32 #else |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
33 $ hg import -q --bypass - <<EOF |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
34 > # HG changeset patch |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
35 > # User test |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
36 > # Date 0 0 |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
37 > base |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
38 > |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
39 > diff --git a/A b/A |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
40 > new file mode 100644 |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
41 > --- /dev/null |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
42 > +++ b/A |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
43 > @@ -0,0 +1,1 @@ |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
44 > +foo |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
45 > \ No newline at end of file |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
46 > diff --git a/B b/B |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
47 > new file mode 100644 |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
48 > --- /dev/null |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
49 > +++ b/B |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
50 > @@ -0,0 +1,1 @@ |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
51 > +foo |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
52 > \ No newline at end of file |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
53 > diff --git a/real_A b/real_A |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
54 > new file mode 100644 |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
55 > --- /dev/null |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
56 > +++ b/real_A |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
57 > @@ -0,0 +1,1 @@ |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
58 > +A |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
59 > \ No newline at end of file |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
60 > diff --git a/sym_A b/sym_A |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
61 > new file mode 120000 |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
62 > --- /dev/null |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
63 > +++ b/sym_A |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
64 > @@ -0,0 +1,1 @@ |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
65 > +A |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
66 > \ No newline at end of file |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
67 > EOF |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
68 $ hg up -q |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
69 #endif |
34835
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
70 |
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
71 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
|
72 (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
|
73 for simplicity): |
41334
5361f9ed8a30
py3: fix missing b prefixes in test-arbitraryfilectx.t
Augie Fackler <augie@google.com>
parents:
37318
diff
changeset
|
74 $ hg eval "context.arbitraryfilectx(b'A', repo).cmp(repo[None][b'real_A'])" |
34835
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
75 True (no-eol) |
41334
5361f9ed8a30
py3: fix missing b prefixes in test-arbitraryfilectx.t
Augie Fackler <augie@google.com>
parents:
37318
diff
changeset
|
76 $ hg eval "not filecmp.cmp(b'A', b'real_A')" |
34835
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
77 True (no-eol) |
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
78 |
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
79 These files are identical and should return False (same): |
41334
5361f9ed8a30
py3: fix missing b prefixes in test-arbitraryfilectx.t
Augie Fackler <augie@google.com>
parents:
37318
diff
changeset
|
80 $ hg eval "context.arbitraryfilectx(b'A', repo).cmp(repo[None][b'A'])" |
34835
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
81 False (no-eol) |
41334
5361f9ed8a30
py3: fix missing b prefixes in test-arbitraryfilectx.t
Augie Fackler <augie@google.com>
parents:
37318
diff
changeset
|
82 $ hg eval "context.arbitraryfilectx(b'A', repo).cmp(repo[None][b'B'])" |
34835
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
83 False (no-eol) |
41334
5361f9ed8a30
py3: fix missing b prefixes in test-arbitraryfilectx.t
Augie Fackler <augie@google.com>
parents:
37318
diff
changeset
|
84 $ hg eval "not filecmp.cmp(b'A', b'B')" |
34835
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
85 False (no-eol) |
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
86 |
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
87 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
|
88 the same in the eyes of ``filectx.cmp``, which looks at data only. |
41334
5361f9ed8a30
py3: fix missing b prefixes in test-arbitraryfilectx.t
Augie Fackler <augie@google.com>
parents:
37318
diff
changeset
|
89 $ hg eval "context.arbitraryfilectx(b'real_A', repo).cmp(repo[None][b'sym_A'])" |
34835
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
90 False (no-eol) |
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
91 |
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
92 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
|
93 the symlink to "A", which has different contents. |
34936
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
94 #if symlink |
41334
5361f9ed8a30
py3: fix missing b prefixes in test-arbitraryfilectx.t
Augie Fackler <augie@google.com>
parents:
37318
diff
changeset
|
95 $ hg eval "not filecmp.cmp(b'real_A', b'sym_A')" |
34835
14c87708f432
arbitraryfilecontext: skip the cmp fast path if any side is a symlink
Phil Cohen <phillco@fb.com>
parents:
diff
changeset
|
96 True (no-eol) |
34936
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
97 #else |
41334
5361f9ed8a30
py3: fix missing b prefixes in test-arbitraryfilectx.t
Augie Fackler <augie@google.com>
parents:
37318
diff
changeset
|
98 $ hg eval "not filecmp.cmp(b'real_A', b'sym_A')" |
34936
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
99 False (no-eol) |
9645c2a2bc2a
test-arbitraryfilectx: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
34835
diff
changeset
|
100 #endif |