diff options
author | Rémy Coutable <remy@rymai.me> | 2017-02-08 14:49:28 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-02-08 14:49:28 +0000 |
commit | 31d6e247041d4bb13aa712dcbbfad10ee5e403b8 (patch) | |
tree | 2d6500c76b7a3d9e67e32c1cff0a849e8965ab32 /lib/gitlab/git/rev_list.rb | |
parent | f0453905418dab64a1a53ff67044a5eb8f7aa333 (diff) | |
parent | b54b031638e7a98c1e51b369cff53602db40e4b0 (diff) | |
download | gitlab-ce-31d6e247041d4bb13aa712dcbbfad10ee5e403b8.tar.gz |
Merge branch 'backport-7967-and-8189-to-8-13-stable' into '8-13-stable'
8-13-stable
Backport !7967 and !8189 to `8-13-stable`
See merge request !8991
Diffstat (limited to 'lib/gitlab/git/rev_list.rb')
-rw-r--r-- | lib/gitlab/git/rev_list.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/gitlab/git/rev_list.rb b/lib/gitlab/git/rev_list.rb new file mode 100644 index 00000000000..79dd0cf7df2 --- /dev/null +++ b/lib/gitlab/git/rev_list.rb @@ -0,0 +1,42 @@ +module Gitlab + module Git + class RevList + attr_reader :project, :env + + ALLOWED_VARIABLES = %w[GIT_OBJECT_DIRECTORY GIT_ALTERNATE_OBJECT_DIRECTORIES].freeze + + def initialize(oldrev, newrev, project:, env: nil) + @project = project + @env = env.presence || {} + @args = [Gitlab.config.git.bin_path, + "--git-dir=#{project.repository.path_to_repo}", + "rev-list", + "--max-count=1", + oldrev, + "^#{newrev}"] + end + + def execute + Gitlab::Popen.popen(@args, nil, parse_environment_variables) + end + + def valid? + environment_variables.all? do |(name, value)| + value.to_s.start_with?(project.repository.path_to_repo) + end + end + + private + + def parse_environment_variables + return {} unless valid? + + environment_variables + end + + def environment_variables + @environment_variables ||= env.slice(*ALLOWED_VARIABLES).compact + end + end + end +end |