Answer architecture round 2: list an override by its branch or by a commit the default branch lacks, so an amend or a rebase hides none, split main into reading, judging and answering, move the hook input into call.py, strip comments with one pattern, and log overrides only once each can be

This commit is contained in:
2026-10-12 23:50:41 +02:00
parent f3bfff1af4
commit 11e613d083
6 changed files with 157 additions and 110 deletions
+3 -24
View File
@@ -7,6 +7,8 @@ import shlex
HEREDOC = re.compile(r"<<-?[ \t]*([\"']?)([A-Za-z_]\w*)\1[^\n]*\n.*?^[ \t]*\2[ \t]*$", re.DOTALL | re.MULTILINE)
ASSIGNMENT = re.compile(r"[A-Za-z_][A-Za-z0-9_]*=")
OPERATOR = set("\n();&|<>")
# A quoted string or an escape is taken whole, so a # inside one starts no comment; a comment starts a word.
PIECE = re.compile(r"""'[^']*'|"(?:\\.|[^"\\])*"|\\.|(?<![^\s;&|()])#[^\n]*""", re.DOTALL)
@dataclasses.dataclass(frozen=True)
@@ -59,30 +61,7 @@ def lexed(text: str) -> list[str] | None:
def uncommented(text: str) -> str:
"""The text without its comments; shlex's own would also swallow the line break that ends one, joining two commands."""
kept = []
quote = ""
at = 0
while at < len(text):
char = text[at]
if quote:
if char == "\\" and quote == '"':
kept.append(text[at:at + 2])
at += 2
continue
quote = "" if char == quote else quote
elif char == "\\":
kept.append(text[at:at + 2])
at += 2
continue
elif char in "'\"":
quote = char
elif char == "#" and (at == 0 or text[at - 1] in " \t\n;&|()"):
end = text.find("\n", at)
at = len(text) if end < 0 else end
continue
kept.append(char)
at += 1
return "".join(kept)
return PIECE.sub(lambda piece: "" if piece.group(0).startswith("#") else piece.group(0), text)
def resolved(base: str, path: str, home: str) -> str: