tools.linux.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH b4] Create temporary directory in current working directory
@ 2025-06-13 19:04 Dave Marquardt
  2025-06-18 13:54 ` Konstantin Ryabitsev
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Marquardt @ 2025-06-13 19:04 UTC (permalink / raw)
  To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Dave Marquardt



---
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.

Signed-off-by: Dave Marquardt <davemarq@linux.ibm.com>
---
 src/b4/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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)

---
base-commit: 220ba25f86b6f295eab8b4e9e67b624e460f0126
change-id: 20250613-fix-magit-edit-491efacc71a9

Best regards,
--  
Dave Marquardt <davemarq@linux.ibm.com>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH b4] Create temporary directory in current working directory
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Konstantin Ryabitsev @ 2025-06-18 13:54 UTC (permalink / raw)
  To: Dave Marquardt; +Cc: Kernel.org Tools

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.

> 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?

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.

-K

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH b4] Create temporary directory in current working directory
  2025-06-18 13:54 ` Konstantin Ryabitsev
@ 2025-06-18 15:02   ` Dave Marquardt
  0 siblings, 0 replies; 3+ messages in thread
From: Dave Marquardt @ 2025-06-18 15:02 UTC (permalink / raw)
  To: Konstantin Ryabitsev; +Cc: Kernel.org Tools

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-18 15:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).