Mercurial > evolve
comparison hgext/simple4server.py @ 874:19a7ed6384a9
simple4server: add origin and documentation to most function
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Mon, 10 Mar 2014 17:40:38 -0700 |
parents | c758717ff3c7 |
children | 10867a8e27c6 |
comparison
equal
deleted
inserted
replaced
873:c758717ff3c7 | 874:19a7ed6384a9 |
---|---|
22 from cStringIO import StringIO | 22 from cStringIO import StringIO |
23 from mercurial import node | 23 from mercurial import node |
24 from mercurial.hgweb import hgweb_mod | 24 from mercurial.hgweb import hgweb_mod |
25 _pack = struct.pack | 25 _pack = struct.pack |
26 | 26 |
27 # from evolve extension: 1a23c7c52a43 | |
27 def srv_pushobsmarkers(repo, proto): | 28 def srv_pushobsmarkers(repo, proto): |
28 """wireprotocol command""" | 29 """That receives a stream of markers and apply then to the repo""" |
29 fp = StringIO() | 30 fp = StringIO() |
30 proto.redirect() | 31 proto.redirect() |
31 proto.getfile(fp) | 32 proto.getfile(fp) |
32 data = fp.getvalue() | 33 data = fp.getvalue() |
33 fp.close() | 34 fp.close() |
41 tr.release() | 42 tr.release() |
42 finally: | 43 finally: |
43 lock.release() | 44 lock.release() |
44 return wireproto.pushres(0) | 45 return wireproto.pushres(0) |
45 | 46 |
47 # from mercurial.obsolete: 19e9478c1a22 | |
46 def _encodemarkersstream(fp, markers): | 48 def _encodemarkersstream(fp, markers): |
49 """write a binary version of a set of markers | |
50 | |
51 Includes the initial version number""" | |
47 fp.write(_pack('>B', 0)) | 52 fp.write(_pack('>B', 0)) |
48 for mark in markers: | 53 for mark in markers: |
49 fp.write(obsolete._encodeonemarker(mark)) | 54 fp.write(obsolete._encodeonemarker(mark)) |
50 | 55 |
56 # from evolve extension: 1a23c7c52a43 | |
51 def _getobsmarkersstream(repo, heads=None, common=None): | 57 def _getobsmarkersstream(repo, heads=None, common=None): |
58 """Get a binary stream for all markers relevant to `::<heads> - ::<common>` | |
59 """ | |
52 revset = '' | 60 revset = '' |
53 args = [] | 61 args = [] |
54 repo = repo.unfiltered() | 62 repo = repo.unfiltered() |
55 if heads is None: | 63 if heads is None: |
56 revset = 'all()' | 64 revset = 'all()' |
67 obsdata = StringIO() | 75 obsdata = StringIO() |
68 _encodemarkersstream(obsdata, markers) | 76 _encodemarkersstream(obsdata, markers) |
69 obsdata.seek(0) | 77 obsdata.seek(0) |
70 return obsdata | 78 return obsdata |
71 | 79 |
80 # from evolve extension: 1a23c7c52a43 | |
72 class pruneobsstore(obsolete.obsstore): | 81 class pruneobsstore(obsolete.obsstore): |
82 """And extended obsstore class that read parent information from v1 format | |
83 | |
84 Evolve extension adds parent information in prune marker. We use it to make | |
85 markers relevant to pushed changeset.""" | |
73 | 86 |
74 def __init__(self, *args, **kwargs): | 87 def __init__(self, *args, **kwargs): |
75 self.prunedchildren = {} | 88 self.prunedchildren = {} |
76 return super(pruneobsstore, self).__init__(*args, **kwargs) | 89 return super(pruneobsstore, self).__init__(*args, **kwargs) |
77 | 90 |
90 if 'p2' in meta: | 103 if 'p2' in meta: |
91 p2 = node.bin(meta['p2']) | 104 p2 = node.bin(meta['p2']) |
92 self.prunedchildren.setdefault(p2, set()).add(m) | 105 self.prunedchildren.setdefault(p2, set()).add(m) |
93 yield m | 106 yield m |
94 | 107 |
108 # from evolve extension: 1a23c7c52a43 | |
95 def relevantmarkers(self, nodes): | 109 def relevantmarkers(self, nodes): |
96 """return a set of all obsolescence marker relevant to a set of node. | 110 """return a set of all obsolescence marker relevant to a set of node. |
97 | 111 |
98 "relevant" to a set of node mean: | 112 "relevant" to a set of node mean: |
99 | 113 |
100 - marker that use this changeset as successors | 114 - marker that use this changeset as successors |
101 - prune marker of direct children on this changeset. | 115 - prune marker of direct children on this changeset. |
102 - recursive application of the two rules on precursors of these markers | 116 - recursive application of the two rules on precursors of these markers |
103 | 117 |
104 It a set so you cannot rely on order""" | 118 It is a set so you cannot rely on order""" |
105 seennodes = set(nodes) | 119 seennodes = set(nodes) |
106 seenmarkers = set() | 120 seenmarkers = set() |
107 pendingnodes = set(nodes) | 121 pendingnodes = set(nodes) |
108 precursorsmarkers = self.precursors | 122 precursorsmarkers = self.precursors |
109 prunedchildren = self.prunedchildren | 123 prunedchildren = self.prunedchildren |
117 seenmarkers |= direct | 131 seenmarkers |= direct |
118 pendingnodes -= seennodes | 132 pendingnodes -= seennodes |
119 seennodes |= pendingnodes | 133 seennodes |= pendingnodes |
120 return seenmarkers | 134 return seenmarkers |
121 | 135 |
136 # from evolve extension: 1a23c7c52a43 | |
122 def srv_pullobsmarkers(repo, proto, others): | 137 def srv_pullobsmarkers(repo, proto, others): |
138 """serves a binary stream of markers. | |
139 | |
140 Serves relevant to changeset between heads and common. The stream is prefix | |
141 by a -string- representation of an integer. This integer is the size of the | |
142 stream.""" | |
123 opts = wireproto.options('', ['heads', 'common'], others) | 143 opts = wireproto.options('', ['heads', 'common'], others) |
124 for k, v in opts.iteritems(): | 144 for k, v in opts.iteritems(): |
125 if k in ('heads', 'common'): | 145 if k in ('heads', 'common'): |
126 opts[k] = wireproto.decodelist(v) | 146 opts[k] = wireproto.decodelist(v) |
127 obsdata = _getobsmarkersstream(repo, **opts) | 147 obsdata = _getobsmarkersstream(repo, **opts) |
131 for c in proto.groupchunks(obsdata): | 151 for c in proto.groupchunks(obsdata): |
132 yield c | 152 yield c |
133 return wireproto.streamres(data()) | 153 return wireproto.streamres(data()) |
134 | 154 |
135 | 155 |
156 # from evolve extension: 1a23c7c52a43 | |
136 def _obsrelsethashtree(repo): | 157 def _obsrelsethashtree(repo): |
158 """Build an obshash for every node in a repo | |
159 | |
160 return a [(node), (obshash)] list. in revision order.""" | |
137 cache = [] | 161 cache = [] |
138 unfi = repo.unfiltered() | 162 unfi = repo.unfiltered() |
139 for i in unfi: | 163 for i in unfi: |
140 ctx = unfi[i] | 164 ctx = unfi[i] |
141 entry = 0 | 165 entry = 0 |
161 cache.append((ctx.node(), sha.digest())) | 185 cache.append((ctx.node(), sha.digest())) |
162 else: | 186 else: |
163 cache.append((ctx.node(), node.nullid)) | 187 cache.append((ctx.node(), node.nullid)) |
164 return cache | 188 return cache |
165 | 189 |
190 # from evolve extension: 1a23c7c52a43 | |
166 def _obshash(repo, nodes): | 191 def _obshash(repo, nodes): |
192 """hash of binary version of relevant markers + obsparent | |
193 | |
194 (special case so that all empty are hashed as nullid)""" | |
167 hashs = _obsrelsethashtree(repo) | 195 hashs = _obsrelsethashtree(repo) |
168 nm = repo.changelog.nodemap | 196 nm = repo.changelog.nodemap |
169 return [hashs[nm.get(n)][1] for n in nodes] | 197 return [hashs[nm.get(n)][1] for n in nodes] |
170 | 198 |
199 # from evolve extension: 1a23c7c52a43 | |
171 def srv_obshash(repo, proto, nodes): | 200 def srv_obshash(repo, proto, nodes): |
201 """give the obshash of a a set of node | |
202 | |
203 Used for markes discovery""" | |
172 return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes))) | 204 return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes))) |
173 | 205 |
206 # from evolve extension: 1a23c7c52a43 | |
174 def capabilities(orig, repo, proto): | 207 def capabilities(orig, repo, proto): |
175 """wrapper to advertise new capability""" | 208 """wrapper to advertise new capability""" |
176 caps = orig(repo, proto) | 209 caps = orig(repo, proto) |
177 if obsolete._enabled: | 210 if obsolete._enabled: |
178 caps += ' _evoext_pushobsmarkers_0' | 211 caps += ' _evoext_pushobsmarkers_0' |
179 caps += ' _evoext_pullobsmarkers_0' | 212 caps += ' _evoext_pullobsmarkers_0' |
180 caps += ' _evoext_obshash_0' | 213 caps += ' _evoext_obshash_0' |
181 return caps | 214 return caps |
182 | 215 |
216 # from evolve extension: 1a23c7c52a43 | |
217 # heavily modified | |
183 def extsetup(ui): | 218 def extsetup(ui): |
184 obsolete.obsstore = pruneobsstore | 219 obsolete.obsstore = pruneobsstore |
185 obsolete.obsstore.relevantmarkers = relevantmarkers | 220 obsolete.obsstore.relevantmarkers = relevantmarkers |
186 hgweb_mod.perms['evoext_pushobsmarkers_0'] = 'push' | 221 hgweb_mod.perms['evoext_pushobsmarkers_0'] = 'push' |
187 hgweb_mod.perms['evoext_pullobsmarkers_0'] = 'pull' | 222 hgweb_mod.perms['evoext_pullobsmarkers_0'] = 'pull' |