[edk2-devel] [Edk2-staging/EdkRepo] [PATCH 2/2] EdkRepo: Add the edkrepo maintenance command

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


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 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>
---
 .../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



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#68327): https://edk2.groups.io/g/devel/message/68327
Mute This Topic: https://groups.io/mt/78703868/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