MCPcopy Index your code
hub / github.com/git/git / shift_tree

Function shift_tree

match-trees.c:262–319  ·  view source on GitHub ↗

* We are trying to come up with a merge between one and two that * results in a tree shape similar to one. The tree two might * correspond to a subtree of one, in which case it needs to be * shifted down by prefixing otherwise empty directories. On the * other hand, it could cover tree one and we might need to pick a * subtree of it. */

Source from the content-addressed store, hash-verified

260 * subtree of it.
261 */
262void shift_tree(struct repository *r,
263 const struct object_id *hash1,
264 const struct object_id *hash2,
265 struct object_id *shifted,
266 int depth_limit)
267{
268 char *add_prefix;
269 char *del_prefix;
270 int add_score, del_score;
271
272 /*
273 * NEEDSWORK: this limits the recursion depth to hardcoded
274 * value '2' to avoid excessive overhead.
275 */
276 if (!depth_limit)
277 depth_limit = 2;
278
279 add_score = del_score = score_trees(r, hash1, hash2);
280 add_prefix = xcalloc(1, 1);
281 del_prefix = xcalloc(1, 1);
282
283 /*
284 * See if one's subtree resembles two; if so we need to prefix
285 * two with a few fake trees to match the prefix.
286 */
287 match_trees(r, hash1, hash2, &add_score, &add_prefix, "", depth_limit);
288
289 /*
290 * See if two's subtree resembles one; if so we need to
291 * pick only subtree of two.
292 */
293 match_trees(r, hash2, hash1, &del_score, &del_prefix, "", depth_limit);
294
295 /* Assume we do not have to do any shifting */
296 oidcpy(shifted, hash2);
297
298 if (add_score < del_score) {
299 /* We need to pick a subtree of two */
300 unsigned short mode;
301
302 if (!*del_prefix)
303 goto out;
304
305 if (get_tree_entry(r, hash2, del_prefix, shifted, &mode))
306 die("cannot find path %s in tree %s",
307 del_prefix, oid_to_hex(hash2));
308 goto out;
309 }
310
311 if (!*add_prefix)
312 goto out;
313
314 splice_tree(r, hash1, add_prefix, hash2, shifted);
315
316out:
317 free(add_prefix);
318 free(del_prefix);
319}

Callers 2

shift_tree_objectFunction · 0.85
cmd__match_treesFunction · 0.85

Calls 8

score_treesFunction · 0.85
xcallocFunction · 0.85
match_treesFunction · 0.85
oidcpyFunction · 0.85
get_tree_entryFunction · 0.85
oid_to_hexFunction · 0.85
splice_treeFunction · 0.85
dieFunction · 0.70

Tested by 1

cmd__match_treesFunction · 0.68