##// END OF EJS Templates
split: close transaction in the unlikely event of a conflict while rebasing...
Martin von Zweigbergk -
r47492:7f6c002d default
parent child Browse files
Show More
@@ -27,6 +27,7 b' from mercurial import ('
27 revsetlang,
27 revsetlang,
28 rewriteutil,
28 rewriteutil,
29 scmutil,
29 scmutil,
30 util,
30 )
31 )
31
32
32 # allow people to use split without explicitly enabling rebase extension
33 # allow people to use split without explicitly enabling rebase extension
@@ -69,57 +70,62 b' def split(ui, repo, *revs, **opts):'
69 if opts.get(b'rev'):
70 if opts.get(b'rev'):
70 revlist.append(opts.get(b'rev'))
71 revlist.append(opts.get(b'rev'))
71 revlist.extend(revs)
72 revlist.extend(revs)
72 with repo.wlock(), repo.lock(), repo.transaction(b'split') as tr:
73 with repo.wlock(), repo.lock():
73 revs = scmutil.revrange(repo, revlist or [b'.'])
74 tr = repo.transaction(b'split')
74 if len(revs) > 1:
75 # If the rebase somehow runs into conflicts, make sure
75 raise error.InputError(_(b'cannot split multiple revisions'))
76 # we close the transaction so the user can continue it.
77 with util.acceptintervention(tr):
78 revs = scmutil.revrange(repo, revlist or [b'.'])
79 if len(revs) > 1:
80 raise error.InputError(_(b'cannot split multiple revisions'))
76
81
77 rev = revs.first()
82 rev = revs.first()
78 ctx = repo[rev]
83 ctx = repo[rev]
79 # Handle nullid specially here (instead of leaving for precheck()
84 # Handle nullid specially here (instead of leaving for precheck()
80 # below) so we get a nicer message and error code.
85 # below) so we get a nicer message and error code.
81 if rev is None or ctx.node() == nullid:
86 if rev is None or ctx.node() == nullid:
82 ui.status(_(b'nothing to split\n'))
87 ui.status(_(b'nothing to split\n'))
83 return 1
88 return 1
84 if ctx.node() is None:
89 if ctx.node() is None:
85 raise error.InputError(_(b'cannot split working directory'))
90 raise error.InputError(_(b'cannot split working directory'))
86
91
87 if opts.get(b'rebase'):
92 if opts.get(b'rebase'):
88 # Skip obsoleted descendants and their descendants so the rebase
93 # Skip obsoleted descendants and their descendants so the rebase
89 # won't cause conflicts for sure.
94 # won't cause conflicts for sure.
90 descendants = list(repo.revs(b'(%d::) - (%d)', rev, rev))
95 descendants = list(repo.revs(b'(%d::) - (%d)', rev, rev))
91 torebase = list(
96 torebase = list(
92 repo.revs(
97 repo.revs(
93 b'%ld - (%ld & obsolete())::', descendants, descendants
98 b'%ld - (%ld & obsolete())::', descendants, descendants
99 )
94 )
100 )
95 )
101 else:
96 else:
102 torebase = []
97 torebase = []
103 rewriteutil.precheck(repo, [rev] + torebase, b'split')
98 rewriteutil.precheck(repo, [rev] + torebase, b'split')
99
104
100 if len(ctx.parents()) > 1:
105 if len(ctx.parents()) > 1:
101 raise error.InputError(_(b'cannot split a merge changeset'))
106 raise error.InputError(_(b'cannot split a merge changeset'))
102
107
103 cmdutil.bailifchanged(repo)
108 cmdutil.bailifchanged(repo)
104
109
105 # Deactivate bookmark temporarily so it won't get moved unintentionally
110 # Deactivate bookmark temporarily so it won't get moved
106 bname = repo._activebookmark
111 # unintentionally
107 if bname and repo._bookmarks[bname] != ctx.node():
112 bname = repo._activebookmark
108 bookmarks.deactivate(repo)
113 if bname and repo._bookmarks[bname] != ctx.node():
114 bookmarks.deactivate(repo)
109
115
110 wnode = repo[b'.'].node()
116 wnode = repo[b'.'].node()
111 top = None
117 top = None
112 try:
118 try:
113 top = dosplit(ui, repo, tr, ctx, opts)
119 top = dosplit(ui, repo, tr, ctx, opts)
114 finally:
120 finally:
115 # top is None: split failed, need update --clean recovery.
121 # top is None: split failed, need update --clean recovery.
116 # wnode == ctx.node(): wnode split, no need to update.
122 # wnode == ctx.node(): wnode split, no need to update.
117 if top is None or wnode != ctx.node():
123 if top is None or wnode != ctx.node():
118 hg.clean(repo, wnode, show_stats=False)
124 hg.clean(repo, wnode, show_stats=False)
119 if bname:
125 if bname:
120 bookmarks.activate(repo, bname)
126 bookmarks.activate(repo, bname)
121 if torebase and top:
127 if torebase and top:
122 dorebase(ui, repo, torebase, top)
128 dorebase(ui, repo, torebase, top)
123
129
124
130
125 def dosplit(ui, repo, tr, ctx, opts):
131 def dosplit(ui, repo, tr, ctx, opts):
General Comments 0
You need to be logged in to leave comments. Login now