From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com []) by mx.groups.io with SMTP id smtpd.web12.10472.1607061047330862554 for ; Thu, 03 Dec 2020 21:50:47 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: ashley.e.desimone@intel.com) IronPort-SDR: DGZ12Yq1wIXKsDsfiZeyikXKLaPrfG8fb3IoOmAT+GZO0R7L7g1QFQo2sjMS1XI3BwTJQhitfW GST1WN8aIXAA== X-IronPort-AV: E=McAfee;i="6000,8403,9824"; a="161100984" X-IronPort-AV: E=Sophos;i="5.78,391,1599548400"; d="scan'208";a="161100984" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2020 21:50:44 -0800 IronPort-SDR: GYQVENtaY5ZA0TGdVp38suKT8Wh7ThkUky8xD2PCdUgBNRiwRqoRvPM3HEVyHACG6EnEIsX7V+ a0GzsUly1s2Q== X-IronPort-AV: E=Sophos;i="5.78,391,1599548400"; d="scan'208";a="540566778" Received: from aedesimo-desk.amr.corp.intel.com ([10.254.71.13]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2020 21:50:44 -0800 From: "Ashley E Desimone" To: devel@edk2.groups.io Cc: Nate DeSimone , Puja Pandya , Bret Barkelew , Prince Agyeman , Erik Bjorge Subject: [Edk2-staging/EdkRepo] [PATCH 2/2] EdkRepo: Add the edkrepo maintenance command Date: Thu, 3 Dec 2020 21:50:15 -0800 Message-Id: <20201204055015.3432-3-ashley.e.desimone@intel.com> X-Mailer: git-send-email 2.27.0.windows.1 In-Reply-To: <20201204055015.3432-1-ashley.e.desimone@intel.com> References: <20201204055015.3432-1-ashley.e.desimone@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Nate DeSimone Cc: Puja Pandya Cc: Bret Barkelew Cc: Prince Agyeman Cc: Erik Bjorge Signed-off-by: Ashley E Desimone --- .../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.
+# 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.
+# 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.
+# 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