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:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2017-11-03 17:33:06 +0300
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2017-11-06 13:20:14 +0300
commitca049902dc7dad6e6177b05c8e3dc74c00487d27 (patch)
tree47f7bc6019deab6b51b7c1a9f6321a6001a559ed /lib/gitlab/git/rev_list.rb
parent95640413e64c4a857bcfcf7a4dcf0ce79189f894 (diff)
Gitlab::Git::RevList and LfsChanges use lazy popen
Diffstat (limited to 'lib/gitlab/git/rev_list.rb')
-rw-r--r--lib/gitlab/git/rev_list.rb43
1 files changed, 28 insertions, 15 deletions
diff --git a/lib/gitlab/git/rev_list.rb b/lib/gitlab/git/rev_list.rb
index e0c884aceaa..4974205b8fd 100644
--- a/lib/gitlab/git/rev_list.rb
+++ b/lib/gitlab/git/rev_list.rb
@@ -25,17 +25,18 @@ module Gitlab
# This skips commit objects and root trees, which might not be needed when
# looking for blobs
#
- # Can return a lazy enumerator to limit work done on megabytes of data
- def new_objects(require_path: nil, lazy: false, not_in: nil)
- object_output = execute([*base_args, newrev, *not_in_refs(not_in), '--objects'])
+ # 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)
+ args = [*base_args, newrev, *not_in_refs(not_in), '--objects']
- objects_from_output(object_output, require_path: require_path, lazy: lazy)
+ get_objects(args, require_path: require_path, &lazy_block)
end
- def all_objects(require_path: nil)
- object_output = execute([*base_args, '--all', '--objects'])
+ def all_objects(require_path: nil, &lazy_block)
+ args = [*base_args, '--all', '--objects']
- objects_from_output(object_output, require_path: require_path, lazy: true)
+ get_objects(args, require_path: require_path, &lazy_block)
end
# This methods returns an array of missed references
@@ -64,6 +65,10 @@ module Gitlab
output.split("\n")
end
+ def lazy_execute(args, &lazy_block)
+ popen(args, nil, Gitlab::Git::Env.to_env_hash, lazy_block: lazy_block)
+ end
+
def base_args
[
Gitlab.config.git.bin_path,
@@ -72,20 +77,28 @@ module Gitlab
]
end
- def objects_from_output(object_output, require_path: nil, lazy: nil)
- objects = object_output.lazy.map do |output_line|
+ def get_objects(args, require_path: nil)
+ if block_given?
+ lazy_execute(args) do |lazy_output|
+ objects = objects_from_output(lazy_output, require_path: require_path)
+
+ yield(objects)
+ end
+ else
+ object_output = execute(args)
+
+ objects_from_output(object_output, require_path: require_path)
+ end
+ end
+
+ 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.blank?
sha
end.reject(&:nil?)
-
- if lazy
- objects
- else
- objects.force
- end
end
end
end