Add Comment.safe_in_reply_to to improve comment xml output.
authorW. Trevor King <wking@drexel.edu>
Fri, 22 Jan 2010 01:54:00 +0000 (20:54 -0500)
committerW. Trevor King <wking@drexel.edu>
Fri, 22 Jan 2010 01:54:00 +0000 (20:54 -0500)
Now
  be show --xml ID | be-xml-to-mbox | catmutt
shows appropriate linking regardless of missing references or
references to alt-ids in the original comments.  On the other hand,
  be show --xml ID | be import-xml
could alter alt-ids.  If that's a problem we could turn off
save_in_reply_to usage via an option to the xml methods in the future.

libbe/comment.py

index b80188be9f7cf812dee84b15ece62a1fd1dafd68..f0cc45c2cc2626ed3bc27b6ce47f8849b4bb45cd 100644 (file)
@@ -253,6 +253,23 @@ class Comment(Tree, settings_object.SavedSettingsObject):
             return str(value)
         return value
 
+    def safe_in_reply_to(self):
+        """
+        Return self.in_reply_to, except...
+          * if no comment matches that id, in which case return None.
+          * if that id matches another comments .alt_id, in which case
+            return the matching comments .uuid.
+        """
+        if self.in_reply_to == None:
+            return None
+        else:
+            try:
+                irt_comment = self.bug.comment_from_uuid(
+                    self.in_reply_to, match_alt_id=True)
+                return irt_comment.uuid
+            except KeyError:
+                return None
+
     def xml(self, indent=0):
         """
         >>> comm = Comment(bug=None, body="Some\\ninsightful\\nremarks\\n")
@@ -281,7 +298,7 @@ class Comment(Tree, settings_object.SavedSettingsObject):
         info = [('uuid', self.uuid),
                 ('alt-id', self.alt_id),
                 ('short-name', self.id.user()),
-                ('in-reply-to', self.in_reply_to),
+                ('in-reply-to', self.safe_in_reply_to()),
                 ('author', self._setting_attr_string('author')),
                 ('date', self.date),
                 ('content-type', self.content_type),