Skip to content

Commit

Permalink
Fix prep-perpatch-check-cmd in .b4-config
Browse files Browse the repository at this point in the history
Trying to use the 'prep-perpatch-check-cmd' config from a repo
with '.b4-config' fails. For example as follows

  $ b4 --version
  0.14.0
  $ printf '[b4]\n\tprep-perpatch-check-cmd = "true"\n' >.b4-config \
        && git add .b4-config && git commit -m b4-test
  $ b4 prep --check
  Checking patches using:
    t
    r
    u
    e
  ---
  Traceback (most recent call last):
    File "/home/blmaier/.local/bin/b4", line 8, in <module>
      sys.exit(cmd())
               ^^^^^
    File "/home/blmaier/.local/lib/python3.12/site-packages/b4/command.py", line 417, in cmd
      cmdargs.func(cmdargs)
    File "/home/blmaier/.local/lib/python3.12/site-packages/b4/command.py", line 83, in cmd_prep
      b4.ez.cmd_prep(cmdargs)
    File "/home/blmaier/.local/lib/python3.12/site-packages/b4/ez.py", line 2822, in cmd_prep
      return check(cmdargs)
             ^^^^^^^^^^^^^^
    File "/home/blmaier/.local/lib/python3.12/site-packages/b4/ez.py", line 1707, in check
      ckrep = b4.LoreMessage.run_local_check(ppcmdargs, commit, msg, nocache=cmdargs.nocache)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/blmaier/.local/lib/python3.12/site-packages/b4/__init__.py", line 1522, in run_local_check
      ecode, out, err = _run_command(cmdargs, stdin=bdata, rundir=topdir)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/blmaier/.local/lib/python3.12/site-packages/b4/__init__.py", line 2650, in _run_command
      sp = subprocess.Popen(cmdargs, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.12/subprocess.py", line 1026, in __init__
      self._execute_child(args, executable, preexec_fn, close_fds,
    File "/usr/lib64/python3.12/subprocess.py", line 1955, in _execute_child
      raise child_exception_type(errno_num, err_msg, err_filename)
  FileNotFoundError: [Errno 2] No such file or directory: 't'

The problem is 'prep-perpatch-check-cmd' is the special 'multival' type
(Python list). But when the .b4-config is imported it does not specify
the multival types, so it gets imported as a string. When b4 tries to
call the check-cmd later on, it gets iterated over as if it were a list
but instead returns each character.

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Link: https://patch.msgid.link/20240626-b4-config-check-cmd-v1-1-83fc971196f9@collins.com
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
(cherry picked from commit d5f3956)
  • Loading branch information
blmaier authored and mricon committed Sep 6, 2024
1 parent 9c06d72 commit 0741bc9
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/b4/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2857,6 +2857,14 @@ def get_config_from_git(regexp: str, defaults: Optional[dict] = None,
return gitconfig


def _val_to_path(topdir, val):
if val.startswith('./'):
# replace it with full topdir path
return os.path.abspath(os.path.join(topdir, val))
else:
return val


def _setup_main_config(cmdargs: Optional[argparse.Namespace] = None) -> None:
global MAIN_CONFIG

Expand All @@ -2865,23 +2873,24 @@ def _setup_main_config(cmdargs: Optional[argparse.Namespace] = None) -> None:
# so load them up and use as defaults
topdir = git_get_toplevel()
wtglobs = ['prep-*-check-cmd', 'send-*', '*mask', '*template*', 'trailer*', 'pw-*']
multivals = ['keyringsrc', 'am-perpatch-check-cmd', 'prep-perpatch-check-cmd']
if topdir:
wtcfg = os.path.join(topdir, '.b4-config')
if os.access(wtcfg, os.R_OK):
logger.debug('Loading worktree configs from %s', wtcfg)
wtconfig = get_config_from_git(r'b4\..*', source=wtcfg)
wtconfig = get_config_from_git(r'b4\..*', multivals=multivals, source=wtcfg)
logger.debug('wtcfg=%s', wtconfig)
for key, val in wtconfig.items():
if val.startswith('./'):
# replace it with full topdir path
val = os.path.abspath(os.path.join(topdir, val))
if key in multivals:
val = [_val_to_path(topdir, x) for x in val]
else:
val = _val_to_path(topdir, val)
for wtglob in wtglobs:
if fnmatch.fnmatch(key, wtglob):
logger.debug('wtcfg: %s=%s', key, val)
defcfg[key] = val
break
config = get_config_from_git(r'b4\..*', defaults=defcfg,
multivals=['keyringsrc', 'am-perpatch-check-cmd', 'prep-perpatch-check-cmd'])
config = get_config_from_git(r'b4\..*', defaults=defcfg, multivals=multivals)
config['listid-preference'] = config['listid-preference'].split(',')
config['listid-preference'].remove('*')
config['listid-preference'].append('*')
Expand Down

0 comments on commit 0741bc9

Please sign in to comment.