* [PATCH b4 0/2] prep, diff: support overriding range-diff creation factor
@ 2025-02-04 16:44 Antonin Godard
2025-02-04 16:44 ` [PATCH b4 1/2] diff: add a creation factor argument Antonin Godard
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Antonin Godard @ 2025-02-04 16:44 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 default creation factor
value.
I can update the doc in a v2 if needed.
Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
---
Antonin Godard (2):
diff: add a creation factor argument
prep: add creation-factor argument
src/b4/command.py | 4 ++++
src/b4/diff.py | 7 ++++++-
src/b4/ez.py | 6 ++++--
3 files changed, 14 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 1/2] diff: add a creation factor argument
2025-02-04 16:44 [PATCH b4 0/2] prep, diff: support overriding range-diff creation factor Antonin Godard
@ 2025-02-04 16:44 ` Antonin Godard
2025-02-04 16:44 ` [PATCH b4 2/2] prep: add creation-factor argument Antonin Godard
2025-02-06 18:09 ` [PATCH b4 0/2] prep, diff: support overriding range-diff creation factor Konstantin Ryabitsev
2 siblings, 0 replies; 5+ messages in thread
From: Antonin Godard @ 2025-02-04 16:44 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 | 7 ++++++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/b4/command.py b/src/b4/command.py
index 2bdd785..0485196 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('--creation-factor', default=None, type=int,
+ help='Creation factor integer 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 1de3063..83fad67 100644
--- a/src/b4/diff.py
+++ b/src/b4/diff.py
@@ -156,7 +156,10 @@ 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)
+ cf_str = ""
+ if cmdargs.creation_factor:
+ cf_str = f"--creation-factor={cmdargs.creation_factor} "
+ grdcmd = 'git range-diff %s%.12s..%.12s %.12s..%.12s' % (cf_str, 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 +170,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 cmdargs.creation_factor:
+ gitargs.append(cf_str.strip())
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 2/2] prep: add creation-factor argument
2025-02-04 16:44 [PATCH b4 0/2] prep, diff: support overriding range-diff creation factor Antonin Godard
2025-02-04 16:44 ` [PATCH b4 1/2] diff: add a creation factor argument Antonin Godard
@ 2025-02-04 16:44 ` Antonin Godard
2025-02-06 18:09 ` [PATCH b4 0/2] prep, diff: support overriding range-diff creation factor Konstantin Ryabitsev
2 siblings, 0 replies; 5+ messages in thread
From: Antonin Godard @ 2025-02-04 16:44 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 | 6 ++++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/b4/command.py b/src/b4/command.py
index 0485196..d4a70fd 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('--creation-factor', default=None, type=int,
+ help='Creation factor integer passed to git range-diff')
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 f381727..d76acae 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, creation_factor: int = 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,8 @@ 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 creation_factor:
+ grdcmd = grdcmd[:2] + [f"--creation-factor={creation_factor}"] + grdcmd[2:]
logger.debug('Running %s', ' '.join(grdcmd))
if execvp:
# We exec range-diff and let it take over
@@ -2792,7 +2794,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, creation_factor=cmdargs.creation_factor)
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
* Re: [PATCH b4 0/2] prep, diff: support overriding range-diff creation factor
2025-02-04 16:44 [PATCH b4 0/2] prep, diff: support overriding range-diff creation factor Antonin Godard
2025-02-04 16:44 ` [PATCH b4 1/2] diff: add a creation factor argument Antonin Godard
2025-02-04 16:44 ` [PATCH b4 2/2] prep: add creation-factor argument Antonin Godard
@ 2025-02-06 18:09 ` Konstantin Ryabitsev
2025-02-07 7:58 ` Antonin Godard
2 siblings, 1 reply; 5+ messages in thread
From: Konstantin Ryabitsev @ 2025-02-06 18:09 UTC (permalink / raw)
To: Antonin Godard; +Cc: Kernel.org Tools, Thomas Petazzoni
On Tue, Feb 04, 2025 at 05:44:15PM +0100, Antonin Godard wrote:
> 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 default creation factor
> value.
Does it make more sense to have a more generic way to provide arguments to
pass to git-range-diff instead of duplicating options?
E.g. something like:
b4 diff [...] --range-diff-opts="--creation-factor=80 --left-only"
We'd have to re-parse them with shlex to make sure they are safe, but it seems
like a better approach, no?
-K
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH b4 0/2] prep, diff: support overriding range-diff creation factor
2025-02-06 18:09 ` [PATCH b4 0/2] prep, diff: support overriding range-diff creation factor Konstantin Ryabitsev
@ 2025-02-07 7:58 ` Antonin Godard
0 siblings, 0 replies; 5+ messages in thread
From: Antonin Godard @ 2025-02-07 7:58 UTC (permalink / raw)
To: Konstantin Ryabitsev; +Cc: Kernel.org Tools, Thomas Petazzoni
Hi Konstantin,
On Thu Feb 6, 2025 at 7:09 PM CET, Konstantin Ryabitsev wrote:
> On Tue, Feb 04, 2025 at 05:44:15PM +0100, Antonin Godard wrote:
>> 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 default creation factor
>> value.
>
> Does it make more sense to have a more generic way to provide arguments to
> pass to git-range-diff instead of duplicating options?
>
> E.g. something like:
>
> b4 diff [...] --range-diff-opts="--creation-factor=80 --left-only"
>
> We'd have to re-parse them with shlex to make sure they are safe, but it seems
> like a better approach, no?
Right, did not think about it, but I like that approach too. It will avoid
having to make b4's options expand too much over time.
For shlex, were you thinking of shlex.quote()? Do you have any example in b4
that uses shlex for the same purpose?
I will try to work on that when I have some time, thanks for the suggestion!
Antonin
--
Antonin Godard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-02-07 7:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-04 16:44 [PATCH b4 0/2] prep, diff: support overriding range-diff creation factor Antonin Godard
2025-02-04 16:44 ` [PATCH b4 1/2] diff: add a creation factor argument Antonin Godard
2025-02-04 16:44 ` [PATCH b4 2/2] prep: add creation-factor argument Antonin Godard
2025-02-06 18:09 ` [PATCH b4 0/2] prep, diff: support overriding range-diff creation factor Konstantin Ryabitsev
2025-02-07 7:58 ` Antonin Godard
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.