diff mbox series

[b4,v2,1/3] diff: add a creation factor argument

Message ID 20250220-creation-factor-v2-1-7a0949a3a060@bootlin.com (mailing list archive)
State New
Headers show
Series prep, diff: support adding range-diff arguments | expand

Commit Message

Antonin Godard Feb. 20, 2025, 2:24 p.m. UTC
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

Comments

Antonin Godard Feb. 21, 2025, 8:25 a.m. UTC | #1
On Thu Feb 20, 2025 at 3:24 PM CET, Antonin Godard wrote:
> 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
diff mbox series

Patch

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.

Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
---
 src/b4/command.py |  2 ++
 src/b4/diff.py    | 10 +++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/b4/command.py b/src/b4/command.py
index 2bdd785d90004bc0be9c839fe50938dc9cbbe207..1a9bd1c0b02181b432d535eee2fe0c4f510cf39b 100644
--- a/src/b4/command.py
+++ b/src/b4/command.py
@@ -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
diff --git a/src/b4/diff.py b/src/b4/diff.py
index 1de3063ea0b3c73e4e3d8bfd4ec91b4c6f90cce6..0fe6e26d4e3a7a0fea4c7e14cabdfd366361968a 100644
--- a/src/b4/diff.py
+++ b/src/b4/diff.py
@@ -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')