Fix compiler warning due to missing function prototype.
[svn.git] / subversion / bindings / swig / ruby / svn / wc.rb
blobcbc6aa853e8f518d10ccb96b0c01713ba6d98d9d
1 require "English"
2 require "svn/error"
3 require "svn/util"
4 require "svn/core"
5 require "svn/delta"
6 require "svn/ext/wc"
8 module Svn
9   module Wc
10     Util.set_constants(Ext::Wc, self)
11     Util.set_methods(Ext::Wc, self)
12     self.swig_init_asp_dot_net_hack()
14     @@alias_targets = %w(parse_externals_description
15                          ensure_adm cleanup)
16     class << self
17       @@alias_targets.each do |target|
18         alias_method "_#{target}", target
19       end
20     end
21     @@alias_targets.each do |target|
22       alias_method "_#{target}", target
23     end
24     @@alias_targets = nil
26     module_function
27     def locked?(path)
28       Wc.locked(path)
29     end
31     def ensure_adm(*args)
32       AdmAccess.ensure(*args)
33     end
35     # For backward compatibility
36     def parse_externals_description(*args)
37       ExternalsDescription.parse(*args)
38     end
40     def actual_target(path)
41       Wc.get_actual_target(path)
42     end
44     def normal_prop?(name)
45       Wc.is_normal_prop(name)
46     end
48     def wc_prop?(name)
49       Wc.is_wc_prop(name)
50     end
52     def entry_prop?(name)
53       Wc.is_entry_prop(name)
54     end
56     def pristine_copy_path(path)
57       Wc.get_pristine_copy_path(path)
58     end
60     def default_ignores(config)
61       Wc.get_default_ignores(config)
62     end
64     def cleanup(path, diff3_cmd=nil, cancel_func=nil)
65       Wc.cleanup2(path, diff3_cmd, cancel_func)
66     end
68     def ignore?(path, patterns)
69       Wc.match_ignore_list(path, patterns)
70     end
72     module ExternalsDescription
73       module_function
74       def parse(parent_dir, desc, canonicalize_url=true)
75         Wc.parse_externals_description3(parent_dir, desc, canonicalize_url)
76       end
77     end
79     class ExternalItem
80       class << self
81         undef new
82       end
83     end
85     AdmAccess = SWIG::TYPE_p_svn_wc_adm_access_t
86     class AdmAccess
87       class << self
88         def ensure(path, uuid, url, repos, revision, depth=nil)
89           Wc.ensure_adm3(path, uuid, url, repos, revision, depth)
90         end
92         def open(associated, path, write_lock=true,
93                  depth=-1, cancel_func=nil, &block)
94           _open(:adm_open3, associated, path, write_lock,
95                 depth, cancel_func, &block)
96         end
98         def probe_open(associated, path, write_lock=true, depth=-1,
99                        cancel_func=nil, &block)
100           _open(:adm_probe_open3, associated, path, write_lock,
101                 depth, cancel_func, &block)
102         end
104         def open_anchor(path, write_lock=true, depth=-1,
105                         cancel_func=nil, &block)
106           _open(:adm_open_anchor, path, write_lock, depth,
107                 cancel_func, &block)
108         end
110         private
111         def _open(name, *args, &block)
112           results = Wc.__send__(name, *args, &block)
113           adm, *rest = results
115           if block_given?
116             begin
117               yield *results
118             ensure
119               adm.close
120             end
121           else
122             results
123           end
124         end
125       end
127       attr_accessor :traversal_info
129       def open(*args, &block)
130         self.class.open(self, *args, &block)
131       end
133       def probe_open(*args, &block)
134         self.class.probe_open(self, *args, &block)
135       end
137       def retrieve(path)
138         Wc.adm_retrieve(self, path)
139       end
141       def probe_retrieve(path)
142         Wc.adm_probe_retrieve(self, path)
143       end
145       def probe_try(path, write_lock, depth, &cancel_func)
146         Wc.adm_probe_try3(self, path, write_lock, depth, cancel_func)
147       end
149       def close
150         Wc.adm_close(self)
151       end
153       def path
154         Wc.adm_access_path(self)
155       end
157       def locked?
158         Wc.adm_locked(self)
159       end
161       def has_binary_prop?(path)
162         Wc.has_binary_prop(path, self)
163       end
165       def text_modified?(filename, force=false)
166         Wc.text_modified_p(filename, force, self)
167       end
169       def props_modified?(path)
170         Wc.props_modified_p(path, self)
171       end
173       def entry(path, show_hidden=false)
174         Entry.new(path, self, show_hidden, Svn::Core::Pool.new)
175       end
177       def read_entries(show_hidden=false)
178         Wc.entries_read(self, show_hidden, Svn::Core::Pool.new)
179       end
181       def ancestry(path)
182         Wc.get_ancestry(path, self)
183       end
185       def walk_entries(path, callbacks, show_hidden=false, cancel_func=nil,
186                        depth=nil)
187         Wc.walk_entries3(path, self, callbacks, depth, show_hidden,
188                          cancel_func)
189       end
191       def mark_missing_deleted(path)
192         Wc.mark_missing_deleted(path, self)
193       end
195       def maybe_set_repos_root(path, repos)
196         Wc.maybe_set_repos_root(self, path, repos)
197       end
199       def status(path)
200         Wc.status2(path, self)
201       end
203       def status_editor(target, config, recurse=true,
204                         get_all=true, no_ignore=true,
205                         cancel_func=nil, traversal_info=nil)
206         traversal_info ||= _traversal_info
207         status_func = Proc.new do |path, status|
208           yield(path, status)
209         end
210         ret = Wc.get_status_editor2(self, target, config, recurse,
211                                     get_all, no_ignore, status_func,
212                                     cancel_func, traversal_info)
213         editor, editor_baton, set_lock_baton = *ret
214         editor.instance_variable_set("@__status_fun__", status_func)
215         editor.baton = editor_baton
216         def set_lock_baton.set_repos_locks(locks, repos_root)
217           Wc.status_set_repos_locks(self, locks, repos_root)
218         end
219         [editor, set_lock_baton]
220       end
222       def copy(src, dst_basename, cancel_func=nil, notify_func=nil)
223         Wc.copy2(src, self, dst_basename, cancel_func, notify_func)
224       end
226       def delete(path, cancel_func=nil, notify_func=nil, keep_local=false)
227         Wc.delete3(path, self, cancel_func, notify_func, keep_local)
228       end
230       def add(path, copyfrom_url=nil, copyfrom_rev=0,
231               cancel_func=nil, notify_func=nil)
232         Wc.add2(path, self, copyfrom_url, copyfrom_rev,
233                 cancel_func, notify_func)
234       end
236       def add_repos_file(dst_path, new_text_path, new_props,
237                          copyfrom_url=nil, copyfrom_rev=0)
238         Wc.add_repos_file(dst_path, self, new_text_path,
239                           new_props, copyfrom_url, copyfrom_rev)
240       end
242       def add_repos_file2(dst_path, new_text_base_path, new_base_props,
243                           new_text_path=nil, new_props=nil,
244                           copyfrom_url=nil, copyfrom_rev=0)
245         Wc.add_repos_file2(dst_path, self,
246                            new_text_base_path, new_text_path,
247                            new_base_props, new_props,
248                            copyfrom_url, copyfrom_rev)
249       end
251       def remove_from_revision_control(name, destroy_wf=true,
252                                        instant_error=true,
253                                        cancel_func=nil)
254         Wc.remove_from_revision_control(self, name,
255                                         destroy_wf,
256                                         instant_error,
257                                         cancel_func)
258       end
260       def resolved_conflict(path, resolve_text=true,
261                             resolve_props=true, recurse=true,
262                             notify_func=nil, cancel_func=nil)
263         Wc.resolved_conflict2(path, self, resolve_text,
264                               resolve_props, recurse,
265                               notify_func, cancel_func)
266       end
268       def process_committed(path, new_revnum, rev_date=nil, rev_author=nil,
269                             wcprop_changes=[], recurse=true,
270                             remove_lock=true, digest=nil,
271                             remove_changelist=false)
272         Wc.process_committed4(path, self, recurse,
273                               new_revnum, rev_date,
274                               rev_author, wcprop_changes,
275                               remove_lock, remove_changelist, digest)
276       end
278       def crawl_revisions(path, reporter, restore_files=true,
279                           depth=nil, use_commit_times=true,
280                           notify_func=nil, traversal_info=nil)
281         traversal_info ||= _traversal_info
282         Wc.crawl_revisions3(path, self, reporter, reporter.baton,
283                             restore_files, depth, use_commit_times,
284                             notify_func, traversal_info)
285       end
287       def wc_root?(path)
288         Wc.is_wc_root(path, self)
289       end
291       def update_editor(target, target_revision=nil, use_commit_times=nil,
292                         depth=nil, allow_unver_obstruction=nil, diff3_cmd=nil,
293                         notify_func=nil, cancel_func=nil, traversal_info=nil,
294                         preserved_exts=nil)
295         update_editor2(:target => target,
296                        :target_revision => target_revision,
297                        :use_commit_times => use_commit_times,
298                        :depth => depth,
299                        :allow_unver_obstruction => allow_unver_obstruction,
300                        :diff3_cmd => diff3_cmd,
301                        :notify_func => notify_func,
302                        :cancel_func => cancel_func,
303                        :traversal_info => traversal_info,
304                        :preserved_exts => preserved_exts )
305       end
307       UPDATE_EDITOR2_REQUIRED_ARGUMENTS_KEYS = [:target]
308       def update_editor2(arguments={})
309         arguments = arguments.reject {|k, v| v.nil?}
310         optional_arguments_defaults = {
311             :target_revision => nil,
312             :use_commit_times => true,
313             :depth => nil,
314             :depth_is_sticky => false,
315             :allow_unver_obstruction => false,
316             :diff3_cmd => nil,
317             :notify_func => nil,
318             :cancel_func => nil,
319             :conflict_func => nil,
320             :traversal_info => _traversal_info,
321             :preserved_exts => []
322           }
324         arguments = optional_arguments_defaults.merge(arguments)
325         Util.validate_options(arguments,
326                               optional_arguments_defaults.keys,
327                               UPDATE_EDITOR2_REQUIRED_ARGUMENTS_KEYS)
329         # TODO(rb support fetch_fun): implement support for the fetch_func
330         # callback.
331         arguments[:fetch_func] = nil
333         results = Wc.get_update_editor3(arguments[:target_revision], self,
334                                         arguments[:target],
335                                         arguments[:use_commit_times],
336                                         arguments[:depth],
337                                         arguments[:depth_is_sticky],
338                                         arguments[:allow_unver_obstruction],
339                                         arguments[:notify_func],
340                                         arguments[:cancel_func],
341                                         arguments[:conflict_func],
342                                         arguments[:fetch_func],
343                                         arguments[:diff3_cmd],
344                                         arguments[:preserved_exts],
345                                         arguments[:traversal_info])
346         target_revision_address, editor, editor_baton = results
347         editor.__send__(:target_revision_address=, target_revision_address)
348         editor.baton = editor_baton
349         editor
350       end
352       def switch_editor(target, switch_url, target_revision=nil,
353                         use_commit_times=nil, depth=nil,
354                         allow_unver_obstruction=nil, diff3_cmd=nil,
355                         notify_func=nil, cancel_func=nil, traversal_info=nil,
356                         preserved_exts=nil)
357         switch_editor2(:target => target,
358                        :switch_url => switch_url,
359                        :target_revision => target_revision,
360                        :use_commit_times => use_commit_times,
361                        :depth => depth,
362                        :allow_unver_obstruction => allow_unver_obstruction,
363                        :diff3_cmd => diff3_cmd,
364                        :notify_func => notify_func,
365                        :cancel_func => cancel_func,
366                        :traversal_info => traversal_info,
367                        :preserved_exts => preserved_exts )
368        end
370       SWITCH_EDITOR2_REQUIRED_ARGUMENTS_KEYS = [:target, :switch_url]
371       def switch_editor2(arguments={})
372         arguments = arguments.reject {|k, v| v.nil?}
373         optional_arguments_defaults = {
374           :target_revision => nil,
375           :use_commit_times => true,
376           :depth => nil,
377           :depth_is_sticky => false,
378           :allow_unver_obstruction => false,
379           :diff3_cmd => nil,
380           :notify_func => nil,
381           :cancel_func => nil,
382           :conflict_func => nil,
383           :traversal_info => _traversal_info,
384           :preserved_exts => []
385         }
386         arguments = optional_arguments_defaults.merge(arguments)
387         Util.validate_options(arguments,
388                               optional_arguments_defaults.keys,
389                               SWITCH_EDITOR2_REQUIRED_ARGUMENTS_KEYS)
391         results = Wc.get_switch_editor3(arguments[:target_revision], self,
392                                         arguments[:target],
393                                         arguments[:switch_url],
394                                         arguments[:use_commit_times],
395                                         arguments[:depth],
396                                         arguments[:depth_is_sticky],
397                                         arguments[:allow_unver_obstruction],
398                                         arguments[:notify_func],
399                                         arguments[:cancel_func],
400                                         arguments[:conflict_func],
401                                         arguments[:diff3_cmd],
402                                         arguments[:preserved_exts],
403                                         arguments[:traversal_info])
404         target_revision_address, editor, editor_baton = results
405         editor.__send__(:target_revision_address=, target_revision_address)
406         editor.baton = editor_baton
407         editor
408       end
410       def prop_list(path)
411         Wc.prop_list(path, self)
412       end
414       def prop(name, path)
415         Wc.prop_get(name, path, self)
416       end
418       def set_prop(name, value, path, skip_checks=false)
419         Wc.prop_set2(name, value, path, self, skip_checks)
420       end
422       def diff_editor(target, callbacks, depth=nil,
423                       ignore_ancestry=true, use_text_base=false,
424                       reverse_order=false, cancel_func=nil)
425         callbacks_wrapper = DiffCallbacksWrapper.new(callbacks)
426         args = [target, callbacks_wrapper, depth, ignore_ancestry,
427                 use_text_base, reverse_order, cancel_func]
428         diff_editor2(*args)
429       end
431       def diff_editor2(target, callbacks, depth=nil,
432                        ignore_ancestry=true, use_text_base=false,
433                        reverse_order=false, cancel_func=nil, changelists=nil)
434         editor, editor_baton = Wc.get_diff_editor4(self, target, callbacks,
435                                                    depth, ignore_ancestry,
436                                                    use_text_base, reverse_order,
437                                                    cancel_func, changelists)
438         editor.baton = editor_baton
439         editor
440       end
442       def diff(target, callbacks, recurse=true, ignore_ancestry=true)
443         callbacks_wrapper = DiffCallbacksWrapper.new(callbacks)
444         args = [target, callbacks_wrapper, recurse, ignore_ancestry]
445         diff2(*args)
446       end
448       def diff2(target, callbacks, recurse=true, ignore_ancestry=true)
449         Wc.diff3(self, target, callbacks, recurse, ignore_ancestry)
450       end
452       def prop_diffs(path)
453         Wc.get_prop_diffs(path, self)
454       end
456       def merge(left, right, merge_target, left_label,
457                 right_label, target_label, dry_run=false,
458                 diff3_cmd=nil, merge_options=nil)
459         Wc.merge2(left, right, merge_target, self,
460                   left_label, right_label, target_label,
461                   dry_run, diff3_cmd, merge_options)
462       end
464       def merge_props(path, baseprops, propchanges, base_merge=true,
465                       dry_run=false)
466         Wc.merge_props(path, self, baseprops, propchanges,
467                       base_merge, dry_run)
468       end
470       def merge_prop_diffs(path, propchanges, base_merge=true,
471                            dry_run=false)
472         Wc.merge_prop_diffs(path, self, propchanges,
473                            base_merge, dry_run)
474       end
476       def relocate(path, from, to, recurse=true, old_validator=nil, &validator)
477         if validator.nil? and !old_validator.nil?
478           validator = Proc.new do |uuid, url, root_url|
479             old_validator.call(uuid,
480                                root_url ? root_url : url,
481                                root_url ? true : false)
482           end
483         end
484         Wc.relocate3(path, self, from, to, recurse, validator)
485       end
487       def revert(path, recurse=true, use_commit_times=true,
488                  cancel_func=nil, notify_func=nil)
489         Wc.revert2(path, self, recurse, use_commit_times,
490                    cancel_func, notify_func)
491       end
493       def translated_file(src, versioned_file, flags)
494         temp = Wc.translated_file2(src, versioned_file, self, flags)
495         temp.close
496         path = temp.path
497         path.instance_variable_set("@__temp__", temp)
498         path
499       end
501       def translated_file2(src, versioned_file, flags)
502         Wc.translated_file2(src, versioned_file, self, flags)
503       end
505       def translated_stream(path, versioned_file, flags)
506         Wc.translated_stream(path, versioned_file, self, flags)
507       end
509       def transmit_text_deltas(path, editor, file_baton, fulltext=false)
510         editor.baton = file_baton
511         Wc.transmit_text_deltas(path, self, fulltext, editor)
512       end
514       def transmit_text_deltas2(path, editor, fulltext=false)
515         Wc.transmit_text_deltas2(path, self, fulltext, editor)
516       end
518       def transmit_prop_deltas(path, entry, editor, baton=nil)
519         editor.baton = baton if baton
520         Wc.transmit_prop_deltas(path, self, entry, editor)
521       end
523       def ignores(config)
524         Wc.get_ignores(config, self)
525       end
527       def add_lock(path, lock)
528         Wc.add_lock(path, lock, self)
529       end
531       def remove_lock(path)
532         Wc.remove_lock(path, self)
533       end
535       def set_changelist(path, changelist_name, cancel_func=nil,
536                          notify_func=nil)
537         Wc.set_changelist(path, changelist_name, self, cancel_func,
538                           notify_func)
539       end
541       private
542       def _traversal_info
543         @traversal_info ||= nil
544       end
545     end
547     class DiffCallbacksWrapper
548       def initialize(original)
549         @original = original
550       end
552       def file_changed(access, path, tmpfile1, tmpfile2, rev1,
553                        rev2, mimetype1, mimetype2,
554                        prop_changes, original_props)
555         prop_changes = Util.hash_to_prop_array(prop_changes)
556         @original.file_changed(access, path, tmpfile1, tmpfile2, rev1,
557                                rev2, mimetype1, mimetype2,
558                                prop_changes, original_props)
559       end
561       def file_added(access, path, tmpfile1, tmpfile2, rev1,
562                      rev2, mimetype1, mimetype2,
563                      prop_changes, original_props)
564         prop_changes = Util.hash_to_prop_array(prop_changes)
565         @original.file_added(access, path, tmpfile1, tmpfile2, rev1,
566                              rev2, mimetype1, mimetype2,
567                              prop_changes, original_props)
568       end
570       def dir_props_changed(access, path, prop_changes, original_props)
571         prop_changes = Util.hash_to_prop_array(prop_changes)
572         @original.dir_props_changed(access, path, prop_changes, original_props)
573       end
575       def method_missing(method, *args, &block)
576         @original.__send__(method, *args, &block)
577       end
578     end
580     class TraversalInfo
581       def edited_externals
582         Wc.edited_externals(self)
583       end
584     end
586     class Entry
587       def dup
588         Wc.entry_dup(self, Svn::Core::Pool.new)
589       end
591       def conflicted(dir_path)
592         Wc.conflicted_p(dir_path, self)
593       end
595       def conflicted?(dir_path)
596         conflicted(dir_path).any? {|x| x}
597       end
599       def text_conflicted?(dir_path)
600         conflicted(dir_path)[0]
601       end
603       def prop_conflicted?(dir_path)
604         conflicted(dir_path)[1]
605       end
607       def dir?
608         kind == Core::NODE_DIR
609       end
611       def file?
612         kind == Core::NODE_FILE
613       end
615       def add?
616         schedule == SCHEDULE_ADD
617       end
619       def normal?
620         schedule == SCHEDULE_NORMAL
621       end
622     end
624     class Status2
625       def dup
626         Wc.dup_status2(self, Core::Pool.new)
627       end
629       def text_added?
630         text_status == STATUS_ADDED
631       end
633       def text_normal?
634         text_status == STATUS_NORMAL
635       end
636     end
638     class Notify
639       def dup
640         Wc.dup_notify(self, Core::Pool.new)
641       end
643       def commit_added?
644         action == NOTIFY_COMMIT_ADDED
645       end
647       def commit_deleted?
648         action == NOTIFY_COMMIT_DELETED
649       end
651       def commit_postfix_txdelta?
652         action == NOTIFY_COMMIT_POSTFIX_TXDELTA
653       end
655       def add?
656         action == NOTIFY_ADD
657       end
659       def locked?
660         lock_state = NOTIFY_LOCK_STATE_LOCKED
661       end
663       def unlocked?
664         lock_state = NOTIFY_LOCK_STATE_UNLOCKED
665       end
666     end
668     class RevisionStatus
669       alias _initialize initialize
670       def initialize(wc_path, trail_url, committed, cancel_func=nil)
671         _initialize(wc_path, trail_url, committed, cancel_func)
672       end
673     end
675     class CommittedQueue
676       def push(access, path, recurse=true, wcprop_changes={}, remove_lock=true,
677                remove_changelist=false, digest=nil)
678         Wc.queue_committed(self, path, access, recurse, wcprop_changes,
679                            remove_lock, remove_changelist, digest)
680         self
681       end
683       def process(access, new_rev, rev_date=nil, rev_author=nil)
684         rev_date = rev_date.to_svn_format if rev_date.is_a?(Time)
685         Wc.process_committed_queue(self, access, new_rev, rev_date, rev_author)
686       end
687     end
688   end