MCPcopy Create free account
hub / github.com/cloudflare/computer / makePathFilter

Function makePathFilter

packages/computer/src/git/diff.ts:264–277  ·  view source on GitHub ↗
(paths: string[] | undefined)

Source from the content-addressed store, hash-verified

262}
263
264function makePathFilter(paths: string[] | undefined): (p: string) => boolean {
265 if (paths === undefined || paths.length === 0) return () => true;
266 // Match either an exact path or a directory prefix. Globs are
267 // not supported on this surface; the docs call this out
268 // explicitly under the `diff` command reference.
269 const exact = new Set(paths.map((p) => normalizePath(p)));
270 const prefixes = [...exact].map((p) => `${p}/`);
271 return (candidate) => {
272 const c = normalizePath(candidate);
273 if (exact.has(c)) return true;
274 for (const prefix of prefixes) if (c.startsWith(prefix)) return true;
275 return false;
276 };
277}
278
279function normalizePath(p: string): string {
280 // Drop leading './' and trailing '/'.

Callers 2

collectDiffEntriesFunction · 0.85
collectRefToRefFunction · 0.85

Calls 2

hasMethod · 0.80
normalizePathFunction · 0.70

Tested by

no test coverage detected