Skip to content

Commit

Permalink
Don't break when the inspected location doesn't exist in the revision.
Browse files Browse the repository at this point in the history
- Start at revision 1.
- Catch exceptions and return blank result for unknown locations.
  • Loading branch information
Manfred committed Feb 12, 2010
1 parent 1ddcf71 commit 26ea4be
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
6 changes: 3 additions & 3 deletions bin/locke
Expand Up @@ -15,8 +15,8 @@ end

repository_path = ARGV[0] || Dir.pwd
repository = Locke::Subversion::Repository.new(repository_path)
repository.changes.each_with_index do |changes, index|
message = ["Revision #{index+1}:"]
message << pluralize(changes[:added] + changes[:removed], 'change', 'changes')
repository.each_change do |changes|
message = ["Revision #{changes[:revision]}:"]
message << pluralize(changes[:added].to_i + changes[:removed].to_i, 'change', 'changes')
puts message.join(' ')
end
23 changes: 17 additions & 6 deletions lib/locke/subversion.rb
Expand Up @@ -10,16 +10,26 @@ def initialize(path)
@path = path
end

def changes
if last_revision > 1
(2..last_revision).map do |revision|
self.class.count_changes(svn("diff -x -b --change #{revision} #{@path}"))
def each_change
if last_revision > 0
(1..last_revision).each do |revision|
begin
changes = self.class.count_changes(svn("diff -x -b --change #{revision} #{@path}"))
rescue Executioner::ProcessError
changes = {}
end
changes[:revision] = revision
yield changes
end
else
[]
end
end

def changes
changes = []
each_change { |change| changes << change }
changes
end

def last_revision
attributes['Revision'].to_i
end
Expand All @@ -37,6 +47,7 @@ def self.parse_attributes(input)
end

def self.count_changes(input)
return {} if input.nil?
input.split("\n").inject({:added => 0, :removed => 0}) do |changes, line|
if %w(--- +++).include?(line[0,3])
changes
Expand Down
18 changes: 14 additions & 4 deletions test/subversion_test.rb
Expand Up @@ -19,10 +19,20 @@

it "should return a list changes to the repository" do
@repository.changes.should == [
{:added=>1, :removed=>0},
{:added=>1, :removed=>1},
{:added=>5, :removed=>1},
{:added=>1, :removed=>3}
{:revision => 1, :added=>0, :removed=>0},
{:revision => 2, :added=>1, :removed=>0},
{:revision => 3, :added=>1, :removed=>1},
{:revision => 4, :added=>5, :removed=>1},
{:revision => 5, :added=>1, :removed=>3}
]
end

it "should accept blocks to iterate through changes" do
count = 0
@repository.each_change do |change|
count += 1
change.should.be.kind_of(Hash)
end
count.should == @repository.last_revision
end
end

0 comments on commit 26ea4be

Please sign in to comment.