[edk2-devel] [Edk2-staging/EdkRepo] [PATCH 1/2] EdkRepo: Move git config clean up function to a common location

Ashley E Desimone ashley.e.desimone at intel.com
Fri Dec 4 05:50:14 UTC 2020


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 <ashley.e.desimone at intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone at intel.com>
Cc: Puja Pandya <puja.pandya at intel.com>
Cc: Bret Barkelew <Bret.Barkelew at microsoft.com>
Cc: Prince Agyeman <prince.agyeman at intel.com>
Cc: Erik Bjorge <erik.c.bjorge at intel.com>
Signed-off-by: Ashley E Desimone <ashley.e.desimone at intel.com>
---
 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.<BR>
+# 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



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#68328): https://edk2.groups.io/g/devel/message/68328
Mute This Topic: https://groups.io/mt/78703869/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list