aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2024-03-20 14:24:20 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2024-03-20 14:24:20 -0400
commit14bf644c74114cb69672cafde9d8a0d8e80f6bfa (patch)
treebd2d4d2c543ed0d429a0dab84f6f8ea6e0500c07
parent98848133e0f058c579759b05d3f6287912118a84 (diff)
downloadb4-14bf644c74114cb69672cafde9d8a0d8e80f6bfa.tar.gz
ez: implement --edit-deps
Implement opening an editor to make changes to the dependencies. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--plan.otl4
-rw-r--r--src/b4/command.py2
-rw-r--r--src/b4/ez.py51
3 files changed, 55 insertions, 2 deletions
diff --git a/plan.otl b/plan.otl
index 713dd41..eed7309 100644
--- a/plan.otl
+++ b/plan.otl
@@ -6,8 +6,8 @@ v0.14
[X] Retrieve dependencies using the standard prerequisite-patch-id
[X] Define the prerequisite-change-id trailer
[X] Expand prerequisite-change-id into prerequisite-patch-id for locally sent series
- [_] Add b4 prep --edit-dependencies to open an editor with dependencies
- [_] Add b4 prep --check-dependencies to report if there are updates to prerequisite series
+ [X] Add b4 prep --edit-deps to open an editor with dependencies
+ [_] Add b4 prep --check-deps to report if there are problems or updates available
[_] Retrieve dependencies using preprequisite-change-id
[_] Dependency chaining (within reason)
diff --git a/src/b4/command.py b/src/b4/command.py
index 69f0593..adb49cd 100644
--- a/src/b4/command.py
+++ b/src/b4/command.py
@@ -300,6 +300,8 @@ def setup_parser() -> argparse.ArgumentParser:
help='Output prep-tracked commits as patches')
spp_g.add_argument('--edit-cover', action='store_true', default=False,
help='Edit the cover letter in your defined $EDITOR (or core.editor)')
+ spp_g.add_argument('--edit-deps', action='store_true', default=False,
+ help='Edit the series dependencies in your defined $EDITOR (or core.editor)')
spp_g.add_argument('--show-revision', action='store_true', default=False,
help='Show current series revision number')
spp_g.add_argument('--compare-to', metavar='vN',
diff --git a/src/b4/ez.py b/src/b4/ez.py
index 2f3cb87..35e5e0d 100644
--- a/src/b4/ez.py
+++ b/src/b4/ez.py
@@ -79,6 +79,28 @@ Range-diff versus v${oldrev}:
"""
+DEPS_HELP = """
+# All lines starting with # will be removed
+#
+# You can define series prerequisites using the following formats:
+#
+# patch-id: [patch-id as returned by git-patch-id --stable]
+# change-id: [the change-id of a series, followed by a colon and series version]
+# message-id: <[the message-id of a series]>
+#
+# IMPORTANT: specify all dependencies in the order they must be applied
+#
+# For example:
+# ------------
+# patch-id: 7709c0eec24c2c0c973d6af92c7915b8d0a2e52c
+# change-id: 20240320-example-change-id:v1
+# change-id: 20240320-some-other-example-change-id:v5
+# message-id: <20240320-some-prereq-series-v1-0@example.com>
+#
+# All dependencies will be checked and converted into prerequisite-patch-id: entries
+# during "b4 send".
+"""
+
def get_auth_configs() -> Tuple[str, str, str, str, str, str]:
config = b4.get_main_config()
@@ -751,6 +773,32 @@ def edit_cover() -> None:
logger.info('Cover letter updated.')
+def edit_deps() -> None:
+ cover, tracking = load_cover()
+ prereqs = tracking['series'].get('prerequisites', list())
+ deps = '\n'.join(prereqs)
+ toedit = f'{deps}\n{DEPS_HELP}'
+ bdata = toedit.encode()
+ new_bdata = b4.edit_in_editor(bdata, filehint='prereqs.yaml')
+ if new_bdata == bdata:
+ logger.info('Dependencies unchanged.')
+ return
+ new_data = new_bdata.decode(errors='replace').strip()
+ prereqs = list()
+ if len(new_data):
+ for entry in new_data.split('\n'):
+ if entry.startswith('patch-id:') or entry.startswith('change-id:') or entry.startswith('message-id:'):
+ prereqs.append(entry)
+ elif entry.startswith('#'):
+ logger.debug('Ignoring comment: %s', entry)
+ else:
+ logger.critical('Unknown dependency format, ignored:')
+ logger.critical(entry)
+
+ tracking['series']['prerequisites'] = prereqs
+ store_cover(cover, tracking)
+
+
def get_series_start(usebranch: Optional[str] = None) -> str:
if usebranch:
mybranch = usebranch
@@ -2322,6 +2370,9 @@ def cmd_prep(cmdargs: argparse.Namespace) -> None:
if cmdargs.edit_cover:
return edit_cover()
+ if cmdargs.edit_deps:
+ return edit_deps()
+
def cmd_trailers(cmdargs: argparse.Namespace) -> None:
check_can_gfr()