MCPcopy Create free account
hub / github.com/boostorg/build / _do_tree_difference

Function _do_tree_difference

test/tree.py:137–185  ·  view source on GitHub ↗

Internal recursive worker function for tree_difference().

(a, b, parent_path, root=False)

Source from the content-addressed store, hash-verified

135
136
137def _do_tree_difference(a, b, parent_path, root=False):
138 """Internal recursive worker function for tree_difference()."""
139
140 # We do not want to list root node names.
141 if root:
142 assert not parent_path
143 assert not a.is_file()
144 assert not b.is_file()
145 full_path = ""
146 else:
147 assert a.name == b.name
148 full_path = parent_path + a.name
149 result = TreeDifference()
150
151 # A and B are both files.
152 if a.is_file() and b.is_file():
153 if a.contents != b.contents:
154 result.modified_files.append(full_path)
155 elif a.mtime != b.mtime:
156 result.touched_files.append(full_path)
157 return result
158
159 # Directory converted to file.
160 if not a.is_file() and b.is_file():
161 result.removed_files.extend(_traverse_tree(a, parent_path))
162 result.added_files.append(full_path)
163
164 # File converted to directory.
165 elif a.is_file() and not b.is_file():
166 result.removed_files.append(full_path)
167 result.added_files.extend(_traverse_tree(b, parent_path))
168
169 # A and B are both directories.
170 else:
171 if full_path:
172 full_path += "/"
173 accounted_for = [] # Children present in both trees.
174 for a_child in a.children:
175 b_child = b.get_child(a_child.name)
176 if b_child:
177 accounted_for.append(b_child)
178 result.append(_do_tree_difference(a_child, b_child, full_path))
179 else:
180 result.removed_files.append(full_path + a_child.name)
181 for b_child in b.children:
182 if b_child not in accounted_for:
183 result.added_files.extend(_traverse_tree(b_child, full_path))
184
185 return result
186
187
188def _traverse_tree(t, parent_path):

Callers 1

tree_differenceFunction · 0.85

Calls 5

appendMethod · 0.95
TreeDifferenceClass · 0.85
_traverse_treeFunction · 0.85
is_fileMethod · 0.80
get_childMethod · 0.80

Tested by

no test coverage detected