From 78725ba63b2f48bd0f0a3f716908966773f36f8f Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Mon, 25 Jul 2022 16:59:15 -0400 Subject: ez-send: initial support for tagging sent revisions After we sent off the revision, create the structure in the tree that would allow us to go back to that revision regardless of what changes we make to the working branch. This is tricky for the default "commit" strategy, because we want to remove the cover letter from the history and store its final version in the tag applied to the tip commit. For this, we create a detached head, cherry-pick the range without the cover, and then tag the resulting detached head. Future work will make it possible to prep and send these as pull requests. Signed-off-by: Konstantin Ryabitsev --- b4/ez.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/b4/ez.py b/b4/ez.py index 3ffc4a3..3e6581c 100644 --- a/b4/ez.py +++ b/b4/ez.py @@ -785,7 +785,7 @@ def cmd_ez_send(cmdargs: argparse.Namespace) -> None: topdir = b4.git_get_toplevel() getm = os.path.join(topdir, 'scripts', 'get_maintainer.pl') if os.access(getm, os.X_OK): - logger.debug('Using kernel get_maintainer.pl for to and cc list') + logger.info('Using kernel get_maintainer.pl for to and cc lists') tocmdstr = f'{getm} --nogit --nogit-fallback --nogit-chief-penguins --norolestats --nol' cccmdstr = f'{getm} --nogit --nogit-fallback --nogit-chief-penguins --norolestats --nom' if tocmdstr: @@ -922,6 +922,54 @@ def cmd_ez_send(cmdargs: argparse.Namespace) -> None: else: logger.info('Sent %s messages', counter) + mybranch = b4.git_get_current_branch() + if get_cover_strategy() == 'commit': + # Detach the head at our parent commit and apply the cover-less series + cover_commit = find_cover_commit() + gitargs = ['checkout', f'{cover_commit}~1'] + ecode, out = b4.git_run_command(None, gitargs) + if ecode > 0: + # TODO: do something + raise RuntimeError('Could not switch to a detached head') + # cherry-pick from cover letter to the last commit + last_commit = patches[-1][0] + gitargs = ['cherry-pick', f'{cover_commit}..{last_commit}'] + ecode, out = b4.git_run_command(None, gitargs) + if ecode > 0: + # TODO: do something + raise RuntimeError('Could not cherry-pick the cover-less range') + # Find out the head commit + gitargs = ['rev-parse', 'HEAD'] + ecode, out = b4.git_run_command(None, gitargs) + if ecode > 0: + # TODO: do something + raise RuntimeError('Could not find the HEAD commit of the detached head') + tagcommit = out.strip() + # Switch back to our branch + gitargs = ['checkout', mybranch] + ecode, out = b4.git_run_command(None, gitargs) + if ecode > 0: + # TODO: do something + raise RuntimeError('Could not switch back to %s', mybranch) + else: + # TODO: commit-tip will have HEAD~1 + tagcommit = 'HEAD' + + # TODO: make sent/ prefix configurable? + tagprefix = 'sent/' + if mybranch.startswith('b4/'): + tagname = f'{tagprefix}{mybranch[3:]}-v{revision}' + else: + tagname = f'{tagprefix}{mybranch}-v{revision}' + + # TODO: check if we already have this tag for some reason + logger.info('Tagging %s', tagname) + gitargs = ['tag', '-a', '-F', '-', tagname, tagcommit] + ecode, out = b4.git_run_command(None, gitargs, stdin=cover.encode()) + if ecode > 0: + # TODO: do something + raise RuntimeError('Could not tag %s as %s', tagcommit, tagname) + if not cover_msgid: return -- cgit v1.2.3