Rev 4733: (garyvdm) Make diff.get_trees_and_branches_to_diff a public API in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Oct 8 18:26:38 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4733 [merge]
revision-id: pqm at pqm.ubuntu.com-20091008172636-tygnfi5hsnn9203g
parent: pqm at pqm.ubuntu.com-20091008031135-6d7vxh4s0umav1eo
parent: v.ladeuil+lp at free.fr-20091008163243-ub35bqc4k53d3ihp
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-10-08 18:26:36 +0100
message:
(garyvdm) Make diff.get_trees_and_branches_to_diff a public API
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/diff.py diff.py-20050309040759-26944fbbf2ebbf36
bzrlib/tests/test_diff.py testdiff.py-20050727164403-d1a3496ebb12e339
=== modified file 'NEWS'
--- a/NEWS 2009-10-08 01:55:33 +0000
+++ b/NEWS 2009-10-08 16:15:00 +0000
@@ -180,6 +180,10 @@
* ``bzrlib.tests`` now uses ``stopTestRun`` for its ``TestResult``
subclasses - the same as python's unittest module. (Robert Collins)
+
+* ``diff._get_trees_to_diff`` has been renamed to
+ ``diff.get_trees_and_branches_to_diff``. It is now a public API, and it
+ returns the old and new branches. (Gary van der Merwe)
* ``bzrlib.trace.log_error``, ``error`` and ``info`` have been deprecated.
(Martin Pool)
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2009-10-06 19:42:23 +0000
+++ b/bzrlib/builtins.py 2009-10-08 16:32:43 +0000
@@ -1885,7 +1885,7 @@
@display_command
def run(self, revision=None, file_list=None, diff_options=None,
prefix=None, old=None, new=None, using=None):
- from bzrlib.diff import _get_trees_to_diff, show_diff_trees
+ from bzrlib.diff import get_trees_and_branches_to_diff, show_diff_trees
if (prefix is None) or (prefix == '0'):
# diff -p0 format
@@ -1905,9 +1905,10 @@
raise errors.BzrCommandError('bzr diff --revision takes exactly'
' one or two revision specifiers')
- old_tree, new_tree, specific_files, extra_trees = \
- _get_trees_to_diff(file_list, revision, old, new,
- apply_view=True)
+ (old_tree, new_tree,
+ old_branch, new_branch,
+ specific_files, extra_trees) = get_trees_and_branches_to_diff(
+ file_list, revision, old, new, apply_view=True)
return show_diff_trees(old_tree, new_tree, sys.stdout,
specific_files=specific_files,
external_diff_options=diff_options,
=== modified file 'bzrlib/diff.py'
--- a/bzrlib/diff.py 2009-07-29 21:35:05 +0000
+++ b/bzrlib/diff.py 2009-10-08 16:32:43 +0000
@@ -277,8 +277,8 @@
new_abspath, e)
-def _get_trees_to_diff(path_list, revision_specs, old_url, new_url,
- apply_view=True):
+def get_trees_and_branches_to_diff(path_list, revision_specs, old_url, new_url,
+ apply_view=True):
"""Get the trees and specific files to diff given a list of paths.
This method works out the trees to be diff'ed and the files of
@@ -341,6 +341,7 @@
views.check_path_in_view(working_tree, relpath)
specific_files.append(relpath)
old_tree = _get_tree_to_diff(old_revision_spec, working_tree, branch)
+ old_branch = branch
# Get the new location
if new_url is None:
@@ -354,6 +355,7 @@
specific_files.append(relpath)
new_tree = _get_tree_to_diff(new_revision_spec, working_tree, branch,
basis_is_default=working_tree is None)
+ new_branch = branch
# Get the specific files (all files is None, no files is [])
if make_paths_wt_relative and working_tree is not None:
@@ -378,7 +380,7 @@
extra_trees = None
if working_tree is not None and working_tree not in (old_tree, new_tree):
extra_trees = (working_tree,)
- return old_tree, new_tree, specific_files, extra_trees
+ return old_tree, new_tree, old_branch, new_branch, specific_files, extra_trees
def _get_tree_to_diff(spec, tree=None, branch=None, basis_is_default=True):
if branch is None and tree is not None:
=== modified file 'bzrlib/tests/test_diff.py'
--- a/bzrlib/tests/test_diff.py 2009-03-31 00:12:10 +0000
+++ b/bzrlib/tests/test_diff.py 2009-10-08 16:32:43 +0000
@@ -32,6 +32,7 @@
external_diff,
internal_diff,
show_diff_trees,
+ get_trees_and_branches_to_diff,
)
from bzrlib.errors import BinaryFile, NoDiff, ExecutableMissing
import bzrlib.osutils as osutils
@@ -41,6 +42,8 @@
import bzrlib._patiencediff_py
from bzrlib.tests import (Feature, TestCase, TestCaseWithTransport,
TestCaseInTempDir, TestSkipped)
+from bzrlib.revisiontree import RevisionTree
+from bzrlib.revisionspec import RevisionSpec
class _AttribFeature(Feature):
@@ -1382,3 +1385,46 @@
self.assertTrue(os.path.samefile('tree/newname', new_path))
# make sure we can create files with the same parent directories
diff_obj._prepare_files('file2-id', 'oldname2', 'newname2')
+
+
+class TestGetTreesAndBranchesToDiff(TestCaseWithTransport):
+
+ def test_basic(self):
+ tree = self.make_branch_and_tree('tree')
+ (old_tree, new_tree,
+ old_branch, new_branch,
+ specific_files, extra_trees) = \
+ get_trees_and_branches_to_diff(['tree'], None, None, None)
+
+ self.assertIsInstance(old_tree, RevisionTree)
+ #print dir (old_tree)
+ self.assertEqual(_mod_revision.NULL_REVISION, old_tree.get_revision_id())
+ self.assertEqual(tree.basedir, new_tree.basedir)
+ self.assertEqual(tree.branch.base, old_branch.base)
+ self.assertEqual(tree.branch.base, new_branch.base)
+ self.assertIs(None, specific_files)
+ self.assertIs(None, extra_trees)
+
+ def test_with_rev_specs(self):
+ tree = self.make_branch_and_tree('tree')
+ self.build_tree_contents([('tree/file', 'oldcontent')])
+ tree.add('file', 'file-id')
+ tree.commit('old tree', timestamp=0, rev_id="old-id")
+ self.build_tree_contents([('tree/file', 'newcontent')])
+ tree.commit('new tree', timestamp=0, rev_id="new-id")
+
+ revisions = [RevisionSpec.from_string('1'),
+ RevisionSpec.from_string('2')]
+ (old_tree, new_tree,
+ old_branch, new_branch,
+ specific_files, extra_trees) = \
+ get_trees_and_branches_to_diff(['tree'], revisions, None, None)
+
+ self.assertIsInstance(old_tree, RevisionTree)
+ self.assertEqual("old-id", old_tree.get_revision_id())
+ self.assertIsInstance(new_tree, RevisionTree)
+ self.assertEqual("new-id", new_tree.get_revision_id())
+ self.assertEqual(tree.branch.base, old_branch.base)
+ self.assertEqual(tree.branch.base, new_branch.base)
+ self.assertIs(None, specific_files)
+ self.assertEqual(tree.basedir, extra_trees[0].basedir)
More information about the bazaar-commits
mailing list