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>
maint
Brandon Williams 2017-05-30 10:31:06 -07:00 committed by Junio C Hamano
parent 128be8767d
commit fda94b416e
3 changed files with 39 additions and 38 deletions

View File

@ -1364,22 +1364,22 @@ static struct combine_diff_path *find_paths_multitree(
struct diff_options *opt) struct diff_options *opt)
{ {
int i, nparent = parents->nr; int i, nparent = parents->nr;
const unsigned char **parents_sha1; const struct object_id **parents_oid;
struct combine_diff_path paths_head; struct combine_diff_path paths_head;
struct strbuf base; struct strbuf base;


ALLOC_ARRAY(parents_sha1, nparent); ALLOC_ARRAY(parents_oid, nparent);
for (i = 0; i < nparent; i++) for (i = 0; i < nparent; i++)
parents_sha1[i] = parents->oid[i].hash; parents_oid[i] = &parents->oid[i];


/* fake list head, so worker can assume it is non-NULL */ /* fake list head, so worker can assume it is non-NULL */
paths_head.next = NULL; paths_head.next = NULL;


strbuf_init(&base, PATH_MAX); strbuf_init(&base, PATH_MAX);
diff_tree_paths(&paths_head, oid->hash, parents_sha1, nparent, &base, opt); diff_tree_paths(&paths_head, oid, parents_oid, nparent, &base, opt);


strbuf_release(&base); strbuf_release(&base);
free(parents_sha1); free(parents_oid);
return paths_head.next; return paths_head.next;
} }



4
diff.h
View File

@ -210,8 +210,8 @@ const char *diff_line_prefix(struct diff_options *);
extern const char mime_boundary_leader[]; extern const char mime_boundary_leader[];


extern struct combine_diff_path *diff_tree_paths( extern struct combine_diff_path *diff_tree_paths(
struct combine_diff_path *p, const unsigned char *sha1, struct combine_diff_path *p, const struct object_id *oid,
const unsigned char **parent_sha1, int nparent, const struct object_id **parents_oid, int nparent,
struct strbuf *base, struct diff_options *opt); struct strbuf *base, struct diff_options *opt);
extern int diff_tree_oid(const struct object_id *old_oid, extern int diff_tree_oid(const struct object_id *old_oid,
const struct object_id *new_oid, const struct object_id *new_oid,

View File

@ -26,11 +26,12 @@
} while(0) } while(0)


static struct combine_diff_path *ll_diff_tree_paths( static struct combine_diff_path *ll_diff_tree_paths(
struct combine_diff_path *p, const unsigned char *sha1, struct combine_diff_path *p, const struct object_id *oid,
const unsigned char **parents_sha1, int nparent, const struct object_id **parents_oid, int nparent,
struct strbuf *base, struct diff_options *opt); struct strbuf *base, struct diff_options *opt);
static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new, static int ll_diff_tree_oid(const struct object_id *old_oid,
struct strbuf *base, struct diff_options *opt); const struct object_id *new_oid,
struct strbuf *base, struct diff_options *opt);


/* /*
* Compare two tree entries, taking into account only path/S_ISDIR(mode), * 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,
{ {
unsigned mode; unsigned mode;
const char *path; const char *path;
const unsigned char *sha1; const struct object_id *oid;
int pathlen; int pathlen;
int old_baselen = base->len; int old_baselen = base->len;
int i, isdir, recurse = 0, emitthis = 1; int i, isdir, recurse = 0, emitthis = 1;
@ -193,7 +194,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,


if (t) { if (t) {
/* path present in resulting tree */ /* path present in resulting tree */
sha1 = tree_entry_extract(t, &path, &mode)->hash; oid = tree_entry_extract(t, &path, &mode);
pathlen = tree_entry_len(&t->entry); pathlen = tree_entry_len(&t->entry);
isdir = S_ISDIR(mode); isdir = S_ISDIR(mode);
} else { } else {
@ -208,7 +209,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
pathlen = tree_entry_len(&tp[imin].entry); pathlen = tree_entry_len(&tp[imin].entry);


isdir = S_ISDIR(mode); isdir = S_ISDIR(mode);
sha1 = NULL; oid = NULL;
mode = 0; mode = 0;
} }


@ -220,7 +221,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
if (emitthis) { if (emitthis) {
int keep; int keep;
struct combine_diff_path *pprev = p; struct combine_diff_path *pprev = p;
p = path_appendnew(p, nparent, base, path, pathlen, mode, sha1); p = path_appendnew(p, nparent, base, path, pathlen, mode, oid ? oid->hash : NULL);


for (i = 0; i < nparent; ++i) { for (i = 0; i < nparent; ++i) {
/* /*
@ -229,7 +230,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
*/ */
int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ); int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ);


const unsigned char *sha1_i; const struct object_id *oid_i;
unsigned mode_i; unsigned mode_i;


p->parent[i].status = p->parent[i].status =
@ -239,16 +240,16 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
DIFF_STATUS_ADDED; DIFF_STATUS_ADDED;


if (tpi_valid) { if (tpi_valid) {
sha1_i = tp[i].entry.oid->hash; oid_i = tp[i].entry.oid;
mode_i = tp[i].entry.mode; mode_i = tp[i].entry.mode;
} }
else { else {
sha1_i = NULL; oid_i = &null_oid;
mode_i = 0; mode_i = 0;
} }


p->parent[i].mode = mode_i; p->parent[i].mode = mode_i;
hashcpy(p->parent[i].oid.hash, sha1_i ? sha1_i : null_sha1); oidcpy(&p->parent[i].oid, oid_i);
} }


keep = 1; keep = 1;
@ -273,21 +274,20 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
} }


if (recurse) { if (recurse) {
const unsigned char **parents_sha1; const struct object_id **parents_oid;


FAST_ARRAY_ALLOC(parents_sha1, nparent); FAST_ARRAY_ALLOC(parents_oid, nparent);
for (i = 0; i < nparent; ++i) { for (i = 0; i < nparent; ++i) {
/* same rule as in emitthis */ /* same rule as in emitthis */
int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ); int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ);


parents_sha1[i] = tpi_valid ? tp[i].entry.oid->hash parents_oid[i] = tpi_valid ? tp[i].entry.oid : NULL;
: NULL;
} }


strbuf_add(base, path, pathlen); strbuf_add(base, path, pathlen);
strbuf_addch(base, '/'); strbuf_addch(base, '/');
p = ll_diff_tree_paths(p, sha1, parents_sha1, nparent, base, opt); p = ll_diff_tree_paths(p, oid, parents_oid, nparent, base, opt);
FAST_ARRAY_FREE(parents_sha1, nparent); FAST_ARRAY_FREE(parents_oid, nparent);
} }


strbuf_setlen(base, old_baselen); strbuf_setlen(base, old_baselen);
@ -312,7 +312,7 @@ static void skip_uninteresting(struct tree_desc *t, struct strbuf *base,




/* /*
* generate paths for combined diff D(sha1,parents_sha1[]) * generate paths for combined diff D(sha1,parents_oid[])
* *
* Resulting paths are appended to combine_diff_path linked list, and also, are * Resulting paths are appended to combine_diff_path linked list, and also, are
* emitted on the go via opt->pathchange() callback, so it is possible to * 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)
} }


static struct combine_diff_path *ll_diff_tree_paths( static struct combine_diff_path *ll_diff_tree_paths(
struct combine_diff_path *p, const unsigned char *sha1, struct combine_diff_path *p, const struct object_id *oid,
const unsigned char **parents_sha1, int nparent, const struct object_id **parents_oid, int nparent,
struct strbuf *base, struct diff_options *opt) struct strbuf *base, struct diff_options *opt)
{ {
struct tree_desc t, *tp; struct tree_desc t, *tp;
@ -422,8 +422,8 @@ static struct combine_diff_path *ll_diff_tree_paths(
* diff_tree_oid(parent, commit) ) * diff_tree_oid(parent, commit) )
*/ */
for (i = 0; i < nparent; ++i) for (i = 0; i < nparent; ++i)
tptree[i] = fill_tree_descriptor(&tp[i], parents_sha1[i]); tptree[i] = fill_tree_descriptor(&tp[i], parents_oid[i]->hash);
ttree = fill_tree_descriptor(&t, sha1); ttree = fill_tree_descriptor(&t, oid->hash);


/* Enable recursion indefinitely */ /* Enable recursion indefinitely */
opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE); opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE);
@ -548,11 +548,11 @@ static struct combine_diff_path *ll_diff_tree_paths(
} }


