annotate tests/test-nested-repo.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 93452579df9e
children 9910f60a37ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
1 $ hg init a
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
2 $ cd a
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
3 $ hg init b
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
4 $ echo x > b/x
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
5
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
6 Should print nothing:
2061
5987c1eac2ce support nested repositories.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
7
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
8 $ hg add b
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
9 $ hg st
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
10
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
11 Should fail:
5158
d316124ebbea Make audit_path more stringent.
Bryan O'Sullivan <bos@serpentine.com>
parents: 2982
diff changeset
12
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
13 $ hg st b/x
13910
93452579df9e audit: improve nested repo message
Matt Mackall <mpm@selenic.com>
parents: 12316
diff changeset
14 abort: path 'b/x' is inside nested repo 'b'
12316
4134686b83e1 tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 12279
diff changeset
15 [255]
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
16 $ hg add b/x
13910
93452579df9e audit: improve nested repo message
Matt Mackall <mpm@selenic.com>
parents: 12316
diff changeset
17 abort: path 'b/x' is inside nested repo 'b'
12316
4134686b83e1 tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 12279
diff changeset
18 [255]
5158
d316124ebbea Make audit_path more stringent.
Bryan O'Sullivan <bos@serpentine.com>
parents: 2982
diff changeset
19
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
20 Should fail:
2061
5987c1eac2ce support nested repositories.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
21
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
22 $ hg add b b/x
13910
93452579df9e audit: improve nested repo message
Matt Mackall <mpm@selenic.com>
parents: 12316
diff changeset
23 abort: path 'b/x' is inside nested repo 'b'
12316
4134686b83e1 tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 12279
diff changeset
24 [255]
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
25 $ hg st
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
26
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
27 Should arguably print nothing:
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
28
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
29 $ hg st b
5200
c7e8fe11f34a path_auditor: cache names of audited directories
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5158
diff changeset
30
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
31 $ echo a > a
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
32 $ hg ci -Ama a
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
33
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
34 Should fail:
5158
d316124ebbea Make audit_path more stringent.
Bryan O'Sullivan <bos@serpentine.com>
parents: 2982
diff changeset
35
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
36 $ hg mv a b
13910
93452579df9e audit: improve nested repo message
Matt Mackall <mpm@selenic.com>
parents: 12316
diff changeset
37 abort: path 'b/a' is inside nested repo 'b'
12316
4134686b83e1 tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 12279
diff changeset
38 [255]
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 5200
diff changeset
39 $ hg st
5158
d316124ebbea Make audit_path more stringent.
Bryan O'Sullivan <bos@serpentine.com>
parents: 2982
diff changeset
40