Mercurial > hg
comparison hgext/rebase.py @ 11205:d26f662bfbf5
rebase: add error codes
Suggested by Dirk Hasselbalch
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 20 May 2010 15:58:16 -0500 |
parents | 54e93b86a9e3 |
children | f118029e534c |
comparison
equal
deleted
inserted
replaced
11204:54e93b86a9e3 | 11205:d26f662bfbf5 |
---|---|
67 destination (or ``update`` to the other head, if it's the head of | 67 destination (or ``update`` to the other head, if it's the head of |
68 the intended source branch). | 68 the intended source branch). |
69 | 69 |
70 If a rebase is interrupted to manually resolve a merge, it can be | 70 If a rebase is interrupted to manually resolve a merge, it can be |
71 continued with --continue/-c or aborted with --abort/-a. | 71 continued with --continue/-c or aborted with --abort/-a. |
72 | |
73 Returns 0 on success, 1 if nothing to rebase. | |
72 """ | 74 """ |
73 originalwd = target = None | 75 originalwd = target = None |
74 external = nullrev | 76 external = nullrev |
75 state = {} | 77 state = {} |
76 skipped = set() | 78 skipped = set() |
113 _('abort and continue do not allow specifying revisions')) | 115 _('abort and continue do not allow specifying revisions')) |
114 | 116 |
115 (originalwd, target, state, collapsef, keepf, | 117 (originalwd, target, state, collapsef, keepf, |
116 keepbranchesf, external) = restorestatus(repo) | 118 keepbranchesf, external) = restorestatus(repo) |
117 if abortf: | 119 if abortf: |
118 abort(repo, originalwd, target, state) | 120 return abort(repo, originalwd, target, state) |
119 return | |
120 else: | 121 else: |
121 if srcf and basef: | 122 if srcf and basef: |
122 raise error.ParseError('rebase', _('cannot specify both a ' | 123 raise error.ParseError('rebase', _('cannot specify both a ' |
123 'revision and a base')) | 124 'revision and a base')) |
124 if detachf: | 125 if detachf: |
132 cmdutil.bail_if_changed(repo) | 133 cmdutil.bail_if_changed(repo) |
133 result = buildstate(repo, destf, srcf, basef, detachf) | 134 result = buildstate(repo, destf, srcf, basef, detachf) |
134 if not result: | 135 if not result: |
135 # Empty state built, nothing to rebase | 136 # Empty state built, nothing to rebase |
136 ui.status(_('nothing to rebase\n')) | 137 ui.status(_('nothing to rebase\n')) |
137 return | 138 return 1 |
138 else: | 139 else: |
139 originalwd, target, state = result | 140 originalwd, target, state = result |
140 if collapsef: | 141 if collapsef: |
141 targetancestors = set(repo.changelog.ancestors(target)) | 142 targetancestors = set(repo.changelog.ancestors(target)) |
142 external = checkexternal(repo, state, targetancestors) | 143 external = checkexternal(repo, state, targetancestors) |
426 def abort(repo, originalwd, target, state): | 427 def abort(repo, originalwd, target, state): |
427 'Restore the repository to its original state' | 428 'Restore the repository to its original state' |
428 if set(repo.changelog.descendants(target)) - set(state.values()): | 429 if set(repo.changelog.descendants(target)) - set(state.values()): |
429 repo.ui.warn(_("warning: new changesets detected on target branch, " | 430 repo.ui.warn(_("warning: new changesets detected on target branch, " |
430 "can't abort\n")) | 431 "can't abort\n")) |
432 return -1 | |
431 else: | 433 else: |
432 # Strip from the first rebased revision | 434 # Strip from the first rebased revision |
433 merge.update(repo, repo[originalwd].rev(), False, True, False) | 435 merge.update(repo, repo[originalwd].rev(), False, True, False) |
434 rebased = filter(lambda x: x > -1, state.values()) | 436 rebased = filter(lambda x: x > -1, state.values()) |
435 if rebased: | 437 if rebased: |
436 strippoint = min(rebased) | 438 strippoint = min(rebased) |
437 # no backup of rebased cset versions needed | 439 # no backup of rebased cset versions needed |
438 repair.strip(repo.ui, repo, repo[strippoint].node()) | 440 repair.strip(repo.ui, repo, repo[strippoint].node()) |
439 clearstatus(repo) | 441 clearstatus(repo) |
440 repo.ui.status(_('rebase aborted\n')) | 442 repo.ui.status(_('rebase aborted\n')) |
443 return 0 | |
441 | 444 |
442 def buildstate(repo, dest, src, base, detach): | 445 def buildstate(repo, dest, src, base, detach): |
443 'Define which revisions are going to be rebased and where' | 446 'Define which revisions are going to be rebased and where' |
444 targetancestors = set() | 447 targetancestors = set() |
445 detachset = set() | 448 detachset = set() |