Skip to content

S08-10 - WSL

Purpose: How the fetches of the git round trip cross between a WSL distribution and the Windows side.

When wb runs inside WSL (S12-platformsS12-platforms: PlatformsWhich host and guest operating systems Wraith Box targets, how platform-specific code is isolated, what each platform uses, and how wb works inside WSL.), the repository is in the WSL distribution. export.git and landing.git are on the Windows side. Both fetches cross between the two with git fetch --upload-pack=<command>:

Fetch Runs on Its upload-pack runs on
Export update the Windows side, wb.exe relay the WSL side, wb upload-pack-relay
Land and diff the WSL side, wb the Windows side, wb.exe landing-upload-pack

Everything else in S08-workspace-and-gitS08-workspace-and-git: Workspace and Git Round TripHow code gets into the guest and how the agent's work gets back out, without sharing the host filesystem. is the same under WSL.

Git runs the --upload-pack value as a POSIX shell command line, with sh -c. On the Windows side that is the sh of Git for Windows. Git appends the fetch’s path as the last word.

The side that composes the value:

  1. checks each project ID and session ID in it against its format;
  2. single-quotes every word the way git’s sq_quote_buf does. The word goes in single quotes, with each ' in it written as '\'' and each ! as '\!'.

The quoting covers the program’s path, the distribution and user names, the repository’s path and the IDs. No word can expand or split.

  • The path of wsl.exe is written with forward slashes, which sh doesn’t read as escapes.
  • The first word is an absolute path. Git then doesn’t look up a remote helper, and the shell doesn’t search PATH for the program.

The Git for Windows sh converts arguments that look like POSIX paths into Windows paths when it starts a program that isn’t an MSYS program, such as wsl.exe. /usr/local/bin/wb or /home/<user>/repo would then reach the distribution as Windows paths. MSYS_NO_PATHCONV=1 turns that conversion off. The Windows-side fetch runs with it in its environment.

The fetch’s path is a placeholder that the program ignores. But git reads an existing bundle file at that path as a bundle, and then ignores --upload-pack (reproduced with git 2.56.0 for I67I67 (closed): wb-hostd can't read the user's repository under its sandbox profile (S08 upload-pack)Found in the review of #65 (X23-sandboxed-daemons result).). So the composing side:

  1. creates a new empty directory, readable only by the user, in its temporary directory;
  2. uses wb-relay in it as the placeholder;
  3. checks with lstat, right before the fetch, that the placeholder doesn’t exist.

The check guards against a file that is already there. Between the check and git’s own stat, only a process of the user can create one, because only the user can write the directory.

T00-indexT00-indexboundary 6 is the host terminal stream. trusts the user’s processes. On Windows they include wb-hostd, until I190I190 (open): wb-hostd write rule for landing.git without export.git on Linux and WindowsFound while writing #67 into S04-architecture. gives it a profile there. What it could gain depends on the side:

Each fetch runs with the settings of S08-06-landing-on-the-hostS08-06-landing-on-the-host: Landing on the HostHow wb land and wb diff bring a session's work into the user's repository, and the checks that keep that fetch from running anything., “Fetch settings”: GIT_PROTOCOL_FROM_USER=0, protocol.allow=never, protocol.file.allow=always and --no-recurse-submodules.

The WSL-side wb starts wb.exe relay on the Windows side (S12-05-wslS12-05-wsl: WSLHow wb works inside a WSL 2 distribution on a Windows host (FR16-wsl).). The relay runs as the Windows user, outside any sandbox. It is the wb of S08-02-export-repositoryS08-02-export-repository: Export RepositoryWhich refs and objects the guest can fetch from export.git, and how wb, its one writer, keeps it safe to run git in. and S08-07-repository-lifecycleS08-07-repository-lifecycle: Repository LifecycleWhen objects leave export.git and landing.git, and the locks that order that work against fetches and pushes. for export.git, with the Windows host git (S08-08-host-gitS08-08-host-git: Host GitWhich git binary runs on the host, the oldest version Wraith Box accepts, and where that is checked.).

  1. It takes the export lock over wb-hostd’s named pipe.
  2. Under the lock it checks the layout and config of export.git.
  3. It fetches, deletes refs, and runs the shrink steps and the prune.

Its --upload-pack command is wsl.exe from the Windows system directory, with:

  • the distribution and the Linux user of the WSL-side wb;
  • --exec and the WSL-side wb’s absolute path;
  • the subcommand upload-pack-relay;
  • the repository’s path.

The WSL-side wb sends those values. wb.exe takes none of them from wb-hostd.

In the distribution, wb upload-pack-relay checks that the path is the git common directory that the rules of S05-04-namingS05-04-naming: NamingHow wb identifies a project, a session and its branch, and how projects are registered, checked, moved and removed. give for that path. Then it runs git upload-pack on it, with GIT_NO_LAZY_FETCH=1 and its own git, which it resolves and checks by S08-08-host-gitS08-08-host-git: Host GitWhich git binary runs on the host, the oldest version Wraith Box accepts, and where that is checked.. WSL interop carries the standard input and output.

The WSL-side wb runs the fetch of S08-06-landing-on-the-hostS08-06-landing-on-the-host: Landing on the HostHow wb land and wb diff bring a session's work into the user's repository, and the checks that keep that fetch from running anything. in the distribution. It fetches into the user’s repository, or the scratch repository of wb diff.

Its --upload-pack command is wb.exe, at the path the WSL-side wb uses to start the relay, with the subcommand landing-upload-pack, the project ID, and the session ID. wb.exe then:

  1. checks both IDs against their formats again;
  2. derives the landing repository’s path itself;
  3. runs the checks of S08-06-landing-on-the-hostS08-06-landing-on-the-host: Landing on the HostHow wb land and wb diff bring a session's work into the user's repository, and the checks that keep that fetch from running anything. on it;
  4. runs git upload-pack on it with the Windows git.

One writer for export.git, on the Windows side

Section titled “One writer for export.git, on the Windows side”

The WSL-side wb doesn’t write export.git over the cross-OS file share. export.git has one writer, on the Windows side, with the Windows git.

Status: Draft