diff options
| author | LaMont Jones <lamontjones@google.com> | 2022-03-29 21:54:22 +0000 |
|---|---|---|
| committer | LaMont Jones <lamontjones@google.com> | 2022-03-31 21:02:52 +0000 |
| commit | 9b72cf2ba5c00bee726aa4bddbb84be554294284 (patch) | |
| tree | 9b9e34554a46c2af45a02f8f56366c50d7390efd | |
| parent | 5d3291d818ba479afc112370e3c5fc2dc0587d6e (diff) | |
| download | git-repo-9b72cf2ba5c00bee726aa4bddbb84be554294284.tar.gz | |
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>
| -rw-r--r-- | manifest_xml.py | 11 | ||||
| -rw-r--r-- | project.py | 59 |
2 files changed, 37 insertions, 33 deletions
diff --git a/manifest_xml.py b/manifest_xml.py index a14cc526..d3e952a5 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
| @@ -25,7 +25,8 @@ import gitc_utils | |||
| 25 | from git_config import GitConfig, IsId | 25 | from git_config import GitConfig, IsId |
| 26 | from git_refs import R_HEADS, HEAD | 26 | from git_refs import R_HEADS, HEAD |
| 27 | import platform_utils | 27 | import platform_utils |
| 28 | from project import Annotation, RemoteSpec, Project, MetaProject | 28 | from project import (Annotation, RemoteSpec, Project, RepoProject, |
| 29 | ManifestProject) | ||
| 29 | from error import (ManifestParseError, ManifestInvalidPathError, | 30 | from error import (ManifestParseError, ManifestInvalidPathError, |
| 30 | ManifestInvalidRevisionError) | 31 | ManifestInvalidRevisionError) |
| 31 | from wrapper import Wrapper | 32 | from wrapper import Wrapper |
| @@ -360,7 +361,7 @@ class XmlManifest(object): | |||
| 360 | # multi-tree. | 361 | # multi-tree. |
| 361 | self._outer_client = outer_client or self | 362 | self._outer_client = outer_client or self |
| 362 | 363 | ||
| 363 | self.repoProject = MetaProject(self, 'repo', | 364 | self.repoProject = RepoProject(self, 'repo', |
| 364 | gitdir=os.path.join(repodir, 'repo/.git'), | 365 | gitdir=os.path.join(repodir, 'repo/.git'), |
| 365 | worktree=os.path.join(repodir, 'repo')) | 366 | worktree=os.path.join(repodir, 'repo')) |
| 366 | 367 | ||
| @@ -953,9 +954,9 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
| 953 | def SubmanifestProject(self, submanifest_path): | 954 | def SubmanifestProject(self, submanifest_path): |
| 954 | """Return a manifestProject for a submanifest.""" | 955 | """Return a manifestProject for a submanifest.""" |
| 955 | subdir = self.SubmanifestInfoDir(submanifest_path) | 956 | subdir = self.SubmanifestInfoDir(submanifest_path) |
| 956 | mp = MetaProject(self, 'manifests', | 957 | mp = ManifestProject(self, 'manifests', |
| 957 | gitdir=os.path.join(subdir, 'manifests.git'), | 958 | gitdir=os.path.join(subdir, 'manifests.git'), |
| 958 | worktree=os.path.join(subdir, 'manifests')) | 959 | worktree=os.path.join(subdir, 'manifests')) |
| 959 | return mp | 960 | return mp |
| 960 | 961 | ||
| 961 | def GetDefaultGroupsStr(self): | 962 | def GetDefaultGroupsStr(self): |
| @@ -3284,9 +3284,7 @@ class SyncBuffer(object): | |||
| 3284 | 3284 | ||
| 3285 | 3285 | ||
| 3286 | class MetaProject(Project): | 3286 | class MetaProject(Project): |
| 3287 | 3287 | """A special project housed under .repo.""" | |
| 3288 | """A special project housed under .repo. | ||
| 3289 | """ | ||
| 3290 | 3288 | ||
| 3291 | def __init__(self, manifest, name, gitdir, worktree): | 3289 | def __init__(self, manifest, name, gitdir, worktree): |
| 3292 | Project.__init__(self, | 3290 | Project.__init__(self, |
| @@ -3310,33 +3308,9 @@ class MetaProject(Project): | |||
| 3310 | self.revisionExpr = base | 3308 | self.revisionExpr = base |
| 3311 | self.revisionId = None | 3309 | self.revisionId = None |
| 3312 | 3310 | ||
| 3313 | def MetaBranchSwitch(self, submodules=False): | ||
| 3314 | """ Prepare MetaProject for manifest branch switch | ||
| 3315 | """ | ||
| 3316 | |||
| 3317 | # detach and delete manifest branch, allowing a new | ||
| 3318 | # branch to take over | ||
| 3319 | syncbuf = SyncBuffer(self.config, detach_head=True) | ||
| 3320 | self.Sync_LocalHalf(syncbuf, submodules=submodules) | ||
| 3321 | syncbuf.Finish() | ||
| 3322 | |||
| 3323 | return GitCommand(self, | ||
| 3324 | ['update-ref', '-d', 'refs/heads/default'], | ||
| 3325 | capture_stdout=True, | ||
| 3326 | capture_stderr=True).Wait() == 0 | ||
| 3327 | |||
| 3328 | @property | ||
| 3329 | def LastFetch(self): | ||
| 3330 | try: | ||
| 3331 | fh = os.path.join(self.gitdir, 'FETCH_HEAD') | ||
| 3332 | return os.path.getmtime(fh) | ||
| 3333 | except OSError: | ||
| 3334 | return 0 | ||
| 3335 | |||
| 3336 | @property | 3311 | @property |
| 3337 | def HasChanges(self): | 3312 | def HasChanges(self): |
| 3338 | """Has the remote received new commits not yet checked out? | 3313 | """Has the remote received new commits not yet checked out?""" |
| 3339 | """ | ||
| 3340 | if not self.remote or not self.revisionExpr: | 3314 | if not self.remote or not self.revisionExpr: |
| 3341 | return False | 3315 | return False |
| 3342 | 3316 | ||
| @@ -3354,3 +3328,32 @@ class MetaProject(Project): | |||
| 3354 | elif self._revlist(not_rev(HEAD), revid): | 3328 | elif self._revlist(not_rev(HEAD), revid): |
| 3355 | return True | 3329 | return True |
| 3356 | return False | 3330 | return False |
| 3331 | |||
| 3332 | |||
| 3333 | class RepoProject(MetaProject): | ||
| 3334 | """The MetaProject for repo itself.""" | ||
| 3335 | |||
| 3336 | @property | ||
| 3337 | def LastFetch(self): | ||
| 3338 | try: | ||
| 3339 | fh = os.path.join(self.gitdir, 'FETCH_HEAD') | ||
| 3340 | return os.path.getmtime(fh) | ||
| 3341 | except OSError: | ||
| 3342 | return 0 | ||
| 3343 | |||
| 3344 | class ManifestProject(MetaProject): | ||
| 3345 | """The MetaProject for manifests.""" | ||
| 3346 | |||
| 3347 | def MetaBranchSwitch(self, submodules=False): | ||
| 3348 | """Prepare for manifest branch switch.""" | ||
| 3349 | |||
| 3350 | # detach and delete manifest branch, allowing a new | ||
| 3351 | # branch to take over | ||
| 3352 | syncbuf = SyncBuffer(self.config, detach_head=True) | ||
| 3353 | self.Sync_LocalHalf(syncbuf, submodules=submodules) | ||
| 3354 | syncbuf.Finish() | ||
| 3355 | |||
| 3356 | return GitCommand(self, | ||
| 3357 | ['update-ref', '-d', 'refs/heads/default'], | ||
| 3358 | capture_stdout=True, | ||
| 3359 | capture_stderr=True).Wait() == 0 | ||
