Skip to contentSkip to conversation

prep, diff: support overriding range-diff creation factor

PATCH Superseded Antonin Godard 2 participants 5 messages Feb 4, 2025 – Feb 7, 2025

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover prep, diff: support overriding range-diff creation factor

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.

---
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,

Signature · 1 line
Antonin Godard <[email protected]>
#2 lore raw

PATCH 2/2 prep: add creation-factor argument

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

---
 src/b4/command.py | 2 ++
 src/b4/ez.py      | 6 ++++--
 2 files changed, 6 insertions(+), 2 deletions(-)
src/b4/command.py +2 -0
index 0485196..d4a70fd 100644
@@ -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',
src/b4/ez.py +4 -2
index f381727..d76acae 100644
@@ -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.')
Signature · 1 line
2.47.0
#1 lore raw

PATCH 1/2 diff: add a creation factor argument

In reply to 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.

---
 src/b4/command.py | 2 ++
 src/b4/diff.py    | 7 ++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
src/b4/command.py +2 -0
index 2bdd785..0485196 100644
@@ -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
src/b4/diff.py +6 -1
index 1de3063..83fad67 100644
@@ -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')
Signature · 1 line
2.47.0
#3 lore raw
In reply to Antonin Godard
Quoted 7 lines · 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.

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

#4 lore raw

Hi Konstantin,

Quoted 12 lines · Konstantin Ryabitsev
Quoted 7 lines · 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.

Does it make more sense to have a more generic way to provide arguments to pass to git-range-diff instead of duplicating options?

Quoted 6 lines

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

Signature · 3 lines
Antonin Godard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com