# HG changeset patch
# User Antonio Muci <
a....@inwind.it>
# Date 1779721401 -7200
# Mon May 25 17:03:21 2026 +0200
# Branch stable
# Node ID 3dd80784c722e8bbbb28c00b95d12dd999b4e75b
# 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.).
The behavior before and after the change should however 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