Skip to content

Commit 5ea41e6

Browse files
committed
fix: last interval hash was not correct
1 parent fc3e08b commit 5ea41e6

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

preprocess.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,26 @@ def process_header_file(input_file: Path, output_file: Path, interval: int = 8)
2828
lines = content.splitlines()
2929

3030
# Calculate positions and hashes
31-
positions = list(range(interval, len(lines), interval)) + [len(lines)+1]
31+
positions = list(range(0, len(lines), interval))
3232

33+
ends = []
3334
prefix_hashes = []
3435
hashes = []
3536
for pos in positions:
36-
# Join lines up to position and compute hash
37-
prefix = '\n'.join(lines[:pos])
37+
# Join lines from position up to position+interval and compute hash
38+
r = min(len(lines), pos+interval)
39+
ends.append(r)
40+
prefix = '\n'.join(lines[:r])
3841
prefix_hashes.append(hash_content(prefix))
3942

40-
segment = '\n'.join(lines[(pos-interval):pos])
43+
segment = '\n'.join(lines[pos:r])
4144
hashes.append(hash_content(segment))
4245

4346
# Write results
4447
with open(output_file, 'w') as f:
4548
f.write(f"hashes = {hashes}\n")
4649
f.write(f"prefix-hashes = {prefix_hashes}\n")
47-
f.write(f"positions = {positions}\n")
50+
f.write(f"positions = {ends}\n")
4851

4952
def main():
5053
# Configuration

template.typ

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
}
7373

7474
#let extract-code(contents) = {
75-
return contents.split("- */\n").at(-1)
75+
return contents.split("- */\n").at(-1).trim("\n")
7676
}
7777

7878
#let extract-metadata(contents) = {

0 commit comments

Comments
 (0)