74
74
:param path: The FastPath being added
75
75
:param kind: The kind of the object being added.
77
if not self.should_print:
79
self._to_file.write('added %s\n' % _quote(path.raw_path))
78
self._to_file.write('added %s\n' % _quote(path.raw_path))
82
class AddFromBaseAction(AddAction):
83
"""This class will try to extract file ids from another tree."""
85
def __init__(self, base_tree, base_path, to_file=None, should_print=None):
86
super(AddFromBaseAction, self).__init__(to_file=to_file,
87
should_print=should_print)
88
self.base_tree = base_tree
89
self.base_path = base_path
91
def __call__(self, inv, parent_ie, path, kind):
92
# Place the parent call
93
# Now check to see if we can extract an id for this file
94
file_id, base_path = self._get_base_file_id(path, parent_ie)
95
if file_id is not None:
97
self._to_file.write('added %s w/ file id from %s\n'
98
% (path.raw_path, base_path))
100
# we aren't doing anything special, so let the default
102
file_id = super(AddFromBaseAction, self).__call__(
103
inv, parent_ie, path, kind)
106
def _get_base_file_id(self, path, parent_ie):
107
"""Look for a file id in the base branch.
109
First, if the base tree has the parent directory,
110
we look for a file with the same name in that directory.
111
Else, we look for an entry in the base tree with the same path.
114
if (parent_ie.file_id in self.base_tree):
115
base_parent_ie = self.base_tree.inventory[parent_ie.file_id]
116
base_child_ie = base_parent_ie.children.get(path.base_path)
117
if base_child_ie is not None:
118
return (base_child_ie.file_id,
119
self.base_tree.id2path(base_child_ie.file_id))
120
full_base_path = bzrlib.osutils.pathjoin(self.base_path, path.raw_path)
121
# This may return None, but it is our last attempt
122
return self.base_tree.path2id(full_base_path), full_base_path
82
125
# TODO: jam 20050105 These could be used for compatibility
321
364
:param inv: Inventory which will receive the new entry.
322
365
:param parent_ie: Parent inventory entry.
323
366
:param kind: Kind of new entry (file, directory, etc)
324
:param action: callback(inv, parent_ie, path, kind); return ignored.
367
:param action: callback(inv, parent_ie, path, kind); return a file_id
368
or None to generate a new file id
327
action(inv, parent_ie, path, kind)
328
entry = bzrlib.inventory.make_entry(kind, path.base_path, parent_ie.file_id)
371
file_id = action(inv, parent_ie, path, kind)
372
entry = bzrlib.inventory.make_entry(kind, path.base_path, parent_ie.file_id,