comparison mercurial/dagparser.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents e7aa113b14f7
children 687b865b95ad
comparison
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
13 from .i18n import _ 13 from .i18n import _
14 from . import ( 14 from . import (
15 error, 15 error,
16 pycompat, 16 pycompat,
17 ) 17 )
18 from .utils import ( 18 from .utils import stringutil
19 stringutil, 19
20 )
21 20
22 def parsedag(desc): 21 def parsedag(desc):
23 '''parses a DAG from a concise textual description; generates events 22 '''parses a DAG from a concise textual description; generates events
24 23
25 "+n" is a linear run of n nodes based on the current default parent 24 "+n" is a linear run of n nodes based on the current default parent
265 c = nextch() 264 c = nextch()
266 elif c == '$': 265 elif c == '$':
267 p1 = -1 266 p1 = -1
268 c = nextch() 267 c = nextch()
269 elif c == '\0': 268 elif c == '\0':
270 return # in case it was preceded by whitespace 269 return # in case it was preceded by whitespace
271 else: 270 else:
272 s = '' 271 s = ''
273 i = 0 272 i = 0
274 while c != '\0' and i < 10: 273 while c != '\0' and i < 10:
275 s += c 274 s += c
276 i += 1 275 i += 1
277 c = nextch() 276 c = nextch()
278 raise error.Abort(_('invalid character in dag description: ' 277 raise error.Abort(
279 '%s...') % s) 278 _('invalid character in dag description: ' '%s...') % s
280 279 )
281 def dagtextlines(events, 280
282 addspaces=True, 281
283 wraplabels=False, 282 def dagtextlines(
284 wrapannotations=False, 283 events,
285 wrapcommands=False, 284 addspaces=True,
286 wrapnonlinear=False, 285 wraplabels=False,
287 usedots=False, 286 wrapannotations=False,
288 maxlinewidth=70): 287 wrapcommands=False,
288 wrapnonlinear=False,
289 usedots=False,
290 maxlinewidth=70,
291 ):
289 '''generates single lines for dagtext()''' 292 '''generates single lines for dagtext()'''
290 293
291 def wrapstring(text): 294 def wrapstring(text):
292 if re.match("^[0-9a-z]*$", text): 295 if re.match("^[0-9a-z]*$", text):
293 return text 296 return text
308 if not ps: 311 if not ps:
309 ps = [-1] 312 ps = [-1]
310 else: 313 else:
311 for p in ps: 314 for p in ps:
312 if p >= r: 315 if p >= r:
313 raise error.Abort(_("parent id %i is larger than " 316 raise error.Abort(
314 "current id %i") % (p, r)) 317 _(
318 "parent id %i is larger than "
319 "current id %i"
320 )
321 % (p, r)
322 )
315 wantr += 1 323 wantr += 1
316 324
317 # new root? 325 # new root?
318 p1 = r - 1 326 p1 = r - 1
319 if len(ps) == 1 and ps[0] == -1: 327 if len(ps) == 1 and ps[0] == -1:
370 yield '@' + wrapstring(data) 378 yield '@' + wrapstring(data)
371 elif kind == '#': 379 elif kind == '#':
372 yield '#' + data 380 yield '#' + data
373 yield '\n' 381 yield '\n'
374 else: 382 else:
375 raise error.Abort(_("invalid event type in dag: " 383 raise error.Abort(
376 "('%s', '%s')") 384 _("invalid event type in dag: " "('%s', '%s')")
377 % (stringutil.escapestr(kind), 385 % (
378 stringutil.escapestr(data))) 386 stringutil.escapestr(kind),
387 stringutil.escapestr(data),
388 )
389 )
379 if run: 390 if run:
380 yield '+%d' % run 391 yield '+%d' % run
381 392
382 line = '' 393 line = ''
383 for part in gen(): 394 for part in gen():
393 line += ' ' 404 line += ' '
394 line += part 405 line += part
395 if line: 406 if line:
396 yield line 407 yield line
397 408
398 def dagtext(dag, 409
399 addspaces=True, 410 def dagtext(
400 wraplabels=False, 411 dag,
401 wrapannotations=False, 412 addspaces=True,
402 wrapcommands=False, 413 wraplabels=False,
403 wrapnonlinear=False, 414 wrapannotations=False,
404 usedots=False, 415 wrapcommands=False,
405 maxlinewidth=70): 416 wrapnonlinear=False,
417 usedots=False,
418 maxlinewidth=70,
419 ):
406 '''generates lines of a textual representation for a dag event stream 420 '''generates lines of a textual representation for a dag event stream
407 421
408 events should generate what parsedag() does, so: 422 events should generate what parsedag() does, so:
409 423
410 ('n', (id, [parentids])) for node creation 424 ('n', (id, [parentids])) for node creation
478 492
479 >>> dagtext(parsedag(b'+1 :f +1 :p2 *f */p2')) 493 >>> dagtext(parsedag(b'+1 :f +1 :p2 *f */p2'))
480 '+1 :f +1 :p2 *f */p2' 494 '+1 :f +1 :p2 *f */p2'
481 495
482 ''' 496 '''
483 return "\n".join(dagtextlines(dag, 497 return "\n".join(
484 addspaces, 498 dagtextlines(
485 wraplabels, 499 dag,
486 wrapannotations, 500 addspaces,
487 wrapcommands, 501 wraplabels,
488 wrapnonlinear, 502 wrapannotations,
489 usedots, 503 wrapcommands,
490 maxlinewidth)) 504 wrapnonlinear,
505 usedots,
506 maxlinewidth,
507 )
508 )