git-and-grep.ts 1.1 KB

12345678910111213141516171819202122
  1. // Multi-argument and optional-argument world reads. What this pins in the lowered output:
  2. // arguments are packed positionally, and an absent trailing optional yields a SHORTER
  3. // array — not a `undefined` hole — because `inputHash({op, args})` is the journal key and
  4. // `["TODO"]` must not hash the same as `["TODO", undefined]`.
  5. const hits = await files.grep("TODO");
  6. const narrowed = await files.grep("TODO", "*.ts");
  7. const changed = await git.changedFiles();
  8. const againstMain = await git.changedFiles("main");
  9. const wholeDiff = await git.diff();
  10. const onePath = await git.diff("main", "src/a.ts");
  11. const state = await git.status();
  12. const recent = await git.log();
  13. const fiveCommits = await git.log(5);
  14. // The collision case, in lowered form: a top-level log call becomes __host.log, while the
  15. // git container's log member becomes __host.worldRead with the "git-log" op.
  16. log(`${hits.length} / ${narrowed.length}`);
  17. return {
  18. changed: changed.length + againstMain.length,
  19. commits: recent.length + fiveCommits.length,
  20. diffBytes: wholeDiff.length + onePath.length,
  21. branch: state.branch ?? "detached",
  22. };