From: Dave Marquardt <davemarq@linux.ibm.com>
To: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Cc: "Kernel.org Tools" <tools@kernel.org>
Subject: Re: [PATCH b4] Create temporary directory in current working directory
Date: Wed, 18 Jun 2025 10:02:13 -0500 [thread overview]
Message-ID: <87wm99hz4a.fsf@linux.ibm.com> (raw)
In-Reply-To: <20250618-bipedal-saluki-of-expression-04cde5@lemur> (Konstantin Ryabitsev's message of "Wed, 18 Jun 2025 09:54:00 -0400")
Konstantin Ryabitsev <konstantin@linuxfoundation.org> writes:
> On Fri, Jun 13, 2025 at 02:04:05PM -0500, Dave Marquardt wrote:
>>
>>
>> ---
>> In edit_with_editor, create temporary directory in current working
>> directory. This avoids issues with Emacs and Magit, which insists
>> COMMIT_EDITMSG must be in the repo's directory tree.
>
> I'm curious how you ended up with the --- at the start of this. Seems like a
> bug that needs fixing.
Hmm, I'll take a look at that too!
>> diff --git a/src/b4/__init__.py b/src/b4/__init__.py
>> index 0a7daec..79d695a 100644
>> --- a/src/b4/__init__.py
>> +++ b/src/b4/__init__.py
>> @@ -4423,7 +4423,7 @@ def edit_in_editor(bdata: bytes, filehint: str = 'COMMIT_EDITMSG') -> bytes:
>> editor = corecfg.get('editor')
>> logger.debug('editor=%s', editor)
>> # Use filehint name in hopes that editors autoload necessary highlight rules
>> - with tempfile.TemporaryDirectory(prefix='b4-editor') as temp_dir:
>> + with tempfile.TemporaryDirectory(prefix='b4-editor', dir=Path.cwd()) as temp_dir:
>> temp_fpath = os.path.join(temp_dir, filehint)
>> with open(temp_fpath, 'xb') as edit_file:
>> edit_file.write(bdata)
>
> I think we can do better than that. We can call call git_get_toplevel() and,
> if that is not None, specify dir as toplevel/.git/b4, otherwise default to dir
> as being None to let it use whatever Python thinks should be the default. Can
> you test if using .git/b4/COMMIT_EDITMSG will do the right thing for you?
Yes, that's a good idea. I'll work on an update.
> We shouldn't use cwd(), because this can litter your git tree with junk. I
> know Python is supposed to always clean it up, but this can still have bad
> consequences if you run the editor in b4, forget that it's open in another
> terminal window, and then try to do some git operations.
Yeah, I can see that happening!
-Dave
prev parent reply other threads:[~2025-06-18 15:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-13 19:04 [PATCH b4] Create temporary directory in current working directory Dave Marquardt
2025-06-18 13:54 ` Konstantin Ryabitsev
2025-06-18 15:02 ` 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=87wm99hz4a.fsf@linux.ibm.com \
--to=davemarq@linux.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.