mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
Refactor how projects parse remotes so it can be replaced
We now feed Project a RemoteSpec, instead of the Remote directly from the XmlManifest. This way the RemoteSpec already has the full project URL, rather than just the base, permitting other types of manifests to produce the URL in their own style. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
parent
c8a300f639
commit
d1f70d9929
@ -18,8 +18,7 @@ import sys
|
|||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
|
|
||||||
from git_config import GitConfig, IsId
|
from git_config import GitConfig, IsId
|
||||||
from project import Project, MetaProject, R_HEADS, HEAD
|
from project import RemoteSpec, Project, MetaProject, R_HEADS, HEAD
|
||||||
from remote import Remote
|
|
||||||
from error import ManifestParseError
|
from error import ManifestParseError
|
||||||
|
|
||||||
MANIFEST_FILE_NAME = 'manifest.xml'
|
MANIFEST_FILE_NAME = 'manifest.xml'
|
||||||
@ -31,6 +30,21 @@ class _Default(object):
|
|||||||
revision = None
|
revision = None
|
||||||
remote = None
|
remote = None
|
||||||
|
|
||||||
|
class _XmlRemote(object):
|
||||||
|
def __init__(self,
|
||||||
|
name,
|
||||||
|
fetch=None,
|
||||||
|
review=None):
|
||||||
|
self.name = name
|
||||||
|
self.fetchUrl = fetch
|
||||||
|
self.reviewUrl = review
|
||||||
|
|
||||||
|
def ToRemoteSpec(self, projectName):
|
||||||
|
url = self.fetchUrl
|
||||||
|
while url.endswith('/'):
|
||||||
|
url = url[:-1]
|
||||||
|
url += '/%s.git' % projectName
|
||||||
|
return RemoteSpec(self.name, url, self.reviewUrl)
|
||||||
|
|
||||||
class XmlManifest(object):
|
class XmlManifest(object):
|
||||||
"""manages the repo configuration file"""
|
"""manages the repo configuration file"""
|
||||||
@ -257,7 +271,7 @@ class XmlManifest(object):
|
|||||||
|
|
||||||
if name is None:
|
if name is None:
|
||||||
s = m_url.rindex('/') + 1
|
s = m_url.rindex('/') + 1
|
||||||
remote = Remote('origin', fetch = m_url[:s])
|
remote = _XmlRemote('origin', m_url[:s])
|
||||||
name = m_url[s:]
|
name = m_url[s:]
|
||||||
|
|
||||||
if name.endswith('.git'):
|
if name.endswith('.git'):
|
||||||
@ -268,7 +282,7 @@ class XmlManifest(object):
|
|||||||
gitdir = os.path.join(self.topdir, '%s.git' % name)
|
gitdir = os.path.join(self.topdir, '%s.git' % name)
|
||||||
project = Project(manifest = self,
|
project = Project(manifest = self,
|
||||||
name = name,
|
name = name,
|
||||||
remote = remote,
|
remote = remote.ToRemoteSpec(name),
|
||||||
gitdir = gitdir,
|
gitdir = gitdir,
|
||||||
worktree = None,
|
worktree = None,
|
||||||
relpath = None,
|
relpath = None,
|
||||||
@ -284,7 +298,7 @@ class XmlManifest(object):
|
|||||||
review = node.getAttribute('review')
|
review = node.getAttribute('review')
|
||||||
if review == '':
|
if review == '':
|
||||||
review = None
|
review = None
|
||||||
return Remote(name=name, fetch=fetch, review=review)
|
return _XmlRemote(name, fetch, review)
|
||||||
|
|
||||||
def _ParseDefault(self, node):
|
def _ParseDefault(self, node):
|
||||||
"""
|
"""
|
||||||
@ -337,7 +351,7 @@ class XmlManifest(object):
|
|||||||
|
|
||||||
project = Project(manifest = self,
|
project = Project(manifest = self,
|
||||||
name = name,
|
name = name,
|
||||||
remote = remote,
|
remote = remote.ToRemoteSpec(name),
|
||||||
gitdir = gitdir,
|
gitdir = gitdir,
|
||||||
worktree = worktree,
|
worktree = worktree,
|
||||||
relpath = path,
|
relpath = path,
|
||||||
|
23
project.py
23
project.py
@ -26,7 +26,6 @@ from git_command import GitCommand
|
|||||||
from git_config import GitConfig, IsId
|
from git_config import GitConfig, IsId
|
||||||
from error import GitError, ImportError, UploadError
|
from error import GitError, ImportError, UploadError
|
||||||
from error import ManifestInvalidRevisionError
|
from error import ManifestInvalidRevisionError
|
||||||
from remote import Remote
|
|
||||||
|
|
||||||
from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M
|
from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M
|
||||||
|
|
||||||
@ -212,6 +211,14 @@ class _CopyFile:
|
|||||||
except IOError:
|
except IOError:
|
||||||
_error('Cannot copy file %s to %s', src, dest)
|
_error('Cannot copy file %s to %s', src, dest)
|
||||||
|
|
||||||
|
class RemoteSpec(object):
|
||||||
|
def __init__(self,
|
||||||
|
name,
|
||||||
|
url = None,
|
||||||
|
review = None):
|
||||||
|
self.name = name
|
||||||
|
self.url = url
|
||||||
|
self.review = review
|
||||||
|
|
||||||
class Project(object):
|
class Project(object):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
@ -1061,16 +1068,10 @@ class Project(object):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
def _InitRemote(self):
|
def _InitRemote(self):
|
||||||
if self.remote.fetchUrl:
|
if self.remote.url:
|
||||||
remote = self.GetRemote(self.remote.name)
|
remote = self.GetRemote(self.remote.name)
|
||||||
|
remote.url = self.remote.url
|
||||||
url = self.remote.fetchUrl
|
remote.review = self.remote.review
|
||||||
while url.endswith('/'):
|
|
||||||
url = url[:-1]
|
|
||||||
url += '/%s.git' % self.name
|
|
||||||
remote.url = url
|
|
||||||
remote.review = self.remote.reviewUrl
|
|
||||||
if remote.projectname is None:
|
|
||||||
remote.projectname = self.name
|
remote.projectname = self.name
|
||||||
|
|
||||||
if self.worktree:
|
if self.worktree:
|
||||||
@ -1426,7 +1427,7 @@ class MetaProject(Project):
|
|||||||
name = name,
|
name = name,
|
||||||
gitdir = gitdir,
|
gitdir = gitdir,
|
||||||
worktree = worktree,
|
worktree = worktree,
|
||||||
remote = Remote('origin'),
|
remote = RemoteSpec('origin'),
|
||||||
relpath = '.repo/%s' % name,
|
relpath = '.repo/%s' % name,
|
||||||
revision = 'refs/heads/master')
|
revision = 'refs/heads/master')
|
||||||
|
|
||||||
|
22
remote.py
22
remote.py
@ -1,22 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright (C) 2008 The Android Open Source Project
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
class Remote(object):
|
|
||||||
def __init__(self, name,
|
|
||||||
fetch=None,
|
|
||||||
review=None):
|
|
||||||
self.name = name
|
|
||||||
self.fetchUrl = fetch
|
|
||||||
self.reviewUrl = review
|
|
@ -19,7 +19,6 @@ import sys
|
|||||||
from color import Coloring
|
from color import Coloring
|
||||||
from command import InteractiveCommand, MirrorSafeCommand
|
from command import InteractiveCommand, MirrorSafeCommand
|
||||||
from error import ManifestParseError
|
from error import ManifestParseError
|
||||||
from remote import Remote
|
|
||||||
from project import SyncBuffer
|
from project import SyncBuffer
|
||||||
from git_command import git, MIN_GIT_VERSION
|
from git_command import git, MIN_GIT_VERSION
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user