tools.linux.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH b4 v2 0/3] prep, diff: support adding range-diff arguments
@ 2025-02-20 14:24 Antonin Godard
  2025-02-20 14:24 ` [PATCH b4 v2 1/3] diff: add a creation factor argument Antonin Godard
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Antonin Godard @ 2025-02-20 14:24 UTC (permalink / raw)
  To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Thomas Petazzoni, Antonin Godard

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"

Signed-off-by: Antonin Godard <antonin.godard@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 (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,
-- 
Antonin Godard <antonin.godard@bootlin.com>


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

* [PATCH b4 v2 1/3] diff: add a creation factor argument
  2025-02-20 14:24 [PATCH b4 v2 0/3] prep, diff: support adding range-diff arguments Antonin Godard
@ 2025-02-20 14:24 ` Antonin Godard
  2025-02-21  8:25   ` Antonin Godard
  2025-02-20 14:24 ` [PATCH b4 v2 2/3] prep: add creation-factor argument Antonin Godard
  2025-02-20 14:24 ` [PATCH b4 v2 3/3] prep, diff: document the --range-diff-opts option Antonin Godard
  2 siblings, 1 reply; 5+ messages in thread
From: Antonin Godard @ 2025-02-20 14:24 UTC (permalink / raw)
  To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Thomas Petazzoni, 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.

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')

-- 
2.47.0


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

* [PATCH b4 v2 2/3] prep: add creation-factor argument
  2025-02-20 14:24 [PATCH b4 v2 0/3] prep, diff: support adding range-diff arguments Antonin Godard
  2025-02-20 14:24 ` [PATCH b4 v2 1/3] diff: add a creation factor argument Antonin Godard
@ 2025-02-20 14:24 ` Antonin Godard
  2025-02-20 14:24 ` [PATCH b4 v2 3/3] prep, diff: document the --range-diff-opts option Antonin Godard
  2 siblings, 0 replies; 5+ messages in thread
From: Antonin Godard @ 2025-02-20 14:24 UTC (permalink / raw)
  To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Thomas Petazzoni, Antonin Godard

Like the previous commit ("diff: add a creation factor argument"), make
it possible to pass a creation factor when using b4 prep --compare-to.

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

diff --git a/src/b4/command.py b/src/b4/command.py
index 1a9bd1c0b02181b432d535eee2fe0c4f510cf39b..d1624c736195a1a1f023629afe06cf184c727098 100644
--- a/src/b4/command.py
+++ b/src/b4/command.py
@@ -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',
diff --git a/src/b4/ez.py b/src/b4/ez.py
index f381727d9bc6fe0d29328ef384647e3a6a23e767..d3dfea47a20a5622d2f8a349a731d25769e1a664 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] 5+ messages in thread

* [PATCH b4 v2 3/3] prep, diff: document the --range-diff-opts option
  2025-02-20 14:24 [PATCH b4 v2 0/3] prep, diff: support adding range-diff arguments Antonin Godard
  2025-02-20 14:24 ` [PATCH b4 v2 1/3] diff: add a creation factor argument Antonin Godard
  2025-02-20 14:24 ` [PATCH b4 v2 2/3] prep: add creation-factor argument Antonin Godard
@ 2025-02-20 14:24 ` Antonin Godard
  2 siblings, 0 replies; 5+ messages in thread
From: Antonin Godard @ 2025-02-20 14:24 UTC (permalink / raw)
  To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Thomas Petazzoni, Antonin Godard

This argument allows adding options to `git range-diff`.

Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
---
 docs/contributor/prep.rst | 6 ++++++
 docs/maintainer/diff.rst  | 5 +++++
 2 files changed, 11 insertions(+)

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/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``

-- 
2.47.0


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

* Re: [PATCH b4 v2 1/3] diff: add a creation factor argument
  2025-02-20 14:24 ` [PATCH b4 v2 1/3] diff: add a creation factor argument Antonin Godard
@ 2025-02-21  8:25   ` Antonin Godard
  0 siblings, 0 replies; 5+ messages in thread
From: Antonin Godard @ 2025-02-21  8:25 UTC (permalink / raw)
  To: Antonin Godard, Kernel.org Tools; +Cc: Konstantin Ryabitsev, Thomas Petazzoni

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

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

end of thread, other threads:[~2025-02-21  8:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-20 14:24 [PATCH b4 v2 0/3] prep, diff: support adding range-diff arguments Antonin Godard
2025-02-20 14:24 ` [PATCH b4 v2 1/3] diff: add a creation factor argument Antonin Godard
2025-02-21  8:25   ` Antonin Godard
2025-02-20 14:24 ` [PATCH b4 v2 2/3] prep: add creation-factor argument Antonin Godard
2025-02-20 14:24 ` [PATCH b4 v2 3/3] prep, diff: document the --range-diff-opts option Antonin Godard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).