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>
diff --git a/manifest_xml.py b/manifest_xml.py
index 4697653..5c5617a 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -18,8 +18,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 5ccf33e..53fd38e 100644
--- a/project.py
+++ b/project.py
@@ -26,7 +26,6 @@
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 @@
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 @@
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 @@
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 bb8f740..0000000
--- 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 90b76e8..0d0fcd0 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -19,7 +19,6 @@
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