Linux maintainer tooling and workflows
 help / color / mirror / Atom feed
* [PATCH b4 v3 0/2] prep, diff: support passing arguments to range-diff
@ 2025-03-04 13:00 Antonin Godard
  2025-03-04 13:00 ` [PATCH b4 v3 1/2] diff: support passing arguments to git range-diff Antonin Godard
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Antonin Godard @ 2025-03-04 13:00 UTC (permalink / raw)
  To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Thomas Petazzoni, 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" 20250220-creation-factor-v2-0-7a0949a3a060@bootlin.com

Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
---
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/20250220-creation-factor-v2-0-7a0949a3a060@bootlin.com

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/20250204-creation-factor-v1-0-9988d594a018@bootlin.com

---
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,
-- 
Antonin Godard <antonin.godard@bootlin.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH b4 v3 1/2] diff: support passing arguments to git range-diff
  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
  2025-03-04 13:00 ` [PATCH b4 v3 2/2] prep: " Antonin Godard
  2025-03-05 20:46 ` [PATCH b4 v3 0/2] prep, diff: support passing arguments to range-diff Konstantin Ryabitsev
  2 siblings, 0 replies; 4+ messages in thread
From: Antonin Godard @ 2025-03-04 13:00 UTC (permalink / raw)
  To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Thomas Petazzoni, Antonin Godard

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH b4 v3 2/2] prep: support passing arguments to git range-diff
  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 ` [PATCH b4 v3 1/2] diff: support passing arguments to git range-diff Antonin Godard
@ 2025-03-04 13:00 ` Antonin Godard
  2025-03-05 20:46 ` [PATCH b4 v3 0/2] prep, diff: support passing arguments to range-diff Konstantin Ryabitsev
  2 siblings, 0 replies; 4+ messages in thread
From: Antonin Godard @ 2025-03-04 13:00 UTC (permalink / raw)
  To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Thomas Petazzoni, Antonin Godard

Like 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.

Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
---
 docs/contributor/prep.rst | 6 ++++++
 src/b4/command.py         | 2 ++
 src/b4/ez.py              | 9 +++++++--
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/docs/contributor/prep.rst b/docs/contributor/prep.rst
index df8582426850df88b9e174e6429837e1eb49f792..18c710dd415794f5c1587b3375d86c8761c57602 100644
--- a/docs/contributor/prep.rst
+++ b/docs/contributor/prep.rst
@@ -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"
diff --git a/src/b4/command.py b/src/b4/command.py
index df2ec55ee9da6440b4176bee14ef011aa717f6f0..4b71d8a81f7e4160632d76a8c993fc396efc8d53 100644
--- a/src/b4/command.py
+++ b/src/b4/command.py
@@ -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',
diff --git a/src/b4/ez.py b/src/b4/ez.py
index 61918f57722e817781b74d7a700fea030bc2145f..156926aae33c84106ba8197e43dba249cf698c8b 100644
--- a/src/b4/ez.py
+++ b/src/b4/ez.py
@@ -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.')

-- 
2.47.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH b4 v3 0/2] prep, diff: support passing arguments to range-diff
  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 ` [PATCH b4 v3 1/2] diff: support passing arguments to git range-diff Antonin Godard
  2025-03-04 13:00 ` [PATCH b4 v3 2/2] prep: " Antonin Godard
@ 2025-03-05 20:46 ` Konstantin Ryabitsev
  2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Ryabitsev @ 2025-03-05 20:46 UTC (permalink / raw)
  To: Kernel.org Tools, Antonin Godard; +Cc: Thomas Petazzoni


On Tue, 04 Mar 2025 14:00:28 +0100, Antonin Godard wrote:
> 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" 20250220-creation-factor-v2-0-7a0949a3a060@bootlin.com
> 
> [...]

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: eb4a66b12bc424854f453493dc627436952b3573

Best regards,
-- 
Konstantin Ryabitsev <konstantin@linuxfoundation.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-03-05 20:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH b4 v3 1/2] diff: support passing arguments to git range-diff Antonin Godard
2025-03-04 13:00 ` [PATCH b4 v3 2/2] prep: " Antonin Godard
2025-03-05 20:46 ` [PATCH b4 v3 0/2] prep, diff: support passing arguments to range-diff Konstantin Ryabitsev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox