summaryrefslogtreecommitdiffstats
path: root/technical/reftable.html
blob: 16c612f2491148ba3a424ea6e45a3c5e9d8f2118 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 10.2.0" />
<title></title>
<style type="text/css">
/* Shared CSS for AsciiDoc xhtml11 and html5 backends */

/* Default font. */
body {
  font-family: Georgia,serif;
}

/* Title font. */
h1, h2, h3, h4, h5, h6,
div.title, caption.title,
thead, p.table.header,
#toctitle,
#author, #revnumber, #revdate, #revremark,
#footer {
  font-family: Arial,Helvetica,sans-serif;
}

body {
  margin: 1em 5% 1em 5%;
}

a {
  color: blue;
  text-decoration: underline;
}
a:visited {
  color: fuchsia;
}

em {
  font-style: italic;
  color: navy;
}

strong {
  font-weight: bold;
  color: #083194;
}

h1, h2, h3, h4, h5, h6 {
  color: #527bbd;
  margin-top: 1.2em;
  margin-bottom: 0.5em;
  line-height: 1.3;
}

h1, h2, h3 {
  border-bottom: 2px solid silver;
}
h2 {
  padding-top: 0.5em;
}
h3 {
  float: left;
}
h3 + * {
  clear: left;
}
h5 {
  font-size: 1.0em;
}

div.sectionbody {
  margin-left: 0;
}

hr {
  border: 1px solid silver;
}

p {
  margin-top: 0.5em;
  margin-bottom: 0.5em;
}

ul, ol, li > p {
  margin-top: 0;
}
ul > li     { color: #aaa; }
ul > li > * { color: black; }

.monospaced, code, pre {
  font-family: "Courier New", Courier, monospace;
  font-size: inherit;
  color: navy;
  padding: 0;
  margin: 0;
}
pre {
  white-space: pre-wrap;
}

#author {
  color: #527bbd;
  font-weight: bold;
  font-size: 1.1em;
}
#email {
}
#revnumber, #revdate, #revremark {
}

#footer {
  font-size: small;
  border-top: 2px solid silver;
  padding-top: 0.5em;
  margin-top: 4.0em;
}
#footer-text {
  float: left;
  padding-bottom: 0.5em;
}
#footer-badges {
  float: right;
  padding-bottom: 0.5em;
}

#preamble {
  margin-top: 1.5em;
  margin-bottom: 1.5em;
}
div.imageblock, div.exampleblock, div.verseblock,
div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
div.admonitionblock {
  margin-top: 1.0em;
  margin-bottom: 1.5em;
}
div.admonitionblock {
  margin-top: 2.0em;
  margin-bottom: 2.0em;
  margin-right: 10%;
  color: #606060;
}

div.content { /* Block element content. */
  padding: 0;
}

/* Block element titles. */
div.title, caption.title {
  color: #527bbd;
  font-weight: bold;
  text-align: left;
  margin-top: 1.0em;
  margin-bottom: 0.5em;
}
div.title + * {
  margin-top: 0;
}

td div.title:first-child {
  margin-top: 0.0em;
}
div.content div.title:first-child {
  margin-top: 0.0em;
}
div.content + div.title {
  margin-top: 0.0em;
}

div.sidebarblock > div.content {
  background: #ffffee;
  border: 1px solid #dddddd;
  border-left: 4px solid #f0f0f0;
  padding: 0.5em;
}

div.listingblock > div.content {
  border: 1px solid #dddddd;
  border-left: 5px solid #f0f0f0;
  background: #f8f8f8;
  padding: 0.5em;
}

div.quoteblock, div.verseblock {
  padding-left: 1.0em;
  margin-left: 1.0em;
  margin-right: 10%;
  border-left: 5px solid #f0f0f0;
  color: #888;
}

div.quoteblock > div.attribution {
  padding-top: 0.5em;
  text-align: right;
}

div.verseblock > pre.content {
  font-family: inherit;
  font-size: inherit;
}
div.verseblock > div.attribution {
  padding-top: 0.75em;
  text-align: left;
}
/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
div.verseblock + div.attribution {
  text-align: left;
}

div.admonitionblock .icon {
  vertical-align: top;
  font-size: 1.1em;
  font-weight: bold;
  text-decoration: underline;
  color: #527bbd;
  padding-right: 0.5em;
}
div.admonitionblock td.content {
  padding-left: 0.5em;
  border-left: 3px solid #dddddd;
}

div.exampleblock > div.content {
  border-left: 3px solid #dddddd;
  padding-left: 0.5em;
}

div.imageblock div.content { padding-left: 0; }
span.image img { border-style: none; vertical-align: text-bottom; }
a.image:visited { color: white; }

dl {
  margin-top: 0.8em;
  margin-bottom: 0.8em;
}
dt {
  margin-top: 0.5em;
  margin-bottom: 0;
  font-style: normal;
  color: navy;
}
dd > *:first-child {
  margin-top: 0.1em;
}

ul, ol {
    list-style-position: outside;
}
ol.arabic {
  list-style-type: decimal;
}
ol.loweralpha {
  list-style-type: lower-alpha;
}
ol.upperalpha {
  list-style-type: upper-alpha;
}
ol.lowerroman {
  list-style-type: lower-roman;
}
ol.upperroman {
  list-style-type: upper-roman;
}

div.compact ul, div.compact ol,
div.compact p, div.compact p,
div.compact div, div.compact div {
  margin-top: 0.1em;
  margin-bottom: 0.1em;
}

tfoot {
  font-weight: bold;
}
td > div.verse {
  white-space: pre;
}

div.hdlist {
  margin-top: 0.8em;
  margin-bottom: 0.8em;
}
div.hdlist tr {
  padding-bottom: 15px;
}
dt.hdlist1.strong, td.hdlist1.strong {
  font-weight: bold;
}
td.hdlist1 {
  vertical-align: top;
  font-style: normal;
  padding-right: 0.8em;
  color: navy;
}
td.hdlist2 {
  vertical-align: top;
}
div.hdlist.compact tr {
  margin: 0;
  padding-bottom: 0;
}

.comment {
  background: yellow;
}

.footnote, .footnoteref {
  font-size: 0.8em;
}

span.footnote, span.footnoteref {
  vertical-align: super;
}

#footnotes {
  margin: 20px 0 20px 0;
  padding: 7px 0 0 0;
}

#footnotes div.footnote {
  margin: 0 0 5px 0;
}

#footnotes hr {
  border: none;
  border-top: 1px solid silver;
  height: 1px;
  text-align: left;
  margin-left: 0;
  width: 20%;
  min-width: 100px;
}

div.colist td {
  padding-right: 0.5em;
  padding-bottom: 0.3em;
  vertical-align: top;
}
div.colist td img {
  margin-top: 0.3em;
}

@media print {
  #footer-badges { display: none; }
}

#toc {
  margin-bottom: 2.5em;
}

#toctitle {
  color: #527bbd;
  font-size: 1.1em;
  font-weight: bold;
  margin-top: 1.0em;
  margin-bottom: 0.1em;
}

div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
  margin-top: 0;
  margin-bottom: 0;
}
div.toclevel2 {
  margin-left: 2em;
  font-size: 0.9em;
}
div.toclevel3 {
  margin-left: 4em;
  font-size: 0.9em;
}
div.toclevel4 {
  margin-left: 6em;
  font-size: 0.9em;
}

span.aqua { color: aqua; }
span.black { color: black; }
span.blue { color: blue; }
span.fuchsia { color: fuchsia; }
span.gray { color: gray; }
span.green { color: green; }
span.lime { color: lime; }
span.maroon { color: maroon; }
span.navy { color: navy; }
span.olive { color: olive; }
span.purple { color: purple; }
span.red { color: red; }
span.silver { color: silver; }
span.teal { color: teal; }
span.white { color: white; }
span.yellow { color: yellow; }

span.aqua-background { background: aqua; }
span.black-background { background: black; }
span.blue-background { background: blue; }
span.fuchsia-background { background: fuchsia; }
span.gray-background { background: gray; }
span.green-background { background: green; }
span.lime-background { background: lime; }
span.maroon-background { background: maroon; }
span.navy-background { background: navy; }
span.olive-background { background: olive; }
span.purple-background { background: purple; }
span.red-background { background: red; }
span.silver-background { background: silver; }
span.teal-background { background: teal; }
span.white-background { background: white; }
span.yellow-background { background: yellow; }

span.big { font-size: 2em; }
span.small { font-size: 0.6em; }

span.underline { text-decoration: underline; }
span.overline { text-decoration: overline; }
span.line-through { text-decoration: line-through; }

div.unbreakable { page-break-inside: avoid; }


/*
 * xhtml11 specific
 *
 * */

