git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 RESEND 4/5] git-p4: open temporary patch file for write only

From
Joel Holdsworth <jholdsworth@nvidia.com>
Date
Jan 4, 2022, 12:49 UTC
Message-ID
<20220104124913.2894-5-jholdsworth@nvidia.com>
In-Reply-To
<20220104124913.2894-1-jholdsworth@nvidia.com>

The patchRCSKeywords method creates a temporary file in which to store the patched output data. Previously this file was opened in "w+" mode (write and read), but the code never reads the contents of the file while open, so it only needs to be opened in "w" mode (write-only).

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
---
 git-p4.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/git-p4.py b/git-p4.py
index 509feac2d8..7845210e69 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1754,7 +1754,7 @@ def patchRCSKeywords(self, file, regexp):
         # Attempt to zap the RCS keywords in a p4 controlled file matching the given regex
         (handle, outFileName) = tempfile.mkstemp(dir='.')
         try:
-            with os.fdopen(handle, "w+") as outFile, open(file, "r") as inFile:
+            with os.fdopen(handle, "w") as outFile, open(file, "r") as inFile:
                 for line in inFile.readlines():
                     outFile.write(regexp.sub(r'$\1$', line))
             # Forcibly overwrite the original file
-- 
2.34.1
Previous: Joel HoldsworthNext: Joel Holdsworth
Message 5 of 9 in “git-p4: fix RCS keyword processing encoding errors”
  1. 0/5 git-p4: fix RCS keyword processing encoding errorsJoel Holdsworth, Jan 4, 2022
  2. 1/5 git-p4: use with statements to close files after use in patchRCSKeywordsJoel Holdsworth, Jan 4, 2022
  3. 2/5 git-p4: pre-compile RCS keyword regexesJoel Holdsworth, Jan 4, 2022
  4. 3/5 git-p4: add raw option to read_pipelinesJoel Holdsworth, Jan 4, 2022
  5. 4/5 git-p4: open temporary patch file for write onlyJoel Holdsworth, Jan 4, 2022
  6. 5/5 git-p4: resolve RCS keywords in bytes not utf-8Joel Holdsworth, Jan 4, 2022
  7. Junio C HamanoJan 4, 2022
  8. Joel HoldsworthJan 4, 2022
  9. Junio C HamanoJan 4, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.