Skip to content

Commit

Permalink
fix diff @@ processing bug when single file has multiple differences
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltan committed Nov 3, 2008
1 parent cbd9e5d commit 9860701
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
6 changes: 3 additions & 3 deletions git_commit_notifier/lib/commit_hook.rb
Expand Up @@ -13,12 +13,12 @@ def self.run(rev1, rev2, ref_name, config_file = nil)
config = YAML.load_file(config_file || '/usr/local/share/git_commit_notifier/config/config.yml')
project_path = Dir.getwd

project_config = config['projects'] ? config['projects'][project_path] : {}
project_config = config['projects'] && config['projects'][project_path] ? config['projects'][project_path] : nil

recipient = project_config['recipient_address'].to_s
recipient = project_config ? project_config['recipient_address'] : ''
recipient = Git.mailing_list_address if recipient.empty?

repo = project_config['application_name'].to_s
repo = project_config ? project_config['application_name'] : ''
repo = Git.prefix if repo.empty?
repo = 'scm' if repo.empty?
prefix = "[#{repo}][#{short_ref_name(ref_name)}]"
Expand Down
9 changes: 4 additions & 5 deletions git_commit_notifier/lib/diff_to_html.rb
Expand Up @@ -157,14 +157,14 @@ def diff_for_revision(content)
@current_file_name = file_name
end

@left_ln.nil? ? process_info_line(line) : process_code_line(line)
op = line[0,1]
@left_ln.nil? || op == '@' ? process_info_line(line, op) : process_code_line(line, op)
end
add_changes_to_result
@diff_result
end

def process_code_line(line)
op = line[0,1]
def process_code_line(line, op)
if op == '-'
@diff_lines << { :removed => @left_ln, :added => nil, :op => :removal, :content => line[1..-1] }
@left_ln += 1
Expand All @@ -178,8 +178,7 @@ def process_code_line(line)
end
end

def process_info_line(line)
op = line[0,1]
def process_info_line(line, op)
if line =~/^deleted\sfile\s/
@file_removed = true
elsif line =~ /^\-\-\-\s/ && line =~ /\/dev\/null/
Expand Down
5 changes: 5 additions & 0 deletions git_commit_notifier/test/diff_to_html_test.rb
Expand Up @@ -21,6 +21,10 @@ def test_multiple_commits
diff.diff_between_revisions REVISIONS.first, REVISIONS.last, 'testproject', 'master'
assert_equal 4, diff.result.size # one result for each of the commits

diff.result.each do |html|
assert !html.include?('@@') # diff correctly processed
end

# first commit
hp = Hpricot diff.result.first[:html_content]
assert_equal 2, (hp/"table").size # 8 files updated - one table for each of the files
Expand Down Expand Up @@ -66,6 +70,7 @@ def test_single_commit
assert_equal 1, diff.result.size # single result for a single commit

hp = Hpricot(diff.result.first[:html_content])
assert !diff.result.first[:html_content].include?('@@')
assert_equal 2, (hp/"table").size # 2 files updated
(hp/"table/tr/").each do |td|
if td.inner_html == "require&nbsp;'iconv'"
Expand Down
Expand Up @@ -3,7 +3,7 @@ Author: Tom Stuart <tom@experthuman.com>
Date: Wed Oct 8 09:31:00 2008 +0100

Allow use of :path_prefix and :name_prefix outside of namespaced routes. [#1188 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>

diff --git a/actionpack/lib/action_controller/routing/builder.rb b/actionpack/lib/action_controller/routing/builder.rb
Expand All @@ -16,22 +16,33 @@ index 5704d9d..7b888fa 100644
def divide_route_options(segments, options)
- options = options.dup
+ options = options.except(:path_prefix, :name_prefix)

if options[:namespace]
options[:controller] = "#{options.delete(:namespace).sub(/\/$/, '')}/#{options[:controller]}"
- options.delete(:path_prefix)
- options.delete(:name_prefix)
end

requirements = (options.delete(:requirements) || {}).dup
@@ -68,7 +73,9 @@ class Client < ActiveRecord::Base
end

def removable?
- self.projects.find(:first, :select => 'id').nil? && self.invoices.find(:first, :select => 'id').nil?
+ self.projects.find(:first, :select => 'id').nil? &&
+ self.invoices.find(:first, :select => 'id').nil? &&
+ self.recurring_invoices.find(:first, :select => 'id').nil?
end

# some comment
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 1eb26a7..9699a04 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -924,6 +924,20 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do

end

+ def test_named_route_with_name_prefix
+ rs.add_named_route :page, 'page', :controller => 'content', :action => 'show_page', :name_prefix => 'my_'
+ x = setup_for_named_route
Expand All @@ -52,7 +63,7 @@ index 1eb26a7..9699a04 100644
@@ -2147,6 +2161,13 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do
assert_equal [:x], set.extra_keys(args)
end

+ def test_generate_with_path_prefix
+ set.draw { |map| map.connect ':controller/:action/:id', :path_prefix => 'my' }
+
Expand Down

0 comments on commit 9860701

Please sign in to comment.