tests/test-phabricator.t
author Gregory Szorc <gregory.szorc@gmail.com>
Wed, 12 Sep 2018 11:02:16 -0700
changeset 39703 bfeab472e3c0
parent 39670 4057e38bba76
child 40473 d7d3164e6a31
permissions -rw-r--r--
localrepo: create new function for instantiating a local repo object Today, there is a single local repository class - localrepository. Its __init__ is responsible for loading the .hg/requires file and taking different actions depending on what is present. In addition, extensions may define a "reposetup" function that monkeypatches constructed repository instances, often by implementing a derived type and changing the __class__ of the repo instance. Work around alternate storage backends and partial clone has made it clear to me that shoehorning all this logic into __init__ and operating on an existing instance is too convoluted. For example, localrepository assumes revlog storage and swapping in non-revlog storage requires overriding e.g. file() to return something that isn't a revlog. I've authored various patches that either: a) teach various methods (like file()) about different states and taking the appropriate code path at run-time b) create methods/attributes/callables used for instantiating things and populating these in __init__ "a" incurs run-time performance penalties and makes code more complicated since various functions have a bunch of "if storage is X" branches. "b" makes localrepository quickly explode in complexity. My plan for tackling this problem is to make the local repository type more dynamic. Instead of a static localrepository class/type that supports all of the local repository configurations (revlogs vs other, revlogs with ellipsis, revlog v1 versus revlog v2, etc), we'll dynamically construct a type providing the implementations that are needed for the repository on disk, derived from the .hg/requires file and configuration options. The constructed repository type will be specialized and methods won't need to be taught about different implementations nor overloaded. We may also leverage this functionality for building types that don't implement all attributes. For example, the "intents" feature allows commands to declare that they are read only. By dynamically constructing a repository type, we could return a repository instance with no attributes related to mutating the repository. This could include things like a "changelog" property implementation that doesn't check whether it needs to invalidate the hidden revisions set on every access. This commit establishes a function for building a local repository instance. Future commits will start moving functionality from localrepository.__init__ to this function. Then we'll start dynamically changing the returned type depending on options that are present. This change may seem radical. But it should be fully compatible with the reposetup() model - at least for now. Differential Revision: https://phab.mercurial-scm.org/D4563
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39667
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
     1
#require vcr
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
     2
  $ cat >> $HGRCPATH <<EOF
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
     3
  > [extensions]
39668
d2c81e83de2a phabricator: move extension from contrib to hgext
Augie Fackler <raf@durin42.com>
parents: 39667
diff changeset
     4
  > phabricator = 
