Mercurial > hg
annotate tests/test-subrepo-missing.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 | d0e21c5fde41 |
children | f73c7b70df68 |
rev | line source |
---|---|
13017
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
1 $ hg init repo |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
2 $ cd repo |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
3 $ hg init subrepo |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
4 $ echo a > subrepo/a |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
5 $ hg -R subrepo ci -Am adda |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
6 adding a |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
7 $ echo 'subrepo = subrepo' > .hgsub |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
8 $ hg ci -Am addsubrepo |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
9 adding .hgsub |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
10 committing subrepository subrepo |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
11 $ echo b > subrepo/b |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
12 $ hg -R subrepo ci -Am addb |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
13 adding b |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
14 $ hg ci -m updatedsub |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
15 committing subrepository subrepo |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
16 |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
17 delete .hgsub and revert it |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
18 |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
19 $ rm .hgsub |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
20 $ hg revert .hgsub |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
21 warning: subrepo spec file .hgsub not found |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
22 |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
23 delete .hgsubstate and revert it |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
24 |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
25 $ rm .hgsubstate |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
26 $ hg revert .hgsubstate |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
27 |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
28 delete .hgsub and update |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
29 |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
30 $ rm .hgsub |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
31 $ hg up 0 |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
32 warning: subrepo spec file .hgsub not found |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
33 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
34 $ hg st |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
35 ! .hgsub |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
36 $ ls subrepo |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
37 a |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
38 |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
39 delete .hgsubstate and update |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
40 |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
41 $ hg up -C |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
42 warning: subrepo spec file .hgsub not found |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
43 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
44 $ rm .hgsubstate |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
45 $ hg up 0 |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
46 remote changed .hgsubstate which local deleted |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
47 use (c)hanged version or leave (d)eleted? c |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
48 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
49 $ hg st |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
50 $ ls subrepo |
d0e21c5fde41
subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
51 a |