зеркало из https://github.com/microsoft/git.git
Merge branch 'jc/diff-index-unpack' into maint
* jc/diff-index-unpack: diff-index: pass pathspec down to unpack-trees machinery unpack-trees: allow pruning with pathspec traverse_trees(): allow pruning with pathspec
This commit is contained in:
Коммит
fc26f57b84
|
@ -468,6 +468,7 @@ static int diff_cache(struct rev_info *revs,
|
|||
opts.unpack_data = revs;
|
||||
opts.src_index = &the_index;
|
||||
opts.dst_index = NULL;
|
||||
opts.pathspec = &revs->diffopt.pathspec;
|
||||
|
||||
init_tree_desc(&t, tree->buffer, tree->size);
|
||||
return unpack_trees(1, &t, &opts);
|
||||
|
|
39
tree-walk.c
39
tree-walk.c
|
@ -309,6 +309,18 @@ static void free_extended_entry(struct tree_desc_x *t)
|
|||
}
|
||||
}
|
||||
|
||||
static inline int prune_traversal(struct name_entry *e,
|
||||
struct traverse_info *info,
|
||||
struct strbuf *base,
|
||||
int still_interesting)
|
||||
{
|
||||
if (!info->pathspec || still_interesting == 2)
|
||||
return 2;
|
||||
if (still_interesting < 0)
|
||||
return still_interesting;
|
||||
return tree_entry_interesting(e, base, 0, info->pathspec);
|
||||
}
|
||||
|
||||
int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
|
||||
{
|
||||
int ret = 0;
|
||||
|
@ -316,10 +328,18 @@ int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
|
|||
struct name_entry *entry = xmalloc(n*sizeof(*entry));
|
||||
int i;
|
||||
struct tree_desc_x *tx = xcalloc(n, sizeof(*tx));
|
||||
struct strbuf base = STRBUF_INIT;
|
||||
int interesting = 1;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
tx[i].d = t[i];
|
||||
|
||||
if (info->prev) {
|
||||
strbuf_grow(&base, info->pathlen);
|
||||
make_traverse_path(base.buf, info->prev, &info->name);
|
||||
base.buf[info->pathlen-1] = '/';
|
||||
strbuf_setlen(&base, info->pathlen);
|
||||
}
|
||||
for (;;) {
|
||||
unsigned long mask, dirmask;
|
||||
const char *first = NULL;
|
||||
|
@ -376,16 +396,22 @@ int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
|
|||
mask |= 1ul << i;
|
||||
if (S_ISDIR(entry[i].mode))
|
||||
dirmask |= 1ul << i;
|
||||
e = &entry[i];
|
||||
}
|
||||
if (!mask)
|
||||
break;
|
||||
ret = info->fn(n, mask, dirmask, entry, info);
|
||||
if (ret < 0) {
|
||||
error = ret;
|
||||
if (!info->show_all_errors)
|
||||
break;
|
||||
interesting = prune_traversal(e, info, &base, interesting);
|
||||
if (interesting < 0)
|
||||
break;
|
||||
if (interesting) {
|
||||
ret = info->fn(n, mask, dirmask, entry, info);
|
||||
if (ret < 0) {
|
||||
error = ret;
|
||||
if (!info->show_all_errors)
|
||||
break;
|
||||
}
|
||||
mask &= ret;
|
||||
}
|
||||
mask &= ret;
|
||||
ret = 0;
|
||||
for (i = 0; i < n; i++)
|
||||
if (mask & (1ul << i))
|
||||
|
@ -395,6 +421,7 @@ int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
|
|||
for (i = 0; i < n; i++)
|
||||
free_extended_entry(tx + i);
|
||||
free(tx);
|
||||
strbuf_release(&base);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ struct traverse_info {
|
|||
struct traverse_info *prev;
|
||||
struct name_entry name;
|
||||
int pathlen;
|
||||
struct pathspec *pathspec;
|
||||
|
||||
unsigned long conflicts;
|
||||
traverse_callback_t fn;
|
||||
|
|
|
@ -444,6 +444,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
|
|||
|
||||
newinfo = *info;
|
||||
newinfo.prev = info;
|
||||
newinfo.pathspec = info->pathspec;
|
||||
newinfo.name = *p;
|
||||
newinfo.pathlen += tree_entry_len(p->path, p->sha1) + 1;
|
||||
newinfo.conflicts |= df_conflicts;
|
||||
|
@ -1040,6 +1041,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
|
|||
info.fn = unpack_callback;
|
||||
info.data = o;
|
||||
info.show_all_errors = o->show_all_errors;
|
||||
info.pathspec = o->pathspec;
|
||||
|
||||
if (o->prefix) {
|
||||
/*
|
||||
|
|
|
@ -52,6 +52,7 @@ struct unpack_trees_options {
|
|||
const char *prefix;
|
||||
int cache_bottom;
|
||||
struct dir_struct *dir;
|
||||
struct pathspec *pathspec;
|
||||
merge_fn_t fn;
|
||||
const char *msgs[NB_UNPACK_TREES_ERROR_TYPES];
|
||||
/*
|
||||
|
|
Загрузка…
Ссылка в новой задаче