From 9b72cf2ba5c00bee726aa4bddbb84be554294284 Mon Sep 17 00:00:00 2001 From: LaMont Jones Date: Tue, 29 Mar 2022 21:54:22 +0000 Subject: 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 Reviewed-by: Mike Frysinger --- project.py | 59 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 28 deletions(-) (limited to 'project.py') diff --git a/project.py b/project.py index 480dac63..ed58c956 100644 --- a/project.py +++ b/project.py @@ -3284,9 +3284,7 @@ class SyncBuffer(object): class MetaProject(Project): - - """A special project housed under .repo. - """ + """A special project housed under .repo.""" def __init__(self, manifest, name, gitdir, worktree): Project.__init__(self, @@ -3310,33 +3308,9 @@ class MetaProject(Project): self.revisionExpr = base 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 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: return False @@ -3354,3 +3328,32 @@ class MetaProject(Project): elif self._revlist(not_rev(HEAD), revid): return True 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 -- cgit v1.2.3-54-g00ecf