From d6ede9c73b44062d8831a08f522d519591bf29c2 Mon Sep 17 00:00:00 2001 From: Trevor Gamblin Date: Tue, 24 Sep 2024 07:54:59 -0400 Subject: patchtest: mbox.py: new data implementation Consolidate and improve some objects: - absorb utils.py functionality - repo.py: use mbox.py - repo.py: remove some cruft - utils.py: replace with logs.py - utils.py: delete - patch.py: delete - scripts/patchtest: use logging directly - general cleanup (From OE-Core rev: d4fbdb1d15f281b236137d63710c73bca8911a36) Signed-off-by: Trevor Gamblin Signed-off-by: Richard Purdie --- meta/lib/patchtest/repo.py | 63 +++++++++++----------------------------------- 1 file changed, 14 insertions(+), 49 deletions(-) (limited to 'meta/lib/patchtest/repo.py') diff --git a/meta/lib/patchtest/repo.py b/meta/lib/patchtest/repo.py index 5f361ac500..8ec8f68a0b 100644 --- a/meta/lib/patchtest/repo.py +++ b/meta/lib/patchtest/repo.py @@ -8,40 +8,27 @@ # SPDX-License-Identifier: GPL-2.0-only # -import os -import utils -import logging import git -from patch import PatchTestPatch - -logger = logging.getLogger('patchtest') -info=logger.info +import os +import mbox class PatchTestRepo(object): # prefixes used for temporal branches/stashes prefix = 'patchtest' - def __init__(self, patch, repodir, commit=None, branch=None): - self._repodir = repodir - self._repo = git.Repo.init(repodir) - self._patch = PatchTestPatch(patch) - self._current_branch = self._repo.active_branch.name + self.repodir = repodir + self.repo = git.Repo.init(repodir) + self.patch = mbox.PatchSeries(patch) + self.current_branch = self.repo.active_branch.name # targeted branch defined on the patch may be invalid, so make sure there # is a corresponding remote branch valid_patch_branch = None - if self._patch.branch in self._repo.branches: - valid_patch_branch = self._patch.branch + if self.patch.branch in self.repo.branches: + valid_patch_branch = self.patch.branch - # Target Branch - # Priority (top has highest priority): - # 1. branch given at cmd line - # 2. branch given at the patch - # 3. current branch - self._branch = branch or valid_patch_branch or self._current_branch - # Target Commit # Priority (top has highest priority): # 1. commit given at cmd line @@ -57,7 +44,7 @@ class PatchTestRepo(object): # create working branch. Use the '-B' flag so that we just # check out the existing one if it's there - self._repo.git.execute(['git', 'checkout', '-B', self._workingbranch, self._commit]) + self.repo.git.execute(['git', 'checkout', '-B', self._workingbranch, self._commit]) self._patchmerged = False @@ -65,35 +52,13 @@ class PatchTestRepo(object): self._patchcanbemerged = True try: # Make sure to get the absolute path of the file - self._repo.git.execute(['git', 'apply', '--check', os.path.abspath(self._patch.path)], with_exceptions=True) + self.repo.git.execute(['git', 'apply', '--check', os.path.abspath(self.patch.path)], with_exceptions=True) except git.exc.GitCommandError as ce: self._patchcanbemerged = False - # for debugging purposes, print all repo parameters - logger.debug("Parameters") - logger.debug("\tRepository : %s" % self._repodir) - logger.debug("\tTarget Commit : %s" % self._commit) - logger.debug("\tTarget Branch : %s" % self._branch) - logger.debug("\tWorking branch : %s" % self._workingbranch) - logger.debug("\tPatch : %s" % self._patch) - - @property - def patch(self): - return self._patch.path - - @property - def branch(self): - return self._branch - - @property - def commit(self): - return self._commit - - @property def ismerged(self): return self._patchmerged - @property def canbemerged(self): return self._patchcanbemerged @@ -103,7 +68,7 @@ class PatchTestRepo(object): return None try: - return self._repo.rev_parse(commit).hexsha + return self.repo.rev_parse(commit).hexsha except Exception as e: print(f"Couldn't find commit {commit} in repo") @@ -111,10 +76,10 @@ class PatchTestRepo(object): def merge(self): if self._patchcanbemerged: - self._repo.git.execute(['git', 'am', '--keep-cr', os.path.abspath(self._patch.path)]) + self.repo.git.execute(['git', 'am', '--keep-cr', os.path.abspath(self.patch.path)]) self._patchmerged = True def clean(self): - self._repo.git.execute(['git', 'checkout', self._current_branch]) - self._repo.git.execute(['git', 'branch', '-D', self._workingbranch]) + self.repo.git.execute(['git', 'checkout', self.current_branch]) + self.repo.git.execute(['git', 'branch', '-D', self._workingbranch]) self._patchmerged = False -- cgit v1.2.3-54-g00ecf