div.tableblock {
  margin-top: 1.0em;
  margin-bottom: 1.5em;
}
div.tableblock > table {
  border: 3px solid #527bbd;
}
thead, p.table.header {
  font-weight: bold;
  color: #527bbd;
}
p.table {
  margin-top: 0;
}
/* Because the table frame attribute is overridden by CSS in most browsers. */
div.tableblock > table[frame="void"] {
  border-style: none;
}
div.tableblock > table[frame="hsides"] {
  border-left-style: none;
  border-right-style: none;
}
div.tableblock > table[frame="vsides"] {
  border-top-style: none;
  border-bottom-style: none;
}


/*
 * html5 specific
 *
 * */

table.tableblock {
  margin-top: 1.0em;
  margin-bottom: 1.5em;
}
thead, p.tableblock.header {
  font-weight: bold;
  color: #527bbd;
}
p.tableblock {
  margin-top: 0;
}
table.tableblock {
  border-width: 3px;
  border-spacing: 0px;
  border-style: solid;
  border-color: #527bbd;
  border-collapse: collapse;
}
th.tableblock, td.tableblock {
  border-width: 1px;
  padding: 4px;
  border-style: solid;
  border-color: #527bbd;
}

table.tableblock.frame-topbot {
  border-left-style: hidden;
  border-right-style: hidden;
}
table.tableblock.frame-sides {
  border-top-style: hidden;
  border-bottom-style: hidden;
}
table.tableblock.frame-none {
  border-style: hidden;
}

th.tableblock.halign-left, td.tableblock.halign-left {
  text-align: left;
}
th.tableblock.halign-center, td.tableblock.halign-center {
  text-align: center;
}
th.tableblock.halign-right, td.tableblock.halign-right {
  text-align: right;
}

th.tableblock.valign-top, td.tableblock.valign-top {
  vertical-align: top;
}
th.tableblock.valign-middle, td.tableblock.valign-middle {
  vertical-align: middle;
}
th.tableblock.valign-bottom, td.tableblock.valign-bottom {
  vertical-align: bottom;
}


/*
 * manpage specific
 *
 * */

body.manpage h1 {
  padding-top: 0.5em;
  padding-bottom: 0.5em;
  border-top: 2px solid silver;
  border-bottom: 2px solid silver;
}
body.manpage h2 {
  border-style: none;
}
body.manpage div.sectionbody {
  margin-left: 3em;
}

@media print {
  body.manpage div#toc { display: none; }
}


</style>
<script type="text/javascript">
/*<![CDATA[*/
var asciidoc = {  // Namespace.

/////////////////////////////////////////////////////////////////////
// Table Of Contents generator
/////////////////////////////////////////////////////////////////////

/* Author: Mihai Bazon, September 2002
 * http://students.infoiasi.ro/~mishoo
 *
 * Table Of Content generator
 * Version: 0.4
 *
 * Feel free to use this script under the terms of the GNU General Public
 * License, as long as you do not remove or alter this notice.
 */

 /* modified by Troy D. Hanson, September 2006. License: GPL */
 /* modified by Stuart Rackham, 2006, 2009. License: GPL */

// toclevels = 1..4.
toc: function (toclevels) {

  function getText(el) {
    var text = "";
    for (var i = el.firstChild; i != null; i = i.nextSibling) {
      if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
        text += i.data;
      else if (i.firstChild != null)
        text += getText(i);
    }
    return text;
  }

  function TocEntry(el, text, toclevel) {
    this.element = el;
    this.text = text;
    this.toclevel = toclevel;
  }

  function tocEntries(el, toclevels) {
    var result = new Array;
    var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');
    // Function that scans the DOM tree for header elements (the DOM2
    // nodeIterator API would be a better technique but not supported by all
    // browsers).
    var iterate = function (el) {
      for (var i = el.firstChild; i != null; i = i.nextSibling) {
        if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
          var mo = re.exec(i.tagName);
          if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
            result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
          }
          iterate(i);
        }
      }
    }
    iterate(el);
    return result;
  }

  var toc = document.getElementById("toc");
  if (!toc) {
    return;
  }

  // Delete existing TOC entries in case we're reloading the TOC.
  var tocEntriesToRemove = [];
  var i;
  for (i = 0; i < toc.childNodes.length; i++) {
    var entry = toc.childNodes[i];
    if (entry.nodeName.toLowerCase() == 'div'
     && entry.getAttribute("class")
     && entry.getAttribute("class").match(/^toclevel/))
      tocEntriesToRemove.push(entry);
  }
  for (i = 0; i < tocEntriesToRemove.length; i++) {
    toc.removeChild(tocEntriesToRemove[i]);
  }

  // Rebuild TOC entries.
  var entries = tocEntries(document.getElementById("content"), toclevels);
  for (var i = 0; i < entries.length; ++i) {
    var entry = entries[i];
    if (entry.element.id == "")
      entry.element.id = "_toc_" + i;
    var a = document.createElement("a");
    a.href = "#" + entry.element.id;
    a.appendChild(document.createTextNode(entry.text));
    var div = document.createElement("div");
    div.appendChild(a);
    div.className = "toclevel" + entry.toclevel;
    toc.appendChild(div);
  }
  if (entries.length == 0)
    toc.parentNode.removeChild(toc);
},


/////////////////////////////////////////////////////////////////////
// Footnotes generator
/////////////////////////////////////////////////////////////////////

/* Based on footnote generation code from:
 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
 */

