##// END OF EJS Templates
bundle2-push: provide transaction to reply unbundler...
Eric Sumner -
r23439:743736fc default
parent child Browse files
Show More
@@ -0,0 +1,111 b''
1 $ cat > bundle2.py << EOF
2 > """A small extension to test bundle2 pushback parts.
3 > Current bundle2 implementation doesn't provide a way to generate those
4 > parts, so they must be created by extensions.
5 > """
6 > from mercurial import bundle2, pushkey, exchange, util
7 > def _newhandlechangegroup(op, inpart):
8 > """This function wraps the changegroup part handler for getbundle.
9 > It issues an additional b2x:pushkey part to send a new
10 > bookmark back to the client"""
11 > result = bundle2.handlechangegroup(op, inpart)
12 > if 'b2x:pushback' in op.reply.capabilities:
13 > params = {'namespace': 'bookmarks',
14 > 'key': 'new-server-mark',
15 > 'old': '',
16 > 'new': 'tip'}
17 > encodedparams = [(k, pushkey.encode(v)) for (k,v) in params.items()]
18 > op.reply.newpart('b2x:pushkey', mandatoryparams=encodedparams)
19 > else:
20 > op.reply.newpart('b2x:output', data='pushback not enabled')
21 > return result
22 > _newhandlechangegroup.params = bundle2.handlechangegroup.params
23 > bundle2.parthandlermapping['b2x:changegroup'] = _newhandlechangegroup
24 > EOF
25
26 $ cat >> $HGRCPATH <<EOF
27 > [ui]
28 > ssh = python "$TESTDIR/dummyssh"
29 > username = nobody <no.reply@example.com>
30 >
31 > [alias]
32 > tglog = log -G -T "{desc} [{phase}:{node|short}]"
33 > EOF
34
35 Set up server repository
36
37 $ hg init server
38 $ cd server
39 $ echo c0 > f0
40 $ hg commit -Am 0
41 adding f0
42
43 Set up client repository
44
45 $ cd ..
46 $ hg clone ssh://user@dummy/server client -q
47 $ cd client
48
49 Enable extension
50 $ cat >> $HGRCPATH <<EOF
51 > [extensions]
52 > bundle2=$TESTTMP/bundle2.py
53 > [experimental]
54 > bundle2-exp = True
55 > EOF
56
57 Without config
58
59 $ cd ../client
60 $ echo c1 > f1
61 $ hg commit -Am 1
62 adding f1
63 $ hg push
64 pushing to ssh://user@dummy/server
65 searching for changes
66 remote: pushback not enabled
67 remote: adding changesets
68 remote: adding manifests
69 remote: adding file changes
70 remote: added 1 changesets with 1 changes to 1 files
71 $ hg bookmark
72 no bookmarks set
73
74 $ cd ../server
75 $ hg tglog
76 o 1 [public:2b9c7234e035]
77 |
78 @ 0 [public:6cee5c8f3e5b]
79
80
81
82
83 With config
84
85 $ cd ../client
86 $ echo '[experimental]' >> .hg/hgrc
87 $ echo 'bundle2.pushback = True' >> .hg/hgrc
88 $ echo c2 > f2
89 $ hg commit -Am 2
90 adding f2
91 $ hg push
92 pushing to ssh://user@dummy/server
93 searching for changes
94 remote: adding changesets
95 remote: adding manifests
96 remote: adding file changes
97 remote: added 1 changesets with 1 changes to 1 files
98 $ hg bookmark
99 new-server-mark 2:0a76dfb2e179
100
101 $ cd ../server
102 $ hg tglog
103 o 2 [public:0a76dfb2e179]
104 |
105 o 1 [public:2b9c7234e035]
106 |
107 @ 0 [public:6cee5c8f3e5b]
108
109
110
111
@@ -877,7 +877,7 b" capabilities = {'HG2Y': (),"
877 'b2x:remote-changegroup': ('http', 'https'),
877 'b2x:remote-changegroup': ('http', 'https'),
878 }
878 }
879
879
880 def getrepocaps(repo):
880 def getrepocaps(repo, allowpushback=False):
881 """return the bundle2 capabilities for a given repo
881 """return the bundle2 capabilities for a given repo
882
882
883 Exists to allow extensions (like evolution) to mutate the capabilities.
883 Exists to allow extensions (like evolution) to mutate the capabilities.
@@ -887,6 +887,8 b' def getrepocaps(repo):'
887 if obsolete.isenabled(repo, obsolete.exchangeopt):
887 if obsolete.isenabled(repo, obsolete.exchangeopt):
888 supportedformat = tuple('V%i' % v for v in obsolete.formats)
888 supportedformat = tuple('V%i' % v for v in obsolete.formats)
889 caps['b2x:obsmarkers'] = supportedformat
889 caps['b2x:obsmarkers'] = supportedformat
890 if allowpushback:
891 caps['b2x:pushback'] = ()
890 return caps
892 return caps
891
893
892 def bundle2caps(remote):
894 def bundle2caps(remote):
@@ -572,8 +572,12 b' def _pushbundle2(pushop):'
572 The only currently supported type of data is changegroup but this will
572 The only currently supported type of data is changegroup but this will
573 evolve in the future."""
573 evolve in the future."""
574 bundler = bundle2.bundle20(pushop.ui, bundle2.bundle2caps(pushop.remote))
574 bundler = bundle2.bundle20(pushop.ui, bundle2.bundle2caps(pushop.remote))
575 pushback = (pushop.trmanager
576 and pushop.ui.configbool('experimental', 'bundle2.pushback'))
577
575 # create reply capability
578 # create reply capability
576 capsblob = bundle2.encodecaps(bundle2.getrepocaps(pushop.repo))
579 capsblob = bundle2.encodecaps(bundle2.getrepocaps(pushop.repo,
580 allowpushback=pushback))
577 bundler.newpart('b2x:replycaps', data=capsblob)
581 bundler.newpart('b2x:replycaps', data=capsblob)
578 replyhandlers = []
582 replyhandlers = []
579 for partgenname in b2partsgenorder:
583 for partgenname in b2partsgenorder:
@@ -590,7 +594,10 b' def _pushbundle2(pushop):'
590 except error.BundleValueError, exc:
594 except error.BundleValueError, exc:
591 raise util.Abort('missing support for %s' % exc)
595 raise util.Abort('missing support for %s' % exc)
592 try:
596 try:
593 op = bundle2.processbundle(pushop.repo, reply)
597 trgetter = None
598 if pushback:
599 trgetter = pushop.trmanager.transaction
600 op = bundle2.processbundle(pushop.repo, reply, trgetter)
594 except error.BundleValueError, exc:
601 except error.BundleValueError, exc:
595 raise util.Abort('missing support for %s' % exc)
602 raise util.Abort('missing support for %s' % exc)
596 for rephand in replyhandlers:
603 for rephand in replyhandlers:
General Comments 0
You need to be logged in to leave comments. Login now