mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
project: Isolate ManifestProject from RepoProject
Create RepoProject and ManifestProject, inheriting from MetaProject, with methods separated for isolation and clarity. Change-Id: Ic1d6efc65c99470290fea612e2abaf8670d199f4 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/334139 Tested-by: LaMont Jones <lamontjones@google.com> Reviewed-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
parent
5d3291d818
commit
9b72cf2ba5
@ -25,7 +25,8 @@ import gitc_utils
|
|||||||
from git_config import GitConfig, IsId
|
from git_config import GitConfig, IsId
|
||||||
from git_refs import R_HEADS, HEAD
|
from git_refs import R_HEADS, HEAD
|
||||||
import platform_utils
|
import platform_utils
|
||||||
from project import Annotation, RemoteSpec, Project, MetaProject
|
from project import (Annotation, RemoteSpec, Project, RepoProject,
|
||||||
|
ManifestProject)
|
||||||
from error import (ManifestParseError, ManifestInvalidPathError,
|
from error import (ManifestParseError, ManifestInvalidPathError,
|
||||||
ManifestInvalidRevisionError)
|
ManifestInvalidRevisionError)
|
||||||
from wrapper import Wrapper
|
from wrapper import Wrapper
|
||||||
@ -360,7 +361,7 @@ class XmlManifest(object):
|
|||||||
# multi-tree.
|
# multi-tree.
|
||||||
self._outer_client = outer_client or self
|
self._outer_client = outer_client or self
|
||||||
|
|
||||||
self.repoProject = MetaProject(self, 'repo',
|
self.repoProject = RepoProject(self, 'repo',
|
||||||
gitdir=os.path.join(repodir, 'repo/.git'),
|
gitdir=os.path.join(repodir, 'repo/.git'),
|
||||||
worktree=os.path.join(repodir, 'repo'))
|
worktree=os.path.join(repodir, 'repo'))
|
||||||
|
|
||||||
@ -953,9 +954,9 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
|
|||||||
def SubmanifestProject(self, submanifest_path):
|
def SubmanifestProject(self, submanifest_path):
|
||||||
"""Return a manifestProject for a submanifest."""
|
"""Return a manifestProject for a submanifest."""
|
||||||
subdir = self.SubmanifestInfoDir(submanifest_path)
|
subdir = self.SubmanifestInfoDir(submanifest_path)
|
||||||
mp = MetaProject(self, 'manifests',
|
mp = ManifestProject(self, 'manifests',
|
||||||
gitdir=os.path.join(subdir, 'manifests.git'),
|
gitdir=os.path.join(subdir, 'manifests.git'),
|
||||||
worktree=os.path.join(subdir, 'manifests'))
|
worktree=os.path.join(subdir, 'manifests'))
|
||||||
return mp
|
return mp
|
||||||
|
|
||||||
def GetDefaultGroupsStr(self):
|
def GetDefaultGroupsStr(self):
|
||||||
|
59
project.py
59
project.py
@ -3284,9 +3284,7 @@ class SyncBuffer(object):
|
|||||||
|
|
||||||
|
|
||||||
class MetaProject(Project):
|
class MetaProject(Project):
|
||||||
|
"""A special project housed under .repo."""
|
||||||
"""A special project housed under .repo.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, manifest, name, gitdir, worktree):
|
def __init__(self, manifest, name, gitdir, worktree):
|
||||||
Project.__init__(self,
|
Project.__init__(self,
|
||||||
@ -3310,33 +3308,9 @@ class MetaProject(Project):
|
|||||||
self.revisionExpr = base
|
self.revisionExpr = base
|
||||||
self.revisionId = None
|
self.revisionId = None
|
||||||
|
|
||||||
def MetaBranchSwitch(self, submodules=False):
|
|
||||||
""" Prepare MetaProject for manifest branch switch
|
|
||||||
"""
|
|
||||||
|
|
||||||
# detach and delete manifest branch, allowing a new
|
|
||||||
# branch to take over
|
|
||||||
syncbuf = SyncBuffer(self.config, detach_head=True)
|
|
||||||
self.Sync_LocalHalf(syncbuf, submodules=submodules)
|
|
||||||
syncbuf.Finish()
|
|
||||||
|
|
||||||
return GitCommand(self,
|
|
||||||
['update-ref', '-d', 'refs/heads/default'],
|
|
||||||
capture_stdout=True,
|
|
||||||
capture_stderr=True).Wait() == 0
|
|
||||||
|
|
||||||
@property
|
|
||||||
def LastFetch(self):
|
|
||||||
try:
|
|
||||||
fh = os.path.join(self.gitdir, 'FETCH_HEAD')
|
|
||||||
return os.path.getmtime(fh)
|
|
||||||
except OSError:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def HasChanges(self):
|
def HasChanges(self):
|
||||||
"""Has the remote received new commits not yet checked out?
|
"""Has the remote received new commits not yet checked out?"""
|
||||||
"""
|
|
||||||
if not self.remote or not self.revisionExpr:
|
if not self.remote or not self.revisionExpr:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -3354,3 +3328,32 @@ class MetaProject(Project):
|
|||||||
elif self._revlist(not_rev(HEAD), revid):
|
elif self._revlist(not_rev(HEAD), revid):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class RepoProject(MetaProject):
|
||||||
|
"""The MetaProject for repo itself."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def LastFetch(self):
|
||||||
|
try:
|
||||||
|
fh = os.path.join(self.gitdir, 'FETCH_HEAD')
|
||||||
|
return os.path.getmtime(fh)
|
||||||
|
except OSError:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
class ManifestProject(MetaProject):
|
||||||
|
"""The MetaProject for manifests."""
|
||||||
|
|
||||||
|
def MetaBranchSwitch(self, submodules=False):
|
||||||
|
"""Prepare for manifest branch switch."""
|
||||||
|
|
||||||
|
# detach and delete manifest branch, allowing a new
|
||||||
|
# branch to take over
|
||||||
|
syncbuf = SyncBuffer(self.config, detach_head=True)
|
||||||
|
self.Sync_LocalHalf(syncbuf, submodules=submodules)
|
||||||
|
syncbuf.Finish()
|
||||||
|
|
||||||
|
return GitCommand(self,
|
||||||
|
['update-ref', '-d', 'refs/heads/default'],
|
||||||
|
capture_stdout=True,
|
||||||
|
capture_stderr=True).Wait() == 0
|
||||||
|
Loading…
Reference in New Issue
Block a user