Class: Gitlab::Git::RemoteRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/git/remote_repository.rb

Overview

When a Gitaly call involves two repositories instead of one we cannot assume that both repositories are on the same Gitaly server. In this case we need to make a distinction between the repository that the call is being made on (a Repository instance), and the “other” repository (a RemoteRepository instance). This is the reason why we have the RemoteRepository class in Gitlab::Git.

When you make changes, be aware that gitaly-ruby sub-classes this class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository) ⇒ RemoteRepository

Returns a new instance of RemoteRepository.


19
20
21
22
23
24
25
26
# File 'lib/gitlab/git/remote_repository.rb', line 19

def initialize(repository)
  @relative_path = repository.relative_path
  @gitaly_repository = repository.gitaly_repository

  # These instance variables will not be available in gitaly-ruby, where
  # we have no disk access to this repository.
  @repository = repository
end

Instance Attribute Details

#gitaly_repositoryObject (readonly)

Returns the value of attribute gitaly_repository.


17
18
19
# File 'lib/gitlab/git/remote_repository.rb', line 17

def gitaly_repository
  @gitaly_repository
end

#relative_pathObject (readonly)

Returns the value of attribute relative_path.


17
18
19
# File 'lib/gitlab/git/remote_repository.rb', line 17

def relative_path
  @relative_path
end

Instance Method Details

#branch_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)

42
43
44
45
46
# File 'lib/gitlab/git/remote_repository.rb', line 42

def branch_exists?(name)
  # We will override this implementation in gitaly-ruby because we cannot
  # use '@repository' there.
  @repository.branch_exists?(name)
end

#commit_id(revision) ⇒ Object


36
37
38
39
40
# File 'lib/gitlab/git/remote_repository.rb', line 36

def commit_id(revision)
  # We will override this implementation in gitaly-ruby because we cannot
  # use '@repository' there.
  @repository.commit(revision)&.sha
end

#empty?Boolean

Returns:

  • (Boolean)

28
29
30
31
32
33
34
# File 'lib/gitlab/git/remote_repository.rb', line 28

def empty?
  # We will override this implementation in gitaly-ruby because we cannot
  # use '@repository' there.
  #
  # Caches and memoization used on the Rails side
  !@repository.exists? || @repository.empty?
end

#pathObject


56
57
58
# File 'lib/gitlab/git/remote_repository.rb', line 56

def path
  @repository.path
end

#same_repository?(other_repository) ⇒ Boolean

Compares self to a Gitlab::Git::Repository. This implementation uses 'self.gitaly_repository' so that it will also work in the GitalyRemoteRepository subclass defined in gitaly-ruby.

Returns:

  • (Boolean)

51
52
53
54
# File 'lib/gitlab/git/remote_repository.rb', line 51

def same_repository?(other_repository)
  gitaly_repository.storage_name == other_repository.storage &&
    gitaly_repository.relative_path == other_repository.relative_path
end