patman: Implement the upstream subcommand

Add a command to allow managing the upstream tree. This is very basic
so far, only allowing setting the name and URL. Further work may allow
checking whether series apply cleaning on the upstream tree, etc.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2025-05-10 13:05:16 +02:00
parent d1b6d855ac
commit cc6ce7157a
2 changed files with 71 additions and 0 deletions

View File

@ -25,6 +25,7 @@ ALIASES = {
'series': ['s', 'ser'],
'status': ['st'],
'patchwork': ['pw'],
'upstream': ['us'],
# Series aliases
'archive': ['ar'],
@ -372,6 +373,41 @@ def add_status_subparser(subparsers):
return status
def add_upstream_subparser(subparsers):
"""Add the 'status' subparser
Args:
subparsers (argparse action): Subparser parent
Return:
ArgumentParser: status subparser
"""
upstream = subparsers.add_parser('upstream', aliases=ALIASES['upstream'],
help='Manage upstream destinations')
upstream.defaults_cmds = [
['add', 'us', 'http://fred'],
['delete', 'us'],
]
upstream_subparsers = upstream.add_subparsers(dest='subcmd')
uadd = upstream_subparsers.add_parser('add')
uadd.add_argument('remote_name',
help="Git remote name used for this upstream, e.g. 'us'")
uadd.add_argument(
'url', help='URL to use for this upstream, e.g. '
"'https://gitlab.denx.de/u-boot/u-boot.git'")
udel = upstream_subparsers.add_parser('delete')
udel.add_argument(
'remote_name',
help="Git remote name used for this upstream, e.g. 'us'")
upstream_subparsers.add_parser('list')
udef = upstream_subparsers.add_parser('default')
udef.add_argument('-u', '--unset', action='store_true',
help='Unset the default upstream')
udef.add_argument('remote_name', nargs='?',
help="Git remote name used for this upstream, e.g. 'us'")
return upstream
def setup_parser():
"""Set up command-line parser
@ -413,6 +449,7 @@ def setup_parser():
patchwork = add_patchwork_subparser(subparsers)
series = add_series_subparser(subparsers)
add_status_subparser(subparsers)
upstream = add_upstream_subparser(subparsers)
# Only add the 'test' action if the test data files are available.
if HAS_TESTS:
@ -424,6 +461,7 @@ def setup_parser():
'main': parser,
'series': series,
'patchwork': patchwork,
'upstream': upstream,
}
return parsers

View File

@ -218,6 +218,37 @@ def do_series(args, test_db=None, pwork=None, cser=None):
cser.close_database()
def upstream(args, test_db=None):
"""Process an 'upstream' subcommand
Args:
args (Namespace): Arguments to process
test_db (str or None): Directory containing the test database, None to
use the normal one
"""
cser = cseries.Cseries(test_db)
try:
cser.open_database()
if args.subcmd == 'add':
cser.upstream_add(args.remote_name, args.url)
elif args.subcmd == 'default':
if args.unset:
cser.upstream_set_default(None)
elif args.remote_name:
cser.upstream_set_default(args.remote_name)
else:
result = cser.upstream_get_default()
print(result if result else 'unset')
elif args.subcmd == 'delete':
cser.upstream_delete(args.remote_name)
elif args.subcmd == 'list':
cser.upstream_list()
else:
raise ValueError(f"Unknown upstream subcommand '{args.subcmd}'")
finally:
cser.close_database()
def patchwork(args, test_db=None, pwork=None):
"""Process a 'patchwork' subcommand
Args:
@ -288,6 +319,8 @@ def do_patman(args, test_db=None, pwork=None, cser=None):
args.patchwork_url)
elif args.cmd == 'series':
do_series(args, test_db, pwork, cser)
elif args.cmd == 'upstream':
upstream(args, test_db)
elif args.cmd == 'patchwork':
patchwork(args, test_db, pwork)
except Exception as exc: