Show More
@@ -2314,6 +2314,23 b' def _matchonly(revs, bases):' | |||||
2314 | and getsymbol(bases[1][1]) == 'ancestors'): |
|
2314 | and getsymbol(bases[1][1]) == 'ancestors'): | |
2315 | return ('list', revs[2], bases[1][2]) |
|
2315 | return ('list', revs[2], bases[1][2]) | |
2316 |
|
2316 | |||
|
2317 | def _fixops(x): | |||
|
2318 | """Rewrite raw parsed tree to resolve ambiguous syntax which cannot be | |||
|
2319 | handled well by our simple top-down parser""" | |||
|
2320 | if not isinstance(x, tuple): | |||
|
2321 | return x | |||
|
2322 | ||||
|
2323 | op = x[0] | |||
|
2324 | if op == 'parent': | |||
|
2325 | # x^:y means (x^) : y, not x ^ (:y) | |||
|
2326 | post = ('parentpost', x[1]) | |||
|
2327 | if x[2][0] == 'dagrangepre': | |||
|
2328 | return _fixops(('dagrange', post, x[2][1])) | |||
|
2329 | elif x[2][0] == 'rangepre': | |||
|
2330 | return _fixops(('range', post, x[2][1])) | |||
|
2331 | ||||
|
2332 | return (op,) + tuple(_fixops(y) for y in x[1:]) | |||
|
2333 | ||||
2317 | def _optimize(x, small): |
|
2334 | def _optimize(x, small): | |
2318 | if x is None: |
|
2335 | if x is None: | |
2319 | return 0, x |
|
2336 | return 0, x | |
@@ -2407,14 +2424,6 b' def _optimize(x, small):' | |||||
2407 | elif op == 'group': |
|
2424 | elif op == 'group': | |
2408 | return _optimize(x[1], small) |
|
2425 | return _optimize(x[1], small) | |
2409 | elif op in 'dagrange range parent ancestorspec': |
|
2426 | elif op in 'dagrange range parent ancestorspec': | |
2410 | if op == 'parent': |
|
|||
2411 | # x^:y means (x^) : y, not x ^ (:y) |
|
|||
2412 | post = ('parentpost', x[1]) |
|
|||
2413 | if x[2][0] == 'dagrangepre': |
|
|||
2414 | return _optimize(('dagrange', post, x[2][1]), small) |
|
|||
2415 | elif x[2][0] == 'rangepre': |
|
|||
2416 | return _optimize(('range', post, x[2][1]), small) |
|
|||
2417 |
|
||||
2418 | wa, ta = _optimize(x[1], small) |
|
2427 | wa, ta = _optimize(x[1], small) | |
2419 | wb, tb = _optimize(x[2], small) |
|
2428 | wb, tb = _optimize(x[2], small) | |
2420 | return wa + wb, (op, ta, tb) |
|
2429 | return wa + wb, (op, ta, tb) | |
@@ -2470,7 +2479,7 b' def _parsewith(spec, lookup=None, symini' | |||||
2470 | syminitletters=syminitletters)) |
|
2479 | syminitletters=syminitletters)) | |
2471 | if pos != len(spec): |
|
2480 | if pos != len(spec): | |
2472 | raise error.ParseError(_('invalid token'), pos) |
|
2481 | raise error.ParseError(_('invalid token'), pos) | |
2473 | return parser.simplifyinfixops(tree, ('list', 'or')) |
|
2482 | return _fixops(parser.simplifyinfixops(tree, ('list', 'or'))) | |
2474 |
|
2483 | |||
2475 | class _aliasrules(parser.basealiasrules): |
|
2484 | class _aliasrules(parser.basealiasrules): | |
2476 | """Parsing and expansion rule set of revset aliases""" |
|
2485 | """Parsing and expansion rule set of revset aliases""" |
@@ -482,12 +482,7 b' infix/suffix resolution of ^ operator (i' | |||||
482 |
|
482 | |||
483 | x^:y means (x^):y |
|
483 | x^:y means (x^):y | |
484 |
|
484 | |||
485 |
$ try |
|
485 | $ try '1^:2' | |
486 | (parent |
|
|||
487 | ('symbol', '1') |
|
|||
488 | (rangepre |
|
|||
489 | ('symbol', '2'))) |
|
|||
490 | * optimized: |
|
|||
491 | (range |
|
486 | (range | |
492 | (parentpost |
|
487 | (parentpost | |
493 | ('symbol', '1')) |
|
488 | ('symbol', '1')) | |
@@ -498,12 +493,7 b' infix/suffix resolution of ^ operator (i' | |||||
498 | 1 |
|
493 | 1 | |
499 | 2 |
|
494 | 2 | |
500 |
|
495 | |||
501 |
$ try |
|
496 | $ try '1^::2' | |
502 | (parent |
|
|||
503 | ('symbol', '1') |
|
|||
504 | (dagrangepre |
|
|||
505 | ('symbol', '2'))) |
|
|||
506 | * optimized: |
|
|||
507 | (dagrange |
|
497 | (dagrange | |
508 | (parentpost |
|
498 | (parentpost | |
509 | ('symbol', '1')) |
|
499 | ('symbol', '1')) | |
@@ -516,31 +506,18 b' infix/suffix resolution of ^ operator (i' | |||||
516 |
|
506 | |||
517 | x^:y should be resolved before omitting group operators |
|
507 | x^:y should be resolved before omitting group operators | |
518 |
|
508 | |||
519 |
$ try |
|
509 | $ try '1^(:2)' | |
520 | (parent |
|
510 | (parent | |
521 | ('symbol', '1') |
|
511 | ('symbol', '1') | |
522 | (group |
|
512 | (group | |
523 | (rangepre |
|
513 | (rangepre | |
524 | ('symbol', '2')))) |
|
514 | ('symbol', '2')))) | |
525 | * optimized: |
|
|||
526 | (parent |
|
|||
527 | ('symbol', '1') |
|
|||
528 | (range |
|
|||
529 | ('string', '0') |
|
|||
530 | ('symbol', '2'))) |
|
|||
531 | hg: parse error: ^ expects a number 0, 1, or 2 |
|
515 | hg: parse error: ^ expects a number 0, 1, or 2 | |
532 | [255] |
|
516 | [255] | |
533 |
|
517 | |||
534 | x^:y should be resolved recursively |
|
518 | x^:y should be resolved recursively | |
535 |
|
519 | |||
536 |
$ try |
|
520 | $ try 'sort(1^:2)' | |
537 | (func |
|
|||
538 | ('symbol', 'sort') |
|
|||
539 | (parent |
|
|||
540 | ('symbol', '1') |
|
|||
541 | (rangepre |
|
|||
542 | ('symbol', '2')))) |
|
|||
543 | * optimized: |
|
|||
544 | (func |
|
521 | (func | |
545 | ('symbol', 'sort') |
|
522 | ('symbol', 'sort') | |
546 | (range |
|
523 | (range | |
@@ -553,22 +530,14 b' infix/suffix resolution of ^ operator (i' | |||||
553 | 1 |
|
530 | 1 | |
554 | 2 |
|
531 | 2 | |
555 |
|
532 | |||
556 |
$ try |
|
533 | $ try '(3^:4)^:2' | |
557 | (parent |
|
|||
558 | (group |
|
|||
559 | (parent |
|
|||
560 | ('symbol', '3') |
|
|||
561 | (rangepre |
|
|||
562 | ('symbol', '4')))) |
|
|||
563 | (rangepre |
|
|||
564 | ('symbol', '2'))) |
|
|||
565 | * optimized: |
|
|||
566 | (range |
|
534 | (range | |
567 | (parentpost |
|
535 | (parentpost | |
568 |
( |
|
536 | (group | |
569 |
( |
|
537 | (range | |
570 | ('symbol', '3')) |
|
538 | (parentpost | |
571 |
('symbol', ' |
|
539 | ('symbol', '3')) | |
|
540 | ('symbol', '4')))) | |||
572 | ('symbol', '2')) |
|
541 | ('symbol', '2')) | |
573 | * set: |
|
542 | * set: | |
574 | <spanset+ 0:2> |
|
543 | <spanset+ 0:2> | |
@@ -576,22 +545,14 b' infix/suffix resolution of ^ operator (i' | |||||
576 | 1 |
|
545 | 1 | |
577 | 2 |
|
546 | 2 | |
578 |
|
547 | |||
579 |
$ try |
|
548 | $ try '(3^::4)^::2' | |
580 | (parent |
|
|||
581 | (group |
|
|||
582 | (parent |
|
|||
583 | ('symbol', '3') |
|
|||
584 | (dagrangepre |
|
|||
585 | ('symbol', '4')))) |
|
|||
586 | (dagrangepre |
|
|||
587 | ('symbol', '2'))) |
|
|||
588 | * optimized: |
|
|||
589 | (dagrange |
|
549 | (dagrange | |
590 | (parentpost |
|
550 | (parentpost | |
591 |
( |
|
551 | (group | |
592 |
( |
|
552 | (dagrange | |
593 | ('symbol', '3')) |
|
553 | (parentpost | |
594 |
('symbol', ' |
|
554 | ('symbol', '3')) | |
|
555 | ('symbol', '4')))) | |||
595 | ('symbol', '2')) |
|
556 | ('symbol', '2')) | |
596 | * set: |
|
557 | * set: | |
597 | <baseset+ [0, 1, 2]> |
|
558 | <baseset+ [0, 1, 2]> | |
@@ -601,14 +562,9 b' infix/suffix resolution of ^ operator (i' | |||||
601 |
|
562 | |||
602 | x^ in alias should also be resolved |
|
563 | x^ in alias should also be resolved | |
603 |
|
564 | |||
604 |
$ try |
|
565 | $ try 'A' --config 'revsetalias.A=1^:2' | |
605 | ('symbol', 'A') |
|
566 | ('symbol', 'A') | |
606 | * expanded: |
|
567 | * expanded: | |
607 | (parent |
|
|||
608 | ('symbol', '1') |
|
|||
609 | (rangepre |
|
|||
610 | ('symbol', '2'))) |
|
|||
611 | * optimized: |
|
|||
612 | (range |
|
568 | (range | |
613 | (parentpost |
|
569 | (parentpost | |
614 | ('symbol', '1')) |
|
570 | ('symbol', '1')) | |
@@ -619,7 +575,7 b' infix/suffix resolution of ^ operator (i' | |||||
619 | 1 |
|
575 | 1 | |
620 | 2 |
|
576 | 2 | |
621 |
|
577 | |||
622 |
$ try |
|
578 | $ try 'A:2' --config 'revsetalias.A=1^' | |
623 | (range |
|
579 | (range | |
624 | ('symbol', 'A') |
|
580 | ('symbol', 'A') | |
625 | ('symbol', '2')) |
|
581 | ('symbol', '2')) | |
@@ -628,11 +584,6 b' infix/suffix resolution of ^ operator (i' | |||||
628 | (parentpost |
|
584 | (parentpost | |
629 | ('symbol', '1')) |
|
585 | ('symbol', '1')) | |
630 | ('symbol', '2')) |
|
586 | ('symbol', '2')) | |
631 | * optimized: |
|
|||
632 | (range |
|
|||
633 | (parentpost |
|
|||
634 | ('symbol', '1')) |
|
|||
635 | ('symbol', '2')) |
|
|||
636 | * set: |
|
587 | * set: | |
637 | <spanset+ 0:2> |
|
588 | <spanset+ 0:2> | |
638 | 0 |
|
589 | 0 | |
@@ -642,7 +593,7 b' infix/suffix resolution of ^ operator (i' | |||||
642 | but not beyond the boundary of alias expansion, because the resolution should |
|
593 | but not beyond the boundary of alias expansion, because the resolution should | |
643 | be made at the parsing stage |
|
594 | be made at the parsing stage | |
644 |
|
595 | |||
645 |
$ try |
|
596 | $ try '1^A' --config 'revsetalias.A=:2' | |
646 | (parent |
|
597 | (parent | |
647 | ('symbol', '1') |
|
598 | ('symbol', '1') | |
648 | ('symbol', 'A')) |
|
599 | ('symbol', 'A')) | |
@@ -651,17 +602,8 b' infix/suffix resolution of ^ operator (i' | |||||
651 | ('symbol', '1') |
|
602 | ('symbol', '1') | |
652 | (rangepre |
|
603 | (rangepre | |
653 | ('symbol', '2'))) |
|
604 | ('symbol', '2'))) | |
654 | * optimized: |
|
605 | hg: parse error: ^ expects a number 0, 1, or 2 | |
655 | (range |
|
606 | [255] | |
656 | (parentpost |
|
|||
657 | ('symbol', '1')) |
|
|||
658 | ('symbol', '2')) |
|
|||
659 | * set: |
|
|||
660 | <spanset+ 0:2> |
|
|||
661 | 0 |
|
|||
662 | 1 |
|
|||
663 | 2 |
|
|||
664 | BROKEN: should be parsed as '1^(:2)' |
|
|||
665 |
|
607 | |||
666 | ancestor can accept 0 or more arguments |
|
608 | ancestor can accept 0 or more arguments | |
667 |
|
609 |
General Comments 0
You need to be logged in to leave comments.
Login now