Method: Grit::GitRuby::Repository#quick_diff

Defined in:
lib/grit/git-ruby/repository.rb

#quick_diff(tree1, tree2, path = '.', recurse = true) ⇒ Object

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 [ [full_path, ‘added’, tree1_hash, nil],

 [full_path, 'removed', nil, tree2_hash],
 [full_path, 'modified', tree1_hash, tree2_hash]
]


499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
# File 'lib/grit/git-ruby/repository.rb', line 499

def quick_diff(tree1, tree2, path = '.', recurse = true)
  # handle empty trees
  return changed if tree1 == tree2

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

  # finding files that are different
  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
    full = File.join(path, dir)
    if !t2_tree
      if recurse
        changed += quick_diff(hsh[:sha], nil, full, true)
      else
        changed << [full, 'added', hsh[:sha], nil]      # not in parent
      end
    elsif (hsh[:sha] != t2_tree[:sha])
      if recurse
        changed += quick_diff(hsh[:sha], t2_tree[:sha], full, true)
      else
        changed << [full, 'modified', hsh[:sha], t2_tree[:sha]]   # file changed
      end
    end
  end if t1
  t2['tree'].each do |dir, hsh|
    t1_tree = t1['tree'][dir] rescue nil
    full = File.join(path, dir)
    if !t1_tree
      if recurse
        changed += quick_diff(nil, hsh[:sha], full, true)
      else
        changed << [full, 'removed', nil, hsh[:sha]]
      end
    end
  end if t2

  changed
end