footnotes: function () {
  // Delete existing footnote entries in case we're reloading the footnodes.
  var i;
  var noteholder = document.getElementById("footnotes");
  if (!noteholder) {
    return;
  }
  var entriesToRemove = [];
  for (i = 0; i < noteholder.childNodes.length; i++) {
    var entry = noteholder.childNodes[i];
    if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")
      entriesToRemove.push(entry);
  }
  for (i = 0; i < entriesToRemove.length; i++) {
    noteholder.removeChild(entriesToRemove[i]);
  }

  // Rebuild footnote entries.
  var cont = document.getElementById("content");
  var spans = cont.getElementsByTagName("span");
  var refs = {};
  var n = 0;
  for (i=0; i<spans.length; i++) {
    if (spans[i].className == "footnote") {
      n++;
      var note = spans[i].getAttribute("data-note");
      if (!note) {
        // Use [\s\S] in place of . so multi-line matches work.
        // Because JavaScript has no s (dotall) regex flag.
        note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
        spans[i].innerHTML =
          "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
          "' title='View footnote' class='footnote'>" + n + "</a>]";
        spans[i].setAttribute("data-note", note);
      }
      noteholder.innerHTML +=
        "<div class='footnote' id='_footnote_" + n + "'>" +
        "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
        n + "</a>. " + note + "</div>";
      var id =spans[i].getAttribute("id");
      if (id != null) refs["#"+id] = n;
    }
  }
  if (n == 0)
    noteholder.parentNode.removeChild(noteholder);
  else {
    // Process footnoterefs.
    for (i=0; i<spans.length; i++) {
      if (spans[i].className == "footnoteref") {
        var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
        href = href.match(/#.*/)[0];  // Because IE return full URL.
        n = refs[href];
        spans[i].innerHTML =
          "[<a href='#_footnote_" + n +
          "' title='View footnote' class='footnote'>" + n + "</a>]";
      }
    }
  }
},

install: function(toclevels) {
  var timerId;

  function reinstall() {
    asciidoc.footnotes();
    if (toclevels) {
      asciidoc.toc(toclevels);
    }
  }

  function reinstallAndRemoveTimer() {
    clearInterval(timerId);
    reinstall();
  }

  timerId = setInterval(reinstall, 500);
  if (document.addEventListener)
    document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
  else
    window.onload = reinstallAndRemoveTimer;
}

}
asciidoc.install();
/*]]>*/
</script>
</head>
<body class="article">
<div id="header">
</div>
<div id="content">
<div class="sect1">
<h2 id="_reftable">reftable</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_overview">Overview</h3>
<div class="sect3">
<h4 id="_problem_statement">Problem statement</h4>
<div class="paragraph"><p>Some repositories contain a lot of references (e.g. android at 866k,
rails at 31k). The existing packed-refs format takes up a lot of space
(e.g. 62M), and does not scale with additional references. Lookup of a
single reference requires linearly scanning the file.</p></div>
<div class="paragraph"><p>Atomic pushes modifying multiple references require copying the entire
packed-refs file, which can be a considerable amount of data moved
(e.g. 62M in, 62M out) for even small transactions (2 refs modified).</p></div>
<div class="paragraph"><p>Repositories with many loose references occupy a large number of disk
blocks from the local file system, as each reference is its own file
storing 41 bytes (and another file for the corresponding reflog). This
negatively affects the number of inodes available when a large number of
repositories are stored on the same filesystem. Readers can be penalized
due to the larger number of syscalls required to traverse and read the
<code>$GIT_DIR/refs</code> directory.</p></div>
</div>
<div class="sect3">
<h4 id="_objectives">Objectives</h4>
<div class="ulist"><ul>
<li>
<p>
Near constant time lookup for any single reference, even when the
repository is cold and not in process or kernel cache.
</p>
</li>
<li>
<p>
Near constant time verification if an object name is referred to by at least
one reference (for allow-tip-sha1-in-want).
</p>
</li>
<li>
<p>
Efficient enumeration of an entire namespace, such as <code>refs/tags/</code>.
</p>
</li>
<li>
<p>
Support atomic push with <code>O(size_of_update)</code> operations.
</p>
</li>
<li>
<p>
Combine reflog storage with ref storage for small transactions.
</p>
</li>
<li>
<p>
Separate reflog storage for base refs and historical logs.
</p>
</li>
</ul></div>
</div>
<div class="sect3">
<h4 id="_description">Description</h4>
<div class="paragraph"><p>A reftable file is a portable binary file format customized for
reference storage. References are sorted, enabling linear scans, binary
search lookup, and range scans.</p></div>
<div class="paragraph"><p>Storage in the file is organized into variable sized blocks. Prefix
compression is used within a single block to reduce disk space. Block
size and alignment is tunable by the writer.</p></div>
</div>
<div class="sect3">
<h4 id="_performance">Performance</h4>
<div class="paragraph"><p>Space used, packed-refs vs. reftable:</p></div>
<div class="tableblock">
<table rules="all"
width="100%"
frame="border"
cellspacing="0" cellpadding="4">
<col width="16%" />
<col width="16%" />
<col width="16%" />
<col width="16%" />
<col width="16%" />
<col width="16%" />
<thead>
<tr>
<th align="left" valign="top">repository </th>
<th align="right" valign="top">packed-refs </th>
<th align="right" valign="top">reftable </th>
<th align="right" valign="top">% original </th>
<th align="right" valign="top">avg ref </th>
<th align="right" valign="top">avg obj</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left" valign="top"><p class="table">android</p></td>
<td align="right" valign="top"><p class="table">62.2 M</p></td>
<td align="right" valign="top"><p class="table">36.1 M</p></td>
<td align="right" valign="top"><p class="table">58.0%</p></td>
<td align="right" valign="top"><p class="table">33 bytes</p></td>
<td align="right" valign="top"><p class="table">5 bytes</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table">rails</p></td>
<td align="right" valign="top"><p class="table">1.8 M</p></td>
<td align="right" valign="top"><p class="table">1.1 M</p></td>
<td align="right" valign="top"><p class="table">57.7%</p></td>
<td align="right" valign="top"><p class="table">29 bytes</p></td>
<td align="right" valign="top"><p class="table">4 bytes</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table">git</p></td>
<td align="right" valign="top"><p class="table">78.7 K</p></td>
<td align="right" valign="top"><p class="table">48.1 K</p></td>
<td align="right" valign="top"><p class="table">61.0%</p></td>
<td align="right" valign="top"><p class="table">50 bytes</p></td>
<td align="right" valign="top"><p class="table">4 bytes</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table">git (heads)</p></td>
<td align="right" valign="top"><p class="table">332 b</p></td>
<td align="right" valign="top"><p class="table">269 b</p></td>
<td align="right" valign="top"><p class="table">81.0%</p></td>
<td align="right" valign="top"><p class="table">33 bytes</p></td>
<td align="right" valign="top"><p class="table">0 bytes</p></td>
</tr>
</tbody>
</table>
</div>
<div class="paragraph"><p>Scan (read 866k refs), by reference name lookup (single ref from 866k
refs), and by SHA-1 lookup (refs with that SHA-1, from 866k refs):</p></div>
<div class="tableblock">
<table rules="all"
width="100%"
frame="border"
cellspacing="0" cellpadding="4">
<col width="20%" />
<col width="20%" />
<col width="20%" />
<col width="20%" />
<col width="20%" />
<thead>
<tr>
<th align="left" valign="top">format </th>
<th align="right" valign="top">cache </th>
<th align="right" valign="top">scan </th>
<th align="right" valign="top">by name </th>
<th align="right" valign="top">by SHA-1</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left" valign="top"><p class="table">packed-refs</p></td>
<td align="right" valign="top"><p class="table">cold</p></td>
<td align="right" valign="top"><p class="table">402 ms</p></td>
<td align="right" valign="top"><p class="table">409,660.1 usec</p></td>
<td align="right" valign="top"><p class="table">412,535.8 usec</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table">packed-refs</p></td>
<td align="right" valign="top"><p class="table">hot</p></td>
<td align="right" valign="top"><p class="table"></p></td>
<td align="right" valign="top"><p class="table">6,844.6 usec</p></td>
<td align="right" valign="top"><p class="table">20,110.1 usec</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table">reftable</p></td>
<td align="right" valign="top"><p class="table">cold</p></td>
<td align="right" valign="top"><p class="table">112 ms</p></td>
<td align="right" valign="top"><p class="table">33.9 usec</p></td>
<td align="right" valign="top"><p class="table">323.2 usec</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table">reftable</p></td>
<td align="right" valign="top"><p class="table">hot</p></td>
<td align="right" valign="top"><p class="table"></p></td>
<td align="right" valign="top"><p class="table">20.2 usec</p></td>
<td align="right" valign="top"><p class="table">320.8 usec</p></td>
</tr>
</tbody>
</table>
</div>
<div class="paragraph"><p>Space used for 149,932 log entries for 43,061 refs, reflog vs. reftable:</p></div>
<div class="tableblock">
<table rules="all"
width="100%"
frame="border"
cellspacing="0" cellpadding="4">
<col width="33%" />
<col width="33%" />
<col width="33%" />
<thead>
<tr>
<th align="left" valign="top">format </th>
<th align="right" valign="top">size </th>
<th align="right" valign="top">avg entry</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left" valign="top"><p class="table">$GIT_DIR/logs</p></td>
<td align="right" valign="top"><p class="table">173 M</p></td>
<td align="right" valign="top"><p class="table">1209 bytes</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table">reftable</p></td>
<td align="right" valign="top"><p class="table">5 M</p></td>
<td align="right" valign="top"><p class="table">37 bytes</p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_details">Details</h3>
<div class="sect3">
<h4 id="_peeling">Peeling</h4>
<div class="paragraph"><p>References stored in a reftable are peeled, a record for an annotated
(or signed) tag records both the tag object, and the object it refers
to. This is analogous to storage in the packed-refs format.</p></div>
</div>
<div class="sect3">
<h4 id="_reference_name_encoding">Reference name encoding</h4>
<div class="paragraph"><p>Reference names are an uninterpreted sequence of bytes that must pass
<a href="../git-check-ref-format.html">git-check-ref-format(1)</a> as a valid reference name.</p></div>
</div>
<div class="sect3">
<h4 id="_key_unicity">Key unicity</h4>
<div class="paragraph"><p>Each entry must have a unique key; repeated keys are disallowed.</p></div>
</div>
<div class="sect3">
<h4 id="_network_byte_order">Network byte order</h4>
<div class="paragraph"><p>All multi-byte, fixed width fields are in network byte order.</p></div>
</div>
<div class="sect3">
<h4 id="_varint_encoding">Varint encoding</h4>
<div class="paragraph"><p>Varint encoding is identical to the ofs-delta encoding method used
within pack files.</p></div>
<div class="paragraph"><p>Decoder works such as:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>val = buf[ptr] &amp; 0x7f
while (buf[ptr] &amp; 0x80) {
  ptr++
  val = ((val + 1) &lt;&lt; 7) | (buf[ptr] &amp; 0x7f)
}</code></pre>
</div></div>
</div>
<div class="sect3">
<h4 id="_ordering">Ordering</h4>
<div class="paragraph"><p>Blocks are lexicographically ordered by their first reference.</p></div>
</div>
<div class="sect3">
<h4 id="_directory_file_conflicts">Directory/file conflicts</h4>
<div class="paragraph"><p>The reftable format accepts both <code>refs/heads/foo</code> and
<code>refs/heads/foo/bar</code> as distinct references.</p></div>
<div class="paragraph"><p>This property is useful for retaining log records in reftable, but may
confuse versions of Git using <code>$GIT_DIR/refs</code> directory tree to maintain
references. Users of reftable may choose to continue to reject <code>foo</code> and
<code>foo/bar</code> type conflicts to prevent problems for peers.</p></div>
</div>
</div>
<div class="sect2">
<h3 id="_file_format">File format</h3>
<div class="sect3">
<h4 id="_structure">Structure</h4>
<div class="paragraph"><p>A reftable file has the following high-level structure:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>first_block {
  header
  first_ref_block
}
ref_block*
ref_index*
obj_block*
obj_index*
log_block*
log_index*
footer</code></pre>
</div></div>
<div class="paragraph"><p>A log-only file omits the <code>ref_block</code>, <code>ref_index</code>, <code>obj_block</code> and
<code>obj_index</code> sections, containing only the file header and log block:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>first_block {
  header
}
log_block*
log_index*
footer</code></pre>
</div></div>
<div class="paragraph"><p>in a log-only file the first log block immediately follows the file
header, without padding to block alignment.</p></div>
</div>
<div class="sect3">
<h4 id="_block_size">Block size</h4>
<div class="paragraph"><p>The file&#8217;s block size is arbitrarily determined by the writer, and does
not have to be a power of 2. The block size must be larger than the
longest reference name or log entry used in the repository, as
references cannot span blocks.</p></div>
<div class="paragraph"><p>Powers of two that are friendly to the virtual memory system or
filesystem (such as 4k or 8k) are recommended. Larger sizes (64k) can
yield better compression, with a possible increased cost incurred by
readers during access.</p></div>
<div class="paragraph"><p>The largest block size is <code>16777215</code> bytes (15.99 MiB).</p></div>
</div>
<div class="sect3">
<h4 id="_block_alignment">Block alignment</h4>
<div class="paragraph"><p>Writers may choose to align blocks at multiples of the block size by
including <code>padding</code> filled with NUL bytes at the end of a block to round
out to the chosen alignment. When alignment is used, writers must
specify the alignment with the file header&#8217;s <code>block_size</code> field.</p></div>
<div class="paragraph"><p>Block alignment is not required by the file format. Unaligned files must
set <code>block_size = 0</code> in the file header, and omit <code>padding</code>. Unaligned
files with more than one ref block must include the <a href="#Ref-index">ref
index</a> to support fast lookup. Readers must be able to read both aligned
and non-aligned files.</p></div>
<div class="paragraph"><p>Very small files (e.g. a single ref block) may omit <code>padding</code> and the ref
index to reduce total file size.</p></div>
</div>
<div class="sect3">
<h4 id="_header_version_1">Header (version 1)</h4>
<div class="paragraph"><p>A 24-byte header appears at the beginning of the file:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>'REFT'
uint8( version_number = 1 )
uint24( block_size )
uint64( min_update_index )
uint64( max_update_index )</code></pre>
</div></div>
<div class="paragraph"><p>Aligned files must specify <code>block_size</code> to configure readers with the
expected block alignment. Unaligned files must set <code>block_size = 0</code>.</p></div>
<div class="paragraph"><p>The <code>min_update_index</code> and <code>max_update_index</code> describe bounds for the
<code>update_index</code> field of all log records in this file. When reftables are
used in a stack for <a href="#Update-transactions">transactions</a>, these
fields can order the files such that the prior file&#8217;s
<code>max_update_index + 1</code> is the next file&#8217;s <code>min_update_index</code>.</p></div>
</div>
<div class="sect3">
<h4 id="_header_version_2">Header (version 2)</h4>
<div class="paragraph"><p>A 28-byte header appears at the beginning of the file:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>'REFT'
uint8( version_number = 2 )
uint24( block_size )
uint64( min_update_index )
uint64( max_update_index )
uint32( hash_id )</code></pre>
</div></div>
<div class="paragraph"><p>The header is identical to <code>version_number=1</code>, with the 4-byte hash ID
("sha1" for SHA1 and "s256" for SHA-256) append to the header.</p></div>
<div class="paragraph"><p>For maximum backward compatibility, it is recommended to use version 1 when
writing SHA1 reftables.</p></div>
</div>
<div class="sect3">
<h4 id="_first_ref_block">First ref block</h4>
<div class="paragraph"><p>The first ref block shares the same block as the file header, and is 24
bytes smaller than all other blocks in the file. The first block
immediately begins after the file header, at position 24.</p></div>
<div class="paragraph"><p>If the first block is a log block (a log-only file), its block header
begins immediately at position 24.</p></div>
</div>
<div class="sect3">
<h4 id="_ref_block_format">Ref block format</h4>
<div class="paragraph"><p>A ref block is written as:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>'r'
uint24( block_len )
ref_record+
uint24( restart_offset )+
uint16( restart_count )

