sapling/tests/test-bundle2-pushback.t
Jun Wu 9dc21f8d0b codemod: import from the edenscm package
Summary:
D13853115 adds `edenscm/` to `sys.path` and code still uses `import mercurial`.
That has nasty problems if both `import mercurial` and
`import edenscm.mercurial` are used, because Python would think `mercurial.foo`
and `edenscm.mercurial.foo` are different modules so code like
`try: ... except mercurial.error.Foo: ...`, or `isinstance(x, mercurial.foo.Bar)`
would fail to handle the `edenscm.mercurial` version. There are also some
module-level states (ex. `extensions._extensions`) that would cause trouble if
they have multiple versions in a single process.

Change imports to use the `edenscm` so ideally the `mercurial` is no longer
imported at all. Add checks in extensions.py to catch unexpected extensions
importing modules from the old (wrong) locations when running tests.

Reviewed By: phillco

Differential Revision: D13868981

fbshipit-source-id: f4e2513766957fd81d85407994f7521a08e4de48
2019-01-29 17:25:32 -08:00

108 lines
2.6 KiB
Perl

$ cat > bundle2.py << EOF
> """A small extension to test bundle2 pushback parts.
> Current bundle2 implementation doesn't provide a way to generate those
> parts, so they must be created by extensions.
> """
> from __future__ import absolute_import
> from edenscm.mercurial import bundle2, exchange, pushkey, util
> def _newhandlechangegroup(op, inpart):
> """This function wraps the changegroup part handler for getbundle.
> It issues an additional pushkey part to send a new
> bookmark back to the client"""
> result = bundle2.handlechangegroup(op, inpart)
> if 'pushback' in op.reply.capabilities:
> params = {'namespace': 'bookmarks',
> 'key': 'new-server-mark',
> 'old': '',
> 'new': 'tip'}
> encodedparams = [(k, pushkey.encode(v)) for (k,v) in params.items()]
> op.reply.newpart('pushkey', mandatoryparams=encodedparams)
> else:
> op.reply.newpart('output', data='pushback not enabled')
> return result
> _newhandlechangegroup.params = bundle2.handlechangegroup.params
> bundle2.parthandlermapping['changegroup'] = _newhandlechangegroup
> EOF
$ cat >> $HGRCPATH <<EOF
> [ui]
> ssh = $PYTHON "$TESTDIR/dummyssh"
> username = nobody <no.reply@example.com>
> EOF
Set up server repository
$ hg init server
$ cd server
$ echo c0 > f0
$ hg commit -Am 0
adding f0
Set up client repository
$ cd ..
$ hg clone ssh://user@dummy/server client -q
$ cd client
Enable extension
$ cat >> $HGRCPATH <<EOF
> [extensions]
> bundle2=$TESTTMP/bundle2.py
> EOF
Without config
$ cd ../client
$ echo c1 > f1
$ hg commit -Am 1
adding f1
$ hg push
pushing to ssh://user@dummy/server
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files
remote: pushback not enabled
$ hg bookmark
no bookmarks set
$ cd ../server
$ tglogp
o 1: 2b9c7234e035 public '1'
|
@ 0: 6cee5c8f3e5b public '0'
With config
$ cd ../client
$ echo '[experimental]' >> .hg/hgrc
$ echo 'bundle2.pushback = True' >> .hg/hgrc
$ echo c2 > f2
$ hg commit -Am 2
adding f2
$ hg push
pushing to ssh://user@dummy/server
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files
$ hg bookmark
new-server-mark 2:0a76dfb2e179
$ cd ../server
$ tglogp
o 2: 0a76dfb2e179 public '2'
|
o 1: 2b9c7234e035 public '1'
|
@ 0: 6cee5c8f3e5b public '0'