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:
Shawn O. Pearce 2009-05-19 14:58:02 -07:00
parent c8a300f639
commit d1f70d9929
4 changed files with 33 additions and 41 deletions

View File

@ -18,8 +18,7 @@ import sys
import xml.dom.minidom
from git_config import GitConfig, IsId
from project import Project, MetaProject, R_HEADS, HEAD
from remote import Remote
from project import RemoteSpec, Project, MetaProject, R_HEADS, HEAD
from error import ManifestParseError
MANIFEST_FILE_NAME = 'manifest.xml'
@ -31,6 +30,21 @@ class _Default(object):
revision = 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):
"""manages the repo configuration file"""
@ -257,7 +271,7 @@ class XmlManifest(object):
if name is None:
s = m_url.rindex('/') + 1
remote = Remote('origin', fetch = m_url[:s])
remote = _XmlRemote('origin', m_url[:s])
name = m_url[s:]
if name.endswith('.git'):
@ -268,7 +282,7 @@ class XmlManifest(object):
gitdir = os.path.join(self.topdir, '%s.git' % name)
project = Project(manifest = self,
name = name,
remote = remote,
remote = remote.ToRemoteSpec(name),
gitdir = gitdir,
worktree = None,
relpath = None,
@ -284,7 +298,7 @@ class XmlManifest(object):
review = node.getAttribute('review')
if review == '':
review = None
return Remote(name=name, fetch=fetch, review=review)
return _XmlRemote(name, fetch, review)
def _ParseDefault(self, node):
"""
@ -337,7 +351,7 @@ class XmlManifest(object):
project = Project(manifest = self,
name = name,
remote = remote,
remote = remote.ToRemoteSpec(name),
gitdir = gitdir,
worktree = worktree,
relpath = path,

View File

@ -26,7 +26,6 @@ from git_command import GitCommand
from git_config import GitConfig, IsId
from error import GitError, ImportError, UploadError
from error import ManifestInvalidRevisionError
from remote import Remote
from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M
@ -212,6 +211,14 @@ class _CopyFile:
except IOError:
_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):
def __init__(self,
@ -1061,16 +1068,10 @@ class Project(object):
raise
def _InitRemote(self):
if self.remote.fetchUrl:
if self.remote.url:
remote = self.GetRemote(self.remote.name)
url = self.remote.fetchUrl
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.url = self.remote.url
remote.review = self.remote.review
remote.projectname = self.name
if self.worktree:
@ -1426,7 +1427,7 @@ class MetaProject(Project):
name = name,
gitdir = gitdir,
worktree = worktree,
remote = Remote('origin'),
remote = RemoteSpec('origin'),
relpath = '.repo/%s' % name,
revision = 'refs/heads/master')

View File

@ -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

View File

@ -19,7 +19,6 @@ import sys
from color import Coloring
from command import InteractiveCommand, MirrorSafeCommand
from error import ManifestParseError
from remote import Remote
from project import SyncBuffer
from git_command import git, MIN_GIT_VERSION