padding?</code></pre>
</div></div>
<div class="paragraph"><p>Blocks begin with <code>block_type = 'r'</code> and a 3-byte <code>block_len</code> which
encodes the number of bytes in the block up to, but not including the
optional <code>padding</code>. This is always less than or equal to the file&#8217;s
block size. In the first ref block, <code>block_len</code> includes 24 bytes for
the file header.</p></div>
<div class="paragraph"><p>The 2-byte <code>restart_count</code> stores the number of entries in the
<code>restart_offset</code> list, which must not be empty. Readers can use
<code>restart_count</code> to binary search between restarts before starting a
linear scan.</p></div>
<div class="paragraph"><p>Exactly <code>restart_count</code> 3-byte <code>restart_offset</code> values precedes the
<code>restart_count</code>. Offsets are relative to the start of the block and
refer to the first byte of any <code>ref_record</code> whose name has not been
prefix compressed. Entries in the <code>restart_offset</code> list must be sorted,
ascending. Readers can start linear scans from any of these records.</p></div>
<div class="paragraph"><p>A variable number of <code>ref_record</code> fill the middle of the block,
describing reference names and values. The format is described below.</p></div>
<div class="paragraph"><p>As the first ref block shares the first file block with the file header,
all <code>restart_offset</code> in the first block are relative to the start of the
file (position 0), and include the file header. This forces the first
<code>restart_offset</code> to be <code>28</code>.</p></div>
<div class="sect4">
<h5 id="_ref_record">ref record</h5>
<div class="paragraph"><p>A <code>ref_record</code> describes a single reference, storing both the name and
its value(s). Records are formatted as:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>varint( prefix_length )
varint( (suffix_length &lt;&lt; 3) | value_type )
suffix
varint( update_index_delta )
value?</code></pre>
</div></div>
<div class="paragraph"><p>The <code>prefix_length</code> field specifies how many leading bytes of the prior
reference record&#8217;s name should be copied to obtain this reference&#8217;s
name. This must be 0 for the first reference in any block, and also must
be 0 for any <code>ref_record</code> whose offset is listed in the <code>restart_offset</code>
table at the end of the block.</p></div>
<div class="paragraph"><p>Recovering a reference name from any <code>ref_record</code> is a simple concat:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>this_name = prior_name[0..prefix_length] + suffix</code></pre>
</div></div>
<div class="paragraph"><p>The <code>suffix_length</code> value provides the number of bytes available in
<code>suffix</code> to copy from <code>suffix</code> to complete the reference name.</p></div>
<div class="paragraph"><p>The <code>update_index</code> that last modified the reference can be obtained by
adding <code>update_index_delta</code> to the <code>min_update_index</code> from the file
header: <code>min_update_index + update_index_delta</code>.</p></div>
<div class="paragraph"><p>The <code>value</code> follows. Its format is determined by <code>value_type</code>, one of
the following:</p></div>
<div class="ulist"><ul>
<li>
<p>
<code>0x0</code>: deletion; no value data (see transactions, below)
</p>
</li>
<li>
<p>
<code>0x1</code>: one object name; value of the ref
</p>
</li>
<li>
<p>
<code>0x2</code>: two object names; value of the ref, peeled target
</p>
</li>
<li>
<p>
<code>0x3</code>: symbolic reference: <code>varint( target_len ) target</code>
</p>
</li>
</ul></div>
<div class="paragraph"><p>Symbolic references use <code>0x3</code>, followed by the complete name of the
reference target. No compression is applied to the target name.</p></div>
<div class="paragraph"><p>Types <code>0x4..0x7</code> are reserved for future use.</p></div>
</div>
</div>
<div class="sect3">
<h4 id="_ref_index">Ref index</h4>
<div class="paragraph"><p>The ref index stores the name of the last reference from every ref block
in the file, enabling reduced disk seeks for lookups. Any reference can
be found by searching the index, identifying the containing block, and
searching within that block.</p></div>
<div class="paragraph"><p>The index may be organized into a multi-level index, where the 1st level
index block points to additional ref index blocks (2nd level), which may
in turn point to either additional index blocks (e.g. 3rd level) or ref
blocks (leaf level). Disk reads required to access a ref go up with
higher index levels. Multi-level indexes may be required to ensure no
single index block exceeds the file format&#8217;s max block size of
<code>16777215</code> bytes (15.99 MiB). To achieve constant O(1) disk seeks for
lookups the index must be a single level, which is permitted to exceed
the file&#8217;s configured block size, but not the format&#8217;s max block size of
15.99 MiB.</p></div>
<div class="paragraph"><p>If present, the ref index block(s) appears after the last ref block.</p></div>
<div class="paragraph"><p>If there are at least 4 ref blocks, a ref index block should be written
to improve lookup times. Cold reads using the index require 2 disk reads
(read index, read block), and binary searching &lt; 4 blocks also requires
&#8656; 2 reads. Omitting the index block from smaller files saves space.</p></div>
<div class="paragraph"><p>If the file is unaligned and contains more than one ref block, the ref
index must be written.</p></div>
<div class="paragraph"><p>Index block format:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>'i'
uint24( block_len )
index_record+
uint24( restart_offset )+
uint16( restart_count )

