tree-diff: convert diff_tree_paths to struct object_id

Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed May 30, 2017 at 10:31 UTC fda94b416ed07988e645cec22bf61742d4dd5c95
3 files changed +39 -38
combine-diff.c
+5 -5
@@ -1364,22 +1364,22 @@ static struct combine_diff_path *find_paths_multitree(
1364 struct diff_options *opt)
1365 {
1366 int i, nparent = parents->nr;
1367 - const unsigned char **parents_sha1;
1367 + const struct object_id **parents_oid;
1368 struct combine_diff_path paths_head;
1369 struct strbuf base;
1370
1371 - ALLOC_ARRAY(parents_sha1, nparent);
1371 + ALLOC_ARRAY(parents_oid, nparent);
1372 for (i = 0; i < nparent; i++)
1373 - parents_sha1[i] = parents->oid[i].hash;
1373 + parents_oid[i] = &parents->oid[i];
1374
1375 /* fake list head, so worker can assume it is non-NULL */
1376 paths_head.next = NULL;
1377
1378 strbuf_init(&base, PATH_MAX);
1379 - diff_tree_paths(&paths_head, oid->hash, parents_sha1, nparent, &base, opt);
1379 + diff_tree_paths(&paths_head, oid, parents_oid, nparent, &base, opt);
1380
1381 strbuf_release(&base);
1382 - free(parents_sha1);
1382 + free(parents_oid);
1383 return paths_head.next;
1384 }
1385
diff.h
+2 -2
@@ -210,8 +210,8 @@ const char *diff_line_prefix(struct diff_options *);
210 extern const char mime_boundary_leader[];
211
212 extern struct combine_diff_path *diff_tree_paths(
213 - struct combine_diff_path *p, const unsigned char *sha1,
214 - const unsigned char **parent_sha1, int nparent,
213 + struct combine_diff_path *p, const struct object_id *oid,
214 + const struct object_id **parents_oid, int nparent,
215 struct strbuf *base, struct diff_options *opt);
216 extern int diff_tree_oid(const struct object_id *old_oid,
217 const struct object_id *new_oid,
tree-diff.c
+32 -31
@@ -26,11 +26,12 @@
26 } while(0)
27
28 static struct combine_diff_path *ll_diff_tree_paths(
29 - struct combine_diff_path *p, const unsigned char *sha1,
30 - const unsigned char **parents_sha1, int nparent,
29 + struct combine_diff_path *p, const struct object_id *oid,
30 + const struct object_id **parents_oid, int nparent,
31 struct strbuf *base, struct diff_options *opt);
32 -static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new,
33 - struct strbuf *base, struct diff_options *opt);
32 +static int ll_diff_tree_oid(const struct object_id *old_oid,
33 + const struct object_id *new_oid,
34 + struct strbuf *base, struct diff_options *opt);
35
36 /*
37 * Compare two tree entries, taking into account only path/S_ISDIR(mode),
@@ -183,7 +184,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
184 {
185 unsigned mode;
186 const char *path;
186 - const unsigned char *sha1;
187 + const struct object_id *oid;
188 int pathlen;
189 int old_baselen = base->len;
190 int i, isdir, recurse = 0, emitthis = 1;
@@ -193,7 +194,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
194
195 if (t) {
196 /* path present in resulting tree */
196 - sha1 = tree_entry_extract(t, &path, &mode)->hash;
197 + oid = tree_entry_extract(t, &path, &mode);
198 pathlen = tree_entry_len(&t->entry);
199 isdir = S_ISDIR(mode);
200 } else {
@@ -208,7 +209,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
209 pathlen = tree_entry_len(&tp[imin].entry);
210
211 isdir = S_ISDIR(mode);
211 - sha1 = NULL;
212 + oid = NULL;
213 mode = 0;
214 }
215
@@ -220,7 +221,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
221 if (emitthis) {
222 int keep;
223 struct combine_diff_path *pprev = p;
223 - p = path_appendnew(p, nparent, base, path, pathlen, mode, sha1);
224 + p = path_appendnew(p, nparent, base, path, pathlen, mode, oid ? oid->hash : NULL);
225
226 for (i = 0; i < nparent; ++i) {
227 /*
@@ -229,7 +230,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
230 */
231 int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ);
232
232 - const unsigned char *sha1_i;
233 + const struct object_id *oid_i;
234 unsigned mode_i;
235
236 p->parent[i].status =
@@ -239,16 +240,16 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
240 DIFF_STATUS_ADDED;
241
242 if (tpi_valid) {
242 - sha1_i = tp[i].entry.oid->hash;
243 + oid_i = tp[i].entry.oid;
244 mode_i = tp[i].entry.mode;
245 }
246 else {
246 - sha1_i = NULL;
247 + oid_i = &null_oid;
248 mode_i = 0;
249 }
250
251 p->parent[i].mode = mode_i;
251 - hashcpy(p->parent[i].oid.hash, sha1_i ? sha1_i : null_sha1);
252 + oidcpy(&p->parent[i].oid, oid_i);
253 }
254
255 keep = 1;
@@ -273,21 +274,20 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
274 }
275
276 if (recurse) {
276 - const unsigned char **parents_sha1;
277 + const struct object_id **parents_oid;
278
278 - FAST_ARRAY_ALLOC(parents_sha1, nparent);
279 + FAST_ARRAY_ALLOC(parents_oid, nparent);
280 for (i = 0; i < nparent; ++i) {
281 /* same rule as in emitthis */
282 int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ);
283
283 - parents_sha1[i] = tpi_valid ? tp[i].entry.oid->hash
284 - : NULL;
284 + parents_oid[i] = tpi_valid ? tp[i].entry.oid : NULL;
285 }
286
287 strbuf_add(base, path, pathlen);
288 strbuf_addch(base, '/');
289 - p = ll_diff_tree_paths(p, sha1, parents_sha1, nparent, base, opt);
290 - FAST_ARRAY_FREE(parents_sha1, nparent);
289 + p = ll_diff_tree_paths(p, oid, parents_oid, nparent, base, opt);
290 + FAST_ARRAY_FREE(parents_oid, nparent);
291 }
292
293 strbuf_setlen(base, old_baselen);
@@ -312,7 +312,7 @@ static void skip_uninteresting(struct tree_desc *t, struct strbuf *base,
312
313
314 /*
315 - * generate paths for combined diff D(sha1,parents_sha1[])
315 + * generate paths for combined diff D(sha1,parents_oid[])
316 *
317 * Resulting paths are appended to combine_diff_path linked list, and also, are
318 * emitted on the go via opt->pathchange() callback, so it is possible to
@@ -404,8 +404,8 @@ static inline void update_tp_entries(struct tree_desc *tp, int nparent)
404 }
405
406 static struct combine_diff_path *ll_diff_tree_paths(
407 - struct combine_diff_path *p, const unsigned char *sha1,
408 - const unsigned char **parents_sha1, int nparent,
407 + struct combine_diff_path *p, const struct object_id *oid,
408 + const struct object_id **parents_oid, int nparent,
409 struct strbuf *base, struct diff_options *opt)
410 {
411 struct tree_desc t, *tp;
@@ -422,8 +422,8 @@ static struct combine_diff_path *ll_diff_tree_paths(
422 * diff_tree_oid(parent, commit) )
423 */
424 for (i = 0; i < nparent; ++i)
425 - tptree[i] = fill_tree_descriptor(&tp[i], parents_sha1[i]);
426 - ttree = fill_tree_descriptor(&t, sha1);
425 + tptree[i] = fill_tree_descriptor(&tp[i], parents_oid[i]->hash);
426 + ttree = fill_tree_descriptor(&t, oid->hash);
427
428 /* Enable recursion indefinitely */
429 opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE);
@@ -548,11 +548,11 @@ static struct combine_diff_path *ll_diff_tree_paths(
548 }
549
550 struct combine_diff_path *diff_tree_paths(
551 - struct combine_diff_path *p, const unsigned char *sha1,
552 - const unsigned char **parents_sha1, int nparent,
551 + struct combine_diff_path *p, const struct object_id *oid,
552 + const struct object_id **parents_oid, int nparent,
553 struct strbuf *base, struct diff_options *opt)
554 {
555 - p = ll_diff_tree_paths(p, sha1, parents_sha1, nparent, base, opt);
555 + p = ll_diff_tree_paths(p, oid, parents_oid, nparent, base, opt);
556
557 /*
558 * free pre-allocated last element, if any
@@ -617,7 +617,7 @@ static void try_to_follow_renames(const struct object_id *old_oid,
617 diff_opts.break_opt = opt->break_opt;
618 diff_opts.rename_score = opt->rename_score;
619 diff_setup_done(&diff_opts);
620 - ll_diff_tree_sha1(old_oid->hash, new_oid->hash, base, &diff_opts);
620 + ll_diff_tree_oid(old_oid, new_oid, base, &diff_opts);
621 diffcore_std(&diff_opts);
622 clear_pathspec(&diff_opts.pathspec);
623
@@ -676,15 +676,16 @@ static void try_to_follow_renames(const struct object_id *old_oid,
676 q->nr = 1;
677 }
678
679 -static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new,
680 - struct strbuf *base, struct diff_options *opt)
679 +static int ll_diff_tree_oid(const struct object_id *old_oid,
680 + const struct object_id *new_oid,
681 + struct strbuf *base, struct diff_options *opt)
682 {
683 struct combine_diff_path phead, *p;
684 pathchange_fn_t pathchange_old = opt->pathchange;
685
686 phead.next = NULL;
687 opt->pathchange = emit_diff_first_parent_only;
687 - diff_tree_paths(&phead, new, &old, 1, base, opt);
688 + diff_tree_paths(&phead, new_oid, &old_oid, 1, base, opt);
689
690 for (p = phead.next; p;) {
691 struct combine_diff_path *pprev = p;
@@ -706,7 +707,7 @@ int diff_tree_oid(const struct object_id *old_oid,
707 strbuf_init(&base, PATH_MAX);
708 strbuf_addstr(&base, base_str);
709
709 - retval = ll_diff_tree_sha1(old_oid->hash, new_oid->hash, &base, opt);
710 + retval = ll_diff_tree_oid(old_oid, new_oid, &base, opt);
711 if (!*base_str && DIFF_OPT_TST(opt, FOLLOW_RENAMES) && diff_might_be_rename())
712 try_to_follow_renames(old_oid, new_oid, &base, opt);
713