# HG changeset patch # User Laurent Charignon # Date 1430780505 25200 # Node ID f113636997660b807c36cf1d0a06b76d53ada1a4 # Parent 445d7f46f25dad1d5893b47b21140572159823fa evolve: refactoring of the code displaying error when no trouble found Before this patch, we had many return statements in the evolve function especially in the part in charge of displaying errors when no troubles were found. We move this code in a separate function. diff -r 445d7f46f25d -r f11363699766 hgext/evolve.py --- a/hgext/evolve.py Thu Apr 30 15:11:00 2015 -0700 +++ b/hgext/evolve.py Mon May 04 16:01:45 2015 -0700 @@ -1152,6 +1152,53 @@ mean = sum(len(x[1]) for x in allpclusters) // nbcluster ui.write(' mean length: %9i\n' % mean) +def handlenotrouble(ui, repo, startnode, dryrunopt): + if repo['.'].obsolete(): + displayer = cmdutil.show_changeset( + ui, repo, {'template': shorttemplate}) + successors = set() + + for successorsset in obsolete.successorssets(repo, repo['.'].node()): + for nodeid in successorsset: + successors.add(repo[nodeid]) + + if not successors: + ui.warn(_('parent is obsolete without successors; ' + + 'likely killed\n')) + return 2 + + elif len(successors) > 1: + ui.warn(_('parent is obsolete with multiple successors:\n')) + + for ctx in sorted(successors, key=lambda ctx: ctx.rev()): + displayer.show(ctx) + + return 2 + + else: + ctx = successors.pop() + + ui.status(_('update:')) + if not ui.quiet: + displayer.show(ctx) + + if dryrunopt: + return 0 + else: + res = hg.update(repo, ctx.rev()) + if ctx != startnode: + ui.status(_('working directory is now at %s\n') % ctx) + return res + + troubled = repo.revs('troubled()') + if troubled: + ui.write_err(_('nothing to evolve here\n')) + ui.status(_('(%i troubled changesets, do you want --any ?)\n') + % len(troubled)) + return 2 + else: + ui.write_err(_('no troubled changesets\n')) + return 1 @command('^evolve|stabilize|solve', [('n', 'dry-run', False, 'do not perform actions, just print what would be done'), @@ -1207,56 +1254,12 @@ tro = _picknexttroubled(ui, repo, anyopt or allopt) if tro is None: - if repo['.'].obsolete(): - displayer = cmdutil.show_changeset( - ui, repo, {'template': shorttemplate}) - successors = set() - - for successorsset in obsolete.successorssets(repo, repo['.'].node()): - for nodeid in successorsset: - successors.add(repo[nodeid]) - - if not successors: - ui.warn(_('parent is obsolete without successors; ' + - 'likely killed\n')) - return 2 - - elif len(successors) > 1: - ui.warn(_('parent is obsolete with multiple successors:\n')) - - for ctx in sorted(successors, key=lambda ctx: ctx.rev()): - displayer.show(ctx) - - return 2 - - else: - ctx = successors.pop() - - ui.status(_('update:')) - if not ui.quiet: - displayer.show(ctx) - - if dryrunopt: - return 0 - else: - res = hg.update(repo, ctx.rev()) - if ctx != startnode: - ui.status(_('working directory is now at %s\n') % ctx) - return res - - troubled = repo.revs('troubled()') - if troubled: - ui.write_err(_('nothing to evolve here\n')) - ui.status(_('(%i troubled changesets, do you want --any ?)\n') - % len(troubled)) - return 2 - else: - ui.write_err(_('no troubled changesets\n')) - return 1 + return handlenotrouble(ui, repo, startnode, dryrunopt) def progresscb(): if allopt: ui.progress('evolve', seen, unit='changesets', total=count) + seen = 1 count = allopt and _counttroubled(ui, repo) or 1