Linux maintainer tooling and workflows
 help / color / mirror / Atom feed
From: "Clément Le Goffic" <clegoffic@baylibre.com>
To: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Cc: "Kernel.org Tools" <tools@kernel.org>
Subject: Re: [PATCH b4 3/3] lore: stop a less pager quitting on output that fits one screen
Date: Mon, 5 Oct 2026 14:37:11 +0200	[thread overview]
Message-ID: <01c5b15f-7f4e-4620-be36-bddaa37255d6@baylibre.com> (raw)
In-Reply-To: <179119498922.1802901.11622089083955121536.b4-review@b4>

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


  reply	other threads:[~2026-10-05 12:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=01c5b15f-7f4e-4620-be36-bddaa37255d6@baylibre.com \
    --to=clegoffic@baylibre.com \
    --cc=konstantin@linuxfoundation.org \
    --cc=tools@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox