Show More
@@ -1,82 +1,82 b'' | |||
|
1 | 1 | # closehead.py - Close arbitrary heads without checking them out first |
|
2 | 2 | # |
|
3 | 3 | # This software may be used and distributed according to the terms of the |
|
4 | 4 | # GNU General Public License version 2 or any later version. |
|
5 | 5 | |
|
6 | 6 | '''close arbitrary heads without checking them out first''' |
|
7 | 7 | |
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | from mercurial.i18n import _ |
|
11 | 11 | from mercurial import ( |
|
12 | 12 | bookmarks, |
|
13 | 13 | cmdutil, |
|
14 | 14 | context, |
|
15 | 15 | error, |
|
16 | 16 | pycompat, |
|
17 | 17 | registrar, |
|
18 | 18 | scmutil, |
|
19 | 19 | ) |
|
20 | 20 | |
|
21 | 21 | cmdtable = {} |
|
22 | 22 | command = registrar.command(cmdtable) |
|
23 | 23 | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
|
24 | 24 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
|
25 | 25 | # be specifying the version(s) of Mercurial they are tested with, or |
|
26 | 26 | # leave the attribute unspecified. |
|
27 | 27 | testedwith = 'ships-with-hg-core' |
|
28 | 28 | |
|
29 | 29 | commitopts = cmdutil.commitopts |
|
30 | 30 | commitopts2 = cmdutil.commitopts2 |
|
31 |
commitopts3 = [('r', 'rev', |
|
|
31 | commitopts3 = [('r', 'rev', [], | |
|
32 | 32 | _('revision to check'), _('REV'))] |
|
33 | 33 | |
|
34 | 34 | @command('close-head|close-heads', commitopts + commitopts2 + commitopts3, |
|
35 | 35 | _('[OPTION]... [REV]...'), inferrepo=True) |
|
36 | 36 | def close_branch(ui, repo, *revs, **opts): |
|
37 | 37 | """close the given head revisions |
|
38 | 38 | |
|
39 | 39 | This is equivalent to checking out each revision in a clean tree and running |
|
40 | 40 | ``hg commit --close-branch``, except that it doesn't change the working |
|
41 | 41 | directory. |
|
42 | 42 | |
|
43 | 43 | The commit message must be specified with -l or -m. |
|
44 | 44 | """ |
|
45 | 45 | def docommit(rev): |
|
46 | 46 | cctx = context.memctx(repo, parents=[rev, None], text=message, |
|
47 | 47 | files=[], filectxfn=None, user=opts.get('user'), |
|
48 | 48 | date=opts.get('date'), extra=extra) |
|
49 | 49 | tr = repo.transaction('commit') |
|
50 | 50 | ret = repo.commitctx(cctx, True) |
|
51 | 51 | bookmarks.update(repo, [rev, None], ret) |
|
52 | 52 | cctx.markcommitted(ret) |
|
53 | 53 | tr.close() |
|
54 | 54 | |
|
55 | 55 | opts = pycompat.byteskwargs(opts) |
|
56 | 56 | |
|
57 | 57 | revs += tuple(opts.get('rev', [])) |
|
58 | 58 | revs = scmutil.revrange(repo, revs) |
|
59 | 59 | |
|
60 | 60 | if not revs: |
|
61 | 61 | raise error.Abort(_('no revisions specified')) |
|
62 | 62 | |
|
63 | 63 | heads = [] |
|
64 | 64 | for branch in repo.branchmap(): |
|
65 | 65 | heads.extend(repo.branchheads(branch)) |
|
66 | 66 | heads = set(repo[h].rev() for h in heads) |
|
67 | 67 | for rev in revs: |
|
68 | 68 | if rev not in heads: |
|
69 | 69 | raise error.Abort(_('revision is not an open head: %s') % rev) |
|
70 | 70 | |
|
71 | 71 | message = cmdutil.logmessage(ui, opts) |
|
72 | 72 | if not message: |
|
73 | 73 | raise error.Abort(_("no commit message specified with -l or -m")) |
|
74 | 74 | extra = { 'close': '1' } |
|
75 | 75 | |
|
76 | 76 | with repo.wlock(), repo.lock(): |
|
77 | 77 | for rev in revs: |
|
78 | 78 | r = repo[rev] |
|
79 | 79 | branch = r.branch() |
|
80 | 80 | extra['branch'] = branch |
|
81 | 81 | docommit(r) |
|
82 | 82 | return 0 |
@@ -1,61 +1,74 b'' | |||
|
1 | 1 | $ hg init test-content |
|
2 | 2 | $ cd test-content |
|
3 | $ hg debugbuilddag '+2*2*3*4' | |
|
3 | $ hg debugbuilddag '+2*2*3*4+7' | |
|
4 | 4 | $ hg bookmark -r 1 @ |
|
5 | 5 | $ hg log -G --template '{rev}:{node|short}' |
|
6 | o 11:1d876b1f862c | |
|
7 | | | |
|
8 | o 10:ea5f71948eb8 | |
|
9 | | | |
|
10 | o 9:f1b0356d867a | |
|
11 | | | |
|
12 | o 8:e8d1253fb0d7 | |
|
13 | | | |
|
14 | o 7:d423bbba4459 | |
|
15 | | | |
|
16 | o 6:a2f58e9c1e56 | |
|
17 | | | |
|
18 | o 5:3a367db1fabc | |
|
19 | | | |
|
6 | 20 | o 4:e7bd5218ca15 |
|
7 | 21 | | |
|
8 | 22 | | o 3:6100d3090acf |
|
9 | 23 | |/ |
|
10 | 24 | | o 2:fa942426a6fd |
|
11 | 25 | |/ |
|
12 | 26 | | o 1:66f7d451a68b |
|
13 | 27 | |/ |
|
14 | 28 | o 0:1ea73414a91b |
|
15 | 29 | |
|
16 | 30 | $ hg --config extensions.closehead= close-head -m 'Not a head' 0 1 |
|
17 | 31 | abort: revision is not an open head: 0 |
|
18 | 32 | [255] |
|
19 | 33 | $ hg --config extensions.closehead= close-head -m 'Not a head' -r 0 1 |
|
20 | 34 | abort: revision is not an open head: 0 |
|
21 | 35 | [255] |
|
22 | 36 | $ hg --config extensions.closehead= close-head -m 'Close old heads' -r 1 2 |
|
23 | 37 | $ hg bookmark |
|
24 | 38 | @ 1:66f7d451a68b |
|
25 | 39 | $ hg heads |
|
26 |
changeset: |
|
|
27 | parent: 0:1ea73414a91b | |
|
40 | changeset: 11:1d876b1f862c | |
|
28 | 41 | user: debugbuilddag |
|
29 |
date: Thu Jan 01 00:00: |
|
|
30 |
summary: r |
|
|
42 | date: Thu Jan 01 00:00:11 1970 +0000 | |
|
43 | summary: r11 | |
|
31 | 44 | |
|
32 | 45 | changeset: 3:6100d3090acf |
|
33 | 46 | parent: 0:1ea73414a91b |
|
34 | 47 | user: debugbuilddag |
|
35 | 48 | date: Thu Jan 01 00:00:03 1970 +0000 |
|
36 | 49 | summary: r3 |
|
37 | 50 | |
|
38 |
$ hg --config extensions.closehead= close-head -m 'Close more old heads' |
|
|
51 | $ hg --config extensions.closehead= close-head -m 'Close more old heads' -r 11 | |
|
39 | 52 | $ hg heads |
|
40 | 53 | changeset: 3:6100d3090acf |
|
41 | 54 | parent: 0:1ea73414a91b |
|
42 | 55 | user: debugbuilddag |
|
43 | 56 | date: Thu Jan 01 00:00:03 1970 +0000 |
|
44 | 57 | summary: r3 |
|
45 | 58 | |
|
46 | 59 | $ hg --config extensions.closehead= close-head -m 'Not a head' 0 |
|
47 | 60 | abort: revision is not an open head: 0 |
|
48 | 61 | [255] |
|
49 | 62 | $ hg --config extensions.closehead= close-head -m 'Already closed head' 1 |
|
50 | 63 | abort: revision is not an open head: 1 |
|
51 | 64 | [255] |
|
52 | 65 | |
|
53 | 66 | $ hg init ../test-empty |
|
54 | 67 | $ cd ../test-empty |
|
55 | 68 | $ hg debugbuilddag '+1' |
|
56 | 69 | $ hg log -G --template '{rev}:{node|short}' |
|
57 | 70 | o 0:1ea73414a91b |
|
58 | 71 | |
|
59 | 72 | $ hg --config extensions.closehead= close-head -m 'Close initial revision' 0 |
|
60 | 73 | $ hg heads |
|
61 | 74 | [1] |
General Comments 0
You need to be logged in to leave comments.
Login now