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 2/2] EdkRepo: Add the edkrepo maintenance command
Date: Thu,  3 Dec 2020 21:50:15 -0800	[thread overview]
Message-ID: <20201204055015.3432-3-ashley.e.desimone@intel.com> (raw)
In-Reply-To: <20201204055015.3432-1-ashley.e.desimone@intel.com>

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


  parent 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 ` [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 [this message]
2020-12-07 22:11 ` [Edk2-staging/EdkRepo] [PATCH 0/2] Edkrepo: Add the maintenance command 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-3-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