|
@@ -0,0 +1,57 @@
|
|
|
+# patch.py -- For dealing wih packed-style patches.
|
|
|
+# Copryight (C) 2009 Jelmer Vernooij <jelmer@samba.org>
|
|
|
+#
|
|
|
+# This program is free software; you can redistribute it and/or
|
|
|
+# modify it under the terms of the GNU General Public License
|
|
|
+# as published by the Free Software Foundation; version 2
|
|
|
+# of the License or (at your option) a later version.
|
|
|
+#
|
|
|
+# This program is distributed in the hope that it will be useful,
|
|
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+# GNU General Public License for more details.
|
|
|
+#
|
|
|
+# You should have received a copy of the GNU General Public License
|
|
|
+# along with this program; if not, write to the Free Software
|
|
|
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
+# MA 02110-1301, USA.
|
|
|
+
|
|
|
+"""Classes for dealing with git am-style patches.
|
|
|
+
|
|
|
+These patches are basically unified diffs with some extra metadata tacked
|
|
|
+on.
|
|
|
+"""
|
|
|
+
|
|
|
+import time
|
|
|
+
|
|
|
+def write_commit_patch(f, commit, progress, version=None):
|
|
|
+ """Write a individual file patch.
|
|
|
+
|
|
|
+ :param commit: Commit object
|
|
|
+ :param progress: Tuple with current patch number and total.
|
|
|
+ :return: tuple with filename and contents
|
|
|
+ """
|
|
|
+ (num, total) = progress
|
|
|
+ f.write("From %s %s\n" % (commit.id, time.ctime(commit.commit_time)))
|
|
|
+ f.write("From: %s\n" % commit.author)
|
|
|
+ f.write("Date: %s\n" % time.strftime("%a, %d %b %Y %H:%M:%S %Z"))
|
|
|
+ f.write("Subject: [PATCH %d/%d] %s\n" % (num, total, commit.message))
|
|
|
+ f.write("\n")
|
|
|
+ f.write("---\n")
|
|
|
+ f.write("TODO: Print diffstat\n")
|
|
|
+ f.write("\n")
|
|
|
+ f.write("-- \n")
|
|
|
+ if version is None:
|
|
|
+ from dulwich import __version__ as dulwich_version
|
|
|
+ f.write("Dulwich %d.%d.%d\n" % dulwich_version)
|
|
|
+ else:
|
|
|
+ f.write("%s\n" % version)
|
|
|
+
|
|
|
+
|
|
|
+def get_summary(commit):
|
|
|
+ """Determine the summary line for use in a filename.
|
|
|
+
|
|
|
+ :param commit: Commit
|
|
|
+ :return: Summary string
|
|
|
+ """
|
|
|
+ return commit.message.splitlines()[0].replace(" ", "-")
|