Class: MultiGit::JGitBackend::Repository
- Inherits:
-
Repository
- Object
- Repository
- MultiGit::JGitBackend::Repository
show all
- Extended by:
- Forwardable
- Defined in:
- lib/multi_git/jgit_backend/repository.rb
Instance Method Summary
collapse
Methods inherited from Repository
#bare?, #branch, #head, #tag
#abstract
Constructor Details
#initialize(path, options = {}) ⇒ Repository
Returns a new instance of Repository.
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/multi_git/jgit_backend/repository.rb', line 44
def initialize(path, options = {})
options = initialize_options(path,options)
builder = Java::OrgEclipseJgitStorageFile::FileRepositoryBuilder.new
builder.setGitDir(Java::JavaIO::File.new(options[:repository]))
if options[:working_directory]
builder.setWorkTree(Java::JavaIO::File.new(options[:working_directory]))
end
if options[:index]
builder.setIndexFile(Java::JavaIO::File.new(options[:index]))
end
@git = builder.build
if !@git.getObjectDatabase().exists
if options[:init]
@git.create(!!options[:bare])
else
raise MultiGit::Error::NotARepository, path
end
end
verify_bareness(path, options)
end
|
Instance Method Details
119
120
121
|
# File 'lib/multi_git/jgit_backend/repository.rb', line 119
def config
@config ||= Config.new(@git.config)
end
|
#each_branch(filter = :all) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/multi_git/jgit_backend/repository.rb', line 129
def each_branch(filter = :all)
return to_enum(:each_branch, filter) unless block_given?
prefix = case filter
when :all, Regexp then 'refs/'
when :local then Java::OrgEclipseJgitLib::Constants::R_HEADS
when :remote then Java::OrgEclipseJgitLib::Constants::R_REMOTES
end
refs = @git.ref_database.get_refs(prefix)
if filter.kind_of? Regexp
refs.each do |name, ref|
next unless filter === name[(name.index('/')+1)..-1]
yield Ref.new(self, ref)
end
else
refs.each do |name, ref|
yield Ref.new(self, ref)
end
end
return self
end
|
150
151
152
153
154
155
156
157
|
# File 'lib/multi_git/jgit_backend/repository.rb', line 150
def each_tag
return to_enum(:each_branch, filter) unless block_given?
refs = @git.ref_database.get_refs('refs/tags')
refs.each do |name, ref|
yield Ref.new(self, ref)
end
return self
end
|
36
37
38
|
# File 'lib/multi_git/jgit_backend/repository.rb', line 36
def git_dir
@git.getDirectory.to_s
end
|
#git_work_tree ⇒ Object
40
41
42
|
# File 'lib/multi_git/jgit_backend/repository.rb', line 40
def git_work_tree
bare? ? nil : @git.getWorkTree.to_s
end
|
#include?(oid) ⇒ Boolean
209
210
211
|
# File 'lib/multi_git/jgit_backend/repository.rb', line 209
def include?(oid)
@git.hasObject(Java::OrgEclipseJgitLib::ObjectId.fromString(oid))
end
|
#parse(ref) ⇒ String
217
218
219
|
# File 'lib/multi_git/jgit_backend/repository.rb', line 217
def parse(ref)
return Java::OrgEclipseJgitLib::ObjectId.toString(parse_java(ref))
end
|
103
104
105
106
107
108
|
# File 'lib/multi_git/jgit_backend/repository.rb', line 103
def read(read)
java_oid = parse_java(read)
object = use_reader{|rdr| rdr.open(java_oid) }
type = REVERSE_OBJECT_TYPE_IDS.fetch(object.getType)
return OBJECT_CLASSES[type].new(self, java_oid, object)
end
|
114
115
116
117
|
# File 'lib/multi_git/jgit_backend/repository.rb', line 114
def ref(name)
validate_ref_name(name)
Ref.new(self, name)
end
|
#remote(name_or_url) ⇒ Object
221
222
223
224
225
226
227
228
|
# File 'lib/multi_git/jgit_backend/repository.rb', line 221
def remote( name_or_url )
if looks_like_remote_url? name_or_url
remote = Remote.new(self, name_or_url)
else
remote = Remote::Persistent.new(self, name_or_url)
end
return remote
end
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/multi_git/jgit_backend/repository.rb', line 69
def write(content, type = :blob)
if content.kind_of? MultiGit::Builder
return content >> self
end
validate_type(type)
if content.kind_of? MultiGit::Object
if include?(content.oid)
return read(content.oid)
end
content = content.to_io
end
use_inserter do |inserter|
begin
t_id = OBJECT_TYPE_IDS[type]
reader = nil
if content.respond_to? :path
path = content.path
reader = Java::JavaIO::FileInputStream.new(path)
oid = inserter.insert(t_id.to_java(:int), ::File.size(content.path).to_java(:long), reader)
else
content = content.read if content.respond_to? :read
oid = inserter.insert(t_id, content.bytes.to_a.to_java(:byte))
end
return OBJECT_CLASSES[type].new(self, oid)
ensure
reader.close if reader
end
end
end
|