ruby - Why am I seeing inaccurate diff deltas in libgit2 / rugged? -
when using rugged remove files stage commit, diff commit comes out false information files deleted. files supposed there still there , resulting state of project correct. it's diff reporting incorrectly.
i may misunderstanding / misusing rugged::tree::builder
, other diffs, seems come out correctly. note leaving empty tree object here, don't see why should affect this.
project structure:
demo-project/ └── masterdir ├── directory1 │ ├── file1 │ ├── file2 │ └── file3 ├── directory2 │ ├── file4 │ └── file5 ├── directory3 │ └── file6 └── directory4 └── file7
call sequence
require 'rugged' repo = rugged::repository.new("/users/davetakahashi/demo-project") # tree "masterdir/directory1" tree = repo.lookup(repo.head.target.tree.path("masterdir/directory1")[:oid]) # initialize builder tree builder = rugged::tree::builder.new(tree) # remove files builder.remove("file1") builder.remove("file2") builder.remove("file3") # write tree, saving oid write parent tree empty_directory_1_oid = builder.write(repo) # tree "masterdir" parent_tree = repo.lookup(repo.head.target.tree.path("masterdir")[:oid]) # initialize builder builder = rugged::tree::builder.new(parent_tree) # add updated entry "directory1" builder << {:oid => empty_directory_1_oid, :filemode => 040000, :name => "directory1", :type => :tree} # write repo, save oid new_master_dir_oid = builder.write(repo) # oid "masterdir" @ head old_master_dir_oid = repo.head.target.tree.path("masterdir")[:oid] # new masterdir tree empty directory1 new_thing = repo.lookup(new_master_dir_oid) # original masterdir tree old_thing = repo.lookup(old_master_dir_oid) # diff shows every file in masterdir deleted old_thing.diff(new_thing).deltas
irb session:
[demo-project (master)]$ irb 2.1.3 :001 > require 'rugged' => true 2.1.3 :002 > repo = rugged::repository.new("/users/davetakahashi/demo-project") => #<rugged::repository:70270137753220 {path: "/users/davetakahashi/demo-project/.git/"}> 2.1.3 :003 > tree = repo.lookup(repo.head.target.tree.path("masterdir/directory1")[:oid]) => #<rugged::tree:70270137716900 {oid: abdee7bc13e432263b8da96776faa870a0b705b5}> <"file1" edd02898ce2deab5b06f9af79c97225427aa0202> <"file2" 2289c92f857605706b5bb1405e8b62b188777f36> <"file3" 248bce651b8c13085beb99c77b63d83a9866fbe5> 2.1.3 :004 > builder = rugged::tree::builder.new(tree) => #<rugged::tree::builder:0x007fd215310a08> 2.1.3 :005 > builder.remove("file1") => true 2.1.3 :006 > builder.remove("file2") => true 2.1.3 :007 > builder.remove("file3") => true 2.1.3 :008 > empty_directory_1_oid = builder.write(repo) => "4b825dc642cb6eb9a060e54bf8d69288fbee4904" 2.1.3 :009 > parent_tree = repo.lookup(repo.head.target.tree.path("masterdir")[:oid]) => #<rugged::tree:70270137598260 {oid: 67e1a15042779fd7a0bb5f55517d15acb407a36a}> <"directory1" abdee7bc13e432263b8da96776faa870a0b705b5> <"directory2" ba23af1963e685c6385440ea1d76d92eb0fc4728> <"directory3" eaea4f258ad3488468c52e068994c6289c9ee4ea> <"directory4" 3344b4aa8fec8f28d189d5d2f05285e60f26cbd4> 2.1.3 :010 > builder = rugged::tree::builder.new(parent_tree) => #<rugged::tree::builder:0x007fd2152d2730> 2.1.3 :011 > builder << {:oid => empty_directory_1_oid, :filemode => 040000, :name => "directory1", :type => :tree} => nil 2.1.3 :012 > new_master_dir_oid = builder.write(repo) => "a1a2ebae492b845684bb53a01981b5710a9d1814" 2.1.3 :013 > old_master_dir_oid = repo.head.target.tree.path("masterdir")[:oid] => "67e1a15042779fd7a0bb5f55517d15acb407a36a" 2.1.3 :014 > new_thing = repo.lookup(new_master_dir_oid) => #<rugged::tree:70270137454060 {oid: a1a2ebae492b845684bb53a01981b5710a9d1814}> <"directory1" 4b825dc642cb6eb9a060e54bf8d69288fbee4904> <"directory2" ba23af1963e685c6385440ea1d76d92eb0fc4728> <"directory3" eaea4f258ad3488468c52e068994c6289c9ee4ea> <"directory4" 3344b4aa8fec8f28d189d5d2f05285e60f26cbd4> 2.1.3 :015 > old_thing = repo.lookup(old_master_dir_oid) => #<rugged::tree:70270137436000 {oid: 67e1a15042779fd7a0bb5f55517d15acb407a36a}> <"directory1" abdee7bc13e432263b8da96776faa870a0b705b5> <"directory2" ba23af1963e685c6385440ea1d76d92eb0fc4728> <"directory3" eaea4f258ad3488468c52e068994c6289c9ee4ea> <"directory4" 3344b4aa8fec8f28d189d5d2f05285e60f26cbd4> 2.1.3 :016 > old_thing.diff(new_thing).deltas => [#<rugged::diff::delta:70270137419160 {old_file: {:oid=>"edd02898ce2deab5b06f9af79c97225427aa0202", :path=>"directory1/file1", :size=>0, :flags=>4, :mode=>33188}, new_file: {:oid=>"0000000000000000000000000000000000000000", :path=>"directory1/file1", :size=>0, :flags=>4, :mode=>0}, similarity: 0, status: :deleted>, #<rugged::diff::delta:70270137418980 {old_file: {:oid=>"2289c92f857605706b5bb1405e8b62b188777f36", :path=>"directory1/file2", :size=>0, :flags=>4, :mode=>33188}, new_file: {:oid=>"0000000000000000000000000000000000000000", :path=>"directory1/file2", :size=>0, :flags=>4, :mode=>0}, similarity: 0, status: :deleted>, #<rugged::diff::delta:70270137418840 {old_file: {:oid=>"248bce651b8c13085beb99c77b63d83a9866fbe5", :path=>"directory1/file3", :size=>0, :flags=>4, :mode=>33188}, new_file: {:oid=>"0000000000000000000000000000000000000000", :path=>"directory1/file3", :size=>0, :flags=>4, :mode=>0}, similarity: 0, status: :deleted>, #<rugged::diff::delta:70270137418700 {old_file: {:oid=>"252bae4bbacebe7a44e02b688960ccaff0515ee1", :path=>"directory2/file4", :size=>0, :flags=>4, :mode=>33188}, new_file: {:oid=>"0000000000000000000000000000000000000000", :path=>"directory2/file4", :size=>0, :flags=>4, :mode=>0}, similarity: 0, status: :deleted>, #<rugged::diff::delta:70270137418560 {old_file: {:oid=>"a4b3a268c46f5a5340ab8a59fc74ebdc38d9a74a", :path=>"directory2/file5", :size=>0, :flags=>4, :mode=>33188}, new_file: {:oid=>"0000000000000000000000000000000000000000", :path=>"directory2/file5", :size=>0, :flags=>4, :mode=>0}, similarity: 0, status: :deleted>, #<rugged::diff::delta:70270137418420 {old_file: {:oid=>"1928ee6db9fcd32139f8b7bd315766d645aec086", :path=>"directory3/file6", :size=>0, :flags=>4, :mode=>33188}, new_file: {:oid=>"0000000000000000000000000000000000000000", :path=>"directory3/file6", :size=>0, :flags=>4, :mode=>0}, similarity: 0, status: :deleted>, #<rugged::diff::delta:70270137418280 {old_file: {:oid=>"d4fc3289375ca9a25b52badad06540fe31f9ed73", :path=>"directory4/file7", :size=>0, :flags=>4, :mode=>33188}, new_file: {:oid=>"0000000000000000000000000000000000000000", :path=>"directory4/file7", :size=>0, :flags=>4, :mode=>0}, similarity: 0, status: :deleted>]
so though i've removed 3 files, deltas show i've deleted (7 files). i've tried options available on diff()
, i'm guessing i'm missing step in using tree::builder
. not allowed leave empty tree object?
i suspect because you're inserting empty tree tree, not git do. if want remove 'masterdir/directory1', , should work well.
the usual way of handling multi-level trees via index
takes care of removing empty trees.
Comments
Post a Comment