gitplier.kernel

1from ._commit import  KernelCommit, KernelStableCommit, KernelRHELCommit
2from ._repository import KernelRepository, KernelStableRepository, KernelRHELRepository
3
4__all__ = [
5    'KernelCommit', 'KernelStableCommit', 'KernelRHELCommit',
6    'KernelRepository', 'KernelStableRepository', 'KernelRHELRepository',
7]
class KernelCommit(gitplier._commit.Commit):
 7class KernelCommit(Commit):
 8    """A commit from the kernel tree. If `body` is present, `fixes` will be present as well.
 9    It is a list (possibly empty) of shas of commits there are fixed by this commit. Note the
10    shas will be abbreviated and may not point to an existing commit; they're just parsed from
11    the commit description."""
12
13    def _set_field(self, field: str, value: str) -> None:
14        if field == 'body':
15            self.fixes = re.findall(r'^Fixes: ([0-9a-f]{8,40}) \(".*"\)$', value,
16                                    re.MULTILINE)
17        super()._set_field(field, value)

A commit from the kernel tree. If body is present, fixes will be present as well. It is a list (possibly empty) of shas of commits there are fixed by this commit. Note the shas will be abbreviated and may not point to an existing commit; they're just parsed from the commit description.

class KernelStableCommit(gitplier.kernel.KernelCommit):
20class KernelStableCommit(KernelCommit):
21    """A commit from the kernel stable tree. Contains an upstream reference in the `upstream`
22    attribute. For stable specific commits, `upstream` is None. Also contains the `fixes`
23    attribute; see `KernelCommit` for details."""
24
25    def __init__(self) -> None:
26        """The constructor is private. Never create instances directly; access them via
27        methods of KernelStableRepository."""
28        self.upstream: Optional[str] = None
29        self.fixes: list[str] = []
30
31    def _set_field(self, field: str, value: str) -> None:
32        if field == 'body':
33            first_line = value.split('\n', maxsplit=1)[0]
34            m = re.fullmatch(r'commit ([0-9a-f]{40}) upstream\.', first_line)
35            if m is None:
36                m = re.fullmatch(r'\[ Upstream commit ([0-9a-f]{40}) \]', first_line)
37            if m is not None:
38                self.upstream = m[1]
39        super()._set_field(field, value)

A commit from the kernel stable tree. Contains an upstream reference in the upstream attribute. For stable specific commits, upstream is None. Also contains the fixes attribute; see KernelCommit for details.

KernelStableCommit()
25    def __init__(self) -> None:
26        """The constructor is private. Never create instances directly; access them via
27        methods of KernelStableRepository."""
28        self.upstream: Optional[str] = None
29        self.fixes: list[str] = []

The constructor is private. Never create instances directly; access them via methods of KernelStableRepository.

upstream: Optional[str]
fixes: list[str]
class KernelRHELCommit(gitplier._commit.Commit):
42class KernelRHELCommit(Commit):
43    """A commit from a RHEL or a CentOS Stream kernel repository. Contains a list of upstream
44    references in the `upstream` attribute. If no upstream references are detected, `upstream`
45    is []. For commits that are explicitly marked as RHEL only, `rhel_only` is True. For
46    commits that are explicitly marked as posted, `posted` is the link (or the free text that
47    the developer entered). The list of fixed commits is in the `fixes` attribute; see
48    `KernelCommit` for details and note it's undefined whether the shas are for RHEL or
49    an upstream kernel."""
50
51    def __init__(self) -> None:
52        """The constructor is private. Never create instances directly; access them via
53        methods of KernelRHELRepository."""
54        self.upstream: list[str] = []
55        self.rhel_only = False
56        self.posted: Optional[str] = None
57        self.fixes: list[str] = []
58
59    def _set_field(self, field: str, value: str) -> None:
60        if field == 'body':
61            upstream_refs = re.findall(r'^commit ([0-9a-f]{40})(?: \(.*\))?$|^\(cherry picked from commit ([0-9a-f]{40})\)$',
62                                       value, re.MULTILINE)
63            self.upstream = list(set(a or b for a, b in upstream_refs))
64            m = re.search(r'^upstream(?:[ -]status)?: *rhel[ -]*[0-9.]*[ -]only', value,
65                          re.MULTILINE | re.IGNORECASE)
66            self.rhel_only = m is not None
67            if not self.rhel_only:
68                m = re.search(r'^upstream(?:[ -]status)?: *posted *(.*)$', value,
69                              re.MULTILINE | re.IGNORECASE)
70                if m is not None:
71                    self.posted = m[1]
72            self.fixes = re.findall(r'^(?:    )?Fixes: ([0-9a-f]{8,40}) \(".*"\)$', value,
73                                    re.MULTILINE)
74        super()._set_field(field, value)

A commit from a RHEL or a CentOS Stream kernel repository. Contains a list of upstream references in the upstream attribute. If no upstream references are detected, upstream is []. For commits that are explicitly marked as RHEL only, rhel_only is True. For commits that are explicitly marked as posted, posted is the link (or the free text that the developer entered). The list of fixed commits is in the fixes attribute; see KernelCommit for details and note it's undefined whether the shas are for RHEL or an upstream kernel.

KernelRHELCommit()
51    def __init__(self) -> None:
52        """The constructor is private. Never create instances directly; access them via
53        methods of KernelRHELRepository."""
54        self.upstream: list[str] = []
55        self.rhel_only = False
56        self.posted: Optional[str] = None
57        self.fixes: list[str] = []

The constructor is private. Never create instances directly; access them via methods of KernelRHELRepository.

upstream: list[str]
rhel_only
posted: Optional[str]
fixes: list[str]
class KernelRepository(gitplier._repository.Repository):
10class KernelRepository(Repository):
11    """A kernel git repository. The parameter is a file system path."""
12    _COMMIT_TYPE = KernelCommit
13
14    def in_version(self, id: str, *, include_rc: bool = False) -> Optional[str]:
15        """Returns the kernel version where the given `id` got merged. If `include_rc` is
16        True, include also the "-rcX" part of the version. If the given `id` does not exist
17        or is not a part of any version, return None. Warning: this is a slow operation."""
18        args = ('--match', 'v[1-9]*.*', '--contains', id)
19        try:
20            ver = self._run_git('describe', args).rstrip()
21        except GitError:
22            return None
23        if not ver:
24            return None
25        ver = ver.split('~', maxsplit=1)[0]
26        ver = ver.split('^', maxsplit=1)[0]
27        if not include_rc:
28            ver = ver.split('-', maxsplit=1)[0]
29        return ver
30
31    def versions(self, *, include_rc: bool = False, include_stable: bool = False,
32                 since: Optional[str] = None) -> list[str]:
33        """Returns the list of kernel versions, sorted. If `include_rc` is True, also the -rc
34        versions are included. If `include_stable` is True and the repo is a stable repo,
35        the stable versions are included. If `since` is given, only versions starting from
36        this version (inclusive) are returned."""
37        versions = []
38        for ver in self.tags(patterns=['v[1-9]*.*']):
39            if '-' in ver.name:
40                # this is a -rc or similar
41                if not include_rc or '-rc' not in ver.name:
42                    continue
43            if not include_stable:
44                if ver.name.startswith('v2.'):
45                    if ver.name.count('.') >= 3:
46                        # this is a stable version
47                        continue
48                elif ver.name.count('.') >= 2:
49                    # this is a stable version
50                    continue
51            versions.append(ver.name)
52        versions = _natural_sort(versions)
53        if since:
54            versions = versions[versions.index(since) :]
55        return versions

A kernel git repository. The parameter is a file system path.

def in_version(self, id: str, *, include_rc: bool = False) -> Optional[str]:
14    def in_version(self, id: str, *, include_rc: bool = False) -> Optional[str]:
15        """Returns the kernel version where the given `id` got merged. If `include_rc` is
16        True, include also the "-rcX" part of the version. If the given `id` does not exist
17        or is not a part of any version, return None. Warning: this is a slow operation."""
18        args = ('--match', 'v[1-9]*.*', '--contains', id)
19        try:
20            ver = self._run_git('describe', args).rstrip()
21        except GitError:
22            return None
23        if not ver:
24            return None
25        ver = ver.split('~', maxsplit=1)[0]
26        ver = ver.split('^', maxsplit=1)[0]
27        if not include_rc:
28            ver = ver.split('-', maxsplit=1)[0]
29        return ver

Returns the kernel version where the given id got merged. If include_rc is True, include also the "-rcX" part of the version. If the given id does not exist or is not a part of any version, return None. Warning: this is a slow operation.

def versions( self, *, include_rc: bool = False, include_stable: bool = False, since: Optional[str] = None) -> list[str]:
31    def versions(self, *, include_rc: bool = False, include_stable: bool = False,
32                 since: Optional[str] = None) -> list[str]:
33        """Returns the list of kernel versions, sorted. If `include_rc` is True, also the -rc
34        versions are included. If `include_stable` is True and the repo is a stable repo,
35        the stable versions are included. If `since` is given, only versions starting from
36        this version (inclusive) are returned."""
37        versions = []
38        for ver in self.tags(patterns=['v[1-9]*.*']):
39            if '-' in ver.name:
40                # this is a -rc or similar
41                if not include_rc or '-rc' not in ver.name:
42                    continue
43            if not include_stable:
44                if ver.name.startswith('v2.'):
45                    if ver.name.count('.') >= 3:
46                        # this is a stable version
47                        continue
48                elif ver.name.count('.') >= 2:
49                    # this is a stable version
50                    continue
51            versions.append(ver.name)
52        versions = _natural_sort(versions)
53        if since:
54            versions = versions[versions.index(since) :]
55        return versions

Returns the list of kernel versions, sorted. If include_rc is True, also the -rc versions are included. If include_stable is True and the repo is a stable repo, the stable versions are included. If since is given, only versions starting from this version (inclusive) are returned.

class KernelStableRepository(gitplier.kernel.KernelRepository):
58class KernelStableRepository(KernelRepository):
59    """A kernel stable git repository. The parameter is a file system path. The returned
60    commits have `upstream` attribute present."""
61    _COMMIT_TYPE = KernelStableCommit
62    _FORCED_LOG_FIELDS = ('sha', 'body')
63
64    def stable_branches(self, *, since: Optional[str] = None) -> list[tuple[str, str]]:
65        """Return information about stable branches. The returned value is a list of tuples
66        `(branch_name, upstream_tag)`. The `branch_name` is the full stable branch name,
67        the `upstream_tag` is the upstream (vanilla) tag the branch is based on. The list
68        is sorted from the oldest version to the newest. If `since` is given, only branches
69        starting from this upstream version are returned."""
70        branches = {}
71        for b in self.branch_names(local=False, remote=True):
72            m = re.fullmatch(r'[^ /]*/linux-([1-9][0-9.]+)\.y', b)
73            if m is None:
74                continue
75            tag = f'v{m[1]}'
76            if not self.resolve(tag, 'tag'):
77                continue
78            key = tuple(map(int, m[1].split('.')))
79            branches[key] = (m[0], tag)
80        if since:
81            since = since.removeprefix('v')
82            since_expanded = tuple(map(int, since.split('.')))
83            return [branches[key] for key in sorted(branches.keys()) if key >= since_expanded]
84        else:
85            return [branches[key] for key in sorted(branches.keys())]

A kernel stable git repository. The parameter is a file system path. The returned commits have upstream attribute present.

def stable_branches(self, *, since: Optional[str] = None) -> list[tuple[str, str]]:
64    def stable_branches(self, *, since: Optional[str] = None) -> list[tuple[str, str]]:
65        """Return information about stable branches. The returned value is a list of tuples
66        `(branch_name, upstream_tag)`. The `branch_name` is the full stable branch name,
67        the `upstream_tag` is the upstream (vanilla) tag the branch is based on. The list
68        is sorted from the oldest version to the newest. If `since` is given, only branches
69        starting from this upstream version are returned."""
70        branches = {}
71        for b in self.branch_names(local=False, remote=True):
72            m = re.fullmatch(r'[^ /]*/linux-([1-9][0-9.]+)\.y', b)
73            if m is None:
74                continue
75            tag = f'v{m[1]}'
76            if not self.resolve(tag, 'tag'):
77                continue
78            key = tuple(map(int, m[1].split('.')))
79            branches[key] = (m[0], tag)
80        if since:
81            since = since.removeprefix('v')
82            since_expanded = tuple(map(int, since.split('.')))
83            return [branches[key] for key in sorted(branches.keys()) if key >= since_expanded]
84        else:
85            return [branches[key] for key in sorted(branches.keys())]

Return information about stable branches. The returned value is a list of tuples (branch_name, upstream_tag). The branch_name is the full stable branch name, the upstream_tag is the upstream (vanilla) tag the branch is based on. The list is sorted from the oldest version to the newest. If since is given, only branches starting from this upstream version are returned.

class KernelRHELRepository(gitplier._repository.Repository):
88class KernelRHELRepository(Repository):
89    """A RHEL or CentOS Stream kernel repository. The parameter is a file system path. The
90    returned commits have `upstream` attribute present."""
91    _COMMIT_TYPE = KernelRHELCommit
92    _FORCED_LOG_FIELDS = ('sha', 'body')

A RHEL or CentOS Stream kernel repository. The parameter is a file system path. The returned commits have upstream attribute present.