Linux maintainer tooling and workflows
 help / color / mirror / Atom feed
From: Antonin Godard <antonin.godard@bootlin.com>
To: "Kernel.org Tools" <tools@kernel.org>
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>,
	 Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	 Antonin Godard <antonin.godard@bootlin.com>
Subject: [PATCH b4 v3 1/2] diff: support passing arguments to git range-diff
Date: Tue, 04 Mar 2025 14:00:29 +0100	[thread overview]
Message-ID: <20250304-creation-factor-v3-1-d6515180b7e5@bootlin.com> (raw)
In-Reply-To: <20250304-creation-factor-v3-0-d6515180b7e5@bootlin.com>

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.

Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
---
 docs/maintainer/diff.rst |  5 +++++
 src/b4/command.py        |  2 ++
 src/b4/diff.py           | 12 ++++++++++--
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/docs/maintainer/diff.rst b/docs/maintainer/diff.rst
index e6ba12ef1caf956b60a6022892c26b6af8de5de1..7911cdc054ef58d6f8c92383f23914962a63d659 100644
--- a/docs/maintainer/diff.rst
+++ b/docs/maintainer/diff.rst
@@ -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``
diff --git a/src/b4/command.py b/src/b4/command.py
index 617a2d7ded8f673e33a4b1c2a09b08c415135a2b..df2ec55ee9da6440b4176bee14ef011aa717f6f0 100644
--- a/src/b4/command.py
+++ b/src/b4/command.py
@@ -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
diff --git a/src/b4/diff.py b/src/b4/diff.py
index 1de3063ea0b3c73e4e3d8bfd4ec91b4c6f90cce6..099ea8ca8a42e5e8261340b3e1d54a923d41b493 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,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)

-- 
2.47.0


  reply	other threads:[~2025-03-04 13:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-04 13:00 [PATCH b4 v3 0/2] prep, diff: support passing arguments to range-diff Antonin Godard
2025-03-04 13:00 ` Antonin Godard [this message]
2025-03-04 13:00 ` [PATCH b4 v3 2/2] prep: support passing arguments to git range-diff Antonin Godard
2025-03-05 20:46 ` [PATCH b4 v3 0/2] prep, diff: support passing arguments to range-diff Konstantin Ryabitsev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250304-creation-factor-v3-1-d6515180b7e5@bootlin.com \
    --to=antonin.godard@bootlin.com \
    --cc=konstantin@linuxfoundation.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=tools@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox