def __handleBinaryDiff(self, line, html_id, action, filename): out = "" tag = HtmlTag("a", html_id) out += tag.toHtml(TagMode.CLOSED) + "\n" tag = HtmlTag("div") tag.addClass("binary") out += tag.toHtml() tag = HtmlTag("h4") tag.setText(action + ": " + filename) out += tag.toHtml(TagMode.CLOSED) + "\n" tag = HtmlTag("pre") tag.addClass("diff") out += tag.toHtml() + HtmlTag("span").toHtml() + "\n" tag = HtmlTag("span") tag.addClass("cx") tag.setText(line + "\n") out += tag.toHtml(TagMode.CLOSED) out += HtmlTag.printCloseTag("span") + HtmlTag.printCloseTag("span") out += HtmlTag.printCloseTag("pre") + HtmlTag.printCloseTag("div") + "\n" self.__inSpan = None self.__inDiv = False self.__diff.goToNextLine() return out
def __handlePropertyChange(self, m): out = "" # It's just property changes. filename = self.html_escape(m.group(1)) html_id = re.sub(r"[^\w_]", r"", filename) # Dump line. self.__diff.goToNextLine() # Output the headers. if self.__inSpan: out += self.__inSpan.getCloseTag() if self.__inDiv: out += HtmlTag.printCloseTag("span") + HtmlTag.printCloseTag("pre") + HtmlTag.printCloseTag("div") + "\n" out += HtmlTag("a").setText(html_id).toHtml(TagMode.CLOSED) + "\n" + HtmlTag("div").addClass("propset").toHtml() out += HtmlTag("h4").setText("Property changes: " + filename).toHtml(TagMode.CLOSED) + "\n" out += HtmlTag("pre").addClass("diff").toHtml() + HtmlTag("span").toHtml() + "\n" self.__inDiv = True self.__inSpan = None return out
def output_formatted_diff(self): length = 0 tag = HtmlTag("h3") tag.setText("Diff") divTag = HtmlTag("div", "patch") divTag.setInnerHtml("\n" + tag.toHtml(TagMode.CLOSED)) out = divTag.toHtml() + "\n" self.__diff.resetCurrentLine() while not self.__diff.isEndReached(): line = self.__diff.cleanCurrentLine() if not line: self.__diff.goToNextLine() continue length += len(line) if self.__isMaxLengthReached(length): out += self.__closeAfterMaxLength() break if self.__diff.isFileChangeLine(): out += self.__handleFileChange() else: out += self.__handleOtherLines() self.__diff.goToNextLine() if self.__inSpan: out += self.__inSpan.getCloseTag() if self.__inDiv: out += HtmlTag.printCloseTag("span") out += HtmlTag.printCloseTag("pre") + "\n" out += HtmlTag.printCloseTag("div") + "\n" out += HtmlTag.printCloseTag("div") + "\n" return out
def __handleNoDiffAttached(self, html_id, theClass, action, filename): out = "" self.__inSpan = None self.__inDiv = False tag = HtmlTag("a", html_id) out += tag.toHtml(TagMode.CLOSED) + "\n" tag = HtmlTag("div") tag.addClass(theClass) out += tag.toHtml() tag = HtmlTag("h4") tag.setText(action + ": " + filename) out += tag.toHtml(TagMode.CLOSED) out += HtmlTag.printCloseTag("div") + "\n" self.__diff.goToNextLine() return out
def __handleFileChange(self): out = "" m = self.__diff.isFileChangeLine() action = m.group(1) theClass = self.__types[action] if m.group(2) in self.__seen: self.__seen[m.group(2)] += 1 else: self.__seen[m.group(2)] = 1 filename = self.html_escape(m.group(2)) html_id = re.sub(r"[^\w_]", r"", filename) if self.__inSpan: out += self.__inSpan.getCloseTag() if self.__inDiv: out += HtmlTag.printCloseTag("span") out += HtmlTag.printCloseTag("pre") out += HtmlTag.printCloseTag("div") + "\n" # Dump line, but check it's content. self.__diff.goToNextLine() line = self.__diff.getCurrentLine() if not self.__diff.hasDiffAttached(line): # Looks like they used --no-diff-added or --no-diff-deleted. out += self.__handleNoDiffAttached(html_id, theClass, action, filename) return out self.__diff.goToNextLine() before = self.__diff.cleanCurrentLine() if self.__diff.isBinaryDiffLine(before): # Just output the whole filename div. out += self.__handleBinaryDiff(before, html_id, action, filename) return out rev1 = self.__getRevision(before) self.__diff.goToNextLine() after = self.__diff.cleanCurrentLine() rev2 = self.__getRevision(after) # Output the headers. tag = HtmlTag("a", html_id) out += tag.toHtml(TagMode.CLOSED) + "\n" tag = HtmlTag("div") tag.addClass(theClass) out += tag.toHtml() tag = HtmlTag("h4") tag.setText(action + ": " + filename + " (" + rev1 + " => " + rev2 + ")") out += tag.toHtml(TagMode.CLOSED) + "\n" tag = HtmlTag("pre") tag.addClass("diff") out += tag.toHtml() + HtmlTag("span").toHtml() + "\n" tag = HtmlTag("span") tag.addClass("info") out += tag.toHtml() self.__inDiv = True out += self.html_escape(before) + "\n" out += self.html_escape(after) + "\n" out += HtmlTag.printCloseTag("span") self.__inSpan = None return out