Mercurial > hg
annotate tests/test-share.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 | 6cc4b14fb76b |
children | 574dc5d74f9b |
rev | line source |
---|---|
9990 | 1 |
12487 | 2 $ echo "[extensions]" >> $HGRCPATH |
3 $ echo "share = " >> $HGRCPATH | |
4 | |
5 prepare repo1 | |
9990 | 6 |
12487 | 7 $ hg init repo1 |
8 $ cd repo1 | |
9 $ echo a > a | |
10 $ hg commit -A -m'init' | |
11 adding a | |
12 | |
13 share it | |
9990 | 14 |
12487 | 15 $ cd .. |
16 $ hg share repo1 repo2 | |
17 updating working directory | |
18 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
19 | |
20 share shouldn't have a store dir | |
21 | |
22 $ cd repo2 | |
23 $ test -d .hg/store | |
24 [1] | |
9990 | 25 |
12487 | 26 Some sed versions appends newline, some don't, and some just fails |
27 | |
28 $ cat .hg/sharedpath; echo | |
12640
6cc4b14fb76b
tests: remove redundant globs
Mads Kiilerich <mads@kiilerich.com>
parents:
12487
diff
changeset
|
29 $TESTTMP/repo1/.hg |
12487 | 30 |
31 commit in shared clone | |
32 | |
33 $ echo a >> a | |
34 $ hg commit -m'change in shared clone' | |
35 | |
36 check original | |
9990 | 37 |
12487 | 38 $ cd ../repo1 |
39 $ hg log | |
40 changeset: 1:8af4dc49db9e | |
41 tag: tip | |
42 user: test | |
43 date: Thu Jan 01 00:00:00 1970 +0000 | |
44 summary: change in shared clone | |
45 | |
46 changeset: 0:d3873e73d99e | |
47 user: test | |
48 date: Thu Jan 01 00:00:00 1970 +0000 | |
49 summary: init | |
50 | |
51 $ hg update | |
52 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
53 $ cat a # should be two lines of "a" | |
54 a | |
55 a | |
9990 | 56 |
12487 | 57 commit in original |
58 | |
59 $ echo b > b | |
60 $ hg commit -A -m'another file' | |
61 adding b | |
62 | |
63 check in shared clone | |
9990 | 64 |
12487 | 65 $ cd ../repo2 |
66 $ hg log | |
67 changeset: 2:c2e0ac586386 | |
68 tag: tip | |
69 user: test | |
70 date: Thu Jan 01 00:00:00 1970 +0000 | |
71 summary: another file | |
72 | |
73 changeset: 1:8af4dc49db9e | |
74 user: test | |
75 date: Thu Jan 01 00:00:00 1970 +0000 | |
76 summary: change in shared clone | |
77 | |
78 changeset: 0:d3873e73d99e | |
79 user: test | |
80 date: Thu Jan 01 00:00:00 1970 +0000 | |
81 summary: init | |
82 | |
83 $ hg update | |
84 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
85 $ cat b # should exist with one "b" | |
86 b | |
9990 | 87 |
12487 | 88 hg serve shared clone |
9990 | 89 |
12487 | 90 $ hg serve -n test -p $HGPORT -d --pid-file=hg.pid |
91 $ cat hg.pid >> $DAEMON_PIDS | |
92 $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/raw-file/' | |
93 200 Script output follows | |
94 | |
95 | |
96 -rw-r--r-- 4 a | |
97 -rw-r--r-- 2 b | |
98 | |
99 |