From: Doug Goldstein <car...@cardoe.com>

Changes the way the temporary file for the commit message is generated
to make a temporary directory and create a file called COMMIT_EDITMSG
inside of it. This is to cause various editors to treat this as a git
style commit message by default.

Signed-off-by: Doug Goldstein <car...@cardoe.com>
X-Gentoo-Bug: 571546
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=571546
---
 repoman/pym/repoman/actions.py   | 21 +++++++++++----------
 repoman/pym/repoman/utilities.py | 39 ++++++++++++++++++++-------------------
 2 files changed, 31 insertions(+), 29 deletions(-)

diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.py
index 4144b45..822a538 100644
--- a/repoman/pym/repoman/actions.py
+++ b/repoman/pym/repoman/actions.py
@@ -6,6 +6,7 @@ import errno
 import io
 import logging
 import platform
+import shutil
 import signal
 import sys
 import tempfile
@@ -446,15 +447,15 @@ class Actions(object):
                        myfiles += myremoved
                myfiles.sort()
 
-               fd, commitmessagefile = tempfile.mkstemp(".repoman.msg")
-               mymsg = os.fdopen(fd, "wb")
-               mymsg.write(_unicode_encode(commitmessage))
-               mymsg.close()
+               commitmessagedir = tempfile.mkdtemp(".repoman.msg")
+               commitmessagefile = os.path.join(commitmessagedir, 
"COMMIT_EDITMSG")
+               with open(commitmessagefile, "wb") as mymsg:
+                       mymsg.write(_unicode_encode(commitmessage))
 
                retval = self.vcs_settings.changes.commit(myfiles, 
commitmessagefile)
                # cleanup the commit message before possibly exiting
                try:
-                       os.unlink(commitmessagefile)
+                       shutil.rmtree(commitmessagedir)
                except OSError:
                        pass
                if retval != os.EX_OK:
@@ -467,10 +468,10 @@ class Actions(object):
 
        def priming_commit(self, myupdates, myremoved, commitmessage):
                myfiles = myupdates + myremoved
-               fd, commitmessagefile = tempfile.mkstemp(".repoman.msg")
-               mymsg = os.fdopen(fd, "wb")
-               mymsg.write(_unicode_encode(commitmessage))
-               mymsg.close()
+               commitmessagedir = tempfile.mkdtemp(".repoman.msg")
+               commitmessagefile = os.path.join(commitmessagedir, 
"COMMIT_EDITMSG")
+               with open(commitmessagefile, "wb") as mymsg:
+                       mymsg.write(_unicode_encode(commitmessage))
 
                separator = '-' * 78
 
@@ -489,7 +490,7 @@ class Actions(object):
                retval = self.vcs_settings.changes.commit(myfiles, 
commitmessagefile)
                # cleanup the commit message before possibly exiting
                try:
-                       os.unlink(commitmessagefile)
+                       shutil.rmtree(commitmessagedir)
                except OSError:
                        pass
                if retval != os.EX_OK:
diff --git a/repoman/pym/repoman/utilities.py b/repoman/pym/repoman/utilities.py
index 8a757dc..c204faa 100644
--- a/repoman/pym/repoman/utilities.py
+++ b/repoman/pym/repoman/utilities.py
@@ -30,7 +30,7 @@ import sys
 import time
 import textwrap
 import difflib
-from tempfile import mkstemp
+import tempfile
 
 # import our initialized portage instance
 from repoman._portage import portage
@@ -187,23 +187,24 @@ def get_commit_message_with_editor(editor, message=None, 
prefix=""):
        @rtype: string or None
        @return: A string on success or None if an error occurs.
        """
-       fd, filename = mkstemp()
+       commitmessagedir = tempfile.mkdtemp(".repoman.msg")
+       filename = os.path.join(commitmessagedir, "COMMIT_EDITMSG")
        try:
-               os.write(
-                       fd, _unicode_encode(_(
-                               prefix +
-                               "\n\n# Please enter the commit message "
-                               "for your changes.\n# (Comment lines starting "
-                               "with '#' will not be included)\n"),
-                               encoding=_encodings['content'], 
errors='backslashreplace'))
-               if message:
-                       os.write(fd, b"#\n")
-                       for line in message:
-                               os.write(
-                                       fd, _unicode_encode(
-                                               "#" + line, 
encoding=_encodings['content'],
-                                               errors='backslashreplace'))
-               os.close(fd)
+               with open(filename, "wb") as mymsg:
+                       mymsg.write(
+                               _unicode_encode(_(
+                                       prefix +
+                                       "\n\n# Please enter the commit message "
+                                       "for your changes.\n# (Comment lines 
starting "
+                                       "with '#' will not be included)\n"),
+                                       encoding=_encodings['content'], 
errors='backslashreplace'))
+                       if message:
+                               mymsg.write(b"#\n")
+                               for line in message:
+                                       mymsg.write(
+                                               _unicode_encode(
+                                                       "#" + line, 
encoding=_encodings['content'],
+                                                       
errors='backslashreplace'))
                retval = os.system(editor + " '%s'" % filename)
                if not (os.WIFEXITED(retval) and os.WEXITSTATUS(retval) == 
os.EX_OK):
                        return None
@@ -220,7 +221,7 @@ def get_commit_message_with_editor(editor, message=None, 
prefix=""):
                return "".join(line for line in mylines if not 
line.startswith("#"))
        finally:
                try:
-                       os.unlink(filename)
+                       shutil.rmtree(commitmessagedir)
                except OSError:
                        pass
 
@@ -409,7 +410,7 @@ def UpdateChangeLog(
        except EnvironmentError:
                pass
 
-       f, clnew_path = mkstemp()
+       f, clnew_path = tempfile.mkstemp()
 
        # construct correct header first
        try:
-- 
2.8.3


Reply via email to