From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 868C7138262 for ; Sun, 22 May 2016 21:00:08 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id AF7F921C01D; Sun, 22 May 2016 21:00:06 +0000 (UTC) Received: from mail-ig0-f196.google.com (mail-ig0-f196.google.com [209.85.213.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 28F8D21C012 for ; Sun, 22 May 2016 21:00:05 +0000 (UTC) Received: by mail-ig0-f196.google.com with SMTP id gt8so3325876igc.2 for ; Sun, 22 May 2016 14:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mtu-edu.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=EOtcI8ZGmO81d40oWHWIm/IjzkCuPC/3Gjo4KHB3cBo=; b=DsAHIeLss7etjlTfKhdsY6KzAzm/5kuD+xvuTqUyOVu2RCCscR35+DcrAIOD92hIhS 15JgsqCa03J2cN9g4MqpmpGpgH78vKzQmghS2zzdAQYUxdwVmzgXMAqEnA4IISgODoqx r3LuwAAK5KJqaHdmFNugsotDv7ySg9tKMBCjkf0OAkR6la6+5OCtxkiLREMGtxKQY54U P2jzCGHR/kDmLodFHs84zqPay8P6fnkEi2HYy93RKG45vEdqhfnvNuOFJus2DOuF4/JK SaeJejWXkxIIIEKMQl2SzUgrq6cAkb574uE7aWnESI2SIa6lOTdMWQ7Iw8VZgtfTH8Pa XlnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=EOtcI8ZGmO81d40oWHWIm/IjzkCuPC/3Gjo4KHB3cBo=; b=Jy6y6O4LF9PROE/4RFcme67nCYhwPAGaEOlyo4+eujifdZiyMv4ZSXrWo3R622XkQX +9U0fLKST+p4CuaArNkT8P75Gjx7jxlNVgX0r+SgGH7dVK7yNvexvFSxFgAWmzky/VBR Ezt9T9O2UsLbWObkZV19xv3DAJZ6CNhSC8dnOxM+aGYzwSfD9Hnn0XcBCfLZzk46UpD2 SOSBwuzCT4YJWoQHIJ1I6qmrvqsqVV5ix8QdYGy1LvghjCa+a28iFKjbnrA398Fblply yyaXu/Z2/jYaDknTXe6xZIqaNeOhWFXKdQSPOgnmFPvhnF1KsN5LewvHqO4b2nJ4mP27 X4OA== X-Gm-Message-State: AOPr4FXFLsa+Y+sJloHW0hf/RwbSuYMZPxEZGhj5Yi7XWJcEN4qU4TSsrgUQb1+tNyO+Ab02 X-Received: by 10.50.18.132 with SMTP id w4mr10433380igd.83.1463950805114; Sun, 22 May 2016 14:00:05 -0700 (PDT) Received: from localhost.localdomain (173.241.113.71.4wbi.net. [173.241.113.71]) by smtp.gmail.com with ESMTPSA id m65sm9189213ioa.14.2016.05.22.14.00.01 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 22 May 2016 14:00:04 -0700 (PDT) From: Doug Freed To: gentoo-portage-dev@lists.gentoo.org Cc: Doug Goldstein 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 Message-Id: <20160522205946.40078-1-dwfreed@mtu.edu> X-Mailer: git-send-email 2.8.3 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Archives-Salt: 95453bd9-c069-44aa-8975-8c5e7b46f217 X-Archives-Hash: c06eba9c50edd03a74033b6aee46a69f From: Doug Goldstein 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 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