Skip to content
This repository was archived by the owner on Apr 19, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions lib/grit/git-ruby/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,28 @@ def diff(commit1, commit2, options = {})
'' # one of the trees was bad or lcs isn't there - no diff
end

def quick_what_changed(t1, t2, path, type)
changed = []

t1[type].each do |file, hsh|
t2_file = t2[type][file] rescue nil
full = File.join(path, file)
if !t2_file
changed << [full, 'added', hsh[:sha], nil] # not in parent
elsif (hsh[:sha] != t2_file[:sha])
changed << [full, 'modified', hsh[:sha], t2_file[:sha]] # file changed
end
end if t1

t2[type].each do |file, hsh|
if !t1 || !t1[type][file]
changed << [File.join(path, file), 'removed', nil, hsh[:sha]]
end
end if t2

changed
end

# takes 2 tree shas and recursively walks them to find out what
# files or directories have been modified in them and returns an
# array of changes
Expand All @@ -476,27 +498,14 @@ def diff(commit1, commit2, options = {})
# ]
def quick_diff(tree1, tree2, path = '.', recurse = true)
# handle empty trees
changed = []
return changed if tree1 == tree2

t1 = list_tree(tree1) if tree1
t2 = list_tree(tree2) if tree2

# finding files that are different
t1['blob'].each do |file, hsh|
t2_file = t2['blob'][file] rescue nil
full = File.join(path, file)
if !t2_file
changed << [full, 'added', hsh[:sha], nil] # not in parent
elsif (hsh[:sha] != t2_file[:sha])
changed << [full, 'modified', hsh[:sha], t2_file[:sha]] # file changed
end
end if t1
t2['blob'].each do |file, hsh|
if !t1 || !t1['blob'][file]
changed << [File.join(path, file), 'removed', nil, hsh[:sha]]
end
end if t2
changed = quick_what_changed(t1, t2, path, 'blob') +
quick_what_changed(t1, t2, path, 'link')

t1['tree'].each do |dir, hsh|
t2_tree = t2['tree'][dir] rescue nil
Expand Down
2 changes: 2 additions & 0 deletions test/dot_git/logs/refs/heads/test/kouno
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0000000000000000000000000000000000000000 2d3acf90f35989df8f262dc50beadc4ee3ae1560 Vincent Bonmalais <vb.kouno@gmail.com> 1349255070 +1000 push
2d3acf90f35989df8f262dc50beadc4ee3ae1560 2e0f114810c4974a6cb12eeb04026de7b3f599b3 Vincent Bonmalais <vb.kouno@gmail.com> 1349255247 +1000 push
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x���J�0@]�+f/�<k.�~��ifr�IJ�
����8��z�e��4vx1ll&�"�-!3FAm]�^���ר6ڥ]";Juv#r��ΖSЋ'/�HL���s|�>KK�Go�V*ܾ��������:�^_�8�6k"<�����9���� �O]K{@�f���;l��C&� �'Tr
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions test/dot_git/refs/heads/test/kouno
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2e0f114810c4974a6cb12eeb04026de7b3f599b3
8 changes: 4 additions & 4 deletions test/test_head.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def setup
# inspect

def test_inspect
head = @r.heads[1]
head = @r.heads[2]
assert_equal %Q{#<Grit::Head "test/master">}, head.inspect
end

Expand All @@ -31,7 +31,7 @@ def test_submaster
# heads with slashes

def test_heads_with_slashes
head = @r.heads[3]
head = @r.heads[4]
assert_equal %Q{#<Grit::Head "test/chacon">}, head.inspect
end

Expand All @@ -42,8 +42,8 @@ def test_is_head
end

def test_head_count
assert_equal 5, @r.heads.size
assert_equal 5, @r.head_count
assert_equal 6, @r.heads.size
assert_equal 6, @r.head_count
end


Expand Down
2 changes: 1 addition & 1 deletion test/test_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_heads_should_return_array_of_head_objects

def test_heads_should_populate_head_data
@r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
head = @r.heads[1]
head = @r.heads[2]

assert_equal 'test/master', head.name
assert_equal '2d3acf90f35989df8f262dc50beadc4ee3ae1560', head.commit.id
Expand Down
8 changes: 8 additions & 0 deletions test/test_rubygit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def test_diff_remove
assert_match 'index 0000000..2e3b0cb', out
end

def test_diff_symlink
commit1 = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
commit2 = '2e0f114810c4974a6cb12eeb04026de7b3f599b3'
out = @git.diff({}, commit1, commit2)
assert_match "--- /dev/null\n+++ b/test/fixtures/symlink", out
assert_match "diff --git a/test/fixtures/symlink b/test/fixtures/symlink", out
assert_match "index 0000000..7b45d97", out
end

def test_cat_file_contents_commit
out = @git.cat_file({:p => true}, @commit_sha)
Expand Down