##// END OF EJS Templates
url_util: introduce a `try_path` function...
marmoute -
r47791:fd396eb2 default draft
parent child Browse files
Show More
@@ -445,6 +445,18 b' def removeauth(u):'
445 return bytes(u)
445 return bytes(u)
446
446
447
447
448 def try_path(ui, url):
449 """try to build a path from a url
450
451 Return None if no Path could built.
452 """
453 try:
454 # we pass the ui instance are warning might need to be issued
455 return path(ui, None, rawloc=url)
456 except ValueError:
457 return None
458
459
448 def get_push_paths(repo, ui, dests):
460 def get_push_paths(repo, ui, dests):
449 """yields all the `path` selected as push destination by `dests`"""
461 """yields all the `path` selected as push destination by `dests`"""
450 if not dests:
462 if not dests:
@@ -471,10 +483,10 b' def get_pull_paths(repo, ui, sources, de'
471 url = ui.paths[source].rawloc
483 url = ui.paths[source].rawloc
472 else:
484 else:
473 # Try to resolve as a local path or URI.
485 # Try to resolve as a local path or URI.
474 try:
486 path = try_path(ui, source)
475 # we pass the ui instance are warning might need to be issued
487 if path is not None:
476 url = path(ui, None, rawloc=source).rawloc
488 url = path.rawloc
477 except ValueError:
489 else:
478 url = source
490 url = source
479 yield parseurl(url, default_branches)
491 yield parseurl(url, default_branches)
480
492
@@ -520,10 +532,10 b' def get_unique_pull_path(action, repo, u'
520 url = ui.paths[source].rawloc
532 url = ui.paths[source].rawloc
521 else:
533 else:
522 # Try to resolve as a local path or URI.
534 # Try to resolve as a local path or URI.
523 try:
535 path = try_path(ui, source)
524 # we pass the ui instance are warning might need to be issued
536 if path is not None:
525 url = path(ui, None, rawloc=source).rawloc
537 url = path.rawloc
526 except ValueError:
538 else:
527 url = source
539 url = source
528 return parseurl(url, default_branches)
540 return parseurl(url, default_branches)
529
541
@@ -542,10 +554,10 b' def get_clone_path(ui, source, default_b'
542 url = ui.paths[source].rawloc
554 url = ui.paths[source].rawloc
543 else:
555 else:
544 # Try to resolve as a local path or URI.
556 # Try to resolve as a local path or URI.
545 try:
557 path = try_path(ui, source)
546 # we pass the ui instance are warning might need to be issued
558 if path is not None:
547 url = path(ui, None, rawloc=source).rawloc
559 url = path.rawloc
548 except ValueError:
560 else:
549 url = source
561 url = source
550 clone_path, branch = parseurl(url, default_branches)
562 clone_path, branch = parseurl(url, default_branches)
551 return url, clone_path, branch
563 return url, clone_path, branch
@@ -607,16 +619,14 b' class paths(dict):'
607 # This may need to raise in the future.
619 # This may need to raise in the future.
608 if not name:
620 if not name:
609 return None
621 return None
610
622 if name in self:
611 try:
612 return self[name]
623 return self[name]
613 except KeyError:
624 else:
614 # Try to resolve as a local path or URI.
625 # Try to resolve as a local path or URI.
615 try:
626 path = try_path(ui, name)
616 # we pass the ui instance are warning might need to be issued
627 if path is None:
617 return path(ui, None, rawloc=name)
618 except ValueError:
619 raise error.RepoError(_(b'repository %s does not exist') % name)
628 raise error.RepoError(_(b'repository %s does not exist') % name)
629 return path.rawloc
620
630
621
631
622 _pathsuboptions = {}
632 _pathsuboptions = {}
General Comments 0
You need to be logged in to leave comments. Login now