public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Edk2-staging/EdkRepo] [PATCH 0/2] Edkrepo: Add the maintenance command
@ 2020-12-04  5:50 Ashley E Desimone
  2020-12-04  5:50 ` [Edk2-staging/EdkRepo] [PATCH 1/2] EdkRepo: Move git config clean up function to a common location Ashley E Desimone
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ashley E Desimone @ 2020-12-04  5:50 UTC (permalink / raw)
  To: devel
  Cc: Nate DeSimone, Puja Pandya, Bret Barkelew, Prince Agyeman,
	Erik Bjorge

This patch set add the maintenance command and its required support.
The maintenance command is intended to streamline workspace wide
maintenance operations such as git gc and configuration of the
git global config.

Patch 1 moves the functionality to clean unused insteadOf entires
from the git global config to a shared location and updates the sync
command accordingly.

Patch 2 adds the maintenance command, all strings used by the
maintenance command and support to configure the core.longpaths
setting in the git global config.

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>

Ashley E Desimone (2):
  EdkRepo: Move git config clean up function to a common location
  EdkRepo: Add the edkrepo maintenance command

 .../commands/arguments/maintenance_args.py    | 12 ++++
 edkrepo/commands/humble/maintenance_humble.py | 16 +++++
 edkrepo/commands/maintenance_command.py       | 71 +++++++++++++++++++
 edkrepo/commands/sync_command.py              | 27 ++-----
 .../git_config_maintenance.py                 | 43 +++++++++++
 5 files changed, 147 insertions(+), 22 deletions(-)
 create mode 100644 edkrepo/commands/arguments/maintenance_args.py
 create mode 100644 edkrepo/commands/humble/maintenance_humble.py
 create mode 100644 edkrepo/commands/maintenance_command.py
 create mode 100644 edkrepo/common/workspace_maintenance/git_config_maintenance.py

-- 
2.27.0.windows.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Edk2-staging/EdkRepo] [PATCH 1/2] EdkRepo: Move git config clean up function to a common location
  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
  2020-12-04  5:50 ` [Edk2-staging/EdkRepo] [PATCH 2/2] EdkRepo: Add the edkrepo maintenance command Ashley E Desimone
  2020-12-07 22:11 ` [Edk2-staging/EdkRepo] [PATCH 0/2] Edkrepo: Add the " Nate DeSimone
  2 siblings, 0 replies; 4+ messages in thread
From: Ashley E Desimone @ 2020-12-04  5:50 UTC (permalink / raw)
  To: devel
  Cc: Nate DeSimone, Puja Pandya, Bret Barkelew, Prince Agyeman,
	Erik Bjorge

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Edk2-staging/EdkRepo] [PATCH 2/2] EdkRepo: Add the edkrepo maintenance command
  2020-12-04  5:50 [Edk2-staging/EdkRepo] [PATCH 0/2] Edkrepo: Add the maintenance command Ashley E Desimone
  2020-12-04  5:50 ` [Edk2-staging/EdkRepo] [PATCH 1/2] EdkRepo: Move git config clean up function to a common location Ashley E Desimone
@ 2020-12-04  5:50 ` Ashley E Desimone
  2020-12-07 22:11 ` [Edk2-staging/EdkRepo] [PATCH 0/2] Edkrepo: Add the " Nate DeSimone
  2 siblings, 0 replies; 4+ messages in thread
From: Ashley E Desimone @ 2020-12-04  5:50 UTC (permalink / raw)
  To: devel
  Cc: Nate DeSimone, Puja Pandya, Bret Barkelew, Prince Agyeman,
	Erik Bjorge

Add the maintenance command to streamline workspace
and git global config mainteneance operations.
The command will remove unused insteadOf entries
and configure the longpaths setting in the global
config. The command will also run 'git reflog expire
--expire=now --all', 'git gc --aggressive --prune=now'
and 'git remote prune origin' for all repositories in
the workspace.

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>
---
 .../commands/arguments/maintenance_args.py    | 12 ++++
 edkrepo/commands/humble/maintenance_humble.py | 16 +++++
 edkrepo/commands/maintenance_command.py       | 71 +++++++++++++++++++
 .../git_config_maintenance.py                 |  9 ++-
 4 files changed, 107 insertions(+), 1 deletion(-)
 create mode 100644 edkrepo/commands/arguments/maintenance_args.py
 create mode 100644 edkrepo/commands/humble/maintenance_humble.py
 create mode 100644 edkrepo/commands/maintenance_command.py

