Skip to content

Commit 30c8c55

Browse files
committed
tree-walk: drop unused base_offset from do_match()
The tree-walk.c:do_match() function takes base_offset but just like tree_entry_interesting() we dealt with earlier, nobody passes a value other than 0 in it. Get rid of the parameter to avoid having to worry about potential bugs lurking unexercised. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0ad927e commit 30c8c55

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

tree-walk.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,17 +1016,17 @@ static int match_wildcard_base(const struct pathspec_item *item,
10161016
/*
10171017
* Is a tree entry interesting given the pathspec we have?
10181018
*
1019-
* Pre-condition: either baselen == base_offset (i.e. empty path)
1019+
* Pre-condition: either baselen == 0 (i.e. empty path)
10201020
* or base[baselen-1] == '/' (i.e. with trailing slash).
10211021
*/
10221022
static enum interesting do_match(struct index_state *istate,
10231023
const struct name_entry *entry,
1024-
struct strbuf *base, int base_offset,
1024+
struct strbuf *base,
10251025
const struct pathspec *ps,
10261026
int exclude)
10271027
{
10281028
int i;
1029-
int pathlen, baselen = base->len - base_offset;
1029+
int pathlen, baselen = base->len;
10301030
enum interesting never_interesting = ps->has_wildcard ?
10311031
entry_not_interesting : all_entries_not_interesting;
10321032

@@ -1044,7 +1044,7 @@ static enum interesting do_match(struct index_state *istate,
10441044
!(ps->magic & PATHSPEC_MAXDEPTH) ||
10451045
ps->max_depth == -1)
10461046
return all_entries_interesting;
1047-
return within_depth(base->buf + base_offset, baselen,
1047+
return within_depth(base->buf, baselen,
10481048
!!S_ISDIR(entry->mode),
10491049
ps->max_depth) ?
10501050
entry_interesting : entry_not_interesting;
@@ -1055,7 +1055,7 @@ static enum interesting do_match(struct index_state *istate,
10551055
for (i = ps->nr - 1; i >= 0; i--) {
10561056
const struct pathspec_item *item = ps->items+i;
10571057
const char *match = item->match;
1058-
const char *base_str = base->buf + base_offset;
1058+
const char *base_str = base->buf;
10591059
int matchlen = item->len, matched = 0;
10601060

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

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

1151-
if (!git_fnmatch(item, match, base->buf + base_offset,
1151+
if (!git_fnmatch(item, match, base->buf,
11521152
item->nowildcard_len)) {
1153-
strbuf_setlen(base, base_offset + baselen);
1153+
strbuf_setlen(base, baselen);
11541154
goto interesting;
11551155
}
11561156

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

1171-
strbuf_setlen(base, base_offset + baselen);
1171+
strbuf_setlen(base, baselen);
11721172

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

12061206
strbuf_add(base, entry->path, pathlen);
1207-
ret = match_pathspec_attrs(istate, base->buf + base_offset,
1208-
base->len - base_offset, item);
1209-
strbuf_setlen(base, base_offset + baselen);
1207+
ret = match_pathspec_attrs(istate, base->buf,
1208+
base->len, item);
1209+
strbuf_setlen(base, baselen);
12101210
if (!ret)
12111211
continue;
12121212
}
@@ -1218,7 +1218,7 @@ static enum interesting do_match(struct index_state *istate,
12181218
/*
12191219
* Is a tree entry interesting given the pathspec we have?
12201220
*
1221-
* Pre-condition: either baselen == base_offset (i.e. empty path)
1221+
* Pre-condition: either baselen == 0 (i.e. empty path)
12221222
* or base[baselen-1] == '/' (i.e. with trailing slash).
12231223
*/
12241224
enum interesting tree_entry_interesting(struct index_state *istate,
@@ -1227,8 +1227,7 @@ enum interesting tree_entry_interesting(struct index_state *istate,
12271227
const struct pathspec *ps)
12281228
{
12291229
enum interesting positive, negative;
1230-
const int base_offset = 0;
1231-
positive = do_match(istate, entry, base, base_offset, ps, 0);
1230+
positive = do_match(istate, entry, base, ps, 0);
12321231

12331232
/*
12341233
* case | entry | positive | negative | result
@@ -1265,7 +1264,7 @@ enum interesting tree_entry_interesting(struct index_state *istate,
12651264
positive <= entry_not_interesting) /* #1, #2, #11, #12 */
12661265
return positive;
12671266

1268-
negative = do_match(istate, entry, base, base_offset, ps, 1);
1267+
negative = do_match(istate, entry, base, ps, 1);
12691268

12701269
/* #8, #18 */
12711270
if (positive == all_entries_interesting &&

0 commit comments

Comments
 (0)