| 1 |
Setup: |
| 2 |
$ cat > eval.py <<EOF |
| 3 |
> import filecmp |
| 4 |
> from mercurial import commands, context, pycompat, registrar |
| 5 |
> cmdtable = {} |
| 6 |
> command = registrar.command(cmdtable) |
| 7 |
> @command(b'eval', [], b'hg eval CMD') |
| 8 |
> def eval_(ui, repo, *cmds, **opts): |
| 9 |
> cmd = b" ".join(cmds) |
| 10 |
> res = pycompat.bytestr(eval(cmd, globals(), locals())) |
| 11 |
> ui.warn(b"%s" % res) |
| 12 |
> EOF |
| 13 |
|
| 14 |
$ echo "[extensions]" >> $HGRCPATH |
| 15 |
$ echo "eval=`pwd`/eval.py" >> $HGRCPATH |
| 16 |
|
| 17 |
Arbitraryfilectx.cmp does not follow symlinks: |
| 18 |
$ mkdir case1 |
| 19 |
$ cd case1 |
| 20 |
$ hg init |
| 21 |
#if symlink |
| 22 |
$ printf "A" > real_A |
| 23 |
$ printf "foo" > A |
| 24 |
$ printf "foo" > B |
| 25 |
$ ln -s A sym_A |
| 26 |
$ hg add . |
| 27 |
adding A |
| 28 |
adding B |
| 29 |
adding real_A |
| 30 |
adding sym_A |
| 31 |
$ hg commit -m "base" |
| 32 |
#else |
| 33 |
$ hg import -q --bypass - <<EOF |
| 34 |
> # HG changeset patch |
| 35 |
> # User test |
| 36 |
> # Date 0 0 |
| 37 |
> base |
| 38 |
> |
| 39 |
> diff --git a/A b/A |
| 40 |
> new file mode 100644 |
| 41 |
> --- /dev/null |
| 42 |
> +++ b/A |
| 43 |
> @@ -0,0 +1,1 @@ |
| 44 |
> +foo |
| 45 |
> \ No newline at end of file |
| 46 |
> diff --git a/B b/B |
| 47 |
> new file mode 100644 |
| 48 |
> --- /dev/null |
| 49 |
> +++ b/B |
| 50 |
> @@ -0,0 +1,1 @@ |
| 51 |
> +foo |
| 52 |
> \ No newline at end of file |
| 53 |
> diff --git a/real_A b/real_A |
| 54 |
> new file mode 100644 |
| 55 |
> --- /dev/null |
| 56 |
> +++ b/real_A |
| 57 |
> @@ -0,0 +1,1 @@ |
| 58 |
> +A |
| 59 |
> \ No newline at end of file |
| 60 |
> diff --git a/sym_A b/sym_A |
| 61 |
> new file mode 120000 |
| 62 |
> --- /dev/null |
| 63 |
> +++ b/sym_A |
| 64 |
> @@ -0,0 +1,1 @@ |
| 65 |
> +A |
| 66 |
> \ No newline at end of file |
| 67 |
> EOF |
| 68 |
$ hg up -q |
| 69 |
#endif |
| 70 |
|
| 71 |
These files are different and should return True (different): |
| 72 |
(Note that filecmp.cmp's return semantics are inverted from ours, so we invert |
| 73 |
for simplicity): |
| 74 |
$ hg eval "context.arbitraryfilectx(b'A', repo).cmp(repo[None][b'real_A'])" |
| 75 |
True (no-eol) |
| 76 |
$ hg eval "not filecmp.cmp(b'A', b'real_A')" |
| 77 |
True (no-eol) |
| 78 |
|
| 79 |
These files are identical and should return False (same): |
| 80 |
$ hg eval "context.arbitraryfilectx(b'A', repo).cmp(repo[None][b'A'])" |
| 81 |
False (no-eol) |
| 82 |
$ hg eval "context.arbitraryfilectx(b'A', repo).cmp(repo[None][b'B'])" |
| 83 |
False (no-eol) |
| 84 |
$ hg eval "not filecmp.cmp(b'A', b'B')" |
| 85 |
False (no-eol) |
| 86 |
|
| 87 |
This comparison should also return False, since A and sym_A are substantially |
| 88 |
the same in the eyes of ``filectx.cmp``, which looks at data only. |
| 89 |
$ hg eval "context.arbitraryfilectx(b'real_A', repo).cmp(repo[None][b'sym_A'])" |
| 90 |
False (no-eol) |
| 91 |
|
| 92 |
A naive use of filecmp on those two would wrongly return True, since it follows |
| 93 |
the symlink to "A", which has different contents. |
| 94 |
#if symlink |
| 95 |
$ hg eval "not filecmp.cmp(b'real_A', b'sym_A')" |
| 96 |
True (no-eol) |
| 97 |
#else |
| 98 |
$ hg eval "not filecmp.cmp(b'real_A', b'sym_A')" |
| 99 |
False (no-eol) |
| 100 |
#endif |