diff options
author | Trevor Gamblin <tgamblin@baylibre.com> | 2024-09-24 07:54:59 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-09-30 17:00:50 +0100 |
commit | d6ede9c73b44062d8831a08f522d519591bf29c2 (patch) | |
tree | 17711c77f409da9d7ed38361c9551e6bb6f967dd /meta/lib/patchtest/repo.py | |
parent | bb0f1625d7655d04c6df3c144e488f676ff2f762 (diff) | |
download | poky-d6ede9c73b44062d8831a08f522d519591bf29c2.tar.gz |
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 <tgamblin@baylibre.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/patchtest/repo.py')
-rw-r--r-- | meta/lib/patchtest/repo.py | 63 |
1 files changed, 14 insertions, 49 deletions
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 @@ | |||
8 | # SPDX-License-Identifier: GPL-2.0-only | 8 | # SPDX-License-Identifier: GPL-2.0-only |
9 | # | 9 | # |
10 | 10 | ||
11 | import os | ||
12 | import utils | ||
13 | import logging | ||
14 | import git | 11 | import git |
15 | from patch import PatchTestPatch | 12 | import os |
16 | 13 | import mbox | |
17 | logger = logging.getLogger('patchtest') | ||
18 | info=logger.info | ||
19 | 14 | ||
20 | class PatchTestRepo(object): | 15 | class PatchTestRepo(object): |
21 | 16 | ||
22 | # prefixes used for temporal branches/stashes | 17 | # prefixes used for temporal branches/stashes |
23 | prefix = 'patchtest' | 18 | prefix = 'patchtest' |
24 | 19 | ||
25 | |||
26 | def __init__(self, patch, repodir, commit=None, branch=None): | 20 | def __init__(self, patch, repodir, commit=None, branch=None): |
27 | self._repodir = repodir | 21 | self.repodir = repodir |
28 | self._repo = git.Repo.init(repodir) | 22 | self.repo = git.Repo.init(repodir) |
29 | self._patch = PatchTestPatch(patch) | 23 | self.patch = mbox.PatchSeries(patch) |
30 | self._current_branch = self._repo.active_branch.name | 24 | self.current_branch = self.repo.active_branch.name |
31 | 25 | ||
32 | # targeted branch defined on the patch may be invalid, so make sure there | 26 | # targeted branch defined on the patch may be invalid, so make sure there |
33 | # is a corresponding remote branch | 27 | # is a corresponding remote branch |
34 | valid_patch_branch = None | 28 | valid_patch_branch = None |
35 | if self._patch.branch in self._repo.branches: | 29 | if self.patch.branch in self.repo.branches: |
36 | valid_patch_branch = self._patch.branch | 30 | valid_patch_branch = self.patch.branch |
37 | 31 | ||
38 | # Target Branch | ||
39 | # Priority (top has highest priority): | ||
40 | # 1. branch given at cmd line | ||
41 | # 2. branch given at the patch | ||
42 | # 3. current branch | ||
43 | self._branch = branch or valid_patch_branch or self._current_branch | ||
44 | |||
45 | # Target Commit | 32 | # Target Commit |
46 | # Priority (top has highest priority): | 33 | # Priority (top has highest priority): |
47 | # 1. commit given at cmd line | 34 | # 1. commit given at cmd line |
@@ -57,7 +44,7 @@ class PatchTestRepo(object): | |||
57 | 44 | ||
58 | # create working branch. Use the '-B' flag so that we just | 45 | # create working branch. Use the '-B' flag so that we just |
59 | # check out the existing one if it's there | 46 | # check out the existing one if it's there |
60 | self._repo.git.execute(['git', 'checkout', '-B', self._workingbranch, self._commit]) | 47 | self.repo.git.execute(['git', 'checkout', '-B', self._workingbranch, self._commit]) |
61 | 48 | ||
62 | self._patchmerged = False | 49 | self._patchmerged = False |
63 | 50 | ||
@@ -65,35 +52,13 @@ class PatchTestRepo(object): | |||
65 | self._patchcanbemerged = True | 52 | self._patchcanbemerged = True |
66 | try: | 53 | try: |
67 | # Make sure to get the absolute path of the file | 54 | # Make sure to get the absolute path of the file |
68 | self._repo.git.execute(['git', 'apply', '--check', os.path.abspath(self._patch.path)], with_exceptions=True) | 55 | self.repo.git.execute(['git', 'apply', '--check', os.path.abspath(self.patch.path)], with_exceptions=True) |
69 | except git.exc.GitCommandError as ce: | 56 | except git.exc.GitCommandError as ce: |
70 | self._patchcanbemerged = False | 57 | self._patchcanbemerged = False |
71 | 58 | ||
72 | # for debugging purposes, print all repo parameters | ||
73 | logger.debug("Parameters") | ||
74 | logger.debug("\tRepository : %s" % self._repodir) | ||
75 | logger.debug("\tTarget Commit : %s" % self._commit) | ||
76 | logger.debug("\tTarget Branch : %s" % self._branch) | ||
77 | logger.debug("\tWorking branch : %s" % self._workingbranch) | ||
78 | logger.debug("\tPatch : %s" % self._patch) | ||
79 | |||
80 | @property | ||
81 | def patch(self): | ||
82 | return self._patch.path | ||
83 | |||
84 | @property | ||
85 | def branch(self): | ||
86 | return self._branch | ||
87 | |||
88 | @property | ||
89 | def commit(self): | ||
90 | return self._commit | ||
91 | |||
92 | @property | ||
93 | def ismerged(self): | 59 | def ismerged(self): |
94 | return self._patchmerged | 60 | return self._patchmerged |
95 | 61 | ||
96 | @property | ||
97 | def canbemerged(self): | 62 | def canbemerged(self): |
98 | return self._patchcanbemerged | 63 | return self._patchcanbemerged |
99 | 64 | ||
@@ -103,7 +68,7 @@ class PatchTestRepo(object): | |||
103 | return None | 68 | return None |
104 | 69 | ||
105 | try: | 70 | try: |
106 | return self._repo.rev_parse(commit).hexsha | 71 | return self.repo.rev_parse(commit).hexsha |
107 | except Exception as e: | 72 | except Exception as e: |
108 | print(f"Couldn't find commit {commit} in repo") | 73 | print(f"Couldn't find commit {commit} in repo") |
109 | 74 | ||
@@ -111,10 +76,10 @@ class PatchTestRepo(object): | |||
111 | 76 | ||
112 | def merge(self): | 77 | def merge(self): |
113 | if self._patchcanbemerged: | 78 | if self._patchcanbemerged: |
114 | self._repo.git.execute(['git', 'am', '--keep-cr', os.path.abspath(self._patch.path)]) | 79 | self.repo.git.execute(['git', 'am', '--keep-cr', os.path.abspath(self.patch.path)]) |
115 | self._patchmerged = True | 80 | self._patchmerged = True |
116 | 81 | ||
117 | def clean(self): | 82 | def clean(self): |
118 | self._repo.git.execute(['git', 'checkout', self._current_branch]) | 83 | self.repo.git.execute(['git', 'checkout', self.current_branch]) |
119 | self._repo.git.execute(['git', 'branch', '-D', self._workingbranch]) | 84 | self.repo.git.execute(['git', 'branch', '-D', self._workingbranch]) |
120 | self._patchmerged = False | 85 | self._patchmerged = False |