Fix compiler warning due to missing function prototype.
[svn.git] / subversion / bindings / swig / ruby / svn / ra.rb
blob7fa1a050b7746e5d486ac0d6380159b33dc1f097
1 require "English"
2 require "tempfile"
3 require "svn/error"
4 require "svn/util"
5 require "svn/core"
6 require "svn/repos"
7 require "svn/ext/ra"
9 module Svn
10   module Ra
11     Util.set_constants(Ext::Ra, self)
12     Util.set_methods(Ext::Ra, self)
14     @@ra_pool = Svn::Core::Pool.new
15     Ra.initialize(@@ra_pool)
17     class << self
18       def modules
19         print_modules("")
20       end
21     end
23     Session = SWIG::TYPE_p_svn_ra_session_t
25     class Session
26       class << self
27         def open(url, config=nil, callbacks=nil)
28           Ra.open2(url, callbacks, config || Svn::Core::Config.get)
29         end
30       end
32       def latest_revnum
33         Ra.get_latest_revnum(self)
34       end
35       alias latest_revision latest_revnum
37       def dated_revision(time)
38         Ra.get_dated_revision(self, time.to_apr_time)
39       end
41       def set_prop(name, value, rev=nil)
42         Ra.change_rev_prop(self, rev || latest_revnum, name, value)
43       end
45       def []=(name, *args)
46         value = args.pop
47         set_prop(name, value, *args)
48         value
49       end
51       def proplist(rev=nil)
52         Ra.rev_proplist(self, rev || latest_revnum)
53       end
54       alias properties proplist
56       def prop(name, rev=nil)
57         Ra.rev_prop(self, rev || latest_revnum, name)
58       end
59       alias [] prop
61       def commit_editor(log_msg, lock_tokens={}, keep_lock=false)
62         callback = Proc.new do |new_revision, date, author|
63           yield(new_revision, date, author)
64         end
65         editor, editor_baton = Ra.get_commit_editor(self, log_msg, callback,
66                                                     lock_tokens, keep_lock)
67         editor.baton = editor_baton
68         [editor, editor_baton]
69       end
71       def commit_editor2(log_msg_or_rev_props, lock_tokens={},
72                          keep_lock=false, &callback)
73         if log_msg_or_rev_props.is_a?(Hash)
74           rev_props = log_msg_or_rev_props
75         else
76           rev_props = {Svn::Core::PROP_REVISION_LOG => log_msg_or_rev_props}
77         end
78         editor, editor_baton = Ra.get_commit_editor3(self, rev_props, callback,
79                                                      lock_tokens, keep_lock)
80         editor.baton = editor_baton
81         editor
82       end
84       def file(path, rev=nil)
85         output = StringIO.new
86         rev ||= latest_revnum
87         fetched_rev, props = Ra.get_file(self, path, rev, output)
88         output.rewind
89         props_filter(props)
90         [output.read, props]
91       end
93       def dir(path, rev=nil, fields=nil)
94         rev ||= latest_revnum
95         fields ||= Core::DIRENT_ALL
96         entries, fetched_rev, props = Ra.get_dir2(self, path, rev, fields)
97         props_filter(props)
98         [entries, props]
99       end
101       def update(revision_to_update_to, update_target,
102                  editor, editor_baton, depth=nil, &block)
103         editor.baton = editor_baton
104         update2(revision_to_update_to, update_target,
105                 editor, depth, &block)
106       end
108       def update2(revision_to_update_to, update_target, editor, depth=nil,
109                   send_copyfrom_args=nil)
110         reporter, reporter_baton = Ra.do_update2(self, revision_to_update_to,
111                                                  update_target, depth,
112                                                  send_copyfrom_args, editor)
113         reporter.baton = reporter_baton
114         if block_given?
115           yield(reporter)
116           reporter.finish_report
117           nil
118         else
119           reporter
120         end
121       end
123       def switch(revision_to_switch_to, switch_target, switch_url,
124                  editor, editor_baton, depth=nil, &block)
125         editor.baton = editor_baton
126         switch2(revision_to_switch_to, switch_target, switch_url,
127                 editor, depth, &block)
128       end
130       def switch2(revision_to_switch_to, switch_target, switch_url,
131                   editor, depth=nil)
132         reporter, reporter_baton = Ra.do_switch2(self, revision_to_switch_to,
133                                                  switch_target, depth,
134                                                  switch_url, editor)
135         reporter.baton = reporter_baton
136         if block_given?
137           yield(reporter)
138           reporter.finish_report
139           nil
140         else
141           reporter
142         end
143       end
145       def status(revision, status_target, editor, editor_baton,
146                  recurse=true, &block)
147         editor.baton = editor_baton
148         status2(revision, status_target, editor, recurse, &block)
149       end
151       def status2(revision, status_target, editor, recurse=true)
152         reporter, reporter_baton = Ra.do_status2(self, status_target,
153                                                  revision, recurse, editor)
154         reporter.baton = reporter_baton
155         if block_given?
156           yield(reporter)
157           reporter.finish_report
158           nil
159         else
160           reporter
161         end
162       end
164       def diff(rev, target, versus_url, editor,
165                depth=nil, ignore_ancestry=true, text_deltas=true)
166         args = [self, rev, target, depth, ignore_ancestry,
167                 text_deltas, versus_url, editor]
168         reporter, baton = Ra.do_diff3(*args)
169         reporter.baton = baton
170         reporter
171       end
173       def log(paths, start_rev, end_rev, limit,
174               discover_changed_paths=true,
175               strict_node_history=false)
176         paths = [paths] unless paths.is_a?(Array)
177         receiver = Proc.new do |changed_paths, revision, author, date, message|
178           yield(changed_paths, revision, author, date, message)
179         end
180         Ra.get_log(self, paths, start_rev, end_rev, limit,
181                    discover_changed_paths, strict_node_history,
182                    receiver)
183       end
185       def check_path(path, rev=nil)
186         Ra.check_path(self, path, rev || latest_revnum)
187       end
189       def stat(path, rev=nil)
190         Ra.stat(self, path, rev || latest_revnum)
191       end
193       def uuid
194         Ra.get_uuid(self)
195       end
197       def repos_root
198         Ra.get_repos_root(self)
199       end
201       def locations(path, location_revisions, peg_revision=nil)
202         peg_revision ||= latest_revnum
203         Ra.get_locations(self, path, peg_revision, location_revisions)
204       end
206       def file_revs(path, start_rev, end_rev=nil)
207         args = [path, start_rev, end_rev]
208         if block_given?
209           revs = file_revs2(*args) do |path, rev, rev_props, prop_diffs|
210             yield(path, rev, rev_props, Util.hash_to_prop_array(prop_diffs))
211           end
212         else
213           revs = file_revs2(*args)
214         end
215         revs.collect do |path, rev, rev_props, prop_diffs|
216           [path, rev, rev_props, Util.hash_to_prop_array(prop_diffs)]
217         end
218       end
220       def file_revs2(path, start_rev, end_rev=nil)
221         end_rev ||= latest_revnum
222         revs = []
223         handler = Proc.new do |path, rev, rev_props, prop_diffs|
224           revs << [path, rev, rev_props, prop_diffs]
225           yield(path, rev, rev_props, prop_diffs) if block_given?
226         end
227         Ra.get_file_revs(self, path, start_rev, end_rev, handler)
228         revs
229       end
231       def lock(path_revs, comment=nil, steal_lock=false)
232         lock_func = Proc.new do |path, do_lock, lock, ra_err|
233           yield(path, do_lock, lock, ra_err)
234         end
235         Ra.lock(self, path_revs, comment, steal_lock, lock_func)
236       end
238       def unlock(path_tokens, break_lock=false, &lock_func)
239         Ra.unlock(self, path_tokens, break_lock, lock_func)
240       end
242       def get_lock(path)
243         Ra.get_lock(self, path)
244       end
246       def get_locks(path)
247         Ra.get_locks(self, path)
248       end
250       def replay(rev, low_water_mark, editor, send_deltas=true)
251         Ra.replay(self, rev, low_water_mark, send_deltas, editor)
252       end
254       def reparent(url)
255         Ra.reparent(self, url)
256       end
258       def mergeinfo(paths, revision=nil, inherit=nil, include_descendants=false)
259         paths = [paths] unless paths.is_a?(Array)
260         revision ||= Svn::Core::INVALID_REVNUM
261         info = Ra.get_mergeinfo(self, paths, revision, inherit,
262                                 include_descendants)
263         unless info.nil?
264           info.each_key do |key|
265             info[key] = Core::MergeInfo.new(info[key])
266           end
267         end
268         info
269       end
271       private
272       def props_filter(props)
273         date_str = props[Svn::Core::PROP_ENTRY_COMMITTED_DATE]
274         if date_str
275           date = Time.parse_svn_format(date_str)
276           props[Svn::Core::PROP_ENTRY_COMMITTED_DATE] = date
277         end
278         props
279       end
280     end
282     class Reporter3
283       attr_accessor :baton
284       def set_path(path, revision, depth=nil, start_empty=true,
285                    lock_token=nil)
286         Ra.reporter3_invoke_set_path(self, @baton, path, revision,
287                                      depth, start_empty, lock_token)
288       end
290       def delete_path(path)
291         Ra.reporter3_invoke_delete_path(self, @baton, path)
292       end
294       def link_path(path, url, revision, depth=nil,
295                     start_empty=true, lock_token=nil)
296         Ra.reporter3_invoke_link_path(self, @baton, path, url,
297                                       revision, depth, start_empty, lock_token)
298       end
300       def finish_report
301         Ra.reporter3_invoke_finish_report(self, @baton)
302       end
304       def abort_report
305         Ra.reporter3_invoke_abort_report(self, @baton)
306       end
307     end
309     remove_const(:Callbacks)
310     class Callbacks
311       include Core::Authenticatable
313       def initialize(auth_baton=nil)
314         self.auth_baton = auth_baton || Core::AuthBaton.new
315       end
317       def open_tmp_file
318         tmp = Tempfile.new("Svn::Ra")
319         path = tmp.path
320         tmp.close(true)
321         path
322       end
324       def get_wc_prop(relpath, name)
325         nil
326       end
328       def set_wc_prop(path, name, value)
329       end
331       def push_wc_prop(path, name, value)
332       end
334       def invalidate_wc_props(path, name)
335       end
337       def progress_func(progress, total)
338       end
339     end
340   end