diff options
author | 2022-05-04 20:08:36 +0300 | |
---|---|---|
committer | 2022-05-05 20:27:49 +0300 | |
commit | 9ed5db0a2c63c105feefb124d290949f54a1a86c (patch) | |
tree | 1c83187bdf43e199bb7ea2f4a4fc992723a813b0 /src/pkgdev/scripts | |
parent | Add documentation for configuration (diff) | |
download | pkgdev-9ed5db0a2c63c105feefb124d290949f54a1a86c.tar.gz pkgdev-9ed5db0a2c63c105feefb124d290949f54a1a86c.tar.bz2 pkgdev-9ed5db0a2c63c105feefb124d290949f54a1a86c.zip |
pkgdev manifest: add --if-modified
Restrict targets for manifest to only targets that have uncommitted
modifications.
Resolves: https://github.com/pkgcore/pkgdev/issues/65
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
Diffstat (limited to 'src/pkgdev/scripts')
-rw-r--r-- | src/pkgdev/scripts/pkgdev_manifest.py | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/src/pkgdev/scripts/pkgdev_manifest.py b/src/pkgdev/scripts/pkgdev_manifest.py index 26f6534..76dc69a 100644 --- a/src/pkgdev/scripts/pkgdev_manifest.py +++ b/src/pkgdev/scripts/pkgdev_manifest.py @@ -1,11 +1,13 @@ import os +import re +import subprocess from pkgcore.operations import observer as observer_mod from pkgcore.restrictions import packages from pkgcore.util.parserestrict import parse_match from snakeoil.cli import arghparse -from .. import cli +from .. import cli, git from .argparsers import cwd_repo_argparser manifest = cli.ArgumentParser( @@ -43,17 +45,21 @@ manifest_opts.add_argument( default because manifest generation is often performed when adding new ebuilds with distfiles that aren't on Gentoo mirrors yet. """) +manifest_opts.add_argument( + '--if-modified', dest='if_modified', help='Only check packages that have uncommitted modifications', + action='store_true', + docs=""" + In addition to matching the specified restriction, restrict to targets + which are marked as modified by git, including untracked files. + """) -@manifest.bind_final_check -def _manifest_validate(parser, namespace): - targets = namespace.target if namespace.target else [namespace.cwd] +def _restrict_targets(repo, targets): restrictions = [] - for target in targets: if os.path.exists(target): try: - restrictions.append(namespace.repo.path_restrict(target)) + restrictions.append(repo.path_restrict(target)) except ValueError as e: manifest.error(e) else: @@ -61,8 +67,29 @@ def _manifest_validate(parser, namespace): restrictions.append(parse_match(target)) except ValueError: manifest.error(f'invalid atom: {target!r}') + return packages.OrRestriction(*restrictions) + + +def _restrict_modified_files(repo): + ebuild_re = re.compile(r'^[ MTARC?]{2} (?P<path>[^/]+/[^/]+/[^/]+\.ebuild)$') + p = git.run('status', '--porcelain=v1', '-z', "*.ebuild", + cwd=repo.location, stdout=subprocess.PIPE) + + restrictions = [] + for line in p.stdout.strip('\x00').split('\x00'): + if mo := ebuild_re.match(line): + restrictions.append(repo.path_restrict(mo.group('path'))) + return packages.OrRestriction(*restrictions) + + +@manifest.bind_final_check +def _manifest_validate(parser, namespace): + targets = namespace.target if namespace.target else [namespace.cwd] - namespace.restriction = packages.OrRestriction(*restrictions) + namespace.restriction = _restrict_targets(namespace.repo, targets) + if namespace.if_modified: + namespace.restriction = packages.AndRestriction(namespace.restriction, + _restrict_modified_files(namespace.repo)) @manifest.bind_main_func |