MCPcopy Create free account
hub / github.com/git/git / match_trees

Function match_trees

match-trees.c:139–176  ·  view source on GitHub ↗

* Match one itself and its subtrees with two and pick the best match. */

Source from the content-addressed store, hash-verified

137 * Match one itself and its subtrees with two and pick the best match.
138 */
139static void match_trees(struct repository *r,
140 const struct object_id *hash1,
141 const struct object_id *hash2,
142 int *best_score,
143 char **best_match,
144 const char *base,
145 int recurse_limit)
146{
147 struct tree_desc one;
148 void *one_buf = fill_tree_desc_strict(r, &one, hash1);
149
150 while (one.size) {
151 const char *path;
152 const struct object_id *elem;
153 unsigned short mode;
154 int score;
155
156 elem = tree_entry_extract(&one, &path, &mode);
157 if (!S_ISDIR(mode))
158 goto next;
159 score = score_trees(r, elem, hash2);
160 if (*best_score < score) {
161 free(*best_match);
162 *best_match = xstrfmt("%s%s", base, path);
163 *best_score = score;
164 }
165 if (recurse_limit) {
166 char *newbase = xstrfmt("%s%s/", base, path);
167 match_trees(r, elem, hash2, best_score, best_match,
168 newbase, recurse_limit - 1);
169 free(newbase);
170 }
171
172 next:
173 update_tree_entry(&one);
174 }
175 free(one_buf);
176}
177
178/*
179 * A tree "oid1" has a subdirectory at "prefix". Come up with a tree object by

Callers 1

shift_treeFunction · 0.85

Calls 5

fill_tree_desc_strictFunction · 0.85
tree_entry_extractFunction · 0.85
score_treesFunction · 0.85
xstrfmtFunction · 0.85
update_tree_entryFunction · 0.85

Tested by

no test coverage detected