From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web10.10443.1607061047846610334 for ; Thu, 03 Dec 2020 21:50:47 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: ashley.e.desimone@intel.com) IronPort-SDR: SeJgYueLFgF/9kSTJGunBrrwU8loVxtWLHQSngs6ZqzryBKfjnpaQo1pmPQf2G7hFDChVy02Hg CJ0oRw2xTDVQ== X-IronPort-AV: E=McAfee;i="6000,8403,9824"; a="161100983" X-IronPort-AV: E=Sophos;i="5.78,391,1599548400"; d="scan'208";a="161100983" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2020 21:50:44 -0800 IronPort-SDR: WmVa5HJgWHDv6dylj1WGsufE98pp9nRbcS0Heac594vXl4tFd1dpFsJTlqqFWhC13HI+7dYdbB JtechUQrHyBA== X-IronPort-AV: E=Sophos;i="5.78,391,1599548400"; d="scan'208";a="540566774" Received: from aedesimo-desk.amr.corp.intel.com ([10.254.71.13]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2020 21:50:44 -0800 From: "Ashley E Desimone" To: devel@edk2.groups.io Cc: Nate DeSimone , Puja Pandya , Bret Barkelew , Prince Agyeman , Erik Bjorge Subject: [Edk2-staging/EdkRepo] [PATCH 1/2] EdkRepo: Move git config clean up function to a common location Date: Thu, 3 Dec 2020 21:50:14 -0800 Message-Id: <20201204055015.3432-2-ashley.e.desimone@intel.com> X-Mailer: git-send-email 2.27.0.windows.1 In-Reply-To: <20201204055015.3432-1-ashley.e.desimone@intel.com> References: <20201204055015.3432-1-ashley.e.desimone@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This commit moves the functionality to clean unneeded include if entries from the global git config to a common location and updates the sync command to import this content. Cc: Ashley E Desimone Cc: Nate DeSimone Cc: Puja Pandya Cc: Bret Barkelew Cc: Prince Agyeman Cc: Erik Bjorge Signed-off-by: Ashley E Desimone --- edkrepo/commands/sync_command.py | 27 +++----------- .../git_config_maintenance.py | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 edkrepo/common/workspace_maintenance/git_config_maintenance.py diff --git a/edkrepo/commands/sync_command.py b/edkrepo/commands/sync_command.py index 9b438ad..25c7430 100644 --- a/edkrepo/commands/sync_command.py +++ b/edkrepo/commands/sync_command.py @@ -41,6 +41,7 @@ from edkrepo.common.common_repo_functions import update_repo_commit_template, ge from edkrepo.common.common_repo_functions import has_primary_repo_remote, fetch_from_primary_repo, in_sync_with_primary from edkrepo.common.common_repo_functions import update_hooks, combinations_in_manifest from edkrepo.common.common_repo_functions import write_included_config, remove_included_config +from edkrepo.common.workspace_maintenance.git_config_maintenance import clean_git_globalconfig from edkrepo.common.workspace_maintenance.workspace_maintenance import generate_name_for_obsolete_backup from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import pull_workspace_manifest_repo from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import find_source_manifest_repo @@ -104,7 +105,7 @@ class SyncCommand(EdkrepoCommand): if not args.update_local_manifest: self.__check_for_new_manifest(args, config, initial_manifest, workspace_path, global_manifest_directory) check_dirty_repos(initial_manifest, workspace_path) - + # Determine if sparse checkout needs to be disabled for this operation sparse_settings = initial_manifest.sparse_settings sparse_enabled = sparse_checkout_enabled(workspace_path, initial_sources) @@ -118,7 +119,7 @@ class SyncCommand(EdkrepoCommand): reset_sparse_checkout(workspace_path, initial_sources) # Get the latest manifest if requested - if args.update_local_manifest: # NOTE: hyphens in arg name replaced with underscores due to argparse + if args.update_local_manifest: # NOTE: hyphens in arg name replaced with underscores due to argparse self.__update_local_manifest(args, config, initial_manifest, workspace_path, global_manifest_directory) manifest = get_workspace_manifest() if args.update_local_manifest: @@ -152,7 +153,7 @@ class SyncCommand(EdkrepoCommand): # Update submodule configuration if not args.update_local_manifest: #Performance optimization, __update_local_manifest() will do this self.__check_submodule_config(workspace_path, manifest, repo_sources_to_sync) - self.__clean_git_globalconfig() + clean_git_globalconfig() for repo_to_sync in repo_sources_to_sync: local_repo_path = os.path.join(workspace_path, repo_to_sync.root) # Update any hooks @@ -453,22 +454,4 @@ class SyncCommand(EdkrepoCommand): finally: gitglobalconfig.release() - def __clean_git_globalconfig(self): - global_gitconfig_path = os.path.normpath(expanduser("~/.gitconfig")) - with git.GitConfigParser(global_gitconfig_path, read_only=False) as git_globalconfig: - includeif_regex = re.compile('^includeIf "gitdir:(/.+)/"$') - for section in git_globalconfig.sections(): - data = includeif_regex.match(section) - if data: - gitrepo_path = data.group(1) - gitconfig_path = git_globalconfig.get(section, 'path') - if sys.platform == "win32": - gitrepo_path = gitrepo_path[1:] - gitconfig_path = gitconfig_path[1:] - gitrepo_path = os.path.normpath(gitrepo_path) - gitconfig_path = os.path.normpath(gitconfig_path) - (repo_manifest_path, _) = os.path.split(gitconfig_path) - repo_manifest_path = os.path.join(repo_manifest_path, "Manifest.xml") - if not os.path.isdir(gitrepo_path) and not os.path.isfile(gitconfig_path): - if not os.path.isfile(repo_manifest_path): - git_globalconfig.remove_section(section) + diff --git a/edkrepo/common/workspace_maintenance/git_config_maintenance.py b/edkrepo/common/workspace_maintenance/git_config_maintenance.py new file mode 100644 index 0000000..a90f95d --- /dev/null +++ b/edkrepo/common/workspace_maintenance/git_config_maintenance.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +# +## @file +# git_config_maintenance.py +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +import os +import re +import sys + +import git + +from edkrepo.common.pathfix import expanduser + +def clean_git_globalconfig(): + global_gitconfig_path = os.path.normpath(expanduser("~/.gitconfig")) + with git.GitConfigParser(global_gitconfig_path, read_only=False) as git_globalconfig: + includeif_regex = re.compile('^includeIf "gitdir:(/.+)/"$') + for section in git_globalconfig.sections(): + data = includeif_regex.match(section) + if data: + gitrepo_path = data.group(1) + gitconfig_path = git_globalconfig.get(section, 'path') + if sys.platform == "win32": + gitrepo_path = gitrepo_path[1:] + gitconfig_path = gitconfig_path[1:] + gitrepo_path = os.path.normpath(gitrepo_path) + gitconfig_path = os.path.normpath(gitconfig_path) + (repo_manifest_path, _) = os.path.split(gitconfig_path) + repo_manifest_path = os.path.join(repo_manifest_path, "Manifest.xml") + if not os.path.isdir(gitrepo_path) and not os.path.isfile(gitconfig_path): + if not os.path.isfile(repo_manifest_path): + git_globalconfig.remove_section(section) \ No newline at end of file -- 2.27.0.windows.1