diff --git a/edkrepo/commands/arguments/maintenance_args.py b/edkrepo/commands/arguments/maintenance_args.py
new file mode 100644
index 0000000..09571ff
--- /dev/null
+++ b/edkrepo/commands/arguments/maintenance_args.py
@@ -0,0 +1,12 @@
+#!/usr/bin/env python3
+#
+## @file
+# maintenance_args.py
+#
+# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+
+COMMAND_DESCRIPTION = 'Performs workspace wide maintenance operations'
+
+
diff --git a/edkrepo/commands/humble/maintenance_humble.py b/edkrepo/commands/humble/maintenance_humble.py
new file mode 100644
index 0000000..46e18b5
--- /dev/null
+++ b/edkrepo/commands/humble/maintenance_humble.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+#
+## @file
+# maintenance_humble.py
+#
+# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+
+LONGPATH_CONFIG = 'Configuring git longpaths support'
+CLEAN_INSTEAD_OFS = 'Removing unused "InsteadOf" entries from the git global config'
+NO_WOKKSPACE = 'Not currently in a valid workspace. No workspace level maintenance tasks will be completed.'
+REPO_MAINTENANCE = 'Currently conducting maintenance operations for the {} repository'
+GC_AGGRESSIVE = '   Running: git gc --aggressive --prune=now (this may take a significant amount of time)'
+REFLOG_EXPIRE = '   Running: git reflog expire --expire=now --all'
+REMOTE_PRUNE = '   Running: git remote prune origin'
\ No newline at end of file
diff --git a/edkrepo/commands/maintenance_command.py b/edkrepo/commands/maintenance_command.py
new file mode 100644
index 0000000..aff9d3b
--- /dev/null
+++ b/edkrepo/commands/maintenance_command.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python3
+#
+## @file
+# maintenance_command.py
+#
+# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+
+import os
+import sys
+
+import git
+from git import Repo
+
+from edkrepo.commands.edkrepo_command import EdkrepoCommand
+from edkrepo.commands.arguments import maintenance_args as arguments
+from edkrepo.commands.humble import maintenance_humble as humble
+from edkrepo.common.workspace_maintenance.git_config_maintenance import clean_git_globalconfig, set_long_path_support
+from edkrepo.common.edkrepo_exception import EdkrepoWorkspaceInvalidException
+from edkrepo.config.config_factory import get_workspace_path, get_workspace_manifest
+from edkrepo_manifest_parser.edk_manifest import ManifestXml
+
+
+class MaintenanceCommande(EdkrepoCommand):
+
+    def __init__(self):
+        super().__init__()
+
+    def get_metadata(self):
+        metadata = {}
+        metadata['name'] = 'maintenance'
+        metadata['help-text'] = arguments.COMMAND_DESCRIPTION
+        args = []
+        metadata['arguments'] = args
+        return metadata
+
+    def run_command(self, args, config):
+
+        # Configure git long path support
+        print(humble.LONGPATH_CONFIG)
+        set_long_path_support()
+        print()
+
+        # Remove unneeded instead of entries from git global config
+        print(humble.CLEAN_INSTEAD_OFS)
+        print()
+
+        # If in a valid workspace run the following for each repo:
+        # git reflog --expire, git gc, git remote prune origin
+        try:
+            workspace_path = get_workspace_path()
+        except EdkrepoWorkspaceInvalidException:
+            workspace_path - None
+            print(humble.NO_WOKKSPACE)
+            print()
+
+        if workspace_path:
+            manifest = get_workspace_manifest()
+            repos_to_maintain = manifest.get_repo_sources(manifest.general_config.current_combo)
+            for repo_to_maintain in repos_to_maintain:
+                local_repo_path = os.path.join(workspace_path, repo_to_maintain.root)
+                repo = Repo(local_repo_path)
+                print(humble.REPO_MAINTENANCE.format(repo_to_maintain.root))
+                print(humble.REFLOG_EXPIRE)
+                repo.git.reflog('expire', '--expire=now', '--all')
+                print(humble.GC_AGGRESSIVE)
+                repo.git.gc('--aggressive', '--prune=now')
+                print(humble.REMOTE_PRUNE)
+                repo.git.remote('prune', 'origin')
+                print()
diff --git a/edkrepo/common/workspace_maintenance/git_config_maintenance.py b/edkrepo/common/workspace_maintenance/git_config_maintenance.py
index a90f95d..4f8bc46 100644
--- a/edkrepo/common/workspace_maintenance/git_config_maintenance.py
+++ b/edkrepo/common/workspace_maintenance/git_config_maintenance.py
@@ -33,4 +33,11 @@ def clean_git_globalconfig():
                 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
