=== trac/versioncontrol/svn_fs.py
==================================================================
|
|
|
|
| 61 | 61 | Instances of this type return their associated `pool when called. |
| 62 | 62 | """ |
| 63 | 63 | |
| 64 | | def __init__(self, parent, parent_pool=lambda: None): |
| | 64 | def __init__(self, parent, parent_pool=None): |
| 65 | 65 | """ |
| 66 | 66 | Create a new pool that is a sub-pool of `parent_pool`, and arrange for |
| 67 | | `self.close` to be called up when the `parent` object is destroyed. |
| | 67 | `self._close` to be called up when the `parent` object is destroyed. |
| 68 | 68 | |
| 69 | 69 | The `parent` object must be weak-referenceable. The returned `Pool` |
| 70 | 70 | instance will have the value of the newly created pool. |
| 71 | 71 | """ |
| 72 | | self.pool = core.svn_pool_create(parent_pool()) |
| 73 | | self.children = [] |
| | 72 | self._parent_pool = parent_pool |
| | 73 | self._children = [] |
| | 74 | self._waiting_to_close = False |
| 74 | 75 | |
| 75 | | if parent_pool(): |
| 76 | | parent_pool.children.append(self) |
| | 76 | if self._parent_pool: |
| | 77 | self._pool = core.svn_pool_create(self._parent_pool()) |
| | 78 | self._parent_pool._children.append(self) |
| | 79 | else: |
| | 80 | self._pool = core.svn_pool_create(None) |
| 77 | 81 | |
| 78 | 82 | try: |
| 79 | | parent._pool_closer = weakref.ref(parent, self.close) |
| | 83 | parent._pool_closer = weakref.ref(parent, self._close) |
| 80 | 84 | except TypeError: |
| 81 | | self.close(None) |
| | 85 | self._close(None) |
| 82 | 86 | raise |
| 83 | 87 | |
| 84 | 88 | def __call__(self): |
| 85 | | return self.pool |
| | 89 | return self._pool |
| 86 | 90 | |
| 87 | | def close(self, x): |
| | 91 | def _child_closed(self, child): |
| | 92 | self._children.remove(child) |
| | 93 | if self._waiting_to_close: |
| | 94 | self._close(x) |
| | 95 | |
| | 96 | def _close(self, x): |
| 88 | 97 | """ |
| 89 | 98 | The parent object has been destroyed so it is time for us to go. |
| 90 | 99 | |
| | 100 | If we still have children that are alive, we do not clean up just |
| | 101 | yet. This would lead to their memory being freed from under them. |
| | 102 | Instead, we wait for our child to notify us that they have been |
| | 103 | closed and clean up then. |
| | 104 | |
| 91 | 105 | -- So long, and thanks for all the fish! |
| 92 | 106 | """ |
| 93 | | if not self.pool: |
| | 107 | assert self._pool |
| | 108 | |
| | 109 | if self._children: |
| | 110 | self._waiting_to_close = True |
| 94 | 111 | return |
| 95 | 112 | |
| 96 | | while self.children: |
| 97 | | self.children.pop().close(None) |
| | 113 | core.svn_pool_destroy(self._pool) |
| | 114 | self._pool = None |
| 98 | 115 | |
| 99 | | core.svn_pool_destroy(self.pool) |
| 100 | | self.pool = None |
| | 116 | if self._parent_pool: |
| | 117 | self._parent_pool._child_closed(self) |
| | 118 | self._parent_pool = None |
| 101 | 119 | |
| 102 | 120 | |
| 103 | 121 | class SubversionRepository(Repository): |