Prototypes LoomP35 · Git in the page

GitHub does not let a page call its Git server directly, so the clone runs through this site’s Worker, which passes Git’s protocol on to github.com for public repositories and keeps nothing. Everything else happens in this page: the pack is received, its deltas are resolved in a Web Worker, and the files are checked out.

  1. RefsWaiting
  2. NegotiationWaiting
  3. Pack receivedWaiting
  4. ObjectsWaiting
  5. Deltas resolvedWaiting
  6. CheckoutWaiting
How Loom is built
  1. Loom is Git written for this prototype in plain JavaScript, with no dependencies. It reads and writes Git’s own formats: loose objects, packs with their .idx, refs, packed-refs, HEAD and the index. A repository Loom makes is one Git accepts, and one Git makes is one Loom reads.
  2. An object’s id is the SHA-1 of its kind, its size and its bytes. Loom hashes with its own SHA-1, deflates and inflates with its own zlib, and writes trees in Git’s order, where a folder sorts as if its name ended in a slash.
  3. A pack holds objects one after another with no lengths between them, many stored as deltas against another object. Loom’s inflate says where each stream ended, so it can read a pack from its first byte. It resolves the deltas, works out every id and writes the .idx. It also writes packs with deltas of its own.
  4. The diff is Git’s xdiff written again: Myers’ algorithm with xdiff’s preparation and heuristics, patience and histogram diff, and the indent heuristic that decides where a group of changed lines starts. git diff’s output follows, with the function line Git puts after each hunk header.
  5. A merge works as Git’s ort strategy does. When two branches have more than one merge base, the bases are merged first into a virtual base. Renames are found first on each side, so a file renamed on one side and changed on the other is merged at its new name. Files both sides changed are merged line by line, and conflicts are written with Git’s markers for you to resolve.
  6. Blame walks from the newest commit down, passing each line a commit did not change to its parent, the way git blame does.
  7. The repository is kept in IndexedDB in this browser. Download gives the whole repository as a folder with its .git inside, as a zip or a tar: unpack it and run git log, git status or git fsck on it.
  8. Clone speaks Git’s protocol version 2 over HTTP: ls-refs for the refs, then fetch with want and done. The pack comes back on side-band 64k with the server’s progress, and a Web Worker resolves it. GitHub does not let a browser call it directly, so this site’s Worker passes the protocol on to github.com and keeps nothing.
  9. Loom is held against Git 2.50.1 itself. A script builds scripted histories and 70 fuzz seeds with Git and records Git’s answers, and the page against Git compares Loom’s answers with them. The other way, Git checks the repositories Loom writes with git fsck --strict, git verify-pack, git log and git status.