def __handleOtherLines(self): out = "" line = self.__diff.getCurrentLine() m1 = re.match(r"^Property changes on: (.*)", line) if m1 and (not m1.group(1) in self.__seen or self.__seen[m1.group(1)] <= 0): out += self.__handlePropertyChange(m1) elif re.match(r"^\@\@", line): if self.__inSpan: out += self.__inSpan.getCloseTag() spanTag = HtmlTag("span") spanTag.addClass("lines") spanTag.setText(self.html_escape(line) + "\n") out += spanTag.toHtml(TagMode.CLOSED) self.__inSpan = None else: m2 = re.match(r"^([-+])", line) if m2: out += self.__handleDiff(m2) else: if self.__inSpan == "cx": out += self.html_escape(line) + "\n" else: if self.__inSpan: out += self.__inSpan.getCloseTag() spanTag = HtmlTag("span") spanTag.addClass("cx") spanTag.setText(self.html_escape(line) + "\n") out += spanTag.toHtml() self.__inSpan = HtmlTag("span") return out
def __closeAfterMaxLength(self): out = "" if self.__inSpan: out += self.__inSpan.getCloseTag() tag = HtmlTag("span") tag.addClass("lines") tag.setText("@@ Diff output truncated at " + str(self.max_length) + " characters. @@\n") out += tag.toHtml(TagMode.CLOSED) self.__inSpan = None 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 __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 __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