From 7fd417718e2cde644fd6b6529ca30bfb10ba3a01 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Fri, 11 Dec 2020 18:00:19 -0500 Subject: 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 --- b4/__init__.py | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'b4/__init__.py') diff --git a/b4/__init__.py b/b4/__init__.py index fecd9aa..05bd9bb 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -2001,20 +2001,32 @@ 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 @@ -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): -- cgit v1.2.3