~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shelf_ui.py

  • Committer: John Arbash Meinel
  • Date: 2009-09-02 13:32:52 UTC
  • mfrom: (4634.6.14 2.0)
  • mto: (4634.6.15 2.0)
  • mto: This revision was merged to the branch mainline in revision 4667.
  • Revision ID: john@arbash-meinel.com-20090902133252-t2t94xtckoliv2th
Merge lp:bzr/2.0 to resolve NEWS issues.

Show diffs side-by-side

added added

removed removed

Lines of Context:
149
149
                  message=None, directory='.', destroy=False):
150
150
        """Create a shelver from commandline arguments.
151
151
 
 
152
        The returned shelver wil have a work_tree that is locked and should
 
153
        be unlocked.
 
154
 
152
155
        :param revision: RevisionSpec of the revision to compare to.
153
156
        :param all: If True, shelve all changes without prompting.
154
157
        :param file_list: If supplied, only files in this list may be  shelved.
158
161
            changes.
159
162
        """
160
163
        tree, path = workingtree.WorkingTree.open_containing(directory)
161
 
        target_tree = builtins._get_one_revision_tree('shelf2', revision,
162
 
            tree.branch, tree)
163
 
        files = builtins.safe_relpath_files(tree, file_list)
 
164
        # Ensure that tree is locked for the lifetime of target_tree, as
 
165
        # target tree may be reading from the same dirstate.
 
166
        tree.lock_tree_write()
 
167
        try:
 
168
            target_tree = builtins._get_one_revision_tree('shelf2', revision,
 
169
                tree.branch, tree)
 
170
            files = builtins.safe_relpath_files(tree, file_list)
 
171
        except:
 
172
            tree.unlock()
 
173
            raise
164
174
        return klass(tree, target_tree, diff_writer, all, all, files, message,
165
175
                     destroy)
166
176
 
313
323
    def from_args(klass, shelf_id=None, action='apply', directory='.'):
314
324
        """Create an unshelver from commandline arguments.
315
325
 
 
326
        The returned shelver wil have a tree that is locked and should
 
327
        be unlocked.
 
328
 
316
329
        :param shelf_id: Integer id of the shelf, as a string.
317
330
        :param action: action to perform.  May be 'apply', 'dry-run',
318
331
            'delete'.
319
332
        :param directory: The directory to unshelve changes into.
320
333
        """
321
334
        tree, path = workingtree.WorkingTree.open_containing(directory)
322
 
        manager = tree.get_shelf_manager()
323
 
        if shelf_id is not None:
324
 
            try:
325
 
                shelf_id = int(shelf_id)
326
 
            except ValueError:
327
 
                raise errors.InvalidShelfId(shelf_id)
328
 
        else:
329
 
            shelf_id = manager.last_shelf()
330
 
            if shelf_id is None:
331
 
                raise errors.BzrCommandError('No changes are shelved.')
332
 
            trace.note('Unshelving changes with id "%d".' % shelf_id)
333
 
        apply_changes = True
334
 
        delete_shelf = True
335
 
        read_shelf = True
336
 
        if action == 'dry-run':
337
 
            apply_changes = False
338
 
            delete_shelf = False
339
 
        if action == 'delete-only':
340
 
            apply_changes = False
341
 
            read_shelf = False
 
335
        tree.lock_tree_write()
 
336
        try:
 
337
            manager = tree.get_shelf_manager()
 
338
            if shelf_id is not None:
 
339
                try:
 
340
                    shelf_id = int(shelf_id)
 
341
                except ValueError:
 
342
                    raise errors.InvalidShelfId(shelf_id)
 
343
            else:
 
344
                shelf_id = manager.last_shelf()
 
345
                if shelf_id is None:
 
346
                    raise errors.BzrCommandError('No changes are shelved.')
 
347
                trace.note('Unshelving changes with id "%d".' % shelf_id)
 
348
            apply_changes = True
 
349
            delete_shelf = True
 
350
            read_shelf = True
 
351
            if action == 'dry-run':
 
352
                apply_changes = False
 
353
                delete_shelf = False
 
354
            if action == 'delete-only':
 
355
                apply_changes = False
 
356
                read_shelf = False
 
357
        except:
 
358
            tree.unlock()
 
359
            raise
342
360
        return klass(tree, manager, shelf_id, apply_changes, delete_shelf,
343
361
                     read_shelf)
344
362
 
364
382
 
365
383
    def run(self):
366
384
        """Perform the unshelving operation."""
367
 
        self.tree.lock_write()
 
385
        self.tree.lock_tree_write()
368
386
        cleanups = [self.tree.unlock]
369
387
        try:
370
388
            if self.read_shelf: