author | Pierre-Yves.David@ens-lyon.org |
Thu, 07 Jun 2012 19:15:23 +0200 | |
changeset 17071 | 11f26e2669aa |
parent 17070 | ad0d6c2b3279 |
child 17072 | 517af63ba382 |
permissions | -rw-r--r-- |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
1 |
# obsolete.py - obsolete markers handling |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
2 |
# |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
3 |
# Copyright 2012 Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
4 |
# Logilab SA <contact@logilab.fr> |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
5 |
# |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
6 |
# This software may be used and distributed according to the terms of the |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
7 |
# GNU General Public License version 2 or any later version. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
8 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
9 |
"""Obsolete markers handling |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
10 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
11 |
An obsolete marker maps an old changeset to a list of new |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
12 |
changesets. If the list of new changesets is empty, the old changeset |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
13 |
is said to be "killed". Otherwise, the old changeset is being |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
14 |
"replaced" by the new changesets. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
15 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
16 |
Obsolete markers can be used to record and distribute changeset graph |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
17 |
transformations performed by history rewriting operations, and help |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
18 |
building new tools to reconciliate conflicting rewriting actions. To |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
19 |
facilitate conflicts resolution, markers include various annotations |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
20 |
besides old and news changeset identifiers, such as creation date or |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
21 |
author name. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
22 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
23 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
24 |
Format |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
25 |
------ |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
26 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
27 |
Markers are stored in an append-only file stored in |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
28 |
'.hg/store/obsstore'. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
29 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
30 |
The file starts with a version header: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
31 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
32 |
- 1 unsigned byte: version number, starting at zero. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
33 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
34 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
35 |
The header is followed by the markers. Each marker is made of: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
36 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
37 |
- 1 unsigned byte: number of new changesets "R", could be zero. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
38 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
39 |
- 1 unsigned 32-bits integer: metadata size "M" in bytes. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
40 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
41 |
- 1 byte: a bit field. It is reserved for flags used in obsolete |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
42 |
markers common operations, to avoid repeated decoding of metadata |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
43 |
entries. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
44 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
45 |
- 20 bytes: obsoleted changeset identifier. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
46 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
47 |
- N*20 bytes: new changesets identifiers. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
48 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
49 |
- M bytes: metadata as a sequence of nul-terminated strings. Each |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
50 |
string contains a key and a value, separated by a color ':', without |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
51 |
additional encoding. Keys cannot contain '\0' or ':' and values |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
52 |
cannot contain '\0'. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
53 |
""" |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
54 |
import struct |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
55 |
from mercurial import util |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
56 |
from i18n import _ |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
57 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
58 |
_pack = struct.pack |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
59 |
_unpack = struct.unpack |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
60 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
61 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
62 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
63 |
# data used for parsing and writing |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
64 |
_fmversion = 0 |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
65 |
_fmfixed = '>BIB20s' |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
66 |
_fmnode = '20s' |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
67 |
_fmfsize = struct.calcsize(_fmfixed) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
68 |
_fnodesize = struct.calcsize(_fmnode) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
69 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
70 |
def _readmarkers(data): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
71 |
"""Read and enumerate markers from raw data""" |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
72 |
off = 0 |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
73 |
diskversion = _unpack('>B', data[off:off + 1])[0] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
74 |
off += 1 |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
75 |
if diskversion != _fmversion: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
76 |
raise util.Abort(_('parsing obsolete marker: unknown version %r') |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
77 |
% diskversion) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
78 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
79 |
# Loop on markers |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
80 |
l = len(data) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
81 |
while off + _fmfsize <= l: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
82 |
# read fixed part |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
83 |
cur = data[off:off + _fmfsize] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
84 |
off += _fmfsize |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
85 |
nbsuc, mdsize, flags, pre = _unpack(_fmfixed, cur) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
86 |
# read replacement |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
87 |
sucs = () |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
88 |
if nbsuc: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
89 |
s = (_fnodesize * nbsuc) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
90 |
cur = data[off:off + s] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
91 |
sucs = _unpack(_fmnode * nbsuc, cur) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
92 |
off += s |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
93 |
# read metadata |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
94 |
# (metadata will be decoded on demand) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
95 |
metadata = data[off:off + mdsize] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
96 |
if len(metadata) != mdsize: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
97 |
raise util.Abort(_('parsing obsolete marker: metadata is too ' |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
98 |
'short, %d bytes expected, got %d') |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
99 |
% (len(metadata), mdsize)) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
100 |
off += mdsize |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
101 |
yield (pre, sucs, flags, metadata) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
102 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
103 |
def encodemeta(meta): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
104 |
"""Return encoded metadata string to string mapping. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
105 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
106 |
Assume no ':' in key and no '\0' in both key and value.""" |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
107 |
for key, value in meta.iteritems(): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
108 |
if ':' in key or '\0' in key: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
109 |
raise ValueError("':' and '\0' are forbidden in metadata key'") |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
110 |
if '\0' in value: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
111 |
raise ValueError("':' are forbidden in metadata value'") |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
112 |
return '\0'.join(['%s:%s' % (k, meta[k]) for k in sorted(meta)]) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
113 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
114 |
def decodemeta(data): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
115 |
"""Return string to string dictionary from encoded version.""" |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
116 |
d = {} |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
117 |
for l in data.split('\0'): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
118 |
if l: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
119 |
key, value = l.split(':') |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
120 |
d[key] = value |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
121 |
return d |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
122 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
123 |
class obsstore(object): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
124 |
"""Store obsolete markers |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
125 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
126 |
Markers can be accessed with two mappings: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
127 |
- precursors: old -> set(new) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
128 |
- successors: new -> set(old) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
129 |
""" |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
130 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
131 |
def __init__(self): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
132 |
self._all = [] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
133 |
# new markers to serialize |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
134 |
self._new = [] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
135 |
self.precursors = {} |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
136 |
self.successors = {} |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
137 |
|
17071
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
138 |
def create(self, prec, succs=(), flag=0, metadata=None): |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
139 |
"""obsolete: add a new obsolete marker |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
140 |
|
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
141 |
* ensuring it is hashable |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
142 |
* check mandatory metadata |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
143 |
* encode metadata |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
144 |
""" |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
145 |
if metadata is None: |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
146 |
metadata = {} |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
147 |
if len(prec) != 20: |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
148 |
raise ValueError(prec) |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
149 |
for succ in succs: |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
150 |
if len(succ) != 20: |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
151 |
raise ValueError(prec) |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
152 |
marker = (str(prec), tuple(succs), int(flag), encodemeta(metadata)) |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
153 |
self.add(marker) |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
154 |
|
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
155 |
def add(self, marker): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
156 |
"""Add a new marker to the store |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
157 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
158 |
This marker still needs to be written to disk""" |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
159 |
self._new.append(marker) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
160 |
self._load(marker) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
161 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
162 |
def loadmarkers(self, data): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
163 |
"""Load all markers in data, mark them as known.""" |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
164 |
for marker in _readmarkers(data): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
165 |
self._load(marker) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
166 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
167 |
def flushmarkers(self, stream): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
168 |
"""Write all markers to a stream |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
169 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
170 |
After this operation, "new" markers are considered "known".""" |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
171 |
self._writemarkers(stream) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
172 |
self._new[:] = [] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
173 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
174 |
def _load(self, marker): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
175 |
self._all.append(marker) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
176 |
pre, sucs = marker[:2] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
177 |
self.precursors.setdefault(pre, set()).add(marker) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
178 |
for suc in sucs: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
179 |
self.successors.setdefault(suc, set()).add(marker) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
180 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
181 |
def _writemarkers(self, stream): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
182 |
# Kept separate from flushmarkers(), it will be reused for |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
183 |
# markers exchange. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
184 |
stream.write(_pack('>B', _fmversion)) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
185 |
for marker in self._all: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
186 |
pre, sucs, flags, metadata = marker |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
187 |
nbsuc = len(sucs) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
188 |
format = _fmfixed + (_fmnode * nbsuc) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
189 |
data = [nbsuc, len(metadata), flags, pre] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
190 |
data.extend(sucs) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
191 |
stream.write(_pack(format, *data)) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
192 |
stream.write(metadata) |