comparison hgext/shelve.py @ 30380:84e8cbdbdee4

shelve: move mutableancestors to not be a closure There's no value in it being a closure and everyone who tries to read the outer function code will be distracted by it. IMO moving it out significantly improves readability, especially given how clear it is what mutableancestors function does from its name.
author Kostia Balytskyi <ikostia@fb.com>
date Thu, 10 Nov 2016 03:24:07 -0800
parents 684068d24658
children caba61934721
comparison
equal deleted inserted replaced
30379:684068d24658 30380:84e8cbdbdee4
271 raise error.Abort(_('shelved change names may not contain slashes')) 271 raise error.Abort(_('shelved change names may not contain slashes'))
272 if name.startswith('.'): 272 if name.startswith('.'):
273 raise error.Abort(_("shelved change names may not start with '.'")) 273 raise error.Abort(_("shelved change names may not start with '.'"))
274 return name 274 return name
275 275
276 def mutableancestors(ctx):
277 """return all mutable ancestors for ctx (included)
278
279 Much faster than the revset ancestors(ctx) & draft()"""
280 seen = set([nodemod.nullrev])
281 visit = collections.deque()
282 visit.append(ctx)
283 while visit:
284 ctx = visit.popleft()
285 yield ctx.node()
286 for parent in ctx.parents():
287 rev = parent.rev()
288 if rev not in seen:
289 seen.add(rev)
290 if parent.mutable():
291 visit.append(parent)
292
276 def _docreatecmd(ui, repo, pats, opts): 293 def _docreatecmd(ui, repo, pats, opts):
277 def mutableancestors(ctx):
278 """return all mutable ancestors for ctx (included)
279
280 Much faster than the revset ancestors(ctx) & draft()"""
281 seen = set([nodemod.nullrev])
282 visit = collections.deque()
283 visit.append(ctx)
284 while visit:
285 ctx = visit.popleft()
286 yield ctx.node()
287 for parent in ctx.parents():
288 rev = parent.rev()
289 if rev not in seen:
290 seen.add(rev)
291 if parent.mutable():
292 visit.append(parent)
293
294 wctx = repo[None] 294 wctx = repo[None]
295 parents = wctx.parents() 295 parents = wctx.parents()
296 if len(parents) > 1: 296 if len(parents) > 1:
297 raise error.Abort(_('cannot shelve while merging')) 297 raise error.Abort(_('cannot shelve while merging'))
298 parent = parents[0] 298 parent = parents[0]