padding?</code></pre>
</div></div>
<div class="paragraph"><p>The index blocks begin with <code>block_type = 'i'</code> and a 3-byte <code>block_len</code>
which encodes the number of bytes in the block, up to but not including
the optional <code>padding</code>.</p></div>
<div class="paragraph"><p>The <code>restart_offset</code> and <code>restart_count</code> fields are identical in format,
meaning and usage as in ref blocks.</p></div>
<div class="paragraph"><p>To reduce the number of reads required for random access in very large
files the index block may be larger than other blocks. However, readers
must hold the entire index in memory to benefit from this, so it&#8217;s a
time-space tradeoff in both file size and reader memory.</p></div>
<div class="paragraph"><p>Increasing the file&#8217;s block size decreases the index size. Alternatively
a multi-level index may be used, keeping index blocks within the file&#8217;s
block size, but increasing the number of blocks that need to be
accessed.</p></div>
<div class="sect4">
<h5 id="_index_record">index record</h5>
<div class="paragraph"><p>An index record describes the last entry in another block. Index records
are written as:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>varint( prefix_length )
varint( (suffix_length &lt;&lt; 3) | 0 )
suffix
varint( block_position )</code></pre>
</div></div>
<div class="paragraph"><p>Index records use prefix compression exactly like <code>ref_record</code>.</p></div>
<div class="paragraph"><p>Index records store <code>block_position</code> after the suffix, specifying the
absolute position in bytes (from the start of the file) of the block
that ends with this reference. Readers can seek to <code>block_position</code> to
begin reading the block header.</p></div>
<div class="paragraph"><p>Readers must examine the block header at <code>block_position</code> to determine
if the next block is another level index block, or the leaf-level ref
block.</p></div>
</div>
<div class="sect4">
<h5 id="_reading_the_index">Reading the index</h5>
<div class="paragraph"><p>Readers loading the ref index must first read the footer (below) to
obtain <code>ref_index_position</code>. If not present, the position will be 0. The
<code>ref_index_position</code> is for the 1st level root of the ref index.</p></div>
</div>
</div>
<div class="sect3">
<h4 id="_obj_block_format">Obj block format</h4>
<div class="paragraph"><p>Object blocks are optional. Writers may choose to omit object blocks,
especially if readers will not use the object name to ref mapping.</p></div>
<div class="paragraph"><p>Object blocks use unique, abbreviated 2-31 byte object name keys, mapping to
ref blocks containing references pointing to that object directly, or as
the peeled value of an annotated tag. Like ref blocks, object blocks use
the file&#8217;s standard block size. The abbreviation length is available in
the footer as <code>obj_id_len</code>.</p></div>
<div class="paragraph"><p>To save space in small files, object blocks may be omitted if the ref
index is not present, as brute force search will only need to read a few
ref blocks. When missing, readers should brute force a linear search of
all references to lookup by object name.</p></div>
<div class="paragraph"><p>An object block is written as:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>'o'
uint24( block_len )
obj_record+
uint24( restart_offset )+
uint16( restart_count )

padding?</code></pre>
</div></div>
<div class="paragraph"><p>Fields are identical to ref block. Binary search using the restart table
works the same as in reference blocks.</p></div>
<div class="paragraph"><p>Because object names are abbreviated by writers to the shortest unique
abbreviation within the reftable, obj key lengths have a variable length. Their
length must be at least 2 bytes. Readers must compare only for common prefix
match within an obj block or obj index.</p></div>
<div class="sect4">
<h5 id="_obj_record">obj record</h5>
<div class="paragraph"><p>An <code>obj_record</code> describes a single object abbreviation, and the blocks
containing references using that unique abbreviation:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>varint( prefix_length )
varint( (suffix_length &lt;&lt; 3) | cnt_3 )
suffix
varint( cnt_large )?
varint( position_delta )*</code></pre>
</div></div>
<div class="paragraph"><p>Like in reference blocks, abbreviations are prefix compressed within an
obj block. On large reftables with many unique objects, higher block
sizes (64k), and higher restart interval (128), a <code>prefix_length</code> of 2
or 3 and <code>suffix_length</code> of 3 may be common in obj records (unique
abbreviation of 5-6 raw bytes, 10-12 hex digits).</p></div>
<div class="paragraph"><p>Each record contains <code>position_count</code> number of positions for matching
ref blocks. For 1-7 positions the count is stored in <code>cnt_3</code>. When
<code>cnt_3 = 0</code> the actual count follows in a varint, <code>cnt_large</code>.</p></div>
<div class="paragraph"><p>The use of <code>cnt_3</code> bets most objects are pointed to by only a single
reference, some may be pointed to by a couple of references, and very
few (if any) are pointed to by more than 7 references.</p></div>
<div class="paragraph"><p>A special case exists when <code>cnt_3 = 0</code> and <code>cnt_large = 0</code>: there are no
<code>position_delta</code>, but at least one reference starts with this
abbreviation. A reader that needs exact reference names must scan all
references to find which specific references have the desired object.
Writers should use this format when the <code>position_delta</code> list would have
overflowed the file&#8217;s block size due to a high number of references
pointing to the same object.</p></div>
<div class="paragraph"><p>The first <code>position_delta</code> is the position from the start of the file.
Additional <code>position_delta</code> entries are sorted ascending and relative to
the prior entry, e.g. a reader would perform:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>pos = position_delta[0]
prior = pos
for (j = 1; j &lt; position_count; j++) {
  pos = prior + position_delta[j]
  prior = pos
}</code></pre>
</div></div>
<div class="paragraph"><p>With a position in hand, a reader must linearly scan the ref block,
starting from the first <code>ref_record</code>, testing each reference&#8217;s object names
(for <code>value_type = 0x1</code> or <code>0x2</code>) for full equality. Faster searching by
object name within a single ref block is not supported by the reftable format.
Smaller block sizes reduce the number of candidates this step must
consider.</p></div>
</div>
</div>
<div class="sect3">
<h4 id="_obj_index">Obj index</h4>
<div class="paragraph"><p>The obj index stores the abbreviation from the last entry for every obj
block in the file, enabling reduced disk seeks for all lookups. It is
formatted exactly the same as the ref index, but refers to obj blocks.</p></div>
<div class="paragraph"><p>The obj index should be present if obj blocks are present, as obj blocks
should only be written in larger files.</p></div>
<div class="paragraph"><p>Readers loading the obj index must first read the footer (below) to
obtain <code>obj_index_position</code>. If not present, the position will be 0.</p></div>
</div>
<div class="sect3">
<h4 id="_log_block_format">Log block format</h4>
<div class="paragraph"><p>Unlike ref and obj blocks, log blocks are always unaligned.</p></div>
<div class="paragraph"><p>Log blocks are variable in size, and do not match the <code>block_size</code>
specified in the file header or footer. Writers should choose an
appropriate buffer size to prepare a log block for deflation, such as
<code>2 * block_size</code>.</p></div>
<div class="paragraph"><p>A log block is written as:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>'g'
uint24( block_len )
zlib_deflate {
  log_record+
  uint24( restart_offset )+
  uint16( restart_count )
}</code></pre>
</div></div>
<div class="paragraph"><p>Log blocks look similar to ref blocks, except <code>block_type = 'g'</code>.</p></div>
<div class="paragraph"><p>The 4-byte block header is followed by the deflated block contents using
zlib deflate. The <code>block_len</code> in the header is the inflated size
(including 4-byte block header), and should be used by readers to
preallocate the inflation output buffer. A log block&#8217;s <code>block_len</code> may
exceed the file&#8217;s block size.</p></div>
<div class="paragraph"><p>Offsets within the log block (e.g. <code>restart_offset</code>) still include the
4-byte header. Readers may prefer prefixing the inflation output buffer
with the 4-byte header.</p></div>
<div class="paragraph"><p>Within the deflate container, a variable number of <code>log_record</code> describe
reference changes. The log record format is described below. See ref
block format (above) for a description of <code>restart_offset</code> and
<code>restart_count</code>.</p></div>
<div class="paragraph"><p>Because log blocks have no alignment or padding between blocks, readers
must keep track of the bytes consumed by the inflater to know where the
next log block begins.</p></div>
<div class="sect4">
<h5 id="_log_record">log record</h5>
<div class="paragraph"><p>Log record keys are structured as:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>ref_name '\0' reverse_int64( update_index )</code></pre>
</div></div>
<div class="paragraph"><p>where <code>update_index</code> is the unique transaction identifier. The
<code>update_index</code> field must be unique within the scope of a <code>ref_name</code>.
See the update transactions section below for further details.</p></div>
<div class="paragraph"><p>The <code>reverse_int64</code> function inverses the value so lexicographical
ordering the network byte order encoding sorts the more recent records
with higher <code>update_index</code> values first:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>reverse_int64(int64 t) {
  return 0xffffffffffffffff - t;
}</code></pre>
</div></div>
<div class="paragraph"><p>Log records have a similar starting structure to ref and index records,
utilizing the same prefix compression scheme applied to the log record
key described above.</p></div>
<div class="literalblock">
<div class="content">
<pre><code>    varint( prefix_length )
    varint( (suffix_length &lt;&lt; 3) | log_type )
    suffix
    log_data {
      old_id
      new_id
      varint( name_length    )  name
      varint( email_length   )  email
      varint( time_seconds )
      sint16( tz_offset )
      varint( message_length )  message
    }?</code></pre>
