Skip to content

Commit fea92e4

Browse files
committed
Merge branch 'jc/tree-walk-drop-base-offset'
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
2 parents ee48e70 + 30c8c55 commit fea92e4

File tree

6 files changed

+23
-23
lines changed

6 files changed

+23
-23
lines changed

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
643643
strbuf_addstr(&name, base->buf + tn_len);
644644
match = tree_entry_interesting(repo->index,
645645
&entry, &name,
646-
0, pathspec);
646+
pathspec);
647647
strbuf_setlen(&name, name_base_len);
648648

649649
if (match == all_entries_not_interesting)

list-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static void process_tree_contents(struct traversal_context *ctx,
102102
while (tree_entry(&desc, &entry)) {
103103
if (match != all_entries_interesting) {
104104
match = tree_entry_interesting(ctx->revs->repo->index,
105-
&entry, base, 0,
105+
&entry, base,
106106
&ctx->revs->diffopt.pathspec);
107107
if (match == all_entries_not_interesting)
108108
break;

tree-diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static void skip_uninteresting(struct tree_desc *t, struct strbuf *base,
317317

318318
while (t->size) {
319319
match = tree_entry_interesting(opt->repo->index, &t->entry,
320-
base, 0, &opt->pathspec);
320+
base, &opt->pathspec);
321321
if (match) {
322322
if (match == all_entries_not_interesting)
323323
t->size = 0;

tree-walk.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ static inline int prune_traversal(struct index_state *istate,
434434
if (still_interesting < 0)
435435
return still_interesting;
436436
return tree_entry_interesting(istate, e, base,
437-
0, info->pathspec);
437+
info->pathspec);
438438
}
439439

440440
int traverse_trees(struct index_state *istate,
@@ -1015,17 +1015,17 @@ static int match_wildcard_base(const struct pathspec_item *item,
10151015
/*
10161016
* Is a tree entry interesting given the pathspec we have?
10171017
*
1018-
* Pre-condition: either baselen == base_offset (i.e. empty path)
1018+
* Pre-condition: either baselen == 0 (i.e. empty path)
10191019
* or base[baselen-1] == '/' (i.e. with trailing slash).
10201020
*/
10211021
static enum interesting do_match(struct index_state *istate,
10221022
const struct name_entry *entry,
1023-
struct strbuf *base, int base_offset,
1023+
struct strbuf *base,
10241024
const struct pathspec *ps,
10251025
int exclude)
10261026
{
10271027
int i;
1028-
int pathlen, baselen = base->len - base_offset;
1028+
int pathlen, baselen = base->len;
10291029
enum interesting never_interesting = ps->has_wildcard ?
10301030
entry_not_interesting : all_entries_not_interesting;
10311031

@@ -1043,7 +1043,7 @@ static enum interesting do_match(struct index_state *istate,
10431043
!(ps->magic & PATHSPEC_MAXDEPTH) ||
10441044
ps->max_depth == -1)
10451045
return all_entries_interesting;
1046-
return within_depth(base->buf + base_offset, baselen,
1046+
return within_depth(base->buf, baselen,
10471047
!!S_ISDIR(entry->mode),
10481048
ps->max_depth) ?
10491049
entry_interesting : entry_not_interesting;
@@ -1054,7 +1054,7 @@ static enum interesting do_match(struct index_state *istate,
10541054
for (i = ps->nr - 1; i >= 0; i--) {
10551055
const struct pathspec_item *item = ps->items+i;
10561056
const char *match = item->match;
1057-
const char *base_str = base->buf + base_offset;
1057+
const char *base_str = base->buf;
10581058
int matchlen = item->len, matched = 0;
10591059

10601060
if ((!exclude && item->magic & PATHSPEC_EXCLUDE) ||
@@ -1147,9 +1147,9 @@ static enum interesting do_match(struct index_state *istate,
11471147

11481148
strbuf_add(base, entry->path, pathlen);
11491149

1150-
if (!git_fnmatch(item, match, base->buf + base_offset,
1150+
if (!git_fnmatch(item, match, base->buf,
11511151
item->nowildcard_len)) {
1152-
strbuf_setlen(base, base_offset + baselen);
1152+
strbuf_setlen(base, baselen);
11531153
goto interesting;
11541154
}
11551155

@@ -1161,13 +1161,13 @@ static enum interesting do_match(struct index_state *istate,
11611161
* be performed in the submodule itself.
11621162
*/
11631163
if (ps->recurse_submodules && S_ISGITLINK(entry->mode) &&
1164-
!ps_strncmp(item, match, base->buf + base_offset,
1164+
!ps_strncmp(item, match, base->buf,
11651165
item->nowildcard_len)) {
1166-
strbuf_setlen(base, base_offset + baselen);
1166+
strbuf_setlen(base, baselen);
11671167
goto interesting;
11681168
}
11691169

1170-
strbuf_setlen(base, base_offset + baselen);
1170+
strbuf_setlen(base, baselen);
11711171

11721172
/*
11731173
* Match all directories. We'll try to match files
@@ -1203,9 +1203,9 @@ static enum interesting do_match(struct index_state *istate,
12031203
return entry_interesting;
12041204

12051205
strbuf_add(base, entry->path, pathlen);
1206-
ret = match_pathspec_attrs(istate, base->buf + base_offset,
1207-
base->len - base_offset, item);
1208-
strbuf_setlen(base, base_offset + baselen);
1206+
ret = match_pathspec_attrs(istate, base->buf,
1207+
base->len, item);
1208+
strbuf_setlen(base, baselen);
12091209
if (!ret)
12101210
continue;
12111211
}
@@ -1217,16 +1217,16 @@ static enum interesting do_match(struct index_state *istate,
12171217
/*
12181218
* Is a tree entry interesting given the pathspec we have?
12191219
*
1220-
* Pre-condition: either baselen == base_offset (i.e. empty path)
1220+
* Pre-condition: either baselen == 0 (i.e. empty path)
12211221
* or base[baselen-1] == '/' (i.e. with trailing slash).
12221222
*/
12231223
enum interesting tree_entry_interesting(struct index_state *istate,
12241224
const struct name_entry *entry,
1225-
struct strbuf *base, int base_offset,
1225+
struct strbuf *base,
12261226
const struct pathspec *ps)
12271227
{
12281228
enum interesting positive, negative;
1229-
positive = do_match(istate, entry, base, base_offset, ps, 0);
1229+
positive = do_match(istate, entry, base, ps, 0);
12301230

12311231
/*
12321232
* case | entry | positive | negative | result
@@ -1263,7 +1263,7 @@ enum interesting tree_entry_interesting(struct index_state *istate,
12631263
positive <= entry_not_interesting) /* #1, #2, #11, #12 */
12641264
return positive;
12651265

1266-
negative = do_match(istate, entry, base, base_offset, ps, 1);
1266+
negative = do_match(istate, entry, base, ps, 1);
12671267

12681268
/* #8, #18 */
12691269
if (positive == all_entries_interesting &&

tree-walk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ enum interesting {
224224

225225
enum interesting tree_entry_interesting(struct index_state *istate,
226226
const struct name_entry *,
227-
struct strbuf *, int,
227+
struct strbuf *,
228228
const struct pathspec *ps);
229229

230230
#endif

tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int read_tree_at(struct repository *r,
3232
while (tree_entry(&desc, &entry)) {
3333
if (retval != all_entries_interesting) {
3434
retval = tree_entry_interesting(r->index, &entry,
35-
base, 0, pathspec);
35+
base, pathspec);
3636
if (retval == all_entries_not_interesting)
3737
break;
3838
if (retval == entry_not_interesting)

0 commit comments

Comments
 (0)