Move manifest config logic into ManifestProject

Use ManifestProject properties for config values.

Change-Id: Ib4ad90b0d9a089916e35615b8058942e6d01dc04
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/334519
Tested-by: LaMont Jones <lamontjones@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
diff --git a/git_superproject.py b/git_superproject.py
index 299d253..f4dbb27 100644
--- a/git_superproject.py
+++ b/git_superproject.py
@@ -406,7 +406,7 @@
   if opt.use_superproject is not None:
     return opt.use_superproject
   else:
-    client_value = manifest.manifestProject.config.GetBoolean('repo.superproject')
+    client_value = manifest.manifestProject.use_superproject
     if client_value is not None:
       return client_value
     else:
diff --git a/manifest_xml.py b/manifest_xml.py
index d3e952a..022cad2 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -372,7 +372,7 @@
     # normal repo settings live in the manifestProject which we just setup
     # above, so we couldn't easily query before that.  We assume Project()
     # init doesn't care if this changes afterwards.
-    if os.path.exists(mp.gitdir) and mp.config.GetBoolean('repo.worktree'):
+    if os.path.exists(mp.gitdir) and mp.use_worktree:
       mp.use_git_worktrees = True
 
     self._Unload()
@@ -487,7 +487,7 @@
     mp = self.manifestProject
 
     if groups is None:
-      groups = mp.config.GetString('manifest.groups')
+      groups = mp.manifest_groups
     if groups:
       groups = self._ParseList(groups)
 
@@ -861,22 +861,21 @@
 
   @property
   def CloneBundle(self):
-    clone_bundle = self.manifestProject.config.GetBoolean('repo.clonebundle')
+    clone_bundle = self.manifestProject.clone_bundle
     if clone_bundle is None:
-      return False if self.manifestProject.config.GetBoolean('repo.partialclone') else True
+      return False if self.manifestProject.partial_clone else True
     else:
       return clone_bundle
 
   @property
   def CloneFilter(self):
-    if self.manifestProject.config.GetBoolean('repo.partialclone'):
-      return self.manifestProject.config.GetString('repo.clonefilter')
+    if self.manifestProject.partial_clone:
+      return self.manifestProject.clone_filter
     return None
 
   @property
   def PartialCloneExclude(self):
-    exclude = self.manifest.manifestProject.config.GetString(
-        'repo.partialcloneexclude') or ''
+    exclude = self.manifest.manifestProject.partial_clone_exclude or ''
     return set(x.strip() for x in exclude.split(','))
 
   @property
@@ -897,23 +896,23 @@
 
   @property
   def IsMirror(self):
-    return self.manifestProject.config.GetBoolean('repo.mirror')
+    return self.manifestProject.mirror
 
   @property
   def UseGitWorktrees(self):
-    return self.manifestProject.config.GetBoolean('repo.worktree')
+    return self.manifestProject.use_worktree
 
   @property
   def IsArchive(self):
-    return self.manifestProject.config.GetBoolean('repo.archive')
+    return self.manifestProject.archive
 
   @property
   def HasSubmodules(self):
-    return self.manifestProject.config.GetBoolean('repo.submodules')
+    return self.manifestProject.submodules
 
   @property
   def EnableGitLfs(self):
-    return self.manifestProject.config.GetBoolean('repo.git-lfs')
+    return self.manifestProject.git_lfs
 
   def FindManifestByPath(self, path):
     """Returns the manifest containing path."""
@@ -965,7 +964,7 @@
 
   def GetGroupsStr(self):
     """Returns the manifest group string that should be synced."""
-    groups = self.manifestProject.config.GetString('manifest.groups')
+    groups = self.manifestProject.manifest_groups
     if not groups:
       groups = self.GetDefaultGroupsStr()
     return groups
diff --git a/project.py b/project.py
index 43cac88..2989e09 100644
--- a/project.py
+++ b/project.py
@@ -16,6 +16,7 @@
 import filecmp
 import glob
 import os
+import platform
 import random
 import re
 import shutil
@@ -1162,7 +1163,7 @@
     if self.clone_depth:
       depth = self.clone_depth
     else:
-      depth = self.manifest.manifestProject.config.GetString('repo.depth')
+      depth = self.manifest.manifestProject.depth
 
     # See if we can skip the network fetch entirely.
     if not (optimized_fetch and
@@ -1179,7 +1180,7 @@
         return False
 
     mp = self.manifest.manifestProject
-    dissociate = mp.config.GetBoolean('repo.dissociate')
+    dissociate = mp.dissociate
     if dissociate:
       alternates_file = os.path.join(self.objdir, 'objects/info/alternates')
       if os.path.exists(alternates_file):
@@ -2282,9 +2283,7 @@
     return ok
 
   def _ApplyCloneBundle(self, initial=False, quiet=False, verbose=False):
-    if initial and \
-        (self.manifest.manifestProject.config.GetString('repo.depth') or
-         self.clone_depth):
+    if initial and (self.manifest.manifestProject.depth or self.clone_depth):
       return False
 
     remote = self.GetRemote(self.remote.name)
@@ -2513,7 +2512,7 @@
 
       if init_git_dir:
         mp = self.manifest.manifestProject
-        ref_dir = mp.config.GetString('repo.reference') or ''
+        ref_dir = mp.reference or ''
 
         def _expanded_ref_dirs():
           """Iterate through the possible git reference directory paths."""
@@ -3359,17 +3358,92 @@
                       capture_stderr=True).Wait() == 0
 
   @property