</div></div>
<div class="paragraph"><p>Log record entries use <code>log_type</code> to indicate what follows:</p></div>
<div class="ulist"><ul>
<li>
<p>
<code>0x0</code>: deletion; no log data.
</p>
</li>
<li>
<p>
<code>0x1</code>: standard git reflog data using <code>log_data</code> above.
</p>
</li>
</ul></div>
<div class="paragraph"><p>The <code>log_type = 0x0</code> is mostly useful for <code>git stash drop</code>, removing an
entry from the reflog of <code>refs/stash</code> in a transaction file (below),
without needing to rewrite larger files. Readers reading a stack of
reflogs must treat this as a deletion.</p></div>
<div class="paragraph"><p>For <code>log_type = 0x1</code>, the <code>log_data</code> section follows
<a href="../git-update-ref.html">git-update-ref(1)</a> logging and includes:</p></div>
<div class="ulist"><ul>
<li>
<p>
two object names (old id, new id)
</p>
</li>
<li>
<p>
varint string of committer&#8217;s name
</p>
</li>
<li>
<p>
varint string of committer&#8217;s email
</p>
</li>
<li>
<p>
varint time in seconds since epoch (Jan 1, 1970)
</p>
</li>
<li>
<p>
2-byte timezone offset in minutes (signed)
</p>
</li>
<li>
<p>
varint string of message
</p>
</li>
</ul></div>
<div class="paragraph"><p><code>tz_offset</code> is the absolute number of minutes from GMT the committer was
at the time of the update. For example <code>GMT-0800</code> is encoded in reftable
as <code>sint16(-480)</code> and <code>GMT+0230</code> is <code>sint16(150)</code>.</p></div>
<div class="paragraph"><p>The committer email does not contain <code>&lt;</code> or <code>&gt;</code>, it&#8217;s the value normally
found between the <code>&lt;&gt;</code> in a git commit object header.</p></div>
<div class="paragraph"><p>The <code>message_length</code> may be 0, in which case there was no message
supplied for the update.</p></div>
<div class="paragraph"><p>Contrary to traditional reflog (which is a file), renames are encoded as
a combination of ref deletion and ref creation.  A deletion is a log
record with a zero new_id, and a creation is a log record with a zero old_id.</p></div>
</div>
<div class="sect4">
<h5 id="_reading_the_log">Reading the log</h5>
<div class="paragraph"><p>Readers accessing the log must first read the footer (below) to
determine the <code>log_position</code>. The first block of the log begins at
<code>log_position</code> bytes since the start of the file. The <code>log_position</code> is
not block aligned.</p></div>
</div>
<div class="sect4">
<h5 id="_importing_logs">Importing logs</h5>
<div class="paragraph"><p>When importing from <code>$GIT_DIR/logs</code> writers should globally order all
log records roughly by timestamp while preserving file order, and assign
unique, increasing <code>update_index</code> values for each log line. Newer log
records get higher <code>update_index</code> values.</p></div>
<div class="paragraph"><p>Although an import may write only a single reftable file, the reftable
file must span many unique <code>update_index</code>, as each log line requires its
own <code>update_index</code> to preserve semantics.</p></div>
</div>
</div>
<div class="sect3">
<h4 id="_log_index">Log index</h4>
<div class="paragraph"><p>The log index stores the log key
(<code>refname \0 reverse_int64(update_index)</code>) for the last log record of
every log block in the file, supporting bounded-time lookup.</p></div>
<div class="paragraph"><p>A log index block must be written if 2 or more log blocks are written to
the file. If present, the log index appears after the last log block.
There is no padding used to align the log index to block alignment.</p></div>
<div class="paragraph"><p>Log index format is identical to ref index, except the keys are 9 bytes
longer to include <code>'\0'</code> and the 8-byte <code>reverse_int64(update_index)</code>.
Records use <code>block_position</code> to refer to the start of a log block.</p></div>
<div class="sect4">
<h5 id="_reading_the_index_2">Reading the index</h5>
<div class="paragraph"><p>Readers loading the log index must first read the footer (below) to
obtain <code>log_index_position</code>. If not present, the position will be 0.</p></div>
</div>
</div>
<div class="sect3">
<h4 id="_footer">Footer</h4>
<div class="paragraph"><p>After the last block of the file, a file footer is written. It begins
like the file header, but is extended with additional data.</p></div>
<div class="literalblock">
<div class="content">
<pre><code>    HEADER

    uint64( ref_index_position )
    uint64( (obj_position &lt;&lt; 5) | obj_id_len )
    uint64( obj_index_position )

    uint64( log_position )
    uint64( log_index_position )

    uint32( CRC-32 of above )</code></pre>
