From 546b3aa6ef46c3b9f3546e0b17fedea09626d4b6 Mon Sep 17 00:00:00 2001 From: Vincent Bonmalais Date: Wed, 3 Oct 2012 20:11:07 +1000 Subject: [PATCH] Fixes symlinks omission from diff. --- lib/grit/git-ruby/repository.rb | 39 +++++++++++------- test/dot_git/logs/refs/heads/test/kouno | 2 + .../2a/ffb5512da280a18fc8ce7a1b1bb4e728fae7ff | Bin 0 -> 74 bytes .../2e/0f114810c4974a6cb12eeb04026de7b3f599b3 | 2 + .../71/47bcd75e1a18cab3c1dbfb4acbd24bb431c71b | Bin 0 -> 499 bytes .../71/d12fa2dee43b5fd9a98e9023c04e6fb8882409 | Bin 0 -> 242 bytes .../7b/45d974a391bfd6a994f0d59656bab1ce0f4cb5 | Bin 0 -> 26 bytes .../93/eae0e32c467e3aa59632520ded268b9c3562f0 | Bin 0 -> 726 bytes test/dot_git/refs/heads/test/kouno | 1 + test/test_head.rb | 8 ++-- test/test_repo.rb | 2 +- test/test_rubygit.rb | 8 ++++ 12 files changed, 42 insertions(+), 20 deletions(-) create mode 100644 test/dot_git/logs/refs/heads/test/kouno create mode 100644 test/dot_git/objects/2a/ffb5512da280a18fc8ce7a1b1bb4e728fae7ff create mode 100644 test/dot_git/objects/2e/0f114810c4974a6cb12eeb04026de7b3f599b3 create mode 100644 test/dot_git/objects/71/47bcd75e1a18cab3c1dbfb4acbd24bb431c71b create mode 100644 test/dot_git/objects/71/d12fa2dee43b5fd9a98e9023c04e6fb8882409 create mode 100644 test/dot_git/objects/7b/45d974a391bfd6a994f0d59656bab1ce0f4cb5 create mode 100644 test/dot_git/objects/93/eae0e32c467e3aa59632520ded268b9c3562f0 create mode 100644 test/dot_git/refs/heads/test/kouno diff --git a/lib/grit/git-ruby/repository.rb b/lib/grit/git-ruby/repository.rb index 07306a18..46b5bc62 100644 --- a/lib/grit/git-ruby/repository.rb +++ b/lib/grit/git-ruby/repository.rb @@ -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 @@ -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 diff --git a/test/dot_git/logs/refs/heads/test/kouno b/test/dot_git/logs/refs/heads/test/kouno new file mode 100644 index 00000000..bd55cd8c --- /dev/null +++ b/test/dot_git/logs/refs/heads/test/kouno @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 2d3acf90f35989df8f262dc50beadc4ee3ae1560 Vincent Bonmalais 1349255070 +1000 push +2d3acf90f35989df8f262dc50beadc4ee3ae1560 2e0f114810c4974a6cb12eeb04026de7b3f599b3 Vincent Bonmalais 1349255247 +1000 push diff --git a/test/dot_git/objects/2a/ffb5512da280a18fc8ce7a1b1bb4e728fae7ff b/test/dot_git/objects/2a/ffb5512da280a18fc8ce7a1b1bb4e728fae7ff new file mode 100644 index 0000000000000000000000000000000000000000..ed64bf4dcbd3327b553befb96cbfd6972c143adb GIT binary patch literal 74 zcmV-Q0JZ;k0ZYosPf{>5U`ELH%bM1_>n+}uiqw9K4Tg|z%4h2qNGoXoszg_6|b glFYnxJq4G1g}nR{g`(8l{IXO%1uIQ102(?L&WzV3ivR!s literal 0 HcmV?d00001 diff --git a/test/dot_git/objects/2e/0f114810c4974a6cb12eeb04026de7b3f599b3 b/test/dot_git/objects/2e/0f114810c4974a6cb12eeb04026de7b3f599b3 new file mode 100644 index 00000000..12a7568d --- /dev/null +++ b/test/dot_git/objects/2e/0f114810c4974a6cb12eeb04026de7b3f599b3 @@ -0,0 +1,2 @@ +xJ0@]+f/KKGoV*ܾ:^_86k"<9 O]K{@f;lC& 'Tr \ No newline at end of file diff --git a/test/dot_git/objects/71/47bcd75e1a18cab3c1dbfb4acbd24bb431c71b b/test/dot_git/objects/71/47bcd75e1a18cab3c1dbfb4acbd24bb431c71b new file mode 100644 index 0000000000000000000000000000000000000000..c59b4eac8ce07a7ca07af2be4995423541754440 GIT binary patch literal 499 zcmV6HexU_00M=y%!-oIqSRuB$*&$f)^V$|S~|@ri1)2p_Z-ut z4~7N?W+o;I8L2r1sYQB4Net`Q+jh=BWE-VaeSWLIkgC4GoX7K_iVBMI(=u~XL8^`i zRZ4O1eHLzt?`Ks^Zej60jO`>s20Wzu!uJlYRHd+JEQLZMqMwg{mn@ zEiQ>qOfJa>Tlrk$eS^udh50{M+ID249(-H2U-g>1yrH7%(`lC(FU6y)%Pgq`DcvKuZ`(&70TZ!_zU{6-69P90 z@YSFyEyxF{>yWr+{_*l$pSyo~58l`u-t{D7dIhq&l0o5HDWL{FfcPQQP4}zEXhpI%P&f0*tN=C%xaQ$VaANf`Cc20 zZu@bp>w>EC$Sf|&FRIilsVHG^GP+P~kk5FYyE7u?>C*FSYp>^@gDUe)%*#wmEiM78 zQxfeLC>1m*yKHprtDw$LkI!AtBB1JmTpe9}UBRmE2JiN47K(nhbkmutlP~6$Hh5(f z!&D_^r>14*q%!>7w{T8chl9UXYFTZ6$1JY18#YCm7yyAnPG%CrN_!vUb`#aPT~Et5 srkbzKp1G3K93oo+bP7YE`=0A@QWB>&AH4nB>+~h>Er!RX0pM6>Z#5})VE_OC literal 0 HcmV?d00001 diff --git a/test/dot_git/objects/7b/45d974a391bfd6a994f0d59656bab1ce0f4cb5 b/test/dot_git/objects/7b/45d974a391bfd6a994f0d59656bab1ce0f4cb5 new file mode 100644 index 0000000000000000000000000000000000000000..3a111fa39cf6a0ee118a7670715ceebb44e7316d GIT binary patch literal 26 icmbV(Z6dbPHX8((Q>fil)g!-a1BrL1zeqd7=Uz}N$%CP00rF(jC z;_`A{%^fpz9IE+_ZCU_TosyZB7H`BL&&E@5@YhP8g{xGxZaS7pHDCBDi=rZpA;|4) z_NQtUYjp#|&9z zUTS$fNHs(KvMDd0o=#R)?00<}zoc7#nS0F#WQ7F`4;McTP~=>9!~V;!YgUSB1(~K% z4los^xw)0#U}ezyzco;IQNzOi6X&X=rMEoS`1SlhR8?AjQG9A*az=bnY8u0Q>o<>Y zWw%dW9^7&{KEiH|)b4;>Eb8J*64Q$rj@)lOrkG$hDff$)K>xH(PJhl&W2oYs;`kC^ z8i-G1$lRXqWtN>*diPLSRPoZ=fpMmT7EqN%sb%pwnZ+dxM>=**&bzwU%+X4F z=4O4jch1YbmZPbOPtGsRD`8l{bkOojSxx7iwUsx_F2onGT%NTCU1f1*UV2U{!;NFk za$HT@HtzM^Z22xYzxxX3oPH#w1&Kw)sSL|3Z_LX$+P(St!T$@s9G9=3>(*BbRaBgj zUml;DTToI7v>WV|SE`S-9OmCIIk;1;LqVWdM(obfV3^{}+yY=`NY2ko%S>lDXyC0a zR3XH8X^lvftp4+0pF;`phDHWJpio?yo0FNB%~0)nvt;qa{nu7b`EYew*shJ|_}, head.inspect end @@ -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{#}, head.inspect end @@ -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 diff --git a/test/test_repo.rb b/test/test_repo.rb index 0aa6431b..8c35e638 100644 --- a/test/test_repo.rb +++ b/test/test_repo.rb @@ -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 diff --git a/test/test_rubygit.rb b/test/test_rubygit.rb index 9a4f5a16..83f62ed7 100644 --- a/test/test_rubygit.rb +++ b/test/test_rubygit.rb @@ -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)