Mercurial > hg-stable
annotate hgext/closehead.py @ 43874:bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
In 1fe2e574616e I introduced a temporary bugfix to align Rust code with a new
behavior from C/Python and forgot about a few `Result`s (cargo's compiler cache
does not re-emit warnings on cached modules). This fixes it.
For the record, I am still unsure that this behavior change is a good idea.
Note: I was already quite unhappy with the setters and getters for the
`DirstateMap` and, indirectly, `Dirs`, and this only further reinforces my
feelings. I hope we can one day fix that situation at the type level; Georges
Racinet and I were just talking about devising a POC for using the builder
pattern in the context of FFI with Python, we'll see what comes out of it.
Differential Revision: https://phab.mercurial-scm.org/D7609
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 12 Dec 2019 15:55:25 +0100 |
parents | 687b865b95ad |
children | 9d2b2df2c2ba |
rev | line source |
---|---|
39994
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
1 # closehead.py - Close arbitrary heads without checking them out first |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
2 # |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
3 # This software may be used and distributed according to the terms of the |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
4 # GNU General Public License version 2 or any later version. |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
5 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
6 '''close arbitrary heads without checking them out first''' |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
7 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
8 from __future__ import absolute_import |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
9 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
10 from mercurial.i18n import _ |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
11 from mercurial import ( |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
12 bookmarks, |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
13 cmdutil, |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
14 context, |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
15 error, |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
16 pycompat, |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
17 registrar, |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
18 scmutil, |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
19 ) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
20 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
21 cmdtable = {} |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
22 command = registrar.command(cmdtable) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
23 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
24 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
25 # be specifying the version(s) of Mercurial they are tested with, or |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
26 # leave the attribute unspecified. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
27 testedwith = b'ships-with-hg-core' |
39994
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
28 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
29 commitopts = cmdutil.commitopts |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
30 commitopts2 = cmdutil.commitopts2 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
31 commitopts3 = [(b'r', b'rev', [], _(b'revision to check'), _(b'REV'))] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
32 |
39994
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
33 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
34 @command( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
35 b'close-head|close-heads', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
36 commitopts + commitopts2 + commitopts3, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
37 _(b'[OPTION]... [REV]...'), |
40293
c303d65d2e34
help: assigning categories to existing commands
rdamazio@google.com
parents:
40228
diff
changeset
|
38 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
39 inferrepo=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
40 ) |
39994
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
41 def close_branch(ui, repo, *revs, **opts): |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
42 """close the given head revisions |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
43 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
44 This is equivalent to checking out each revision in a clean tree and running |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
45 ``hg commit --close-branch``, except that it doesn't change the working |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
46 directory. |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
47 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
48 The commit message must be specified with -l or -m. |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
49 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
50 |
39994
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
51 def docommit(rev): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
52 cctx = context.memctx( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
53 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
54 parents=[rev, None], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
55 text=message, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
56 files=[], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
57 filectxfn=None, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
58 user=opts.get(b'user'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
59 date=opts.get(b'date'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
60 extra=extra, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40293
diff
changeset
|
61 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
62 tr = repo.transaction(b'commit') |
39994
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
63 ret = repo.commitctx(cctx, True) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
64 bookmarks.update(repo, [rev, None], ret) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
65 cctx.markcommitted(ret) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
66 tr.close() |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
67 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
68 opts = pycompat.byteskwargs(opts) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
69 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
70 revs += tuple(opts.get(b'rev', [])) |
39994
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
71 revs = scmutil.revrange(repo, revs) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
72 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
73 if not revs: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
74 raise error.Abort(_(b'no revisions specified')) |
39994
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
75 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
76 heads = [] |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
77 for branch in repo.branchmap(): |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
78 heads.extend(repo.branchheads(branch)) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
79 heads = set(repo[h].rev() for h in heads) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
80 for rev in revs: |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
81 if rev not in heads: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
82 raise error.Abort(_(b'revision is not an open head: %d') % rev) |
39994
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
83 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
84 message = cmdutil.logmessage(ui, opts) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
85 if not message: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
86 raise error.Abort(_(b"no commit message specified with -l or -m")) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
87 extra = {b'close': b'1'} |
39994
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
88 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
89 with repo.wlock(), repo.lock(): |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
90 for rev in revs: |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
91 r = repo[rev] |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
92 branch = r.branch() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
93 extra[b'branch'] = branch |
39994
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
94 docommit(r) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
95 return 0 |