public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ashley E Desimone" <ashley.e.desimone@intel.com>
To: devel@edk2.groups.io
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>,
	Puja Pandya <puja.pandya@intel.com>,
	Bret Barkelew <Bret.Barkelew@microsoft.com>,
	Prince Agyeman <prince.agyeman@intel.com>,
	Erik Bjorge <erik.c.bjorge@intel.com>
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	[thread overview]
Message-ID: <20201204055015.3432-2-ashley.e.desimone@intel.com> (raw)
In-Reply-To: <20201204055015.3432-1-ashley.e.desimone@intel.com>

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


  reply	other threads:[~2020-12-04  5:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-04  5:50 [Edk2-staging/EdkRepo] [PATCH 0/2] Edkrepo: Add the maintenance command Ashley E Desimone
2020-12-04  5:50 ` Ashley E Desimone [this message]
2020-12-04  5:50 ` [Edk2-staging/EdkRepo] [PATCH 2/2] EdkRepo: Add the edkrepo " Ashley E Desimone
2020-12-07 22:11 ` [Edk2-staging/EdkRepo] [PATCH 0/2] Edkrepo: Add the " Nate DeSimone

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201204055015.3432-2-ashley.e.desimone@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox