intentumdiff-python 0.0.2b2__py3-none-win_arm64.whl → 0.0.3b1__py3-none-win_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- intentumdiff/__init__.py +7 -0
- intentumdiff/_differ_gate.py +0 -136
- intentumdiff/_differ_presentation.py +1 -72
- intentumdiff/_differ_runtime.py +0 -17
- intentumdiff/analysis/cross_file.py +21 -21
- intentumdiff/analysis/diagnostics.py +1 -164
- intentumdiff/analysis/guardrail_reports.py +24 -28
- intentumdiff/analysis/guardrails.py +2 -67
- intentumdiff/analysis/schema_resolver.py +23 -87
- intentumdiff/analysis/user_schemas.py +2 -17
- intentumdiff/cli/_commands.py +70 -71
- intentumdiff/cli/_parser.py +40 -55
- intentumdiff/cli/_shared.py +55 -4
- intentumdiff/core/commit_differ.py +65 -99
- intentumdiff/core/indexer.py +0 -1
- intentumdiff/core/models.py +226 -69
- intentumdiff/differ.py +125 -432
- intentumdiff/github_app.py +5 -8
- intentumdiff/intentumdiff_rust_core/intentumdiff_rust_core.dll +0 -0
- intentumdiff/live_server.py +17 -17
- intentumdiff/lsp/client.py +42 -42
- intentumdiff/lsp/servers.py +10 -11
- intentumdiff/lsp_server/_handlers.py +1 -1
- intentumdiff/lsp_server/server.py +0 -1
- intentumdiff/plugins/exceptions.py +24 -0
- intentumdiff/plugins/hub.py +38 -41
- intentumdiff/plugins/registry.py +10 -10
- intentumdiff/plugins/registry.schema.json +156 -15
- intentumdiff/plugins/registry_schema.py +47 -140
- intentumdiff/rust_core.py +112 -775
- intentumdiff/serve/_app.py +23 -25
- intentumdiff/sources/git_source.py +0 -183
- intentumdiff/vcs/git_cli.py +0 -47
- intentumdiff/wasm/abap_parser.wasm +0 -0
- intentumdiff/wasm/adf_parser.wasm +0 -0
- intentumdiff/wasm/asciidoc_parser.wasm +0 -0
- intentumdiff/wasm/asm_parser.wasm +0 -0
- intentumdiff/wasm/assemblyscript_parser.wasm +0 -0
- intentumdiff/wasm/astro_parser.wasm +0 -0
- intentumdiff/wasm/bash_parser.wasm +0 -0
- intentumdiff/wasm/cpp_parser.wasm +0 -0
- intentumdiff/wasm/csharp_parser.wasm +0 -0
- intentumdiff/wasm/databricks_parser.wasm +0 -0
- intentumdiff/wasm/dax_parser.wasm +0 -0
- intentumdiff/wasm/dockerfile_parser.wasm +0 -0
- intentumdiff/wasm/freebasic_parser.wasm +0 -0
- intentumdiff/wasm/generic_parser.wasm +0 -0
- intentumdiff/wasm/gitignore_parser.wasm +0 -0
- intentumdiff/wasm/graphql_parser.wasm +0 -0
- intentumdiff/wasm/groovy_parser.wasm +0 -0
- intentumdiff/wasm/js_ts_parser.wasm +0 -0
- intentumdiff/wasm/json_parser.wasm +0 -0
- intentumdiff/wasm/kotlin_parser.wasm +0 -0
- intentumdiff/wasm/latex_parser.wasm +0 -0
- intentumdiff/wasm/make_parser.wasm +0 -0
- intentumdiff/wasm/mdx_parser.wasm +0 -0
- intentumdiff/wasm/ocaml_parser.wasm +0 -0
- intentumdiff/wasm/odin_parser.wasm +0 -0
- intentumdiff/wasm/perl_parser.wasm +0 -0
- intentumdiff/wasm/php_parser.wasm +0 -0
- intentumdiff/wasm/plsql_parser.wasm +0 -0
- intentumdiff/wasm/postscript_parser.wasm +0 -0
- intentumdiff/wasm/powershell_parser.wasm +0 -0
- intentumdiff/wasm/python_parser.wasm +0 -0
- intentumdiff/wasm/qsharp_parser.wasm +0 -0
- intentumdiff/wasm/reasonml_parser.wasm +0 -0
- intentumdiff/wasm/rust_parser.wasm +0 -0
- intentumdiff/wasm/sas_parser.wasm +0 -0
- intentumdiff/wasm/sql_parser.wasm +0 -0
- intentumdiff/wasm/svelte_parser.wasm +0 -0
- intentumdiff/wasm/swift_parser.wasm +0 -0
- intentumdiff/wasm/tsql_parser.wasm +0 -0
- intentumdiff/wasm/vbnet_parser.wasm +0 -0
- intentumdiff/wasm/vue_parser.wasm +0 -0
- intentumdiff/wasm/wasm_provenance.json +219 -219
- intentumdiff/wasm/wat_parser.wasm +0 -0
- intentumdiff/wasm/yaml_parser.wasm +0 -0
- intentumdiff/watcher.py +15 -17
- {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/METADATA +38 -6
- intentumdiff_python-0.0.3b1.dist-info/RECORD +164 -0
- {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/sboms/intentumdiff-rust-core.cyclonedx.json +2 -2
- intentumdiff/analysis/invariances.py +0 -208
- intentumdiff/analysis/keyed_profiles.py +0 -25
- intentumdiff/analysis/resource_profiles.py +0 -14
- intentumdiff/analysis/text_review.py +0 -47
- intentumdiff/invariances/__init__.py +0 -2
- intentumdiff/invariances/rules.schema.json +0 -283
- intentumdiff/invariances/rules.yaml +0 -349
- intentumdiff_python-0.0.2b2.dist-info/RECORD +0 -171
- {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/WHEEL +0 -0
- {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/entry_points.txt +0 -0
- {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/licenses/LICENSE +0 -0
intentumdiff/serve/_app.py
CHANGED
|
@@ -14,6 +14,7 @@ GET /api/docs — OpenAPI / Swagger UI (auto-generated by FastAPI)
|
|
|
14
14
|
from __future__ import annotations
|
|
15
15
|
|
|
16
16
|
import asyncio
|
|
17
|
+
import json
|
|
17
18
|
import re
|
|
18
19
|
from pathlib import Path
|
|
19
20
|
from typing import Annotated, Any
|
|
@@ -53,6 +54,19 @@ _MAX_CANDIDATES = 50
|
|
|
53
54
|
_MAX_CANDIDATE_BYTES = 64
|
|
54
55
|
|
|
55
56
|
|
|
57
|
+
def _has_lone_surrogate(body: bytes) -> bool:
|
|
58
|
+
"""An escaped lone surrogate (``"\\ud800"``) is valid JSON but not a Unicode string (#316)."""
|
|
59
|
+
if not re.search(rb"\\u[dD][89a-fA-F]", body):
|
|
60
|
+
return False
|
|
61
|
+
try:
|
|
62
|
+
json.dumps(json.loads(body), ensure_ascii=False).encode("utf-8")
|
|
63
|
+
except UnicodeEncodeError:
|
|
64
|
+
return True
|
|
65
|
+
except ValueError: # not JSON at all: FastAPI's own validation answers it
|
|
66
|
+
pass
|
|
67
|
+
return False
|
|
68
|
+
|
|
69
|
+
|
|
56
70
|
def _request_body_too_large_response() -> Response:
|
|
57
71
|
limit_mb = _MAX_REQUEST_BODY_BYTES // (1024 * 1024)
|
|
58
72
|
return Response(
|
|
@@ -313,6 +327,9 @@ def create_app(
|
|
|
313
327
|
# Preserve the original receive callable so its next event is the real
|
|
314
328
|
# upstream disconnect, rather than a second replayed request.
|
|
315
329
|
request._body = body # type: ignore[attr-defined]
|
|
330
|
+
if _has_lone_surrogate(body): # rejected before validation, so no engine dispatch
|
|
331
|
+
return Response('{"detail": "strings must not contain lone surrogates"}',
|
|
332
|
+
status_code=422, media_type="application/json")
|
|
316
333
|
return await call_next(request)
|
|
317
334
|
|
|
318
335
|
if cors_origins is not None:
|
|
@@ -350,12 +367,12 @@ def create_app(
|
|
|
350
367
|
@app.get("/languages", summary="List supported languages")
|
|
351
368
|
async def languages() -> dict[str, list[str]]:
|
|
352
369
|
"""Return all language IDs accepted by the ``/diff`` endpoint."""
|
|
353
|
-
return {"languages": _supported_languages
|
|
370
|
+
return {"languages": await asyncio.to_thread(_supported_languages, _differ)} # #320
|
|
354
371
|
|
|
355
372
|
@app.get("/language-info", summary="List language and parser plugin metadata")
|
|
356
373
|
async def language_info() -> dict[str, list[dict[str, Any]]]:
|
|
357
374
|
"""Return grouped language/plugin metadata for the playground UI."""
|
|
358
|
-
return {"languages": _language_info
|
|
375
|
+
return {"languages": await asyncio.to_thread(_language_info, _differ)}
|
|
359
376
|
|
|
360
377
|
@app.post("/diff", summary="Compute semantic diff")
|
|
361
378
|
async def diff(req: DiffRequest) -> Response:
|
|
@@ -389,10 +406,7 @@ def create_app(
|
|
|
389
406
|
detail=f"Unknown language: {exc}",
|
|
390
407
|
) from exc
|
|
391
408
|
except GrammarNotInstalledError as exc:
|
|
392
|
-
raise HTTPException(
|
|
393
|
-
status_code=422,
|
|
394
|
-
detail=str(exc),
|
|
395
|
-
) from exc
|
|
409
|
+
raise HTTPException(status_code=422, detail=str(exc)) from exc
|
|
396
410
|
return Response(
|
|
397
411
|
content=result.model_dump_json(),
|
|
398
412
|
media_type="application/json",
|
|
@@ -408,26 +422,10 @@ def create_app(
|
|
|
408
422
|
regex heuristics in Python. The response is stateless.
|
|
409
423
|
"""
|
|
410
424
|
try:
|
|
425
|
+
args = (req.content, req.candidates, req.preferred_plugins, req.plugin_id)
|
|
426
|
+
count = 4 if req.plugin_id else 3 if req.preferred_plugins else 2
|
|
411
427
|
async with _sem:
|
|
412
|
-
|
|
413
|
-
results = await asyncio.to_thread(
|
|
414
|
-
_differ.detect_all,
|
|
415
|
-
req.content,
|
|
416
|
-
req.candidates,
|
|
417
|
-
req.preferred_plugins,
|
|
418
|
-
req.plugin_id,
|
|
419
|
-
)
|
|
420
|
-
elif req.preferred_plugins:
|
|
421
|
-
results = await asyncio.to_thread(
|
|
422
|
-
_differ.detect_all,
|
|
423
|
-
req.content,
|
|
424
|
-
req.candidates,
|
|
425
|
-
req.preferred_plugins,
|
|
426
|
-
)
|
|
427
|
-
else:
|
|
428
|
-
results = await asyncio.to_thread(
|
|
429
|
-
_differ.detect_all, req.content, req.candidates
|
|
430
|
-
)
|
|
428
|
+
results = await asyncio.to_thread(_differ.detect_all, *args[:count])
|
|
431
429
|
except PluginNotFoundError as exc:
|
|
432
430
|
raise HTTPException(
|
|
433
431
|
status_code=422,
|
|
@@ -13,15 +13,12 @@ path-traversal attacks before any I/O is performed.
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
15
|
import os
|
|
16
|
-
import subprocess
|
|
17
16
|
from collections.abc import Iterator
|
|
18
|
-
from pathlib import Path
|
|
19
17
|
|
|
20
18
|
from intentumdiff import content_type as _content_type
|
|
21
19
|
from intentumdiff.sources.base import Source
|
|
22
20
|
from intentumdiff.vcs._safe_path import safe_policy_path, safe_relative_path, safe_working_tree_path
|
|
23
21
|
from intentumdiff.vcs.git_cli import (
|
|
24
|
-
parse_name_status_z as _parse_name_status_z,
|
|
25
22
|
resolve_repo_root,
|
|
26
23
|
run_git_bytes,
|
|
27
24
|
)
|
|
@@ -49,191 +46,11 @@ def _safe_file_path(file_path: str) -> str:
|
|
|
49
46
|
return safe_relative_path(file_path)
|
|
50
47
|
|
|
51
48
|
|
|
52
|
-
# Change-type codes that produce binary-safe text blobs on both sides.
|
|
53
|
-
_TEXT_CHANGE_TYPES = frozenset({"A", "D", "M", "R", "C"})
|
|
54
|
-
|
|
55
|
-
|
|
56
49
|
# Sentinel new_ref values recognised by iter_changed_sources.
|
|
57
50
|
_REF_STAGED = ":staged" # compare HEAD to the git index (staged files only)
|
|
58
51
|
_REF_UNPUSHED = ":unpushed" # compare remote tracking branch to HEAD (unpushed commits)
|
|
59
52
|
|
|
60
53
|
|
|
61
|
-
_ChangedSource = tuple[str, str, str, str, str | None]
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
def _is_python_path(path: str) -> bool:
|
|
65
|
-
return path.lower().endswith((".py", ".pyi"))
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def _decode_git_path(path: bytes) -> str:
|
|
69
|
-
# A Git pathname need not be UTF-8 on every filesystem. Without a
|
|
70
|
-
# lossless byte transport to Rust, reject rather than invent a new name.
|
|
71
|
-
try:
|
|
72
|
-
return path.decode("utf-8", errors="strict")
|
|
73
|
-
except UnicodeDecodeError as exc:
|
|
74
|
-
raise UnicodeError("Invalid UTF-8 in Git pathname") from exc
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def _decode_nul_paths(data: bytes, *, source: str) -> list[str]:
|
|
78
|
-
"""Require a complete, nonempty Git -z path inventory (#239)."""
|
|
79
|
-
if not data:
|
|
80
|
-
return []
|
|
81
|
-
if not data.endswith(b"\0"):
|
|
82
|
-
raise RuntimeError(f"Incomplete {source} output: missing NUL terminator")
|
|
83
|
-
raw_paths = data[:-1].split(b"\0")
|
|
84
|
-
if any(not path for path in raw_paths):
|
|
85
|
-
raise RuntimeError(f"Empty path in {source} output")
|
|
86
|
-
return [_decode_git_path(path) for path in raw_paths]
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
def _untracked_paths(repo_path: str) -> list[str]:
|
|
90
|
-
data = run_git_bytes(repo_path, ["ls-files", "--others", "--exclude-standard", "-z"])
|
|
91
|
-
return sorted(_decode_nul_paths(data, source="git ls-files -z"))
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
def _read_working_tree_text(path: Path) -> str | None:
|
|
95
|
-
try:
|
|
96
|
-
data = path.read_bytes()
|
|
97
|
-
except OSError as exc:
|
|
98
|
-
# A failed read of an enumerated untracked file is not evidence that
|
|
99
|
-
# the file is binary; skipping it would certify an incomplete diff (#242).
|
|
100
|
-
raise RuntimeError(
|
|
101
|
-
f"Failed to read untracked working-tree source {path}: {exc}"
|
|
102
|
-
) from exc
|
|
103
|
-
# Content-based routing: binary/image assets are skipped (reviewed via the
|
|
104
|
-
# perceptual asset diff), never decoded and sent to the text engine.
|
|
105
|
-
return _decode_text_or_none(data)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
def _read_commit_paths_batch(
|
|
109
|
-
repo_path: str,
|
|
110
|
-
rev: str,
|
|
111
|
-
paths: list[str],
|
|
112
|
-
) -> dict[str, str]:
|
|
113
|
-
unique_paths = list(dict.fromkeys(paths))
|
|
114
|
-
if not unique_paths:
|
|
115
|
-
return {}
|
|
116
|
-
if any("\n" in path or "\r" in path for path in unique_paths):
|
|
117
|
-
raise ValueError("git cat-file batch path contains a newline")
|
|
118
|
-
|
|
119
|
-
request = "".join(f"{rev}:{path}\n" for path in unique_paths).encode("utf-8")
|
|
120
|
-
output = run_git_bytes(repo_path, ["cat-file", "--batch"], input_bytes=request)
|
|
121
|
-
result: dict[str, str] = {}
|
|
122
|
-
pos = 0
|
|
123
|
-
for path in unique_paths:
|
|
124
|
-
header_end = output.find(b"\n", pos)
|
|
125
|
-
if header_end < 0:
|
|
126
|
-
raise RuntimeError("malformed git cat-file batch output")
|
|
127
|
-
header = output[pos:header_end]
|
|
128
|
-
pos = header_end + 1
|
|
129
|
-
if header.endswith(b" missing"):
|
|
130
|
-
# Every requested non-addition path must exist in the base tree.
|
|
131
|
-
# An empty fallback would manufacture semantic change evidence (#241).
|
|
132
|
-
raise RuntimeError(f"Missing tracked Git baseline {rev}:{path}")
|
|
133
|
-
parts = header.split()
|
|
134
|
-
if len(parts) != 3 or parts[1] != b"blob":
|
|
135
|
-
raise RuntimeError("malformed git cat-file batch blob header")
|
|
136
|
-
try:
|
|
137
|
-
size = int(parts[2])
|
|
138
|
-
except ValueError as exc:
|
|
139
|
-
raise RuntimeError("malformed git cat-file batch size") from exc
|
|
140
|
-
if size < 0 or pos + size >= len(output) or output[pos + size] != 0x0A:
|
|
141
|
-
raise RuntimeError("incomplete git cat-file batch blob payload")
|
|
142
|
-
content = output[pos : pos + size]
|
|
143
|
-
pos += size + 1 # consume mandatory delimiter
|
|
144
|
-
try:
|
|
145
|
-
result[path] = content.decode("utf-8", errors="strict")
|
|
146
|
-
except UnicodeDecodeError as exc:
|
|
147
|
-
raise UnicodeError(
|
|
148
|
-
f"Invalid UTF-8 in tracked Git baseline {rev}:{path}"
|
|
149
|
-
) from exc
|
|
150
|
-
if pos != len(output):
|
|
151
|
-
raise RuntimeError("Unexpected extra git cat-file batch output")
|
|
152
|
-
return result
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
def collect_working_tree_python_sources_fast(
|
|
156
|
-
repo_path: "str | os.PathLike[str]",
|
|
157
|
-
old_ref: str,
|
|
158
|
-
) -> "tuple[list[_ChangedSource], str | None] | None":
|
|
159
|
-
"""
|
|
160
|
-
Fast working-tree collector for the certified Rust Python batch path.
|
|
161
|
-
|
|
162
|
-
Returns ``None`` when the conservative Git CLI path cannot be used and the
|
|
163
|
-
caller should fall back to ``iter_changed_sources``. A non-empty fallback
|
|
164
|
-
reason means the diff contains a non-Python changed file, so the certified
|
|
165
|
-
Python-only path must not run.
|
|
166
|
-
"""
|
|
167
|
-
try:
|
|
168
|
-
working_dir = resolve_repo_root(repo_path)
|
|
169
|
-
# git resolves the ref on each call; using it directly (vs a pre-resolved
|
|
170
|
-
# sha) is equivalent here and avoids an extra round-trip.
|
|
171
|
-
old_rev = old_ref
|
|
172
|
-
diff_output = run_git_bytes(working_dir, ["diff", "--name-status", "-z", old_rev])
|
|
173
|
-
entries = _parse_name_status_z(diff_output)
|
|
174
|
-
if any(code not in _TEXT_CHANGE_TYPES for code, _, _ in entries):
|
|
175
|
-
return ([], "Unsupported Git change status requires Rust review")
|
|
176
|
-
untracked_paths = _untracked_paths(working_dir)
|
|
177
|
-
if not entries and not untracked_paths:
|
|
178
|
-
return [], None
|
|
179
|
-
for _code, old_path, new_path in entries:
|
|
180
|
-
if not (_is_python_path(old_path) or _is_python_path(new_path)):
|
|
181
|
-
return (
|
|
182
|
-
[],
|
|
183
|
-
"certified commit JSON requires all changed files to be Python",
|
|
184
|
-
)
|
|
185
|
-
for untracked_path in untracked_paths:
|
|
186
|
-
if not _is_python_path(untracked_path):
|
|
187
|
-
return (
|
|
188
|
-
[],
|
|
189
|
-
"certified commit JSON requires all changed files to be Python",
|
|
190
|
-
)
|
|
191
|
-
|
|
192
|
-
staged_output = run_git_bytes(
|
|
193
|
-
working_dir,
|
|
194
|
-
["diff", "--cached", "--name-only", "-z", old_rev],
|
|
195
|
-
)
|
|
196
|
-
staged_paths = set(
|
|
197
|
-
_decode_nul_paths(staged_output, source="git diff --cached --name-only -z")
|
|
198
|
-
)
|
|
199
|
-
old_paths = [old_path for code, old_path, _new_path in entries if code != "A"]
|
|
200
|
-
old_contents = _read_commit_paths_batch(working_dir, old_rev, old_paths)
|
|
201
|
-
sources: list[_ChangedSource] = []
|
|
202
|
-
root = Path(working_dir)
|
|
203
|
-
for code, old_path, new_path in entries:
|
|
204
|
-
_safe_file_path(old_path)
|
|
205
|
-
_safe_file_path(new_path)
|
|
206
|
-
old_content = "" if code == "A" else old_contents[old_path]
|
|
207
|
-
if code == "D":
|
|
208
|
-
new_content = ""
|
|
209
|
-
else:
|
|
210
|
-
disk_path = safe_working_tree_path(root, new_path)
|
|
211
|
-
if not disk_path.exists():
|
|
212
|
-
new_content = ""
|
|
213
|
-
else:
|
|
214
|
-
new_content = disk_path.read_text(encoding="utf-8")
|
|
215
|
-
staging_status = (
|
|
216
|
-
"staged"
|
|
217
|
-
if old_path in staged_paths or new_path in staged_paths
|
|
218
|
-
else "unstaged"
|
|
219
|
-
)
|
|
220
|
-
sources.append((old_content, new_content, old_path, new_path, staging_status))
|
|
221
|
-
for untracked_path in untracked_paths:
|
|
222
|
-
_safe_file_path(untracked_path)
|
|
223
|
-
disk_path = safe_working_tree_path(root, untracked_path)
|
|
224
|
-
new_content = _read_working_tree_text(disk_path)
|
|
225
|
-
if new_content is None:
|
|
226
|
-
continue
|
|
227
|
-
sources.append(("", new_content, untracked_path, untracked_path, "untracked"))
|
|
228
|
-
return sources, None
|
|
229
|
-
except UnicodeError:
|
|
230
|
-
# The optimizer must not turn a bad source encoding into an altered,
|
|
231
|
-
# successful semantic review or silently reroute it as a normal decline.
|
|
232
|
-
raise
|
|
233
|
-
except (OSError, subprocess.SubprocessError, ValueError):
|
|
234
|
-
return None
|
|
235
|
-
|
|
236
|
-
|
|
237
54
|
def iter_changed_sources(
|
|
238
55
|
repo_path: "str | os.PathLike[str]",
|
|
239
56
|
old_ref: str,
|
intentumdiff/vcs/git_cli.py
CHANGED
|
@@ -71,50 +71,3 @@ def run_git_bytes(
|
|
|
71
71
|
return proc.stdout
|
|
72
72
|
|
|
73
73
|
|
|
74
|
-
def parse_name_status_z(data: bytes) -> "list[tuple[str, str, str]]":
|
|
75
|
-
"""Decode a complete Git name-status -z stream without losing file identities.
|
|
76
|
-
|
|
77
|
-
Git uses NUL terminators to delimit status tokens and raw pathname bytes.
|
|
78
|
-
A malformed stream or an undecodable path is an integrity failure, never a
|
|
79
|
-
successful partial change inventory (Python #240).
|
|
80
|
-
"""
|
|
81
|
-
if not data:
|
|
82
|
-
return []
|
|
83
|
-
if not data.endswith(b"\0"):
|
|
84
|
-
raise RuntimeError("Incomplete git name-status -z: missing NUL terminator")
|
|
85
|
-
|
|
86
|
-
tokens = data[:-1].split(b"\0")
|
|
87
|
-
entries: list[tuple[str, str, str]] = []
|
|
88
|
-
idx = 0
|
|
89
|
-
while idx < len(tokens):
|
|
90
|
-
try:
|
|
91
|
-
status = tokens[idx].decode("ascii", errors="strict")
|
|
92
|
-
except UnicodeDecodeError as exc:
|
|
93
|
-
raise UnicodeError("Invalid ASCII Git change status") from exc
|
|
94
|
-
idx += 1
|
|
95
|
-
if (
|
|
96
|
-
not status
|
|
97
|
-
or status[0] not in "ACDMRTUXB"
|
|
98
|
-
or (len(status) > 1 and (status[0] not in "RC" or not status[1:].isdigit()))
|
|
99
|
-
):
|
|
100
|
-
raise RuntimeError(f"Invalid git name-status code: {status!r}")
|
|
101
|
-
|
|
102
|
-
code = status[0]
|
|
103
|
-
needed = 2 if code in {"R", "C"} else 1
|
|
104
|
-
if len(tokens) - idx < needed:
|
|
105
|
-
raise RuntimeError(
|
|
106
|
-
f"Truncated git name-status -z: {code!r} requires {needed} path(s)"
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
raw_paths = tokens[idx : idx + needed]
|
|
110
|
-
idx += needed
|
|
111
|
-
if any(not path for path in raw_paths):
|
|
112
|
-
raise RuntimeError("Empty filename in git name-status -z")
|
|
113
|
-
try:
|
|
114
|
-
paths = [path.decode("utf-8", errors="strict") for path in raw_paths]
|
|
115
|
-
except UnicodeDecodeError as exc:
|
|
116
|
-
raise UnicodeError("Invalid UTF-8 in Git change filename") from exc
|
|
117
|
-
old_path = paths[0]
|
|
118
|
-
new_path = paths[1] if needed == 2 else old_path
|
|
119
|
-
entries.append((code, old_path, new_path))
|
|
120
|
-
return entries
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|