</div></div>
<div class="paragraph"><p>If a section is missing (e.g. ref index) the corresponding position
field (e.g. <code>ref_index_position</code>) will be 0.</p></div>
<div class="ulist"><ul>
<li>
<p>
<code>obj_position</code>: byte position for the first obj block.
</p>
</li>
<li>
<p>
<code>obj_id_len</code>: number of bytes used to abbreviate object names in
obj blocks.
</p>
</li>
<li>
<p>
<code>log_position</code>: byte position for the first log block.
</p>
</li>
<li>
<p>
<code>ref_index_position</code>: byte position for the start of the ref index.
</p>
</li>
<li>
<p>
<code>obj_index_position</code>: byte position for the start of the obj index.
</p>
</li>
<li>
<p>
<code>log_index_position</code>: byte position for the start of the log index.
</p>
</li>
</ul></div>
<div class="paragraph"><p>The size of the footer is 68 bytes for version 1, and 72 bytes for
version 2.</p></div>
<div class="sect4">
<h5 id="_reading_the_footer">Reading the footer</h5>
<div class="paragraph"><p>Readers must first read the file start to determine the version
number. Then they seek to <code>file_length - FOOTER_LENGTH</code> to access the
footer. A trusted external source (such as <code>stat(2)</code>) is necessary to
obtain <code>file_length</code>. When reading the footer, readers must verify:</p></div>
<div class="ulist"><ul>
<li>
<p>
4-byte magic is correct
</p>
</li>
<li>
<p>
1-byte version number is recognized
</p>
</li>
<li>
<p>
4-byte CRC-32 matches the other 64 bytes (including magic, and
version)
</p>
</li>
</ul></div>
<div class="paragraph"><p>Once verified, the other fields of the footer can be accessed.</p></div>
</div>
<div class="sect4">
<h5 id="_empty_tables">Empty tables</h5>
<div class="paragraph"><p>A reftable may be empty. In this case, the file starts with a header
and is immediately followed by a footer.</p></div>
</div>
</div>
<div class="sect3">
<h4 id="_binary_search">Binary search</h4>
<div class="paragraph"><p>Binary search within a block is supported by the <code>restart_offset</code> fields
at the end of the block. Readers can binary search through the restart
table to locate between which two restart points the sought reference or
key should appear.</p></div>
<div class="paragraph"><p>Each record identified by a <code>restart_offset</code> stores the complete key in
the <code>suffix</code> field of the record, making the compare operation during
binary search straightforward.</p></div>
<div class="paragraph"><p>Once a restart point lexicographically before the sought reference has
been identified, readers can linearly scan through the following record
entries to locate the sought record, terminating if the current record
sorts after (and therefore the sought key is not present).</p></div>
<div class="sect4">
<h5 id="_restart_point_selection">Restart point selection</h5>
<div class="paragraph"><p>Writers determine the restart points at file creation. The process is
arbitrary, but every 16 or 64 records is recommended. Every 16 may be
more suitable for smaller block sizes (4k or 8k), every 64 for larger
block sizes (64k).</p></div>
<div class="paragraph"><p>More frequent restart points reduces prefix compression and increases
space consumed by the restart table, both of which increase file size.</p></div>
<div class="paragraph"><p>Less frequent restart points makes prefix compression more effective,
decreasing overall file size, with increased penalties for readers
walking through more records after the binary search step.</p></div>
<div class="paragraph"><p>A maximum of <code>65535</code> restart points per block is supported.</p></div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_considerations">Considerations</h3>
<div class="sect3">
<h4 id="_lightweight_refs_dominate">Lightweight refs dominate</h4>
<div class="paragraph"><p>The reftable format assumes the vast majority of references are single
object names valued with common prefixes, such as Gerrit Code Review&#8217;s
<code>refs/changes/</code> namespace, GitHub&#8217;s <code>refs/pulls/</code> namespace, or many
lightweight tags in the <code>refs/tags/</code> namespace.</p></div>
<div class="paragraph"><p>Annotated tags storing the peeled object cost an additional object name per
reference.</p></div>
</div>
<div class="sect3">
<h4 id="_low_overhead">Low overhead</h4>
<div class="paragraph"><p>A reftable with very few references (e.g. git.git with 5 heads) is 269
bytes for reftable, vs. 332 bytes for packed-refs. This supports
reftable scaling down for transaction logs (below).</p></div>
</div>
<div class="sect3">
<h4 id="_block_size_2">Block size</h4>
<div class="paragraph"><p>For a Gerrit Code Review type repository with many change refs, larger
block sizes (64 KiB) and less frequent restart points (every 64) yield
better compression due to more references within the block compressing
against the prior reference.</p></div>
<div class="paragraph"><p>Larger block sizes reduce the index size, as the reftable will require
fewer blocks to store the same number of references.</p></div>
</div>
<div class="sect3">
<h4 id="_minimal_disk_seeks">Minimal disk seeks</h4>
<div class="paragraph"><p>Assuming the index block has been loaded into memory, binary searching
for any single reference requires exactly 1 disk seek to load the
containing block.</p></div>
</div>
<div class="sect3">
<h4 id="_scans_and_lookups_dominate">Scans and lookups dominate</h4>
<div class="paragraph"><p>Scanning all references and lookup by name (or namespace such as
<code>refs/heads/</code>) are the most common activities performed on repositories.
Object names are stored directly with references to optimize this use case.</p></div>
</div>
<div class="sect3">
<h4 id="_logs_are_infrequently_read">Logs are infrequently read</h4>
<div class="paragraph"><p>Logs are infrequently accessed, but can be large. Deflating log blocks
saves disk space, with some increased penalty at read time.</p></div>
<div class="paragraph"><p>Logs are stored in an isolated section from refs, reducing the burden on
reference readers that want to ignore logs. Further, historical logs can
be isolated into log-only files.</p></div>
</div>
<div class="sect3">
<h4 id="_logs_are_read_backwards">Logs are read backwards</h4>
<div class="paragraph"><p>Logs are frequently accessed backwards (most recent N records for master
to answer <code>master@{4}</code>), so log records are grouped by reference, and
sorted descending by update index.</p></div>
</div>
</div>
<div class="sect2">
<h3 id="_repository_format">Repository format</h3>
<div class="sect3">
<h4 id="_version_1">Version 1</h4>
<div class="paragraph"><p>A repository must set its <code>$GIT_DIR/config</code> to configure reftable:</p></div>
<div class="literalblock">
<div class="content">
<pre><code>[core]
    repositoryformatversion = 1
[extensions]
    refStorage = reftable</code></pre>
