tools.linux.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Marquardt <davemarq@linux.ibm.com>
To: Dave Marquardt via B4 Relay <devnull+davemarq.linux.ibm.com@kernel.org>
Cc: "Kernel.org Tools" <tools@kernel.org>,
	Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Subject: Re: [PATCH RESEND v2] Make edit_in_editor use temporary file in Git repository
Date: Tue, 18 Nov 2025 16:41:57 -0600	[thread overview]
Message-ID: <87a50jrmiy.fsf@linux.ibm.com> (raw)
In-Reply-To: <20251118-edit-with-tmp-file-in-repo-v2-1-0b633b471ddb@linux.ibm.com> (Dave Marquardt via's message of "Tue, 18 Nov 2025 15:34:25 -0600")

Dave Marquardt via B4 Relay <devnull+davemarq.linux.ibm.com@kernel.org>
writes:

> This is a resend of a patch I sent in June 2025. I noticed on
> reinstalling b4 that this hadn't been included in recent releases, and
> I couldn't find it in the master branch either.
>
> In edit_with_editor, create temporary directory in toplevel/.git/b4 if
> git top level exists. Otherwise let tempfile.TemporaryDirectory use
> its default directory. This avoids issues with Emacs and Magit, which
> insists COMMIT_EDITMSG must be in the repo's directory tree.

Since I sent this, I discovered this doesn't work with Git worktrees,
where the Git toplevel .git file is a regular file, not a directory. I
tried changing the code below to use Path(topdir) / '.b4' instead, and
that works fine. I suppose if you happen to have a .b4 subdirectory in a
repo or repo worktree that won't work.

I will send another patch for this tomorrow, when I've had more time to
think about it.

> Signed-off-by: Dave Marquardt <davemarq@linux.ibm.com>
> ---
>  src/b4/__init__.py | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/src/b4/__init__.py b/src/b4/__init__.py
> index 7689550..cc7623a 100644
> --- a/src/b4/__init__.py
> +++ b/src/b4/__init__.py
> @@ -4575,8 +4575,16 @@ def edit_in_editor(bdata: bytes, filehint: str = 'COMMIT_EDITMSG') -> bytes:
>      corecfg = get_config_from_git(r'core\..*', {'editor': os.environ.get('EDITOR', 'vi')})
>      editor = corecfg.get('editor')
>      logger.debug('editor=%s', editor)
> +
> +    topdir = git_get_toplevel()
> +    if topdir is not None:
> +        p = Path(topdir)
> +        p = p / '.git' / 'b4'
> +        p.mkdir(parents=True, exist_ok=True)
> +    else:
> +        p = None
>      # Use filehint name in hopes that editors autoload necessary highlight rules
> -    with tepmfile.TemporaryDirectory(prefix='b4-editor') as temp_dir:
> +    with tempfile.TemporaryDirectory(prefix='b4-editor', dir=p) as temp_dir:
>          temp_fpath = os.path.join(temp_dir, filehint)
>          with open(temp_fpath, 'xb') as edit_file:
>              edit_file.write(bdata)
>
> ---
> base-commit: a6db3f06ce9836a7fc8921f588452804fc62bed1
> change-id: 20251118-edit-with-tmp-file-in-repo-bc0d0465661a
>
> Best regards,
> --  
>
> Dave Marquardt <davemarq@linux.ibm.com>

      reply	other threads:[~2025-11-18 22:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-18 21:34 [PATCH RESEND v2] Make edit_in_editor use temporary file in Git repository Dave Marquardt via B4 Relay
2025-11-18 22:41 ` Dave Marquardt [this message]

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=87a50jrmiy.fsf@linux.ibm.com \
    --to=davemarq@linux.ibm.com \
    --cc=devnull+davemarq.linux.ibm.com@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).