forked from w3c/csswg-wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-history.py
More file actions
1421 lines (1200 loc) · 52 KB
/
Copy pathbuild-history.py
File metadata and controls
1421 lines (1200 loc) · 52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import gzip
import os
import re
import subprocess
import sys
from datetime import datetime, timezone
from pathlib import Path
# Infrastructure source: the latest commit on origin/main that has all the
# infrastructure files (_config.yml, _layouts/, assets/, .github/, etc.)
# plus the media images. We grab non-page files from this tree.
INFRA_SOURCE = "404588899" # tip of origin/main
# The original Jekyll conversion commit — used for author/date metadata
# on our synthetic "Convert to Jekyll" commit.
JEKYLL_CONVERT = "a7697c84a"
# Post-migration edit commit hashes — used only for author/date metadata.
# The actual edits are applied programmatically by POST_MIGRATION_EDITS
# (defined later alongside the edit functions).
AUTHOR_MAP = {
"127.0.0.1": ("DokuWiki System", "system@wiki.csswg.org"),
"146.82.168.18": ("Anonymous", "anonymous@wiki.csswg.org"),
"188.143.232.12": ("Anonymous", "anonymous@wiki.csswg.org"),
"194.246.102.4": ("Anonymous", "anonymous@wiki.csswg.org"),
"198.246.99.88": ("Anonymous", "anonymous@wiki.csswg.org"),
"218.108.168.134": ("Anonymous", "anonymous@wiki.csswg.org"),
"98.248.36.12": ("Anonymous", "anonymous@wiki.csswg.org"),
"AmeliaBR": ("Amelia Bellamy-Royds", "amelia.bellamy.royds@gmail.com"),
"AryehGregor": ("Aryeh Gregor", "ayg@aryeh.name"),
"JohnJansen": ("John Jansen", "2119039+thejohnjansen@users.noreply.github.com"),
"MaRakow": ("Matt Rakow", "marakow@microsoft.com"),
"SebastianZ": ("Sebastian Zartner", "sebastianzartner@gmail.com"),
"SimonSapin": ("Simon Sapin", "simon.sapin@exyr.org"),
"SteveZilles": ("Steve Zilles", "szilles@adobe.com"),
"Tantek": ("Tantek Çelik", "tantek@cs.stanford.edu"),
"acebal": ("César Acebal", "cfacebal@gmail.com"),
"adam_argyle": ("Adam Argyle", "argyle@google.com"),
"adenilson": ("Adenilson Cavalcanti", "cavalcantii@gmail.com"),
"alancutter": ("Alan Cutter", "alancutter@chromium.org"),
"alexmog": ("Alex Mogilevsky", "alexmog@microsoft.com"),
"alisonmaher": ("Alison Maher", "almaher@microsoft.com"),
"amelia_bellamy_royds": ("Amelia Bellamy-Royds", "amelia.bellamy.royds@gmail.com"),
"andreubotella": ("Andreu Botella", "andreu@andreubotella.com"),
"andrewfedoniouk": ("Andrew Fedoniouk", "6752794+c-smile@users.noreply.github.com"),
"anne": ("Anne van Kesteren", "annevk@opera.com"),
"annevk": ("Anne van Kesteren", "annevk@opera.com"),
"aprowse": ("Andy Prowse", "33927861+aprowse@users.noreply.github.com"),
"arno": ("Arno Gourdol", "63460665+gourdol@users.noreply.github.com"),
"arronei": ("Arron Eicholz", "arron.eicholz@microsoft.com"),
"arybka": ("Andrey Rybka", "4530160+arybka@users.noreply.github.com"),
"astearns": ("Alan Stearns", "stearns@adobe.com"),
"ben": ("Benjamin De Cock", "ben@deaxon.com"),
"bert": ("Bert Bos", "bert@w3.org"),
"birtles": ("Brian Birtles", "birtles@gmail.com"),
"bkardell": ("Brian Kardell", "bkardell@gmail.com"),
"bkardell2": ("Brian Kardell", "bkardell@gmail.com"),
"bkemper": ("Brian Kemper", "1335605+bkemper@users.noreply.github.com"),
"bojcampbell": ("Boj Campbell", "81823204+bojcampbell@users.noreply.github.com"),
"bokan": ("David Bokan", "bokan@chromium.org"),
"bramus": ("Bramus", "bramus@bram.us"),
"brian_birtles": ("Brian Birtles", "birtles@gmail.com"),
"brunoabinader": ("Bruno de Oliveira Abinader", "bruno.d@partner.samsung.com"),
"bts": ("Brandon Stewart", "brandonstewart@apple.com"),
"bzbarsky": ("Boris Zbarsky", "1457979+bzbarsky@users.noreply.github.com"),
"cabanier": ("Rik Cabanier", "cabanier@adobe.com"),
"castastrophe": (
"Cassondra Roberts",
"1840295+castastrophe@users.noreply.github.com",
),
"cbiesinger": ("Christian Biesinger", "cbiesinger@chromium.org"),
"ccameron": ("Christopher Cameron", "ccameron@chromium.org"),
"changseok": ("ChangSeok Oh", "changseok@webkit.org"),
"chris_harrelson": ("Chris Harrelson", "chrishtr@chromium.org"),
"chrisl": ("Chris Lilley", "chris@w3.org"),
"crissov": ("Christoph Päper", "bugzilla@crissov.de"),
"cwilso": ("Chris Wilson", "cwilso@gmail.com"),
"dael": ("Dael Jackson", "dael@daelity.com"),
"daniec": ("Dan Clark", "daniec@microsoft.com"),
"daniel.weck": ("Daniel Weck", "daniel.weck@gmail.com"),
"dauwhe": ("Dave Cramer", "dauwhe@gmail.com"),
"davidleininger": (
"David Leininger",
"1840132+davidleininger@users.noreply.github.com",
),
"dazabani": ("Delan Azabani", "delan@azabani.com"),
"dbaron": ("L. David Baron", "dbaron@dbaron.org"),
"dcrousso": ("Devin Rousso", "dcrousso@webkit.org"),
"dgrogan": ("David Grogan", "dgrogan@chromium.org"),
"dholbert": ("Daniel Holbert", "dholbert@cs.stanford.edu"),
"dino": ("Dean Jackson", "dino@apple.com"),
"drott": ("Dominik Röttsches", "drott@chromium.org"),
"dschulze": ("Dirk Schulze", "dschulze@adobe.com"),
"dsinger2": ("David Singer", "13665985+dsinger@users.noreply.github.com"),
"emeyer": ("Eric Meyer", "eric@meyerweb.com"),
"emil_a_eklund": ("Emil A. Eklund", "1753727+eaenet@users.noreply.github.com"),
"emilio": ("Emilio Cobos Álvarez", "emilio@crisal.io"),
"eportis": ("Eric Portis", "e@ericportis.com"),
"ericwilligers": ("Eric Willigers", "ericwilligers@chromium.org"),
"esprehn": ("Elliott Sprehn", "esprehn@chromium.org"),
"fantasai": ("Elika Etemad", "fantasai.bugs@inkedblade.net"),
"fergal": ("Fergal Daly", "fergal@chromium.org"),
"flackr": ("Robert Flack", "flackr@chromium.org"),
"florian": ("Florian Rivoal", "florian@rivoal.net"),
"fremy": ("François Remy", "frremy@microsoft.com"),
"fserb": ("Fernando Serboncini", "fserb@chromium.org"),
"gadams": ("Glenn Adams", "glenn@skynav.com"),
"glazou": ("Daniel Glazman", "daniel@glazman.org"),
"gregwhitworth": ("Greg Whitworth", "gregwhitworth@outlook.com"),
"gsnedders": ("Sam Sneddon", "me@gsnedders.com"),
"gtalbot": ("Gérard Talbot", "github@gtalbot.org"),
"heycam": ("Cameron McCormack", "cam@mcc.id.au"),
"hixie": ("Ian Hickson", "ian@hixie.ch"),
"hober": ("Theresa O'Connor", "hober@apple.com"),
"howcome": ("Håkon Wium Lie", "howcome@opera.com"),
"http://blog.crissov.de/": ("Christoph Päper", "bugzilla@crissov.de"),
"http://id.annevankesteren.nl/": ("Anne van Kesteren", "annevk@opera.com"),
"hyojin": ("Hyojin Song", "hyojin22.song@lge.com"),
"ihilerio": ("Israel Hilerio", "8966941+ihilerio@users.noreply.github.com"),
"ikilpatrick": ("Ian Kilpatrick", "ikilpatrick@chromium.org"),
"ishida": ("Richard Ishida", "ishida@w3.org"),
"itpastorn": ("Lars Gunther", "gunther@keryx.se"),
"jacobg": ("jacobg", "736985+jacobg@users.noreply.github.com"),
"jarhar": ("Joey Arhar", "jarhar@chromium.org"),
"javier_fernandez": ("Javier Fernandez", "jfernandez@igalia.com"),
"jdaggett": ("John Daggett", "jdaggett@mozilla.com"),
"jensimmons": ("Jen Simmons", "jensimmons@apple.com"),
"jetvillegas": ("Jet Villegas", "1307977+jetvillegas@users.noreply.github.com"),
"jfernandez": ("Javier Fernandez", "jfernandez@igalia.com"),
"jh.hong": ("Jihye Hong", "jh.hong@lge.com"),
"jirka_kosek": ("Jirka Kosek", "jirka@kosek.cz"),
"johanneswilm": ("Johannes Wilm", "mail@johanneswilm.org"),
"johnjansen": ("John Jansen", "2119039+thejohnjansen@users.noreply.github.com"),
"jonathan-watt": ("Jonathan Watt", "jwatt@jwatt.org"),
"jonathan_kew": ("Jonathan Kew", "jfkthame@gmail.com"),
"joone": ("Joone Hur", "joone@outlook.com"),
"joshtumath": ("Josh Tumath", "josh.tumath@bbc.co.uk"),
"kawabata": ("Shinyu Murakami", "murakami@vivliostyle.org"),
"kbabbitt": ("Kevin Babbitt", "kbabbitt@microsoft.com"),
"kennyluck": ("Kang-Hao (Kenny) Lu", "588104+kennyluck@users.noreply.github.com"),
"khushal_sagar": ("Khushal Sagar", "khushalsagar@chromium.org"),
"kiet_ho": ("Kiet Ho", "kiet.ho@apple.com"),
"kojiishi": ("Koji Ishii", "kojiishi@gmail.com"),
"krit": ("Dirk Schulze", "dschulze@adobe.com"),
"lea": ("Lea Verou", "lea@verou.me"),
"liam": ("Liam Quin", "8258535+liamquin@users.noreply.github.com"),
"lstorset": ("Leif Arne Storset", "lstorset@wiki.csswg.org"),
"macpherson": ("Luke Macpherson", "72672442+Macpherson@users.noreply.github.com"),
"majidvp": ("Majid Valipour", "majidvp@chromium.org"),
"masonf": ("Mason Freed", "masonf@chromium.org"),
"matt_woodrow": ("Matt Woodrow", "matt.woodrow@gmail.com"),
"matthieu-dubet": ("Matthieu Dubet", "109102217+mdubet@users.noreply.github.com"),
"megan_gardner": (
"Megan Gardner",
"243650270+megan-gardner@users.noreply.github.com",
),
"megra": ("Manuel Rego", "rego@igalia.com"),
"melanierichards": ("Melanie Richards", "melanie.richards@microsoft.com"),
"mfreed": ("Mason Freed", "masonf@chromium.org"),
"miriam": ("Miriam Suzanne", "miriam@oddbird.net"),
"mirisuzanne": ("Miriam Suzanne", "miriam@oddbird.net"),
"mmaxfield": ("Myles C. Maxfield", "mmaxfield@apple.com"),
"mmielke": ("Markus Mielke", "mmielke@microsoft.com"),
"mnewman": ("Mike Newman", "5278663+mnewman@users.noreply.github.com"),
"molly": ("Molly E. Holzschlag", "96634835+ThisMissMolly@users.noreply.github.com"),
"moonira": ("Munira Tursunova", "moonira@google.com"),
"ms2ger": ("Ms2ger", "111161+Ms2ger@users.noreply.github.com"),
"mstensho": ("Morten Stenshorne", "mstensho@chromium.org"),
"myles": ("Myles C. Maxfield", "mmaxfield@apple.com"),
"nainar": ("Una Kravets", "nainar@google.com"),
"nhthvhvbh": ("nhthvhvbh", "nhthvhvbh@wiki.csswg.org"),
"noamr": ("Noam Rosenthal", "noam.j.rosenthal@gmail.com"),
"nsull": ("Nat McCully", "38678135+nsull@users.noreply.github.com"),
"ntim": ("Tim Nguyen", "ntim@apple.com"),
"ojanvafai": ("Ojan Vafai", "1607171+ojanvafai@users.noreply.github.com"),
"oriol": ("Oriol Brufau", "obrufau@igalia.com"),
"oyvind": ("Øyvind Stenhaug", "oyvinds@opera.com"),
"paulirish": ("Paul Irish", "paulirish@google.com"),
"pcupp": ("Phil Cupp", "pcupp@microsoft.com"),
"phuangce": ("Ping Huang", "phuang@adobe.com"),
"pjmclachlan": ("Penelope McLachlan", "28974+b1tr0t@users.noreply.github.com"),
"plh": ("Philippe Le Hégaret", "plh@w3.org"),
"plinss": ("Peter Linss", "peter@linss.com"),
"rachelandrew": ("Rachel Andrew", "rachelandrew@google.com"),
"rbetts": ("Ryan Betts", "rbetts@adobe.com"),
"rbyers": ("Rick Byers", "rbyers@chromium.org"),
"rcaliman": ("Razvan Caliman", "razvan.caliman@gmail.com"),
"rego": ("Manuel Rego", "rego@igalia.com"),
"rhauck": ("Rebecca Hauck", "rhauck@adobe.com"),
"roman_komarov": ("Roman Komarov", "kizmarh@ya.ru"),
"rossen": ("Rossen Atanassov", "rossen.atanassov@microsoft.com"),
"rune": ("Rune Lillesveen", "rune@opera.com"),
"saloni": ("Saloni Mhapsekar", "797414+saloni@users.noreply.github.com"),
"samomekarajr": (
"Sam Davis Omekara",
"59079555+oSamDavis@users.noreply.github.com",
),
"schenney": ("Stephen Chenney", "schenney@chromium.org"),
"seokho": ("Seokho Song", "seokho@chromium.org"),
"shans": ("Shane Stephens", "shanestephens@google.com"),
"simonp": ("Simon Pieters", "simonp@opera.com"),
"simonsapin": ("Simon Sapin", "simon.sapin@exyr.org"),
"skk": ("Soonho Kwon", "skk@wiki.csswg.org"),
"smcgruer2": ("Stephen McGruer", "smcgruer@chromium.org"),
"smfr": ("Simon Fraser", "simon.fraser@apple.com"),
"smurakam": ("Shinyu Murakami", "murakami@vivliostyle.org"),
"spieters": ("Simon Pieters", "simonp@opera.com"),
"sstephen2": ("Shane Stephens", "shanestephens@google.com"),
"stantonm": ("Stanton Marcum", "83246723+StantonM@users.noreply.github.com"),
"stevezilles": ("Steve Zilles", "szilles@adobe.com"),
"surma": ("Surma", "surma@google.com"),
"svgeesus": ("Chris Lilley", "chris@w3.org"),
"sylvaing": ("Sylvain Galineau", "sylvaing@microsoft.com"),
"tab": ("Tab Atkins-Bittner", "jackalmage@gmail.com"),
"tabatkins": ("Tab Atkins-Bittner", "jackalmage@gmail.com"),
"tantek": ("Tantek Çelik", "tantek@cs.stanford.edu"),
"tclancy": ("Tom Clancy", "67803+tclancy@users.noreply.github.com"),
"tomharms": ("Tom Harms", "9092076+TomHarms@users.noreply.github.com"),
"unakravets": ("Una Kravets", "unakravets@google.com"),
"upsuper": ("Xidorn Quan", "me@upsuper.org"),
"vhardy": ("Vincent Hardy", "vhardy@adobe.com"),
"vlevanto": (
"Vladimir Levantovsky",
"17148826+vlevantovsky@users.noreply.github.com",
),
"vmpstr": ("Vladimir Levin", "vmpstr@chromium.org"),
"vollick": ("Ian Vollick", "vollick@chromium.org"),
"xfq": ("Fuqiao Xue", "xfq@w3.org"),
"xiaocheng_hu": ("Xiaocheng Hu", "xiaochengh@chromium.org"),
"ydaniv": ("Yehonatan Daniv", "maggotfish@gmail.com"),
"zcorpan": ("Simon Pieters", "zcorpan@gmail.com"),
}
def resolve_author(wiki_username):
"""Resolve a DokuWiki username to (name, email)."""
if wiki_username in AUTHOR_MAP:
return AUTHOR_MAP[wiki_username]
key = wiki_username.lower().strip()
for map_key, value in AUTHOR_MAP.items():
if map_key.lower() == key:
return value
# Generate a dummy email if we don't know the user
return (wiki_username, f"{wiki_username}@wiki.csswg.org")
def run_git(args, cwd=None, env=None, input_data=None):
"""Run a git command, returning the CompletedProcess."""
result = subprocess.run(
["git"] + args,
cwd=cwd,
capture_output=True,
text=True,
env=env,
input=input_data,
)
if result.returncode != 0 and args[0] not in ("diff",):
# Don't warn on expected diff non-zero (means "has changes")
pass
return result
def make_author_env(name, email, date_iso):
"""Build env dict for git commit with author/committer info."""
env = os.environ.copy()
env["GIT_AUTHOR_NAME"] = name
env["GIT_AUTHOR_EMAIL"] = email
env["GIT_AUTHOR_DATE"] = date_iso
env["GIT_COMMITTER_NAME"] = name
env["GIT_COMMITTER_EMAIL"] = email
env["GIT_COMMITTER_DATE"] = date_iso
return env
def get_commit_meta(ref):
"""Extract author/committer metadata and message from a commit."""
fmt = "%an%x00%ae%x00%aI%x00%cn%x00%ce%x00%cI"
r = run_git(["log", "-1", f"--format={fmt}", ref])
parts = r.stdout.strip().split("\x00")
r2 = run_git(["log", "-1", "--format=%B", ref])
return {
"an": parts[0],
"ae": parts[1],
"ad": parts[2],
"cn": parts[3],
"ce": parts[4],
"cd": parts[5],
"msg": r2.stdout.rstrip(),
}
def commit_tree(tree, parent, message, env):
"""Create a commit object with the given tree, parent, message, and env."""
r = run_git(["commit-tree", tree, "-p", parent, "-m", message], env=env)
return r.stdout.strip()
def build_tree_with_renames(base_ref, renames):
"""Build a new tree object by applying renames to an existing tree."""
run_git(["read-tree", "--empty"])
run_git(["read-tree", base_ref])
r = run_git(["ls-tree", "-r", base_ref])
blob_map = {}
for line in r.stdout.strip().split("\n"):
if not line:
continue
meta, path = line.split("\t", 1)
parts = meta.split()
blob_map[path] = (parts[0], parts[2]) # (mode, hash)
rename_dict = dict(renames)
remove_paths = [old for old in rename_dict if old in blob_map]
add_lines = []
for old_path in remove_paths:
mode, blob_hash = blob_map[old_path]
new_path = rename_dict[old_path]
add_lines.append(f"{mode} {blob_hash}\t{new_path}")
if remove_paths:
run_git(["update-index", "--remove"] + remove_paths)
if add_lines:
run_git(
["update-index", "--index-info"],
input_data="\n".join(add_lines) + "\n",
)
r = run_git(["write-tree"])
return r.stdout.strip()
def build_tree_with_conversions(base_ref, file_renames, convert_fn):
"""Build a new tree by renaming files AND converting their content.
Like build_tree_with_renames, but also transforms file content through
convert_fn(old_path, content) -> new_content.
"""
import tempfile
r = run_git(["ls-tree", "-r", base_ref])
blob_map = {}
for line in r.stdout.strip().split("\n"):
if not line:
continue
meta, path = line.split("\t", 1)
parts = meta.split()
blob_map[path] = (parts[0], parts[2]) # (mode, hash)
rename_dict = dict(file_renames)
remove_paths = [old for old in rename_dict if old in blob_map]
# Build new blobs with converted content
add_lines = []
for old_path in remove_paths:
mode, old_blob = blob_map[old_path]
new_path = rename_dict[old_path]
if convert_fn:
# Read old content
r = run_git(["cat-file", "blob", old_blob])
old_content = r.stdout
# Convert
new_content = convert_fn(old_path, old_content)
# Hash new content as blob
r = run_git(["hash-object", "-w", "--stdin"], input_data=new_content)
new_blob = r.stdout.strip()
add_lines.append(f"{mode} {new_blob}\t{new_path}")
else:
add_lines.append(f"{mode} {old_blob}\t{new_path}")
# Update index
run_git(["read-tree", "--empty"])
run_git(["read-tree", base_ref])
if remove_paths:
run_git(["update-index", "--remove"] + remove_paths)
if add_lines:
run_git(
["update-index", "--index-info"],
input_data="\n".join(add_lines) + "\n",
)
r = run_git(["write-tree"])
return r.stdout.strip()
# ---------------------------------------------------------------------------
# DokuWiki → Markdown converter
# ---------------------------------------------------------------------------
def dokuwiki_to_markdown(filepath, content):
"""Convert DokuWiki markup to GitHub-Flavored Markdown with Jekyll front matter.
Args:
filepath: the file path (e.g. "faq/index.md") — used to derive page title
and compute relative image paths
content: raw DokuWiki markup string
Returns:
Markdown string with YAML front matter
"""
lines = content.split("\n")
title = _extract_title(lines)
# Compute relative prefix to repo root for image paths.
# e.g. "faq/index.md" → depth 1 → "../"
# "spec/css3-regions/index.md" → depth 2 → "../../"
# "index.md" → depth 0 → "./"
parts = filepath.split("/")
depth = len(parts) - 1 # subtract the filename itself
if depth == 0:
assets_prefix = "./"
else:
assets_prefix = "../" * depth
body = _convert_body(lines, assets_prefix)
# Build front matter
title_escaped = title.replace('"', '\\"')
front_matter = f'---\ntitle: "{title_escaped}"\n---\n\n'
return front_matter + body
def _extract_title(lines):
"""Extract page title from the first DokuWiki heading."""
for line in lines:
m = re.match(r"^(={2,6})\s*(.+?)\s*=*\s*$", line)
if m:
return m.group(2).strip().rstrip("=").strip()
return "Untitled"
def _convert_body(lines, assets_prefix="./"):
"""Convert DokuWiki body lines to Markdown."""
result = []
i = 0
in_code = False
code_lang = ""
while i < len(lines):
line = lines[i]
# Code blocks: <code lang> ... </code>
if not in_code:
code_open = re.match(r"^(\s*)<code\s*(\w*)\s*>(.*)$", line, re.IGNORECASE)
if code_open:
in_code = True
code_lang = code_open.group(2) or ""
# Normalize language names
lang_map = {"html4strict": "html", "html5": "html"}
code_lang = lang_map.get(code_lang, code_lang)
result.append(f"```{code_lang}")
# Content on same line as <code>
rest = code_open.group(3)
if rest.rstrip().endswith("</code>"):
result.append(rest.rstrip().removesuffix("</code>"))
result.append("```")
in_code = False
elif rest:
result.append(rest)
i += 1
continue
# Also handle <file> blocks (DokuWiki downloadable code)
file_open = re.match(
r"^(\s*)<file\s*(\w*)\s*[^>]*>(.*)$", line, re.IGNORECASE
)
if file_open:
in_code = True
code_lang = file_open.group(2) or ""
result.append(f"```{code_lang}")
rest = file_open.group(3)
if rest.rstrip().endswith("</file>"):
result.append(rest.rstrip().removesuffix("</file>"))
result.append("```")
in_code = False
elif rest:
result.append(rest)
i += 1
continue
if in_code:
if re.search(r"</(?:code|file)>", line, re.IGNORECASE):
content_before = re.sub(
r"\s*</(?:code|file)>.*$", "", line, flags=re.IGNORECASE
)
if content_before:
result.append(content_before)
result.append("```")
in_code = False
i += 1
continue
result.append(line)
i += 1
continue
# Headings: ====== H1 ====== to == H5 ==
heading = re.match(r"^(={2,6})\s*(.+?)\s*=*\s*$", line)
if heading:
level = 7 - len(heading.group(1)) # ====== = H1, ===== = H2, etc.
level = max(1, min(6, level))
text = heading.group(2).strip().rstrip("=").strip()
result.append(f"\n{'#' * level} {text}\n")
i += 1
continue
# Horizontal rule
if re.match(r"^-{4,}\s*$", line):
result.append("\n---\n")
i += 1
continue
# Note blocks: <note>, <note warning>, <note important>, <note tip>
note_open = re.match(r"^\s*<note\s*(\w*)\s*>(.*)$", line, re.IGNORECASE)
if note_open:
note_type = note_open.group(1) or "NOTE"
note_type_map = {
"": "NOTE",
"warning": "WARNING",
"important": "IMPORTANT",
"tip": "TIP",
"example": "NOTE",
}
gfm_type = note_type_map.get(note_type.lower(), "NOTE")
# Collect note content
note_lines = []
rest = note_open.group(2)
if rest.rstrip().endswith("</note>"):
note_lines.append(rest.rstrip().removesuffix("</note>"))
else:
if rest.strip():
note_lines.append(rest)
i += 1
while i < len(lines):
if re.search(r"</note>", lines[i], re.IGNORECASE):
before = re.sub(
r"\s*</note>.*$", "", lines[i], flags=re.IGNORECASE
)
if before.strip():
note_lines.append(before)
break
note_lines.append(lines[i])
i += 1
# Convert note content and format as GFM alert
result.append(f"\n> [!{gfm_type}]")
for nl in note_lines:
converted = _convert_inline(nl.strip(), assets_prefix)
if converted:
result.append(f"> {converted}")
else:
result.append(">")
result.append("")
i += 1
continue
# Tables: ^ header ^ header ^ or | cell | cell |
if re.match(r"^\s*[\^|]", line) and ("|" in line or "^" in line):
table_lines = []
while i < len(lines) and re.match(r"^\s*[\^|]", lines[i]):
table_lines.append(lines[i])
i += 1
result.extend(_convert_table(table_lines, assets_prefix))
continue
# Definition lists: DokuWiki uses ; term : definition
# or just indented text with ; and :
defn = re.match(r"^\s*;\s*(.+?)\s*$", line)
if defn:
result.append(f"\n{_convert_inline(defn.group(1).strip(), assets_prefix)}")
i += 1
while i < len(lines) and re.match(r"^\s*:", lines[i]):
dm = re.match(r"^\s*:\s*(.+)", lines[i])
if dm:
result.append(
f": {_convert_inline(dm.group(1).strip(), assets_prefix)}"
)
i += 1
result.append("")
continue
# Unordered list items
list_m = re.match(r"^(\s+)\*\s+(.*)", line)
if list_m:
indent_level = (len(list_m.group(1)) - 2) // 2
indent = " " * max(0, indent_level)
result.append(
f"{indent}- {_convert_inline(list_m.group(2), assets_prefix)}"
)
i += 1
continue
# Ordered list items
olist_m = re.match(r"^(\s+)-\s+(.*)", line)
if olist_m:
indent_level = (len(olist_m.group(1)) - 2) // 2
indent = " " * max(0, indent_level)
result.append(
f"{indent}1. {_convert_inline(olist_m.group(2), assets_prefix)}"
)
i += 1
continue
# Regular text
result.append(_convert_inline(line, assets_prefix))
i += 1
text = "\n".join(result)
# Clean up excessive blank lines
text = re.sub(r"\n{3,}", "\n\n", text)
# Escape Liquid tags for Jekyll
text = text.replace("{%", "{% raw %}{%{% endraw %}")
text = text.replace("{{", "{% raw %}{{{% endraw %}")
return text.strip() + "\n"
def _convert_inline(text, assets_prefix="./"):
"""Convert DokuWiki inline markup to Markdown."""
# Bold: **text** -> **text** (same in both!)
# Italic: //text// -> *text*
text = re.sub(r"(?<![:/])//(.+?)//", r"*\1*", text)
# Underline: __text__ -> <u>text</u> (no native MD equivalent)
text = re.sub(r"__(.+?)__", r"<u>\1</u>", text)
# Monospace: ''text'' -> `text`
text = re.sub(r"''(.+?)''", r"`\1`", text)
# Strikethrough: <del>text</del> -> ~~text~~
text = re.sub(r"<del>(.*?)</del>", r"~~\1~~", text, flags=re.IGNORECASE)
# Superscript: <sup>text</sup> (keep as-is, GFM supports it)
# Subscript: <sub>text</sub> (keep as-is)
# Nowiki: <nowiki>text</nowiki> -> `text`
text = re.sub(r"<nowiki>(.*?)</nowiki>", r"`\1`", text, flags=re.IGNORECASE)
# Internal links: [[page|text]] -> [text](page)
# External links: [[url|text]] -> [text](url)
text = _convert_links(text)
# Images: {{url?size|alt}} -> 
text = _convert_images(text, assets_prefix)
# Line break: \\ at end of line -> <br>
text = re.sub(r"\\\\\s*$", " ", text)
# Line break mid-line
text = re.sub(r"\\\\(\s)", r"<br>\1", text)
# DokuWiki smileys
smiley_map = {
"FIXME": "\U0001f6a7",
"DELETEME": "\u274c",
}
for dw, emoji in smiley_map.items():
text = text.replace(dw, emoji)
return text
def _convert_links(text):
"""Convert DokuWiki links to Markdown links."""
def replace_link(m):
target = m.group(1)
label = m.group(3) if m.group(3) else None
# External URL
if re.match(r"https?://", target):
if label:
return f"[{label}]({target})"
return f"<{target}>"
# Internal wiki link — convert namespace:page to /page/
page_path = target.replace(":", "/").lstrip("/")
display = label if label else page_path.split("/")[-1]
return f"[{display}](/{page_path}/)"
text = re.sub(r"\[\[([^\]|]+)(\|([^\]]*))?\]\]", replace_link, text)
return text
def _convert_images(text, assets_prefix="./"):
"""Convert DokuWiki image syntax to Markdown."""
def replace_image(m):
inner = m.group(1)
# Split on | for alt text
parts = inner.split("|", 1)
src = parts[0].strip()
alt = parts[1].strip() if len(parts) > 1 else ""
# Remove DokuWiki parameters (?200x100, ?200, ?nolink, ?direct, ?linkonly,
# and & combinations like ?nolink&200)
src = re.sub(r"\?[^|]*$", "", src)
# Also strip leading colons/spaces
src = src.lstrip(": ")
# Check for ?linkonly (download link, not inline image)
is_link = "linkonly" in inner
# Convert wiki media paths
if not re.match(r"https?://", src):
media_path = src.replace(":", "/").lstrip("/")
src = f"{assets_prefix}assets/images/{media_path}"
if is_link:
label = alt if alt else src.split("/")[-1]
return f"[{label}]({src})"
return f""
# DokuWiki images: {{src|alt}} but NOT Liquid {{
# Match {{ that isn't followed by % (Liquid) or another {
text = re.sub(r"\{\{([^{}]+)\}\}", replace_image, text)
return text
def _convert_table(table_lines, assets_prefix="./"):
"""Convert DokuWiki table lines to Markdown table."""
rows = []
has_header = False
for line in table_lines:
line = line.strip()
if not line:
continue
# DokuWiki tables: ^ for header cells, | for regular cells
# ^H1^H2^H3^ or |C1|C2|C3|
is_header_row = line.startswith("^")
if is_header_row:
has_header = True
# Split cells — handle both ^ and | as delimiters
# Replace leading/trailing delimiters
line = line.strip("^|").strip()
# Split on ^ or |
cells = re.split(r"\s*[\^|]\s*", line)
cells = [_convert_inline(c.strip(), assets_prefix) for c in cells]
rows.append((is_header_row, cells))
if not rows:
return []
# Determine column count
max_cols = max(len(r[1]) for r in rows)
result = []
header_emitted = False
for is_header, cells in rows:
# Pad cells
while len(cells) < max_cols:
cells.append("")
row_str = "| " + " | ".join(cells) + " |"
result.append(row_str)
if is_header and not header_emitted:
sep = "| " + " | ".join(["---"] * max_cols) + " |"
result.append(sep)
header_emitted = True
# If no header row, insert separator after first row
if not header_emitted and result:
sep = "| " + " | ".join(["---"] * max_cols) + " |"
result.insert(1, sep)
result.insert(0, "") # blank line before table
result.append("") # blank line after table
return result
def page_id_to_filepath(page_id):
"""Convert a DokuWiki page ID (colon-separated) to a .txt filepath."""
return page_id.replace(":", "/") + ".txt"
def page_id_to_fspath(page_id):
"""Convert a DokuWiki page ID to filesystem path segments (/ separated)."""
return page_id.replace(":", "/")
def read_revisions(dump_dir):
"""Read all revisions from the DokuWiki meta/*.changes files.
Returns a sorted list of revision dicts:
{timestamp, page, author, summary, type}
"""
meta_dir = dump_dir / "data" / "meta"
revisions = []
for changes_file in meta_dir.rglob("*.changes"):
# Skip _comments.changes
if changes_file.name == "_comments.changes":
continue
with open(changes_file, encoding="utf-8", errors="replace") as f:
for line in f:
line = line.rstrip("\n")
if not line:
continue
fields = line.split("\t")
if len(fields) < 6:
continue
ts = int(fields[0])
# fields[1] = IP
edit_type = fields[2]
page_id = fields[3]
author = fields[4]
summary = fields[5] if len(fields) > 5 else ""
# Skip comment-related entries (cc, ec, dc)
if edit_type not in ("C", "c", "E", "e", "R", "D"):
continue
revisions.append(
{
"timestamp": ts,
"page": page_id,
"author": author,
"summary": summary,
"type": edit_type,
}
)
revisions.sort(key=lambda r: (r["timestamp"], r["page"]))
return revisions
def get_revision_content(dump_dir, page_id, timestamp, is_latest):
"""Get the content for a specific page revision.
For historical revisions, reads from data/attic/page.timestamp.txt.gz
For the latest revision, reads from data/pages/page.txt
"""
fs_page = page_id_to_fspath(page_id)
if is_latest:
current = dump_dir / "data" / "pages" / f"{fs_page}.txt"
if current.exists():
return current.read_text(encoding="utf-8", errors="replace")
# Try attic (gzipped)
attic = dump_dir / "data" / "attic" / f"{fs_page}.{timestamp}.txt.gz"
if attic.exists():
with gzip.open(attic, "rt", encoding="utf-8", errors="replace") as f:
return f.read()
return None
def read_acl(dump_dir):
"""Read the DokuWiki ACL file and return namespaces blocked from @ALL.
DokuWiki ACL format: <page/namespace> <group> <permission>
Permission 0 = no access. We look for lines that deny @ALL read access.
Returns a list of page ID prefixes that are private.
"""
acl_file = dump_dir / "conf" / "acl.auth.php"
private_prefixes = []
if not acl_file.exists():
return private_prefixes
with open(acl_file, encoding="utf-8") as f:
for line in f:
line = line.strip()
if not line or line.startswith("#"):
continue
parts = line.split("\t")
if len(parts) < 3:
continue
target = parts[0]
group = parts[1]
perm = int(parts[2])
# Check for @ALL with permission 0 (no access)
if group == "@ALL" and perm == 0:
# Normalize: "csswg:*" -> "csswg:", "csswg" -> "csswg"
if target.endswith(":*"):
private_prefixes.append(target[:-1]) # "csswg:*" -> "csswg:"
else:
private_prefixes.append(target) # exact page
return private_prefixes
def is_private(page_id, private_prefixes):
"""Check if a page ID falls under a private ACL prefix."""
for prefix in private_prefixes:
if prefix.endswith(":"):
# Namespace wildcard: matches any page under this namespace
if page_id.startswith(prefix) or page_id + ":" == prefix:
return True
else:
# Exact page match
if page_id == prefix:
return True
return False
def _meta_to_env(meta):
"""Convert a commit metadata dict to a GIT_* environment dict."""
env = os.environ.copy()
env_map = {
"an": "GIT_AUTHOR_NAME",
"ae": "GIT_AUTHOR_EMAIL",
"ad": "GIT_AUTHOR_DATE",
"cn": "GIT_COMMITTER_NAME",
"ce": "GIT_COMMITTER_EMAIL",
"cd": "GIT_COMMITTER_DATE",
}
for short, full in env_map.items():
env[full] = meta[short]
return env
def add_media_to_tree(dump_dir, base_tree):
"""Add all media files from DokuWiki dump to assets/images/ in a tree.
Reads binary files from data/media/, hashes them as git blobs, and
adds them to the index under assets/images/<path>.
Returns a new tree hash.
"""
media_dir = dump_dir / "data" / "media"
if not media_dir.exists():
return base_tree
# Start from the base tree
run_git(["read-tree", "--empty"])
run_git(["read-tree", base_tree])
add_lines = []
media_count = 0
for media_file in sorted(media_dir.rglob("*")):
if not media_file.is_file():
continue
# Get path relative to data/media/
rel_path = media_file.relative_to(media_dir)
dest_path = f"assets/images/{rel_path}"
# Hash the file as a git blob
r = run_git(["hash-object", "-w", str(media_file.resolve())])
blob_hash = r.stdout.strip()
add_lines.append(f"100644 {blob_hash}\t{dest_path}")
media_count += 1
if add_lines:
run_git(
["update-index", "--add", "--index-info"],
input_data="\n".join(add_lines) + "\n",
)
print(f" Added {media_count} media files to assets/images/")
r = run_git(["write-tree"])
return r.stdout.strip()
# ---------------------------------------------------------------------------
# Post-migration edit functions
# Each applies the semantic intent of a GitHub-side edit to our DokuWiki-
# derived Markdown files. They mutate the working tree in place.
# ---------------------------------------------------------------------------
def _edit_cupertino_in_past():
"""Move Cupertino 2026 F2F from Upcoming to Past Meetings."""
p = Path("planning/index.md")
text = p.read_text()
cupertino_re = re.compile(r"^- 2026-01-27.*Cupertino.*\n", re.MULTILINE)
m = cupertino_re.search(text)
if not m:
return []
cupertino_line = m.group(0).rstrip("\n")
text = cupertino_re.sub("", text)
text = text.replace(
"## Past Meetings\n",
"## Past Meetings\n\n### 2026\n\n" + cupertino_line + "\n",
)
p.write_text(text)