debian-mirror-gitlab/lib/gitlab/git/rev_list.rb

79 lines
2.2 KiB
Ruby
Raw Normal View History

2017-09-10 17:25:29 +05:30
# Gitaly note: JV: will probably be migrated indirectly by migrating the call sites.
2017-08-17 22:00:37 +05:30
module Gitlab
module Git
class RevList
2018-03-17 18:26:18 +05:30
include Gitlab::Git::Popen
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
attr_reader :oldrev, :newrev, :repository
def initialize(repository, newrev:, oldrev: nil)
2017-08-17 22:00:37 +05:30
@oldrev = oldrev
@newrev = newrev
2018-03-17 18:26:18 +05:30
@repository = repository
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
# This method returns an array of new commit references
2017-08-17 22:00:37 +05:30
def new_refs
2018-03-17 18:26:18 +05:30
repository.rev_list(including: newrev, excluding: :all).split("\n")
end
# Finds newly added objects
# Returns an array of shas
#
# Can skip objects which do not have a path using required_path: true
# This skips commit objects and root trees, which might not be needed when
# looking for blobs
#
# When given a block it will yield objects as a lazy enumerator so
# the caller can limit work done instead of processing megabytes of data
def new_objects(require_path: nil, not_in: nil, &lazy_block)
opts = {
including: newrev,
excluding: not_in.nil? ? :all : not_in,
require_path: require_path
}
get_objects(opts, &lazy_block)
end
def all_objects(require_path: nil, &lazy_block)
get_objects(including: :all, require_path: require_path, &lazy_block)
2017-08-17 22:00:37 +05:30
end
# This methods returns an array of missed references
2017-09-10 17:25:29 +05:30
#
# Should become obsolete after https://gitlab.com/gitlab-org/gitaly/issues/348.
2017-08-17 22:00:37 +05:30
def missed_ref
2018-03-17 18:26:18 +05:30
repository.missed_ref(oldrev, newrev).split("\n")
2017-08-17 22:00:37 +05:30
end
private
def execute(args)
2018-03-17 18:26:18 +05:30
repository.rev_list(args).split("\n")
end
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
def get_objects(including: [], excluding: [], require_path: nil)
opts = { including: including, excluding: excluding, objects: true }
repository.rev_list(opts) do |lazy_output|
objects = objects_from_output(lazy_output, require_path: require_path)
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
yield(objects)
end
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
def objects_from_output(object_output, require_path: nil)
object_output.map do |output_line|
sha, path = output_line.split(' ', 2)
next if require_path && path.to_s.empty?
sha
end.reject(&:nil?)
2017-08-17 22:00:37 +05:30
end
end
end
end