Welcome to mirror list, hosted at ThFree Co, Russian Federation.

diff_tree.rb « git « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: df48baeb1c3f8d7c124dbdf9a5257f005daed8ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

module Gitlab
  module Git
    # Represents a tree-ish object for git diff-tree command
    # See: https://git-scm.com/docs/git-diff-tree
    class DiffTree
      attr_reader :left_tree_id, :right_tree_id

      def initialize(left_tree_id, right_tree_id)
        @left_tree_id = left_tree_id
        @right_tree_id = right_tree_id
      end

      def self.from_commit(commit)
        return unless commit.tree_id

        parent_tree_id =
          if commit.parent_ids.blank?
            Gitlab::Git::EMPTY_TREE_ID
          else
            parent_id = commit.parent_ids.first
            commit.repository.commit(parent_id).tree_id
          end

        new(parent_tree_id, commit.tree_id)
      end
    end
  end
end