Merge branch 'jc/tree-walk-drop-base-offset' into next
Code simplification. * jc/tree-walk-drop-base-offset: tree-walk: drop unused base_offset from do_match() tree-walk: lose base_offset that is never used in tree_entry_interesting
This commit is contained in:
@ -643,7 +643,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
|
|||||||
strbuf_addstr(&name, base->buf + tn_len);
|
strbuf_addstr(&name, base->buf + tn_len);
|
||||||
match = tree_entry_interesting(repo->index,
|
match = tree_entry_interesting(repo->index,
|
||||||
&entry, &name,
|
&entry, &name,
|
||||||
0, pathspec);
|
pathspec);
|
||||||
strbuf_setlen(&name, name_base_len);
|
strbuf_setlen(&name, name_base_len);
|
||||||
|
|
||||||
if (match == all_entries_not_interesting)
|
if (match == all_entries_not_interesting)
|
||||||
|
@ -102,7 +102,7 @@ static void process_tree_contents(struct traversal_context *ctx,
|
|||||||
while (tree_entry(&desc, &entry)) {
|
while (tree_entry(&desc, &entry)) {
|
||||||
if (match != all_entries_interesting) {
|
if (match != all_entries_interesting) {
|
||||||
match = tree_entry_interesting(ctx->revs->repo->index,
|
match = tree_entry_interesting(ctx->revs->repo->index,
|
||||||
&entry, base, 0,
|
&entry, base,
|
||||||
&ctx->revs->diffopt.pathspec);
|
&ctx->revs->diffopt.pathspec);
|
||||||
if (match == all_entries_not_interesting)
|
if (match == all_entries_not_interesting)
|
||||||
break;
|
break;
|
||||||
|
@ -317,7 +317,7 @@ static void skip_uninteresting(struct tree_desc *t, struct strbuf *base,
|
|||||||
|
|
||||||
while (t->size) {
|
while (t->size) {
|
||||||
match = tree_entry_interesting(opt->repo->index, &t->entry,
|
match = tree_entry_interesting(opt->repo->index, &t->entry,
|
||||||
base, 0, &opt->pathspec);
|
base, &opt->pathspec);
|
||||||
if (match) {
|
if (match) {
|
||||||
if (match == all_entries_not_interesting)
|
if (match == all_entries_not_interesting)
|
||||||
t->size = 0;
|
t->size = 0;
|
||||||
|
36
tree-walk.c
36
tree-walk.c
@ -434,7 +434,7 @@ static inline int prune_traversal(struct index_state *istate,
|
|||||||
if (still_interesting < 0)
|
if (still_interesting < 0)
|
||||||
return still_interesting;
|
return still_interesting;
|
||||||
return tree_entry_interesting(istate, e, base,
|
return tree_entry_interesting(istate, e, base,
|
||||||
0, info->pathspec);
|
info->pathspec);
|
||||||
}
|
}
|
||||||
|
|
||||||
int traverse_trees(struct index_state *istate,
|
int traverse_trees(struct index_state *istate,
|
||||||
@ -1015,17 +1015,17 @@ static int match_wildcard_base(const struct pathspec_item *item,
|
|||||||
/*
|
/*
|
||||||
* Is a tree entry interesting given the pathspec we have?
|
* Is a tree entry interesting given the pathspec we have?
|
||||||
*
|
*
|
||||||
* Pre-condition: either baselen == base_offset (i.e. empty path)
|
* Pre-condition: either baselen == 0 (i.e. empty path)
|
||||||
* or base[baselen-1] == '/' (i.e. with trailing slash).
|
* or base[baselen-1] == '/' (i.e. with trailing slash).
|
||||||
*/
|
*/
|
||||||
static enum interesting do_match(struct index_state *istate,
|
static enum interesting do_match(struct index_state *istate,
|
||||||
const struct name_entry *entry,
|
const struct name_entry *entry,
|
||||||
struct strbuf *base, int base_offset,
|
struct strbuf *base,
|
||||||
const struct pathspec *ps,
|
const struct pathspec *ps,
|
||||||
int exclude)
|
int exclude)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int pathlen, baselen = base->len - base_offset;
|
int pathlen, baselen = base->len;
|
||||||
enum interesting never_interesting = ps->has_wildcard ?
|
enum interesting never_interesting = ps->has_wildcard ?
|
||||||
entry_not_interesting : all_entries_not_interesting;
|
entry_not_interesting : all_entries_not_interesting;
|
||||||
|
|
||||||
@ -1043,7 +1043,7 @@ static enum interesting do_match(struct index_state *istate,
|
|||||||
!(ps->magic & PATHSPEC_MAXDEPTH) ||
|
!(ps->magic & PATHSPEC_MAXDEPTH) ||
|
||||||
ps->max_depth == -1)
|
ps->max_depth == -1)
|
||||||
return all_entries_interesting;
|
return all_entries_interesting;
|
||||||
return within_depth(base->buf + base_offset, baselen,
|
return within_depth(base->buf, baselen,
|
||||||
!!S_ISDIR(entry->mode),
|
!!S_ISDIR(entry->mode),
|
||||||
ps->max_depth) ?
|
ps->max_depth) ?
|
||||||
entry_interesting : entry_not_interesting;
|
entry_interesting : entry_not_interesting;
|
||||||
@ -1054,7 +1054,7 @@ static enum interesting do_match(struct index_state *istate,
|
|||||||
for (i = ps->nr - 1; i >= 0; i--) {
|
for (i = ps->nr - 1; i >= 0; i--) {
|
||||||
const struct pathspec_item *item = ps->items+i;
|
const struct pathspec_item *item = ps->items+i;
|
||||||
const char *match = item->match;
|
const char *match = item->match;
|
||||||
const char *base_str = base->buf + base_offset;
|
const char *base_str = base->buf;
|
||||||
int matchlen = item->len, matched = 0;
|
int matchlen = item->len, matched = 0;
|
||||||
|
|
||||||
if ((!exclude && item->magic & PATHSPEC_EXCLUDE) ||
|
if ((!exclude && item->magic & PATHSPEC_EXCLUDE) ||
|
||||||
@ -1147,9 +1147,9 @@ match_wildcards:
|
|||||||
|
|
||||||
strbuf_add(base, entry->path, pathlen);
|
strbuf_add(base, entry->path, pathlen);
|
||||||
|
|
||||||
if (!git_fnmatch(item, match, base->buf + base_offset,
|
if (!git_fnmatch(item, match, base->buf,
|
||||||
item->nowildcard_len)) {
|
item->nowildcard_len)) {
|
||||||
strbuf_setlen(base, base_offset + baselen);
|
strbuf_setlen(base, baselen);
|
||||||
goto interesting;
|
goto interesting;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1161,13 +1161,13 @@ match_wildcards:
|
|||||||
* be performed in the submodule itself.
|
* be performed in the submodule itself.
|
||||||
*/
|
*/
|
||||||
if (ps->recurse_submodules && S_ISGITLINK(entry->mode) &&
|
if (ps->recurse_submodules && S_ISGITLINK(entry->mode) &&
|
||||||
!ps_strncmp(item, match, base->buf + base_offset,
|
!ps_strncmp(item, match, base->buf,
|
||||||
item->nowildcard_len)) {
|
item->nowildcard_len)) {
|
||||||
strbuf_setlen(base, base_offset + baselen);
|
strbuf_setlen(base, baselen);
|
||||||
goto interesting;
|
goto interesting;
|
||||||
}
|
}
|
||||||
|
|
||||||
strbuf_setlen(base, base_offset + baselen);
|
strbuf_setlen(base, baselen);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Match all directories. We'll try to match files
|
* Match all directories. We'll try to match files
|
||||||
@ -1203,9 +1203,9 @@ interesting:
|
|||||||
return entry_interesting;
|
return entry_interesting;
|
||||||
|
|
||||||
strbuf_add(base, entry->path, pathlen);
|
strbuf_add(base, entry->path, pathlen);
|
||||||
ret = match_pathspec_attrs(istate, base->buf + base_offset,
|
ret = match_pathspec_attrs(istate, base->buf,
|
||||||
base->len - base_offset, item);
|
base->len, item);
|
||||||
strbuf_setlen(base, base_offset + baselen);
|
strbuf_setlen(base, baselen);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1217,16 +1217,16 @@ interesting:
|
|||||||
/*
|
/*
|
||||||
* Is a tree entry interesting given the pathspec we have?
|
* Is a tree entry interesting given the pathspec we have?
|
||||||
*
|
*
|
||||||
* Pre-condition: either baselen == base_offset (i.e. empty path)
|
* Pre-condition: either baselen == 0 (i.e. empty path)
|
||||||
* or base[baselen-1] == '/' (i.e. with trailing slash).
|
* or base[baselen-1] == '/' (i.e. with trailing slash).
|
||||||
*/
|
*/
|
||||||
enum interesting tree_entry_interesting(struct index_state *istate,
|
enum interesting tree_entry_interesting(struct index_state *istate,
|
||||||
const struct name_entry *entry,
|
const struct name_entry *entry,
|
||||||
struct strbuf *base, int base_offset,
|
struct strbuf *base,
|
||||||
const struct pathspec *ps)
|
const struct pathspec *ps)
|
||||||
{
|
{
|
||||||
enum interesting positive, negative;
|
enum interesting positive, negative;
|
||||||
positive = do_match(istate, entry, base, base_offset, ps, 0);
|
positive = do_match(istate, entry, base, ps, 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* case | entry | positive | negative | result
|
* case | entry | positive | negative | result
|
||||||
@ -1263,7 +1263,7 @@ enum interesting tree_entry_interesting(struct index_state *istate,
|
|||||||
positive <= entry_not_interesting) /* #1, #2, #11, #12 */
|
positive <= entry_not_interesting) /* #1, #2, #11, #12 */
|
||||||
return positive;
|
return positive;
|
||||||
|
|
||||||
negative = do_match(istate, entry, base, base_offset, ps, 1);
|
negative = do_match(istate, entry, base, ps, 1);
|
||||||
|
|
||||||
/* #8, #18 */
|
/* #8, #18 */
|
||||||
if (positive == all_entries_interesting &&
|
if (positive == all_entries_interesting &&
|
||||||
|
@ -224,7 +224,7 @@ enum interesting {
|
|||||||
|
|
||||||
enum interesting tree_entry_interesting(struct index_state *istate,
|
enum interesting tree_entry_interesting(struct index_state *istate,
|
||||||
const struct name_entry *,
|
const struct name_entry *,
|
||||||
struct strbuf *, int,
|
struct strbuf *,
|
||||||
const struct pathspec *ps);
|
const struct pathspec *ps);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
2
tree.c
2
tree.c
@ -32,7 +32,7 @@ int read_tree_at(struct repository *r,
|
|||||||
while (tree_entry(&desc, &entry)) {
|
while (tree_entry(&desc, &entry)) {
|
||||||
if (retval != all_entries_interesting) {
|
if (retval != all_entries_interesting) {
|
||||||
retval = tree_entry_interesting(r->index, &entry,
|
retval = tree_entry_interesting(r->index, &entry,
|
||||||
base, 0, pathspec);
|
base, pathspec);
|
||||||
if (retval == all_entries_not_interesting)
|
if (retval == all_entries_not_interesting)
|
||||||
break;
|
break;
|
||||||
if (retval == entry_not_interesting)
|
if (retval == entry_not_interesting)
|
||||||
|
Reference in New Issue
Block a user