navid/veins / commit

8a0ec290e94f

Navid M <navidmomtahen@gmail.com> · 2026-11-28

parents: 343097cb4e32

Browse files at this commit · Download source

fmt: xveins and clang-format
--- a/veins/src/cli/clone_cmd.sx+++ b/veins/src/cli/clone_cmd.sx@@ -192,8 +192,14 @@             c = v         }         none => {+            val detail: bytes.Bytes = client.last_connect_error()             cmsg.error_prefix()-            stdio.eprint("cannot connect or authenticate\n", {})+            if detail.len > 0 {+                stdio.eprint("{s}\n", {str.view(detail.ptr, detail.len as i64)})+            } else {+                stdio.eprint("cannot connect or authenticate\n", {})+            }+            bytes.free_owned(detail)             layout.free_repo(repo)             return 1         }--- a/veins/src/cli/fetch_cmd.sx+++ b/veins/src/cli/fetch_cmd.sx@@ -172,8 +172,14 @@             c = v         }         none => {+            val detail: bytes.Bytes = client.last_connect_error()             cmsg.error_prefix()-            stdio.eprint("cannot connect or authenticate\n", {})+            if detail.len > 0 {+                stdio.eprint("{s}\n", {str.view(detail.ptr, detail.len as i64)})+            } else {+                stdio.eprint("cannot connect or authenticate\n", {})+            }+            bytes.free_owned(detail)             layout.free_repo(repo)             return 1         }--- a/veins/src/cli/push_cmd.sx+++ b/veins/src/cli/push_cmd.sx@@ -203,8 +203,14 @@             c = x         }         none => {+            val detail: bytes.Bytes = client.last_connect_error()             cmsg.error_prefix()-            stdio.eprint("cannot connect or authenticate\n", {})+            if detail.len > 0 {+                stdio.eprint("{s}\n", {str.view(detail.ptr, detail.len as i64)})+            } else {+                stdio.eprint("cannot connect or authenticate\n", {})+            }+            bytes.free_owned(detail)             transfer.free_id_bytes(commits)             transfer.free_id_bytes(objects)             layout.free_repo(repo)--- a/veins/src/cli/whoami_cmd.sx+++ b/veins/src/cli/whoami_cmd.sx@@ -106,7 +106,13 @@         bytes.free_ptr(v.fingerprint.ptr)         return 0     }+    val detail: bytes.Bytes = client.last_connect_error()     cmsg.error_prefix()-    stdio.eprint("cannot authenticate\n", {})+    if detail.len > 0 {+        stdio.eprint("{s}\n", {str.view(detail.ptr, detail.len as i64)})+    } else {+        stdio.eprint("cannot authenticate\n", {})+    }+    bytes.free_owned(detail)     return 1 }--- a/veins/src/protocol/client.sx+++ b/veins/src/protocol/client.sx@@ -33,6 +33,29 @@ pub type WhoAmI = {     role: mut u8     fingerprint: mut bytes.Bytes+}++val connect_error: mut bytes.Bytes = @zeroed++fn set_connect_error(text: ref u8) void = trust {+    if connect_error.ptr != none {+        bytes.free_ptr(connect_error.ptr)+    }+    connect_error = bytes.Bytes.dup(bytes.from_cstr(text))+}++fn clear_connect_error() void = trust {+    if connect_error.ptr != none {+        bytes.free_ptr(connect_error.ptr)+    }+    connect_error = bytes.empty()+}++pub fn last_connect_error() bytes.Bytes = trust {+    if connect_error.ptr == none {+        return bytes.empty()+    }+    return bytes.Bytes.dup(connect_error) }  type Url = {@@ -194,6 +217,9 @@         free_parts(parts)         val res = stream.spawn(cmd)         bytes.free_owned(cmd)+        if res is none {+            set_connect_error(c"cannot start the SSH transport")+        }         return res     }     if u.tls {@@ -201,6 +227,7 @@         val fd: i32 = tls.tcp_connect(host_z2, u.port)         if fd < 0 {             @free(host_z2 as ref void)+            set_connect_error(c"cannot connect: host refused the connection or is unreachable")             return none         }         val ctx: mut ref void = tls.client_ctx()@@ -210,6 +237,7 @@         if ctx == none {             @free(host_z2 as ref void)             native_close(fd)+            set_connect_error(c"cannot initialize TLS")             return none         }         val ssl: ref void = tls.connect(ctx, fd, host_z2)@@ -217,6 +245,7 @@         @free(host_z2 as ref void)         if ssl == none {             native_close(fd)+            set_connect_error(c"TLS handshake failed")             return none         }         return some stream.tls_stream(fd, ssl)@@ -231,6 +260,9 @@     free_parts(parts2)     val res2 = stream.spawn(cmd2)     bytes.free_owned(cmd2)+    if res2 is none {+        set_connect_error(c"cannot start the local vn server")+    }     return res2 } @@ -268,6 +300,7 @@     repo_name: bytes.Bytes,     tls_pin: bytes.Bytes ) option[Client] = trust {+    clear_connect_error()     val u_opt = parse_url(url)     val u: mut Url = Url{         tls: false,@@ -281,6 +314,7 @@             u = v         }         none => {+            set_connect_error(c"invalid remote URL")             return none         }     }@@ -320,6 +354,7 @@                 if binding.ptr != none {                     @free(binding.ptr as ref void)                 }+                set_connect_error(c"TLS certificate pin mismatch")                 return none             }         }@@ -348,6 +383,7 @@         if binding.ptr != none {             bytes.free_owned(binding)         }+        set_connect_error(c"connection closed during the protocol handshake")         return none     }     val f_opt = wire.read_frame(st)@@ -367,6 +403,7 @@             if binding.ptr != none {                 bytes.free_owned(binding)             }+            set_connect_error(c"server closed the connection during the protocol handshake")             return none         }     }@@ -377,6 +414,7 @@         if binding.ptr != none {             bytes.free_owned(binding)         }+        set_connect_error(c"server rejected the protocol handshake")         return none     }     val hd = msg.decode_hello_ok(f.payload)@@ -402,6 +440,7 @@         if binding.ptr != none {             bytes.free_owned(binding)         }+        set_connect_error(c"server sent an invalid protocol handshake")         return none     }     val key_sel: mut bytes.Bytes = key_name@@ -462,9 +501,15 @@     msg.free_hello_ok(hok)     bytes.free_owned(client_nonce)     if auth_req && !c.authed {+        if key_sel.len == 0 {+            set_connect_error(c"authentication required but no key is configured")+        } else {+            set_connect_error(c"authentication failed: the key is missing or not authorized")+        }         free_client(c)         return none     }+    clear_connect_error()     return some c } --- a/xveins/BENCHES.md+++ b/xveins/BENCHES.md@@ -9,11 +9,11 @@  ### Environment -| Implementation | Binary |-|:---|:---|-| Rust | `veins-rust v0.1.0 (veins-store 1)` |-| C++ | `veins v0.0.1 (veins-store 1)` |-| Spectre | `veins v0.0.1 (veins-store 1)` |+| Implementation | Binary                              |+| :------------- | :---------------------------------- |+| Rust           | `veins-rust v0.1.0 (veins-store 1)` |+| C++            | `veins v0.0.1 (veins-store 1)`      |+| Spectre        | `veins v0.0.1 (veins-store 1)`      |  ``` host:        Darwin arm64@@ -39,11 +39,11 @@  ### Summary -| Metric | Rust | C++ | Spectre | C++ / Rust | Spectre / Rust |-|:---|---:|---:|---:|---:|---:|-| Commit total [s] | 0.252 (0.250-0.262) | 0.280 (0.279-0.291) | 0.310 (0.309-0.330) | 1.11x | 1.23x |-| Checkout total [s] | 0.162 (0.161-0.165) | 0.175 (0.172-0.179) | 0.181 (0.179-0.196) | 1.08x | 1.12x |-| Store size [MiB] | 8.28 (8.28-8.37) | 8.28 (8.28-8.37) | 10.60 (10.60-10.69) | 1.00x | 1.28x |+| Metric             |                Rust |                 C++ |             Spectre | C++ / Rust | Spectre / Rust |+| :----------------- | ------------------: | ------------------: | ------------------: | ---------: | -------------: |+| Commit total [s]   | 0.252 (0.250-0.262) | 0.280 (0.279-0.291) | 0.310 (0.309-0.330) |      1.11x |          1.23x |+| Checkout total [s] | 0.162 (0.161-0.165) | 0.175 (0.172-0.179) | 0.181 (0.179-0.196) |      1.08x |          1.12x |+| Store size [MiB]   |    8.28 (8.28-8.37) |    8.28 (8.28-8.37) | 10.60 (10.60-10.69) |      1.00x |          1.28x |  Each cell is the median with the observed min-max range in parentheses. A ratio above 1 means the other implementation took longer or used more space than Rust.@@ -51,12 +51,12 @@ ### Repeats  | Repeat | Rust commit [s] | C++ commit [s] | Spectre commit [s] | Rust checkout [s] | C++ checkout [s] | Spectre checkout [s] |-|:---|---:|---:|---:|---:|---:|---:|-| 1 | 0.262 | 0.291 | 0.330 | 0.165 | 0.172 | 0.195 |-| 2 | 0.250 | 0.280 | 0.310 | 0.162 | 0.172 | 0.196 |-| 3 | 0.252 | 0.281 | 0.309 | 0.161 | 0.179 | 0.179 |-| 4 | 0.252 | 0.279 | 0.309 | 0.162 | 0.175 | 0.179 |-| 5 | 0.257 | 0.280 | 0.311 | 0.165 | 0.177 | 0.181 |+| :----- | --------------: | -------------: | -----------------: | ----------------: | ---------------: | -------------------: |+| 1      |           0.262 |          0.291 |              0.330 |             0.165 |            0.172 |                0.195 |+| 2      |           0.250 |          0.280 |              0.310 |             0.162 |            0.172 |                0.196 |+| 3      |           0.252 |          0.281 |              0.309 |             0.161 |            0.179 |                0.179 |+| 4      |           0.252 |          0.279 |              0.309 |             0.162 |            0.175 |                0.179 |+| 5      |           0.257 |          0.280 |              0.311 |             0.165 |            0.177 |                0.181 |  ### Notes @@ -104,31 +104,31 @@  ### What each benchmark does -| Benchmark | Operation |-|:---|:---|-| `clone-file` | Full clone over `file://`: handshake, refs, history, head chunks, checkout. Includes spawning one local server per run. |-| `fetch-file` | `vn fetch origin` with no new remote refs. Both clients start from a full `-blobs:all` clone. |-| `lazy-checkout-file` | `vn co oldbig` in a `-blobs:none` clone, fetching the 2 MiB old blob from the promisor over `file://`. |-| `push-file` | Push one new commit from a prepared client to a freshly reset copy of `push_pristine` over `file://`. |-| `whoami-file` | Connect, authenticate, `WHOAMI`, close over `file://`. |-| `clone-ssh` | Full clone over `ssh://`, using a local `ssh` shim that runs the remote `vn serve -stdio` command. |-| `clone-tls` | Full clone over TLS 1.3 with a pinned self-signed certificate. Uses long-running servers. |-| `whoami-tls` | Connect, authenticate, `WHOAMI`, close over TLS 1.3. |+| Benchmark            | Operation                                                                                                               |+| :------------------- | :---------------------------------------------------------------------------------------------------------------------- |+| `clone-file`         | Full clone over `file://`: handshake, refs, history, head chunks, checkout. Includes spawning one local server per run. |+| `fetch-file`         | `vn fetch origin` with no new remote refs. Both clients start from a full `-blobs:all` clone.                           |+| `lazy-checkout-file` | `vn co oldbig` in a `-blobs:none` clone, fetching the 2 MiB old blob from the promisor over `file://`.                  |+| `push-file`          | Push one new commit from a prepared client to a freshly reset copy of `push_pristine` over `file://`.                   |+| `whoami-file`        | Connect, authenticate, `WHOAMI`, close over `file://`.                                                                  |+| `clone-ssh`          | Full clone over `ssh://`, using a local `ssh` shim that runs the remote `vn serve -stdio` command.                      |+| `clone-tls`          | Full clone over TLS 1.3 with a pinned self-signed certificate. Uses long-running servers.                               |+| `whoami-tls`         | Connect, authenticate, `WHOAMI`, close over TLS 1.3.                                                                    |  Lower is better. Hyperfine reports wall-clock time; the relative column is against the fastest command.  ### Summary -| Benchmark | C++ mean | Spectre mean | Spectre / C++ |-|:---|---:|---:|---:|-| Clone file:// | 35.9 ms | 61.0 ms | 1.70x |-| Fetch file:// | 24.6 ms | 31.2 ms | 1.27x |-| Lazy checkout file:// | 253.1 ms | 420.2 ms | 1.66x |-| Push file:// | 17.0 ms | 16.0 ms | 0.94x |-| Whoami file:// | 9.7 ms | 12.5 ms | 1.28x |-| Clone ssh:// | 42.5 ms | 66.6 ms | 1.57x |-| Clone TLS 1.3 | 37.9 ms | 64.9 ms | 1.71x |-| Whoami TLS 1.3 | 10.0 ms | 14.8 ms | 1.48x |+| Benchmark             | C++ mean | Spectre mean | Spectre / C++ |+| :-------------------- | -------: | -----------: | ------------: |+| Clone file://         |  35.9 ms |      61.0 ms |         1.70x |+| Fetch file://         |  24.6 ms |      31.2 ms |         1.27x |+| Lazy checkout file:// | 253.1 ms |     420.2 ms |         1.66x |+| Push file://          |  17.0 ms |      16.0 ms |         0.94x |+| Whoami file://        |   9.7 ms |      12.5 ms |         1.28x |+| Clone ssh://          |  42.5 ms |      66.6 ms |         1.57x |+| Clone TLS 1.3         |  37.9 ms |      64.9 ms |         1.71x |+| Whoami TLS 1.3        |  10.0 ms |      14.8 ms |         1.48x |  A ratio above 1 means Spectre took longer than C++. @@ -135,52 +135,60 @@ ### Results  #### Clone over file://-| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |-|:---|---:|---:|---:|---:|-| `C++` | 35.9 ± 0.3 | 35.5 | 36.3 | 1.00 |-| `Spectre` | 61.0 ± 1.8 | 58.2 | 63.4 | 1.70 ± 0.05 |++| Command   |  Mean [ms] | Min [ms] | Max [ms] |    Relative |+| :-------- | ---------: | -------: | -------: | ----------: |+| `C++`     | 35.9 ± 0.3 |     35.5 |     36.3 |        1.00 |+| `Spectre` | 61.0 ± 1.8 |     58.2 |     63.4 | 1.70 ± 0.05 |  #### Fetch over file://-| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |-|:---|---:|---:|---:|---:|-| `C++` | 24.6 ± 0.4 | 23.9 | 25.1 | 1.00 |-| `Spectre` | 31.2 ± 1.0 | 30.2 | 32.6 | 1.27 ± 0.04 |++| Command   |  Mean [ms] | Min [ms] | Max [ms] |    Relative |+| :-------- | ---------: | -------: | -------: | ----------: |+| `C++`     | 24.6 ± 0.4 |     23.9 |     25.1 |        1.00 |+| `Spectre` | 31.2 ± 1.0 |     30.2 |     32.6 | 1.27 ± 0.04 |  #### Lazy checkout over file://-| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |-|:---|---:|---:|---:|---:|-| `C++` | 253.1 ± 7.1 | 247.7 | 272.4 | 1.00 |-| `Spectre` | 420.2 ± 14.5 | 402.5 | 451.8 | 1.66 ± 0.07 |++| Command   |    Mean [ms] | Min [ms] | Max [ms] |    Relative |+| :-------- | -----------: | -------: | -------: | ----------: |+| `C++`     |  253.1 ± 7.1 |    247.7 |    272.4 |        1.00 |+| `Spectre` | 420.2 ± 14.5 |    402.5 |    451.8 | 1.66 ± 0.07 |  #### Push over file://-| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |-|:---|---:|---:|---:|---:|-| `C++` | 17.0 ± 6.8 | 12.3 | 32.0 | 1.06 ± 0.43 |-| `Spectre` | 16.0 ± 0.4 | 15.7 | 16.8 | 1.00 |++| Command   |  Mean [ms] | Min [ms] | Max [ms] |    Relative |+| :-------- | ---------: | -------: | -------: | ----------: |+| `C++`     | 17.0 ± 6.8 |     12.3 |     32.0 | 1.06 ± 0.43 |+| `Spectre` | 16.0 ± 0.4 |     15.7 |     16.8 |        1.00 |  #### Whoami over file://-| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |-|:---|---:|---:|---:|---:|-| `C++` | 9.7 ± 0.6 | 8.7 | 10.5 | 1.00 |-| `Spectre` | 12.5 ± 0.2 | 12.1 | 12.9 | 1.28 ± 0.08 |++| Command   |  Mean [ms] | Min [ms] | Max [ms] |    Relative |+| :-------- | ---------: | -------: | -------: | ----------: |+| `C++`     |  9.7 ± 0.6 |      8.7 |     10.5 |        1.00 |+| `Spectre` | 12.5 ± 0.2 |     12.1 |     12.9 | 1.28 ± 0.08 |  #### Clone over ssh://-| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |-|:---|---:|---:|---:|---:|-| `C++` | 42.5 ± 0.4 | 41.9 | 43.2 | 1.00 |-| `Spectre` | 66.6 ± 1.2 | 64.4 | 67.8 | 1.57 ± 0.03 |++| Command   |  Mean [ms] | Min [ms] | Max [ms] |    Relative |+| :-------- | ---------: | -------: | -------: | ----------: |+| `C++`     | 42.5 ± 0.4 |     41.9 |     43.2 |        1.00 |+| `Spectre` | 66.6 ± 1.2 |     64.4 |     67.8 | 1.57 ± 0.03 |  #### Clone over TLS 1.3-| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |-|:---|---:|---:|---:|---:|-| `C++` | 37.9 ± 1.4 | 35.9 | 39.8 | 1.00 |-| `Spectre` | 64.9 ± 1.6 | 62.0 | 67.7 | 1.71 ± 0.07 |++| Command   |  Mean [ms] | Min [ms] | Max [ms] |    Relative |+| :-------- | ---------: | -------: | -------: | ----------: |+| `C++`     | 37.9 ± 1.4 |     35.9 |     39.8 |        1.00 |+| `Spectre` | 64.9 ± 1.6 |     62.0 |     67.7 | 1.71 ± 0.07 |  #### Whoami over TLS 1.3-| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |-|:---|---:|---:|---:|---:|-| `C++` | 10.0 ± 0.2 | 9.4 | 10.4 | 1.00 |-| `Spectre` | 14.8 ± 0.3 | 14.0 | 15.2 | 1.48 ± 0.04 |++| Command   |  Mean [ms] | Min [ms] | Max [ms] |    Relative |+| :-------- | ---------: | -------: | -------: | ----------: |+| `C++`     | 10.0 ± 0.2 |      9.4 |     10.4 |        1.00 |+| `Spectre` | 14.8 ± 0.3 |     14.0 |     15.2 | 1.48 ± 0.04 |  ### Notes --- a/xveins/bench/core_bench.md+++ b/xveins/bench/core_bench.md@@ -2,11 +2,11 @@  ### Environment -| Implementation | Binary |-|:---|:---|-| Rust | `veins-rust v0.1.0 (veins-store 1)` |-| C++ | `veins v0.0.1 (veins-store 1)` |-| Spectre | `veins v0.0.1 (veins-store 1)` |+| Implementation | Binary                              |+| :------------- | :---------------------------------- |+| Rust           | `veins-rust v0.1.0 (veins-store 1)` |+| C++            | `veins v0.0.1 (veins-store 1)`      |+| Spectre        | `veins v0.0.1 (veins-store 1)`      |  ``` host:        Darwin arm64@@ -32,11 +32,11 @@  ### Summary -| Metric | Rust | C++ | Spectre | C++ / Rust | Spectre / Rust |-|:---|---:|---:|---:|---:|---:|-| Commit total [s] | 0.252 (0.250-0.262) | 0.280 (0.279-0.291) | 0.310 (0.309-0.330) | 1.11x | 1.23x |-| Checkout total [s] | 0.162 (0.161-0.165) | 0.175 (0.172-0.179) | 0.181 (0.179-0.196) | 1.08x | 1.12x |-| Store size [MiB] | 8.28 (8.28-8.37) | 8.28 (8.28-8.37) | 10.60 (10.60-10.69) | 1.00x | 1.28x |+| Metric             |                Rust |                 C++ |             Spectre | C++ / Rust | Spectre / Rust |+| :----------------- | ------------------: | ------------------: | ------------------: | ---------: | -------------: |+| Commit total [s]   | 0.252 (0.250-0.262) | 0.280 (0.279-0.291) | 0.310 (0.309-0.330) |      1.11x |          1.23x |+| Checkout total [s] | 0.162 (0.161-0.165) | 0.175 (0.172-0.179) | 0.181 (0.179-0.196) |      1.08x |          1.12x |+| Store size [MiB]   |    8.28 (8.28-8.37) |    8.28 (8.28-8.37) | 10.60 (10.60-10.69) |      1.00x |          1.28x |  Each cell is the median with the observed min-max range in parentheses. A ratio above 1 means the other implementation took longer or used more space than Rust.@@ -44,12 +44,12 @@ ### Repeats  | Repeat | Rust commit [s] | C++ commit [s] | Spectre commit [s] | Rust checkout [s] | C++ checkout [s] | Spectre checkout [s] |-|:---|---:|---:|---:|---:|---:|---:|-| 1 | 0.262 | 0.291 | 0.330 | 0.165 | 0.172 | 0.195 |-| 2 | 0.250 | 0.280 | 0.310 | 0.162 | 0.172 | 0.196 |-| 3 | 0.252 | 0.281 | 0.309 | 0.161 | 0.179 | 0.179 |-| 4 | 0.252 | 0.279 | 0.309 | 0.162 | 0.175 | 0.179 |-| 5 | 0.257 | 0.280 | 0.311 | 0.165 | 0.177 | 0.181 |+| :----- | --------------: | -------------: | -----------------: | ----------------: | ---------------: | -------------------: |+| 1      |           0.262 |          0.291 |              0.330 |             0.165 |            0.172 |                0.195 |+| 2      |           0.250 |          0.280 |              0.310 |             0.162 |            0.172 |                0.196 |+| 3      |           0.252 |          0.281 |              0.309 |             0.161 |            0.179 |                0.179 |+| 4      |           0.252 |          0.279 |              0.309 |             0.162 |            0.175 |                0.179 |+| 5      |           0.257 |          0.280 |              0.311 |             0.165 |            0.177 |                0.181 |  ### Notes --- a/xveins/bench/core_bench.py+++ b/xveins/bench/core_bench.py@@ -142,7 +142,9 @@     parser = argparse.ArgumentParser(description=__doc__)     root = Path(__file__).resolve().parents[2]     parser.add_argument("--spectre", type=Path, default=root / "veins" / "vn")-    parser.add_argument("--cpp", type=Path, default=root / "veins-cpprewrite" / "build" / "vn")+    parser.add_argument(+        "--cpp", type=Path, default=root / "veins-cpprewrite" / "build" / "vn"+    )     parser.add_argument(         "--rust", type=Path, default=root / "veins-rust" / "target" / "release" / "vn"     )@@ -199,11 +201,15 @@          def spread(label: str, index: int) -> str:             values = [row[index] for row in rows[label]]-            return f"{statistics.median(values):.3f} ({min(values):.3f}-{max(values):.3f})"+            return (+                f"{statistics.median(values):.3f} ({min(values):.3f}-{max(values):.3f})"+            )          def spread_mib(label: str) -> str:             values = [row[2] / (1024 * 1024) for row in rows[label]]-            return f"{statistics.median(values):.2f} ({min(values):.2f}-{max(values):.2f})"+            return (+                f"{statistics.median(values):.2f} ({min(values):.2f}-{max(values):.2f})"+            )          values = {             label: (median(label, 0), median(label, 1), median(label, 2))--- a/xveins/bench/net_bench.sh+++ b/xveins/bench/net_bench.sh@@ -21,7 +21,10 @@ SYS_PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"  case "$WORK" in-  ""|"/"|".") echo "refusing to use WORK='$WORK'" >&2; exit 1 ;;+"" | "/" | ".")+	echo "refusing to use WORK='$WORK'" >&2+	exit 1+	;; esac  CPP_DIR=$(CDPATH= cd -- "$(dirname -- "$VN_CPP")" && pwd)@@ -30,17 +33,17 @@ VN_SPECTRE="$SX_DIR/$(basename -- "$VN_SPECTRE")"  for tool in "$VN_CPP" "$VN_SPECTRE"; do-  if [ ! -x "$tool" ]; then-    echo "missing executable: $tool" >&2-    echo "build the C++ rewrite first: cmake --build $ROOT/build" >&2-    exit 1-  fi+	if [ ! -x "$tool" ]; then+		echo "missing executable: $tool" >&2+		echo "build the C++ rewrite first: cmake --build $ROOT/build" >&2+		exit 1+	fi done for tool in "$HYPERFINE" python3 openssl; do-  if ! command -v "$tool" >/dev/null 2>&1; then-    echo "required tool not found: $tool" >&2-    exit 1-  fi+	if ! command -v "$tool" >/dev/null 2>&1; then+		echo "required tool not found: $tool" >&2+		exit 1+	fi done  rm -rf "$WORK"@@ -55,14 +58,14 @@ SX_SSH_RUN="env XDG_CONFIG_HOME='$XDG_CONFIG_HOME' PATH='$WORK/fakebin:$SX_DIR:$SYS_PATH' '$VN_SPECTRE'"  run_cpp() {-  env XDG_CONFIG_HOME="$XDG_CONFIG_HOME" PATH="$CPP_DIR:$SYS_PATH" "$VN_CPP" "$@"+	env XDG_CONFIG_HOME="$XDG_CONFIG_HOME" PATH="$CPP_DIR:$SYS_PATH" "$VN_CPP" "$@" } run_sx() {-  env XDG_CONFIG_HOME="$XDG_CONFIG_HOME" PATH="$SX_DIR:$SYS_PATH" "$VN_SPECTRE" "$@"+	env XDG_CONFIG_HOME="$XDG_CONFIG_HOME" PATH="$SX_DIR:$SYS_PATH" "$VN_SPECTRE" "$@" }  wait_port() {-  python3 - "$1" <<'PY'+	python3 - "$1" <<'PY' import socket, sys, time port = int(sys.argv[1]) for _ in range(100):@@ -80,7 +83,7 @@ }  generate_small_files() {-  python3 - "$1" "$2" "$3" <<'PY'+	python3 - "$1" "$2" "$3" <<'PY' import os, sys root, start, stop = sys.argv[1], int(sys.argv[2]), int(sys.argv[3]) body = ("abcdefghijklmnopqrstuvwxyz" * 70)[:1800]@@ -100,17 +103,17 @@ # Keys and access # --------------------------------------------------------------------------- -run_cpp key generate benchkey > "$WORK/key.txt"+run_cpp key generate benchkey >"$WORK/key.txt" PUB=$(awk '/public key:/ {print $3}' "$WORK/key.txt") if [ -z "$PUB" ]; then-  echo "could not generate the benchmark key" >&2-  exit 1+	echo "could not generate the benchmark key" >&2+	exit 1 fi run_cpp auth use benchkey >/dev/null  grant_access() {-  ( cd "$1" && run_cpp access anonymous on && \-    run_cpp access add -role write -key "$PUB" -name bench >/dev/null )+	(cd "$1" && run_cpp access anonymous on &&+		run_cpp access add -role write -key "$PUB" -name bench >/dev/null) }  # ---------------------------------------------------------------------------@@ -118,31 +121,31 @@ # ---------------------------------------------------------------------------  (-  cd "$WORK/bench_src"-  run_sx init . >/dev/null-  generate_small_files . 0 12-  python3 - <<'PY'+	cd "$WORK/bench_src"+	run_sx init . >/dev/null+	generate_small_files . 0 12+	python3 - <<'PY' import os with open("big_old.bin", "wb") as handle:     handle.write(os.urandom(2 * 1024 * 1024)) PY-  run_sx go -m "base commit" >/dev/null-  # Point oldbig at the real base commit, not the movable working-copy commit.-  BASE_CHANGE=$(run_sx log | awk '/base commit/ {print $2}' | tail -1)-  if [ -z "$BASE_CHANGE" ]; then-    echo "could not resolve the base commit" >&2-    exit 1-  fi-  run_sx bmk set oldbig -rev "$BASE_CHANGE" >/dev/null-  rm -f big_old.bin-  generate_small_files . 12 18-  python3 - <<'PY'+	run_sx go -m "base commit" >/dev/null+	# Point oldbig at the real base commit, not the movable working-copy commit.+	BASE_CHANGE=$(run_sx log | awk '/base commit/ {print $2}' | tail -1)+	if [ -z "$BASE_CHANGE" ]; then+		echo "could not resolve the base commit" >&2+		exit 1+	fi+	run_sx bmk set oldbig -rev "$BASE_CHANGE" >/dev/null+	rm -f big_old.bin+	generate_small_files . 12 18+	python3 - <<'PY' import os with open("big_head.bin", "wb") as handle:     handle.write(os.urandom(1 * 1024 * 1024)) PY-  run_sx go -m "head commit" >/dev/null-  run_sx bmk set main >/dev/null+	run_sx go -m "head commit" >/dev/null+	run_sx bmk set main >/dev/null ) grant_access "$WORK/bench_src" @@ -149,11 +152,11 @@ # A separate small repository for push, so a push does not transfer the large # dataset. The reference pushes all reachable objects, as does the rewrite. (-  cd "$WORK/push_pristine"-  run_sx init . >/dev/null-  generate_small_files . 0 1-  run_sx go -m "push base" >/dev/null-  run_sx bmk set main >/dev/null+	cd "$WORK/push_pristine"+	run_sx init . >/dev/null+	generate_small_files . 0 1+	run_sx go -m "push base" >/dev/null+	run_sx bmk set main >/dev/null ) grant_access "$WORK/push_pristine" @@ -162,25 +165,25 @@ # ---------------------------------------------------------------------------  run_cpp clone "file://$WORK/bench_src" "$WORK/fetch_pristine_cpp" -blobs:all >/dev/null-run_sx  clone "file://$WORK/bench_src" "$WORK/fetch_pristine_sx" -blobs:all >/dev/null+run_sx clone "file://$WORK/bench_src" "$WORK/fetch_pristine_sx" -blobs:all >/dev/null run_cpp clone "file://$WORK/bench_src" "$WORK/lazy_pristine_cpp" -blobs:none >/dev/null-run_sx  clone "file://$WORK/bench_src" "$WORK/lazy_pristine_sx" -blobs:none >/dev/null+run_sx clone "file://$WORK/bench_src" "$WORK/lazy_pristine_sx" -blobs:none >/dev/null  run_cpp clone "file://$WORK/push_pristine" "$WORK/push_client_cpp" >/dev/null-run_sx  clone "file://$WORK/push_pristine" "$WORK/push_client_sx" >/dev/null+run_sx clone "file://$WORK/push_pristine" "$WORK/push_client_sx" >/dev/null (-  cd "$WORK/push_client_cpp"-  printf 'bench push\n' > push.txt-  run_cpp go -m "bench push" >/dev/null-  run_cpp bmk set main >/dev/null-  run_cpp remote set-url origin "file://$WORK/push_srv_cpp"+	cd "$WORK/push_client_cpp"+	printf 'bench push\n' >push.txt+	run_cpp go -m "bench push" >/dev/null+	run_cpp bmk set main >/dev/null+	run_cpp remote set-url origin "file://$WORK/push_srv_cpp" ) (-  cd "$WORK/push_client_sx"-  printf 'bench push\n' > push.txt-  run_sx go -m "bench push" >/dev/null-  run_sx bmk set main >/dev/null-  run_sx remote set-url origin "file://$WORK/push_srv_sx"+	cd "$WORK/push_client_sx"+	printf 'bench push\n' >push.txt+	run_sx go -m "bench push" >/dev/null+	run_sx bmk set main >/dev/null+	run_sx remote set-url origin "file://$WORK/push_srv_sx" )  # ---------------------------------------------------------------------------@@ -187,7 +190,7 @@ # ssh shim: execute the remote `vn serve -stdio ...` command locally. # --------------------------------------------------------------------------- -cat > "$WORK/fakebin/ssh" <<'SH'+cat >"$WORK/fakebin/ssh" <<'SH' #!/bin/sh while [ $# -gt 0 ]; do   case "$1" in@@ -206,7 +209,7 @@ # TLS certificate and servers # --------------------------------------------------------------------------- -cat > "$WORK/openssl.cnf" <<EOF+cat >"$WORK/openssl.cnf" <<EOF [req] distinguished_name = dn x509_extensions = v3_req@@ -220,13 +223,13 @@ IP.1 = 127.0.0.1 EOF openssl req -x509 -newkey rsa:2048 -nodes \-  -keyout "$WORK/key.pem" -out "$WORK/cert.pem" \-  -days 2 -config "$WORK/openssl.cnf" >/dev/null 2>&1-PIN=$(openssl x509 -in "$WORK/cert.pem" -noout -fingerprint -sha256 \-  | sed 's/.*=//;s/://g' | tr 'A-F' 'a-f')+	-keyout "$WORK/key.pem" -out "$WORK/cert.pem" \+	-days 2 -config "$WORK/openssl.cnf" >/dev/null 2>&1+PIN=$(openssl x509 -in "$WORK/cert.pem" -noout -fingerprint -sha256 |+	sed 's/.*=//;s/://g' | tr 'A-F' 'a-f')  free_port() {-  python3 - <<'PY'+	python3 - <<'PY' import socket sock = socket.socket() sock.bind(("127.0.0.1", 0))@@ -241,20 +244,20 @@ CPP_PID="" SX_PID="" cleanup() {-  if [ -n "$CPP_PID" ]; then kill "$CPP_PID" 2>/dev/null || true; fi-  if [ -n "$SX_PID" ]; then kill "$SX_PID" 2>/dev/null || true; fi-  if [ -n "$CPP_PID" ]; then wait "$CPP_PID" 2>/dev/null || true; fi-  if [ -n "$SX_PID" ]; then wait "$SX_PID" 2>/dev/null || true; fi+	if [ -n "$CPP_PID" ]; then kill "$CPP_PID" 2>/dev/null || true; fi+	if [ -n "$SX_PID" ]; then kill "$SX_PID" 2>/dev/null || true; fi+	if [ -n "$CPP_PID" ]; then wait "$CPP_PID" 2>/dev/null || true; fi+	if [ -n "$SX_PID" ]; then wait "$SX_PID" 2>/dev/null || true; fi } trap cleanup EXIT INT TERM  "$VN_CPP" serve -listen "127.0.0.1:$PORT_CPP" -root "$WORK" \-  -tls-cert "$WORK/cert.pem" -tls-key "$WORK/key.pem" \-  >"$WORK/cpp-server.log" 2>&1 &+	-tls-cert "$WORK/cert.pem" -tls-key "$WORK/key.pem" \+	>"$WORK/cpp-server.log" 2>&1 & CPP_PID=$! "$VN_SPECTRE" serve -listen "127.0.0.1:$PORT_SX" -root "$WORK" \-  -tls-cert "$WORK/cert.pem" -tls-key "$WORK/key.pem" \-  >"$WORK/sx-server.log" 2>&1 &+	-tls-cert "$WORK/cert.pem" -tls-key "$WORK/key.pem" \+	>"$WORK/sx-server.log" 2>&1 & SX_PID=$! wait_port "$PORT_CPP" wait_port "$PORT_SX"@@ -262,12 +265,12 @@ # A tiny repository used only for whoami over TLS. mkdir -p "$WORK/whoami_repo" (-  cd "$WORK/whoami_repo"-  run_cpp init . >/dev/null-  run_cpp remote add tls_cpp "veins://localhost:$PORT_CPP/bench_src" \-    -key:benchkey -pin:"$PIN" >/dev/null-  run_cpp remote add tls_sx "veins://localhost:$PORT_SX/bench_src" \-    -key:benchkey -pin:"$PIN" >/dev/null+	cd "$WORK/whoami_repo"+	run_cpp init . >/dev/null+	run_cpp remote add tls_cpp "veins://localhost:$PORT_CPP/bench_src" \+		-key:benchkey -pin:"$PIN" >/dev/null+	run_cpp remote add tls_sx "veins://localhost:$PORT_SX/bench_src" \+		-key:benchkey -pin:"$PIN" >/dev/null )  # ---------------------------------------------------------------------------@@ -275,35 +278,35 @@ # ---------------------------------------------------------------------------  write_prepare() {-  path="$WORK/$1"-  shift-  {-    echo '#!/bin/sh'-    printf '%s\n' "$@"-  } > "$path"-  chmod +x "$path"+	path="$WORK/$1"+	shift+	{+		echo '#!/bin/sh'+		printf '%s\n' "$@"+	} >"$path"+	chmod +x "$path" }  write_prepare prepare_clone.sh \-  "rm -rf '$WORK/clone_cpp' '$WORK/clone_sx'"+	"rm -rf '$WORK/clone_cpp' '$WORK/clone_sx'" write_prepare prepare_fetch.sh \-  "rm -rf '$WORK/fetch_cpp' '$WORK/fetch_sx'" \-  "cp -R '$WORK/fetch_pristine_cpp' '$WORK/fetch_cpp'" \-  "cp -R '$WORK/fetch_pristine_sx' '$WORK/fetch_sx'"+	"rm -rf '$WORK/fetch_cpp' '$WORK/fetch_sx'" \+	"cp -R '$WORK/fetch_pristine_cpp' '$WORK/fetch_cpp'" \+	"cp -R '$WORK/fetch_pristine_sx' '$WORK/fetch_sx'" write_prepare prepare_lazy.sh \-  "rm -rf '$WORK/lazy_cpp' '$WORK/lazy_sx'" \-  "cp -R '$WORK/lazy_pristine_cpp' '$WORK/lazy_cpp'" \-  "cp -R '$WORK/lazy_pristine_sx' '$WORK/lazy_sx'"+	"rm -rf '$WORK/lazy_cpp' '$WORK/lazy_sx'" \+	"cp -R '$WORK/lazy_pristine_cpp' '$WORK/lazy_cpp'" \+	"cp -R '$WORK/lazy_pristine_sx' '$WORK/lazy_sx'" write_prepare prepare_push.sh \-  "rm -rf '$WORK/push_srv_cpp' '$WORK/push_srv_sx'" \-  "cp -R '$WORK/push_pristine' '$WORK/push_srv_cpp'" \-  "cp -R '$WORK/push_pristine' '$WORK/push_srv_sx'"+	"rm -rf '$WORK/push_srv_cpp' '$WORK/push_srv_sx'" \+	"cp -R '$WORK/push_pristine' '$WORK/push_srv_cpp'" \+	"cp -R '$WORK/push_pristine' '$WORK/push_srv_sx'" write_prepare prepare_ssh.sh \-  "rm -rf '$WORK/clone_ssh_cpp' '$WORK/clone_ssh_sx'"+	"rm -rf '$WORK/clone_ssh_cpp' '$WORK/clone_ssh_sx'" write_prepare prepare_tls.sh \-  "rm -rf '$WORK/clone_tls_cpp' '$WORK/clone_tls_sx'"+	"rm -rf '$WORK/clone_tls_cpp' '$WORK/clone_tls_sx'" write_prepare prepare_noop.sh \-  "exit 0"+	"exit 0"  # --------------------------------------------------------------------------- # Run hyperfine@@ -310,20 +313,20 @@ # ---------------------------------------------------------------------------  run_pair() {-  name=$1-  prepare=$2-  runs=$3-  warmup=$4-  cpp_cmd=$5-  sx_cmd=$6-  echo-  echo "== $name =="-  "$HYPERFINE" --style basic --warmup "$warmup" --runs "$runs" \-    --prepare "$prepare" \-    --export-markdown "$WORK/$name.md" \-    --export-json "$WORK/$name.json" \-    -n "C++" "$cpp_cmd" \-    -n "Spectre" "$sx_cmd"+	name=$1+	prepare=$2+	runs=$3+	warmup=$4+	cpp_cmd=$5+	sx_cmd=$6+	echo+	echo "== $name =="+	"$HYPERFINE" --style basic --warmup "$warmup" --runs "$runs" \+		--prepare "$prepare" \+		--export-markdown "$WORK/$name.md" \+		--export-json "$WORK/$name.json" \+		-n "C++" "$cpp_cmd" \+		-n "Spectre" "$sx_cmd" }  SSH_URL="ssh://localhost/$WORK/bench_src"@@ -331,36 +334,36 @@ TLS_SX_URL="veins://localhost:$PORT_SX/bench_src"  run_pair clone-file "$WORK/prepare_clone.sh" "$RUNS" 1 \-  "cd '$WORK' && $CPP_RUN clone 'file://$WORK/bench_src' '$WORK/clone_cpp'" \-  "cd '$WORK' && $SX_RUN clone 'file://$WORK/bench_src' '$WORK/clone_sx'"+	"cd '$WORK' && $CPP_RUN clone 'file://$WORK/bench_src' '$WORK/clone_cpp'" \+	"cd '$WORK' && $SX_RUN clone 'file://$WORK/bench_src' '$WORK/clone_sx'"  run_pair fetch-file "$WORK/prepare_fetch.sh" "$RUNS" 1 \-  "cd '$WORK/fetch_cpp' && $CPP_RUN fetch origin" \-  "cd '$WORK/fetch_sx' && $SX_RUN fetch origin"+	"cd '$WORK/fetch_cpp' && $CPP_RUN fetch origin" \+	"cd '$WORK/fetch_sx' && $SX_RUN fetch origin"  run_pair lazy-checkout-file "$WORK/prepare_lazy.sh" "$RUNS" 1 \-  "cd '$WORK/lazy_cpp' && $CPP_RUN co oldbig" \-  "cd '$WORK/lazy_sx' && $SX_RUN co oldbig"+	"cd '$WORK/lazy_cpp' && $CPP_RUN co oldbig" \+	"cd '$WORK/lazy_sx' && $SX_RUN co oldbig"  run_pair push-file "$WORK/prepare_push.sh" "$RUNS" 1 \-  "cd '$WORK/push_client_cpp' && $CPP_RUN push origin main" \-  "cd '$WORK/push_client_sx' && $SX_RUN push origin main"+	"cd '$WORK/push_client_cpp' && $CPP_RUN push origin main" \+	"cd '$WORK/push_client_sx' && $SX_RUN push origin main"  run_pair whoami-file "$WORK/prepare_noop.sh" "$WHOAMI_RUNS" 2 \-  "cd '$WORK' && $CPP_RUN whoami 'file://$WORK/bench_src'" \-  "cd '$WORK' && $SX_RUN whoami 'file://$WORK/bench_src'"+	"cd '$WORK' && $CPP_RUN whoami 'file://$WORK/bench_src'" \+	"cd '$WORK' && $SX_RUN whoami 'file://$WORK/bench_src'"  run_pair clone-ssh "$WORK/prepare_ssh.sh" "$RUNS" 1 \-  "cd '$WORK' && $CPP_SSH_RUN clone '$SSH_URL' '$WORK/clone_ssh_cpp'" \-  "cd '$WORK' && $SX_SSH_RUN clone '$SSH_URL' '$WORK/clone_ssh_sx'"+	"cd '$WORK' && $CPP_SSH_RUN clone '$SSH_URL' '$WORK/clone_ssh_cpp'" \+	"cd '$WORK' && $SX_SSH_RUN clone '$SSH_URL' '$WORK/clone_ssh_sx'"  run_pair clone-tls "$WORK/prepare_tls.sh" "$RUNS" 1 \-  "cd '$WORK' && $CPP_RUN clone '$TLS_CPP_URL' '$WORK/clone_tls_cpp' -pin:'$PIN'" \-  "cd '$WORK' && $SX_RUN clone '$TLS_SX_URL' '$WORK/clone_tls_sx' -pin:'$PIN'"+	"cd '$WORK' && $CPP_RUN clone '$TLS_CPP_URL' '$WORK/clone_tls_cpp' -pin:'$PIN'" \+	"cd '$WORK' && $SX_RUN clone '$TLS_SX_URL' '$WORK/clone_tls_sx' -pin:'$PIN'"  run_pair whoami-tls "$WORK/prepare_noop.sh" "$WHOAMI_RUNS" 2 \-  "cd '$WORK/whoami_repo' && $CPP_RUN whoami tls_cpp" \-  "cd '$WORK/whoami_repo' && $SX_RUN whoami tls_sx"+	"cd '$WORK/whoami_repo' && $CPP_RUN whoami tls_cpp" \+	"cd '$WORK/whoami_repo' && $SX_RUN whoami tls_sx"  cleanup trap - 0 2 15@@ -369,7 +372,7 @@ # BENCHES.md # --------------------------------------------------------------------------- -python3 - "$WORK" > "$WORK/summary.md" <<'PY'+python3 - "$WORK" >"$WORK/summary.md" <<'PY' import json, os, sys work = sys.argv[1] names = [@@ -403,108 +406,108 @@ SX_VERSION=$("$VN_SPECTRE" version)  {-  echo "# veins benchmarks"-  echo-  echo "Two reproducible benchmark sets are kept here: a local-core comparison that includes"-  echo "the Rust subset, and the native network comparison between the C++ rewrite and Spectre."-  echo-  if [ -f "$ROOT/bench/core_bench.md" ]; then-    echo "## Local core: Rust subset vs C++ vs Spectre"-    echo-    cat "$ROOT/bench/core_bench.md"-    echo-  fi-  echo "## Networking: C++ rewrite vs Spectre"-  echo-  echo "Generated $(date -u '+%Y-%m-%d %H:%M:%S UTC') by \`bench/net_bench.sh\`."-  echo-  echo "The Rust subset is not included in this section because it does not implement a"-  echo "network transport."-  echo-  echo "### Environment"-  echo-  echo '```'-  echo "host:        $HOST_TEXT"-  echo "cpu:         $CPU_TEXT"-  echo "hyperfine:   $HYPERFINE_VERSION"-  echo "c++ vn:      $CPP_VERSION"-  echo "spectre vn:  $SX_VERSION"-  echo "runs:        $RUNS (clone/fetch/push/checkout), $WHOAMI_RUNS (whoami)"-  echo "warmup:      1 (clone/fetch/push/checkout), 2 (whoami)"-  echo '```'-  echo-  echo "### Dataset"-  echo-  echo "- \`bench_src\`: $FILE_COUNT working files, $DISK_SIZE on disk including packs."-  echo "  - 360 small text files in 18 directories."-  echo "  - 2 MiB \`big_old.bin\` in the \`oldbig\` history."-  echo "  - 1 MiB \`big_head.bin\` in \`main\`."-  echo "- \`push_pristine\`: a separate 20-file repository, so push does not transfer the large dataset."-  echo-  echo "### What each benchmark does"-  echo-  echo "| Benchmark | Operation |"-  echo "|:---|:---|"-  echo "| \`clone-file\` | Full clone over \`file://\`: handshake, refs, history, head chunks, checkout. Includes spawning one local server per run. |"-  echo "| \`fetch-file\` | \`vn fetch origin\` with no new remote refs. Both clients start from a full \`-blobs:all\` clone. |"-  echo "| \`lazy-checkout-file\` | \`vn co oldbig\` in a \`-blobs:none\` clone, fetching the 2 MiB old blob from the promisor over \`file://\`. |"-  echo "| \`push-file\` | Push one new commit from a prepared client to a freshly reset copy of \`push_pristine\` over \`file://\`. |"-  echo "| \`whoami-file\` | Connect, authenticate, \`WHOAMI\`, close over \`file://\`. |"-  echo "| \`clone-ssh\` | Full clone over \`ssh://\`, using a local \`ssh\` shim that runs the remote \`vn serve -stdio\` command. |"-  echo "| \`clone-tls\` | Full clone over TLS 1.3 with a pinned self-signed certificate. Uses long-running servers. |"-  echo "| \`whoami-tls\` | Connect, authenticate, \`WHOAMI\`, close over TLS 1.3. |"-  echo-  echo "Lower is better. Hyperfine reports wall-clock time; the relative column is against the fastest command."-  echo-  echo "### Summary"-  echo-  cat "$WORK/summary.md"-  echo-  echo "A ratio above 1 means Spectre took longer than C++."-  echo-  echo "### Results"-  echo-  echo "#### Clone over file://"-  cat "$WORK/clone-file.md"-  echo-  echo "#### Fetch over file://"-  cat "$WORK/fetch-file.md"-  echo-  echo "#### Lazy checkout over file://"-  cat "$WORK/lazy-checkout-file.md"-  echo-  echo "#### Push over file://"-  cat "$WORK/push-file.md"-  echo-  echo "#### Whoami over file://"-  cat "$WORK/whoami-file.md"-  echo-  echo "#### Clone over ssh://"-  cat "$WORK/clone-ssh.md"-  echo-  echo "#### Clone over TLS 1.3"-  cat "$WORK/clone-tls.md"-  echo-  echo "#### Whoami over TLS 1.3"-  cat "$WORK/whoami-tls.md"-  echo-  echo "### Notes"-  echo-  echo "- Spectre clone destinations are absolute paths on macOS. The reference checkout hardcodes Linux's \`AT_FDCWD\` value (\`-100\`); with a relative destination it cannot open the working directory on macOS."-  echo "- \`file://\` and \`ssh://\` include server process startup. \`clone-tls\` and \`whoami-tls\` use long-running servers, so they isolate protocol and TLS cost more closely."-  echo "- These runs reproduce the reference's transfer behavior: fetch \`haves\` are operation heads (so metadata is re-sent), and push sends all objects reachable from the bookmark rather than using \`HAVE_QUERY\`."-  echo "- Lazy checkout fetches one missing chunk per promisor connection in both implementations, so it is intentionally a worst-case/read-ahead-free measurement."-  echo "- \`push-file\` is only a few milliseconds of real work; process startup noise can dominate. Read the min/max columns alongside the mean."-  echo "- Treat differences below roughly 10 ms as noise; this is a single-machine run, not a controlled lab measurement."-  echo-  echo "### Reproduce"-  echo-  echo '```sh'-  echo "cd veins-cpprewrite"-  echo "cmake -S . -B build && cmake --build build -j"-  echo "./bench/net_bench.sh"-  echo '```'-} > "$OUT"+	echo "# veins benchmarks"+	echo+	echo "Two reproducible benchmark sets are kept here: a local-core comparison that includes"+	echo "the Rust subset, and the native network comparison between the C++ rewrite and Spectre."+	echo+	if [ -f "$ROOT/bench/core_bench.md" ]; then+		echo "## Local core: Rust subset vs C++ vs Spectre"+		echo+		cat "$ROOT/bench/core_bench.md"+		echo+	fi+	echo "## Networking: C++ rewrite vs Spectre"+	echo+	echo "Generated $(date -u '+%Y-%m-%d %H:%M:%S UTC') by \`bench/net_bench.sh\`."+	echo+	echo "The Rust subset is not included in this section because it does not implement a"+	echo "network transport."+	echo+	echo "### Environment"+	echo+	echo '```'+	echo "host:        $HOST_TEXT"+	echo "cpu:         $CPU_TEXT"+	echo "hyperfine:   $HYPERFINE_VERSION"+	echo "c++ vn:      $CPP_VERSION"+	echo "spectre vn:  $SX_VERSION"+	echo "runs:        $RUNS (clone/fetch/push/checkout), $WHOAMI_RUNS (whoami)"+	echo "warmup:      1 (clone/fetch/push/checkout), 2 (whoami)"+	echo '```'+	echo+	echo "### Dataset"+	echo+	echo "- \`bench_src\`: $FILE_COUNT working files, $DISK_SIZE on disk including packs."+	echo "  - 360 small text files in 18 directories."+	echo "  - 2 MiB \`big_old.bin\` in the \`oldbig\` history."+	echo "  - 1 MiB \`big_head.bin\` in \`main\`."+	echo "- \`push_pristine\`: a separate 20-file repository, so push does not transfer the large dataset."+	echo+	echo "### What each benchmark does"+	echo+	echo "| Benchmark | Operation |"+	echo "|:---|:---|"+	echo "| \`clone-file\` | Full clone over \`file://\`: handshake, refs, history, head chunks, checkout. Includes spawning one local server per run. |"+	echo "| \`fetch-file\` | \`vn fetch origin\` with no new remote refs. Both clients start from a full \`-blobs:all\` clone. |"+	echo "| \`lazy-checkout-file\` | \`vn co oldbig\` in a \`-blobs:none\` clone, fetching the 2 MiB old blob from the promisor over \`file://\`. |"+	echo "| \`push-file\` | Push one new commit from a prepared client to a freshly reset copy of \`push_pristine\` over \`file://\`. |"+	echo "| \`whoami-file\` | Connect, authenticate, \`WHOAMI\`, close over \`file://\`. |"+	echo "| \`clone-ssh\` | Full clone over \`ssh://\`, using a local \`ssh\` shim that runs the remote \`vn serve -stdio\` command. |"+	echo "| \`clone-tls\` | Full clone over TLS 1.3 with a pinned self-signed certificate. Uses long-running servers. |"+	echo "| \`whoami-tls\` | Connect, authenticate, \`WHOAMI\`, close over TLS 1.3. |"+	echo+	echo "Lower is better. Hyperfine reports wall-clock time; the relative column is against the fastest command."+	echo+	echo "### Summary"+	echo+	cat "$WORK/summary.md"+	echo+	echo "A ratio above 1 means Spectre took longer than C++."+	echo+	echo "### Results"+	echo+	echo "#### Clone over file://"+	cat "$WORK/clone-file.md"+	echo+	echo "#### Fetch over file://"+	cat "$WORK/fetch-file.md"+	echo+	echo "#### Lazy checkout over file://"+	cat "$WORK/lazy-checkout-file.md"+	echo+	echo "#### Push over file://"+	cat "$WORK/push-file.md"+	echo+	echo "#### Whoami over file://"+	cat "$WORK/whoami-file.md"+	echo+	echo "#### Clone over ssh://"+	cat "$WORK/clone-ssh.md"+	echo+	echo "#### Clone over TLS 1.3"+	cat "$WORK/clone-tls.md"+	echo+	echo "#### Whoami over TLS 1.3"+	cat "$WORK/whoami-tls.md"+	echo+	echo "### Notes"+	echo+	echo "- Spectre clone destinations are absolute paths on macOS. The reference checkout hardcodes Linux's \`AT_FDCWD\` value (\`-100\`); with a relative destination it cannot open the working directory on macOS."+	echo "- \`file://\` and \`ssh://\` include server process startup. \`clone-tls\` and \`whoami-tls\` use long-running servers, so they isolate protocol and TLS cost more closely."+	echo "- These runs reproduce the reference's transfer behavior: fetch \`haves\` are operation heads (so metadata is re-sent), and push sends all objects reachable from the bookmark rather than using \`HAVE_QUERY\`."+	echo "- Lazy checkout fetches one missing chunk per promisor connection in both implementations, so it is intentionally a worst-case/read-ahead-free measurement."+	echo "- \`push-file\` is only a few milliseconds of real work; process startup noise can dominate. Read the min/max columns alongside the mean."+	echo "- Treat differences below roughly 10 ms as noise; this is a single-machine run, not a controlled lab measurement."+	echo+	echo "### Reproduce"+	echo+	echo '```sh'+	echo "cd veins-cpprewrite"+	echo "cmake -S . -B build && cmake --build build -j"+	echo "./bench/net_bench.sh"+	echo '```'+} >"$OUT"  echo echo "wrote $OUT"--- a/xveins/src/auth.cpp+++ b/xveins/src/auth.cpp@@ -127,7 +127,8 @@   if (start >= input.size())     return std::nullopt;   const auto slash = input.find('/', start);-  const std::size_t end = slash == std::string_view::npos ? input.size() : slash;+  const std::size_t end =+      slash == std::string_view::npos ? input.size() : slash;   if (end <= start)     return std::nullopt;   const std::string_view raw = input.substr(start, end - start);@@ -498,7 +499,8 @@   kept.reserve(access.entries.size());   for (const auto &entry : access.entries) {     const bool match_fingerprint =-        !fingerprint.empty() && key_fingerprint(entry.public_key) == fingerprint;+        !fingerprint.empty() &&+        key_fingerprint(entry.public_key) == fingerprint;     const bool match_name = !name.empty() && entry.name == name;     if (match_fingerprint || match_name) {       removed = true;--- a/xveins/src/bookmark.cpp+++ b/xveins/src/bookmark.cpp@@ -32,8 +32,8 @@     const auto c = static_cast<unsigned char>(raw);     if (c == 0 || c == ' ' || c < 32 || c == 127)       return false;-    if (c == '~' || c == '^' || c == ':' || c == '?' || c == '*' ||-        c == '[' || c == '\\')+    if (c == '~' || c == '^' || c == ':' || c == '?' || c == '*' || c == '[' ||+        c == '\\')       return false;   }   if (bmk_contains(name, "..") || bmk_contains(name, "@{") ||@@ -151,8 +151,8 @@   if (!changed) {     (void)set_current_bookmark(*root, name);     info_prefix();-    std::cout << "bookmark " << name << " is already at " << short_commit(*target)-              << "\n";+    std::cout << "bookmark " << name << " is already at "+              << short_commit(*target) << "\n";     return 0;   } @@ -212,8 +212,7 @@     return 1;   }   auto &bookmarks = tx->view().bookmarks;-  bookmarks.erase(bookmarks.begin() +-                  static_cast<std::ptrdiff_t>(*existing));+  bookmarks.erase(bookmarks.begin() + static_cast<std::ptrdiff_t>(*existing));   rebuild_heads(tx->view());   const auto status = tx->finish("bookmark delete " + name);   if (!status)@@ -327,7 +326,8 @@   std::cout << "manage named, movable pointers to commits (branches)\n";   std::cout << "\n";   std::cout << "subcommands:\n";-  std::cout << "  set <name> [-rev <rev>]   create or move a bookmark (default: @)\n";+  std::cout+      << "  set <name> [-rev <rev>]   create or move a bookmark (default: @)\n";   std::cout << "  mv <name> [-rev <rev>]    alias of set\n";   std::cout << "  ls [-no-col-titles]       list bookmarks\n";   std::cout << "  rm <name>                 delete a bookmark\n";--- a/xveins/src/cfg.cpp+++ b/xveins/src/cfg.cpp@@ -14,13 +14,11 @@ namespace {  std::string_view cfg_trim(std::string_view text) {-  while (!text.empty() &&-         (text.front() == ' ' || text.front() == '\t' ||-          text.front() == '\r' || text.front() == '\n'))+  while (!text.empty() && (text.front() == ' ' || text.front() == '\t' ||+                           text.front() == '\r' || text.front() == '\n'))     text.remove_prefix(1);-  while (!text.empty() &&-         (text.back() == ' ' || text.back() == '\t' ||-          text.back() == '\r' || text.back() == '\n'))+  while (!text.empty() && (text.back() == ' ' || text.back() == '\t' ||+                           text.back() == '\r' || text.back() == '\n'))     text.remove_suffix(1);   return text; }@@ -148,11 +146,11 @@     const std::string &arg = args[i];     if (!end_flags && arg == "--") {       end_flags = true;-    } else if (!end_flags && (arg == "-global" || arg == "--global" ||-                              arg == "-g")) {+    } else if (!end_flags &&+               (arg == "-global" || arg == "--global" || arg == "-g")) {       global = true;-    } else if (!end_flags && (arg == "-list" || arg == "--list" ||-                              arg == "-l")) {+    } else if (!end_flags &&+               (arg == "-list" || arg == "--list" || arg == "-l")) {       list = true;     } else if (!end_flags && (arg == "-unset" || arg == "--unset")) {       unset = true;@@ -216,8 +214,7 @@     return cfg_list(root ? &*root : nullptr, global);   if (positional.size() == 1)     return cfg_get(root ? &*root : nullptr, global, positional[0]);-  return cfg_set(root ? &*root : nullptr, global, positional[0],-                 positional[1]);+  return cfg_set(root ? &*root : nullptr, global, positional[0], positional[1]); }  } // namespace vn--- a/xveins/src/cli.cpp+++ b/xveins/src/cli.cpp@@ -580,8 +580,7 @@   bool end_flags = false;   std::optional<std::size_t> limit;   bool first = false;-  auto parse_count = [](std::string_view text,-                        std::size_t &out) -> bool {+  auto parse_count = [](std::string_view text, std::size_t &out) -> bool {     if (text.empty())       return false;     std::size_t value = 0;@@ -2044,8 +2043,10 @@   std::cout << "show commit history, newest first\n\n";   std::cout << "options:\n";   std::cout << "  -rev <revset>             show only the given revision set\n";-  std::cout << "  -lN, -l <N>               show the last N commits (newest N)\n";-  std::cout << "  -fN, -f <N>               show the first N commits (oldest N)\n";+  std::cout+      << "  -lN, -l <N>               show the last N commits (newest N)\n";+  std::cout+      << "  -fN, -f <N>               show the first N commits (oldest N)\n";   std::cout << "  -no-col-titles            omit column titles\n"; } @@ -2143,7 +2144,8 @@   std::cout << "usage: vn bmk <set|mv|ls|rm> ...\n\n";   std::cout << "manage named, movable pointers to commits (branches)\n\n";   std::cout << "subcommands:\n";-  std::cout << "  set <name> [-rev <rev>]   create or move a bookmark (default: @)\n";+  std::cout+      << "  set <name> [-rev <rev>]   create or move a bookmark (default: @)\n";   std::cout << "  mv <name> [-rev <rev>]    alias of set\n";   std::cout << "  ls [-no-col-titles]       list bookmarks\n";   std::cout << "  rm <name>                 delete a bookmark\n\n";@@ -2157,7 +2159,8 @@   std::cout << "usage: vn tag <set|ls|rm|latest> ...\n\n";   std::cout << "manage named pointers to commits (tags)\n\n";   std::cout << "subcommands:\n";-  std::cout << "  set <name> [-rev <rev>]   create or move a tag (default: @)\n";+  std::cout+      << "  set <name> [-rev <rev>]   create or move a tag (default: @)\n";   std::cout << "  ls [-no-col-titles]       list tags\n";   std::cout << "  rm <name>                 delete a tag\n";   std::cout << "  latest                    print the latest tag name\n\n";@@ -2181,14 +2184,15 @@ void show_rm() {   std::cout << "usage: vn rm [-delete] <path>...\n\n";   std::cout << "remove paths from the working-copy tree\n\n";-  std::cout-      << "files stay on disk by default. Arguments may be paths or globs and are\n";-  std::cout-      << "resolved relative to the current directory. Supported wildcards are\n";-  std::cout << "'*', '?', and '**'; '*' and '?' do not cross directory separators.\n\n";+  std::cout << "files stay on disk by default. Arguments may be paths or globs "+               "and are\n";+  std::cout << "resolved relative to the current directory. Supported "+               "wildcards are\n";+  std::cout << "'*', '?', and '**'; '*' and '?' do not cross directory "+               "separators.\n\n";   std::cout << "options:\n";-  std::cout-      << "  -delete                   delete matching files from disk after untracking\n";+  std::cout << "  -delete                   delete matching files from disk "+               "after untracking\n"; }  void show_mv() {@@ -2200,10 +2204,10 @@ void show_ex() {   std::cout << "usage: vn ex <pattern>...\n\n";   std::cout << "append ignore patterns to the repository root .vnexclude\n\n";-  std::cout-      << "patterns use gitignore syntax and are resolved relative to the current\n";-  std::cout-      << "directory. Quote wildcard patterns so the shell does not expand them:\n";+  std::cout << "patterns use gitignore syntax and are resolved relative to the "+               "current\n";+  std::cout << "directory. Quote wildcard patterns so the shell does not "+               "expand them:\n";   std::cout << "  vn ex '*.dSYM'\n"; } @@ -2220,16 +2224,16 @@  void show_merge() {   std::cout << "usage: vn merge <rev>...\n\n";+  std::cout << "create a merge commit from the working-copy commit and the "+               "revisions\n";   std::cout-      << "create a merge commit from the working-copy commit and the revisions\n";-  std::cout       << "the merge never fails; conflicts are stored as conflict values\n"; }  void show_rebase() {   std::cout << "usage: vn rebase -s <rev> -d <rev>\n\n";-  std::cout-      << "rewrite the source change and its descendants onto the destination\n\n";+  std::cout << "rewrite the source change and its descendants onto the "+               "destination\n\n";   std::cout << "options:\n";   std::cout << "  -s, -source <rev>         first change to rewrite\n";   std::cout << "  -d, -destination <rev>    new parent\n";@@ -2237,8 +2241,8 @@  void show_xs() {   std::cout << "usage: vn xs [-porcelain]\n\n";-  std::cout-      << "list conflicted paths and, for text conflicts, conflicting line ranges\n\n";+  std::cout << "list conflicted paths and, for text conflicts, conflicting "+               "line ranges\n\n";   std::cout << "porcelain columns (tab-separated):\n";   std::cout << "  path, kind, base-ranges, ours-ranges, theirs-ranges\n"; }@@ -2247,10 +2251,10 @@   std::cout       << "usage: vn resolve [-take ours|theirs|base] [-tool <cmd>] <path>...\n";   std::cout << "       vn resolve -list\n\n";-  std::cout-      << "resolve conflicted paths. Without -take, the current file content is\n";-  std::cout-      << "recorded as the resolution. -tool substitutes $BASE, $OURS, $THEIRS,\n";+  std::cout << "resolve conflicted paths. Without -take, the current file "+               "content is\n";+  std::cout << "recorded as the resolution. -tool substitutes $BASE, $OURS, "+               "$THEIRS,\n";   std::cout << "and $OUTPUT in the command.\n"; } @@ -2258,10 +2262,14 @@   std::cout << "usage: vn git <subcommand> [arguments]\n\n";   std::cout << "git bridge commands:\n";   std::cout << "  import [-source:<gitdir>] [path]\n";-  std::cout << "                            import reachable git commits and refs\n";-  std::cout << "  export [path]             export commits into the git mirror\n";-  std::cout << "  materialize [path]        replace lazy git blobs with stored blobs\n";-  std::cout << "  fetch [<remote>] [path]   git fetch into the mirror, then import\n";+  std::cout+      << "                            import reachable git commits and refs\n";+  std::cout+      << "  export [path]             export commits into the git mirror\n";+  std::cout << "  materialize [path]        replace lazy git blobs with stored "+               "blobs\n";+  std::cout+      << "  fetch [<remote>] [path]   git fetch into the mirror, then import\n";   std::cout << "  push [<remote>] <bookmark> [path]\n";   std::cout << "                            export and git push a bookmark\n";   std::cout << "  remote <add|list|remove>  manage git remotes\n\n";@@ -2275,13 +2283,15 @@   std::cout << "arguments:\n";   std::cout << "  [path]                    veins repository (default: .)\n\n";   std::cout << "options:\n";-  std::cout << "  -source:<gitdir>          source git root to mirror (a directory "-               "containing .git)\n";+  std::cout+      << "  -source:<gitdir>          source git root to mirror (a directory "+         "containing .git)\n"; }  void show_git_export() {   std::cout << "usage: vn git export [path]\n\n";-  std::cout << "export commits reachable from bookmarks and tags into .veins/git\n";+  std::cout+      << "export commits reachable from bookmarks and tags into .veins/git\n"; }  void show_git_materialize() {--- a/xveins/src/common.cpp+++ b/xveins/src/common.cpp@@ -1449,12 +1449,10 @@       continue;     }     const std::string_view k = trim_view(t.substr(0, eq));-    const bool remove_name =-        (in_user && want_name && k == "name") ||-        (!in_user && want_name && k == "user.name");-    const bool remove_email =-        (in_user && want_email && k == "email") ||-        (!in_user && want_email && k == "user.email");+    const bool remove_name = (in_user && want_name && k == "name") ||+                             (!in_user && want_name && k == "user.name");+    const bool remove_email = (in_user && want_email && k == "email") ||+                              (!in_user && want_email && k == "user.email");     if (!remove_name && !remove_email)       out.push_back(line);   }--- a/xveins/src/crypto.cpp+++ b/xveins/src/crypto.cpp@@ -71,9 +71,8 @@                     Bytes signature) {   if (signature.size() != 64)     return false;-  EVP_PKEY *pkey =-      EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519, nullptr,-                                  public_key.data(), public_key.size());+  EVP_PKEY *pkey = EVP_PKEY_new_raw_public_key(+      EVP_PKEY_ED25519, nullptr, public_key.data(), public_key.size());   if (!pkey)     return false;   EVP_MD_CTX *ctx = EVP_MD_CTX_new();@@ -83,8 +82,8 @@   }   bool ok = false;   if (EVP_DigestVerifyInit(ctx, nullptr, nullptr, nullptr, pkey) == 1 &&-      EVP_DigestVerify(ctx, signature.data(), signature.size(),-                       message.data(), message.size()) == 1) {+      EVP_DigestVerify(ctx, signature.data(), signature.size(), message.data(),+                       message.size()) == 1) {     ok = true;   }   EVP_MD_CTX_free(ctx);@@ -95,8 +94,7 @@ FingerprintBytes key_fingerprint_bytes(const PublicKey &public_key) {   blake3_hasher hasher;   blake3_hasher_init(&hasher);-  blake3_hasher_update(&hasher, FINGERPRINT_DOMAIN,-                       sizeof(FINGERPRINT_DOMAIN));+  blake3_hasher_update(&hasher, FINGERPRINT_DOMAIN, sizeof(FINGERPRINT_DOMAIN));   blake3_hasher_update(&hasher, public_key.data(), public_key.size());   std::array<std::uint8_t, 32> digest{};   blake3_hasher_finalize(&hasher, digest.data(), digest.size());--- a/xveins/src/crypto.h+++ b/xveins/src/crypto.h@@ -27,7 +27,8 @@ std::string base32_text(Bytes raw); // Unpadded base64url. std::string base64url_encode(Bytes raw);-std::optional<std::vector<std::uint8_t>> base64url_decode(std::string_view text);+std::optional<std::vector<std::uint8_t>>+base64url_decode(std::string_view text);  std::string format_public_key(const PublicKey &public_key); std::optional<PublicKey> parse_public_key(std::string_view text);--- a/xveins/src/git.cpp+++ b/xveins/src/git.cpp@@ -180,8 +180,7 @@                                      commit->root_tree); } -std::vector<Id> ordered_commits(Store &store,-                                const std::vector<Id> &roots) {+std::vector<Id> ordered_commits(Store &store, const std::vector<Id> &roots) {   struct Mark {     Id id{};     bool expanded = false;@@ -260,8 +259,8 @@   if (build.root == Id{})     return std::nullopt;   for (auto &object : build.objects) {-    const Id id = object.id ? *object.id-                            : object_id(object.type, bytes_of(object.body));+    const Id id =+        object.id ? *object.id : object_id(object.type, bytes_of(object.body));     (void)ctx.writer.add_known(object.type, id, std::move(object.body));   }   ctx.blobs[old_id] = build.root;@@ -337,8 +336,7 @@     ctx.conflicts[old_id] = old_id;     return old_id;   }-  const Id new_id =-      ctx.writer.add(TYPE_CONFLICT, encode_conflict(*conflict));+  const Id new_id = ctx.writer.add(TYPE_CONFLICT, encode_conflict(*conflict));   ctx.conflicts[old_id] = new_id;   ctx.changed = true;   return new_id;@@ -443,8 +441,8 @@   if (!path_is_dir(dir))     return false;   (void)run_git(dir, {"remote", "remove", std::string(remote)});-  return run_git(dir, {"remote", "add", std::string(remote), std::string(url)}) ==-         0;+  return run_git(dir,+                 {"remote", "add", std::string(remote), std::string(url)}) == 0; }  void add_unique(std::vector<Id> &ids, const Id &id) {@@ -465,12 +463,12 @@   auto object = git::read_object(repo, oid);   if (!object || object->kind != git::KIND_TREE)     return 1;-  auto parsed = git::parse_tree(Bytes(object->body.data(), object->body.size()));+  auto parsed =+      git::parse_tree(Bytes(object->body.data(), object->body.size()));   if (!parsed)     return 1;   std::stable_sort(parsed->entries.begin(), parsed->entries.end(),-                   [](const git::RawTreeEntry &a,-                      const git::RawTreeEntry &b) {+                   [](const git::RawTreeEntry &a, const git::RawTreeEntry &b) {                      return compare(bytes_of(a.name), bytes_of(b.name)) < 0;                    });   std::vector<TreeEntry> entries;@@ -515,10 +513,11 @@  namespace git { -std::optional<Id> import_tree(-    Writer &writer, Repo &repo, IdMap &trees, IdMap &blobs, const Oid &oid,-    std::vector<std::pair<Id, std::vector<std::uint8_t>>> &raw_saves,-    std::size_t &new_trees, std::size_t &new_blobs, std::size_t depth) {+std::optional<Id>+import_tree(Writer &writer, Repo &repo, IdMap &trees, IdMap &blobs,+            const Oid &oid,+            std::vector<std::pair<Id, std::vector<std::uint8_t>>> &raw_saves,+            std::size_t &new_trees, std::size_t &new_blobs, std::size_t depth) {   if (import_tree_impl(writer, repo, trees, blobs, oid, raw_saves, new_trees,                        new_blobs, depth) != 0)     return std::nullopt;@@ -525,8 +524,8 @@   return trees.get(oid); } -bool export_tree(const fs::path &root, Store &store, IdMap &trees,-                 IdMap &blobs, const Id &id, Oid &out, std::size_t depth) {+bool export_tree(const fs::path &root, Store &store, IdMap &trees, IdMap &blobs,+                 const Id &id, Oid &out, std::size_t depth) {   if (depth > 4096)     return false;   if (auto existing = trees.reverse(id)) {@@ -582,8 +581,8 @@         auto data = read_blob(store, entry.target);         if (!data)           return false;-        auto hash = object_hash(git::KIND_BLOB,-                                Bytes(data->data(), data->size()));+        auto hash =+            object_hash(git::KIND_BLOB, Bytes(data->data(), data->size()));         if (!hash || !write_loose(mirror, git::KIND_BLOB, *hash,                                   Bytes(data->data(), data->size())))           return false;@@ -612,10 +611,10 @@     git_body.push_back(0);     git_body.insert(git_body.end(), entry.oid.begin(), entry.oid.end());   }-  auto oid = object_hash(git::KIND_TREE, Bytes(git_body.data(), git_body.size()));-  if (!oid ||-      !write_loose(mirror, git::KIND_TREE, *oid,-                   Bytes(git_body.data(), git_body.size())))+  auto oid =+      object_hash(git::KIND_TREE, Bytes(git_body.data(), git_body.size()));+  if (!oid || !write_loose(mirror, git::KIND_TREE, *oid,+                           Bytes(git_body.data(), git_body.size())))     return false;   trees.put(*oid, id);   out = *oid;@@ -623,9 +622,8 @@ }  bool export_commit(const fs::path &root, Store &store, IdMap &commits,-                   IdMap &trees, IdMap &blobs,-                   const std::vector<Id> &native, const Id &id, Oid &out,-                   std::size_t depth) {+                   IdMap &trees, IdMap &blobs, const std::vector<Id> &native,+                   const Id &id, Oid &out, std::size_t depth) {   if (depth > 4096)     return false;   if (auto existing = commits.reverse(id)) {@@ -651,8 +649,7 @@   std::vector<std::uint8_t> body;   bool used_raw = false;   if (auto raw = load_raw(root, id)) {-    if (auto parsed =-            parse_commit(Bytes(raw->data(), raw->size()))) {+    if (auto parsed = parse_commit(Bytes(raw->data(), raw->size()))) {       bool matches = std::memcmp(parsed->tree.data(), tree_oid.data(),                                  tree_oid.size()) == 0 &&                      parsed->parents.size() == parents.size();@@ -674,10 +671,10 @@     parsed.message = loaded->commit.message;     parsed.extras = loaded->commit.extra;     if (is_native(native, id)) {-      parsed.extras.push_back(KeyValue{-          "veins-change-id",-          hex_encode(Bytes(loaded->commit.change_id.data(),-                           loaded->commit.change_id.size()))});+      parsed.extras.push_back(+          KeyValue{"veins-change-id",+                   hex_encode(Bytes(loaded->commit.change_id.data(),+                                    loaded->commit.change_id.size()))});     }     body = serialize_commit(parsed);   }@@ -803,8 +800,8 @@         git::parse_commit(Bytes(object->body.data(), object->body.size()));     if (!parsed)       continue;-    records.push_back(CommitRecord{oid, std::move(object->body),-                                   std::move(*parsed)});+    records.push_back(+        CommitRecord{oid, std::move(object->body), std::move(*parsed)});     for (const auto &parent : records.back().parsed.parents)       stack.push_back(parent);   }@@ -880,9 +877,8 @@       if (build_failed)         break;       commit.root_tree = *tree;-      commit.change_id = record.parsed.change_id-                             ? *record.parsed.change_id-                             : derive_change_id(record.oid);+      commit.change_id = record.parsed.change_id ? *record.parsed.change_id+                                                 : derive_change_id(record.oid);       commit.author = record.parsed.author;       commit.committer = record.parsed.committer;       commit.message = record.parsed.message;@@ -1002,8 +998,8 @@     const int checkout_status = materialize_working_copy(root, store);     if (checkout_status != 0) {       error_prefix();-      std::cout << "imported history; checkout failed (code "-                << checkout_status << ")\n";+      std::cout << "imported history; checkout failed (code " << checkout_status+                << ")\n";       return 1;     }   }@@ -1037,8 +1033,8 @@     std::cout << "cannot load repository state\n";     return 1;   }-  MaterializeCtx ctx{root, store, tx->writer(), {}, {}, {}, {}, {}, 0, 0, 0,-                     false};+  MaterializeCtx ctx{root, store, tx->writer(), {}, {}, {}, {}, {}, 0,+                     0,    0,     false};   const auto roots = view_roots(*view);   const auto ordered = ordered_commits(store, roots);   for (const auto &old_id : ordered) {@@ -1238,9 +1234,8 @@       if (item.bookmark.targets.adds.empty())         continue;       auto oid = commits.reverse(*item.bookmark.targets.adds.front());-      if (oid &&-          !git::write_ref(git_dir(root), "refs/heads/" + item.bookmark.name,-                          *oid))+      if (oid && !git::write_ref(git_dir(root),+                                 "refs/heads/" + item.bookmark.name, *oid))         status = 1;     }     for (const auto &item : resolved_tags) {@@ -1306,8 +1301,7 @@     return exported;   const std::string refspec = "refs/heads/" + std::string(bookmark) +                               ":refs/heads/" + std::string(bookmark);-  if (run_git(git_dir(root),-              {"push", std::string(remote), refspec}) != 0) {+  if (run_git(git_dir(root), {"push", std::string(remote), refspec}) != 0) {     error_prefix();     std::cout << "git push failed\n";     return 1;@@ -1320,8 +1314,8 @@   return git::prepare_mirror(root, path_from_bytes(source)); } -std::optional<std::vector<std::uint8_t>> git_read_lazy_blob(const fs::path &root,-                                                            const Id &id) {+std::optional<std::vector<std::uint8_t>>+git_read_lazy_blob(const fs::path &root, const Id &id) {   const auto oid = git::lazy_blob_oid(id);   if (!oid)     return std::nullopt;@@ -1371,8 +1365,8 @@                   << " is not a git repository root (expected the directory "                      "containing .git)\n";       } else {-        std::cout << "cannot prepare git mirror from " << *source-                  << " (code " << prepared << ")\n";+        std::cout << "cannot prepare git mirror from " << *source << " (code "+                  << prepared << ")\n";       }       return 1;     }--- a/xveins/src/git.h+++ b/xveins/src/git.h@@ -16,8 +16,8 @@ int git_push(const fs::path &root, std::string_view remote,              std::string_view bookmark); int git_prepare_mirror(const fs::path &root, std::string_view source);-std::optional<std::vector<std::uint8_t>> git_read_lazy_blob(const fs::path &root,-                                                            const Id &id);+std::optional<std::vector<std::uint8_t>>+git_read_lazy_blob(const fs::path &root, const Id &id); int git_cli_run(const std::vector<std::string> &args);  } // namespace vn--- a/xveins/src/git_internal.h+++ b/xveins/src/git_internal.h@@ -131,18 +131,15 @@ std::string remote_key(std::string_view remote, std::string_view field); std::vector<std::string> list_remotes(const fs::path &root); -std::optional<Id> import_tree(Writer &writer, Repo &repo, IdMap &trees,-                              IdMap &blobs, const Oid &oid,-                              std::vector<std::pair<Id, std::vector<std::uint8_t>>>-                                  &raw_saves,-                              std::size_t &new_trees, std::size_t &new_blobs,-                              std::size_t depth = 0);+std::optional<Id> import_tree(+    Writer &writer, Repo &repo, IdMap &trees, IdMap &blobs, const Oid &oid,+    std::vector<std::pair<Id, std::vector<std::uint8_t>>> &raw_saves,+    std::size_t &new_trees, std::size_t &new_blobs, std::size_t depth = 0); -bool export_tree(const fs::path &root, Store &store, IdMap &trees,-                 IdMap &blobs, const Id &id, Oid &out, std::size_t depth = 0);+bool export_tree(const fs::path &root, Store &store, IdMap &trees, IdMap &blobs,+                 const Id &id, Oid &out, std::size_t depth = 0); bool export_commit(const fs::path &root, Store &store, IdMap &commits,-                   IdMap &trees, IdMap &blobs,-                   const std::vector<Id> &native, const Id &id, Oid &out,-                   std::size_t depth = 0);+                   IdMap &trees, IdMap &blobs, const std::vector<Id> &native,+                   const Id &id, Oid &out, std::size_t depth = 0);  } // namespace vn::git--- a/xveins/src/git_object.cpp+++ b/xveins/src/git_object.cpp@@ -151,8 +151,7 @@   } } -std::optional<std::vector<std::uint8_t>> apply_delta(Bytes base,-                                                     Bytes delta) {+std::optional<std::vector<std::uint8_t>> apply_delta(Bytes base, Bytes delta) {   const auto src_size = read_delta_varint(delta, 0);   if (!src_size || src_size->value != base.size())     return std::nullopt;@@ -209,8 +208,10 @@ }  std::optional<std::size_t> find_oid(const Pack &pack, const Oid &oid) {-  auto it = std::lower_bound(pack.oids.begin(), pack.oids.end(), oid, OidLess{});-  if (it == pack.oids.end() || std::memcmp(it->data(), oid.data(), oid.size()) != 0)+  auto it =+      std::lower_bound(pack.oids.begin(), pack.oids.end(), oid, OidLess{});+  if (it == pack.oids.end() ||+      std::memcmp(it->data(), oid.data(), oid.size()) != 0)     return std::nullopt;   return static_cast<std::size_t>(it - pack.oids.begin()); }@@ -295,8 +296,8 @@       std::memcmp(data.data() + data.size() - 40, pack_trailer.data(), 20) != 0)     return std::nullopt; -  const bool is_v2 = data.size() >= 4 && data[0] == 0xff &&-                     data[1] == 0x74 && data[2] == 0x4f && data[3] == 0x63;+  const bool is_v2 = data.size() >= 4 && data[0] == 0xff && data[1] == 0x74 &&+                     data[2] == 0x4f && data[3] == 0x63;   const std::size_t fanout_off = is_v2 ? 8 : 0;   if (is_v2 && be32(data, 4) != 2)     return std::nullopt;@@ -363,8 +364,7 @@   auto idata = read_file_opt(idx_path);   if (!idata)     return std::nullopt;-  auto parsed = parse_idx(bytes_of(*idata),-                          count,+  auto parsed = parse_idx(bytes_of(*idata), count,                           Bytes(pdata->data() + trailer_off, 20));   if (!parsed)     return std::nullopt;@@ -376,9 +376,9 @@ std::optional<Object> read_loose(const Repo &repo, const Oid &oid,                                  bool verify) {   const std::string hex = oid_hex(oid);-  const fs::path path =-      repo.git_dir / "objects" / path_from_bytes(hex.substr(0, 2)) /-      path_from_bytes(hex.substr(2));+  const fs::path path = repo.git_dir / "objects" /+                        path_from_bytes(hex.substr(0, 2)) /+                        path_from_bytes(hex.substr(2));   auto compressed = read_file_opt(path);   if (!compressed)     return std::nullopt;@@ -393,8 +393,7 @@     ++nul;   if (space == 0 || nul >= data.size())     return std::nullopt;-  const std::uint8_t kind =-      kind_from_name(str_of(data.first(space)));+  const std::uint8_t kind = kind_from_name(str_of(data.first(space)));   if (kind == 0)     return std::nullopt;   std::uint64_t declared = 0;@@ -489,9 +488,8 @@       auto content = read_file_opt(child);       if (!content)         continue;-      const std::string line =-          trim_line(std::string_view(reinterpret_cast<const char *>(content->data()),-                                     content->size()));+      const std::string line = trim_line(std::string_view(+          reinterpret_cast<const char *>(content->data()), content->size()));       if (auto oid = oid_from_hex(line))         replace_ref(refs, child_rel, *oid);     }@@ -504,9 +502,8 @@   auto data = read_file_opt(git_dir / "HEAD");   if (!data)     return std::nullopt;-  const std::string line =-      trim_line(std::string_view(reinterpret_cast<const char *>(data->data()),-                                 data->size()));+  const std::string line = trim_line(std::string_view(+      reinterpret_cast<const char *>(data->data()), data->size()));   if (line.starts_with("ref: ")) {     std::string_view name(line.data() + 5, line.size() - 5);     if (name.starts_with("refs/heads/"))@@ -627,8 +624,8 @@  std::shared_ptr<Repo> cached_repo(const fs::path &git_dir) {   static std::mutex mutex;-  static std::map<std::string, std::pair<fs::file_time_type,-                                         std::shared_ptr<Repo>>>+  static std::map<std::string,+                  std::pair<fs::file_time_type, std::shared_ptr<Repo>>>       cache;   std::error_code ec;   const fs::path pack_dir = git_dir / "objects" / "pack";@@ -769,8 +766,8 @@       if (last_extra < 0) {         out.canonical = false;       } else {-        out.extras[static_cast<std::size_t>(last_extra)].value =-            std::string(text.substr(last_extra_start, line_end - last_extra_start));+        out.extras[static_cast<std::size_t>(last_extra)].value = std::string(+            text.substr(last_extra_start, line_end - last_extra_start));       }     } else {       last_extra = -1;@@ -858,8 +855,9 @@       out.canonical = false;       break;     }-    const std::string mode(reinterpret_cast<const char *>(body.data() + mode_start),-                           pos - mode_start);+    const std::string mode(+        reinterpret_cast<const char *>(body.data() + mode_start),+        pos - mode_start);     ++pos;     const std::size_t name_start = pos;     while (pos < body.size() && body[pos] != 0)@@ -972,8 +970,7 @@   auto data = read_file_opt(map_path(root, name));   if (!data)     return true;-  if (data->size() < 9 ||-      std::memcmp(data->data(), "VMAP1", 5) != 0)+  if (data->size() < 9 || std::memcmp(data->data(), "VMAP1", 5) != 0)     return false;   const std::uint32_t count = static_cast<std::uint32_t>((*data)[5]) |                               (static_cast<std::uint32_t>((*data)[6]) << 8) |@@ -1008,7 +1005,8 @@ }  bool save_raw(const fs::path &root, const Id &id, Bytes body) {-  const fs::path path = git_map_dir(root) / "raw" / path_from_bytes(hex_encode(id));+  const fs::path path =+      git_map_dir(root) / "raw" / path_from_bytes(hex_encode(id));   return write_atomic(path, body); } @@ -1045,8 +1043,7 @@  bool ensure_mirror(const fs::path &root) {   const fs::path dir = git_dir(root);-  if (!ensure_directory(dir) ||-      !ensure_directory(dir / "objects") ||+  if (!ensure_directory(dir) || !ensure_directory(dir / "objects") ||       !ensure_directory(dir / "refs" / "heads") ||       !ensure_directory(dir / "refs" / "tags"))     return false;@@ -1056,8 +1053,8 @@       return false;   }   if (!path_is_file(dir / "config")) {-    const std::string body =-        "[core]\n\trepositoryformatversion = 0\n\tfilemode = true\n\tbare = true\n";+    const std::string body = "[core]\n\trepositoryformatversion = "+                             "0\n\tfilemode = true\n\tbare = true\n";     if (!write_file(dir / "config", bytes_of(body)))       return false;   }@@ -1079,9 +1076,9 @@ bool write_loose(const fs::path &git_dir, std::uint8_t kind, const Oid &oid,                  Bytes body) {   const std::string hex = oid_hex(oid);-  const fs::path final_path =-      git_dir / "objects" / path_from_bytes(hex.substr(0, 2)) /-      path_from_bytes(hex.substr(2));+  const fs::path final_path = git_dir / "objects" /+                              path_from_bytes(hex.substr(0, 2)) /+                              path_from_bytes(hex.substr(2));   if (path_is_file(final_path))     return true;   std::string header = kind_name(kind);@@ -1100,8 +1097,7 @@   if (rc != Z_OK)     return false;   compressed.resize(dest_len);-  return write_atomic(final_path,-                      Bytes(compressed.data(), compressed.size()));+  return write_atomic(final_path, Bytes(compressed.data(), compressed.size())); }  bool write_ref(const fs::path &git_dir, std::string_view name, const Oid &oid) {--- a/xveins/src/merge.cpp+++ b/xveins/src/merge.cpp@@ -22,9 +22,8 @@   return std::memcmp(a.data(), b.data(), ID_LEN) == 0; } -std::optional<std::vector<std::uint8_t>> read_body_any(Store &store, Txn *tx,-                                                       std::uint8_t type,-                                                       const Id &id) {+std::optional<std::vector<std::uint8_t>>+read_body_any(Store &store, Txn *tx, std::uint8_t type, const Id &id) {   if (tx) {     if (auto cached = tx->writer().find_cached(type, id))       return cached;@@ -247,9 +246,8 @@       ops.push_back(DiffOp{' ', oi - 1, oj - 1});       --oi;       --oj;-    } else if (oj > 0 &&-               (oi == 0 || dp[oi * cols + (oj - 1)] >=-                               dp[(oi - 1) * cols + oj])) {+    } else if (oj > 0 && (oi == 0 || dp[oi * cols + (oj - 1)] >=+                                         dp[(oi - 1) * cols + oj])) {       ops.push_back(DiffOp{'+', 0, oj - 1});       --oj;     } else {@@ -601,7 +599,8 @@       if (used_new[ai])         continue;       if (same_id(deleted[di].target, added[ai].target)) {-        out.push_back(Rename{parent_index, 0, deleted[di].path, added[ai].path});+        out.push_back(+            Rename{parent_index, 0, deleted[di].path, added[ai].path});         used_old[di] = 1;         used_new[ai] = 1;         break;@@ -615,10 +614,10 @@       if (used_old[di] || (deleted[di].kind != KIND_FILE &&                            deleted[di].kind != KIND_EXECUTABLE))         continue;-      for (std::size_t ai = 0; ai < added.size() && pairs.size() < candidate_limit;-           ++ai) {-        if (used_new[ai] || (added[ai].kind != KIND_FILE &&-                             added[ai].kind != KIND_EXECUTABLE))+      for (std::size_t ai = 0;+           ai < added.size() && pairs.size() < candidate_limit; ++ai) {+        if (used_new[ai] ||+            (added[ai].kind != KIND_FILE && added[ai].kind != KIND_EXECUTABLE))           continue;         RenamePair pair;         pair.old_path = deleted[di].path;@@ -632,8 +631,7 @@       std::ptrdiff_t best_i = -1;       std::size_t best = 0;       for (std::size_t i = 0; i < pairs.size(); ++i) {-        if (!pairs[i].old_used && !pairs[i].new_used &&-            pairs[i].score > best) {+        if (!pairs[i].old_used && !pairs[i].new_used && pairs[i].score > best) {           best = pairs[i].score;           best_i = static_cast<std::ptrdiff_t>(i);         }@@ -646,11 +644,12 @@       out.push_back(Rename{parent_index, 0, pair.old_path, pair.new_path});     }   }-  std::stable_sort(out.begin(), out.end(), [](const Rename &a, const Rename &b) {-    if (a.parent_index != b.parent_index)-      return a.parent_index < b.parent_index;-    return compare(bytes_of(a.to_path), bytes_of(b.to_path)) < 0;-  });+  std::stable_sort(+      out.begin(), out.end(), [](const Rename &a, const Rename &b) {+        if (a.parent_index != b.parent_index)+          return a.parent_index < b.parent_index;+        return compare(bytes_of(a.to_path), bytes_of(b.to_path)) < 0;+      });   return out; } @@ -974,8 +973,8 @@   (void)write_file(resolutions_dir(repo) / key, bytes_of(hex_encode(blob))); } -Id build_level(Txn &tx, const std::vector<OutEntry> &entries,-               std::size_t start, std::size_t end, std::size_t prefix_len) {+Id build_level(Txn &tx, const std::vector<OutEntry> &entries, std::size_t start,+               std::size_t end, std::size_t prefix_len) {   std::vector<TreeEntry> out;   std::size_t i = start;   while (i < end) {@@ -991,9 +990,8 @@       std::size_t j = i + 1;       while (j < end) {         const std::size_t other_end = entries[j].path.find('/', prefix_len);-        const std::size_t other_cut = other_end == std::string::npos-                                          ? entries[j].path.size()-                                          : other_end;+        const std::size_t other_cut =+            other_end == std::string::npos ? entries[j].path.size() : other_end;         if (other_cut != cut ||             entries[j].path.compare(prefix_len, cut - prefix_len, name) != 0)           break;@@ -1017,8 +1015,8 @@   return build_level(tx, entries, 0, entries.size(), 0); } -Id build_subtree(Txn &tx, const std::vector<OrigEntry> &canon,-                 std::size_t term, std::string_view prefix) {+Id build_subtree(Txn &tx, const std::vector<OrigEntry> &canon, std::size_t term,+                 std::string_view prefix) {   std::vector<OutEntry> rels;   for (const auto &entry : canon) {     if (entry.term != term)@@ -1026,9 +1024,8 @@     if (entry.path.size() > prefix.size() &&         entry.path.compare(0, prefix.size(), prefix) == 0 &&         entry.path[prefix.size()] == '/')-      rels.push_back(-          OutEntry{entry.path.substr(prefix.size() + 1), entry.kind,-                   entry.target});+      rels.push_back(OutEntry{entry.path.substr(prefix.size() + 1), entry.kind,+                              entry.target});   }   return build_from_entries(tx, rels); }@@ -1039,8 +1036,8 @@          path[prefix.size()] == '/'; } -std::optional<OutEntry> merge_entry(const fs::path &repo, Txn &tx,-                                    Store &store, const std::string &path,+std::optional<OutEntry> merge_entry(const fs::path &repo, Txn &tx, Store &store,+                                    const std::string &path,                                     const std::vector<EntryTerm> &terms,                                     bool adjacent, std::size_t &rerere) {   std::vector<ConflictValue> adds;@@ -1065,17 +1062,17 @@   if (all_files(sum) && sum.adds.size() == 2 && sum.removes.size() == 1 &&       sum.adds[0].kind != 0 && sum.adds[1].kind != 0 &&       sum.removes[0].kind != 0 && !merge_binary(repo, path)) {-    auto merged = merge_blobs(store, &tx, *sum.removes[0].target,-                              *sum.adds[0].target, *sum.adds[1].target,-                              adjacent);+    auto merged =+        merge_blobs(store, &tx, *sum.removes[0].target, *sum.adds[0].target,+                    *sum.adds[1].target, adjacent);     if (merged && !merged->conflicted) {       const Id blob = add_blob(tx, bytes_of(merged->data));       const int mode = merge_mode(sum);       if (mode >= 0)-        return OutEntry{path,-                        static_cast<std::uint8_t>(mode == 1 ? KIND_EXECUTABLE-                                                            : KIND_FILE),-                        blob};+        return OutEntry{+            path,+            static_cast<std::uint8_t>(mode == 1 ? KIND_EXECUTABLE : KIND_FILE),+            blob};     }   }   const auto body = encode_conflict(sum);@@ -1100,8 +1097,8 @@       orig.push_back(OrigEntry{t, entry.path, entry.kind, entry.target});   } -  auto canonical_targets =-      [&](const std::string &path) -> std::vector<std::pair<std::size_t, std::string>> {+  auto canonical_targets = [&](const std::string &path)+      -> std::vector<std::pair<std::size_t, std::string>> {     std::vector<std::pair<std::size_t, std::string>> out;     for (std::size_t i = 0; i < maps.size(); ++i) {       auto dest = rename_lookup(maps[i], path);@@ -1449,8 +1446,8 @@   if (renames_state == RENAMES_RECORDED) {     for (std::size_t i = 0; i < parents.size(); ++i) {       auto parent_tree = tree_of(store, parents[i]);-      auto detected =-          detect_renames(store, &tx, parent_tree, std::optional<Id>{root}, 0, i);+      auto detected = detect_renames(store, &tx, parent_tree,+                                     std::optional<Id>{root}, 0, i);       for (auto &rename : detected)         commit.renames.push_back(std::move(rename));     }@@ -1510,9 +1507,9 @@       if (present)         entries.push_back(TreeEntry{entry.name, kind, target});     } else if (entry.kind == KIND_SUBTREE) {-      auto child = tree_edit_into(tx, store, entry.target,-                                  path.substr(cut_pos + 1), present, kind,-                                  target, depth + 1);+      auto child =+          tree_edit_into(tx, store, entry.target, path.substr(cut_pos + 1),+                         present, kind, target, depth + 1);       if (child && !tree_empty_any(store, &tx, *child))         entries.push_back(TreeEntry{entry.name, KIND_SUBTREE, *child});     } else {@@ -1527,8 +1524,7 @@ std::optional<Id> tree_edit_replace(Txn &tx, Store &store, const Id &root,                                     std::string_view path, bool present,                                     std::uint8_t kind, const Id &target) {-  auto edited =-      tree_edit_into(tx, store, root, path, present, kind, target, 0);+  auto edited = tree_edit_into(tx, store, root, path, present, kind, target, 0);   if (!edited)     return std::nullopt;   return edited;@@ -1565,8 +1561,8 @@     std::cout << a + 1 << "-" << b; } -std::optional<EditResult> conflict_ranges(Store &store, const Conflict &conflict,-                                          bool adjacent) {+std::optional<EditResult>+conflict_ranges(Store &store, const Conflict &conflict, bool adjacent) {   if (conflict.adds.size() != 2 || conflict.removes.size() != 1)     return std::nullopt;   const auto &ours = conflict.adds[0];@@ -1577,8 +1573,8 @@   if (ours.kind == KIND_SUBTREE || theirs.kind == KIND_SUBTREE ||       base.kind == KIND_SUBTREE)     return std::nullopt;-  return merge_blobs(store, nullptr, *base.target, *ours.target,-                     *theirs.target, adjacent);+  return merge_blobs(store, nullptr, *base.target, *ours.target, *theirs.target,+                     adjacent); }  std::vector<FlatEntry> flatten_store(Store &store, const Id &tree) {@@ -1643,12 +1639,11 @@    const auto old_root = tree_of(store, *wc);   const bool adjacent = adjacent_config(*root);-  MergeOutcome outcome =-      merge_many(*root, *tx, store, parents, adjacent);+  MergeOutcome outcome = merge_many(*root, *tx, store, parents, adjacent);   const Sig author = identity_signature(*root);-  const Id new_id = make_commit(-      *tx, store, *root, parents, outcome.tree, random_change_id(), author, "",-      RENAMES_RECORDED, {});+  const Id new_id =+      make_commit(*tx, store, *root, parents, outcome.tree, random_change_id(),+                  author, "", RENAMES_RECORDED, {});    remove_head(tx->view(), *wc);   move_bookmarks(tx->view(), *wc, new_id);@@ -1766,21 +1761,18 @@       new_parent_trees.push_back(tree_of(store, *dst).value_or(Id{}));     } -    MergeOutcome outcome =-        rewrite_tree(*root, *tx, store, chosen, loaded->commit.root_tree,-                     loaded->commit.parents, new_parents, new_parent_trees,-                     adjacent);+    MergeOutcome outcome = rewrite_tree(+        *root, *tx, store, chosen, loaded->commit.root_tree,+        loaded->commit.parents, new_parents, new_parent_trees, adjacent);     rerere_total += outcome.rerere;-    const Id new_id =-        make_commit(*tx, store, *root, new_parents, outcome.tree,-                    loaded->commit.change_id, loaded->commit.author,-                    loaded->commit.message, loaded->commit.renames_state,-                    loaded->commit.extra);+    const Id new_id = make_commit(+        *tx, store, *root, new_parents, outcome.tree, loaded->commit.change_id,+        loaded->commit.author, loaded->commit.message,+        loaded->commit.renames_state, loaded->commit.extra);     old_ids.push_back(chosen);     new_ids.push_back(new_id);     new_tree_ids.push_back(outcome.tree);-    remaining.erase(remaining.begin() +-                    static_cast<std::ptrdiff_t>(ready_idx));+    remaining.erase(remaining.begin() + static_cast<std::ptrdiff_t>(ready_idx));   }    auto remap = [&](std::optional<Id> &id) {@@ -1812,9 +1804,8 @@       workspace.target = *target;   }   rebuild_heads(tx->view());-  const auto status =-      tx->finish("rebase " + source + " onto " + dest +-                 rerere_suffix(rerere_total));+  const auto status = tx->finish("rebase " + source + " onto " + dest ++                                 rerere_suffix(rerere_total));   if (!status)     return 1;   for (const auto &id : new_ids)@@ -1876,15 +1867,13 @@         for (std::size_t i = 0; i < ranges->ranges.size(); ++i) {           if (i > 0)             std::cout << ",";-          print_range(ranges->ranges[i].base_start,-                      ranges->ranges[i].base_end);+          print_range(ranges->ranges[i].base_start, ranges->ranges[i].base_end);         }         std::cout << "\t";         for (std::size_t i = 0; i < ranges->ranges.size(); ++i) {           if (i > 0)             std::cout << ",";-          print_range(ranges->ranges[i].ours_start,-                      ranges->ranges[i].ours_end);+          print_range(ranges->ranges[i].ours_start, ranges->ranges[i].ours_end);         }         std::cout << "\t";         for (std::size_t i = 0; i < ranges->ranges.size(); ++i) {@@ -1905,11 +1894,9 @@           if (i > 0)             std::cout << ", ";           std::cout << "base ";-          print_range(ranges->ranges[i].base_start,-                      ranges->ranges[i].base_end);+          print_range(ranges->ranges[i].base_start, ranges->ranges[i].base_end);           std::cout << ", ours ";-          print_range(ranges->ranges[i].ours_start,-                      ranges->ranges[i].ours_end);+          print_range(ranges->ranges[i].ours_start, ranges->ranges[i].ours_end);           std::cout << ", theirs ";           print_range(ranges->ranges[i].theirs_start,                       ranges->ranges[i].theirs_end);@@ -2075,8 +2062,7 @@       if (new_kind == KIND_FILE || new_kind == KIND_EXECUTABLE) {         if (auto conflict_body =                 store.read_body(entry->target, TYPE_CONFLICT)) {-          resolution_record(*root, bytes_of(*conflict_body),-                            *new_target);+          resolution_record(*root, bytes_of(*conflict_body), *new_target);         }       }     }--- a/xveins/src/merge.h+++ b/xveins/src/merge.h@@ -8,8 +8,8 @@  namespace vn { -// Detect renames between two trees. `tx` may be provided so trees and blobs that-// have only been added to the pending transaction are visible. Results are+// Detect renames between two trees. `tx` may be provided so trees and blobs+// that have only been added to the pending transaction are visible. Results are // sorted by (parent_index, to_path). std::vector<Rename> detect_renames(Store &store, Txn *tx,                                    std::optional<Id> old_tree,--- a/xveins/src/net.cpp+++ b/xveins/src/net.cpp@@ -12,10 +12,10 @@ #ifndef NOMINMAX #define NOMINMAX #endif+#include <io.h>+#include <windows.h> #include <winsock2.h> #include <ws2tcpip.h>-#include <windows.h>-#include <io.h> #endif  #include <openssl/err.h>@@ -55,8 +55,8 @@ std::wstring widen_utf8(std::string_view text) {   if (text.empty())     return {};-  const int len = MultiByteToWideChar(CP_UTF8, 0, text.data(),-                                      static_cast<int>(text.size()), nullptr, 0);+  const int len = MultiByteToWideChar(+      CP_UTF8, 0, text.data(), static_cast<int>(text.size()), nullptr, 0);   std::wstring out(static_cast<std::size_t>(len), L'\0');   MultiByteToWideChar(CP_UTF8, 0, text.data(), static_cast<int>(text.size()),                       out.data(), len);@@ -91,8 +91,7 @@   return out; } -std::wstring build_windows_command_line(-    const std::vector<std::string> &argv) {+std::wstring build_windows_command_line(const std::vector<std::string> &argv) {   std::wstring out;   for (std::size_t i = 0; i < argv.size(); ++i) {     if (i != 0)@@ -154,10 +153,8 @@   Stream stream;   stream.kind_ = Kind::Stdio; #if defined(_WIN32)-  stream.fd_in_ =-      reinterpret_cast<Socket>(GetStdHandle(STD_INPUT_HANDLE));-  stream.fd_out_ =-      reinterpret_cast<Socket>(GetStdHandle(STD_OUTPUT_HANDLE));+  stream.fd_in_ = reinterpret_cast<Socket>(GetStdHandle(STD_INPUT_HANDLE));+  stream.fd_out_ = reinterpret_cast<Socket>(GetStdHandle(STD_OUTPUT_HANDLE)); #else   stream.fd_in_ = 0;   stream.fd_out_ = 1;@@ -212,8 +209,7 @@       return -1;     return static_cast<std::int64_t>(got);   }-  const int n = recv(static_cast<SOCKET>(fd_in_),-                     static_cast<char *>(buffer),+  const int n = recv(static_cast<SOCKET>(fd_in_), static_cast<char *>(buffer),                      static_cast<int>(std::min<std::size_t>(                          count, static_cast<std::size_t>(INT_MAX))),                      0);@@ -236,11 +232,10 @@     const std::size_t remaining = data.size() - offset;     std::int64_t written = -1;     if (kind_ == Kind::Tls) {-      const int n = SSL_write(-          static_cast<SSL *>(ssl_), data.data() + offset,-          static_cast<int>(std::min<std::size_t>(remaining,-                                                 static_cast<std::size_t>(-                                                     INT_MAX))));+      const int n =+          SSL_write(static_cast<SSL *>(ssl_), data.data() + offset,+                    static_cast<int>(std::min<std::size_t>(+                        remaining, static_cast<std::size_t>(INT_MAX))));       written = n;     } #if defined(_WIN32)@@ -253,12 +248,11 @@         return false;       written = static_cast<std::int64_t>(count);     } else {-      const int n = send(-          static_cast<SOCKET>(fd_out_),-          reinterpret_cast<const char *>(data.data() + offset),-          static_cast<int>(std::min<std::size_t>(-              remaining, static_cast<std::size_t>(INT_MAX))),-          0);+      const int n = send(static_cast<SOCKET>(fd_out_),+                         reinterpret_cast<const char *>(data.data() + offset),+                         static_cast<int>(std::min<std::size_t>(+                             remaining, static_cast<std::size_t>(INT_MAX))),+                         0);       written = n;     } #else@@ -459,7 +453,8 @@     }     closesocket(socket); #else-    const int socket = ::socket(it->ai_family, it->ai_socktype, it->ai_protocol);+    const int socket =+        ::socket(it->ai_family, it->ai_socktype, it->ai_protocol);     if (socket < 0)       continue;     if (::connect(socket, it->ai_addr, it->ai_addrlen) == 0) {@@ -470,9 +465,8 @@ #endif   }   freeaddrinfo(results);-  return connected == INVALID_SOCKET_VALUE-             ? std::nullopt-             : std::optional<Socket>(connected);+  return connected == INVALID_SOCKET_VALUE ? std::nullopt+                                           : std::optional<Socket>(connected); }  Socket tcp_listen(int port, int backlog) {@@ -517,7 +511,8 @@  std::optional<Socket> tcp_accept(Socket listener) { #if defined(_WIN32)-  const SOCKET accepted = ::accept(static_cast<SOCKET>(listener), nullptr, nullptr);+  const SOCKET accepted =+      ::accept(static_cast<SOCKET>(listener), nullptr, nullptr);   if (accepted == INVALID_SOCKET)     return std::nullopt;   return static_cast<Socket>(accepted);@@ -553,9 +548,8 @@ fs::path self_exe() { #if defined(_WIN32)   std::wstring buffer(32768, L'\0');-  const DWORD len =-      GetModuleFileNameW(nullptr, buffer.data(),-                         static_cast<DWORD>(buffer.size()));+  const DWORD len = GetModuleFileNameW(nullptr, buffer.data(),+                                       static_cast<DWORD>(buffer.size()));   if (len > 0) {     buffer.resize(len);     return fs::path(buffer);@@ -575,8 +569,8 @@   return fs::path("vn"); #else   std::string buffer(4096, '\0');-  const ssize_t len = ::readlink("/proc/self/exe", buffer.data(),-                                 buffer.size() - 1);+  const ssize_t len =+      ::readlink("/proc/self/exe", buffer.data(), buffer.size() - 1);   if (len > 0) {     buffer.resize(static_cast<std::size_t>(len));     return fs::path(buffer);@@ -619,8 +613,8 @@     return nullptr;   if (SSL_CTX_set_min_proto_version(ctx, TLS1_3_VERSION) != 1)     goto fail;-  if (SSL_CTX_use_certificate_chain_file(ctx,-                                         std::string(cert_path).c_str()) != 1)+  if (SSL_CTX_use_certificate_chain_file(ctx, std::string(cert_path).c_str()) !=+      1)     goto fail;   if (SSL_CTX_use_PrivateKey_file(ctx, std::string(key_path).c_str(),                                   SSL_FILETYPE_PEM) != 1)@@ -657,8 +651,7 @@   SSL *ssl = SSL_new(static_cast<SSL_CTX *>(ctx));   if (!ssl)     return nullptr;-  if (SSL_set_fd(ssl, static_cast<int>(fd)) != 1 ||-      SSL_accept(ssl) != 1) {+  if (SSL_set_fd(ssl, static_cast<int>(fd)) != 1 || SSL_accept(ssl) != 1) {     SSL_free(ssl);     return nullptr;   }@@ -697,8 +690,7 @@   if (!cert)     return false;   unsigned int len = 0;-  const bool ok =-      X509_digest(cert, EVP_sha256(), out, &len) == 1 && len == 32;+  const bool ok = X509_digest(cert, EVP_sha256(), out, &len) == 1 && len == 32;   X509_free(cert);   return ok; }--- a/xveins/src/net.h+++ b/xveins/src/net.h@@ -37,8 +37,7 @@   static Stream tls_stream(Socket fd, void *ssl);   static std::optional<Stream> spawn_argv(const std::vector<std::string> &argv); -  friend std::optional<Stream>-  spawn_argv(const std::vector<std::string> &argv);+  friend std::optional<Stream> spawn_argv(const std::vector<std::string> &argv);    [[nodiscard]] Kind kind() const { return kind_; }   [[nodiscard]] void *ssl() const { return ssl_; }--- a/xveins/src/net_commands.cpp+++ b/xveins/src/net_commands.cpp@@ -23,13 +23,22 @@ namespace {  bool starts_with(std::string_view text, std::string_view prefix) {-  return text.size() >= prefix.size() && text.substr(0, prefix.size()) == prefix;+  return text.size() >= prefix.size() &&+         text.substr(0, prefix.size()) == prefix; } -bool is_flag(std::string_view arg) { return !arg.empty() && arg.front() == '-'; }+bool is_flag(std::string_view arg) {+  return !arg.empty() && arg.front() == '-';+}  std::string arg_at(const std::vector<std::string> &args, std::size_t index) {   return index < args.size() ? args[index] : std::string();+}++void report_connect_failure(std::string_view fallback) {+  error_prefix();+  const std::string &detail = proto::Client::last_connect_error();+  std::cout << (detail.empty() ? std::string(fallback) : detail) << "\n"; }  std::string trim_text(std::string_view text) {@@ -367,10 +376,12 @@  void auth_usage() {   std::cout << "usage: vn auth <use|list|remove> ...\n";-  std::cout << "  vn auth use <key> [<host|url>]   set the default or host key\n";+  std::cout+      << "  vn auth use <key> [<host|url>]   set the default or host key\n";   std::cout << "  vn auth list                     show stored key mappings\n";-  std::cout << "  vn auth remove [<host|url>]      remove a mapping (default if "-               "omitted)\n";+  std::cout+      << "  vn auth remove [<host|url>]      remove a mapping (default if "+         "omitted)\n"; }  std::optional<PublicKey> read_public_key(std::string_view arg) {@@ -379,9 +390,8 @@   auto data = read_file_opt(path_from_bytes(arg));   if (!data)     return std::nullopt;-  const std::string text = trim_text(-      std::string_view(reinterpret_cast<const char *>(data->data()),-                       data->size()));+  const std::string text = trim_text(std::string_view(+      reinterpret_cast<const char *>(data->data()), data->size()));   return parse_public_key(text); } @@ -578,8 +588,7 @@   const std::string repo_name = proto::url_repo_name(url);   auto client = proto::Client::connect(url, key_name, repo_name, tls_pin);   if (!client) {-    error_prefix();-    std::cout << "cannot connect or authenticate\n";+    report_connect_failure("cannot connect or authenticate");     return 1;   }   std::vector<proto::RefInfo> refs;@@ -710,14 +719,14 @@   std::string pin;   if (!explicit_pin.empty()) {     pin = explicit_pin;-  } else if (auto configured = config_value(root, remote_key(remote_name, "tls-pin"))) {+  } else if (auto configured =+                 config_value(root, remote_key(remote_name, "tls-pin"))) {     pin = *configured;   }   const std::string repo_name = proto::url_repo_name(*url);   auto client = proto::Client::connect(*url, key, repo_name, pin);   if (!client) {-    error_prefix();-    std::cout << "cannot connect or authenticate\n";+    report_connect_failure("cannot connect or authenticate");     return 1;   }   std::vector<proto::RefInfo> refs;@@ -832,7 +841,8 @@   std::string pin;   if (!explicit_pin.empty()) {     pin = explicit_pin;-  } else if (auto configured = config_value(root, remote_key(remote_name, "tls-pin"))) {+  } else if (auto configured =+                 config_value(root, remote_key(remote_name, "tls-pin"))) {     pin = *configured;   } @@ -857,8 +867,7 @@   const std::string repo_name = proto::url_repo_name(*url);   auto client = proto::Client::connect(*url, key, repo_name, pin);   if (!client) {-    error_prefix();-    std::cout << "cannot connect or authenticate\n";+    report_connect_failure("cannot connect or authenticate");     return 1;   }   std::vector<proto::RefInfo> refs;@@ -975,8 +984,7 @@   const std::string sub = arg_at(args, 2);   if (sub.empty()) {     error_prefix();-    std::cout-        << "expected key subcommand (generate, list, show, import)\n";+    std::cout << "expected key subcommand (generate, list, show, import)\n";     return 1;   }   if (sub == "generate") {@@ -1046,8 +1054,7 @@     }     if (!auth::load_key(name)) {       error_prefix();-      std::cout << "key not found or has unsafe permissions: " << name-                << "\n";+      std::cout << "key not found or has unsafe permissions: " << name << "\n";       return 1;     }     const std::string target = auth::normalize_target(arg_at(args, 4));@@ -1248,8 +1255,7 @@   }   auto client = proto::Client::connect(url, key, repo_name, pin);   if (!client) {-    error_prefix();-    std::cout << "cannot authenticate\n";+    report_connect_failure("cannot authenticate");     return 1;   }   std::uint8_t role = 0;@@ -1282,8 +1288,10 @@     std::cout << "  remove <name>             remove a remote\n\n";     std::cout << "an empty -key: or -pin: value clears that setting\n\n";     std::cout << "examples:\n";-    std::cout << "  vn remote add origin veins://127.0.0.1:7419/navid-m/veins2\n";-    std::cout << "  vn remote set-url origin veins://example/repo -key:my-key\n";+    std::cout+        << "  vn remote add origin veins://127.0.0.1:7419/navid-m/veins2\n";+    std::cout+        << "  vn remote set-url origin veins://example/repo -key:my-key\n";     return true;   }   if (command == "clone") {@@ -1302,7 +1310,8 @@     return true;   }   if (command == "push") {-    std::cout << "usage: vn push [-key:<name>] [<remote>] [<bookmark>] [path]\n\n";+    std::cout+        << "usage: vn push [-key:<name>] [<remote>] [<bookmark>] [path]\n\n";     std::cout << "push a bookmark to a configured native remote\n\n";     std::cout << "without <bookmark>, the current bookmark is pushed\n";     std::cout << "auth falls back to remote.<name>.key, then 'vn auth use'\n";@@ -1312,7 +1321,8 @@     std::cout << "usage: vn serve -stdio <repo> [-quota <bytes>]\n";     std::cout << "       vn serve -listen <addr:port> -root <dir> -tls-cert "                  "<file> -tls-key <file> [-quota <bytes>]\n\n";-    std::cout << "run the native server over standard input/output or TLS 1.3\n";+    std::cout+        << "run the native server over standard input/output or TLS 1.3\n";     std::cout << "-quota limits stored pack and index bytes per top-level "                  "namespace\n";     return true;@@ -1327,7 +1337,8 @@     std::cout << "remember which key clone/fetch/push should use\n\n";     std::cout << "  vn auth use <key> [<host|url>]   set the default or host "                  "key\n";-    std::cout << "  vn auth list                     show stored key mappings\n";+    std::cout+        << "  vn auth list                     show stored key mappings\n";     std::cout << "  vn auth remove [<host|url>]      remove a mapping\n";     return true;   }--- a/xveins/src/oplog.cpp+++ b/xveins/src/oplog.cpp@@ -39,13 +39,13 @@ }  void sort_operations(std::vector<OpRec> &recs) {-  std::stable_sort(recs.begin(), recs.end(), [](const OpRec &a, const OpRec &b) {-    return a.op.end.ms > b.op.end.ms;-  });+  std::stable_sort(+      recs.begin(), recs.end(),+      [](const OpRec &a, const OpRec &b) { return a.op.end.ms > b.op.end.ms; }); } -std::optional<std::size_t> resolve_operation(-    const std::vector<OpRec> &recs, std::string_view text) {+std::optional<std::size_t> resolve_operation(const std::vector<OpRec> &recs,+                                             std::string_view text) {   std::optional<std::size_t> found;   std::size_t count = 0;   for (std::size_t i = 0; i < recs.size(); ++i) {@@ -99,8 +99,7 @@   sort_operations(recs);   for (const auto &rec : recs) {     const std::string marker = contains_id(heads, rec.id) ? "@" : " ";-    const std::string stamp =-        format_utc(rec.op.end.ms / 1000);+    const std::string stamp = format_utc(rec.op.end.ms / 1000);     std::cout << marker << " " << hex_encode(rec.id).substr(0, 12) << " "               << stamp << " " << rec.op.description << "\n";   }--- a/xveins/src/protocol.cpp+++ b/xveins/src/protocol.cpp@@ -12,6 +12,9 @@ namespace vn::proto {  namespace {++std::string connect_error;+std::string &connect_error_slot() { return connect_error; }  void put_u16_be(ByteWriter &writer, std::uint16_t value) {   writer.u8(static_cast<std::uint8_t>((value >> 8) & 255u));@@ -110,9 +113,8 @@   return out; } -std::optional<net::Stream> connect_stream(const Url &url,-                                          std::string_view tls_pin,-                                          std::string &binding) {+std::optional<net::Stream>+connect_stream(const Url &url, std::string_view tls_pin, std::string &binding) {   if (url.ssh) {     std::vector<std::string> remote = {"vn", "serve", "-stdio", url.path};     const std::string remote_command = net::build_shell_command(remote);@@ -123,15 +125,22 @@     }     argv.push_back(url.host);     argv.push_back(remote_command);-    return net::Stream::spawn_argv(argv);+    auto stream = net::Stream::spawn_argv(argv);+    if (!stream)+      connect_error = "cannot start the SSH transport";+    return stream;   }   if (url.tls) {     auto fd = net::tcp_connect(url.host, url.port);-    if (!fd)+    if (!fd) {+      connect_error =+          "cannot connect: host refused the connection or is unreachable";       return std::nullopt;+    }     void *ctx = net::tls_client_ctx(!tls_pin.empty());     if (!ctx) {       net::close_socket(*fd);+      connect_error = "cannot initialize TLS";       return std::nullopt;     }     void *ssl = net::tls_connect(ctx, *fd, url.host);@@ -138,6 +147,7 @@     net::tls_ctx_free(ctx);     if (!ssl) {       net::close_socket(*fd);+      connect_error = "TLS handshake failed";       return std::nullopt;     }     std::array<std::uint8_t, 32> exported{};@@ -151,6 +161,7 @@       if (!got || !net::hex_equal(hex, tls_pin)) {         net::close_socket(*fd);         net::tls_free(ssl);+        connect_error = "TLS certificate pin mismatch";         return std::nullopt;       }     }@@ -158,7 +169,10 @@   }   std::vector<std::string> argv = {path_to_bytes(net::self_exe()), "serve",                                    "-stdio", url.path};-  return net::Stream::spawn_argv(argv);+  auto stream = net::Stream::spawn_argv(argv);+  if (!stream)+    connect_error = "cannot start the local vn server";+  return stream; }  std::string id_text(const Id &id) { return hex_encode(id); }@@ -489,7 +503,8 @@ }  std::string auth_message(std::uint16_t version, std::string_view repo,-                         Bytes server_nonce, Bytes client_nonce, Bytes binding) {+                         Bytes server_nonce, Bytes client_nonce,+                         Bytes binding) {   ByteWriter writer(128);   writer.raw(std::string_view("veins-auth/1"));   writer.u8(0);@@ -519,7 +534,8 @@   constexpr std::string_view ssh_prefix = "ssh://";   constexpr std::string_view veins_prefix = "veins://";   if (url.starts_with(file_prefix))-    return Url{false, false, {}, 0, std::string(url.substr(file_prefix.size()))};+    return Url{+        false, false, {}, 0, std::string(url.substr(file_prefix.size()))};   if (url.starts_with(ssh_prefix)) {     std::string_view rest = url.substr(ssh_prefix.size());     const auto slash = rest.find('/');@@ -585,27 +601,35 @@   }   return frame; }++const std::string &Client::last_connect_error() { return connect_error; }  std::optional<Client> Client::connect(std::string_view url,                                       std::string_view key_name,                                       std::string_view repo_name,                                       std::string_view tls_pin) {+  connect_error.clear();   auto parsed = parse_url(url);-  if (!parsed)+  if (!parsed) {+    connect_error = "invalid remote URL";     return std::nullopt;+  }   std::string binding;   auto stream = connect_stream(*parsed, tls_pin, binding);-  if (!stream)+  if (!stream) {+    if (connect_error.empty())+      connect_error = "cannot establish a connection";     return std::nullopt;+  }    const auto nonce_bytes = secure_random(32);   if (nonce_bytes.size() != 32) {     stream->close();+    connect_error = "cannot generate a secure nonce";     return std::nullopt;   }-  const std::string client_nonce(reinterpret_cast<const char *>(-                                     nonce_bytes.data()),-                                 nonce_bytes.size());+  const std::string client_nonce(+      reinterpret_cast<const char *>(nonce_bytes.data()), nonce_bytes.size());    Hello hello;   hello.capabilities = {"zstd-records", "lazy-chunks", "push", "auth-ed25519"};@@ -614,16 +638,19 @@   const auto hello_body = encode_hello(hello);   if (!wire::write_frame(*stream, wire::HELLO, 1, hello_body)) {     stream->close();+    connect_error = "connection closed during the protocol handshake";     return std::nullopt;   }   auto hello_frame = wire::read_frame(*stream);   if (!hello_frame || hello_frame->kind != wire::HELLO_OK) {     stream->close();+    connect_error = "server rejected the protocol handshake";     return std::nullopt;   }   auto hello_ok = decode_hello_ok(hello_frame->payload);   if (!hello_ok) {     stream->close();+    connect_error = "server sent an invalid protocol handshake";     return std::nullopt;   } @@ -648,18 +675,17 @@                 client_nonce.size()),           Bytes(reinterpret_cast<const std::uint8_t *>(client.binding_.data()),                 client.binding_.size()));-      auto signature = ed25519_sign(Bytes(key->seed.data(), key->seed.size()),-                                    Bytes(reinterpret_cast<const std::uint8_t *>(-                                              message.data()),-                                          message.size()));+      auto signature = ed25519_sign(+          Bytes(key->seed.data(), key->seed.size()),+          Bytes(reinterpret_cast<const std::uint8_t *>(message.data()),+                message.size()));       if (signature) {         Auth auth;         auth.public_key.assign(             reinterpret_cast<const char *>(key->public_key.data()),             key->public_key.size());-        auth.signature.assign(-            reinterpret_cast<const char *>(signature->data()),-            signature->size());+        auth.signature.assign(reinterpret_cast<const char *>(signature->data()),+                              signature->size());         const auto body = encode_auth(auth);         if (wire::write_frame(client.stream_, wire::AUTH, 2, body)) {           auto reply = wire::read_frame(client.stream_);@@ -677,9 +703,14 @@   }    if (hello_ok->auth_required != 0 && !client.authed_) {+    connect_error = selected_key.empty()+                        ? "authentication required but no key is configured"+                        : "authentication failed: the key is missing or not "+                          "authorized";     client.stream_.close();     return std::nullopt;   }+  connect_error.clear();   return client; } @@ -750,8 +781,7 @@     if (!record) {       good = false;     } else {-      const Id computed =-          object_id(record->kind, bytes_of(record->body));+      const Id computed = object_id(record->kind, bytes_of(record->body));       if (std::memcmp(computed.data(), record->id.data(), ID_LEN) != 0) {         good = false;       } else {--- a/xveins/src/protocol.h+++ b/xveins/src/protocol.h@@ -79,14 +79,16 @@                                            const std::vector<Id> &haves); std::optional<Negotiate> decode_negotiate(Bytes data); -std::vector<std::uint8_t> encode_negotiate_ok(const std::vector<std::uint8_t> &known,-                                              std::uint8_t enough);+std::vector<std::uint8_t>+encode_negotiate_ok(const std::vector<std::uint8_t> &known,+                    std::uint8_t enough); std::optional<std::vector<std::uint8_t>> decode_negotiate_ok(Bytes data);  std::vector<std::uint8_t> encode_bitmap(const std::vector<std::uint8_t> &bits); std::optional<std::vector<std::uint8_t>> decode_bitmap(Bytes data); -std::vector<std::uint8_t> encode_update_refs(const std::vector<UpdateRef> &updates);+std::vector<std::uint8_t>+encode_update_refs(const std::vector<UpdateRef> &updates); std::optional<std::vector<UpdateRef>> decode_update_refs(Bytes data);  // The bytes signed in AUTH.@@ -128,6 +130,7 @@                                        std::string_view key_name,                                        std::string_view repo_name,                                        std::string_view tls_pin = {});+  static const std::string &last_connect_error();    bool list_refs(std::vector<RefInfo> &refs);   bool negotiate(const std::vector<Id> &wants, const std::vector<Id> &haves);--- a/xveins/src/remove.cpp+++ b/xveins/src/remove.cpp@@ -102,7 +102,8 @@     if (path_removed(full, removes))       continue;     if (entry.kind == KIND_SUBTREE && subtree_affected(full, removes)) {-      auto child = filter_tree(tx, store, entry.target, full, removes, depth + 1);+      auto child =+          filter_tree(tx, store, entry.target, full, removes, depth + 1);       if (child)         entries.push_back(TreeEntry{entry.name, entry.kind, *child});     } else {@@ -147,7 +148,8 @@   } } -int delete_paths(const fs::path &root, const std::vector<std::string> &removes) {+int delete_paths(const fs::path &root,+                 const std::vector<std::string> &removes) {   std::size_t failed = 0;   for (const auto &rel : removes) {     if (!delete_one(root, rel))@@ -213,19 +215,22 @@     for (const auto &rel : removes) {       if (!ignore_path_ignored(root, rel)) {         warning_prefix();-        std::cout << rel-                  << " is not ignored and will be re-added on the next snapshot\n";+        std::cout+            << rel+            << " is not ignored and will be re-added on the next snapshot\n";       }     }   } -  auto new_root = filter_tree(*tx, store, loaded->commit.root_tree, "", removes, 0);+  auto new_root =+      filter_tree(*tx, store, loaded->commit.root_tree, "", removes, 0);   Id root_id{};   if (new_root)     root_id = *new_root;   else     root_id = empty_tree_id(*tx);-  if (std::memcmp(root_id.data(), loaded->commit.root_tree.data(), ID_LEN) == 0) {+  if (std::memcmp(root_id.data(), loaded->commit.root_tree.data(), ID_LEN) ==+      0) {     error_prefix();     std::cout << "no tracked paths to remove\n";     return 1;--- a/xveins/src/server.cpp+++ b/xveins/src/server.cpp@@ -156,8 +156,9 @@   auto loaded = load_commit(session.store, id);   if (!loaded)     return {};-  return std::string(reinterpret_cast<const char *>(loaded->commit.change_id.data()),-                     loaded->commit.change_id.size());+  return std::string(+      reinterpret_cast<const char *>(loaded->commit.change_id.data()),+      loaded->commit.change_id.size()); }  bool send_record(Session &session, std::uint32_t request_id,@@ -236,8 +237,8 @@     failed = true;     return;   }-  if (send && !send_record(session, request_id, hasher, id, kind,-                           bytes_of(*body))) {+  if (send &&+      !send_record(session, request_id, hasher, id, kind, bytes_of(*body))) {     failed = true;   }   if (kind == TYPE_BLOB) {@@ -361,8 +362,7 @@   PublicKey public_key{};   const bool key_well_formed = auth->public_key.size() == public_key.size();   if (key_well_formed) {-    std::memcpy(public_key.data(), auth->public_key.data(),-                public_key.size());+    std::memcpy(public_key.data(), auth->public_key.data(), public_key.size());   }   std::uint8_t role = auth::ROLE_UNKNOWN;   if (key_well_formed && session.repo_present && session.access.valid)@@ -396,8 +396,8 @@   auth_ok.role = role;   auth_ok.fingerprint = session.fingerprint;   const auto body = proto::encode_auth_ok(auth_ok);-  const bool wrote = wire::write_frame(session.stream, wire::AUTH_OK,-                                       frame.request_id, body);+  const bool wrote =+      wire::write_frame(session.stream, wire::AUTH_OK, frame.request_id, body);   log_outcome(session, "auth-ok");   return wrote; }@@ -470,11 +470,10 @@     known.push_back(found ? 1 : 0);     any_known = any_known || found;   }-  const std::uint8_t enough =-      (session.haves.empty() || any_known) ? 1 : 0;+  const std::uint8_t enough = (session.haves.empty() || any_known) ? 1 : 0;   const auto body = proto::encode_negotiate_ok(known, enough);-  return wire::write_frame(session.stream, wire::NEGOTIATE_OK,-                           frame.request_id, body);+  return wire::write_frame(session.stream, wire::NEGOTIATE_OK, frame.request_id,+                           body); }  bool handle_fetch(Session &session, const wire::Frame &frame) {@@ -530,8 +529,7 @@ bool handle_get_chunks(Session &session, const wire::Frame &frame) {   if (deny(session, frame.request_id, false))     return true;-  auto ids = proto::decode_ids(bytes_of(frame.payload),-                               MAX_CHUNKS_PER_REQUEST);+  auto ids = proto::decode_ids(bytes_of(frame.payload), MAX_CHUNKS_PER_REQUEST);   if (!ids) {     wire::write_error(session.stream, frame.request_id, wire::ERR_BAD_FRAME,                       "bad chunk list");@@ -580,8 +578,8 @@   for (const auto &id : *ids)     bits.push_back(session.store.find(id).has_value() ? 1 : 0);   const auto body = proto::encode_bitmap(bits);-  return wire::write_frame(session.stream, wire::HAVE_BITMAP,-                           frame.request_id, body);+  return wire::write_frame(session.stream, wire::HAVE_BITMAP, frame.request_id,+                           body); }  bool object_exists(Session &session, const Id &id) {@@ -741,7 +739,8 @@   if (status != 0) {     wire::write_error(session.stream, frame.request_id,                       status == 2 ? wire::ERR_QUOTA : wire::ERR_INTERNAL,-                      status == 2 ? "storage quota exceeded" : "pack write failed");+                      status == 2 ? "storage quota exceeded"+                                  : "pack write failed");     return true;   }   open_session_store(session);@@ -794,8 +793,7 @@       view.bookmarks.erase(view.bookmarks.begin() +                            static_cast<std::ptrdiff_t>(*index));     if (auto index = find_tag(view, name))-      view.tags.erase(view.tags.begin() +-                      static_cast<std::ptrdiff_t>(*index));+      view.tags.erase(view.tags.begin() + static_cast<std::ptrdiff_t>(*index));     return;   }   if (auto index = find_bookmark(view, name)) {--- a/xveins/src/tag.cpp+++ b/xveins/src/tag.cpp@@ -33,8 +33,8 @@     const auto c = static_cast<unsigned char>(raw);     if (c == 0 || c == ' ' || c < 32 || c == 127)       return false;-    if (c == '~' || c == '^' || c == ':' || c == '?' || c == '*' ||-        c == '[' || c == '\\')+    if (c == '~' || c == '^' || c == ':' || c == '?' || c == '*' || c == '[' ||+        c == '\\')       return false;   }   if (tag_contains(name, "..") || tag_contains(name, "@{") ||@@ -386,7 +386,8 @@   std::cout << "manage named pointers to commits (tags)\n";   std::cout << "\n";   std::cout << "subcommands:\n";-  std::cout << "  set <name> [-rev <rev>]   create or move a tag (default: @)\n";+  std::cout+      << "  set <name> [-rev <rev>]   create or move a tag (default: @)\n";   std::cout << "  ls [-no-col-titles]       list tags\n";   std::cout << "  rm <name>                 delete a tag\n";   std::cout << "  latest                    print the latest tag name\n";--- a/xveins/src/wire.cpp+++ b/xveins/src/wire.cpp@@ -166,9 +166,8 @@     return record;   }   record.body.resize(static_cast<std::size_t>(*raw_len));-  const std::size_t result =-      ZSTD_decompress(record.body.data(), record.body.size(), stored->data(),-                      stored->size());+  const std::size_t result = ZSTD_decompress(+      record.body.data(), record.body.size(), stored->data(), stored->size());   if (ZSTD_isError(result) || result != record.body.size())     return std::nullopt;   return record;--- a/xveins/src/worktree.cpp+++ b/xveins/src/worktree.cpp@@ -844,19 +844,18 @@     renames = old_commit->renames;   if (old_tree &&       std::memcmp(old_tree->data(), new_root->data(), ID_LEN) != 0) {-    auto detected = detect_renames(-        tx->store(), &*tx, old_tree, std::optional<Id>{*new_root},-        rename_similar_pct(root), 0);+    auto detected = detect_renames(tx->store(), &*tx, old_tree,+                                   std::optional<Id>{*new_root},+                                   rename_similar_pct(root), 0);     for (auto &rename : detected)       renames.push_back(std::move(rename));   }-  std::stable_sort(renames.begin(), renames.end(),-                   [](const Rename &a, const Rename &b) {-                     if (a.parent_index != b.parent_index)-                       return a.parent_index < b.parent_index;-                     return compare(bytes_of(a.to_path), bytes_of(b.to_path)) <-                            0;-                   });+  std::stable_sort(+      renames.begin(), renames.end(), [](const Rename &a, const Rename &b) {+        if (a.parent_index != b.parent_index)+          return a.parent_index < b.parent_index;+        return compare(bytes_of(a.to_path), bytes_of(b.to_path)) < 0;+      });    Commit commit;   commit.version = 1;