Project size limit is aborted with submodule commits properly

ZD: https://gitlab.zendesk.com/agent/tickets/82217

Steps to reproduce:

  1. Create a new repository: git init foo
  2. Add a new commit: echo hello > README.md; git commit -m "Test commit
  3. Add a new submodule: git submodule add https://github.com/jneen/rouge.git test-submodule
  4. Commit these changes

The project delta size check in https://gitlab.com/gitlab-org/gitlab-ee/blob/v9.5.4-ee/ee/lib/ee/gitlab/deltas.rb#L13 assumes that each OID is a valid Blob, but that's not necessarily true for a submodule commit. If you simulate the project delta size check, you can see:

require 'rugged'
oldrev = '0c3a03a6b641d7a61db1e6f1bd64503ae01f1bb8'
newrev = 'refs/heads/master'
change = { oldrev: oldrev, newrev: newrev }

repo = Rugged::Repository.new('.')
tree_a = repo.rev_parse(change[:oldrev])
tree_b = repo.rev_parse(change[:newrev])
diff = tree_a.diff(tree_b)

diff.each_delta do |d|
  puts "old_file: #{d.old_file}, new_file #{d.new_file}"
  puts "new file OID is #{d.new_file[:oid]}, object type is #{repo.lookup(d.new_file[:oid])}"
end

The result is:

old_file: {:oid=>"0000000000000000000000000000000000000000", :path=>".gitmodules", :size=>0, :flags=>4, :mode=>0}, new_file {:oid=>"83eef81c869b6f0876224a6190ded45b948897d9", :path=>".gitmodules", :size=>0, :flags=>12, :mode=>33188}
new file OID is 83eef81c869b6f0876224a6190ded45b948897d9, object type is #<Rugged::Blob:0x007fb0838a6688>
old_file: {:oid=>"0000000000000000000000000000000000000000", :path=>"rouge", :size=>0, :flags=>4, :mode=>0}, new_file {:oid=>"95ab4ae821b1bc88bba407db7f80b5fd1f86e6bb", :path=>"rouge", :size=>0, :flags=>12, :mode=>57344}
/Users/stanhu/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rugged-0.26.0/lib/rugged/repository.rb:104:in `lookup': object not found - no match for id (95ab4ae821b1bc88bba407db7f80b5fd1f86e6bb) (Rugged::OdbError)

Because of the Rugged::OdbError, the project size limit check will stop there. We should probably continue and consider that particular revision 0.

Assignee Loading
Time tracking Loading