Mercurial > hg
annotate hgext/closehead.py @ 40228:a17c07793dcd
py3: use '%d' for rev nums instead of '%s'
This makes test-close-head.t pass on Python 3.
Differential Revision: https://phab.mercurial-scm.org/D5040
author | Pulkit Goyal <pulkit@yandex-team.ru> |
---|---|
date | Sat, 13 Oct 2018 05:12:20 +0300 |
parents | 12a72729678e |
children | c303d65d2e34 |
rev | line source |
---|---|
39993
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. |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
27 testedwith = 'ships-with-hg-core' |
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 |
40096
12a72729678e
closehead: fix close-head -r listification
Joerg Sonnenberger <joerg@bec.de>
parents:
39993
diff
changeset
|
31 commitopts3 = [('r', 'rev', [], |
39993
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
32 _('revision to check'), _('REV'))] |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
33 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
34 @command('close-head|close-heads', commitopts + commitopts2 + commitopts3, |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
35 _('[OPTION]... [REV]...'), inferrepo=True) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
36 def close_branch(ui, repo, *revs, **opts): |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
37 """close the given head revisions |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
38 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
39 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
|
40 ``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
|
41 directory. |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
42 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
43 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
|
44 """ |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
45 def docommit(rev): |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
46 cctx = context.memctx(repo, parents=[rev, None], text=message, |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
47 files=[], filectxfn=None, user=opts.get('user'), |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
48 date=opts.get('date'), extra=extra) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
49 tr = repo.transaction('commit') |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
50 ret = repo.commitctx(cctx, True) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
51 bookmarks.update(repo, [rev, None], ret) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
52 cctx.markcommitted(ret) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
53 tr.close() |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
54 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
55 opts = pycompat.byteskwargs(opts) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
56 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
57 revs += tuple(opts.get('rev', [])) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
58 revs = scmutil.revrange(repo, revs) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
59 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
60 if not revs: |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
61 raise error.Abort(_('no revisions specified')) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
62 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
63 heads = [] |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
64 for branch in repo.branchmap(): |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
65 heads.extend(repo.branchheads(branch)) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
66 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
|
67 for rev in revs: |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
68 if rev not in heads: |
40228
a17c07793dcd
py3: use '%d' for rev nums instead of '%s'
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40096
diff
changeset
|
69 raise error.Abort(_('revision is not an open head: %d') % rev) |
39993
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
70 |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
71 message = cmdutil.logmessage(ui, opts) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
72 if not message: |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
73 raise error.Abort(_("no commit message specified with -l or -m")) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
74 extra = { 'close': '1' } |
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 with repo.wlock(), repo.lock(): |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
77 for rev in revs: |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
78 r = repo[rev] |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
79 branch = r.branch() |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
80 extra['branch'] = branch |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
81 docommit(r) |
cd5f2e615262
extensions: new closehead module for closing arbitrary heads
Joerg Sonnenberger <joerg@bec.de>
parents:
diff
changeset
|
82 return 0 |