author | Pierre-Yves David <pierre-yves.david@fb.com> |
Wed, 05 Mar 2014 15:21:21 -0800 | |
changeset 866 | c6dc5822e640 |
parent 852 | aa722de36179 |
child 869 | e9eeef0d07ec |
permissions | -rw-r--r-- |
660
e6e47c432ffd
hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
1 |
'''enable experimental obsolescence feature of Mercurial |
e6e47c432ffd
hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
2 |
|
e6e47c432ffd
hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
3 |
OBSOLESCENCE IS AN EXPERIMENTAL FEATURE MAKE SURE YOU UNDERSTOOD THE INVOLVED |
e6e47c432ffd
hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
4 |
CONCEPT BEFORE USING IT. |
e6e47c432ffd
hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
5 |
|
e6e47c432ffd
hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
6 |
/!\ THIS EXTENSION IS INTENDED FOR SERVER SIDE ONLY USAGE /!\ |
e6e47c432ffd
hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
7 |
|
e6e47c432ffd
hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
8 |
For client side usages it is recommended to use the evolve extension for |
e6e47c432ffd
hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
9 |
improved user interface.''' |
e6e47c432ffd
hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
10 |
|
e6e47c432ffd
hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
11 |
import mercurial.obsolete |
e6e47c432ffd
hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
12 |
mercurial.obsolete._enabled = True |
822
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
13 |
|
852
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
14 |
import struct |
822
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
15 |
from mercurial import wireproto |
852
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
16 |
from mercurial import extensions |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
17 |
from mercurial import obsolete |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
18 |
from cStringIO import StringIO |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
19 |
from mercurial import node |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
20 |
_pack = struct.pack |
822
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
21 |
|
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
22 |
def srv_pushobsmarkers(repo, proto): |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
23 |
"""wireprotocol command""" |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
24 |
fp = StringIO() |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
25 |
proto.redirect() |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
26 |
proto.getfile(fp) |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
27 |
data = fp.getvalue() |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
28 |
fp.close() |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
29 |
lock = repo.lock() |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
30 |
try: |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
31 |
tr = repo.transaction('pushkey: obsolete markers') |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
32 |
try: |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
33 |
repo.obsstore.mergemarkers(tr, data) |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
34 |
tr.close() |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
35 |
finally: |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
36 |
tr.release() |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
37 |
finally: |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
38 |
lock.release() |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
39 |
return wireproto.pushres(0) |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
40 |
|
852
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
41 |
def _encodemarkersstream(fp, markers): |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
42 |
fp.write(_pack('>B', 0)) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
43 |
for mark in markers: |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
44 |
fp.write(obsolete._encodeonemarker(mark)) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
45 |
|
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
46 |
def _getobsmarkersstream(repo, heads=None, common=None): |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
47 |
revset = '' |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
48 |
args = [] |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
49 |
repo = repo.unfiltered() |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
50 |
if heads is None: |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
51 |
revset = 'all()' |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
52 |
elif heads: |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
53 |
revset += "(::%ln)" |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
54 |
args.append(heads) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
55 |
else: |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
56 |
assert False, 'pulling no heads?' |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
57 |
if common: |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
58 |
revset += ' - (::%ln)' |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
59 |
args.append(common) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
60 |
nodes = [c.node() for c in repo.set(revset, *args)] |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
61 |
markers = repo.obsstore.relevantmarkers(nodes) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
62 |
obsdata = StringIO() |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
63 |
_encodemarkersstream(obsdata, markers) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
64 |
obsdata.seek(0) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
65 |
return obsdata |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
66 |
|
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
67 |
class pruneobsstore(obsolete.obsstore): |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
68 |
|
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
69 |
def __init__(self, *args, **kwargs): |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
70 |
self.prunedchildren = {} |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
71 |
return super(pruneobsstore, self).__init__(*args, **kwargs) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
72 |
|
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
73 |
def _load(self, markers): |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
74 |
markers = self._prunedetectingmarkers(markers) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
75 |
return super(pruneobsstore, self)._load(markers) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
76 |
|
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
77 |
|
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
78 |
def _prunedetectingmarkers(self, markers): |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
79 |
for m in markers: |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
80 |
if not m[1]: # no successors |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
81 |
meta = obsolete.decodemeta(m[3]) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
82 |
if 'p1' in meta: |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
83 |
p1 = node.bin(meta['p1']) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
84 |
self.prunedchildren.setdefault(p1, set()).add(m) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
85 |
if 'p2' in meta: |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
86 |
p2 = node.bin(meta['p2']) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
87 |
self.prunedchildren.setdefault(p2, set()).add(m) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
88 |
yield m |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
89 |
|
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
90 |
def relevantmarkers(self, nodes): |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
91 |
"""return a set of all obsolescence marker relevant to a set of node. |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
92 |
|
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
93 |
"relevant" to a set of node mean: |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
94 |
|
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
95 |
- marker that use this changeset as successors |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
96 |
- prune marker of direct children on this changeset. |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
97 |
- recursive application of the two rules on precursors of these markers |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
98 |
|
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
99 |
It a set so you cannot rely on order""" |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
100 |
seennodes = set(nodes) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
101 |
seenmarkers = set() |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
102 |
pendingnodes = set(nodes) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
103 |
precursorsmarkers = self.precursors |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
104 |
prunedchildren = self.prunedchildren |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
105 |
while pendingnodes: |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
106 |
direct = set() |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
107 |
for current in pendingnodes: |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
108 |
direct.update(precursorsmarkers.get(current, ())) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
109 |
direct.update(prunedchildren.get(current, ())) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
110 |
direct -= seenmarkers |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
111 |
pendingnodes = set([m[0] for m in direct]) |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
112 |
seenmarkers |= direct |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
113 |
pendingnodes -= seennodes |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
114 |
seennodes |= pendingnodes |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
115 |
return seenmarkers |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
116 |
|
826
bee5e1105e6c
exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
822
diff
changeset
|
117 |
def srv_pullobsmarkers(repo, proto, others): |
bee5e1105e6c
exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
822
diff
changeset
|
118 |
opts = wireproto.options('', ['heads', 'common'], others) |
bee5e1105e6c
exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
822
diff
changeset
|
119 |
for k, v in opts.iteritems(): |
bee5e1105e6c
exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
822
diff
changeset
|
120 |
if k in ('heads', 'common'): |
bee5e1105e6c
exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
822
diff
changeset
|
121 |
opts[k] = wireproto.decodelist(v) |
bee5e1105e6c
exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
822
diff
changeset
|
122 |
obsdata = _getobsmarkersstream(repo, **opts) |
bee5e1105e6c
exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
822
diff
changeset
|
123 |
length = '%20i' % len(obsdata.getvalue()) |
bee5e1105e6c
exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
822
diff
changeset
|
124 |
def data(): |
bee5e1105e6c
exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
822
diff
changeset
|
125 |
yield length |
bee5e1105e6c
exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
822
diff
changeset
|
126 |
for c in proto.groupchunks(obsdata): |
bee5e1105e6c
exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
822
diff
changeset
|
127 |
yield c |
bee5e1105e6c
exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
822
diff
changeset
|
128 |
return wireproto.streamres(data()) |
bee5e1105e6c
exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
822
diff
changeset
|
129 |
|
866
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
130 |
|
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
131 |
def _obsrelsethashtree(repo): |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
132 |
cache = [] |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
133 |
unfi = repo.unfiltered() |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
134 |
for i in unfi: |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
135 |
ctx = unfi[i] |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
136 |
entry = 0 |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
137 |
sha = util.sha1() |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
138 |
# add data from p1 |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
139 |
for p in ctx.parents(): |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
140 |
p = p.rev() |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
141 |
if p < 0: |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
142 |
p = node.nullid |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
143 |
else: |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
144 |
p = cache[p][1] |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
145 |
if p != node.nullid: |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
146 |
entry += 1 |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
147 |
sha.update(p) |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
148 |
tmarkers = repo.obsstore.relevantmarkers([ctx.node()]) |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
149 |
if tmarkers: |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
150 |
bmarkers = [obsolete._encodeonemarker(m) for m in tmarkers] |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
151 |
bmarkers.sort() |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
152 |
for m in bmarkers: |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
153 |
entry += 1 |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
154 |
sha.update(m) |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
155 |
if entry: |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
156 |
cache.append((ctx.node(), sha.digest())) |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
157 |
else: |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
158 |
cache.append((ctx.node(), node.nullid)) |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
159 |
return cache |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
160 |
|
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
161 |
def _obshash(repo, nodes): |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
162 |
hashs = _obsrelsethashtree(repo) |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
163 |
nm = repo.changelog.nodemap |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
164 |
return [hashs[nm.get(n)][1] for n in nodes] |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
165 |
|
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
166 |
def srv_obshash(repo, proto, nodes): |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
167 |
return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes))) |
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
168 |
|
822
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
169 |
def capabilities(orig, repo, proto): |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
170 |
"""wrapper to advertise new capability""" |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
171 |
caps = orig(repo, proto) |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
172 |
if obsolete._enabled: |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
173 |
caps += ' _evoext_pushobsmarkers_0' |
826
bee5e1105e6c
exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
822
diff
changeset
|
174 |
caps += ' _evoext_pullobsmarkers_0' |
866
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
175 |
caps += ' _evoext_obshash_0' |
822
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
176 |
return caps |
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
177 |
|
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
178 |
def extsetup(ui): |
852
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
179 |
obsolete.obsstore = pruneobsstore |
aa722de36179
exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
826
diff
changeset
|
180 |
obsolete.obsstore.relevantmarkers = relevantmarkers |
822
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
181 |
wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '') |
826
bee5e1105e6c
exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
822
diff
changeset
|
182 |
wireproto.commands['evoext_pullobsmarkers_0'] = (srv_pullobsmarkers, '*') |
822
5f5d269278e9
exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
660
diff
changeset
|
183 |
extensions.wrapfunction(wireproto, 'capabilities', capabilities) |
866
c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
852
diff
changeset
|
184 |
wireproto.commands['evoext_obshash'] = (srv_obshash, 'nodes') |