##// END OF EJS Templates
multi-urls: add a boolean suboption that unlock path specification as list...
marmoute -
r48047:834f4e9d default
parent child Browse files
Show More
@@ -20,6 +20,10 b' from .. import ('
20 urllibcompat,
20 urllibcompat,
21 )
21 )
22
22
23 from . import (
24 stringutil,
25 )
26
23
27
24 if pycompat.TYPE_CHECKING:
28 if pycompat.TYPE_CHECKING:
25 from typing import (
29 from typing import (
@@ -639,19 +643,30 b' class paths(dict):'
639
643
640 home_path = os.path.expanduser(b'~')
644 home_path = os.path.expanduser(b'~')
641
645
642 for name, loc in ui.configitems(b'paths', ignoresub=True):
646 for name, value in ui.configitems(b'paths', ignoresub=True):
643 # No location is the same as not existing.
647 # No location is the same as not existing.
644 if not loc:
648 if not value:
645 continue
649 continue
646 _value, sub_opts = ui.configsuboptions(b'paths', name)
650 _value, sub_opts = ui.configsuboptions(b'paths', name)
647 s = ui.configsource(b'paths', name)
651 s = ui.configsource(b'paths', name)
648 root_key = (name, loc, s)
652 root_key = (name, value, s)
649 root = ui._path_to_root.get(root_key, home_path)
653 root = ui._path_to_root.get(root_key, home_path)
650 loc = os.path.expandvars(loc)
654
651 loc = os.path.expanduser(loc)
655 multi_url = sub_opts.get(b'multi-urls')
652 if not hasscheme(loc) and not os.path.isabs(loc):
656 if multi_url is not None and stringutil.parsebool(multi_url):
653 loc = os.path.normpath(os.path.join(root, loc))
657 base_locs = stringutil.parselist(value)
654 self[name] = [path(ui, name, rawloc=loc, suboptions=sub_opts)]
658 else:
659 base_locs = [value]
660
661 paths = []
662 for loc in base_locs:
663 loc = os.path.expandvars(loc)
664 loc = os.path.expanduser(loc)
665 if not hasscheme(loc) and not os.path.isabs(loc):
666 loc = os.path.normpath(os.path.join(root, loc))
667 p = path(ui, name, rawloc=loc, suboptions=sub_opts)
668 paths.append(p)
669 self[name] = paths
655
670
656 for name, old_paths in sorted(self.items()):
671 for name, old_paths in sorted(self.items()):
657 new_paths = []
672 new_paths = []
@@ -750,6 +765,17 b' def pushrevpathoption(ui, path, value):'
750 return value
765 return value
751
766
752
767
768 @pathsuboption(b'multi-urls', b'multi_urls')
769 def multiurls_pathoption(ui, path, value):
770 res = stringutil.parsebool(value)
771 if res is None:
772 ui.warn(
773 _(b'(paths.%s:multi-urls not a boolean; ignoring)\n') % path.name
774 )
775 res = False
776 return res
777
778
753 def _chain_path(base_path, ui, paths):
779 def _chain_path(base_path, ui, paths):
754 """return the result of "path://" logic applied on a given path"""
780 """return the result of "path://" logic applied on a given path"""
755 new_paths = []
781 new_paths = []
@@ -611,3 +611,177 b' The update has conflict and interrupt th'
611 |
611 |
612 % A 0
612 % A 0
613
613
614
615 Testing multi-path definition
616 ----------------------------
617
618 $ hg clone main-repo repo-paths --rev 0
619 adding changesets
620 adding manifests
621 adding file changes
622 added 1 changesets with 1 changes to 1 files
623 new changesets 4a2df7238c3b
624 updating to branch default
625 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
626 $ cp -R ./branch-E ./branch-E-paths
627 $ cp -R ./branch-G ./branch-G-paths
628 $ cp -R ./branch-H ./branch-H-paths
629 $ cat << EOF >> repo-paths/.hg/hgrc
630 > [paths]
631 > E=../branch-E-paths
632 > G=../branch-G-paths
633 > H=../branch-H-paths
634 > EHG=path://E,path://H,path://G
635 > EHG:multi-urls=yes
636 > GEH=path://G,path://E,path://H
637 > GEH:multi-urls=yes
638 > EOF
639
640 Do various operations and verify that order matters
641
642 $ hg -R repo-paths push EHG --force
643 pushing to $TESTTMP/branch-E-paths
644 searching for changes
645 no changes found
646 pushing to $TESTTMP/branch-H-paths
647 searching for changes
648 no changes found
649 pushing to $TESTTMP/branch-G-paths
650 searching for changes
651 no changes found
652 [1]
653 $ hg -R repo-paths push GEH --force
654 pushing to $TESTTMP/branch-G-paths
655 searching for changes
656 no changes found
657 pushing to $TESTTMP/branch-E-paths
658 searching for changes
659 no changes found
660 pushing to $TESTTMP/branch-H-paths
661 searching for changes
662 no changes found
663 [1]
664 $ hg -R repo-paths push EHG GEH --force
665 pushing to $TESTTMP/branch-E-paths
666 searching for changes
667 no changes found
668 pushing to $TESTTMP/branch-H-paths
669 searching for changes
670 no changes found
671 pushing to $TESTTMP/branch-G-paths
672 searching for changes
673 no changes found
674 pushing to $TESTTMP/branch-G-paths
675 searching for changes
676 no changes found
677 pushing to $TESTTMP/branch-E-paths
678 searching for changes
679 no changes found
680 pushing to $TESTTMP/branch-H-paths
681 searching for changes
682 no changes found
683 [1]
684 $ hg -R repo-paths pull EHG
685 pulling from $TESTTMP/branch-E-paths
686 searching for changes
687 adding changesets
688 adding manifests
689 adding file changes
690 added 4 changesets with 4 changes to 4 files
691 new changesets 27547f69f254:a603bfb5a83e
692 (run 'hg update' to get a working copy)
693 pulling from $TESTTMP/branch-H-paths
694 searching for changes
695 adding changesets
696 adding manifests
697 adding file changes
698 added 1 changesets with 1 changes to 1 files (+1 heads)
699 new changesets 40faebb2ec45
700 (run 'hg heads' to see heads, 'hg merge' to merge)
701 pulling from $TESTTMP/branch-G-paths
702 searching for changes
703 adding changesets
704 adding manifests
705 adding file changes
706 added 2 changesets with 2 changes to 2 files (+1 heads)
707 new changesets 2f3a4c5c1417:c521a06b234b
708 (run 'hg heads .' to see heads, 'hg merge' to merge)
709 $ hg -R repo-paths pull GEH
710 pulling from $TESTTMP/branch-G-paths
711 searching for changes
712 no changes found
713 pulling from $TESTTMP/branch-E-paths
714 searching for changes
715 no changes found
716 pulling from $TESTTMP/branch-H-paths
717 searching for changes
718 no changes found
719 $ hg -R repo-paths pull EHG GEH
720 pulling from $TESTTMP/branch-E-paths
721 searching for changes
722 no changes found
723 pulling from $TESTTMP/branch-H-paths
724 searching for changes
725 no changes found
726 pulling from $TESTTMP/branch-G-paths
727 searching for changes
728 no changes found
729 pulling from $TESTTMP/branch-G-paths
730 searching for changes
731 no changes found
732 pulling from $TESTTMP/branch-E-paths
733 searching for changes
734 no changes found
735 pulling from $TESTTMP/branch-H-paths
736 searching for changes
737 no changes found
738 $ hg -R repo-paths push EHG --force
739 pushing to $TESTTMP/branch-E-paths
740 searching for changes
741 adding changesets
742 adding manifests
743 adding file changes
744 added 3 changesets with 3 changes to 3 files (+2 heads)
745 pushing to $TESTTMP/branch-H-paths
746 searching for changes
747 adding changesets
748 adding manifests
749 adding file changes
750 added 4 changesets with 4 changes to 4 files (+2 heads)
751 pushing to $TESTTMP/branch-G-paths
752 searching for changes
753 adding changesets
754 adding manifests
755 adding file changes
756 added 4 changesets with 4 changes to 4 files (+2 heads)
757 $ hg -R repo-paths push GEH --force
758 pushing to $TESTTMP/branch-G-paths
759 searching for changes
760 no changes found
761 pushing to $TESTTMP/branch-E-paths
762 searching for changes
763 no changes found
764 pushing to $TESTTMP/branch-H-paths
765 searching for changes
766 no changes found
767 [1]
768 $ hg -R repo-paths push EHG GEH --force
769 pushing to $TESTTMP/branch-E-paths
770 searching for changes
771 no changes found
772 pushing to $TESTTMP/branch-H-paths
773 searching for changes
774 no changes found
775 pushing to $TESTTMP/branch-G-paths
776 searching for changes
777 no changes found
778 pushing to $TESTTMP/branch-G-paths
779 searching for changes
780 no changes found
781 pushing to $TESTTMP/branch-E-paths
782 searching for changes
783 no changes found
784 pushing to $TESTTMP/branch-H-paths
785 searching for changes
786 no changes found
787 [1]
@@ -388,3 +388,128 b' Test basic error cases'
388 abort: cannot use `path://unknown`, "unknown" is not a known path
388 abort: cannot use `path://unknown`, "unknown" is not a known path
389 [255]
389 [255]
390
390
391 Test path pointing to multiple urls
392 ===================================
393
394 Simple cases
395 ------------
396 - one layer
397 - one list
398 - no special option
399
400 $ cat << EOF > .hg/hgrc
401 > [paths]
402 > one-path=foo
403 > multiple-path=foo,bar,baz,https://example.org/
404 > multiple-path:multi-urls=yes
405 > EOF
406 $ hg path
407 gpath1 = http://hg.example.com/
408 multiple-path = $TESTTMP/chained_path/foo
409 multiple-path:multi-urls = yes
410 multiple-path = $TESTTMP/chained_path/bar
411 multiple-path:multi-urls = yes
412 multiple-path = $TESTTMP/chained_path/baz
413 multiple-path:multi-urls = yes
414 multiple-path = https://example.org/
415 multiple-path:multi-urls = yes
416 one-path = $TESTTMP/chained_path/foo
417
418 Reference to a list
419 -------------------
420
421 $ cat << EOF >> .hg/hgrc
422 > ref-to-multi=path://multiple-path
423 > EOF
424 $ hg path | grep ref-to-multi
425 ref-to-multi = $TESTTMP/chained_path/foo
426 ref-to-multi:multi-urls = yes
427 ref-to-multi = $TESTTMP/chained_path/bar
428 ref-to-multi:multi-urls = yes
429 ref-to-multi = $TESTTMP/chained_path/baz
430 ref-to-multi:multi-urls = yes
431 ref-to-multi = https://example.org/
432 ref-to-multi:multi-urls = yes
433
434 List with a reference
435 ---------------------
436
437 $ cat << EOF >> .hg/hgrc
438 > multi-with-ref=path://one-path, ssh://babar@savannah/celeste-ville
439 > multi-with-ref:multi-urls=yes
440 > EOF
441 $ hg path | grep multi-with-ref
442 multi-with-ref = $TESTTMP/chained_path/foo
443 multi-with-ref:multi-urls = yes
444 multi-with-ref = ssh://babar@savannah/celeste-ville
445 multi-with-ref:multi-urls = yes
446
447 List with a reference to a list
448 -------------------------------
449
450 $ cat << EOF >> .hg/hgrc
451 > multi-to-multi-ref = path://multiple-path, ssh://celeste@savannah/celeste-ville
452 > multi-to-multi-ref:multi-urls = yes
453 > EOF
454 $ hg path | grep multi-to-multi-ref
455 multi-to-multi-ref = $TESTTMP/chained_path/foo
456 multi-to-multi-ref:multi-urls = yes
457 multi-to-multi-ref = $TESTTMP/chained_path/bar
458 multi-to-multi-ref:multi-urls = yes
459 multi-to-multi-ref = $TESTTMP/chained_path/baz
460 multi-to-multi-ref:multi-urls = yes
461 multi-to-multi-ref = https://example.org/
462 multi-to-multi-ref:multi-urls = yes
463 multi-to-multi-ref = ssh://celeste@savannah/celeste-ville
464 multi-to-multi-ref:multi-urls = yes
465
466 individual suboptions are inherited
467 -----------------------------------
468
469 $ cat << EOF >> .hg/hgrc
470 > with-pushurl = foo
471 > with-pushurl:pushurl = http://foo.bar/
472 > with-pushrev = bar
473 > with-pushrev:pushrev = draft()
474 > with-both = toto
475 > with-both:pushurl = http://ta.ta
476 > with-both:pushrev = secret()
477 > ref-all-no-opts = path://with-pushurl, path://with-pushrev, path://with-both
478 > ref-all-no-opts:multi-urls = yes
479 > with-overwrite = path://with-pushurl, path://with-pushrev, path://with-both
480 > with-overwrite:multi-urls = yes
481 > with-overwrite:pushrev = public()
482 > EOF
483 $ hg path | grep with-pushurl
484 with-pushurl = $TESTTMP/chained_path/foo
485 with-pushurl:pushurl = http://foo.bar/
486 $ hg path | grep with-pushrev
487 with-pushrev = $TESTTMP/chained_path/bar
488 with-pushrev:pushrev = draft()
489 $ hg path | grep with-both
490 with-both = $TESTTMP/chained_path/toto
491 with-both:pushrev = secret()
492 with-both:pushurl = http://ta.ta/
493 $ hg path | grep ref-all-no-opts
494 ref-all-no-opts = $TESTTMP/chained_path/foo
495 ref-all-no-opts:multi-urls = yes
496 ref-all-no-opts:pushurl = http://foo.bar/
497 ref-all-no-opts = $TESTTMP/chained_path/bar
498 ref-all-no-opts:multi-urls = yes
499 ref-all-no-opts:pushrev = draft()
500 ref-all-no-opts = $TESTTMP/chained_path/toto
501 ref-all-no-opts:multi-urls = yes
502 ref-all-no-opts:pushrev = secret()
503 ref-all-no-opts:pushurl = http://ta.ta/
504 $ hg path | grep with-overwrite
505 with-overwrite = $TESTTMP/chained_path/foo
506 with-overwrite:multi-urls = yes
507 with-overwrite:pushrev = public()
508 with-overwrite:pushurl = http://foo.bar/
509 with-overwrite = $TESTTMP/chained_path/bar
510 with-overwrite:multi-urls = yes
511 with-overwrite:pushrev = public()
512 with-overwrite = $TESTTMP/chained_path/toto
513 with-overwrite:multi-urls = yes
514 with-overwrite:pushrev = public()
515 with-overwrite:pushurl = http://ta.ta/
General Comments 0
You need to be logged in to leave comments. Login now