equal
deleted
inserted
replaced
20 cmdutil, |
20 cmdutil, |
21 commands, |
21 commands, |
22 error, |
22 error, |
23 hg, |
23 hg, |
24 logcmdutil, |
24 logcmdutil, |
25 pycompat, |
|
26 registrar, |
25 registrar, |
27 revsetlang, |
26 revsetlang, |
28 rewriteutil, |
27 rewriteutil, |
29 scmutil, |
28 scmutil, |
30 util, |
29 util, |
63 If --rev was not given, split the working directory parent. |
62 If --rev was not given, split the working directory parent. |
64 |
63 |
65 By default, rebase connected non-obsoleted descendants onto the new |
64 By default, rebase connected non-obsoleted descendants onto the new |
66 changeset. Use --no-rebase to avoid the rebase. |
65 changeset. Use --no-rebase to avoid the rebase. |
67 """ |
66 """ |
68 opts = pycompat.byteskwargs(opts) |
|
69 revlist = [] |
67 revlist = [] |
70 if opts.get(b'rev'): |
68 if opts.get('rev'): |
71 revlist.append(opts.get(b'rev')) |
69 revlist.append(opts.get('rev')) |
72 revlist.extend(revs) |
70 revlist.extend(revs) |
73 with repo.wlock(), repo.lock(): |
71 with repo.wlock(), repo.lock(): |
74 tr = repo.transaction(b'split') |
72 tr = repo.transaction(b'split') |
75 # If the rebase somehow runs into conflicts, make sure |
73 # If the rebase somehow runs into conflicts, make sure |
76 # we close the transaction so the user can continue it. |
74 # we close the transaction so the user can continue it. |
87 return 1 |
85 return 1 |
88 ctx = repo[rev] |
86 ctx = repo[rev] |
89 if ctx.node() is None: |
87 if ctx.node() is None: |
90 raise error.InputError(_(b'cannot split working directory')) |
88 raise error.InputError(_(b'cannot split working directory')) |
91 |
89 |
92 if opts.get(b'rebase'): |
90 if opts.get('rebase'): |
93 # Skip obsoleted descendants and their descendants so the rebase |
91 # Skip obsoleted descendants and their descendants so the rebase |
94 # won't cause conflicts for sure. |
92 # won't cause conflicts for sure. |
95 descendants = list(repo.revs(b'(%d::) - (%d)', rev, rev)) |
93 descendants = list(repo.revs(b'(%d::) - (%d)', rev, rev)) |
96 torebase = list( |
94 torebase = list( |
97 repo.revs( |
95 repo.revs( |
114 bookmarks.deactivate(repo) |
112 bookmarks.deactivate(repo) |
115 |
113 |
116 wnode = repo[b'.'].node() |
114 wnode = repo[b'.'].node() |
117 top = None |
115 top = None |
118 try: |
116 try: |
119 top = dosplit(ui, repo, tr, ctx, opts) |
117 top = dosplit(ui, repo, tr, ctx, **opts) |
120 finally: |
118 finally: |
121 # top is None: split failed, need update --clean recovery. |
119 # top is None: split failed, need update --clean recovery. |
122 # wnode == ctx.node(): wnode split, no need to update. |
120 # wnode == ctx.node(): wnode split, no need to update. |
123 if top is None or wnode != ctx.node(): |
121 if top is None or wnode != ctx.node(): |
124 hg.clean(repo, wnode, show_stats=False) |
122 hg.clean(repo, wnode, show_stats=False) |
126 bookmarks.activate(repo, bname) |
124 bookmarks.activate(repo, bname) |
127 if torebase and top: |
125 if torebase and top: |
128 dorebase(ui, repo, torebase, top) |
126 dorebase(ui, repo, torebase, top) |
129 |
127 |
130 |
128 |
131 def dosplit(ui, repo, tr, ctx, opts): |
129 def dosplit(ui, repo, tr, ctx, **opts): |
132 committed = [] # [ctx] |
130 committed = [] # [ctx] |
133 |
131 |
134 # Set working parent to ctx.p1(), and keep working copy as ctx's content |
132 # Set working parent to ctx.p1(), and keep working copy as ctx's content |
135 if ctx.node() != repo.dirstate.p1(): |
133 if ctx.node() != repo.dirstate.p1(): |
136 hg.clean(repo, ctx.node(), show_stats=False) |
134 hg.clean(repo, ctx.node(), show_stats=False) |
164 b'HG: Splitting %s. Write commit message for the ' |
162 b'HG: Splitting %s. Write commit message for the ' |
165 b'first split changeset.\n' |
163 b'first split changeset.\n' |
166 ) % short(ctx.node()) |
164 ) % short(ctx.node()) |
167 opts.update( |
165 opts.update( |
168 { |
166 { |
169 b'edit': True, |
167 'edit': True, |
170 b'interactive': True, |
168 'interactive': True, |
171 b'message': header + ctx.description(), |
169 'message': header + ctx.description(), |
172 } |
170 } |
173 ) |
171 ) |
174 origctx = repo[b'.'] |
172 origctx = repo[b'.'] |
175 commands.commit(ui, repo, **pycompat.strkwargs(opts)) |
173 commands.commit(ui, repo, **opts) |
176 newctx = repo[b'.'] |
174 newctx = repo[b'.'] |
177 # Ensure user didn't do a "no-op" split (such as deselecting |
175 # Ensure user didn't do a "no-op" split (such as deselecting |
178 # everything). |
176 # everything). |
179 if origctx.node() != newctx.node(): |
177 if origctx.node() != newctx.node(): |
180 committed.append(newctx) |
178 committed.append(newctx) |