39667
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
     5
  > EOF
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
     6
  $ hg init repo
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
     7
  $ cd repo
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
     8
  $ cat >> .hg/hgrc <<EOF
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
     9
  > [phabricator]
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    10
  > url = https://phab.mercurial-scm.org/
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    11
  > callsign = HG
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    12
  > 
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    13
  > [auth]
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    14
  > hgphab.schemes = https
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    15
  > hgphab.prefix = phab.mercurial-scm.org
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    16
  > # When working on the extension and making phabricator interaction
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    17
  > # changes, edit this to be a real phabricator token. When done, edit
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    18
  > # it back, and make sure to also edit your VCR transcripts to match
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    19
  > # whatever value you put here.
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    20
  > hgphab.phabtoken = cli-hahayouwish
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    21
  > EOF
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    22
  $ VCR="$TESTDIR/phabricator"
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    23
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    24
Error is handled reasonably. We override the phabtoken here so that
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    25
when you're developing changes to phabricator.py you can edit the
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    26
above config and have a real token in the test but not have to edit
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    27
this test.
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    28
  $ hg phabread --config auth.hgphab.phabtoken=cli-notavalidtoken \
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    29
  >  --test-vcr "$VCR/phabread-conduit-error.json" D4480 | head
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    30
  abort: Conduit Error (ERR-INVALID-AUTH): API token "cli-notavalidtoken" has the wrong length. API tokens should be 32 characters long.
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    31
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    32
Basic phabread:
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    33
  $ hg phabread --test-vcr "$VCR/phabread-4480.json" D4480 | head
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    34
  # HG changeset patch
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    35
  exchangev2: start to implement pull with wire protocol v2
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    36
  
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    37
  Wire protocol version 2 will take a substantially different
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    38
  approach to exchange than version 1 (at least as far as pulling
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    39
  is concerned).
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    40
  
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    41
  This commit establishes a new exchangev2 module for holding
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    42
  code related to exchange using wire protocol v2. I could have
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    43
  added things to the existing exchange module. But it is already
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    44
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    45
phabupdate with an accept:
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    46
  $ hg phabupdate --accept D4564 \
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    47
  > -m 'I think I like where this is headed. Will read rest of series later.'\
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    48
  >  --test-vcr "$VCR/accept-4564.json"
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    49
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    50
Create a differential diff:
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    51
  $ echo alpha > alpha
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    52
  $ hg ci --addremove -m 'create alpha for phabricator test'
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    53
  adding alpha
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    54
  $ hg phabsend -r . --test-vcr "$VCR/phabsend-create-alpha.json"
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    55
  D4596 - created - 5206a4fa1e6c: create alpha for phabricator test
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    56
  saved backup bundle to $TESTTMP/repo/.hg/strip-backup/5206a4fa1e6c-dec9e777-phabsend.hg
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    57
  $ echo more >> alpha
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    58
  $ HGEDITOR=true hg ci --amend
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    59
  saved backup bundle to $TESTTMP/repo/.hg/strip-backup/d8f232f7d799-c573510a-amend.hg
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    60
  $ echo beta > beta
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    61
  $ hg ci --addremove -m 'create beta for phabricator test'
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    62
  adding beta
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    63
  $ hg phabsend -r ".^::" --test-vcr "$VCR/phabsend-update-alpha-create-beta.json"
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    64
  D4596 - updated - f70265671c65: create alpha for phabricator test
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    65
  D4597 - created - 1a5640df7bbf: create beta for phabricator test
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    66
  saved backup bundle to $TESTTMP/repo/.hg/strip-backup/1a5640df7bbf-6daf3e6e-phabsend.hg
39669
10c53b2e9d52 phabricator: add tests of templatekeyword
Augie Fackler <raf@durin42.com>
parents: 39668
diff changeset
    67
10c53b2e9d52 phabricator: add tests of templatekeyword
Augie Fackler <raf@durin42.com>
parents: 39668
diff changeset
    68
Template keywords
10c53b2e9d52 phabricator: add tests of templatekeyword
Augie Fackler <raf@durin42.com>
parents: 39668
diff changeset
    69
  $ hg log -T'{rev} {phabreview|json}\n'
10c53b2e9d52 phabricator: add tests of templatekeyword
Augie Fackler <raf@durin42.com>
parents: 39668
diff changeset
    70
  1 {"id": "D4597", "url": "https://phab.mercurial-scm.org/D4597"}
10c53b2e9d52 phabricator: add tests of templatekeyword
Augie Fackler <raf@durin42.com>
parents: 39668
diff changeset
    71
  0 {"id": "D4596", "url": "https://phab.mercurial-scm.org/D4596"}
10c53b2e9d52 phabricator: add tests of templatekeyword
Augie Fackler <raf@durin42.com>
parents: 39668
diff changeset
    72
39670
4057e38bba76 phabricator: fix templating bug by using hybriddict
Augie Fackler <raf@durin42.com>
parents: 39669
diff changeset
    73
  $ hg log -T'{rev} {phabreview.url} {phabreview.id}\n'
4057e38bba76 phabricator: fix templating bug by using hybriddict
Augie Fackler <raf@durin42.com>
parents: 39669
diff changeset
    74
  1 https://phab.mercurial-scm.org/D4597 D4597
4057e38bba76 phabricator: fix templating bug by using hybriddict
Augie Fackler <raf@durin42.com>
parents: 39669
diff changeset
    75
  0 https://phab.mercurial-scm.org/D4596 D4596
39669
10c53b2e9d52 phabricator: add tests of templatekeyword
Augie Fackler <raf@durin42.com>
parents: 39668
diff changeset
    76
39667
a641fd1a1196 tests: add some basic tests of phabricator interactions
Augie Fackler <raf@durin42.com>
parents:
diff changeset
    77
  $ cd ..