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
--- 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