* [PATCH b4 0/3] lore: three fixes between a posted serie and the reader
@ 2026-09-25 12:50 Clément Le Goffic
2026-09-25 12:50 ` [PATCH b4 1/3] lore: parse per-file modes in get_indexes Clément Le Goffic
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Clément Le Goffic @ 2026-09-25 12:50 UTC (permalink / raw)
To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Clément Le Goffic
I'm using b4 in other projects and this allow to catch some issues.
I used an LLM to find where does those come from and fix them.
Here is a serie with three independant fixes.
The first two are linked and come from the diff parsing:
- a prior parsed file mode is kept and not cleaned
- a commit diff with a submodule mode didn't allow fake-am
The last one is fixing some pager issues with less that is leaving the
window mode when the content fits the screen.
It was causing tui range-diff issues on my end.
Signed-off-by: Clément Le Goffic <clegoffic@baylibre.com>
---
Clément Le Goffic (3):
lore: parse per-file modes in get_indexes
lore: fake-am series that touch submodule gitlinks
lore: stop a less pager quitting on output that fits one screen
src/b4/__init__.py | 77 ++++++++++++--
src/tests/test___init__.py | 251 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 318 insertions(+), 10 deletions(-)
---
base-commit: e5168b69c2b0661c7a167eff8ddc5753c458b1d1
change-id: 20260925-b4-lore-fixes-315d5e5819a3
Best regards,
--
Clément Le Goffic <clegoffic@baylibre.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH b4 1/3] lore: parse per-file modes in get_indexes
2026-09-25 12:50 [PATCH b4 0/3] lore: three fixes between a posted serie and the reader Clément Le Goffic
@ 2026-09-25 12:50 ` Clément Le Goffic
2026-09-25 12:50 ` [PATCH b4 2/3] lore: fake-am series that touch submodule gitlinks Clément Le Goffic
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Clément Le Goffic @ 2026-09-25 12:50 UTC (permalink / raw)
To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Clément Le Goffic
A mode is per-file state, but get_indexes() never reset it between
files. A file's own mode is taken from its index line only when none
is held yet, so once one file had set a mode, every later file that did
not announce a new one kept it instead of reading its own -- a gitlink
or symlink after a regular file came out as 100644.
Reset it on each 'diff --git', and while there parse 'deleted file mode'
and 'old mode', which were never matched at all, and fix the five-digit
'10644' fallback to 100644.
Assisted-by: claude-fable-5
Signed-off-by: Clément Le Goffic <clegoffic@baylibre.com>
---
src/b4/__init__.py | 21 +++++++++++--
src/tests/test___init__.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 91 insertions(+), 3 deletions(-)
diff --git a/src/b4/__init__.py b/src/b4/__init__.py
index 584755a556b4..3e9145f4a6a5 100644
--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -2906,14 +2906,29 @@ class LoreMessage:
newfile = None
fmod = None
for line in diff.split('\n'):
- if not (line.startswith(('diff ', 'index ', 'new file mode '))):
+ if not (
+ line.startswith(
+ (
+ 'diff ',
+ 'index ',
+ 'new file mode ',
+ 'deleted file mode ',
+ 'old mode ',
+ )
+ )
+ ):
continue
matches = re.search(r'^diff\s+--git\s+\w/(.*)\s+\w/(.*)$', line)
if matches:
oldfile = matches.groups()[0]
newfile = matches.groups()[1]
+ # mode is per-file state; a value left over from the
+ # previous file must not leak onto this one
+ fmod = None
continue
- matches = re.search(r'^new file mode (\d+)', line)
+ matches = re.search(
+ r'^(?:new file mode|deleted file mode|old mode) (\d+)$', line
+ )
if matches:
fmod = matches.groups()[0]
matches = re.search(r'^index\s+([\da-f]+)\.\.[\da-f]+.*$', line)
@@ -2925,7 +2940,7 @@ class LoreMessage:
fmod = matches.groups()[0]
if not fmod:
# fall back if we can't figure it out
- fmod = '10644'
+ fmod = '100644'
indexes.add((oldfile, ohash, newfile, fmod))
return indexes
diff --git a/src/tests/test___init__.py b/src/tests/test___init__.py
index 11504bba02c8..980082e26a49 100644
--- a/src/tests/test___init__.py
+++ b/src/tests/test___init__.py
@@ -1808,3 +1808,76 @@ class TestUnicodeControlChars:
def test_plain_ascii_body_is_not_flagged(self) -> None:
lmsg = self._get_lmsg('This adds a fancy widget.')
lmsg.get_am_message(add_trailers=False)
+
+
+class TestGetIndexesPerFileModes:
+ """A mode belongs to the file whose diff header carried it.
+
+ make_fake_am_range() binds every preimage by (hash, mode), so a mode
+ read off the file before it binds a gitlink or a symlink as a regular
+ blob, and the series stops fake-am'ing at all.
+ """
+
+ def test_a_mode_does_not_leak_onto_the_next_file(self) -> None:
+ """A gitlink and a symlink after a regular file keep their own.
+
+ The deleted file states its mode nowhere but on its own
+ "deleted file mode" line, which the index line does not repeat.
+ """
+ diff = (
+ 'diff --git a/README b/README\n'
+ 'index 1111111..2222222 100644\n'
+ '--- a/README\n'
+ '+++ b/README\n'
+ '@@ -1 +1 @@\n'
+ '-readme\n'
+ '+readme v2\n'
+ 'diff --git a/sub b/sub\n'
+ 'index 3333333..4444444 160000\n'
+ '--- a/sub\n'
+ '+++ b/sub\n'
+ '@@ -1 +1 @@\n'
+ '-Subproject commit 3333333333333333333333333333333333333333\n'
+ '+Subproject commit 4444444444444444444444444444444444444444\n'
+ 'diff --git a/link b/link\n'
+ 'index 5555555..6666666 120000\n'
+ '--- a/link\n'
+ '+++ b/link\n'
+ '@@ -1 +1 @@\n'
+ '-README\n'
+ '+sub\n'
+ 'diff --git a/gone b/gone\n'
+ 'deleted file mode 100755\n'
+ 'index 7777777..0000000\n'
+ '--- a/gone\n'
+ '+++ /dev/null\n'
+ '@@ -1 +0,0 @@\n'
+ '-#!/bin/sh\n'
+ )
+ assert b4.LoreMessage.get_indexes(diff) == {
+ ('README', '1111111', 'README', '100644'),
+ ('sub', '3333333', 'sub', '160000'),
+ ('link', '5555555', 'link', '120000'),
+ ('gone', '7777777', 'gone', '100755'),
+ }
+
+ def test_a_mode_change_names_the_preimage_mode(self) -> None:
+ """A chmod alongside an edit: the index line carries no mode.
+
+ get_indexes describes the preimage, so "old mode" is the answer --
+ and nothing anywhere is mode 10644.
+ """
+ diff = (
+ 'diff --git a/run.sh b/run.sh\n'
+ 'old mode 100644\n'
+ 'new mode 100755\n'
+ 'index 8888888..9999999\n'
+ '--- a/run.sh\n'
+ '+++ b/run.sh\n'
+ '@@ -1 +1 @@\n'
+ '-echo old\n'
+ '+echo new\n'
+ )
+ assert b4.LoreMessage.get_indexes(diff) == {
+ ('run.sh', '8888888', 'run.sh', '100644')
+ }
--
2.55.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH b4 2/3] lore: fake-am series that touch submodule gitlinks
2026-09-25 12:50 [PATCH b4 0/3] lore: three fixes between a posted serie and the reader Clément Le Goffic
2026-09-25 12:50 ` [PATCH b4 1/3] lore: parse per-file modes in get_indexes Clément Le Goffic
@ 2026-09-25 12:50 ` Clément Le Goffic
2026-09-25 12:50 ` [PATCH b4 3/3] lore: stop a less pager quitting on output that fits one screen Clément Le Goffic
` (2 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Clément Le Goffic @ 2026-09-25 12:50 UTC (permalink / raw)
To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Clément Le Goffic
make_fake_am_range() binds every preimage through a blob lookup, but a
gitlink's old value is a commit in the submodule's object store, which
this repository cannot resolve, so a series bumping a submodule could
never be fake-am'd at all. "b4 diff" on such a series gives up with
"Could not create fake-am range", and every other caller that needs the
preimage tree loses it the same way.
The diff itself has both halves, so for mode 160000 bind that sha with
"update-index --cacheinfo", which records a gitlink without the object:
index 1a2b3c..5d6e7f 160000 <- gitlink mode
-Subproject commit <40 hex> <- the preimage, in full
Assisted-by: claude-fable-5
Signed-off-by: Clément Le Goffic <clegoffic@baylibre.com>
---
src/b4/__init__.py | 38 +++++++++++++++++
src/tests/test___init__.py | 100 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 138 insertions(+)
diff --git a/src/b4/__init__.py b/src/b4/__init__.py
index 3e9145f4a6a5..f55e9d9e73aa 100644
--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -1540,6 +1540,44 @@ class LoreSeries:
# renamed file, make sure to not add the new name later on
logger.debug(' Renamed file: %s -> %s', ofn, nfn)
seenfiles.add(nfn)
+ if fmod == '160000':
+ # A gitlink's preimage lives in the submodule's object
+ # store, not ours; --cacheinfo binds it without the object.
+ section = re.search(
+ r'^diff --git \w/'
+ + re.escape(ofn)
+ + r'\s.*?(?=^diff --git |\Z)',
+ lmsg.body,
+ flags=re.M | re.S,
+ )
+ glink = (
+ re.search(
+ r'^-Subproject commit ([0-9a-f]{40,64})$',
+ section.group(0),
+ flags=re.M,
+ )
+ if section
+ else None
+ )
+ if glink:
+ bound_hash = glink.group(1)
+ logger.debug(' Gitlink preimage for: %s', ofn)
+ gitargs = [
+ 'update-index',
+ '--add',
+ '--cacheinfo',
+ f'{fmod},{bound_hash},{ofn}',
+ ]
+ ecode, out = git_run_command(dfn, gitargs)
+ if ecode > 0:
+ logger.critical(
+ ' ERROR: Could not run update-index for %s (%s)',
+ ofn,
+ bound_hash,
+ )
+ return None, None
+ continue
+ logger.debug(' No gitlink preimage for %s', ofn)
# Try to grab full ref_id of this hash
try:
bound_hash = git_revparse_obj(ofi, dfn)
diff --git a/src/tests/test___init__.py b/src/tests/test___init__.py
index 980082e26a49..18de9ab0f114 100644
--- a/src/tests/test___init__.py
+++ b/src/tests/test___init__.py
@@ -1881,3 +1881,103 @@ class TestGetIndexesPerFileModes:
assert b4.LoreMessage.get_indexes(diff) == {
('run.sh', '8888888', 'run.sh', '100644')
}
+
+
+class TestFakeAmGitlinkPreimage:
+ """A series bumping a submodule has to fake-am in either hash format.
+
+ The preimage of a gitlink is a commit in the submodule's object store,
+ which the superproject cannot resolve, so the only copy of it anywhere
+ on this side is the one written out in the diff -- as 64 hex digits in a
+ sha256 repository.
+ """
+
+ @staticmethod
+ def _bump_repo(
+ tmp_path: pathlib.Path, object_format: str
+ ) -> Tuple[str, str, int, b4.LoreSeries]:
+ """Build a repo whose gitlink bump names objects nobody has.
+
+ Returns (repo, base commit, hash length, series). master keeps no
+ gitlink at all, so the index lookup make_fake_am_range falls back to
+ has nothing to find either -- exactly like a submodule that was never
+ cloned here. The bump edits README as well, so the gitlink is not
+ the first file in the diff: a mode is per-file state, and one left
+ over from the file before would bind this one as a regular blob.
+ """
+ repo = str(tmp_path / f'gitlink-{object_format}')
+ ecode, out = b4.git_run_command(
+ None, ['init', f'--object-format={object_format}', '-b', 'master', repo]
+ )
+ assert ecode == 0, out
+ assert b4.git_set_config(repo, 'user.name', 'Gitlink Tester') == 0
+ assert b4.git_set_config(repo, 'user.email', 'gitlink@example.com') == 0
+ (pathlib.Path(repo) / 'README').write_text('readme\n')
+ for args in (['add', 'README'], ['commit', '-q', '-m', 'initial']):
+ assert b4.git_run_command(repo, args, rundir=repo)[0] == 0, args
+
+ hexlen = 64 if object_format == 'sha256' else 40
+ old, new = '1' * hexlen, '2' * hexlen
+ parent = 'master'
+ commits = list()
+ for idx, gitlink in enumerate((old, new)):
+ ecode, _out = b4.git_run_command(
+ repo,
+ ['update-index', '--add', '--cacheinfo', f'160000,{gitlink},sub'],
+ rundir=repo,
+ )
+ assert ecode == 0
+ if idx:
+ (pathlib.Path(repo) / 'README').write_text('readme v2\n')
+ assert b4.git_run_command(repo, ['add', 'README'], rundir=repo)[0] == 0
+ ecode, tree = b4.git_run_command(repo, ['write-tree'], rundir=repo)
+ assert ecode == 0
+ ecode, commit = b4.git_run_command(
+ repo,
+ ['commit-tree', tree.strip(), '-p', parent],
+ stdin=f'point sub at {gitlink[:7]}\n'.encode(),
+ )
+ assert ecode == 0
+ parent = commit.strip()
+ commits.append(parent)
+ base, bump = commits
+
+ ecode, mbox = b4.git_run_command(
+ repo, ['format-patch', '-1', '--stdout', bump], decode=False
+ )
+ assert ecode == 0
+ assert f'-Subproject commit {old}'.encode() in mbox
+ assert mbox.index(b'diff --git a/README') < mbox.index(b'diff --git a/sub')
+ # Back to a master that never heard of the submodule.
+ assert (
+ b4.git_run_command(repo, ['reset', '--hard', 'master'], rundir=repo)[0] == 0
+ )
+
+ lmbx = b4.LoreMailbox()
+ for idx, msg in enumerate(b4.mailsplit_bytes(mbox)):
+ if not msg['Message-Id']:
+ msg['Message-Id'] = f'<{object_format}-gitlink-{idx}@test.local>'
+ lmbx.add_message(msg)
+ lser = lmbx.get_series()
+ assert lser is not None
+ return repo, base, hexlen, lser
+
+ @pytest.mark.parametrize('object_format', ['sha1', 'sha256'])
+ def test_gitlink_preimage_is_bound_without_the_object(
+ self,
+ tmp_path: pathlib.Path,
+ monkeypatch: pytest.MonkeyPatch,
+ object_format: str,
+ ) -> None:
+ """Both ends of the range carry the gitlink the diff named."""
+ repo, base, hexlen, lser = self._bump_repo(tmp_path, object_format)
+ monkeypatch.chdir(repo)
+
+ start, end = lser.make_fake_am_range(gitdir=repo, at_base=base)
+
+ assert start, 'the gitlink preimage did not make it into a fake-am range'
+ assert end
+ for commit, gitlink in ((start, '1' * hexlen), (end, '2' * hexlen)):
+ ecode, entry = b4.git_run_command(repo, ['ls-tree', commit, 'sub'])
+ assert ecode == 0
+ assert entry.split()[:3] == ['160000', 'commit', gitlink]
--
2.55.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH b4 3/3] lore: stop a less pager quitting on output that fits one screen
2026-09-25 12:50 [PATCH b4 0/3] lore: three fixes between a posted serie and the reader Clément Le Goffic
2026-09-25 12:50 ` [PATCH b4 1/3] lore: parse per-file modes in get_indexes Clément Le Goffic
2026-09-25 12:50 ` [PATCH b4 2/3] lore: fake-am series that touch submodule gitlinks Clément Le Goffic
@ 2026-09-25 12:50 ` Clément Le Goffic
2026-10-05 10:09 ` Konstantin Ryabitsev
2026-10-05 10:09 ` [PATCH b4 0/3] lore: three fixes between a posted serie and the reader Konstantin Ryabitsev
2026-10-05 10:11 ` (subset) " Konstantin Ryabitsev
4 siblings, 1 reply; 10+ messages in thread
From: Clément Le Goffic @ 2026-09-25 12:50 UTC (permalink / raw)
To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Clément Le Goffic
view_in_pager() stripped F from LESS so the pager stays open on output
that fits one screen, but a core.pager of "less -FRSX" carries the flag
on the command line, where it beats the environment. Anything b4 hands
the pager that is short enough to fit then flashed past and was gone
with the pager, which is the one case the stripping exists to prevent.
Append -+F instead when the pager is less: it reads its options left to
right and -+X resets one to its default, so this reaches the flag
whichever set it and however it was spelled, including the long
--quit-if-one-screen. The environment is left to the pipeline case,
where the less inside "diff-highlight | less -RFX" is out of reach and
an -F written there still wins, as it did before.
Assisted-by: claude-fable-5
Signed-off-by: Clément Le Goffic <clegoffic@baylibre.com>
---
src/b4/__init__.py | 18 ++++++-----
src/tests/test___init__.py | 78 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+), 7 deletions(-)
diff --git a/src/b4/__init__.py b/src/b4/__init__.py
index f55e9d9e73aa..97caf4c8a00f 100644
--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -6783,24 +6783,28 @@ def view_in_pager(bdata: bytes, filehint: str = 'b4-view.txt') -> None:
with open(temp_fpath, 'xb') as view_file:
view_file.write(bdata)
- # Strip -F (quit-if-one-screen) from LESS so the pager always
- # stays open, even when the output fits on a single screen.
- env = dict(os.environ)
- env['LESS'] = env.get('LESS', 'FRX').replace('F', '')
if '|' in pager:
# Pager uses a pipeline (e.g. "diff-highlight | less -RFX"),
# so we must use the shell to interpret it. Feed data on
# stdin since piped pagers read from the pipe, not from a
- # file argument.
+ # file argument. The less inside is out of reach, so F only
+ # comes off the environment here.
+ env = dict(os.environ)
+ env['LESS'] = env.get('LESS', 'FRX').replace('F', '')
logger.debug('Running (shell): %s < %s', pager, temp_fpath)
with open(temp_fpath, 'rb') as fh:
spop = subprocess.Popen(pager, shell=True, stdin=fh, env=env)
else:
sp = shlex.shlex(pager, posix=True)
sp.whitespace_split = True
- cmdargs = list(sp) + [temp_fpath]
+ cmdargs = list(sp)
+ if cmdargs and os.path.basename(cmdargs[0]) == 'less':
+ # less takes its options left to right, so -+F resets
+ # quit-if-one-screen whichever set it.
+ cmdargs.append('-+F')
+ cmdargs += [temp_fpath]
logger.debug('Running %s', ' '.join(cmdargs))
- spop = subprocess.Popen(cmdargs, env=env)
+ spop = subprocess.Popen(cmdargs)
spop.wait()
diff --git a/src/tests/test___init__.py b/src/tests/test___init__.py
index 18de9ab0f114..d253af11a86c 100644
--- a/src/tests/test___init__.py
+++ b/src/tests/test___init__.py
@@ -1981,3 +1981,81 @@ class TestFakeAmGitlinkPreimage:
ecode, entry = b4.git_run_command(repo, ['ls-tree', commit, 'sub'])
assert ecode == 0
assert entry.split()[:3] == ['160000', 'commit', gitlink]
+
+
+class TestViewInPagerLessFlags:
+ """-F has to come off a "less" pager, and nothing else may change.
+
+ Output short enough to fit one screen -- a range-diff narrowed to a
+ single patch, say -- is exactly what quit-if-one-screen flashes past
+ the reader, and a core.pager of "less -FRSX" carries that flag where
+ the LESS environment cannot reach it. less reads its options left to
+ right, so appending -+F resets it whatever spelling the pager used,
+ and nothing in the pager's own arguments is parsed or rewritten.
+ """
+
+ class _Spawned:
+ """Stands in for the pager process, which nobody is here to read."""
+
+ def wait(self) -> int:
+ return 0
+
+ @classmethod
+ def _spawned(cls, monkeypatch: pytest.MonkeyPatch, pager: str) -> List[str]:
+ """Return the argv view_in_pager() would have run."""
+ seen: List[Any] = list()
+ real_popen = b4.subprocess.Popen
+
+ def fake_popen(args: Any, **kwargs: Any) -> Any:
+ # b4 reads its config through Popen too, and those calls are the
+ # ones capturing stdout; the pager's own goes to the terminal.
+ if kwargs.get('stdout') is not None:
+ return real_popen(args, **kwargs)
+ seen.append(args)
+ return cls._Spawned()
+
+ monkeypatch.setenv('GIT_PAGER', pager)
+ monkeypatch.setattr(b4.subprocess, 'Popen', fake_popen)
+ b4.view_in_pager(b'short enough to fit one screen\n')
+ assert len(seen) == 1
+ argv = seen[0]
+ assert isinstance(argv, list)
+ assert argv[-1].endswith('b4-view.txt')
+ return [str(arg) for arg in argv[:-1]]
+
+ @pytest.mark.parametrize(
+ 'pager,expected',
+ [
+ # A bundled cluster, on its own, and spelled out,
+ ('less -FRSX', ['less', '-FRSX', '-+F']),
+ ('less -F', ['less', '-F', '-+F']),
+ ('less -R -F -X', ['less', '-R', '-F', '-X', '-+F']),
+ ('/usr/bin/less -FRX', ['/usr/bin/less', '-FRX', '-+F']),
+ # the long form, which no amount of letter-splitting reaches,
+ (
+ 'less --quit-if-one-screen',
+ ['less', '--quit-if-one-screen', '-+F'],
+ ),
+ # and a pager with no -F at all: -+F is a no-op there.
+ ('less -R', ['less', '-R', '-+F']),
+ # Only less is ours to touch,
+ ('most -F', ['most', '-F']),
+ # and its own arguments are left exactly as written: a prompt
+ # string whose text happens to contain an F,
+ ('less -R "-PsFile %f"', ['less', '-R', '-PsFile %f', '-+F']),
+ # a log file to write,
+ ('less -oFramelog.txt', ['less', '-oFramelog.txt', '-+F']),
+ # the pattern to open at,
+ ('less -pFoo', ['less', '-pFoo', '-+F']),
+ # and "+F" as the command to start with.
+ ('less +F', ['less', '+F', '-+F']),
+ ],
+ )
+ def test_less_is_told_to_reset_f(
+ self,
+ gitdir: str,
+ monkeypatch: pytest.MonkeyPatch,
+ pager: str,
+ expected: List[str],
+ ) -> None:
+ assert self._spawned(monkeypatch, pager) == expected
--
2.55.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH b4 0/3] lore: three fixes between a posted serie and the reader
2026-09-25 12:50 [PATCH b4 0/3] lore: three fixes between a posted serie and the reader Clément Le Goffic
` (2 preceding siblings ...)
2026-09-25 12:50 ` [PATCH b4 3/3] lore: stop a less pager quitting on output that fits one screen Clément Le Goffic
@ 2026-10-05 10:09 ` Konstantin Ryabitsev
2026-10-05 10:11 ` (subset) " Konstantin Ryabitsev
4 siblings, 0 replies; 10+ messages in thread
From: Konstantin Ryabitsev @ 2026-10-05 10:09 UTC (permalink / raw)
To: Clément Le Goffic; +Cc: Kernel.org Tools, Konstantin Ryabitsev
> I'm using b4 in other projects and this allow to catch some issues.
> I used an LLM to find where does those come from and fix them.
>
> Here is a serie with three independant fixes.
> The first two are linked and come from the diff parsing:
> - a prior parsed file mode is kept and not cleaned
> - a commit diff with a submodule mode didn't allow fake-am
>
> The last one is fixing some pager issues with less that is leaving the
> window mode when the content fits the screen.
> It was causing tui range-diff issues on my end.
I'll take the first two, but I think the 3rd one needs more work, if
only because it fails ci.sh runs.
--
Konstantin Ryabitsev <konstantin@linuxfoundation.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH b4 3/3] lore: stop a less pager quitting on output that fits one screen
2026-09-25 12:50 ` [PATCH b4 3/3] lore: stop a less pager quitting on output that fits one screen Clément Le Goffic
@ 2026-10-05 10:09 ` Konstantin Ryabitsev
2026-10-05 12:37 ` Clément Le Goffic
0 siblings, 1 reply; 10+ messages in thread
From: Konstantin Ryabitsev @ 2026-10-05 10:09 UTC (permalink / raw)
To: Clément Le Goffic; +Cc: Kernel.org Tools, Konstantin Ryabitsev
> [ ... 32 lines skipped ... ]
> if '|' in pager:
> # Pager uses a pipeline (e.g. "diff-highlight | less -RFX"),
> # so we must use the shell to interpret it. Feed data on
> # stdin since piped pagers read from the pipe, not from a
> - # file argument.
> + # file argument. The less inside is out of reach, so F only
> + # comes off the environment here.
> + env = dict(os.environ)
> + env['LESS'] = env.get('LESS', 'FRX').replace('F', '')
> logger.debug('Running (shell): %s < %s', pager, temp_fpath)
> with open(temp_fpath, 'rb') as fh:
> spop = subprocess.Popen(pager, shell=True, stdin=fh, env=env)
> else:
> sp = shlex.shlex(pager, posix=True)
> sp.whitespace_split = True
> - cmdargs = list(sp) + [temp_fpath]
> + cmdargs = list(sp)
> + if cmdargs and os.path.basename(cmdargs[0]) == 'less':
> + # less takes its options left to right, so -+F resets
> + # quit-if-one-screen whichever set it.
> + cmdargs.append('-+F')
> + cmdargs += [temp_fpath]
> logger.debug('Running %s', ' '.join(cmdargs))
> - spop = subprocess.Popen(cmdargs, env=env)
> + spop = subprocess.Popen(cmdargs)
Would this cause problems for people who set their less env to different
settings? I'm not sure I'm comfortable blindly appending +F to all
possible less invocations.
> spop.wait()
>
>
> diff --git a/src/tests/test___init__.py b/src/tests/test___init__.py
> index 601c0dc..b677b69 100644
> --- a/src/tests/test___init__.py
> +++ b/src/tests/test___init__.py
> @@ -2763,3 +2763,81 @@ class TestFakeAmGitlinkPreimage:
> ecode, entry = b4.git_run_command(repo, ['ls-tree', commit, 'sub'])
> assert ecode == 0
> assert entry.split()[:3] == ['160000', 'commit', gitlink]
> +
> +
> +class TestViewInPagerLessFlags:
> + """-F has to come off a "less" pager, and nothing else may change.
> +
> + Output short enough to fit one screen -- a range-diff narrowed to a
> + single patch, say -- is exactly what quit-if-one-screen flashes past
> + the reader, and a core.pager of "less -FRSX" carries that flag where
> + the LESS environment cannot reach it. less reads its options left to
> + right, so appending -+F resets it whatever spelling the pager used,
> + and nothing in the pager's own arguments is parsed or rewritten.
> + """
> +
> + class _Spawned:
> + """Stands in for the pager process, which nobody is here to read."""
> +
> + def wait(self) -> int:
> + return 0
> +
> + @classmethod
> + def _spawned(cls, monkeypatch: pytest.MonkeyPatch, pager: str) -> List[str]:
> + """Return the argv view_in_pager() would have run."""
> + seen: List[Any] = list()
> + real_popen = b4.subprocess.Popen
This line and the monkeypatch.setattr() below fail ci.sh at the mypy
step (mypy runs in strict mode, so implicit re-exports are off):
src/tests/test___init__.py:2789: error: Module "b4" does not
explicitly export attribute "subprocess" [attr-defined]
src/tests/test___init__.py:2800: error: (same)
You should just add `import subprocess` to the test imports and use
`subprocess.Popen` / `monkeypatch.setattr(subprocess, 'Popen',
fake_popen)`. It patches the same object, so the behaviour does not
change.
--
Konstantin Ryabitsev <konstantin@linuxfoundation.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: (subset) [PATCH b4 0/3] lore: three fixes between a posted serie and the reader
2026-09-25 12:50 [PATCH b4 0/3] lore: three fixes between a posted serie and the reader Clément Le Goffic
` (3 preceding siblings ...)
2026-10-05 10:09 ` [PATCH b4 0/3] lore: three fixes between a posted serie and the reader Konstantin Ryabitsev
@ 2026-10-05 10:11 ` Konstantin Ryabitsev
4 siblings, 0 replies; 10+ messages in thread
From: Konstantin Ryabitsev @ 2026-10-05 10:11 UTC (permalink / raw)
To: Kernel.org Tools, Clément Le Goffic
On Fri, 25 Sep 2026 14:50:25 +0200, Clément Le Goffic wrote:
> lore: three fixes between a posted serie and the reader
>
> I'm using b4 in other projects and this allow to catch some issues.
> I used an LLM to find where does those come from and fix them.
>
> Here is a serie with three independant fixes.
> The first two are linked and come from the diff parsing:
> - a prior parsed file mode is kept and not cleaned
> - a commit diff with a submodule mode didn't allow fake-am
>
> [...]
Applied, thanks!
[1/3] lore: parse per-file modes in get_indexes
commit: c45656e17d1fa2dfa975c9fbde91785828c8a818
[2/3] lore: fake-am series that touch submodule gitlinks
commit: 5563c054a0b1471cc3f6f0b8179595e6bc457409
Best regards,
--
Konstantin Ryabitsev <konstantin@linuxfoundation.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH b4 3/3] lore: stop a less pager quitting on output that fits one screen
2026-10-05 10:09 ` Konstantin Ryabitsev
@ 2026-10-05 12:37 ` Clément Le Goffic
2026-10-06 7:15 ` Konstantin Ryabitsev
0 siblings, 1 reply; 10+ messages in thread
From: Clément Le Goffic @ 2026-10-05 12:37 UTC (permalink / raw)
To: Konstantin Ryabitsev; +Cc: Kernel.org Tools
Hi Konstantin,
On 10/5/26 12:09 PM, Konstantin Ryabitsev wrote:
>> [ ... 32 lines skipped ... ]
>> if '|' in pager:
>> # Pager uses a pipeline (e.g. "diff-highlight | less -RFX"),
>> # so we must use the shell to interpret it. Feed data on
>> # stdin since piped pagers read from the pipe, not from a
>> - # file argument.
>> + # file argument. The less inside is out of reach, so F only
>> + # comes off the environment here.
>> + env = dict(os.environ)
>> + env['LESS'] = env.get('LESS', 'FRX').replace('F', '')
>> logger.debug('Running (shell): %s < %s', pager, temp_fpath)
>> with open(temp_fpath, 'rb') as fh:
>> spop = subprocess.Popen(pager, shell=True, stdin=fh, env=env)
>> else:
>> sp = shlex.shlex(pager, posix=True)
>> sp.whitespace_split = True
>> - cmdargs = list(sp) + [temp_fpath]
>> + cmdargs = list(sp)
>> + if cmdargs and os.path.basename(cmdargs[0]) == 'less':
>> + # less takes its options left to right, so -+F resets
>> + # quit-if-one-screen whichever set it.
>> + cmdargs.append('-+F')
>> + cmdargs += [temp_fpath]
>> logger.debug('Running %s', ' '.join(cmdargs))
>> - spop = subprocess.Popen(cmdargs, env=env)
>> + spop = subprocess.Popen(cmdargs)
>
> Would this cause problems for people who set their less env to different
> settings? I'm not sure I'm comfortable blindly appending +F to all
> possible less invocations.
We were already removing F from environment variable before this patch
and to me it wouldn't interfere with people settings:
From `less --help`:
-F ........ --quit-if-one-screen
Quit if entire file fits on first screen.
From `man less`:
The environment variable is parsed before the command line, so command
line options override the LESS environment variable. If an option
appears in the LESS variable, it can be reset to its default value on
the command line by beginning the command line option with "-+".
This let me think that we might not need the env path at all in fact...
I'll rework the whole patch.
>
>> spop.wait()
>>
>>
>> diff --git a/src/tests/test___init__.py b/src/tests/test___init__.py
>> index 601c0dc..b677b69 100644
>> --- a/src/tests/test___init__.py
>> +++ b/src/tests/test___init__.py
>> @@ -2763,3 +2763,81 @@ class TestFakeAmGitlinkPreimage:
>> ecode, entry = b4.git_run_command(repo, ['ls-tree', commit, 'sub'])
>> assert ecode == 0
>> assert entry.split()[:3] == ['160000', 'commit', gitlink]
>> +
>> +
>> +class TestViewInPagerLessFlags:
>> + """-F has to come off a "less" pager, and nothing else may change.
>> +
>> + Output short enough to fit one screen -- a range-diff narrowed to a
>> + single patch, say -- is exactly what quit-if-one-screen flashes past
>> + the reader, and a core.pager of "less -FRSX" carries that flag where
>> + the LESS environment cannot reach it. less reads its options left to
>> + right, so appending -+F resets it whatever spelling the pager used,
>> + and nothing in the pager's own arguments is parsed or rewritten.
>> + """
>> +
>> + class _Spawned:
>> + """Stands in for the pager process, which nobody is here to read."""
>> +
>> + def wait(self) -> int:
>> + return 0
>> +
>> + @classmethod
>> + def _spawned(cls, monkeypatch: pytest.MonkeyPatch, pager: str) -> List[str]:
>> + """Return the argv view_in_pager() would have run."""
>> + seen: List[Any] = list()
>> + real_popen = b4.subprocess.Popen
>
> This line and the monkeypatch.setattr() below fail ci.sh at the mypy
> step (mypy runs in strict mode, so implicit re-exports are off):
>
> src/tests/test___init__.py:2789: error: Module "b4" does not
> explicitly export attribute "subprocess" [attr-defined]
> src/tests/test___init__.py:2800: error: (same)
>
> You should just add `import subprocess` to the test imports and use
> `subprocess.Popen` / `monkeypatch.setattr(subprocess, 'Popen',
> fake_popen)`. It patches the same object, so the behaviour does not
> change.
Right I'll rework the whole patch.
Best regards,
Clément
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH b4 3/3] lore: stop a less pager quitting on output that fits one screen
2026-10-05 12:37 ` Clément Le Goffic
@ 2026-10-06 7:15 ` Konstantin Ryabitsev
2026-10-06 8:27 ` Clément Le Goffic
0 siblings, 1 reply; 10+ messages in thread
From: Konstantin Ryabitsev @ 2026-10-06 7:15 UTC (permalink / raw)
To: Clément Le Goffic; +Cc: Kernel.org Tools
On Mon, Oct 05, 2026 at 02:37:11PM +0200, Clément Le Goffic wrote:
> > Would this cause problems for people who set their less env to different
> > settings? I'm not sure I'm comfortable blindly appending +F to all
> > possible less invocations.
>
> We were already removing F from environment variable before this patch and
> to me it wouldn't interfere with people settings:
>
> From `less --help`:
> -F ........ --quit-if-one-screen
> Quit if entire file fits on first screen.
> From `man less`:
> The environment variable is parsed before the command line, so command line
> options override the LESS environment variable. If an option appears in the
> LESS variable, it can be reset to its default value on the command line by
> beginning the command line option with "-+".
>
> This let me think that we might not need the env path at all in fact...
> I'll rework the whole patch.
I applied the new version, but then backed it out because it broke things for
me. :)
Fedora uses lesspipe.sh, and +F was putting it into "follow" mode that
resulted in a screen full of "~" marks and "Read error" at the bottom.
So, my initial reluctance has been confirmed -- there are too many possible
setups out there for us to try to second-guess what we should be trying to do.
It's best not to try to alter flags on the fly and let the users set up their
GIT_PAGER appropriately instead.
-K
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH b4 3/3] lore: stop a less pager quitting on output that fits one screen
2026-10-06 7:15 ` Konstantin Ryabitsev
@ 2026-10-06 8:27 ` Clément Le Goffic
0 siblings, 0 replies; 10+ messages in thread
From: Clément Le Goffic @ 2026-10-06 8:27 UTC (permalink / raw)
To: Konstantin Ryabitsev; +Cc: Kernel.org Tools
Hi Konstantin,
On 10/6/26 9:15 AM, Konstantin Ryabitsev wrote:
> On Mon, Oct 05, 2026 at 02:37:11PM +0200, Clément Le Goffic wrote:
>>> Would this cause problems for people who set their less env to different
>>> settings? I'm not sure I'm comfortable blindly appending +F to all
>>> possible less invocations.
>>
>> We were already removing F from environment variable before this patch and
>> to me it wouldn't interfere with people settings:
>>
>> From `less --help`:
>> -F ........ --quit-if-one-screen
>> Quit if entire file fits on first screen.
>> From `man less`:
>> The environment variable is parsed before the command line, so command line
>> options override the LESS environment variable. If an option appears in the
>> LESS variable, it can be reset to its default value on the command line by
>> beginning the command line option with "-+".
>>
>> This let me think that we might not need the env path at all in fact...
>> I'll rework the whole patch.
>
> I applied the new version, but then backed it out because it broke things for
> me. :)
Oh ok
> Fedora uses lesspipe.sh, and +F was putting it into "follow" mode that
> resulted in a screen full of "~" marks and "Read error" at the bottom.
:(
> So, my initial reluctance has been confirmed -- there are too many possible
> setups out there for us to try to second-guess what we should be trying to do.
> It's best not to try to alter flags on the fly and let the users set up their
> GIT_PAGER appropriately instead.
Yes I understand. We were already removing the 'F' option in LESS, I was
thinking that this was also making sense of removing it from the command
line.
Should we drop this LESS special case?
alias b4='GIT_PAGER="less -RSX" b4'
Will be my solution.
Best regards,
Clément
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-10-06 8:27 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-25 12:50 [PATCH b4 0/3] lore: three fixes between a posted serie and the reader Clément Le Goffic
2026-09-25 12:50 ` [PATCH b4 1/3] lore: parse per-file modes in get_indexes Clément Le Goffic
2026-09-25 12:50 ` [PATCH b4 2/3] lore: fake-am series that touch submodule gitlinks Clément Le Goffic
2026-09-25 12:50 ` [PATCH b4 3/3] lore: stop a less pager quitting on output that fits one screen Clément Le Goffic
2026-10-05 10:09 ` Konstantin Ryabitsev
2026-10-05 12:37 ` Clément Le Goffic
2026-10-06 7:15 ` Konstantin Ryabitsev
2026-10-06 8:27 ` Clément Le Goffic
2026-10-05 10:09 ` [PATCH b4 0/3] lore: three fixes between a posted serie and the reader Konstantin Ryabitsev
2026-10-05 10:11 ` (subset) " Konstantin Ryabitsev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox