aboutsummaryrefslogtreecommitdiff
path: root/b4/__init__.py
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-12-11 18:00:19 -0500
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-12-11 18:00:19 -0500
commit7fd417718e2cde644fd6b6529ca30bfb10ba3a01 (patch)
tree6f647d8a28927ef08c3a7358137b19c026fbc115 /b4/__init__.py
parentc41f94b0f5c9ff2f56eae628b30d5b59f785481e (diff)
downloadb4-7fd417718e2cde644fd6b6529ca30bfb10ba3a01.tar.gz
Rework b4 pr exploder for transparency log needs
Two services we'll be running in the near future: 1. Transparency log for all pull requests 2. Auto-exploder for pull requests that can send auto-exploded patches to all the same recipients. This requires quite a bit more testing and refinement, but the core of the functionality is there. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Diffstat (limited to 'b4/__init__.py')
-rw-r--r--b4/__init__.py38
1 files changed, 28 insertions, 10 deletions
diff --git a/b4/__init__.py b/b4/__init__.py
index fecd9aa..05bd9bb 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -2001,21 +2001,33 @@ def git_get_command_lines(gitdir, args):
@contextmanager
-def git_temp_worktree(gitdir=None):
+def git_temp_worktree(gitdir=None, commitish=None):
"""Context manager that creates a temporary work tree and chdirs into it. The
worktree is deleted when the contex manager is closed. Taken from gj_tools."""
dfn = None
try:
with TemporaryDirectory() as dfn:
- git_run_command(gitdir, ['worktree', 'add', '--detach', '--no-checkout', dfn])
+ gitargs = ['worktree', 'add', '--detach', '--no-checkout', dfn]
+ if commitish:
+ gitargs.append(commitish)
+ git_run_command(gitdir, gitargs)
with in_directory(dfn):
- yield
+ yield dfn
finally:
if dfn is not None:
git_run_command(gitdir, ['worktree', 'remove', dfn])
@contextmanager
+def git_temp_clone(gitdir=None):
+ """Context manager that creates a temporary shared clone."""
+ with TemporaryDirectory() as dfn:
+ gitargs = ['clone', '--mirror', '--shared', gitdir, dfn]
+ git_run_command(None, gitargs)
+ yield dfn
+
+
+@contextmanager
def in_directory(dirname):
"""Context manager that chdirs into a directory and restores the original
directory when closed. Taken from gj_tools."""
@@ -2313,13 +2325,19 @@ def get_pi_thread_by_msgid(msgid, savefile, useproject=None, nocache=False):
return savefile
-def git_format_patches(gitdir, start, end, reroll=None):
- gitargs = ['format-patch', '--stdout']
- if reroll is not None:
- gitargs += ['-v', str(reroll)]
- gitargs += ['%s..%s' % (start, end)]
- ecode, out = git_run_command(gitdir, gitargs)
- return ecode, out
+@contextmanager
+def git_format_patches(gitdir, start, end, prefixes=None):
+ with TemporaryDirectory() as tmpd:
+ gitargs = ['format-patch', '--cover-letter', '-o', tmpd, '--signature', f'b4 {__VERSION__}']
+ if prefixes is not None and len(prefixes):
+ gitargs += ['--subject-prefix', ' '.join(prefixes)]
+ gitargs += ['%s..%s' % (start, end)]
+ ecode, out = git_run_command(gitdir, gitargs)
+ if ecode > 0:
+ logger.critical('ERROR: Could not convert pull request into patches')
+ logger.critical(out)
+ yield None
+ yield tmpd
def git_commit_exists(gitdir, commit_id):