prep, diff: support adding range-diff arguments
v2 cover prep, diff: support adding range-diff arguments
git range-diff allows to override the creation factor, which is sometimes useful to adjust for seeing different diff outputs. This is not possible with the current code, and is also not configurable from git config.
Add an option to diff and prep to override the git range-diff arguments, such as --creation-factor.
Example:
b4 --debug prep --compare-to v1 --range-diff-opts "--creation-factor=80 --no-dual-color"
---
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 (3):
diff: add a creation factor argument
prep: add creation-factor argument
prep, diff: document the --range-diff-opts option
docs/contributor/prep.rst | 6 ++++++ docs/maintainer/diff.rst | 5 +++++ src/b4/command.py | 4 ++++ src/b4/diff.py | 10 +++++++++- src/b4/ez.py | 9 +++++++-- 5 files changed, 31 insertions(+), 3 deletions(-)
---
base-commit: d23a9a2d5684369710bd2e416e41159193df3756
change-id: 20250127-creation-factor-ce8069a0bb3c
Best regards,
Signature · 1 line
Antonin Godard <[email protected]>
PATCH v2 1/3 diff: add a creation factor argument
When using git range-diff it is possible to override the creation factor when git considers a large change a total rewrite (and so showing no diff at all), or a change so small it shouldn't be considered.
This parameter is only possible to set from command-line, it has no global option associated to it within Git's config, so add a --creation-factor parameter to b4 to achieve the same behavior.
--- src/b4/command.py | 2 ++ src/b4/diff.py | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-)
src/b4/command.py +2 -0
@@ -287,6 +287,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 +9 -1
@@ -16,6 +16,7 @@ import email.parser import shutil import pathlib import argparse +import shlex from typing import Tuple, Optional, List
@@ -156,7 +157,12 @@ 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 = " ".join(list(sp)) + grdcmd = 'git range-diff %s %.12s..%.12s %.12s..%.12s' % (rd_opts, 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}')
@@ -167,6 +173,8 @@ def main(cmdargs: argparse.Namespace) -> None: gitargs = ['range-diff', f'{lsc}..{lec}', f'{usc}..{uec}'] if cmdargs.outdiff is None or cmdargs.color: gitargs.append('--color') + if rd_opts: + gitargs.append(rd_opts) ecode, rdiff = b4.git_run_command(cmdargs.gitdir, gitargs) if ecode > 0: logger.critical('Unable to generate diff')
Signature · 1 line
2.47.0
Re: [PATCH b4 v2 1/3] diff: add a creation factor argument
Quoted 7 lines · Antonin Godard
When using git range-diff it is possible to override the creation factor when git considers a large change a total rewrite (and so showing no diff at all), or a change so small it shouldn't be considered.
This parameter is only possible to set from command-line, it has no global option associated to it within Git's config, so add a --creation-factor parameter to b4 to achieve the same behavior.
Gah, sorry, I forgot to update the commit titles/descriptions. I'll update that in the next version.
Antonin
PATCH v2 2/3 prep: add creation-factor argument
In reply to Antonin GodardLike the previous commit ("diff: add a creation factor argument"), make it possible to pass a creation factor when using b4 prep --compare-to.
--- src/b4/command.py | 2 ++ src/b4/ez.py | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-)
src/b4/command.py +2 -0
@@ -310,6 +310,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
PATCH v2 3/3 prep, diff: document the --range-diff-opts option
In reply to Antonin GodardThis argument allows adding options to git range-diff.
--- docs/contributor/prep.rst | 6 ++++++ docs/maintainer/diff.rst | 5 +++++ 2 files changed, 11 insertions(+)
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"
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``
Signature · 1 line
2.47.0