Mercurial > evolve
comparison hgext/simple4server.py @ 866:c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
This come with its usual train of duplicated utility.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Wed, 05 Mar 2014 15:21:21 -0800 |
parents | aa722de36179 |
children | e9eeef0d07ec |
comparison
equal
deleted
inserted
replaced
865:5c40b2a4b52f | 866:c6dc5822e640 |
---|---|
125 yield length | 125 yield length |
126 for c in proto.groupchunks(obsdata): | 126 for c in proto.groupchunks(obsdata): |
127 yield c | 127 yield c |
128 return wireproto.streamres(data()) | 128 return wireproto.streamres(data()) |
129 | 129 |
130 | |
131 def _obsrelsethashtree(repo): | |
132 cache = [] | |
133 unfi = repo.unfiltered() | |
134 for i in unfi: | |
135 ctx = unfi[i] | |
136 entry = 0 | |
137 sha = util.sha1() | |
138 # add data from p1 | |
139 for p in ctx.parents(): | |
140 p = p.rev() | |
141 if p < 0: | |
142 p = node.nullid | |
143 else: | |
144 p = cache[p][1] | |
145 if p != node.nullid: | |
146 entry += 1 | |
147 sha.update(p) | |
148 tmarkers = repo.obsstore.relevantmarkers([ctx.node()]) | |
149 if tmarkers: | |
150 bmarkers = [obsolete._encodeonemarker(m) for m in tmarkers] | |
151 bmarkers.sort() | |
152 for m in bmarkers: | |
153 entry += 1 | |
154 sha.update(m) | |
155 if entry: | |
156 cache.append((ctx.node(), sha.digest())) | |
157 else: | |
158 cache.append((ctx.node(), node.nullid)) | |
159 return cache | |
160 | |
161 def _obshash(repo, nodes): | |
162 hashs = _obsrelsethashtree(repo) | |
163 nm = repo.changelog.nodemap | |
164 return [hashs[nm.get(n)][1] for n in nodes] | |
165 | |
166 def srv_obshash(repo, proto, nodes): | |
167 return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes))) | |
168 | |
130 def capabilities(orig, repo, proto): | 169 def capabilities(orig, repo, proto): |
131 """wrapper to advertise new capability""" | 170 """wrapper to advertise new capability""" |
132 caps = orig(repo, proto) | 171 caps = orig(repo, proto) |
133 if obsolete._enabled: | 172 if obsolete._enabled: |
134 caps += ' _evoext_pushobsmarkers_0' | 173 caps += ' _evoext_pushobsmarkers_0' |
135 caps += ' _evoext_pullobsmarkers_0' | 174 caps += ' _evoext_pullobsmarkers_0' |
175 caps += ' _evoext_obshash_0' | |
136 return caps | 176 return caps |
137 | 177 |
138 def extsetup(ui): | 178 def extsetup(ui): |
139 obsolete.obsstore = pruneobsstore | 179 obsolete.obsstore = pruneobsstore |
140 obsolete.obsstore.relevantmarkers = relevantmarkers | 180 obsolete.obsstore.relevantmarkers = relevantmarkers |
141 wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '') | 181 wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '') |
142 wireproto.commands['evoext_pullobsmarkers_0'] = (srv_pullobsmarkers, '*') | 182 wireproto.commands['evoext_pullobsmarkers_0'] = (srv_pullobsmarkers, '*') |
143 extensions.wrapfunction(wireproto, 'capabilities', capabilities) | 183 extensions.wrapfunction(wireproto, 'capabilities', capabilities) |
184 wireproto.commands['evoext_obshash'] = (srv_obshash, 'nodes') |