* Match one itself and its subtrees with two and pick the best match. */
| 137 | * Match one itself and its subtrees with two and pick the best match. |
| 138 | */ |
| 139 | static 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 |
no test coverage detected