You are here: Home > Latest news from Darcs > Changes parameters of Revision#diff

Revision 20080402024634-49d33-cb154e...

Changes parameters of Revision#diff

With this refactoring revisions no longer receive the revision number they have to diff against, just the revision itself.

app/models/revision.rb
app/views/wiki/sourcediff.rhtml
test/unit/revision_test.rb

Changes to revision.rb

24
    define_method(method) { page.send(method) }
    define_method(method) { page.send(method) }
24
25
  end
  end
25
26
  
  
26
27
  def diff(rev_num)
  def diff(other)
27
28
    ChunkDiffer.new.diff(text.split($/),
    ChunkDiffer.new.diff(text.split($/),
28
29
      #position numbers are 1-based, but we want 0-based when indexing revisions
                         other.text.split($/))
29
30
                         page.revisions[rev_num - 1].text.split($/))
 
31
  end
  end
30
32
31
33
end
end
32

Changes to sourcediff.rhtml

1
<% pagetext(@page.title, '(Comparing revisions %s and %s)' / @old_revision_num / @new_revision_num) do %>
<% pagetext(@page.title, '(Comparing revisions %s and %s)' / @old_revision_num / @new_revision_num) do %>
1
2
  <%= render_diff_table(@old_revision.diff(@new_revision_num.to_i))%>
  <%= render_diff_table(@old_revision.diff(@new_revision))%>
2
3
  <%= render :partial => 'diffbar' %>
  <%= render :partial => 'diffbar' %>
3
4
<% end %>
<% end %>
4

Changes to revision_test.rb

39
    fst_rev = pages('changed_page').revisions[0]
    fst_rev = pages('changed_page').revisions[0]
39
40
    snd_rev = pages('changed_page').revisions[1]
    snd_rev = pages('changed_page').revisions[1]
40
41
    
    
41
42
    change_chunks = fst_rev.diff(2)
    change_chunks = fst_rev.diff(snd_rev)
42
43
    assert_equal 1, change_chunks.size
    assert_equal 1, change_chunks.size
43
44
    chunk = change_chunks.first
    chunk = change_chunks.first
44
45
    assert !chunk.unchanged?
    assert !chunk.unchanged?
45
14 more lines
60
                          :text => "This is the modified first line\n" +
                          :text => "This is the modified first line\n" +
60
61
                                   "And this is the modified second line")
                                   "And this is the modified second line")
61
62
                                   
                                   
62
63
    chunks = page.revisions[0].diff(2)
    chunks = page.revisions[0].diff(page.revisions[1])
63
64
    assert_equal 1, chunks.size
    assert_equal 1, chunks.size
64
65
    chunk = chunks.first
    chunk = chunks.first
65
66
    assert_equal :modification, chunk.action
    assert_equal :modification, chunk.action
66
16 more lines
83
                                   "This line will not be changed\n" +
                                   "This line will not be changed\n" +
83
84
                                   "And this is another modification")
                                   "And this is another modification")
84
85
                                   
                                   
85
86
    chunks = page.revisions[0].diff(2)
    chunks = page.revisions[0].diff(page.revisions[1])
86
87
    assert_equal 3, chunks.size
    assert_equal 3, chunks.size
87
88
    assert !chunks[0].unchanged?
    assert !chunks[0].unchanged?
88
89
    assert_equal :modification, chunks[0].action
    assert_equal :modification, chunks[0].action
89
21 more lines
111
                                   "But I also inserted a new one\n" +
                                   "But I also inserted a new one\n" +
111
112
                                   "This line will not be changed\n" +
                                   "This line will not be changed\n" +
112
113
                                   "And this is the last one")
                                   "And this is the last one")
113
114
    chunks = page.revisions[0].diff(2)
    chunks = page.revisions[0].diff(page.revisions[1])
114
115
    assert_equal 2, chunks.size
    assert_equal 2, chunks.size
115
116
    assert !chunks.first.unchanged?
    assert !chunks.first.unchanged?
116
117
    assert  chunks.last.unchanged?
    assert  chunks.last.unchanged?
117
17 more lines
135
    page.revise(bob, now, :title => 'A good page',
    page.revise(bob, now, :title => 'A good page',
135
136
                          :text => "This is the modified first line\n" +
                          :text => "This is the modified first line\n" +
136
137
                                   "And this one won't be changed")
                                   "And this one won't be changed")
137
138
    chunks = page.revisions[0].diff(2)
    chunks = page.revisions[0].diff(page.revisions[1])
138
139
    assert_equal 2, chunks.size
    assert_equal 2, chunks.size
139
140
    assert_equal 2, chunks.first.lines.size
    assert_equal 2, chunks.first.lines.size
140
141
    assert_equal 'This is the first line', chunks.first.lines.first.original_text
    assert_equal 'This is the first line', chunks.first.lines.first.original_text
141
13 more lines
155
                                   "But it is not the last\n" +
                                   "But it is not the last\n" +
155
156
                                   "Because someone added other two")
                                   "Because someone added other two")
156
157
157
158
    chunks = page.revisions[0].diff(2)
    chunks = page.revisions[0].diff(page.revisions[1])
158
159
    assert_equal 2, chunks.size
    assert_equal 2, chunks.size
159
160
    assert  chunks.first.unchanged?
    assert  chunks.first.unchanged?
160
161
    assert !chunks.last.unchanged?
    assert !chunks.last.unchanged?
161
17 more lines
179
                          :text => "This is the first line\n" +
                          :text => "This is the first line\n" +
179
180
                                   "And this is the last one")
                                   "And this is the last one")
180
181
181
182
    chunks = page.revisions[0].diff(2)
    chunks = page.revisions[0].diff(page.revisions[1])
182
183
    assert_equal 3, chunks.size
    assert_equal 3, chunks.size
183
184
    assert  chunks[0].unchanged?
    assert  chunks[0].unchanged?
184
185
    assert !chunks[1].unchanged?
    assert !chunks[1].unchanged?
185