+  def standalone_manifest_url(self):
+    """The URL of the standalone manifest, or None."""
+    return self.config.getString('manifest.standalone')
+
+  @property
+  def manifest_groups(self):
+    """The manifest groups string."""
+    return self.config.GetString('manifest.groups')
+
+  @property
+  def reference(self):
+    """The --reference for this manifest."""
+    self.config.GetString('repo.reference')
+
+  @property
+  def dissociate(self):
+    """Whether to dissociate."""
+    self.config.GetBoolean('repo.dissociate')
+
+  @property
+  def archive(self):
+    """Whether we use archive."""
+    self.config.GetBoolean('repo.archive')
+
+  @property
+  def mirror(self):
+    """Whether we use mirror."""
+    self.config.GetBoolean('repo.mirror')
+
+  @property
+  def use_worktree(self):
+    """Whether we use worktree."""
+    self.config.GetBoolean('repo.worktree')
+
+  @property
+  def clone_bundle(self):
+    """Whether we use clone_bundle."""
+    self.config.GetBoolean('repo.clonebundle')
+
+  @property
+  def submodules(self):
+    """Whether we use submodules."""
+    self.config.GetBoolean('repo.submodules')
+
+  @property
+  def git_lfs(self):
+    """Whether we use git_lfs."""
+    self.config.GetBoolean('repo.git-lfs')
+
+  @property
+  def use_superproject(self):
+    """Whether we use superproject."""
+    self.config.GetBoolean('repo.superproject')
+
+  @property
+  def partial_clone(self):
+    """Whether this is a partial clone."""
+    self.config.GetBoolean('repo.partialclone')
+
+  @property
+  def depth(self):
+    """Partial clone depth."""
+    self.config.GetString('repo.depth')
+
+  @property
+  def clone_filter(self):
+    """The clone filter."""
+    self.config.GetString('repo.clonefilter')
+
+  @property
+  def partial_clone_exclude(self):
+    """Partial clone exclude string"""
+    self.config.GetBoolean('repo.partialcloneexclude')
+
+  @property
   def _platform_name(self):
     """Return the name of the platform."""
     return platform.system().lower()
 
   def Sync(self, _kwargs_only=(), manifest_url='', manifest_branch=None,
-           standalone_manifest=False, groups='', platform='', mirror=False,
-           dissociate=False, reference='', worktree=False, submodules=False,
-           archive=False, partial_clone=None, clone_filter='blob:none',
+           standalone_manifest=False, groups='', mirror=False, reference='',
+           dissociate=False, worktree=False, submodules=False, archive=False,
+           partial_clone=None, depth=None, clone_filter='blob:none',
            partial_clone_exclude=None, clone_bundle=None, git_lfs=None,
            use_superproject=None, verbose=False, current_branch_only=False,
-           tags='', depth=None):
+           platform='', tags=''):
     """Sync the manifest and all submanifests.
 
     Args:
@@ -3379,8 +3453,6 @@
           file.
       groups: a string, restricts the checkout to projects with the specified
           groups.
-      platform: a string, restrict the checkout to projects with the specified
-          platform group.
       mirror: a boolean, whether to create a mirror of the remote repository.
       reference: a string, location of a repo instance to use as a reference.
       dissociate: a boolean, whether to dissociate from reference mirrors after
@@ -3391,6 +3463,7 @@
       archive: a boolean, whether to checkout each project as an archive.  See
           git-archive.
       partial_clone: a boolean, whether to perform a partial clone.
+      depth: an int, how deep of a shallow clone to create.
       clone_filter: a string, filter to use with partial_clone.
       partial_clone_exclude : a string, comma-delimeted list of project namess
           to exclude from partial clone.
@@ -3401,8 +3474,9 @@
       verbose: a boolean, whether to show all output, rather than only errors.
       current_branch_only: a boolean, whether to only fetch the current manifest
           branch from the server.
+      platform: a string, restrict the checkout to projects with the specified
+          platform group.
       tags: a boolean, whether to fetch tags.,
-      depth: an int, how deep of a shallow clone to create.
 
     Returns:
       a boolean, whether the sync was successful.
@@ -3493,11 +3567,11 @@
         else:
           self.PreSync()
 
-    groups = re.split(r'[,\s]+', groups)
+    groups = re.split(r'[,\s]+', groups or '')
     all_platforms = ['linux', 'darwin', 'windows']
     platformize = lambda x: 'platform-' + x
     if platform == 'auto':
-      if (not mirror and not self.config.GetString('repo.mirror') == 'true'):
+      if not mirror and not self.mirror:
         groups.append(platformize(self._platform_name))
     elif platform == 'all':
       groups.extend(map(platformize, all_platforms))
@@ -3561,8 +3635,8 @@
       self.config.SetBoolean('repo.partialclone', partial_clone)
       if clone_filter:
         self.config.SetString('repo.clonefilter', clone_filter)
-    elif self.config.GetBoolean('repo.partialclone'):
-      clone_filter = self.config.GetString('repo.clonefilter')
+    elif self.partialclone:
+      clone_filter = self.clone_filter
     else:
       clone_filter = None
 
diff --git a/subcmds/init.py b/subcmds/init.py
index b6c891a..13085fa 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -345,7 +345,7 @@
     self._SyncManifest(opt)
     self._LinkManifest(opt.manifest_name)
 
-    if self.manifest.manifestProject.config.GetBoolean('repo.superproject'):
+    if self.manifest.manifestProject.use_superproject:
       self._CloneSuperproject(opt)
 
     if os.isatty(0) and os.isatty(1) and not self.manifest.IsMirror:
diff --git a/subcmds/sync.py b/subcmds/sync.py
index f5584dc..c165515 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -976,7 +976,7 @@
               file=sys.stderr)
 
     mp = self.manifest.manifestProject
-    is_standalone_manifest = mp.config.GetString('manifest.standalone')
+    is_standalone_manifest = bool(mp.standalone_manifest_url)
     if not is_standalone_manifest:
       mp.PreSync()