Class: RightScraper::Retrievers::Svn

Inherits:
CheckoutBasedRetriever show all
Includes:
SvnClient
Defined in:
lib/right_scraper/retrievers/svn.rb

Overview

Retriever for svn repositories

Constant Summary collapse

@@available =
false

Instance Attribute Summary

Attributes inherited from Base

#max_bytes, #max_seconds, #repo_dir, #repository

Instance Method Summary collapse

Methods included from SvnClient

#calculate_version, #exit_svn_client, #get_tag, #get_tag_argument, #run_svn, #run_svn_no_chdir, #run_svn_with, #run_svn_with_buffered_output, #safe_output_svn_client, #size_limit_svn_client, #svn_arguments, #timeout_svn_client, #unsafe_output_svn_client

Methods inherited from CheckoutBasedRetriever

#retrieve

Methods inherited from Base

#initialize, repo_dir, #retrieve

Constructor Details

This class inherits a constructor from RightScraper::Retrievers::Base

Instance Method Details

#available?Boolean

Determines if svn is available.

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/right_scraper/retrievers/svn.rb', line 35

def available?
  unless @@available
    begin
      calculate_version
      @@available = true
    rescue SvnClientError => e
      @logger.note_error(e, :available, "svn retriever is unavailable")
    end
  end
  @@available
end

#do_checkoutObject

Check out the remote repository. The operations are as follows:

  • checkout repository at #tag to @repo_dir



86
87
88
89
90
91
92
# File 'lib/right_scraper/retrievers/svn.rb', line 86

def do_checkout
  super
  @logger.operation(:checkout_revision) do
    run_svn_no_chdir("checkout", @repository.url, @repo_dir, get_tag_argument)
  end
  do_update_tag
end

#do_updateObject

Incrementally update the checkout. The operations are as follows:

  • update to #tag

In theory if #tag is a revision number that already exists no update is necessary. It’s not clear if the SVN client libraries are bright enough to notice this.



62
63
64
65
66
67
# File 'lib/right_scraper/retrievers/svn.rb', line 62

def do_update
  @logger.operation(:update) do
    run_svn("update", get_tag_argument)
  end
  do_update_tag
end

#do_update_tagObject

Update our idea of what the head of the repository is. We would like to use svn info, but that doesn’t do the right thing all the time; the right thing to do is to run log and pick out the first tag.



73
74
75
76
77
78
79
80
81
82
# File 'lib/right_scraper/retrievers/svn.rb', line 73

def do_update_tag
  @repository = @repository.clone
  lines = run_svn_with_buffered_output("log", "-r", 'HEAD')
  lines.each do |line|
    if line =~ /^r(\d+)/
      @repository.tag = $1
      break
    end
  end
end

#exists?Boolean

Return true if a checkout exists. Currently tests for .svn in the checkout.

Returns

Boolean

true if the checkout already exists (and thus incremental updating can occur).

Returns:

  • (Boolean)


53
54
55
# File 'lib/right_scraper/retrievers/svn.rb', line 53

def exists?
  File.exists?(File.join(@repo_dir, '.svn'))
end

#ignorable_pathsObject

Ignore .svn directories.



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

def ignorable_paths
  ['.svn']
end