diff --git a/lib/git_diff_utils.rb b/lib/git_diff_utils.rb index 56d79a7f..19416430 100644 --- a/lib/git_diff_utils.rb +++ b/lib/git_diff_utils.rb @@ -33,7 +33,9 @@ def self.get_tagged_commit_diffs(repo_name, commit, options = {}) if GitHelper.blob_binary?(diff.a_blob) || GitHelper.blob_binary?(diff.b_blob) data.binary = true data.special_case = "This is a binary file." - elsif data.submodule? + elsif !(a_path =~ /\.(gen|properties|relations|functions)\.cs/).nil? || !(a_path =~ /PI_/).nil? || !(a_path =~ /DBSchema.xml$/).nil? + data.special_case = "Generated File - not showing diff." + elsif data.submodule? data.special_case = data.submodule_special_case_message elsif diff.diff.nil? && (data.file_mode_before != data.file_mode_after) data.special_case = "File mode changed: #{data.file_mode_before} → #{data.file_mode_after}" @@ -57,7 +59,10 @@ def self.get_tagged_commit_diffs(repo_name, commit, options = {}) # Diffs can be missing a_blob or b_blob if the change is an added or removed file. before, after = [diff.a_blob, diff.b_blob].map { |blob| blob ? blob.data : "" } end - raw_diff = GitDiffUtils.diff(diff.a_blob, diff.b_blob) + + raw_diff = diff.diff + raw_diff.gsub! "\r", "" + raw_diff.sub %r{[^@]*}, "" unless options[:warm_the_cache] new_data = GitDiffUtils.tag_file(before, after, diff, raw_diff) @@ -87,27 +92,10 @@ def self.tag_file(file_before, file_after, diff, raw_diff) chunks = tag_diff(diff, raw_diff, before_lines, after_lines) chunks.each_with_index do |chunk, i| - if chunk.original_line_start && chunk.original_line_start > orig_line - tagged_lines += before_lines[orig_line...chunk.original_line_start].map do |data| - diff_line += 1 - orig_line += 1 - LineDiff.new(:same, before_lines[orig_line - 1], orig_line, diff_line) - end - chunk_breaks << tagged_lines.size - end tagged_lines += chunk.tagged_lines orig_line += chunk.original_lines_changed diff_line += chunk.new_lines_changed end - - if !before_lines.empty? && orig_line <= before_lines.count - chunk_breaks << tagged_lines.size - tagged_lines += before_lines[orig_line..before_lines.count].map do |data| - diff_line += 1 - orig_line += 1 - LineDiff.new(:same, before_lines[orig_line - 1], orig_line, diff_line ) - end - end lines_added = tagged_lines.select { |line| line.tag == :added }.count lines_removed = tagged_lines.select { |line| line.tag == :removed }.count { :lines => tagged_lines, :breaks => chunk_breaks, @@ -189,10 +177,10 @@ def self.tag_diff(diff, raw_diff, before_highlighted, after_highlighted) def self.show(repo, commit) if commit.parents.size > 0 - diff = repo.git.native(:diff, { :full_index => true, :find_renames => true }, commit.parents[0].id, + diff = repo.git.native(:diff, { :inter_hunk_context => 33, :unified => 9, :ignore_all_space => true, :full_index => true, :find_renames => true }, commit.parents[0].id, commit.id) else - raw_diff = repo.git.native(:show, { :full_index => true, :pretty => "raw" }, commit.id) + raw_diff = repo.git.native(:show, { :inter_hunk_context => 33, :unified => 9, :ignore_all_space => true, :full_index => true, :pretty => "raw" }, commit.id) # git show has a lot of headers in the diff, we try to strip it out here cutpoint = raw_diff.index("diff --git a") diff = cutpoint ? raw_diff[cutpoint, raw_diff.length] : "" diff --git a/lib/git_helper.rb b/lib/git_helper.rb index 328cf320..5a220584 100644 --- a/lib/git_helper.rb +++ b/lib/git_helper.rb @@ -58,4 +58,4 @@ def self.rev_list(repo, command_options, mode = :commits) def self.blob_binary?(blob) blob && !blob.data.empty? && blob.data.index("\0") end -end \ No newline at end of file +end diff --git a/public/coffee/commit.coffee b/public/coffee/commit.coffee index 60ecaa17..d622f3e2 100644 --- a/public/coffee/commit.coffee +++ b/public/coffee/commit.coffee @@ -11,28 +11,29 @@ window.Commit = SIDE_BY_SIDE_CODE_WIDTH: 830 init: -> - $(".addCommentButton").click (e) => @onAddCommentMouseAction e + $(document).on("click", ".addCommentButton", (e) => @onAddCommentMouseAction e) $("a.tipsyCommentCount").tipsy(gravity: "w") - $(".diffLine").dblclick (e) => @onAddCommentMouseAction e - $(".reply").live "click", (e) => @onAddCommentMouseAction e - $(".diffLine").hover(((e) => @selectLine(e)), ((e) => @clearSelectedLine())) - $(".commentForm").live "submit", (e) => @onCommentSubmit e - $(".commentPreview").click (e) => @onCommentPreview e - $(".commentEditForm").live "submit", (e) => @onCommentEditSubmit e - $("#approveButton").live "click", (e) => @onApproveClicked e - $("#disapproveButton").live "click", (e) => @onDisapproveClicked e - $(".delete").live "click", (e) => @onCommentDelete e - $(".edit").live "click", (e) => @onCommentEdit e - $("#sideBySideButton").live "click", => @toggleSideBySide true - $("#requestReviewButton").click (e) => @toggleReviewRequest() - $("#hideCommentButton").live "click", (e) => @toggleComments() - $(".diffCommentCount > a").live "click", (e) => @toggleSingleComment(e) - $("#requestInput button").click (e) => @submitReviewRequest() - $(".expandLink.all").click (e) => @expandContextAll(e) - $(".expandLink.below").click (e) => @expandContext(e, 10, "below") - $(".expandLink.above").click (e) => @expandContext(e, 10, "above") - $("#commit .file").on("mouseenter", ".contextExpander", @expandContextHoverIn) - $("#commit .file").on("mouseleave", ".contextExpander", @expandContextHoverOut) + $(document).on("dblclick", ".diffLine", (e) => @onAddCommentMouseAction e) + $(document).on("click", ".reply", (e) => @onAddCommentMouseAction e) + $(document).on("mouseenter", ".diffLine", (e) => @selectLine(e)) + $(document).on("mouseleave", ".diffLine", (e) => @clearSelectedLine()) + $(document).on("submit", ".commentForm", (e) => @onCommentSubmit e) + $(document).on("click", ".commentPreview", (e) => @onCommentPreview e) + $(document).on("submit", ".commentEditForm", (e) => @onCommentEditSubmit e) + $(document).on("click", "#approveButton", (e) => @onApproveClicked e) + $(document).on("click", "#disapproveButton", (e) => @onDisapproveClicked e) + $(document).on("click", ".delete", (e) => @onCommentDelete e) + $(document).on("click", ".edit", (e) => @onCommentEdit e) + $(document).on("click", "#sideBySideButton", => @toggleSideBySide true) + $(document).on("click", "#requestReviewButton", (e) => @toggleReviewRequest()) + $(document).on("click", "#hideCommentButton", (e) => @toggleComments()) + $(document).on("click", ".diffCommentCount > a", (e) => @toggleSingleComment(e)) + $(document).on("click", "#requestInput button", (e) => @submitReviewRequest()) + $(document).on("click", ".expandLink.all", (e) => @expandContextAll(e)) + $(document).on("click", ".expandLink.below", (e) => @expandContext(e, 10, "below")) + $(document).on("click", ".expandLink.above", (e) => @expandContext(e, 10, "above")) + $(document).on("mouseenter", "#commit .file .contextExpander", @expandContextHoverIn) + $(document).on("mouseleave", "#commit .file .contextExpander", @expandContextHoverOut) @currentlyScrollingTimer = null @@ -315,9 +316,9 @@ window.Commit = createContextExpander: (codeLines, attachDirection, top, bottom, incremental, refreshLine) -> renderedExpander = Snippets.contextExpander(top, bottom, codeLines.attr("diff-line-number"), incremental) contextExpander = $(renderedExpander) - contextExpander.find(".expandLink.all").click (e) => @expandContextAll(e) - contextExpander.find(".expandLink.above").click (e) => @expandContext(e, 10, "above") - contextExpander.find(".expandLink.below").click (e) => @expandContext(e, 10, "below") + contextExpander.on("click", ".expandLink.all", (e) => @expandContextAll(e)) + contextExpander.on("click", ".expandLink.above", (e) => @expandContext(e, 10, "above")) + contextExpander.on("click", ".expandLink.below", (e) => @expandContext(e, 10, "below")) codeLines.before(contextExpander) if attachDirection == "above" codeLines.after(contextExpander) if attachDirection == "below" expander = if attachDirection == "above" then codeLines.prev() else codeLines.next()