1 |
From: Doug Goldstein <cardoe@××××××.com> |
2 |
|
3 |
Changes the way the temporary file for the commit message is generated |
4 |
to make a temporary directory and create a file called COMMIT_EDITMSG |
5 |
inside of it. This is to cause various editors to treat this as a git |
6 |
style commit message by default. |
7 |
|
8 |
Signed-off-by: Doug Goldstein <cardoe@××××××.com> |
9 |
X-Gentoo-Bug: 571546 |
10 |
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=571546 |
11 |
--- |
12 |
repoman/pym/repoman/actions.py | 21 +++++++++++---------- |
13 |
repoman/pym/repoman/utilities.py | 39 ++++++++++++++++++++------------------- |
14 |
2 files changed, 31 insertions(+), 29 deletions(-) |
15 |
|
16 |
diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.py |
17 |
index 4144b45..822a538 100644 |
18 |
--- a/repoman/pym/repoman/actions.py |
19 |
+++ b/repoman/pym/repoman/actions.py |
20 |
@@ -6,6 +6,7 @@ import errno |
21 |
import io |
22 |
import logging |
23 |
import platform |
24 |
+import shutil |
25 |
import signal |
26 |
import sys |
27 |
import tempfile |
28 |
@@ -446,15 +447,15 @@ class Actions(object): |
29 |
myfiles += myremoved |
30 |
myfiles.sort() |
31 |
|
32 |
- fd, commitmessagefile = tempfile.mkstemp(".repoman.msg") |
33 |
- mymsg = os.fdopen(fd, "wb") |
34 |
- mymsg.write(_unicode_encode(commitmessage)) |
35 |
- mymsg.close() |
36 |
+ commitmessagedir = tempfile.mkdtemp(".repoman.msg") |
37 |
+ commitmessagefile = os.path.join(commitmessagedir, "COMMIT_EDITMSG") |
38 |
+ with open(commitmessagefile, "wb") as mymsg: |
39 |
+ mymsg.write(_unicode_encode(commitmessage)) |
40 |
|
41 |
retval = self.vcs_settings.changes.commit(myfiles, commitmessagefile) |
42 |
# cleanup the commit message before possibly exiting |
43 |
try: |
44 |
- os.unlink(commitmessagefile) |
45 |
+ shutil.rmtree(commitmessagedir) |
46 |
except OSError: |
47 |
pass |
48 |
if retval != os.EX_OK: |
49 |
@@ -467,10 +468,10 @@ class Actions(object): |
50 |
|
51 |
def priming_commit(self, myupdates, myremoved, commitmessage): |
52 |
myfiles = myupdates + myremoved |
53 |
- fd, commitmessagefile = tempfile.mkstemp(".repoman.msg") |
54 |
- mymsg = os.fdopen(fd, "wb") |
55 |
- mymsg.write(_unicode_encode(commitmessage)) |
56 |
- mymsg.close() |
57 |
+ commitmessagedir = tempfile.mkdtemp(".repoman.msg") |
58 |
+ commitmessagefile = os.path.join(commitmessagedir, "COMMIT_EDITMSG") |
59 |
+ with open(commitmessagefile, "wb") as mymsg: |
60 |
+ mymsg.write(_unicode_encode(commitmessage)) |
61 |
|
62 |
separator = '-' * 78 |
63 |
|
64 |
@@ -489,7 +490,7 @@ class Actions(object): |
65 |
retval = self.vcs_settings.changes.commit(myfiles, commitmessagefile) |
66 |
# cleanup the commit message before possibly exiting |
67 |
try: |
68 |
- os.unlink(commitmessagefile) |
69 |
+ shutil.rmtree(commitmessagedir) |
70 |
except OSError: |
71 |
pass |
72 |
if retval != os.EX_OK: |
73 |
diff --git a/repoman/pym/repoman/utilities.py b/repoman/pym/repoman/utilities.py |
74 |
index 8a757dc..c204faa 100644 |
75 |
--- a/repoman/pym/repoman/utilities.py |
76 |
+++ b/repoman/pym/repoman/utilities.py |
77 |
@@ -30,7 +30,7 @@ import sys |
78 |
import time |
79 |
import textwrap |
80 |
import difflib |
81 |
-from tempfile import mkstemp |
82 |
+import tempfile |
83 |
|
84 |
# import our initialized portage instance |
85 |
from repoman._portage import portage |
86 |
@@ -187,23 +187,24 @@ def get_commit_message_with_editor(editor, message=None, prefix=""): |
87 |
@rtype: string or None |
88 |
@return: A string on success or None if an error occurs. |
89 |
""" |
90 |
- fd, filename = mkstemp() |
91 |
+ commitmessagedir = tempfile.mkdtemp(".repoman.msg") |
92 |
+ filename = os.path.join(commitmessagedir, "COMMIT_EDITMSG") |
93 |
try: |
94 |
- os.write( |
95 |
- fd, _unicode_encode(_( |
96 |
- prefix + |
97 |
- "\n\n# Please enter the commit message " |
98 |
- "for your changes.\n# (Comment lines starting " |
99 |
- "with '#' will not be included)\n"), |
100 |
- encoding=_encodings['content'], errors='backslashreplace')) |
101 |
- if message: |
102 |
- os.write(fd, b"#\n") |
103 |
- for line in message: |
104 |
- os.write( |
105 |
- fd, _unicode_encode( |
106 |
- "#" + line, encoding=_encodings['content'], |
107 |
- errors='backslashreplace')) |
108 |
- os.close(fd) |
109 |
+ with open(filename, "wb") as mymsg: |
110 |
+ mymsg.write( |
111 |
+ _unicode_encode(_( |
112 |
+ prefix + |
113 |
+ "\n\n# Please enter the commit message " |
114 |
+ "for your changes.\n# (Comment lines starting " |
115 |
+ "with '#' will not be included)\n"), |
116 |
+ encoding=_encodings['content'], errors='backslashreplace')) |
117 |
+ if message: |
118 |
+ mymsg.write(b"#\n") |
119 |
+ for line in message: |
120 |
+ mymsg.write( |
121 |
+ _unicode_encode( |
122 |
+ "#" + line, encoding=_encodings['content'], |
123 |
+ errors='backslashreplace')) |
124 |
retval = os.system(editor + " '%s'" % filename) |
125 |
if not (os.WIFEXITED(retval) and os.WEXITSTATUS(retval) == os.EX_OK): |
126 |
return None |
127 |
@@ -220,7 +221,7 @@ def get_commit_message_with_editor(editor, message=None, prefix=""): |
128 |
return "".join(line for line in mylines if not line.startswith("#")) |
129 |
finally: |
130 |
try: |
131 |
- os.unlink(filename) |
132 |
+ shutil.rmtree(commitmessagedir) |
133 |
except OSError: |
134 |
pass |
135 |
|
136 |
@@ -409,7 +410,7 @@ def UpdateChangeLog( |
137 |
except EnvironmentError: |
138 |
pass |
139 |
|
140 |
- f, clnew_path = mkstemp() |
141 |
+ f, clnew_path = tempfile.mkstemp() |
142 |
|
143 |
# construct correct header first |
144 |
try: |
145 |
-- |
146 |
2.8.3 |