lib/oxidized/output/gitcrypt.rb
def get_diff(node, group, oid1, oid2)
      diff_commits = nil
      repo, _path = yield_repo_and_path(node, group)
      repo = Git.open repo
      unlock repo
      commit = repo.gcommit(oid1)

      if oid2
        commit_old = repo.gcommit(oid2)
        diff = repo.diff(commit_old, commit)
        stats = [diff.stats[:files][node.name][:insertions], diff.stats[:files][node.name][:deletions]]
        diff.each do |patch|
          if /#{node.name}\s+/ =~ patch.patch.to_s.lines.first
            diff_commits = { patch: patch.patch.to_s, stat: stats }
            break
          end
        end
      else
        stat = commit.parents[0].diff(commit).stats
        stat = [stat[:files][node.name][:insertions], stat[:files][node.name][:deletions]]
        patch = commit.parents[0].diff(commit).patch
        diff_commits = { patch: patch, stat: stat }
      end
      lock repo
      diff_commits
    rescue StandardError
      'no diffs'
    ensure
      lock repo
    end
def get_diff(node, group, oid1, oid2)
      diff_commits = nil
      repo, _path = yield_repo_and_path(node, group)
      repo = Git.open repo
      unlock repo
      commit = repo.gcommit(oid1)

      if oid2
        commit_old = repo.gcommit(oid2)
        diff = repo.diff(commit_old, commit)
        stats = [diff.stats[:files][node.name][:insertions], diff.stats[:files][node.name][:deletions]]
        diff.each do |patch|
          if /#{node.name}\s+/ =~ patch.patch.to_s.lines.first
            diff_commits = { patch: patch.patch.to_s, stat: stats }
            break
          end
        end
      else
        stat = commit.parents[0].diff(commit).stats
        stat = [stat[:files][node.name][:insertions], stat[:files][node.name][:deletions]]
        patch = commit.parents[0].diff(commit).patch
        diff_commits = { patch: patch, stat: stat }
      end
      lock repo
      diff_commits
    rescue StandardError
      'no diffs'
    ensure
      lock repo
    end
give a hash with the patch of a diff between 2 revision and the stats (added and deleted lines)