struct combine_diff_path *diff_tree_paths( struct combine_diff_path *diff_tree_paths(
struct combine_diff_path *p, const unsigned char *sha1, struct combine_diff_path *p, const struct object_id *oid,
const unsigned char **parents_sha1, int nparent, const struct object_id **parents_oid, int nparent,
struct strbuf *base, struct diff_options *opt) struct strbuf *base, struct diff_options *opt)
{ {
p = ll_diff_tree_paths(p, sha1, parents_sha1, nparent, base, opt); p = ll_diff_tree_paths(p, oid, parents_oid, nparent, base, opt);


/* /*
* free pre-allocated last element, if any * free pre-allocated last element, if any
@ -617,7 +617,7 @@ static void try_to_follow_renames(const struct object_id *old_oid,
diff_opts.break_opt = opt->break_opt; diff_opts.break_opt = opt->break_opt;
diff_opts.rename_score = opt->rename_score; diff_opts.rename_score = opt->rename_score;
diff_setup_done(&diff_opts); diff_setup_done(&diff_opts);
ll_diff_tree_sha1(old_oid->hash, new_oid->hash, base, &diff_opts); ll_diff_tree_oid(old_oid, new_oid, base, &diff_opts);
diffcore_std(&diff_opts); diffcore_std(&diff_opts);
clear_pathspec(&diff_opts.pathspec); clear_pathspec(&diff_opts.pathspec);


@ -676,15 +676,16 @@ static void try_to_follow_renames(const struct object_id *old_oid,
q->nr = 1; q->nr = 1;
} }


static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new, static int ll_diff_tree_oid(const struct object_id *old_oid,
struct strbuf *base, struct diff_options *opt) const struct object_id *new_oid,
struct strbuf *base, struct diff_options *opt)
{ {
struct combine_diff_path phead, *p; struct combine_diff_path phead, *p;
pathchange_fn_t pathchange_old = opt->pathchange; pathchange_fn_t pathchange_old = opt->pathchange;


phead.next = NULL; phead.next = NULL;
opt->pathchange = emit_diff_first_parent_only; opt->pathchange = emit_diff_first_parent_only;
diff_tree_paths(&phead, new, &old, 1, base, opt); diff_tree_paths(&phead, new_oid, &old_oid, 1, base, opt);


for (p = phead.next; p;) { for (p = phead.next; p;) {
struct combine_diff_path *pprev = p; struct combine_diff_path *pprev = p;
@ -706,7 +707,7 @@ int diff_tree_oid(const struct object_id *old_oid,
strbuf_init(&base, PATH_MAX); strbuf_init(&base, PATH_MAX);
strbuf_addstr(&base, base_str); strbuf_addstr(&base, base_str);


retval = ll_diff_tree_sha1(old_oid->hash, new_oid->hash, &base, opt); retval = ll_diff_tree_oid(old_oid, new_oid, &base, opt);
if (!*base_str && DIFF_OPT_TST(opt, FOLLOW_RENAMES) && diff_might_be_rename()) if (!*base_str && DIFF_OPT_TST(opt, FOLLOW_RENAMES) && diff_might_be_rename())
try_to_follow_renames(old_oid, new_oid, &base, opt); try_to_follow_renames(old_oid, new_oid, &base, opt);