annotate tests/test-commit-copy.t @ 14007:d764463b433e

atomictempfile: avoid infinite recursion in __del__(). The problem is that a programmer using atomictempfile directly can make an innocent everyday mistake -- not enough args to the constructor -- which escalates badly. You would expect a simple TypeError crash in that case, but you actually get an infinite recursion that is surprisingly difficult to kill: it happens between __del__() and __getattr__(), and Python does not handle infinite recursion from __del__() well. The fix is to not implement __getattr__(), but instead assign instance attributes for the methods we wish to delegate to the builtin file type: write() and fileno(). I've audited mercurial.* and hgext.* and found no users of atomictempfile using methods other than write() and rename(). I audited third-party extensions and found one (snap) passing an atomictempfile to util.fstat(), so I also threw in fileno(). The last time I submitted a similar patch, Matt proposed that we make atomictempfile a subclass of file instead of wrapping it. Rejected on grounds of unnecessary complexity: for one thing, it would make the Windows implementation of posixfile quite a bit more complex. It would have to become a subclass of file rather than a simple function -- but since it's written in C, this is non-obvious and non-trivial. Furthermore, there's nothing wrong with wrapping objects and delegating methods: it's a well-established pattern that works just fine in many cases. Subclassing is not the answer to all of life's problems.
author Greg Ward <greg@gerg.ca>
date Sun, 24 Apr 2011 19:25:10 -0400
parents b90199179eb5
children ec5886db9dc6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11803
b90199179eb5 unify test-commit-copy
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 3853
diff changeset
1 $ hg init dir
b90199179eb5 unify test-commit-copy
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 3853
diff changeset
2 $ cd dir
b90199179eb5 unify test-commit-copy
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 3853
diff changeset
3 $ echo bleh > bar
b90199179eb5 unify test-commit-copy
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 3853
diff changeset
4 $ hg add bar
b90199179eb5 unify test-commit-copy
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 3853
diff changeset
5 $ hg ci -m 'add bar'
3675
6990e499d71a Revert almost all of 5be434785317; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
6
11803
b90199179eb5 unify test-commit-copy
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 3853
diff changeset
7 $ hg cp bar foo
b90199179eb5 unify test-commit-copy
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 3853
diff changeset
8 $ echo >> bar
b90199179eb5 unify test-commit-copy
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 3853
diff changeset
9 $ hg ci -m 'cp bar foo; change bar'
3675
6990e499d71a Revert almost all of 5be434785317; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
10
11803
b90199179eb5 unify test-commit-copy
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 3853
diff changeset
11 $ hg debugrename foo
b90199179eb5 unify test-commit-copy
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 3853
diff changeset
12 foo renamed from bar:26d3ca0dfd18e44d796b564e38dd173c9668d3a9
b90199179eb5 unify test-commit-copy
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 3853
diff changeset
13 $ hg debugindex .hg/store/data/bar.i
b90199179eb5 unify test-commit-copy
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 3853
diff changeset
14 rev offset length base linkrev nodeid p1 p2
b90199179eb5 unify test-commit-copy
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 3853
diff changeset
15 0 0 6 0 0 26d3ca0dfd18 000000000000 000000000000
b90199179eb5 unify test-commit-copy
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 3853
diff changeset
16 1 6 7 1 1 d267bddd54f7 26d3ca0dfd18 000000000000