# Date 1779696270 -7200
# Mon May 25 10:04:30 2026 +0200
# Branch stable
# Node ID 9a3dd29b9a8c3e961528232dd04086a0c3ad82fd
# Parent d932cf48ea4f92f1173804e3de3b57ac9a7cd4cf
patchctx: use context manager in _files()
diff --git a/tortoisehg/util/patchctx.py b/tortoisehg/util/patchctx.py
--- a/tortoisehg/util/patchctx.py
+++ b/tortoisehg/util/patchctx.py
@@ -225,30 +225,28 @@ class patchctx:
return type, rawpath.split(b'/', 1)[-1]
files = {}
- pf = open(self._path, 'rb')
- try:
- # consume comments and headers
- for i in range(self._ph.diffstartline):
- pf.readline()
- for chunk in patch.parsepatch(pf):
- if not isinstance(chunk, patch.header):
- continue
- top = patch.parsefilename(chunk.header[-2])
- bot = patch.parsefilename(chunk.header[-1])
- type, path = get_path(top, bot)
- if path not in chunk.files():
- type, path = 0, chunk.files()[-1]
- if path not in files:
- self._status[type].append(path)
- files[path] = [chunk]
- self._fileorder.append(path)
- files[path].extend(chunk.hunks)
- except (patch.PatchError, AttributeError) as e:
- self._status[2].append(self._parseErrorFileName)
- files[self._parseErrorFileName] = []
- self._parseerror = e
- if 'THGDEBUG' in os.environ:
- print(hglib.exception_str(e))
- finally:
- pf.close()
+ with open(self._path, 'rb') as pf:
+ try:
+ # consume comments and headers
+ for i in range(self._ph.diffstartline):
+ pf.readline()
+ for chunk in patch.parsepatch(pf):
+ if not isinstance(chunk, patch.header):
+ continue
+ top = patch.parsefilename(chunk.header[-2])
+ bot = patch.parsefilename(chunk.header[-1])
+ type, path = get_path(top, bot)
+ if path not in chunk.files():
+ type, path = 0, chunk.files()[-1]
+ if path not in files:
+ self._status[type].append(path)
+ files[path] = [chunk]
+ self._fileorder.append(path)
+ files[path].extend(chunk.hunks)
+ except (patch.PatchError, AttributeError) as e:
+ self._status[2].append(self._parseErrorFileName)
+ files[self._parseErrorFileName] = []
+ self._parseerror = e
+ if 'THGDEBUG' in os.environ:
+ print(hglib.exception_str(e))
return files