From d1f70d9929ddd2748ccc9c1dd2f9603068e1f3e6 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 19 May 2009 14:58:02 -0700 Subject: [PATCH] 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 --- manifest_xml.py | 26 ++++++++++++++++++++------ project.py | 25 +++++++++++++------------ remote.py | 22 ---------------------- subcmds/init.py | 1 - 4 files changed, 33 insertions(+), 41 deletions(-) delete mode 100644 remote.py diff --git a/manifest_xml.py b/manifest_xml.py index 46976538..5c5617ac 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -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, diff --git a/project.py b/project.py index 5ccf33eb..53fd38ee 100644 --- a/project.py +++ b/project.py @@ -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,17 +1068,11 @@ 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.projectname = self.name + remote.url = self.remote.url + remote.review = self.remote.review + remote.projectname = self.name if self.worktree: remote.ResetFetch(mirror=False) @@ -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') diff --git a/remote.py b/remote.py deleted file mode 100644 index bb8f740c..00000000 --- a/remote.py +++ /dev/null @@ -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 diff --git a/subcmds/init.py b/subcmds/init.py index 90b76e8b..0d0fcd06 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -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