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

Function _do_tree_difference

test/tree.py:135–183  ·  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

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