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

[PATCH v4 3/4] git-p4: wrap patchRCSKeywords test to revert changes on failure

From
Ben Keene via GitGitGadget <gitgitgadget@gmail.com>
Date
Dec 13, 2019, 13:58 UTC
Message-ID
<20f63986935cd4ca850d0ecdbb5af5fa0658167b.1576245481.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.675.v4.git.git.1576245481.gitgitgadget@gmail.com>
From: Ben Keene <seraphire@gmail.com>

The patchRCSKeywords function has the potentional of throwing an exception and this would leave files checked out in P4 and partially modified.

Add a try-catch block around the patchRCSKeywords call and revert the edited files in P4 before leaving the method.

Signed-off-by: Ben Keene <seraphire@gmail.com>
---
 git-p4.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index 9165ada2fd..03969052c8 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1953,8 +1953,15 @@ def applyCommit(self, id):
                     # disable the read-only bit on windows.
                     if self.isWindows and file not in editedFiles:
                         os.chmod(file, stat.S_IWRITE)
-                    self.patchRCSKeywords(file, kwfiles[file])
-                    fixed_rcs_keywords = True
+                    
+                    try:
+                        self.patchRCSKeywords(file, kwfiles[file])
+                        fixed_rcs_keywords = True
+                    except:
+                        # We are throwing an exception, undo all open edits
+                        for f in editedFiles:
+                            p4_revert(f)
+                        raise
 
             if fixed_rcs_keywords:
                 print("Retrying the patch with RCS keywords cleaned up")
-- 
gitgitgadget
Previous: Ben Keene via GitGitGadgetNext: Ben Keene via GitGitGadget
Message 32 of 46 in “git-p4: Usability enhancements”
  1. 0/3 git-p4: Usability enhancementsBen Keene via GitGitGadget, Dec 9, 2019
  2. 1/3 git-p4: [usability] yes/no prompts should sanitize user textBen Keene via GitGitGadget, Dec 9, 2019
  3. Junio C HamanoDec 9, 2019
  4. Ben KeeneDec 10, 2019
  5. 2/3 git-p4: [usability] RCS Keyword failure should suggest helpBen Keene via GitGitGadget, Dec 9, 2019
  6. Junio C HamanoDec 9, 2019
  7. 3/3 git-p4: [usability] Show detailed help when parsing options failBen Keene via GitGitGadget, Dec 9, 2019
  8. Junio C HamanoDec 9, 2019
  9. Junio C HamanoDec 9, 2019
  10. 0/4 git-p4: Usability enhancementsBen Keene via GitGitGadget, Dec 10, 2019
  11. 2/4 git-p4: show detailed help when parsing options failBen Keene via GitGitGadget, Dec 10, 2019
  12. 4/4 git-p4: failure because of RCS keywords should show helpBen Keene via GitGitGadget, Dec 10, 2019
  13. Denton LiuDec 11, 2019
  14. 3/4 git-p4: wrap patchRCSKeywords test to revert changes on failureBen Keene via GitGitGadget, Dec 10, 2019
  15. 1/4 git-p4: yes/no prompts should sanitize user textBen Keene via GitGitGadget, Dec 10, 2019
  16. Denton LiuDec 11, 2019
  17. Denton LiuDec 11, 2019
  18. Luke DiamandDec 11, 2019
  19. 0/4 git-p4: Usability enhancementsBen Keene via GitGitGadget, Dec 12, 2019
  20. 2/4 git-p4: show detailed help when parsing options failBen Keene via GitGitGadget, Dec 12, 2019
  21. 3/4 git-p4: wrap patchRCSKeywords test to revert changes on failureBen Keene via GitGitGadget, Dec 12, 2019
  22. 4/4 git-p4: failure because of RCS keywords should show helpBen Keene via GitGitGadget, Dec 12, 2019
  23. 1/4 git-p4: yes/no prompts should sanitize user textBen Keene via GitGitGadget, Dec 12, 2019
  24. Denton LiuDec 13, 2019
  25. Ben KeeneDec 13, 2019
  26. Junio C HamanoDec 13, 2019
  27. Johannes SchindelinDec 15, 2019
  28. Junio C HamanoDec 16, 2019
  29. Ben KeeneDec 16, 2019
  30. 0/4 git-p4: Usability enhancementsBen Keene via GitGitGadget, Dec 13, 2019
  31. 2/4 git-p4: show detailed help when parsing options failBen Keene via GitGitGadget, Dec 13, 2019
  32. 3/4 git-p4: wrap patchRCSKeywords test to revert changes on failureBen Keene via GitGitGadget, Dec 13, 2019
  33. 1/4 git-p4: yes/no prompts should sanitize user textBen Keene via GitGitGadget, Dec 13, 2019
  34. Denton LiuDec 13, 2019
  35. Ben KeeneDec 16, 2019
  36. 4/4 git-p4: failure because of RCS keywords should show helpBen Keene via GitGitGadget, Dec 13, 2019
  37. 0/4 git-p4: Usability enhancementsBen Keene via GitGitGadget, Dec 16, 2019
  38. 1/4 git-p4: yes/no prompts should sanitize user textBen Keene via GitGitGadget, Dec 16, 2019
  39. 4/4 git-p4: failure because of RCS keywords should show helpBen Keene via GitGitGadget, Dec 16, 2019
  40. 3/4 git-p4: wrap patchRCSKeywords test to revert changes on failureBen Keene via GitGitGadget, Dec 16, 2019
  41. 2/4 git-p4: show detailed help when parsing options failBen Keene via GitGitGadget, Dec 16, 2019
  42. Junio C HamanoDec 16, 2019
  43. Luke DiamandDec 21, 2019
  44. Junio C HamanoDec 25, 2019
  45. Ben KeeneJan 2, 2020
  46. Junio C HamanoJan 2, 2020

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.