annotate hgext/split.py @ 43283:96eb9ef777a8

run-tests: make code coverage work on Python 3 This code path was obviously not tested on Python 3 because it blew up in several places due to str/bytes mismatch. For internal code, we normalize paths to bytes. For code calling into `coverage`, we normalize paths to str, which is what `coverage` seems to expect. After this, `run-tests.py -H` works on Python 3! Differential Revision: https://phab.mercurial-scm.org/D7133
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 17 Oct 2019 20:40:12 -0700
parents 8ff1ecfadcd1
children 705738def50c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
1 # split.py - split a changeset into smaller ones
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
2 #
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
3 # Copyright 2015 Laurent Charignon <lcharignon@fb.com>
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
4 # Copyright 2017 Facebook, Inc.
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
5 #
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
6 # This software may be used and distributed according to the terms of the
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
7 # GNU General Public License version 2 or any later version.
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
8 """command to split a changeset into smaller ones (EXPERIMENTAL)"""
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
9
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
10 from __future__ import absolute_import
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
11
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
12 from mercurial.i18n import _
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
13
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
14 from mercurial.node import (
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
15 nullid,
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
16 short,
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
17 )
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
18
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
19 from mercurial import (
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
20 bookmarks,
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
21 cmdutil,
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
22 commands,
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
23 error,
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
24 hg,
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
25 obsolete,
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
26 phases,
36400
7b86aa31b004 py3: fix handling of keyword arguments at more places
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35455
diff changeset
27 pycompat,
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
28 registrar,
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
29 revsetlang,
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
30 scmutil,
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
31 )
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
32
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
33 # allow people to use split without explicitly enabling rebase extension
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
34 from . import rebase
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
35
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
36 cmdtable = {}
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
37 command = registrar.command(cmdtable)
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
38
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
39 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
40 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
41 # be specifying the version(s) of Mercurial they are tested with, or
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
42 # leave the attribute unspecified.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
43 testedwith = b'ships-with-hg-core'
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
44
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
45
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
46 @command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
47 b'split',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
48 [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
49 (b'r', b'rev', b'', _(b"revision to split"), _(b'REV')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
50 (b'', b'rebase', True, _(b'rebase descendants after split')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
51 ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
52 + cmdutil.commitopts2,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
53 _(b'hg split [--no-rebase] [[-r] REV]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
54 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
55 helpbasic=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
56 )
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
57 def split(ui, repo, *revs, **opts):
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
58 """split a changeset into smaller ones
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
59
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
60 Repeatedly prompt changes and commit message for new changesets until there
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
61 is nothing left in the original changeset.
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
62
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
63 If --rev was not given, split the working directory parent.
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
64
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
65 By default, rebase connected non-obsoleted descendants onto the new
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
66 changeset. Use --no-rebase to avoid the rebase.
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
67 """
38069
5ba0cf22e4d0 py3: fix kwargs handling in hgext/split.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36408
diff changeset
68 opts = pycompat.byteskwargs(opts)
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
69 revlist = []
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
70 if opts.get(b'rev'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
71 revlist.append(opts.get(b'rev'))
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
72 revlist.extend(revs)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
73 with repo.wlock(), repo.lock(), repo.transaction(b'split') as tr:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
74 revs = scmutil.revrange(repo, revlist or [b'.'])
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
75 if len(revs) > 1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
76 raise error.Abort(_(b'cannot split multiple revisions'))
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
77
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
78 rev = revs.first()
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
79 ctx = repo[rev]
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
80 if rev is None or ctx.node() == nullid:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
81 ui.status(_(b'nothing to split\n'))
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
82 return 1
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
83 if ctx.node() is None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
84 raise error.Abort(_(b'cannot split working directory'))
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
85
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
86 # rewriteutil.precheck is not very useful here because:
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
87 # 1. null check is done above and it's more friendly to return 1
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
88 # instead of abort
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
89 # 2. mergestate check is done below by cmdutil.bailifchanged
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
90 # 3. unstable check is more complex here because of --rebase
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
91 #
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
92 # So only "public" check is useful and it's checked directly here.
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
93 if ctx.phase() == phases.public:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
94 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
95 _(b'cannot split public changeset'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
96 hint=_(b"see 'hg help phases' for details"),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
97 )
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
98
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
99 descendants = list(repo.revs(b'(%d::) - (%d)', rev, rev))
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
100 alloworphaned = obsolete.isenabled(repo, obsolete.allowunstableopt)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
101 if opts.get(b'rebase'):
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
102 # Skip obsoleted descendants and their descendants so the rebase
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
103 # won't cause conflicts for sure.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
104 torebase = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
105 repo.revs(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
106 b'%ld - (%ld & obsolete())::', descendants, descendants
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
107 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
108 )
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
109 if not alloworphaned and len(torebase) != len(descendants):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
110 raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43077
diff changeset
111 _(b'split would leave orphaned changesets behind')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
112 )
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
113 else:
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
114 if not alloworphaned and descendants:
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
115 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
116 _(b'cannot split changeset with children without rebase')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
117 )
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
118 torebase = ()
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
119
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
120 if len(ctx.parents()) > 1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
121 raise error.Abort(_(b'cannot split a merge changeset'))
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
122
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
123 cmdutil.bailifchanged(repo)
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
124
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
125 # Deactivate bookmark temporarily so it won't get moved unintentionally
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
126 bname = repo._activebookmark
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
127 if bname and repo._bookmarks[bname] != ctx.node():
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
128 bookmarks.deactivate(repo)
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
129
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
130 wnode = repo[b'.'].node()
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
131 top = None
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
132 try:
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
133 top = dosplit(ui, repo, tr, ctx, opts)
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
134 finally:
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
135 # top is None: split failed, need update --clean recovery.
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
136 # wnode == ctx.node(): wnode split, no need to update.
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
137 if top is None or wnode != ctx.node():
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
138 hg.clean(repo, wnode, show_stats=False)
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
139 if bname:
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
140 bookmarks.activate(repo, bname)
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
141 if torebase and top:
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
142 dorebase(ui, repo, torebase, top)
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
143
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
144
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
145 def dosplit(ui, repo, tr, ctx, opts):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
146 committed = [] # [ctx]
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
147
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
148 # Set working parent to ctx.p1(), and keep working copy as ctx's content
41966
42e2c7c52e1b split: use the new movedirstate() we now have in scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 40295
diff changeset
149 if ctx.node() != repo.dirstate.p1():
42e2c7c52e1b split: use the new movedirstate() we now have in scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 40295
diff changeset
150 hg.clean(repo, ctx.node(), show_stats=False)
42e2c7c52e1b split: use the new movedirstate() we now have in scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 40295
diff changeset
151 with repo.dirstate.parentchange():
42e2c7c52e1b split: use the new movedirstate() we now have in scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 40295
diff changeset
152 scmutil.movedirstate(repo, ctx.p1())
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
153
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
154 # Any modified, added, removed, deleted result means split is incomplete
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
155 incomplete = lambda repo: any(repo.status()[:4])
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
156
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
157 # Main split loop
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
158 while incomplete(repo):
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
159 if committed:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
160 header = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
161 b'HG: Splitting %s. So far it has been split into:\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
162 ) % short(ctx.node())
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
163 for c in committed:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
164 firstline = c.description().split(b'\n', 1)[0]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
165 header += _(b'HG: - %s: %s\n') % (short(c.node()), firstline)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
166 header += _(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43077
diff changeset
167 b'HG: Write commit message for the next split changeset.\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
168 )
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
169 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
170 header = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
171 b'HG: Splitting %s. Write commit message for the '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
172 b'first split changeset.\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
173 ) % short(ctx.node())
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
174 opts.update(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
175 {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
176 b'edit': True,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
177 b'interactive': True,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
178 b'message': header + ctx.description(),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
179 }
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
180 )
36400
7b86aa31b004 py3: fix handling of keyword arguments at more places
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35455
diff changeset
181 commands.commit(ui, repo, **pycompat.strkwargs(opts))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
182 newctx = repo[b'.']
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
183 committed.append(newctx)
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
184
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
185 if not committed:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
186 raise error.Abort(_(b'cannot split an empty revision'))
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
187
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
188 scmutil.cleanupnodes(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
189 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
190 {ctx.node(): [c.node() for c in committed]},
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
191 operation=b'split',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
192 fixphase=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
193 )
35455
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
194
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
195 return committed[-1]
02ea370c2baa split: new extension to split changesets
Jun Wu <quark@fb.com>
parents:
diff changeset
196
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
197
36408
83bade6206d4 split: use ctx.rev() instead of %d % ctx
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36400
diff changeset
198 def dorebase(ui, repo, src, destctx):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
199 rebase.rebase(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
200 ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
201 repo,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
202 rev=[revsetlang.formatspec(b'%ld', src)],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
203 dest=revsetlang.formatspec(b'%d', destctx.rev()),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41966
diff changeset
204 )