Rev 4955: (salgado) bug # 308122, Implement 'bzr unshelve --preview' in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Jan 13 00:25:51 GMT 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4955 [merge]
revision-id: pqm at pqm.ubuntu.com-20100113002544-mztf6nwrfgqienjc
parent: pqm at pqm.ubuntu.com-20100112215001-mu2pjccnxb01p3u1
parent: john at arbash-meinel.com-20100112225506-az9qfhq4akbrr8jr
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2010-01-13 00:25:44 +0000
message:
(salgado) bug # 308122, Implement 'bzr unshelve --preview'
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/shelf_ui.py shelver.py-20081005210102-33worgzwrtdw0yrm-1
bzrlib/tests/test_shelf_ui.py test_shelf_ui.py-20081027155203-wtcuazg85wp9u4fv-1
=== modified file 'NEWS'
--- a/NEWS 2010-01-12 21:08:30 +0000
+++ b/NEWS 2010-01-13 00:25:44 +0000
@@ -23,6 +23,10 @@
* ``bzr branch`` now takes a ``--bind`` option. This lets you
branch and bind all in one command. (Ian Clatworthy)
+* ``bzr unshelve --preview`` can now be used to show how a patch on the
+ shelf would be applied to the working tree.
+ (Guilherme Salgado, #308122)
+
* ``bzr update`` now takes a ``--revision`` argument. This lets you
change the revision of the working tree to any revision in the
ancestry of the current or master branch. (Matthieu Moy, Mark Hammond,
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2010-01-12 09:05:11 +0000
+++ b/bzrlib/builtins.py 2010-01-12 22:36:23 +0000
@@ -5751,6 +5751,8 @@
enum_switch=False, value_switches=True,
apply="Apply changes and remove from the shelf.",
dry_run="Show changes, but do not apply or remove them.",
+ preview="Instead of unshelving the changes, show the diff that "
+ "would result from unshelving.",
delete_only="Delete changes without applying them.",
keep="Apply changes but don't delete them.",
)
=== modified file 'bzrlib/shelf_ui.py'
--- a/bzrlib/shelf_ui.py 2009-12-15 17:57:26 +0000
+++ b/bzrlib/shelf_ui.py 2010-01-12 22:51:31 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2008 Canonical Ltd
+# Copyright (C) 2008, 2009, 2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -22,7 +22,6 @@
from bzrlib import (
builtins,
- commands,
delta,
diff,
errors,
@@ -383,16 +382,18 @@
"""Unshelve changes into a working tree."""
@classmethod
- def from_args(klass, shelf_id=None, action='apply', directory='.'):
+ def from_args(klass, shelf_id=None, action='apply', directory='.',
+ write_diff_to=None):
"""Create an unshelver from commandline arguments.
- The returned shelver wil have a tree that is locked and should
+ The returned shelver will have a tree that is locked and should
be unlocked.
:param shelf_id: Integer id of the shelf, as a string.
:param action: action to perform. May be 'apply', 'dry-run',
- 'delete'.
+ 'delete', 'preview'.
:param directory: The directory to unshelve changes into.
+ :param write_diff_to: See Unshelver.__init__().
"""
tree, path = workingtree.WorkingTree.open_containing(directory)
tree.lock_tree_write()
@@ -410,9 +411,14 @@
apply_changes = True
delete_shelf = True
read_shelf = True
+ show_diff = False
if action == 'dry-run':
apply_changes = False
delete_shelf = False
+ elif action == 'preview':
+ apply_changes = False
+ delete_shelf = False
+ show_diff = True
elif action == 'delete-only':
apply_changes = False
read_shelf = False
@@ -423,10 +429,11 @@
tree.unlock()
raise
return klass(tree, manager, shelf_id, apply_changes, delete_shelf,
- read_shelf)
+ read_shelf, show_diff, write_diff_to)
def __init__(self, tree, manager, shelf_id, apply_changes=True,
- delete_shelf=True, read_shelf=True):
+ delete_shelf=True, read_shelf=True, show_diff=False,
+ write_diff_to=None):
"""Constructor.
:param tree: The working tree to unshelve into.
@@ -436,6 +443,11 @@
working tree.
:param delete_shelf: If True, delete the changes from the shelf.
:param read_shelf: If True, read the changes from the shelf.
+ :param show_diff: If True, show the diff that would result from
+ unshelving the changes.
+ :param write_diff_to: A file-like object where the diff will be
+ written to. If None, ui.ui_factory.make_output_stream() will
+ be used.
"""
self.tree = tree
manager = tree.get_shelf_manager()
@@ -444,6 +456,8 @@
self.apply_changes = apply_changes
self.delete_shelf = delete_shelf
self.read_shelf = read_shelf
+ self.show_diff = show_diff
+ self.write_diff_to = write_diff_to
def run(self):
"""Perform the unshelving operation."""
@@ -463,6 +477,8 @@
merger.change_reporter = change_reporter
if self.apply_changes:
merger.do_merge()
+ elif self.show_diff:
+ self.write_diff(merger)
else:
self.show_changes(merger)
finally:
@@ -474,6 +490,16 @@
for cleanup in reversed(cleanups):
cleanup()
+ def write_diff(self, merger):
+ """Write this operation's diff to self.write_diff_to."""
+ tree_merger = merger.make_merger()
+ tt = tree_merger.make_preview_transform()
+ new_tree = tt.get_preview_tree()
+ if self.write_diff_to is None:
+ self.write_diff_to = ui.ui_factory.make_output_stream()
+ diff.show_diff_trees(merger.this_tree, new_tree, self.write_diff_to)
+ tt.finalize()
+
def show_changes(self, merger):
"""Show the changes that this operation specifies."""
tree_merger = merger.make_merger()
=== modified file 'bzrlib/tests/test_shelf_ui.py'
--- a/bzrlib/tests/test_shelf_ui.py 2009-12-16 15:56:25 +0000
+++ b/bzrlib/tests/test_shelf_ui.py 2010-01-12 22:36:23 +0000
@@ -18,6 +18,7 @@
from cStringIO import StringIO
import os
import sys
+from textwrap import dedent
from bzrlib import (
errors,
@@ -504,6 +505,38 @@
self.assertFileEqual(LINES_AJ, 'tree/foo')
self.assertEqual(1, tree.get_shelf_manager().last_shelf())
+ def test_unshelve_args_preview(self):
+ tree = self.create_tree_with_shelf()
+ write_diff_to = StringIO()
+ unshelver = shelf_ui.Unshelver.from_args(
+ directory='tree', action='preview', write_diff_to=write_diff_to)
+ try:
+ unshelver.run()
+ finally:
+ unshelver.tree.unlock()
+ # The changes were not unshelved.
+ self.assertFileEqual(LINES_AJ, 'tree/foo')
+ self.assertEqual(1, tree.get_shelf_manager().last_shelf())
+
+ # But the diff was written to write_diff_to.
+ diff = write_diff_to.getvalue()
+ expected = dedent("""\
+ @@ -1,4 +1,4 @@
+ -a
+ +z
+ b
+ c
+ d
+ @@ -7,4 +7,4 @@
+ g
+ h
+ i
+ -j
+ +y
+
+ """)
+ self.assertEqualDiff(expected, diff[-len(expected):])
+
def test_unshelve_args_delete_only(self):
tree = self.make_branch_and_tree('tree')
manager = tree.get_shelf_manager()
More information about the bazaar-commits
mailing list