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:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-03 18:07:07 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-03 18:07:07 +0300
commit9a1c5456747a7b5b218b8b44e4b43396bf7fd705 (patch)
treedc5873f33437c897389e923a59365fb192d87fb8 /lib/gitlab/git
parent927cfbfe63dd3dc64df9d341d7c4328a2fe3597f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/git')
-rw-r--r--lib/gitlab/git/changes.rb74
1 files changed, 74 insertions, 0 deletions
diff --git a/lib/gitlab/git/changes.rb b/lib/gitlab/git/changes.rb
new file mode 100644
index 00000000000..4e888eec44f
--- /dev/null
+++ b/lib/gitlab/git/changes.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Git
+ class Changes
+ include Enumerable
+
+ attr_reader :repository_data
+
+ def initialize
+ @refs = Set.new
+ @items = []
+ @branches_index = []
+ @tags_index = []
+ @repository_data = []
+ end
+
+ def includes_branches?
+ branches_index.any?
+ end
+
+ def includes_tags?
+ tags_index.any?
+ end
+
+ def add_branch_change(change)
+ @branches_index << add_change(change)
+ self
+ end
+
+ def add_tag_change(change)
+ @tags_index << add_change(change)
+ self
+ end
+
+ def each
+ items.each do |item|
+ yield item
+ end
+ end
+
+ def refs
+ @refs.to_a
+ end
+
+ def branch_changes
+ items.values_at(*branches_index)
+ end
+
+ def tag_changes
+ items.values_at(*tags_index)
+ end
+
+ private
+
+ attr_reader :items, :branches_index, :tags_index
+
+ def add_change(change)
+ # refs and repository_data are being cached when a change is added to
+ # the collection to remove the need to iterate through changes multiple
+ # times.
+ @refs << change[:ref]
+ @repository_data << build_change_repository_data(change)
+ @items << change
+
+ @items.size - 1
+ end
+
+ def build_change_repository_data(change)
+ DataBuilder::Repository.single_change(change[:oldrev], change[:newrev], change[:ref])
+ end
+ end
+ end
+end