comparison hgext/rebase.py @ 26671:66dc39cd7d06

rebase: factor out nothing to rebase return code A rebase call that results in nothing to rebase might be considered successful in some contexts. This factors out the return code from places where hg determines that there is nothing to rebase, so an extenion might change this return code to be something that would allow scripts to run without seeing this as an error.
author Ryan McElroy <rmcelroy@fb.com>
date Tue, 13 Oct 2015 03:20:05 -0700
parents 07db7e95c464
children fd4a38bd7e49
comparison
equal deleted inserted replaced
26670:ab2cd800f1b0 26671:66dc39cd7d06
38 # Note for extension authors: ONLY specify testedwith = 'internal' for 38 # Note for extension authors: ONLY specify testedwith = 'internal' for
39 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should 39 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
40 # be specifying the version(s) of Mercurial they are tested with, or 40 # be specifying the version(s) of Mercurial they are tested with, or
41 # leave the attribute unspecified. 41 # leave the attribute unspecified.
42 testedwith = 'internal' 42 testedwith = 'internal'
43
44 def _nothingtorebase():
45 return 1
43 46
44 def _savegraft(ctx, extra): 47 def _savegraft(ctx, extra):
45 s = ctx.extra().get('source', None) 48 s = ctx.extra().get('source', None)
46 if s is not None: 49 if s is not None:
47 extra['source'] = s 50 extra['source'] = s
288 if revf: 291 if revf:
289 rebaseset = scmutil.revrange(repo, revf) 292 rebaseset = scmutil.revrange(repo, revf)
290 if not rebaseset: 293 if not rebaseset:
291 ui.status(_('empty "rev" revision set - ' 294 ui.status(_('empty "rev" revision set - '
292 'nothing to rebase\n')) 295 'nothing to rebase\n'))
293 return 1 296 return _nothingtorebase()
294 elif srcf: 297 elif srcf:
295 src = scmutil.revrange(repo, [srcf]) 298 src = scmutil.revrange(repo, [srcf])
296 if not src: 299 if not src:
297 ui.status(_('empty "source" revision set - ' 300 ui.status(_('empty "source" revision set - '
298 'nothing to rebase\n')) 301 'nothing to rebase\n'))
299 return 1 302 return _nothingtorebase()
300 rebaseset = repo.revs('(%ld)::', src) 303 rebaseset = repo.revs('(%ld)::', src)
301 assert rebaseset 304 assert rebaseset
302 else: 305 else:
303 base = scmutil.revrange(repo, [basef or '.']) 306 base = scmutil.revrange(repo, [basef or '.'])
304 if not base: 307 if not base:
305 ui.status(_('empty "base" revision set - ' 308 ui.status(_('empty "base" revision set - '
306 "can't compute rebase set\n")) 309 "can't compute rebase set\n"))
307 return 1 310 return _nothingtorebase()
308 commonanc = repo.revs('ancestor(%ld, %d)', base, dest).first() 311 commonanc = repo.revs('ancestor(%ld, %d)', base, dest).first()
309 if commonanc is not None: 312 if commonanc is not None:
310 rebaseset = repo.revs('(%d::(%ld) - %d)::', 313 rebaseset = repo.revs('(%d::(%ld) - %d)::',
311 commonanc, base, commonanc) 314 commonanc, base, commonanc)
312 else: 315 else:
335 'directory parent is already an ' 338 'directory parent is already an '
336 'ancestor of destination %s\n') % dest) 339 'ancestor of destination %s\n') % dest)
337 else: # can it happen? 340 else: # can it happen?
338 ui.status(_('nothing to rebase from %s to %s\n') % 341 ui.status(_('nothing to rebase from %s to %s\n') %
339 ('+'.join(str(repo[r]) for r in base), dest)) 342 ('+'.join(str(repo[r]) for r in base), dest))
340 return 1 343 return _nothingtorebase()
341 344
342 allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt) 345 allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt)
343 if (not (keepf or allowunstable) 346 if (not (keepf or allowunstable)
344 and repo.revs('first(children(%ld) - %ld)', 347 and repo.revs('first(children(%ld) - %ld)',
345 rebaseset, rebaseset)): 348 rebaseset, rebaseset)):
363 obsoletenotrebased) 366 obsoletenotrebased)
364 367
365 if not result: 368 if not result:
366 # Empty state built, nothing to rebase 369 # Empty state built, nothing to rebase
367 ui.status(_('nothing to rebase\n')) 370 ui.status(_('nothing to rebase\n'))
368 return 1 371 return _nothingtorebase()
369 372
370 root = min(rebaseset) 373 root = min(rebaseset)
371 if not keepf and not repo[root].mutable(): 374 if not keepf and not repo[root].mutable():
372 raise error.Abort(_("can't rebase public changeset %s") 375 raise error.Abort(_("can't rebase public changeset %s")
373 % repo[root], 376 % repo[root],