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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/git/diff_tree.rb')
-rw-r--r--lib/gitlab/git/diff_tree.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/gitlab/git/diff_tree.rb b/lib/gitlab/git/diff_tree.rb
new file mode 100644
index 00000000000..df48baeb1c3
--- /dev/null
+++ b/lib/gitlab/git/diff_tree.rb
@@ -0,0 +1,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