Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Holdsworth <jholdsworth@nvidia.com>2021-12-16 16:46:15 +0300
committerJunio C Hamano <gitster@pobox.com>2021-12-17 01:06:35 +0300
commit8618d322e00f88b7b5528abfc75b26c162032a21 (patch)
tree28f95d9e9a5a508d2026e7281a280d6b872dc40c /git-p4.py
parente773545c7fe7eca21b134847f4fc2cbc9547fa14 (diff)
git-p4: use with statements to close files after use in patchRCSKeywords
Python with statements are used to wrap the execution of a block of code so that an object can be safely released when execution leaves the scope. They are desirable for improving code tidyness, and to ensure that objects are properly destroyed even when exceptions are thrown. Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-p4.py')
-rwxr-xr-xgit-p4.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/git-p4.py b/git-p4.py
index 2b4500226a..226cdef424 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1757,14 +1757,11 @@ class P4Submit(Command, P4UserMap):
# Attempt to zap the RCS keywords in a p4 controlled file matching the given pattern
(handle, outFileName) = tempfile.mkstemp(dir='.')
try:
- outFile = os.fdopen(handle, "w+")
- inFile = open(file, "r")
- regexp = re.compile(pattern, re.VERBOSE)
- for line in inFile.readlines():
- line = regexp.sub(r'$\1$', line)
- outFile.write(line)
- inFile.close()
- outFile.close()
+ with os.fdopen(handle, "w+") as outFile, open(file, "r") as inFile:
+ regexp = re.compile(pattern, re.VERBOSE)
+ for line in inFile.readlines():
+ line = regexp.sub(r'$\1$', line)
+ outFile.write(line)
# Forcibly overwrite the original file
os.unlink(file)
shutil.move(outFileName, file)