+                        git_globalconfig.remove_section(section)
+
+def set_long_path_support():
+    global_git_config_path = os.path.normpath(expanduser("~/.gitconfig"))
+    with git.GitConfigParser(global_git_config_path, read_only=False) as git_globalconfig:
+        if 'core' not in git_globalconfig.sections():
+            git_globalconfig.add_section('core')
+        git_globalconfig.set('core', 'longpaths', 'true')
\ No newline at end of file
-- 
2.27.0.windows.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Edk2-staging/EdkRepo] [PATCH 0/2] Edkrepo: Add the maintenance command
  2020-12-04  5:50 [Edk2-staging/EdkRepo] [PATCH 0/2] Edkrepo: Add the maintenance command Ashley E Desimone
  2020-12-04  5:50 ` [Edk2-staging/EdkRepo] [PATCH 1/2] EdkRepo: Move git config clean up function to a common location Ashley E Desimone
  2020-12-04  5:50 ` [Edk2-staging/EdkRepo] [PATCH 2/2] EdkRepo: Add the edkrepo maintenance command Ashley E Desimone
@ 2020-12-07 22:11 ` Nate DeSimone
  2 siblings, 0 replies; 4+ messages in thread
From: Nate DeSimone @ 2020-12-07 22:11 UTC (permalink / raw)
  To: Desimone, Ashley E, devel@edk2.groups.io
  Cc: Pandya, Puja, Bret Barkelew, Agyeman, Prince, Bjorge, Erik C

For the series...

Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>

> -----Original Message-----
> From: Ashley E Desimone <ashley.e.desimone@intel.com>
> Sent: Thursday, December 3, 2020 9:50 PM
> To: devel@edk2.groups.io
> Cc: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Pandya, Puja
> <puja.pandya@intel.com>; Bret Barkelew <Bret.Barkelew@microsoft.com>;
> Agyeman, Prince <prince.agyeman@intel.com>; Bjorge, Erik C
> <erik.c.bjorge@intel.com>
> Subject: [Edk2-staging/EdkRepo] [PATCH 0/2] Edkrepo: Add the maintenance
> command
> 
> This patch set add the maintenance command and its required support.
> The maintenance command is intended to streamline workspace wide
> maintenance operations such as git gc and configuration of the git global
> config.
> 
> Patch 1 moves the functionality to clean unused insteadOf entires from the
> git global config to a shared location and updates the sync command
> accordingly.
> 
> Patch 2 adds the maintenance command, all strings used by the maintenance
> command and support to configure the core.longpaths setting in the git
> global config.
> 
> 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>
> 
> Ashley E Desimone (2):
>   EdkRepo: Move git config clean up function to a common location
>   EdkRepo: Add the edkrepo maintenance command
> 
>  .../commands/arguments/maintenance_args.py    | 12 ++++
>  edkrepo/commands/humble/maintenance_humble.py | 16 +++++
>  edkrepo/commands/maintenance_command.py       | 71
> +++++++++++++++++++
>  edkrepo/commands/sync_command.py              | 27 ++-----
>  .../git_config_maintenance.py                 | 43 +++++++++++
>  5 files changed, 147 insertions(+), 22 deletions(-)  create mode 100644
> edkrepo/commands/arguments/maintenance_args.py
>  create mode 100644 edkrepo/commands/humble/maintenance_humble.py
>  create mode 100644 edkrepo/commands/maintenance_command.py
>  create mode 100644
> edkrepo/common/workspace_maintenance/git_config_maintenance.py
> 
> --
> 2.27.0.windows.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-12-07 22:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-04  5:50 [Edk2-staging/EdkRepo] [PATCH 0/2] Edkrepo: Add the maintenance command Ashley E Desimone
2020-12-04  5:50 ` [Edk2-staging/EdkRepo] [PATCH 1/2] EdkRepo: Move git config clean up function to a common location Ashley E Desimone
2020-12-04  5:50 ` [Edk2-staging/EdkRepo] [PATCH 2/2] EdkRepo: Add the edkrepo maintenance command Ashley E Desimone
2020-12-07 22:11 ` [Edk2-staging/EdkRepo] [PATCH 0/2] Edkrepo: Add the " Nate DeSimone

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox