From: Doug Freed <dwfreed@mtu.edu>
To: gentoo-portage-dev@lists.gentoo.org
Cc: Doug Goldstein <cardoe@cardoe.com>
Subject: [gentoo-portage-dev] [PATCH] Change how the tmp file for the commit msg is made (bug 571546)
Date: Sun, 22 May 2016 16:59:46 -0400 [thread overview]
Message-ID: <20160522205946.40078-1-dwfreed@mtu.edu> (raw)
From: Doug Goldstein <cardoe@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 <cardoe@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 other threads:[~2016-05-22 21:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160522205946.40078-1-dwfreed@mtu.edu \
--to=dwfreed@mtu.edu \
--cc=cardoe@cardoe.com \
--cc=gentoo-portage-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox