diff options
author | Nick Thomas <nick@gitlab.com> | 2018-05-18 15:53:35 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-05-18 15:53:35 +0000 |
commit | 8bacfbd1cc4f6c3678d50dd516df2b59eb0c8864 (patch) | |
tree | 95f10ff3ad472c77733eed972e238454e84d61e6 /lib | |
parent | 63831a24a693663a152d03f896e3ae1b5c6ef8cc (diff) | |
parent | 18a8eb96b34db63101c2b1210c1f93342b138a55 (diff) | |
download | gitlab-ce-8bacfbd1cc4f6c3678d50dd516df2b59eb0c8864.tar.gz |
Merge branch 'zj-calculate-checksum-mandator' into 'master'
Calculating repository checksums executed by Gitaly
Closes gitaly#1105 and #46293
See merge request gitlab-org/gitlab-ce!18907
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/repository.rb | 44 |
1 files changed, 6 insertions, 38 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 061865a7acf..b521d69930a 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -1572,14 +1572,12 @@ module Gitlab end def checksum - gitaly_migrate(:calculate_checksum, - status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled| - if is_enabled - gitaly_repository_client.calculate_checksum - else - calculate_checksum_by_shelling_out - end - end + # The exists? RPC is much cheaper, so we perform this request first + raise NoRepository, "Repository does not exists" unless exists? + + gitaly_repository_client.calculate_checksum + rescue GRPC::NotFound + raise NoRepository # Guard against data races. end private @@ -2478,36 +2476,6 @@ module Gitlab rev_parse_target(ref).oid end - def calculate_checksum_by_shelling_out - raise NoRepository unless exists? - - args = %W(--git-dir=#{path} show-ref --heads --tags) - output, status = run_git(args) - - if status.nil? || !status.zero? - # Non-valid git repositories return 128 as the status code and an error output - raise InvalidRepository if status == 128 && output.to_s.downcase =~ /not a git repository/ - # Empty repositories returns with a non-zero status and an empty output. - raise ChecksumError, output unless output.blank? - - return EMPTY_REPOSITORY_CHECKSUM - end - - refs = output.split("\n") - - result = refs.inject(nil) do |checksum, ref| - value = Digest::SHA1.hexdigest(ref).hex - - if checksum.nil? - value - else - checksum ^ value - end - end - - result.to_s(16) - end - def build_git_cmd(*args) object_directories = alternate_object_directories.join(File::PATH_SEPARATOR) |