prep, diff: support passing arguments to range-diff
v3 cover prep, diff: support passing arguments to range-diff
Add --range-diff-opts to diff and prep to pass additional options to the git range-diff command. It can be useful when the output of git range-diff needs adjustments, such as modifying the creation factor.
Examples:
b4 --debug prep --compare-to v1 --range-diff-opts "--creation-factor=80 --no-dual-color" b4 diff --range-diff-opts "--creation-factor=80" [email protected]
---
Changes in v3:
- Fix erroneous commit titles and descriptions.
- Merge doc commit in corresponding prep/diff commits.
- Fix an issue with diff.py's rd_opts array not handled correctly.
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- As suggested by Konstantin, change "--creation-factor" to "--range-diff-opts" to be able to add git range-diff arguments more generally.
- Add a commit to document the option.
- Link to v1: https://patch.msgid.link/[email protected]
---
Antonin Godard (2):
diff: support passing arguments to git range-diff
prep: support passing arguments to git range-diff
docs/contributor/prep.rst | 6 ++++++ docs/maintainer/diff.rst | 5 +++++ src/b4/command.py | 4 ++++ src/b4/diff.py | 12 ++++++++++-- src/b4/ez.py | 9 +++++++-- 5 files changed, 32 insertions(+), 4 deletions(-)
---
base-commit: 42535902a457332560d860608b770fca9eea1382
change-id: 20250127-creation-factor-ce8069a0bb3c
Best regards,
Signature · 1 line
Antonin Godard <[email protected]>
PATCH v3 1/2 diff: support passing arguments to git range-diff
Add a --range-diff-opts argument to allow passing arguments to git range-diff when comparing commit ranges. This can be especially useful to override the creation factor or adjusting options that affect the behavior of this command.
--- docs/maintainer/diff.rst | 5 +++++ src/b4/command.py | 2 ++ src/b4/diff.py | 12 ++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-)
docs/maintainer/diff.rst +5 -0
@@ -42,6 +42,11 @@ Optional flags Compares two mbox files prepared by ``b4 am`` instead of querying the public-inbox server directly. +``--range-diff-opts RANGE_DIFF_OPTS`` + Additional arguments passed to ``git range-diff``. For example:: + + b4 diff --range-diff-opts "--creation-factor=80 --no-dual-color" <url> + ``-o OUTDIFF, --output-diff OUTDIFF`` **(DEPRECATED)** Sends ``range-diff`` output into a file. You should use ``-n`` instead and redirect output from the actual ``git range-diff``
src/b4/command.py +2 -0
@@ -286,6 +286,8 @@ def setup_parser() -> argparse.ArgumentParser: help='Force color output even when writing to file') sp_diff.add_argument('-m', '--compare-am-mboxes', dest='ambox', nargs=2, default=None, help='Compare two mbx files prepared with "b4 am"') + sp_diff.add_argument('--range-diff-opts', default=None, + help='Arguments passed to git range-diff') sp_diff.set_defaults(func=cmd_diff) # b4 kr
src/b4/diff.py +10 -2
@@ -16,6 +16,7 @@ import email.parser import shutil import pathlib import argparse +import shlex from typing import Tuple, Optional, List
@@ -156,7 +157,14 @@ def main(cmdargs: argparse.Namespace) -> None: logger.critical('---') logger.critical('Could not create fake-am range for upper series v%s', user.revision) sys.exit(1) - grdcmd = 'git range-diff %.12s..%.12s %.12s..%.12s' % (lsc, lec, usc, uec) + rd_opts = [] + if cmdargs.range_diff_opts: + sp = shlex.shlex(cmdargs.range_diff_opts, posix=True) + sp.whitespace_split = True + rd_opts = list(sp) + grdcmd = 'git range-diff %s%.12s..%.12s %.12s..%.12s' % ( + " ".join(rd_opts) + " " if rd_opts else "", + lsc, lec, usc, uec) if cmdargs.nodiff: logger.info('Success, to compare v%s and v%s:', lser.revision, user.revision) logger.info(f' {grdcmd}')
@@ -164,7 +172,7 @@ def main(cmdargs: argparse.Namespace) -> None: logger.info('---') logger.info('Diffing v%s and v%s', lser.revision, user.revision) logger.info(' Running: %s', grdcmd) - gitargs = ['range-diff', f'{lsc}..{lec}', f'{usc}..{uec}'] + gitargs = ['range-diff'] + rd_opts + [f'{lsc}..{lec}', f'{usc}..{uec}'] if cmdargs.outdiff is None or cmdargs.color: gitargs.append('--color') ecode, rdiff = b4.git_run_command(cmdargs.gitdir, gitargs)
Signature · 1 line
2.47.0
PATCH v3 2/2 prep: support passing arguments to git range-diff
In reply to Antonin GodardLike the previous commit ("diff: support passing arguments to git range-diff"), make it possible to pass additional options to git range-diff, which can be useful to modify the command's behavior.
--- docs/contributor/prep.rst | 6 ++++++ src/b4/command.py | 2 ++ src/b4/ez.py | 9 +++++++-- 3 files changed, 15 insertions(+), 2 deletions(-)
docs/contributor/prep.rst +6 -0
@@ -494,3 +494,9 @@ modifying defaults for some of these flags. ``-e ENROLL_BASE, --enroll ENROLL_BASE`` Enrolls your current branch to be b4-prep managed. Requires the name of the branch to use as the fork-point tracking base. + +``--range-diff-opts RANGE_DIFF_OPTS`` + Additional arguments passed to ``git range-diff`` when comparing series with + ``--compare-to``. For example:: + + b4 prep --compare-to v1 --range-diff-opts "--creation-factor=80 --no-dual-color"
src/b4/command.py +2 -0
@@ -309,6 +309,8 @@ def setup_parser() -> argparse.ArgumentParser: help='Additional prefixes to add to those already defined') sp_prep.add_argument('-C', '--no-cache', dest='nocache', action='store_true', default=False, help='Do not use local cache when performing remote queries') + sp_prep.add_argument('--range-diff-opts', default=None, type=str, + help='Arguments passed to git range-diff when comparing series') spp_g = sp_prep.add_mutually_exclusive_group() spp_g.add_argument('-p', '--format-patch', metavar='OUTPUT_DIR',
src/b4/ez.py +7 -2
@@ -2550,7 +2550,7 @@ def force_revision(forceto: int) -> None: store_cover(cover, tracking) -def compare(compareto: str, execvp: bool = True) -> Union[str, None]: +def compare(compareto: str, execvp: bool = True, range_diff_opts: str = None) -> Union[str, None]: cover, tracking = load_cover() # Try the new format first tagname, revision = get_sent_tagname(tracking['series']['change-id'], SENT_TAG_PREFIX, compareto)
@@ -2580,6 +2580,11 @@ def compare(compareto: str, execvp: bool = True) -> Union[str, None]: lines = b4.git_get_command_lines(None, gitargs) curr_end = lines[0] grdcmd = ['git', 'range-diff', '%.12s..%.12s' % (prev_start, prev_end), '%.12s..%.12s' % (curr_start, curr_end)] + if range_diff_opts: + sp = shlex.shlex(range_diff_opts, posix=True) + sp.whitespace_split = True + rd_opts = list(sp) + grdcmd = grdcmd + rd_opts logger.debug('Running %s', ' '.join(grdcmd)) if execvp: # We exec range-diff and let it take over
@@ -2792,7 +2797,7 @@ def cmd_prep(cmdargs: argparse.Namespace) -> None: return format_patch(cmdargs.format_patch) if cmdargs.compare_to: - return compare(cmdargs.compare_to) + return compare(cmdargs.compare_to, range_diff_opts=cmdargs.range_diff_opts) if cmdargs.enroll_base and cmdargs.new_series_name: logger.critical('CRITICAL: -n NEW_SERIES_NAME and -e [ENROLL_BASE] can not be used together.')
Signature · 1 line
2.47.0
Konstantin Ryabitsev
AppliedQuoted 9 lines · Antonin Godard
Add --range-diff-opts to diff and prep to pass additional options to the git range-diff command. It can be useful when the output of git range-diff needs adjustments, such as modifying the creation factor.
Examples:
b4 --debug prep --compare-to v1 --range-diff-opts "--creation-factor=80 --no-dual-color" b4 diff --range-diff-opts "--creation-factor=80" [email protected][...]
Applied, thanks!
[1/2] diff: support passing arguments to git range-diff
commit: 3c7fbc395fc6599c83cb6c8cfc796c9ee9ab43f0
[2/2] prep: support passing arguments to git range-diff
commit: eb4a66b12bc424854f453493dc627436952b3573Best regards,
Signature · 1 line
Konstantin Ryabitsev <[email protected]>