Mercurial > evolve
annotate hgext/pushexperiment.py @ 727:cb907cf3b556
Add a new pushexperiment extension
This extension introduce a faster way to push obsolescence marker. Send the
obsstore directly instead of inefficiently going through pushkey's
inefficiency.
author | Julien Cristau <julien.cristau@logilab.fr> |
---|---|
date | Mon, 03 Jun 2013 14:53:24 +0200 |
parents | |
children | 5d368ae3d5a0 |
rev | line source |
---|---|
727
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
1 """Small extension altering some push behavior |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
2 |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
3 - Add a new wire protocol command to exchange obsolescence marker. Sending the |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
4 raw file as a binary instead of using pushkey hack. |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
5 |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
6 """ |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
7 |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
8 import errno |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
9 from StringIO import StringIO |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
10 |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
11 from mercurial.i18n import _ |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
12 from mercurial import extensions |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
13 from mercurial import wireproto |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
14 from mercurial import obsolete |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
15 |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
16 |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
17 def client_pushobsmarkers(self, obsfile): |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
18 """wireprotocol peer method""" |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
19 self.requirecap('_push_experiment_pushobsmarkers_0', |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
20 _('push obsolete markers faster')) |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
21 ret, output = self._callpush('push_experiment_pushobsmarkers_0', obsfile) |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
22 for l in output.splitlines(True): |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
23 self.ui.status(_('remote: '), l) |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
24 return ret |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
25 |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
26 |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
27 def srv_pushobsmarkers(repo, proto): |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
28 """wireprotocol command""" |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
29 fp = StringIO() |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
30 proto.redirect() |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
31 proto.getfile(fp) |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
32 data = fp.getvalue() |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
33 fp.close() |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
34 lock = repo.lock() |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
35 try: |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
36 tr = repo.transaction('pushkey: obsolete markers') |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
37 try: |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
38 repo.obsstore.mergemarkers(tr, data) |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
39 tr.close() |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
40 finally: |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
41 tr.release() |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
42 finally: |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
43 lock.release() |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
44 return wireproto.pushres(0) |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
45 |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
46 |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
47 def syncpush(orig, repo, remote): |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
48 """wraper for obsolete.syncpush to use the fast way if possible""" |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
49 if not (obsolete._enabled and repo.obsstore): |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
50 return |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
51 if remote.capable('_push_experiment_pushobsmarkers_0'): |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
52 try: |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
53 obsfp = repo.sopener('obsstore') |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
54 except IOError as e: |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
55 if e.errno != errno.ENOENT: |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
56 raise |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
57 return |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
58 remote.push_experiment_pushobsmarkers_0(obsfp) |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
59 return |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
60 return orig(repo, remote) |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
61 |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
62 |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
63 def capabilities(orig, repo, proto): |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
64 """wrapper to advertise new capability""" |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
65 caps = orig(repo, proto) |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
66 if obsolete._enabled: |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
67 caps += ' _push_experiment_pushobsmarkers_0' |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
68 return caps |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
69 |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
70 |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
71 def extsetup(ui): |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
72 wireproto.wirepeer.push_experiment_pushobsmarkers_0 = client_pushobsmarkers |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
73 wireproto.commands['push_experiment_pushobsmarkers_0'] = (srv_pushobsmarkers, '') |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
74 extensions.wrapfunction(wireproto, 'capabilities', capabilities) |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
75 extensions.wrapfunction(obsolete, 'syncpush', syncpush) |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
76 |
cb907cf3b556
Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
77 |