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
|
********
Revfiles
********
The unit for compressed storage in bzr is a *revfile*, whose design
was suggested by Matt Mackall.
This document describes version 1 of the file, and has some notes on
what might be done in version 2.
Requirements
============
Compressed storage is a tradeoff between several goals:
* Reasonably compact storage of long histories.
* Robustness and simplicity.
* Fast extraction of versions and addition of new versions (preferably
without rewriting the whole file, or reading the whole history.)
* Fast and precise annotations.
* Storage of files of at least a few hundred MB.
* Lossless in useful ways: we can extract a series of texts and write
them back out without losing any information.
Design
======
revfiles store the history of a single logical file, which is
identified in bzr by its file-id. In this sense they are similar to
an RCS or CVS ``,v`` file or an SCCS sfile.
Each state of the file is called a *text*.
Renaming, adding and deleting this file is handled at a higher level
by the inventory system, and is outside the scope of the revfile. The
revfile name is typically based on the file id which is itself
typically based on the name the file had when it was first added. But
this is purely cosmetic.
For example a file now called ``frob.c`` may have the id
``frobber.c-12873`` because it was originally called
``frobber.c``. Its texts are kept in the revfile
``.bzr/revfiles/frobber.c-12873.revs``.
When the file is deleted from the inventory the revfile does not
change. It's just not used in reproducing trees from that point
onwards.
The revfile does not record the date when the text was added, a commit
message, properties, or any other metadata. That is handled in the
higher-level revision history.
Inventories and other metadata files that vary from one version to the
next can themselves be stored in revfiles.
revfiles store files as simple byte streams, with no consideration of
translating character sets, line endings, or keywords. Those are also
handled at a higher level. However, the revfile may make use of
knowledge that a file is line-based in generating a diff.
(The Python builtin difflib is too slow when generating a purely
byte-by-byte delta so we always make a line-by-line diff; when this
is fixed it may be feasible to use line-by-line diffs for all
files.)
Files whose text does not change from one revision to the next are
stored as just a single text in the revfile. This can happen even if
the file was renamed or other properties were changed in the
inventory.
The revfile is held on disk as two files: an *index* and a *data*
file. The index file is short and always read completely into memory;
the data file is much longer and only the relevant bits of it,
identified by the index file, need to be read.
This design is similar to that of Netscape `mail summary files`_, in
that there is a small index which can always be read into memory and
that quickly identifies where to look in the main file. They differ
in many other ways though, most particularly that the index is not
just a cache but holds precious data in its own right.
.. _`mail summary files`: http://www.jwz.org/doc/mailsum.html
This is meant to scale to hold 100,000 revisions of a single file, by
which time the index file will be ~4.8MB and a bit big to read
sequentially.
Some of the reserved fields could be used to implement a (semi?)
balanced tree indexed by SHA1 so we can much more efficiently find the
index associated with a particular hash. For 100,000 revs we would be
able to find it in about 17 random reads, which is not too bad. On
the other hand that would compromise the append-only indexing, and
100,000 revs is a fairly extreme case.
This performs pretty well except when trying to calculate deltas of
really large files. For that the main thing would be to plug in
something faster than difflib, which is after all pure Python.
Another approach is to just store the gzipped full text of big files,
though perhaps that's too perverse?
Identifying texts
-----------------
In the current version, texts are identified by their SHA-1.
Skip-deltas
-----------
Because the basis of a delta does not need to be the text's logical
predecessor, we can adjust the deltas to avoid ever needing to apply
too many deltas to reproduce a particular file.
Tools
-----
The revfile module can be invoked as a program to give low-level
access for data recovery, debugging, etc.
Open issues
===========
* revfiles use unsigned 32-bit integers both in diffs and the index.
This should be more than enough for any reasonable source file but
perhaps not enough for large binaries that are frequently committed.
Perhaps for those files there should be an option to continue to use
the text-store. There is unlikely to be any benefit in holding
deltas between them, and deltas will anyhow be hard to calculate.
* The append-only design does not allow for destroying committed data,
as when confidential information is accidentally added. That could
be fixed by creating the fixed repository as a separate branch, into
which only the preserved revisions are exported.
* Should we also store full-texts as a transitional step?
|