</div></div>
</div>
<div class="sect3">
<h4 id="_layout">Layout</h4>
<div class="paragraph"><p>A collection of reftable files are stored in the <code>$GIT_DIR/reftable/</code> directory.
Their names should have a random element, such that each filename is globally
unique; this helps avoid spurious failures on Windows, where open files cannot
be removed or overwritten. It suggested to use
<code>${min_update_index}-${max_update_index}-${random}.ref</code> as a naming convention.</p></div>
<div class="paragraph"><p>Log-only files use the <code>.log</code> extension, while ref-only and mixed ref
and log files use <code>.ref</code>. extension.</p></div>
<div class="paragraph"><p>The stack ordering file is <code>$GIT_DIR/reftable/tables.list</code> and lists the
current files, one per line, in order, from oldest (base) to newest
(most recent):</p></div>
<div class="literalblock">
<div class="content">
<pre><code>$ cat .git/reftable/tables.list
00000001-00000001-RANDOM1.log
00000002-00000002-RANDOM2.ref
00000003-00000003-RANDOM3.ref</code></pre>
</div></div>
<div class="paragraph"><p>Readers must read <code>$GIT_DIR/reftable/tables.list</code> to determine which
files are relevant right now, and search through the stack in reverse
order (last reftable is examined first).</p></div>
<div class="paragraph"><p>Reftable files not listed in <code>tables.list</code> may be new (and about to be
added to the stack by the active writer), or ancient and ready to be
pruned.</p></div>
</div>
<div class="sect3">
<h4 id="_backward_compatibility">Backward compatibility</h4>
<div class="paragraph"><p>Older clients should continue to recognize the directory as a git
repository so they don&#8217;t look for an enclosing repository in parent
directories. To this end, a reftable-enabled repository must contain the
following dummy files</p></div>
<div class="ulist"><ul>
<li>
<p>
<code>.git/HEAD</code>, a regular file containing <code>ref: refs/heads/.invalid</code>.
</p>
</li>
<li>
<p>
<code>.git/refs/</code>, a directory
</p>
</li>
<li>
<p>
<code>.git/refs/heads</code>, a regular file
</p>
</li>
</ul></div>
</div>
<div class="sect3">
<h4 id="_readers">Readers</h4>
<div class="paragraph"><p>Readers can obtain a consistent snapshot of the reference space by
following:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Open and read the <code>tables.list</code> file.
</p>
</li>
<li>
<p>
Open each of the reftable files that it mentions.
</p>
</li>
<li>
<p>
If any of the files is missing, goto 1.
</p>
</li>
<li>
<p>
Read from the now-open files as long as necessary.
</p>
</li>
</ol></div>
</div>
<div class="sect3">
<h4 id="_update_transactions">Update transactions</h4>
<div class="paragraph"><p>Although reftables are immutable, mutations are supported by writing a
new reftable and atomically appending it to the stack:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Acquire <code>tables.list.lock</code>.
</p>
</li>
<li>
<p>
Read <code>tables.list</code> to determine current reftables.
</p>
</li>
<li>
<p>
Select <code>update_index</code> to be most recent file&#8217;s
<code>max_update_index + 1</code>.
</p>
</li>
<li>
<p>
Prepare temp reftable <code>tmp_XXXXXX</code>, including log entries.
</p>
</li>
<li>
<p>
Rename <code>tmp_XXXXXX</code> to <code>${update_index}-${update_index}-${random}.ref</code>.
</p>
</li>
<li>
<p>
Copy <code>tables.list</code> to <code>tables.list.lock</code>, appending file from (5).
</p>
</li>
<li>
<p>
Rename <code>tables.list.lock</code> to <code>tables.list</code>.
</p>
</li>
</ol></div>
<div class="paragraph"><p>During step 4 the new file&#8217;s <code>min_update_index</code> and <code>max_update_index</code>
are both set to the <code>update_index</code> selected by step 3. All log records
for the transaction use the same <code>update_index</code> in their keys. This
enables later correlation of which references were updated by the same
transaction.</p></div>
<div class="paragraph"><p>Because a single <code>tables.list.lock</code> file is used to manage locking, the
repository is single-threaded for writers. Writers may have to busy-spin
(with backoff) around creating <code>tables.list.lock</code>, for up to an
acceptable wait period, aborting if the repository is too busy to
mutate. Application servers wrapped around repositories (e.g. Gerrit
Code Review) can layer their own lock/wait queue to improve fairness to
writers.</p></div>
</div>
<div class="sect3">
<h4 id="_reference_deletions">Reference deletions</h4>
<div class="paragraph"><p>Deletion of any reference can be explicitly stored by setting the <code>type</code>
to <code>0x0</code> and omitting the <code>value</code> field of the <code>ref_record</code>. This serves
as a tombstone, overriding any assertions about the existence of the
reference from earlier files in the stack.</p></div>
</div>
<div class="sect3">
<h4 id="_compaction">Compaction</h4>
<div class="paragraph"><p>A partial stack of reftables can be compacted by merging references
using a straightforward merge join across reftables, selecting the most
recent value for output, and omitting deleted references that do not
appear in remaining, lower reftables.</p></div>
<div class="paragraph"><p>A compacted reftable should set its &#8216;min_update_index` to the smallest
of the input files&#8217; <code>min_update_index</code>, and its <code>max_update_index</code>
likewise to the largest input <code>max_update_index</code>.</p></div>
<div class="paragraph"><p>For sake of illustration, assume the stack currently consists of
reftable files (from oldest to newest): A, B, C, and D. The compactor is
going to compact B and C, leaving A and D alone.</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Obtain lock <code>tables.list.lock</code> and read the <code>tables.list</code> file.
</p>
</li>
<li>
<p>
Obtain locks <code>B.lock</code> and <code>C.lock</code>. Ownership of these locks
prevents other processes from trying to compact these files.
</p>
</li>
<li>
<p>
Release <code>tables.list.lock</code>.
</p>
</li>
<li>
<p>
Compact <code>B</code> and <code>C</code> into a temp file
<code>${min_update_index}-${max_update_index}_XXXXXX</code>.
</p>
</li>
<li>
<p>
Reacquire lock <code>tables.list.lock</code>.
</p>
</li>
<li>
<p>
Verify that <code>B</code> and <code>C</code> are still in the stack, in that order. This
should always be the case, assuming that other processes are adhering to
the locking protocol.
</p>
</li>
<li>
<p>
Rename <code>${min_update_index}-${max_update_index}_XXXXXX</code> to
<code>${min_update_index}-${max_update_index}-${random}.ref</code>.
</p>
</li>
<li>
<p>
Write the new stack to <code>tables.list.lock</code>, replacing <code>B</code> and <code>C</code>
with the file from (4).
</p>
</li>
<li>
<p>
Rename <code>tables.list.lock</code> to <code>tables.list</code>.
</p>
</li>
<li>
<p>
Delete <code>B</code> and <code>C</code>, perhaps after a short sleep to avoid forcing
readers to backtrack.
</p>
</li>
</ol></div>
<div class="paragraph"><p>This strategy permits compactions to proceed independently of updates.</p></div>
<div class="paragraph"><p>Each reftable (compacted or not) is uniquely identified by its name, so
open reftables can be cached by their name.</p></div>
</div>
<div class="sect3">
<h4 id="_windows">Windows</h4>
<div class="paragraph"><p>On windows, and other systems that do not allow deleting or renaming to open
files, compaction may succeed, but other readers may prevent obsolete tables
from being deleted.</p></div>
<div class="paragraph"><p>On these platforms, the following strategy can be followed: on closing a
reftable stack, reload <code>tables.list</code>, and delete any tables no longer mentioned
in <code>tables.list</code>.</p></div>
<div class="paragraph"><p>Irregular program exit may still leave about unused files. In this case, a
cleanup operation should proceed as follows:</p></div>
<div class="ulist"><ul>
<li>
<p>
take a lock <code>tables.list.lock</code> to prevent concurrent modifications
</p>
</li>
<li>
<p>
refresh the reftable stack, by reading <code>tables.list</code>
</p>
</li>
<li>
<p>
for each <code>*.ref</code> file, remove it if
</p>
<div class="ulist"><ul>
<li>
<p>
it is not mentioned in <code>tables.list</code>, and
</p>
</li>
<li>
<p>
its max update_index is not beyond the max update_index of the stack
</p>
</li>
</ul></div>
</li>
</ul></div>
</div>
</div>
<div class="sect2">
<h3 id="_alternatives_considered">Alternatives considered</h3>
<div class="sect3">
<h4 id="_bzip_packed_refs">bzip packed-refs</h4>
<div class="paragraph"><p><code>bzip2</code> can significantly shrink a large packed-refs file (e.g. 62 MiB
compresses to 23 MiB, 37%). However the bzip format does not support
random access to a single reference. Readers must inflate and discard
while performing a linear scan.</p></div>
<div class="paragraph"><p>Breaking packed-refs into chunks (individually compressing each chunk)
would reduce the amount of data a reader must inflate, but still leaves
the problem of indexing chunks to support readers efficiently locating
the correct chunk.</p></div>
<div class="paragraph"><p>Given the compression achieved by reftable&#8217;s encoding, it does not seem
necessary to add the complexity of bzip/gzip/zlib.</p></div>
</div>
<div class="sect3">
<h4 id="_michael_haggerty_8217_s_alternate_format">Michael Haggerty&#8217;s alternate format</h4>
<div class="paragraph"><p>Michael Haggerty proposed
<a href="https://lore.kernel.org/git/CAMy9T_HCnyc1g8XWOOWhe7nN0aEFyyBskV2aOMb_fe%2BwGvEJ7A%40mail.gmail.com/">an
alternate</a> format to reftable on the Git mailing list. This format uses
smaller chunks, without the restart table, and avoids block alignment
with padding. Reflog entries immediately follow each ref, and are thus
interleaved between refs.</p></div>
<div class="paragraph"><p>Performance testing indicates reftable is faster for lookups (51%
faster, 11.2 usec vs. 5.4 usec), although reftable produces a slightly
larger file (+ ~3.2%, 28.3M vs 29.2M):</p></div>
<div class="tableblock">
<table rules="all"
width="100%"
frame="border"
cellspacing="0" cellpadding="4">
<col width="25%" />
<col width="25%" />
<col width="25%" />
<col width="25%" />
<thead>
<tr>
<th align="right" valign="top">format </th>
<th align="right" valign="top">size </th>
<th align="right" valign="top">seek cold </th>
<th align="right" valign="top">seek hot</th>
</tr>
</thead>
<tbody>
<tr>
<td align="right" valign="top"><p class="table">mh-alt</p></td>
<td align="right" valign="top"><p class="table">28.3 M</p></td>
<td align="right" valign="top"><p class="table">23.4 usec</p></td>
<td align="right" valign="top"><p class="table">11.2 usec</p></td>
</tr>
<tr>
<td align="right" valign="top"><p class="table">reftable</p></td>
<td align="right" valign="top"><p class="table">29.2 M</p></td>
<td align="right" valign="top"><p class="table">19.9 usec</p></td>
<td align="right" valign="top"><p class="table">5.4 usec</p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="sect3">
<h4 id="_jgit_ketch_reftree">JGit Ketch RefTree</h4>
<div class="paragraph"><p><a href="https://dev.eclipse.org/mhonarc/lists/jgit-dev/msg03073.html">JGit Ketch</a>
proposed
<a href="https://lore.kernel.org/git/CAJo%3DhJvnAPNAdDcAAwAvU9C4RVeQdoS3Ev9WTguHx4fD0V_nOg%40mail.gmail.com/">RefTree</a>,
an encoding of references inside Git tree objects stored as part of the
repository&#8217;s object database.</p></div>
<div class="paragraph"><p>The RefTree format adds additional load on the object database storage
layer (more loose objects, more objects in packs), and relies heavily on
the packer&#8217;s delta compression to save space. Namespaces which are flat
(e.g. thousands of tags in refs/tags) initially create very large loose
objects, and so RefTree does not address the problem of copying many
references to modify a handful.</p></div>
<div class="paragraph"><p>Flat namespaces are not efficiently searchable in RefTree, as tree
objects in canonical formatting cannot be binary searched. This fails
the need to handle a large number of references in a single namespace,
such as GitHub&#8217;s <code>refs/pulls</code>, or a project with many tags.</p></div>
</div>
<div class="sect3">
<h4 id="_lmdb">LMDB</h4>
<div class="paragraph"><p>David Turner proposed
<a href="https://lore.kernel.org/git/1455772670-21142-26-git-send-email-dturner@twopensource.com/">using
LMDB</a>, as LMDB is lightweight (64k of runtime code) and GPL-compatible
license.</p></div>
<div class="paragraph"><p>A downside of LMDB is its reliance on a single C implementation. This
makes embedding inside JGit (a popular reimplementation of Git)
difficult, and hoisting onto virtual storage (for JGit DFS) virtually
impossible.</p></div>
<div class="paragraph"><p>A common format that can be supported by all major Git implementations
(git-core, JGit, libgit2) is strongly preferred.</p></div>
</div>
</div>
</div>
</div>
</div>
<div id="footnotes"><hr /></div>
<div id="footer">
<div id="footer-text">
Last updated
 2022-03-09 14:17:38 PST
</div>
</div>
</body>
</html>