Markus Armbruster <[email protected]> writes:
> John Snow <[email protected]> writes:
>
>> On Fri, Jul 24, 2026 at 4:38 AM Markus Armbruster <[email protected]> wrote:
>
> [...]
>
>>> I believe all the problematic first paragraphs consist of more than one
>>> sentence. What about splitting "trivial" into "very trivial" (just one
>>> paragraph, no sentence-ending punctuation in the middle) and "hopefully
>>> trivial" (just one paragraph, remainder)?
>>
>> That's tricky to automate, and doing it by hand doesn't sound much fun
>> either... can we just power through one-by-one?
>>
>> Unless you have a script or a trick you believe will help, and then I
>> am happy to oblige.
>
> By hand would clearly be a bad use of your time.
>
> I'll look into automating it.
Lightly tested throwaway script:
#!/usr/bin/env python3
import os
import re
import subprocess
import sys
proc = subprocess.Popen(['/usr/bin/git', 'add', '-p'],
bufsize=1,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
text=True)
n = 0
while True:
n += 1
chunk = os.read(proc.stdout.fileno(), 1024*1024).decode('utf-8')
if not chunk:
break
lines = chunk.splitlines()
prompt = lines[-1]
if prompt.find('Stage this hunk') == -1:
print(f"{sys.argv[0]}: no recognizable prompt after chunk #{n}",
file=sys.stderr)
break
#old = '\n'.join(filter(lambda l: re.match(r'^[- ]', l), lines))
#print(old)
deleted = '\n'.join(filter(lambda l: re.match(r'^-#', l), lines))
if re.search(r'[!.?].*[!.?]', deleted, flags=re.DOTALL):
proc.stdin.write('n\n')
else:
proc.stdin.write('y\n')
ch = os.read(proc.stdout.fileno(), 1).decode('utf-8')
try:
proc.wait(1)
except:
print(f"{sys.argv[0]}: git-add appears to hang, sending SIGTERM",
file=sys.stderr)
proc.terminate()
proc.wait()
if proc.returncode != 0:
print(f"{sys.argv[0]}: git-add terminated abnormally
(code={proc.returncode})",
file=sys.stderr)