[PATCH] v2

6 views
Skip to first unread message

Antonio Muci

unread,
May 25, 2026, 11:14:35 AMMay 25
to thg...@googlegroups.com, a....@inwind.it
# HG changeset patch
# User Antonio Muci <a....@inwind.it>
# Date 1779721401 -7200
# Mon May 25 17:03:21 2026 +0200
# Branch stable
# Node ID 4f75624f6ec32e159c9438a6231d91c2b173d9fc
# Parent 9a3dd29b9a8c3e961528232dd04086a0c3ad82fd
shlib: use context manager in POSIX implementation of shell_notify()

This code change is more delicate than the ones done in the preceding commits,
because the initial logic was a bit more complex, and the function is used in
critical code paths (RepoWidget._notifyWorkingDirChanges(), thgstatus.run(),
etc.).

Please note that in fa72eb129087 ("shlib: simplify some file handling with
context managers") a judgement call was made not to modify this function.

However, I think that even in this case, and for all the relevant purposes, the
behavior before and after the change should be equivalent (but safer).

diff --git a/tortoisehg/util/shlib.py b/tortoisehg/util/shlib.py
--- a/tortoisehg/util/shlib.py
+++ b/tortoisehg/util/shlib.py
@@ -146,14 +146,11 @@ else:
if not os.path.isfile(notify):
return
try:
- f_notify = open(notify, 'wb')
+ with open(notify, 'wb') as f_notify:
+ abspaths = [os.path.abspath(path) for path in paths if path]
+ f_notify.write(b'\n'.join(abspaths))
except OSError:
return
- try:
- abspaths = [os.path.abspath(path) for path in paths if path]
- f_notify.write(b'\n'.join(abspaths))
- finally:
- f_notify.close()

def update_thgstatus(*args, **kws):
pass

Yuya Nishihara

unread,
May 26, 2026, 10:40:51 AMMay 26
to 'Antonio Muci' via TortoiseHg Developers, a....@inwind.it
On Mon, 25 May 2026 17:14:31 +0200, 'Antonio Muci' via TortoiseHg Developers wrote:
> # HG changeset patch
> # User Antonio Muci <a....@inwind.it>
> # Date 1779721401 -7200
> # Mon May 25 17:03:21 2026 +0200
> # Branch stable
> # Node ID 4f75624f6ec32e159c9438a6231d91c2b173d9fc
> # Parent 9a3dd29b9a8c3e961528232dd04086a0c3ad82fd
> shlib: use context manager in POSIX implementation of shell_notify()

Queued, thanks.
Reply all
Reply to author
Forward
0 new messages