##// END OF EJS Templates
urlutil: make `paths` class old list of `path`...
marmoute -
r47958:7531cc34 default
parent child Browse files
Show More
@@ -667,14 +667,19 b' def showpeerurls(context, mapping):'
667 667 urls = util.sortdict((k, p.rawloc) for k, p in all_paths)
668 668
669 669 def makemap(k):
670 p = paths[k]
671 d = {b'name': k, b'url': p.rawloc}
672 sub_opts = util.sortdict(sorted(pycompat.iteritems(p.suboptions)))
673 d.update(sub_opts)
670 ps = paths[k]
671 d = {b'name': k}
672 if len(ps) == 1:
673 d[b'url'] = ps[0].rawloc
674 sub_opts = pycompat.iteritems(ps[0].suboptions)
675 sub_opts = util.sortdict(sorted(sub_opts))
676 d.update(sub_opts)
674 677 path_dict = util.sortdict()
675 path_dict[b'url'] = p.rawloc
676 path_dict.update(sub_opts)
677 d[b'urls'] = [path_dict]
678 for p in ps:
679 sub_opts = util.sortdict(sorted(pycompat.iteritems(p.suboptions)))
680 path_dict[b'url'] = p.rawloc
681 path_dict.update(sub_opts)
682 d[b'urls'] = [path_dict]
678 683 return d
679 684
680 685 def format_one(k):
@@ -447,14 +447,16 b' def removeauth(u):'
447 447
448 448 def list_paths(ui, target_path=None):
449 449 """list all the (name, paths) in the passed ui"""
450 result = []
450 451 if target_path is None:
451 return sorted(pycompat.iteritems(ui.paths))
452 for name, paths in sorted(pycompat.iteritems(ui.paths)):
453 for p in paths:
454 result.append((name, p))
455
452 456 else:
453 path = ui.paths.get(target_path)
454 if path is None:
455 return []
456 else:
457 return [(target_path, path)]
457 for path in ui.paths.get(target_path, []):
458 result.append((target_path, path))
459 return result
458 460
459 461
460 462 def try_path(ui, url):
@@ -473,9 +475,11 b' def get_push_paths(repo, ui, dests):'
473 475 """yields all the `path` selected as push destination by `dests`"""
474 476 if not dests:
475 477 if b'default-push' in ui.paths:
476 yield ui.paths[b'default-push']
478 for p in ui.paths[b'default-push']:
479 yield p
477 480 elif b'default' in ui.paths:
478 yield ui.paths[b'default']
481 for p in ui.paths[b'default']:
482 yield p
479 483 else:
480 484 raise error.ConfigError(
481 485 _(b'default repository not configured!'),
@@ -484,7 +488,8 b' def get_push_paths(repo, ui, dests):'
484 488 else:
485 489 for dest in dests:
486 490 if dest in ui.paths:
487 yield ui.paths[dest]
491 for p in ui.paths[dest]:
492 yield p
488 493 else:
489 494 path = try_path(ui, dest)
490 495 if path is None:
@@ -500,7 +505,8 b' def get_pull_paths(repo, ui, sources, de'
500 505 sources = [b'default']
501 506 for source in sources:
502 507 if source in ui.paths:
503 url = ui.paths[source].rawloc
508 for p in ui.paths[source]:
509 yield parseurl(p.rawloc, default_branches)
504 510 else:
505 511 # Try to resolve as a local path or URI.
506 512 path = try_path(ui, source)
@@ -508,7 +514,7 b' def get_pull_paths(repo, ui, sources, de'
508 514 url = path.rawloc
509 515 else:
510 516 url = source
511 yield parseurl(url, default_branches)
517 yield parseurl(url, default_branches)
512 518
513 519
514 520 def get_unique_push_path(action, repo, ui, dest=None):
@@ -526,7 +532,14 b' def get_unique_push_path(action, repo, u'
526 532 else:
527 533 dests = [dest]
528 534 dests = list(get_push_paths(repo, ui, dests))
529 assert len(dests) == 1
535 if len(dests) != 1:
536 if dest is None:
537 msg = _("default path points to %d urls while %s only supports one")
538 msg %= (len(dests), action)
539 else:
540 msg = _("path points to %d urls while %s only supports one: %s")
541 msg %= (len(dests), action, dest)
542 raise error.Abort(msg)
530 543 return dests[0]
531 544
532 545
@@ -540,45 +553,66 b' def get_unique_pull_path(action, repo, u'
540 553
541 554 The `action` parameter will be used for the error message.
542 555 """
556 urls = []
543 557 if source is None:
544 558 if b'default' in ui.paths:
545 url = ui.paths[b'default'].rawloc
559 urls.extend(p.rawloc for p in ui.paths[b'default'])
546 560 else:
547 561 # XXX this is the historical default behavior, but that is not
548 562 # great, consider breaking BC on this.
549 url = b'default'
563 urls.append(b'default')
550 564 else:
551 565 if source in ui.paths:
552 url = ui.paths[source].rawloc
566 urls.extend(p.rawloc for p in ui.paths[source])
553 567 else:
554 568 # Try to resolve as a local path or URI.
555 569 path = try_path(ui, source)
556 570 if path is not None:
557 url = path.rawloc
571 urls.append(path.rawloc)
558 572 else:
559 url = source
560 return parseurl(url, default_branches)
573 urls.append(source)
574 if len(urls) != 1:
575 if source is None:
576 msg = _("default path points to %d urls while %s only supports one")
577 msg %= (len(urls), action)
578 else:
579 msg = _("path points to %d urls while %s only supports one: %s")
580 msg %= (len(urls), action, source)
581 raise error.Abort(msg)
582 return parseurl(urls[0], default_branches)
561 583
562 584
563 585 def get_clone_path(ui, source, default_branches=()):
564 586 """return the `(origsource, path, branch)` selected as clone source"""
587 urls = []
565 588 if source is None:
566 589 if b'default' in ui.paths:
567 url = ui.paths[b'default'].rawloc
590 urls.extend(p.rawloc for p in ui.paths[b'default'])
568 591 else:
569 592 # XXX this is the historical default behavior, but that is not
570 593 # great, consider breaking BC on this.
571 url = b'default'
594 urls.append(b'default')
572 595 else:
573 596 if source in ui.paths:
574 url = ui.paths[source].rawloc
597 urls.extend(p.rawloc for p in ui.paths[source])
575 598 else:
576 599 # Try to resolve as a local path or URI.
577 600 path = try_path(ui, source)
578 601 if path is not None:
579 url = path.rawloc
602 urls.append(path.rawloc)
580 603 else:
581 url = source
604 urls.append(source)
605 if len(urls) != 1:
606 if source is None:
607 msg = _(
608 "default path points to %d urls while only one is supported"
609 )
610 msg %= len(urls)
611 else:
612 msg = _("path points to %d urls while only one is supported: %s")
613 msg %= (len(urls), source)
614 raise error.Abort(msg)
615 url = urls[0]
582 616 clone_path, branch = parseurl(url, default_branches)
583 617 return url, clone_path, branch
584 618
@@ -608,10 +642,13 b' class paths(dict):'
608 642 if not loc:
609 643 continue
610 644 loc, sub_opts = ui.configsuboptions(b'paths', name)
611 self[name] = path(ui, name, rawloc=loc, suboptions=sub_opts)
645 self[name] = [path(ui, name, rawloc=loc, suboptions=sub_opts)]
612 646
613 for name, p in sorted(self.items()):
614 self[name] = _chain_path(p, ui, self)
647 for name, old_paths in sorted(self.items()):
648 new_paths = []
649 for p in old_paths:
650 new_paths.extend(_chain_path(p, ui, self))
651 self[name] = new_paths
615 652
616 653 def getpath(self, ui, name, default=None):
617 654 """Return a ``path`` from a string, falling back to default.
@@ -632,7 +669,7 b' class paths(dict):'
632 669 default = (default,)
633 670 for k in default:
634 671 try:
635 return self[k]
672 return self[k][0]
636 673 except KeyError:
637 674 continue
638 675 return None
@@ -642,7 +679,7 b' class paths(dict):'
642 679 if not name:
643 680 return None
644 681 if name in self:
645 return self[name]
682 return self[name][0]
646 683 else:
647 684 # Try to resolve as a local path or URI.
648 685 path = try_path(ui, name)
@@ -704,31 +741,37 b' def pushrevpathoption(ui, path, value):'
704 741 return value
705 742
706 743
707 def _chain_path(path, ui, paths):
744 def _chain_path(base_path, ui, paths):
708 745 """return the result of "path://" logic applied on a given path"""
709 if path.url.scheme == b'path':
710 assert path.url.path is None
711 subpath = paths.get(path.url.host)
712 if subpath is None:
746 new_paths = []
747 if base_path.url.scheme != b'path':
748 new_paths.append(base_path)
749 else:
750 assert base_path.url.path is None
751 sub_paths = paths.get(base_path.url.host)
752 if sub_paths is None:
713 753 m = _(b'cannot use `%s`, "%s" is not a known path')
714 m %= (path.rawloc, path.url.host)
715 raise error.Abort(m)
716 if subpath.raw_url.scheme == b'path':
717 m = _(b'cannot use `%s`, "%s" is also defined as a `path://`')
718 m %= (path.rawloc, path.url.host)
754 m %= (base_path.rawloc, base_path.url.host)
719 755 raise error.Abort(m)
720 path.url = subpath.url
721 path.rawloc = subpath.rawloc
722 path.loc = subpath.loc
723 if path.branch is None:
724 path.branch = subpath.branch
725 else:
726 base = path.rawloc.rsplit(b'#', 1)[0]
727 path.rawloc = b'%s#%s' % (base, path.branch)
728 suboptions = subpath._all_sub_opts.copy()
729 suboptions.update(path._own_sub_opts)
730 path._apply_suboptions(ui, suboptions)
731 return path
756 for subpath in sub_paths:
757 path = base_path.copy()
758 if subpath.raw_url.scheme == b'path':
759 m = _(b'cannot use `%s`, "%s" is also defined as a `path://`')
760 m %= (path.rawloc, path.url.host)
761 raise error.Abort(m)
762 path.url = subpath.url
763 path.rawloc = subpath.rawloc
764 path.loc = subpath.loc
765 if path.branch is None:
766 path.branch = subpath.branch
767 else:
768 base = path.rawloc.rsplit(b'#', 1)[0]
769 path.rawloc = b'%s#%s' % (base, path.branch)
770 suboptions = subpath._all_sub_opts.copy()
771 suboptions.update(path._own_sub_opts)
772 path._apply_suboptions(ui, suboptions)
773 new_paths.append(path)
774 return new_paths
732 775
733 776
734 777 class path(object):
General Comments 0
You need to be logged in to leave comments. Login now