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 <gitster@pobox.com>

Junio C Hamano committed Jul 7, 2023 at 15:21 UTC 30c8c55cbfa6e4f81e4d73767294f50f5d9c7d10
1 file changed +16 -17
tree-walk.c
+16 -17
@@ -1016,17 +1016,17 @@ static int match_wildcard_base(const struct pathspec_item *item,
1016 /*
1017 * Is a tree entry interesting given the pathspec we have?
1018 *
1019 - * Pre-condition: either baselen == base_offset (i.e. empty path)
1019 + * Pre-condition: either baselen == 0 (i.e. empty path)
1020 * or base[baselen-1] == '/' (i.e. with trailing slash).
1021 */
1022 static enum interesting do_match(struct index_state *istate,
1023 const struct name_entry *entry,
1024 - struct strbuf *base, int base_offset,
1024 + struct strbuf *base,
1025 const struct pathspec *ps,
1026 int exclude)
1027 {
1028 int i;
1029 - int pathlen, baselen = base->len - base_offset;
1029 + int pathlen, baselen = base->len;
1030 enum interesting never_interesting = ps->has_wildcard ?
1031 entry_not_interesting : all_entries_not_interesting;
1032
@@ -1044,7 +1044,7 @@ static enum interesting do_match(struct index_state *istate,
1044 !(ps->magic & PATHSPEC_MAXDEPTH) ||
1045 ps->max_depth == -1)
1046 return all_entries_interesting;
1047 - return within_depth(base->buf + base_offset, baselen,
1047 + return within_depth(base->buf, baselen,
1048 !!S_ISDIR(entry->mode),
1049 ps->max_depth) ?
1050 entry_interesting : entry_not_interesting;
@@ -1055,7 +1055,7 @@ static enum interesting do_match(struct index_state *istate,
1055 for (i = ps->nr - 1; i >= 0; i--) {
1056 const struct pathspec_item *item = ps->items+i;
1057 const char *match = item->match;
1058 - const char *base_str = base->buf + base_offset;
1058 + const char *base_str = base->buf;
1059 int matchlen = item->len, matched = 0;
1060
1061 if ((!exclude && item->magic & PATHSPEC_EXCLUDE) ||
@@ -1148,9 +1148,9 @@ match_wildcards:
1148
1149 strbuf_add(base, entry->path, pathlen);
1150
1151 - if (!git_fnmatch(item, match, base->buf + base_offset,
1151 + if (!git_fnmatch(item, match, base->buf,
1152 item->nowildcard_len)) {
1153 - strbuf_setlen(base, base_offset + baselen);
1153 + strbuf_setlen(base, baselen);
1154 goto interesting;
1155 }
1156
@@ -1162,13 +1162,13 @@ match_wildcards:
1162 * be performed in the submodule itself.
1163 */
1164 if (ps->recurse_submodules && S_ISGITLINK(entry->mode) &&
1165 - !ps_strncmp(item, match, base->buf + base_offset,
1165 + !ps_strncmp(item, match, base->buf,
1166 item->nowildcard_len)) {
1167 - strbuf_setlen(base, base_offset + baselen);
1167 + strbuf_setlen(base, baselen);
1168 goto interesting;
1169 }
1170
1171 - strbuf_setlen(base, base_offset + baselen);
1171 + strbuf_setlen(base, baselen);
1172
1173 /*
1174 * Match all directories. We'll try to match files
@@ -1204,9 +1204,9 @@ interesting:
1204 return entry_interesting;
1205
1206 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);
1210 if (!ret)
1211 continue;
1212 }
@@ -1218,7 +1218,7 @@ interesting:
1218 /*
1219 * Is a tree entry interesting given the pathspec we have?
1220 *
1221 - * Pre-condition: either baselen == base_offset (i.e. empty path)
1221 + * Pre-condition: either baselen == 0 (i.e. empty path)
1222 * or base[baselen-1] == '/' (i.e. with trailing slash).
1223 */
1224 enum interesting tree_entry_interesting(struct index_state *istate,
@@ -1227,8 +1227,7 @@ enum interesting tree_entry_interesting(struct index_state *istate,
1227 const struct pathspec *ps)
1228 {
1229 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);
1231
1232 /*
1233 * case | entry | positive | negative | result
@@ -1265,7 +1264,7 @@ enum interesting tree_entry_interesting(struct index_state *istate,
1264 positive <= entry_not_interesting) /* #1, #2, #11, #12 */
1265 return positive;
1266
1268 - negative = do_match(istate, entry, base, base_offset, ps, 1);
1267 + negative = do_match(istate, entry, base, ps, 1);
1268
1269 /* #8, #18 */
1270 if (positive == all_entries_interesting &&