[PATCH 1/5] Add log_msg field
Nate Case
ncase at xes-inc.com
Fri Mar 20 05:59:52 EST 2009
Create a new patch field named 'log_msg' which contains the patch
commit log message. Previously this was stored as the first comment
of the patch. Storing it explicitly gets rid of the special case
handling for comment 0 and eliminates the redundant metadata between
comment 0 and the patch object. It also has the nice side effect of
making the number of comments accurately reflect how many replies were
made to the patch.
SQL/python migration scripts are also included to move the first
comment (the patch log message) to the newly created log_msg field.
Signed-off-by: Nate Case <ncase at xes-inc.com>
Signed-off-by: Peter Tyser <ptyser at xes-inc.com>
---
This was submitted before in a different form. This commit
contains only the log_msg addition and not the CSS/layout
stuff in the previous patches. Also rebased against latest HEAD.
apps/patchwork/bin/log_msg.py | 39 +++++++++++++++++++++++++++++++++
apps/patchwork/bin/parsemail.py | 8 +++---
apps/patchwork/models.py | 11 +-------
apps/patchwork/templatetags/syntax.py | 8 +++++-
lib/sql/migration/003-add-log_msg.sql | 3 ++
templates/patchwork/patch.html | 10 ++++++-
6 files changed, 62 insertions(+), 17 deletions(-)
create mode 100644 apps/patchwork/bin/log_msg.py
create mode 100644 lib/sql/migration/003-add-log_msg.sql
diff --git a/apps/patchwork/bin/log_msg.py b/apps/patchwork/bin/log_msg.py
new file mode 100644
index 0000000..8a2d6e4
--- /dev/null
+++ b/apps/patchwork/bin/log_msg.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python
+#
+# Patchwork - automated patch tracking system
+# Copyright (C) 2008 Jeremy Kerr <jk at ozlabs.org>
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork 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; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork 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 Patchwork; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+from patchwork.models import Patch, Comment
+import sys
+
+if __name__ == '__main__':
+ if len(sys.argv) > 1:
+ patches = Patch.objects.filter(id__in = sys.argv[1:])
+ else:
+ patches = Patch.objects.all()
+
+ for patch in patches:
+ print patch.id, patch.name
+ if not patch.log_msg:
+ # Find first comment matching this patch
+ comment = Comment.objects.filter(patch = patch)[0]
+ patch.log_msg = comment.content
+ patch.save()
+ print "Deleting comment #%d" % comment.id
+ comment.delete()
diff --git a/apps/patchwork/bin/parsemail.py b/apps/patchwork/bin/parsemail.py
index 7f6727f..995b59f 100755
--- a/apps/patchwork/bin/parsemail.py
+++ b/apps/patchwork/bin/parsemail.py
@@ -165,11 +165,11 @@ def find_content(project, mail):
if patchbuf:
mail_headers(mail)
- name = clean_subject(mail.get('Subject'), [project.linkname])
+ name = clean_subject(mail.get('Subject'), [project.linkname])
patch = Patch(name = name, content = patchbuf,
- date = mail_date(mail), headers = mail_headers(mail))
-
- if commentbuf:
+ date = mail_date(mail), headers = mail_headers(mail),
+ log_msg = clean_content(commentbuf))
+ elif commentbuf:
if patch:
cpatch = patch
else:
diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py
index db1774e..503da20 100644
--- a/apps/patchwork/models.py
+++ b/apps/patchwork/models.py
@@ -189,6 +189,7 @@ class Patch(models.Model):
content = models.TextField()
commit_ref = models.CharField(max_length=255, null = True, blank = True)
hash = HashField(null = True, db_index = True)
+ log_msg = models.TextField(blank = True)
def __str__(self):
return self.name
@@ -229,15 +230,7 @@ class Patch(models.Model):
def mbox(self):
postscript_re = re.compile('\n-{2,3} ?\n')
- comment = None
- try:
- comment = Comment.objects.get(patch = self, msgid = self.msgid)
- except Exception:
- pass
-
- body = ''
- if comment:
- body = comment.content.strip() + "\n"
+ body = self.log_msg.strip() + "\n"
parts = postscript_re.split(body, 1)
if len(parts) == 2:
diff --git a/apps/patchwork/templatetags/syntax.py b/apps/patchwork/templatetags/syntax.py
index 7b8c985..b0bc26d 100644
--- a/apps/patchwork/templatetags/syntax.py
+++ b/apps/patchwork/templatetags/syntax.py
@@ -65,10 +65,14 @@ def patchsyntax(patch):
return mark_safe(content)
@register.filter
-def commentsyntax(comment):
- content = escape(comment.content)
+def msgsyntax(content):
+ content = escape(content)
for (r,cls) in _comment_span_res:
content = r.sub(lambda x: _span % (cls, x.group(0)), content)
return mark_safe(content)
+
+ at register.filter
+def commentsyntax(comment):
+ return msgsyntax(comment.content)
diff --git a/lib/sql/migration/003-add-log_msg.sql b/lib/sql/migration/003-add-log_msg.sql
new file mode 100644
index 0000000..a56d9ba
--- /dev/null
+++ b/lib/sql/migration/003-add-log_msg.sql
@@ -0,0 +1,3 @@
+BEGIN;
+ALTER TABLE patchwork_patch ADD COLUMN log_msg text;
+COMMIT;
diff --git a/templates/patchwork/patch.html b/templates/patchwork/patch.html
index 7c249ec..d6e4abf 100644
--- a/templates/patchwork/patch.html
+++ b/templates/patchwork/patch.html
@@ -197,8 +197,14 @@ function toggle_headers(link_id, headers_id)
</div>
</div>
-
-
+<h2>Description</h2>
+{% if patch.log_msg %}
+<div class="comment">
+<pre class="content">
+{{ patch.log_msg|msgsyntax }}
+</pre>
+</div>
+{% endif %}
<h2>Comments</h2>
{% for comment in patch.comments %}
--
1.6.2
More information about the Patchwork
mailing list