Class: Svn::Repo

Inherits:
FFI::AutoPointer
  • Object
show all
Defined in:
lib/svn/repos.rb

Overview

A subverion repository object

This represents both the repository and the filesystem

Defined Under Namespace

Modules: C Classes: FileSystem

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, pool) ⇒ Repo



15
16
17
18
# File 'lib/svn/repos.rb', line 15

def initialize( ptr, pool )
  super( ptr )
  @pool = pool
end

Instance Attribute Details

#poolObject (readonly)

Returns the value of attribute pool.



13
14
15
# File 'lib/svn/repos.rb', line 13

def pool
  @pool
end

Class Method Details

.create(path, parent = RootPool) ⇒ Object

Raises:

  • (ArgumentError)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/svn/repos.rb', line 43

def create( path, parent=RootPool )
  raise ArgumentError, 'Path cannot be nil' if path.nil?

  # get a new pool for all interactions with this repository
  pool = Pool.create( parent )

  out = FFI::MemoryPointer.new( :pointer )

  # make sure the path is canonical: full path from / and no trailing /
  final_path = File.expand_path( path.chomp(File::SEPARATOR) )

  Error.check_and_raise(
      C.create(
          out, # an out pointer to the newly created repository
          path.chomp(File::SEPARATOR), # path on disk
          nil, nil, # unused
          nil, nil, # configs are not implemeted
          pool # the pool to use for any allocations
        )
    )

  new( out.read_pointer, pool )
end

.delete(path, pool = RootPool) ⇒ Object



67
68
69
70
71
# File 'lib/svn/repos.rb', line 67

def delete( path, pool=RootPool )
  Error.check_and_raise(
      C.delete( path.chomp(File::SEPARATOR), pool )
    )
end

.open(path, parent = RootPool) ⇒ Object

– several methods remove trailing separators; this is to avoid triggering assertions in SVN libs ++

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/svn/repos.rb', line 25

def open( path, parent=RootPool )
  raise ArgumentError, 'Path cannot be nil' if path.nil?

  # get a new pool for all interactions with this repository
  pool = Pool.create( parent )

  out = FFI::MemoryPointer.new( :pointer )

  # make sure the path is canonical: full path from / and no trailing /
  final_path = File.expand_path( path.chomp(File::SEPARATOR) )

  Error.check_and_raise(
      C.open( out, final_path, pool )
    )

  new( out.read_pointer, pool )
end

.release(ptr) ⇒ Object

this release method does nothing because the repo will be released when its pool is destroyed



75
76
# File 'lib/svn/repos.rb', line 75

def release( ptr )
end

Instance Method Details

#changes(path, options = {}, &block) ⇒ Object

returns an array of “interesting” [path, rev] pairs for path

for more detailed information, use history

if a block is given, each pair will be yielded

options:

start_rev

restricts revisions to newer than :start_rev

end_rev

restricts revisions to older than :end_rev

cross_copies

continue history at filesystem copies?



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/svn/repos.rb', line 273

def changes( path, options={}, &block )
  # ensure the options can be passed to C successfully
  start_rev = (options[:start_rev] || 0).to_i
  end_rev = (options[:end_rev] || youngest).to_i
  cross_copies = ( options[:cross_copies] ? 1 : 0 )

  # collect the change [path, rev] pairs
  changes = []
  Error.check_and_raise( C.history(
      fs, path,
      C::CollectChanges, Utils.wrap( changes ),
      nil, nil, start_rev, end_rev, cross_copies, pool
    ) )

  # if the caller supplied a block, use it
  changes.each( &block ) if block_given?

  changes
end

#filesystemObject Also known as: fs

returns the repository’s filesystem

this is for internal use because Repo objects should handle all fs functionality



95
96
97
# File 'lib/svn/repos.rb', line 95

def filesystem
  @fs ||= C.filesystem( self )
end

#history(paths = nil, options = {}, &block) ⇒ Object

returns an array of log entry hashes for relevant revisions, containing:

  • revision number (rev), log, author, and timestamp

if a block is given, each log entry hash will be yielded

options:

start_rev

restricts revisions to newer than :start_rev

end_rev

restricts revisions to older than :end_rev

cross_copies

continue history at filesystem copies?

include_merged

include merged history?

include_changes

include change info in :changed_paths?

starting and ending revisions can be switched to reverse the final order



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/svn/repos.rb', line 306

def history( paths=nil, options={}, &block )
  # if no paths were passed, but options were, then paths will be a hash
  if paths.is_a? Hash
    options = paths
    paths = nil
  end

  # ensure the options can be passed to C successfully
  paths_c_arr = AprArray.create_from( Array( paths ), :string )
  start_rev = (options[:start_rev] || 0).to_i
  end_rev = (options[:end_rev] || youngest).to_i
  limit = (options[:limit] || 0).to_i # 0 => all entries
  discover_changed_paths = ( options[:include_changes] ? 1 : 0 )
  strict_history = ( options[:cross_copies] ? 0 : 1 )
  include_merged = ( options[:include_merged] ? 1 : 0 )

  # collect the history entries
  history = []
  Error.check_and_raise( C.logs(
      self, paths_c_arr,
      start_rev, end_rev, limit,
      discover_changed_paths, strict_history, include_merged,
      nil, nil, nil,
      C::CollectHistory, Utils.wrap( history ),
      pool
    ) )

  # if the caller supplied a block, use it
  history.each( &block ) if block_given?

  history
end