Mercurial > evolve
comparison hgext/evolve.py @ 1316:f11363699766
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.
author | Laurent Charignon <lcharignon@fb.com> |
---|---|
date | Mon, 04 May 2015 16:01:45 -0700 |
parents | 445d7f46f25d |
children | 48f78feb0b47 |
comparison
equal
deleted
inserted
replaced
1315:445d7f46f25d | 1316:f11363699766 |
---|---|
1150 median = len(allpclusters[nbcluster//2][1]) | 1150 median = len(allpclusters[nbcluster//2][1]) |
1151 ui.write(' median length: %9i\n' % median) | 1151 ui.write(' median length: %9i\n' % median) |
1152 mean = sum(len(x[1]) for x in allpclusters) // nbcluster | 1152 mean = sum(len(x[1]) for x in allpclusters) // nbcluster |
1153 ui.write(' mean length: %9i\n' % mean) | 1153 ui.write(' mean length: %9i\n' % mean) |
1154 | 1154 |
1155 def handlenotrouble(ui, repo, startnode, dryrunopt): | |
1156 if repo['.'].obsolete(): | |
1157 displayer = cmdutil.show_changeset( | |
1158 ui, repo, {'template': shorttemplate}) | |
1159 successors = set() | |
1160 | |
1161 for successorsset in obsolete.successorssets(repo, repo['.'].node()): | |
1162 for nodeid in successorsset: | |
1163 successors.add(repo[nodeid]) | |
1164 | |
1165 if not successors: | |
1166 ui.warn(_('parent is obsolete without successors; ' + | |
1167 'likely killed\n')) | |
1168 return 2 | |
1169 | |
1170 elif len(successors) > 1: | |
1171 ui.warn(_('parent is obsolete with multiple successors:\n')) | |
1172 | |
1173 for ctx in sorted(successors, key=lambda ctx: ctx.rev()): | |
1174 displayer.show(ctx) | |
1175 | |
1176 return 2 | |
1177 | |
1178 else: | |
1179 ctx = successors.pop() | |
1180 | |
1181 ui.status(_('update:')) | |
1182 if not ui.quiet: | |
1183 displayer.show(ctx) | |
1184 | |
1185 if dryrunopt: | |
1186 return 0 | |
1187 else: | |
1188 res = hg.update(repo, ctx.rev()) | |
1189 if ctx != startnode: | |
1190 ui.status(_('working directory is now at %s\n') % ctx) | |
1191 return res | |
1192 | |
1193 troubled = repo.revs('troubled()') | |
1194 if troubled: | |
1195 ui.write_err(_('nothing to evolve here\n')) | |
1196 ui.status(_('(%i troubled changesets, do you want --any ?)\n') | |
1197 % len(troubled)) | |
1198 return 2 | |
1199 else: | |
1200 ui.write_err(_('no troubled changesets\n')) | |
1201 return 1 | |
1155 @command('^evolve|stabilize|solve', | 1202 @command('^evolve|stabilize|solve', |
1156 [('n', 'dry-run', False, | 1203 [('n', 'dry-run', False, |
1157 'do not perform actions, just print what would be done'), | 1204 'do not perform actions, just print what would be done'), |
1158 ('', 'confirm', False, | 1205 ('', 'confirm', False, |
1159 'ask for confirmation before performing the action'), | 1206 'ask for confirmation before performing the action'), |
1205 graftcmd = commands.table['graft'][0] | 1252 graftcmd = commands.table['graft'][0] |
1206 return graftcmd(ui, repo, old_obsolete=True, **{'continue': True}) | 1253 return graftcmd(ui, repo, old_obsolete=True, **{'continue': True}) |
1207 | 1254 |
1208 tro = _picknexttroubled(ui, repo, anyopt or allopt) | 1255 tro = _picknexttroubled(ui, repo, anyopt or allopt) |
1209 if tro is None: | 1256 if tro is None: |
1210 if repo['.'].obsolete(): | 1257 return handlenotrouble(ui, repo, startnode, dryrunopt) |
1211 displayer = cmdutil.show_changeset( | |
1212 ui, repo, {'template': shorttemplate}) | |
1213 successors = set() | |
1214 | |
1215 for successorsset in obsolete.successorssets(repo, repo['.'].node()): | |
1216 for nodeid in successorsset: | |
1217 successors.add(repo[nodeid]) | |
1218 | |
1219 if not successors: | |
1220 ui.warn(_('parent is obsolete without successors; ' + | |
1221 'likely killed\n')) | |
1222 return 2 | |
1223 | |
1224 elif len(successors) > 1: | |
1225 ui.warn(_('parent is obsolete with multiple successors:\n')) | |
1226 | |
1227 for ctx in sorted(successors, key=lambda ctx: ctx.rev()): | |
1228 displayer.show(ctx) | |
1229 | |
1230 return 2 | |
1231 | |
1232 else: | |
1233 ctx = successors.pop() | |
1234 | |
1235 ui.status(_('update:')) | |
1236 if not ui.quiet: | |
1237 displayer.show(ctx) | |
1238 | |
1239 if dryrunopt: | |
1240 return 0 | |
1241 else: | |
1242 res = hg.update(repo, ctx.rev()) | |
1243 if ctx != startnode: | |
1244 ui.status(_('working directory is now at %s\n') % ctx) | |
1245 return res | |
1246 | |
1247 troubled = repo.revs('troubled()') | |
1248 if troubled: | |
1249 ui.write_err(_('nothing to evolve here\n')) | |
1250 ui.status(_('(%i troubled changesets, do you want --any ?)\n') | |
1251 % len(troubled)) | |
1252 return 2 | |
1253 else: | |
1254 ui.write_err(_('no troubled changesets\n')) | |
1255 return 1 | |
1256 | 1258 |
1257 def progresscb(): | 1259 def progresscb(): |
1258 if allopt: | 1260 if allopt: |
1259 ui.progress('evolve', seen, unit='changesets', total=count) | 1261 ui.progress('evolve', seen, unit='changesets', total=count) |
1262 | |
1260 seen = 1 | 1263 seen = 1 |
1261 count = allopt and _counttroubled(ui, repo) or 1 | 1264 count = allopt and _counttroubled(ui, repo) or 1 |
1262 | 1265 |
1263 while tro is not None: | 1266 while tro is not None: |
1264 progresscb() | 1267 progresscb() |