mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
remotenames: normalize 'default-push' to 'default'
Summary: We have seen cases where `default-push` remote name gets written during pull. Teach `paths.getname` (new code path) and `remotenames.activepath` (old code path) to optionally normalize `default-push` to `default` to avoid that. Reviewed By: DurhamG Differential Revision: D22395521 fbshipit-source-id: ed16dc30150fc1369f7037296cf77f7f0fc83fee
This commit is contained in:
parent
6f2adbf2cc
commit
10f53151f4
@ -1369,6 +1369,11 @@ def splitremotename(remote):
|
||||
return remote, name
|
||||
|
||||
|
||||
def remotenameforurl(ui, url):
|
||||
"""Convert an URL to a remote name"""
|
||||
return ui.paths.getname(url, forremotenames=True)
|
||||
|
||||
|
||||
def _trackaccessedbookmarks(ui):
|
||||
return ui.configbool("remotenames", "selectivepullaccessedbookmarks")
|
||||
|
||||
|
@ -49,7 +49,7 @@ def shallowclone(source, repo):
|
||||
|
||||
# Fetch selected remote bookmarks.
|
||||
repo.ui.status(_("fetching selected remote bookmarks\n"))
|
||||
remote = repo.ui.paths.getname(repo.ui.paths.getpath(source).rawloc)
|
||||
remote = bookmod.remotenameforurl(repo.ui, repo.ui.paths.getpath(source).rawloc)
|
||||
assert remote is not None
|
||||
repo.pull(
|
||||
source, bookmarknames=bookmod.selectivepullbookmarknames(repo, remote)
|
||||
|
@ -4769,7 +4769,9 @@ def pull(ui, repo, source="default", **opts):
|
||||
# pull is unaffected (pulls everything instead of just
|
||||
# selectivepull bookmarks)
|
||||
if revs:
|
||||
remotename = ui.paths.getname(other.url()) # ex. 'default' or 'remote'
|
||||
remotename = bookmarks.remotenameforurl(
|
||||
ui, other.url()
|
||||
) # ex. 'default' or 'remote'
|
||||
# Include selective pull bookmarks automatically.
|
||||
implicitbookmarks.update(
|
||||
bookmarks.selectivepullbookmarknames(repo, remotename)
|
||||
|
@ -405,7 +405,7 @@ def checktoomanynames(repo, source="default"):
|
||||
threshold += len(selected)
|
||||
if count < threshold:
|
||||
return
|
||||
defaultname = ui.paths.getname(ui.paths.getpath(source).rawloc)
|
||||
defaultname = bookmod.remotenameforurl(ui, ui.paths.getpath(source).rawloc)
|
||||
if not defaultname:
|
||||
return
|
||||
ui.write(_("repo has too many (%s) remote bookmarks\n") % count)
|
||||
|
@ -1723,7 +1723,9 @@ def _pullbookmarks(pullop):
|
||||
|
||||
# Update important remotenames (ex. remote/master) listed by selectivepull
|
||||
# unconditionally.
|
||||
remotename = ui.paths.getname(pullop.remote.url()) # ex. 'default' or 'remote'
|
||||
remotename = bookmod.remotenameforurl(
|
||||
ui, pullop.remote.url()
|
||||
) # ex. 'default' or 'remote'
|
||||
if remotename is not None:
|
||||
importantnames = bookmod.selectivepullbookmarknames(repo, remotename)
|
||||
remotebookmarks = pullop.remotebookmarks
|
||||
|
@ -950,8 +950,8 @@ class localrepository(object):
|
||||
|
||||
# Update remotenames.
|
||||
if remotenamechanges:
|
||||
remotename = self.ui.paths.getname(
|
||||
remote.url()
|
||||
remotename = bookmarks.remotenameforurl(
|
||||
self.ui, remote.url()
|
||||
) # ex. 'default' or 'remote'
|
||||
bookmarks.saveremotenames(
|
||||
self, {remotename: remotenamechanges}, override=False
|
||||
|
@ -1863,7 +1863,7 @@ class paths(util.sortdict):
|
||||
except ValueError:
|
||||
raise error.RepoError(_("repository %s does not exist") % name)
|
||||
|
||||
def getname(self, rawloc):
|
||||
def getname(self, rawloc, forremotenames=False):
|
||||
# type: (str) -> Optional[str]
|
||||
"""Return name from a raw location.
|
||||
|
||||
@ -1871,6 +1871,11 @@ class paths(util.sortdict):
|
||||
'remotenames.rename.$name' config exists, return the value of that
|
||||
config instead.
|
||||
|
||||
If 'forremotenames' is True, normalize 'default-push' to 'default'.
|
||||
This is only used by 'bookmarks.remotenameforurl' so we never write
|
||||
'default-push' as a remote name. If you're setting this flag, consider
|
||||
using 'bookmarks.remotenameforurl' instead.
|
||||
|
||||
Return `None` if path is unknown.
|
||||
"""
|
||||
|
||||
@ -1893,6 +1898,11 @@ class paths(util.sortdict):
|
||||
if result in {"infinitepush", "infinitepushbookmark"}:
|
||||
result = "default"
|
||||
|
||||
# Do not use 'default-push' as a remote name. Normalize it to
|
||||
# 'default'.
|
||||
if forremotenames and result == "default-push":
|
||||
result = "default"
|
||||
|
||||
if result:
|
||||
renamed = self._uiconfig.config("remotenames", "rename.%s" % result)
|
||||
if renamed:
|
||||
|
Loading…
Reference in New Issue
Block a user