1
1
# Copyright (C) 2005, 2006 Canonical
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
from bzrlib.inventory import InventoryEntry
18
18
from bzrlib.trace import mutter
19
from bzrlib.symbol_versioning import deprecated_function, zero_ten
21
22
class TreeDelta(object):
92
93
def show(self, to_file, show_ids=False, show_unchanged=False):
94
"""output this delta in status-like form to to_file."""
93
95
def show_list(files):
95
97
path, fid, kind = item[:3]
141
143
show_list(self.unchanged)
145
def compare_trees(old_tree, new_tree, want_unchanged=False, specific_files=None):
146
"""Describe changes from one tree to another.
148
Returns a TreeDelta with details of added, modified, renamed, and
151
The root entry is specifically exempt.
153
This only considers versioned files.
156
If true, also list files unchanged from one version to
160
If true, only check for changes to specified names or
161
files within them. Any unversioned files given have no effect
162
(but this might change in the future).
164
# NB: show_status depends on being able to pass in non-versioned files and
165
# report them as unknown
170
return _compare_trees(old_tree, new_tree, want_unchanged,
178
def _compare_trees(old_tree, new_tree, want_unchanged, specific_files):
146
@deprecated_function(zero_ten)
147
def compare_trees(old_tree, new_tree, want_unchanged=False,
148
specific_files=None, extra_trees=None,
149
require_versioned=False):
150
"""compare_trees was deprecated in 0.10. Please see Tree.changes_from."""
151
return new_tree.changes_from(old_tree,
152
want_unchanged=want_unchanged,
153
specific_files=specific_files,
154
extra_trees=extra_trees,
155
require_versioned=require_versioned)
158
def _compare_trees(old_tree, new_tree, want_unchanged, specific_file_ids):
180
160
from osutils import is_inside_any
187
167
# TODO: Rather than iterating over the whole tree and then filtering, we
188
168
# could diff just the specified files (if any) and their subtrees.
189
# Perhaps should take a list of file-ids instead? Need to indicate any
190
# ids or names which were not found in the trees.
192
170
old_files = old_tree.list_files()
193
171
new_files = new_tree.list_files()
211
189
"""We have matched up 2 file_ids, check for changes."""
212
190
assert old_entry.kind == new_entry.kind
214
if old_entry.kind == 'root_directory':
218
if (not is_inside_any(specific_files, old_path)
219
and not is_inside_any(specific_files, new_path)):
192
if specific_file_ids:
193
if (old_entry.file_id not in specific_file_ids and
194
new_entry.file_id not in specific_file_ids):
222
197
# temporary hack until all entries are populated before clients
315
290
# Now we have a set of added and removed files, mark them all
316
291
for old_path, old_entry in removed.itervalues():
318
if not is_inside_any(specific_files, old_path):
292
if specific_file_ids:
293
if not old_entry.file_id in specific_file_ids:
320
295
delta.removed.append((old_path, old_entry.file_id, old_entry.kind))
321
296
for new_path, new_entry in added.itervalues():
323
if not is_inside_any(specific_files, new_path):
297
if specific_file_ids:
298
if not new_entry.file_id in specific_file_ids:
325
300
delta.added.append((new_path, new_entry.file_id, new_entry.kind))