/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/shelf_ui.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-20 14:27:19 UTC
  • mto: This revision was merged to the branch mainline in revision 5837.
  • Revision ID: john@arbash-meinel.com-20110420142719-advs1k5vztqzbrgv
Fix bug #767177. Be more agressive with file.close() calls.

Our test suite gets a number of thread leaks and failures because it happens to get async
SFTPFile.close() calls. (if an SFTPFile closes due to __del__ it is done as an async request,
while if you call SFTPFile.close() it is done as a synchronous request.)
We have a couple other cases, probably. Namely SFTPTransport.get() also does an async
prefetch of the content, so if you don't .read() you'll also leak threads that think they
are doing work that you want.

The biggest change here, though, is using a try/finally in a generator, which is not 
python2.4 compatible.

Show diffs side-by-side

added added

removed removed

Lines of Context:
154
154
 
155
155
    @classmethod
156
156
    def from_args(klass, diff_writer, revision=None, all=False, file_list=None,
157
 
                  message=None, directory='.', destroy=False):
 
157
                  message=None, directory=None, destroy=False):
158
158
        """Create a shelver from commandline arguments.
159
159
 
160
160
        The returned shelver wil have a work_tree that is locked and should
168
168
        :param destroy: Change the working tree without storing the shelved
169
169
            changes.
170
170
        """
 
171
        if directory is None:
 
172
            directory = u'.'
 
173
        elif file_list:
 
174
            file_list = [osutils.pathjoin(directory, f) for f in file_list]
171
175
        tree, path = workingtree.WorkingTree.open_containing(directory)
172
176
        # Ensure that tree is locked for the lifetime of target_tree, as
173
177
        # target tree may be reading from the same dirstate.
175
179
        try:
176
180
            target_tree = builtins._get_one_revision_tree('shelf2', revision,
177
181
                tree.branch, tree)
178
 
            files = builtins.safe_relpath_files(tree, file_list)
 
182
            files = tree.safe_relpath_files(file_list)
179
183
            return klass(tree, target_tree, diff_writer, all, all, files,
180
184
                         message, destroy)
181
185
        finally:
241
245
            new_tree = self.work_tree
242
246
        old_path = old_tree.id2path(file_id)
243
247
        new_path = new_tree.id2path(file_id)
244
 
        text_differ = diff.DiffText(old_tree, new_tree, diff_file)
 
248
        text_differ = diff.DiffText(old_tree, new_tree, diff_file,
 
249
            path_encoding=osutils.get_terminal_encoding())
245
250
        patch = text_differ.diff(file_id, old_path, new_path, 'file', 'file')
246
251
        diff_file.seek(0)
247
252
        return patches.parse_patch(diff_file)
492
497
        tt = tree_merger.make_preview_transform()
493
498
        new_tree = tt.get_preview_tree()
494
499
        if self.write_diff_to is None:
495
 
            self.write_diff_to = ui.ui_factory.make_output_stream()
496
 
        diff.show_diff_trees(merger.this_tree, new_tree, self.write_diff_to)
 
500
            self.write_diff_to = ui.ui_factory.make_output_stream(encoding_type='exact')
 
501
        path_encoding = osutils.get_diff_header_encoding()
 
502
        diff.show_diff_trees(merger.this_tree, new_tree, self.write_diff_to,
 
503
            path_encoding=path_encoding)
497
504
        tt.finalize()
498
505
 
499
506
    def show_changes(self, merger):