mozreview: HOTFIX allow to modify the DiffSet's files list for diff download. (bug 1346321) r=glob
authorPiotr Zalewa <pzalewa@mozilla.com>
Wed, 15 Mar 2017 13:25:49 +0100
changeset 72 12009690bcc28bf1012ce3ca26362d086deafe59
parent 71 bc491b5efdb738ca352ae0e15cd012492568621b
child 73 86cbd77aa85b6ecbdd9316fe4b3b898aa195b8b0
push id40
push userbjones@mozilla.com
push dateThu, 16 Mar 2017 06:01:07 +0000
reviewersglob
bugs1346321
mozreview: HOTFIX allow to modify the DiffSet's files list for diff download. (bug 1346321) r=glob commit-message FileDiff appears in [Download Diff] as a normal file. External tools are using this diff and it might be pushed to the project. Due to recursive import issue (parser is loaded from MozReview extension) I've defined the DownloadRawHook in separate file - outside of hooks.py MozReview-Commit-ID: LFH104ewzRA
reviewboard/reviewboard/diffviewer/parser.py
reviewboard/reviewboard/extensions/fixuphook.py
--- a/reviewboard/reviewboard/diffviewer/parser.py
+++ b/reviewboard/reviewboard/diffviewer/parser.py
@@ -2,16 +2,17 @@ from __future__ import unicode_literals
 
 import logging
 import re
 
 from django.utils import six
 from django.utils.six.moves import range
 
 from reviewboard.diffviewer.errors import DiffParserError
+from reviewboard.extensions.fixuphook import DownloadRawHook
 
 
 class File(object):
     def __init__(self):
         self.origFile = None
         self.newFile = None
         self.origInfo = None
         self.newInfo = None
@@ -224,17 +225,20 @@ class DiffParser(object):
                               "found in the diff header",
                               linenum)
 
     def raw_diff(self, diffset):
         """Returns a raw diff as a string.
 
         The returned diff as composed of all FileDiffs in the provided diffset.
         """
-        return b''.join([filediff.diff for filediff in diffset.files.all()])
+        files = diffset.files.all()
+        for hook in DownloadRawHook.hooks:
+            files = hook.filter(files)
+        return b''.join([filediff.diff for filediff in files])
 
     def get_orig_commit_id(self):
         """Returns the commit ID of the original revision for the diff.
 
         This is overridden by tools that only use commit IDs, not file
         revision IDs.
         """
         return None
new file mode 100644
--- /dev/null
+++ b/reviewboard/reviewboard/extensions/fixuphook.py
@@ -0,0 +1,11 @@
+from django.utils import six
+
+from djblets.extensions.hooks import (ExtensionHook, ExtensionHookPoint)
+
+
+@six.add_metaclass(ExtensionHookPoint)
+class DownloadRawHook(ExtensionHook):
+    """A hook to modify the download raw content."""
+    def filter(self, files):
+        """Returns a diffset ready to display."""
+        raise NotImplementedError