git-and-grep.js 1.4 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 __host.worldRead("world-read#1", "grep", ["TODO"]);
  6. const narrowed = await __host.worldRead("world-read#2", "grep", ["TODO", "*.ts"]);
  7. const changed = await __host.worldRead("world-read#3", "git-changed-files", []);
  8. const againstMain = await __host.worldRead("world-read#4", "git-changed-files", ["main"]);
  9. const wholeDiff = await __host.worldRead("world-read#5", "git-diff", []);
  10. const onePath = await __host.worldRead("world-read#6", "git-diff", ["main", "src/a.ts"]);
  11. const state = await __host.worldRead("world-read#7", "git-status", []);
  12. const recent = await __host.worldRead("world-read#8", "git-log", []);
  13. const fiveCommits = await __host.worldRead("world-read#9", "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. __host.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. };