tests/test-context-metadata.t
author Gregory Szorc <gregory.szorc@gmail.com>
Tue, 10 Apr 2018 14:29:15 -0700
changeset 37557 734515aca84d
parent 36086 194463554ba5
child 37897 8327fd79adf8
permissions -rw-r--r--
wireproto: define and implement HTTP handshake to upgrade protocol When clients connect to repositories over HTTP, they issue a request to the well-known URL "?cmd=capabilities" to fetch the repository capabilities. This is the handshake portion of the HTTP protocol. This commit defines a mechanism to use that HTTP request to return information about modern server features. If a client sends an X-HgUpgrade-* header containing a list of client-supported API names, the server responds with a response containing information about available services. This includes the normal capabilities string. So if the server doesn't support any newer services, the client can easily fall back. By advertising supported services from clients, server operators can see and log what client support exists in the wild. This will also help with debugging. The response contains the base path to API services. We know there are potential issues with the <repo>/api/ URL space conflicting with hgwebdir and subrepos. By making the API URL dynamic from the perspective of the client, the URL for APIs is not subject to backwards compatibility concerns - at least as long as a ?cmd=capabilities request is made. We've also defined the ``cbor`` client capability for the X-HgProto-* header. This MUST be sent in order to get the modern response from "?cmd=capabilities". During implementation, I initially always sent an application/mercurial-cbor response. However, the handshake mechanism will be more future compatible if the client is in charge of which formats to request. We already perform content negotiation from X-HgProto-*, so keying off this for the capabilities response feels appropriate. In addition, I initially used application/cbor. However, it is conceivable that a non-Mercurial server could serve application/cbor. To rule out this possibility, I've invented a new media type that is Mercurial specific and can't be confused for generic CBOR. Differential Revision: https://phab.mercurial-scm.org/D3242
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34017
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     1
Tests about metadataonlyctx
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     2
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     3
  $ hg init
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     4
  $ echo A > A
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     5
  $ hg commit -A A -m 'Add A'
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     6
  $ echo B > B
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     7
  $ hg commit -A B -m 'Add B'
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     8
  $ hg rm A
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
     9
  $ echo C > C
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    10
  $ echo B2 > B
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    11
  $ hg add C -q
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    12
  $ hg commit -m 'Remove A'
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    13
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    14
  $ cat > metaedit.py <<EOF
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    15
  > from __future__ import absolute_import
36086
194463554ba5 py3: port metaedit extension to Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34078
diff changeset
    16
  > from mercurial import context, pycompat, registrar
34017
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    17
  > cmdtable = {}
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    18
  > command = registrar.command(cmdtable)
36086
194463554ba5 py3: port metaedit extension to Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34078
diff changeset
    19
  > @command(b'metaedit')
34017
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    20
  > def metaedit(ui, repo, arg):
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    21
  >     # Modify commit message to "FOO"
36086
194463554ba5 py3: port metaedit extension to Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34078
diff changeset
    22
  >     with repo.wlock(), repo.lock(), repo.transaction(b'metaedit'):
194463554ba5 py3: port metaedit extension to Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34078
diff changeset
    23
  >         old = repo[b'.']
194463554ba5 py3: port metaedit extension to Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34078
diff changeset
    24
  >         kwargs = dict(s.split(b'=', 1) for s in arg.split(b';'))
34017
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    25
  >         if 'parents' in kwargs:
36086
194463554ba5 py3: port metaedit extension to Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34078
diff changeset
    26
  >             kwargs[b'parents'] = kwargs[b'parents'].split(b',')
194463554ba5 py3: port metaedit extension to Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34078
diff changeset
    27
  >         new = context.metadataonlyctx(repo, old,
194463554ba5 py3: port metaedit extension to Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34078
diff changeset
    28
  >                                       **pycompat.strkwargs(kwargs))
34017
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    29
  >         new.commit()
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    30
  > EOF
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    31
  $ hg --config extensions.metaedit=$TESTTMP/metaedit.py metaedit 'text=Changed'
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    32
  $ hg log -r tip
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    33
  changeset:   3:ad83e9e00ec9
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    34
  tag:         tip
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    35
  parent:      1:3afb7afe6632
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    36
  user:        test
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    37
  date:        Thu Jan 01 00:00:00 1970 +0000
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    38
  summary:     Changed
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    39
  
34078
11499bad0359 check-code: forbid "\S" in egrep regular expression
Jun Wu <quark@fb.com>
parents: 34017
diff changeset
    40
  $ hg --config extensions.metaedit=$TESTTMP/metaedit.py metaedit 'parents=0' 2>&1 | egrep '^RuntimeError'
34017
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    41
  RuntimeError: can't reuse the manifest: its p1 doesn't match the new ctx p1
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    42
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    43
  $ hg --config extensions.metaedit=$TESTTMP/metaedit.py metaedit 'user=foo <foo@example.com>'
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    44
  $ hg log -r tip
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    45
  changeset:   4:1f86eaeca92b
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    46
  tag:         tip
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    47
  parent:      1:3afb7afe6632
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    48
  user:        foo <foo@example.com>
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    49
  date:        Thu Jan 01 00:00:00 1970 +0000
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    50
  summary:     Remove A
be814edf3306 metadataonlyctx: don't crash when reusing the manifest with deletions
Jun Wu <quark@fb.com>
parents:
diff changeset
    51