Class: Autobuild::SVN
Instance Attribute Summary collapse
-
#revision ⇒ Object
readonly
Returns the value of attribute revision.
-
#svnroot ⇒ String
readonly
Returns the SVN root.
Attributes inherited from Importer
#interactive, #options, #post_hooks, #repository_id, #source_id
Instance Method Summary collapse
-
#checkout(package, _options = Hash.new) ⇒ Object
:nodoc:.
-
#has_local_modifications?(package, with_untracked_files = false) ⇒ Boolean
Returns true if the SVN working copy at package.importdir has local modifications.
-
#initialize(svnroot, options = {}) ⇒ SVN
constructor
Creates an importer which gets the source for the Subversion URL
source
. - #relocate(root, options = Hash.new) ⇒ Object
-
#repository ⇒ Object
Alias for #svnroot.
-
#run_svn(package, *args, &block) ⇒ Object
Helper method to run a SVN command on a package’s working copy.
-
#source ⇒ String
deprecated
Deprecated.
use #svnroot instead
-
#status(package, only_local = false) ⇒ Package::Status
Returns status information for package.
-
#svn_info(package) ⇒ Array<String>
Returns the result of the ‘svn info’ command.
-
#svn_revision(package) ⇒ Integer
Returns the SVN revision of the package.
-
#svn_url(package) ⇒ String
Returns the URL of the remote SVN repository.
-
#update(package, options = Hash.new) ⇒ Object
:nodoc:.
- #validate_importdir(package) ⇒ Object
-
#vcs_fingerprint(package) ⇒ String
fingerprint method returns an unique hash to identify this package, for SVN the revision and URL will be used.
Methods inherited from Importer
#add_post_hook, add_post_hook, #apply, cache_dirs, #call_patch, #currently_applied_patches, default_cache_dirs, default_cache_dirs=, #each_post_hook, each_post_hook, #execute_post_hooks, #fallback, fallback, #fingerprint, #import, #interactive?, #parse_patch_list, #patch, #patchdir, #patches, #patches_fingerprint, #patchlist, #perform_checkout, #perform_update, #retry_count, #retry_count=, #save_patch_state, set_cache_dirs, #supports_relocation?, #unapply, unset_cache_dirs, #update_retry_count
Constructor Details
#initialize(svnroot, options = {}) ⇒ SVN
Creates an importer which gets the source for the Subversion URL source
. The following options are allowed:
- :svnup
-
options to give to ‘svn up’
- :svnco
-
options to give to ‘svn co’
This importer uses the ‘svn’ tool to perform the import. It defaults to ‘svn’ and can be configured by doing
Autobuild.programs['svn'] = 'my_svn_tool'
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/autobuild/import/svn.rb', line 11 def initialize(svnroot, = {}) svnroot = [*svnroot].join("/") svnopts, common = Kernel.( , :svnup => [], :svnco => [], :revision => nil, :repository_id => "svn:#{svnroot}" ) common[:repository_id] = svnopts.delete(:repository_id) relocate(svnroot, svnopts) super(common.merge(repository_id: svnopts[:repository_id])) end |
Instance Attribute Details
#revision ⇒ Object (readonly)
Returns the value of attribute revision.
42 43 44 |
# File 'lib/autobuild/import/svn.rb', line 42 def revision @revision end |
#svnroot ⇒ String (readonly)
Returns the SVN root
33 34 35 |
# File 'lib/autobuild/import/svn.rb', line 33 def svnroot @svnroot end |
Instance Method Details
#checkout(package, _options = Hash.new) ⇒ Object
:nodoc:
245 246 247 248 249 |
# File 'lib/autobuild/import/svn.rb', line 245 def checkout(package, = Hash.new) # :nodoc: run_svn(package, 'co', "--non-interactive", *@options_co, svnroot, package.importdir, working_directory: nil) end |
#has_local_modifications?(package, with_untracked_files = false) ⇒ Boolean
Returns true if the SVN working copy at package.importdir has local modifications
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/autobuild/import/svn.rb', line 110 def has_local_modifications?(package, with_untracked_files = false) status = run_svn(package, 'status', '--xml') not_modified = %w[external ignored none normal] not_modified << "unversioned" unless with_untracked_files REXML::Document.new(status.join("")). elements.enum_for(:each, '//wc-status'). any? do |status_item| !not_modified.include?(status_item.attributes['item'].to_s) end end |
#relocate(root, options = Hash.new) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/autobuild/import/svn.rb', line 44 def relocate(root, = Hash.new) @svnroot = [*root].join("/") @options_up = [*[:svnup]] @options_co = [*[:svnco]] @revision = [:revision] if revision @options_co << '--revision' << revision # We do not add it to @options_up as the behaviour depends on # the parameters given to {update} and to the state of the # working copy end end |
#repository ⇒ Object
Alias for #svnroot
For consistency with the other importers
38 39 40 |
# File 'lib/autobuild/import/svn.rb', line 38 def repository svnroot end |
#run_svn(package, *args, &block) ⇒ Object
Helper method to run a SVN command on a package’s working copy
160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/autobuild/import/svn.rb', line 160 def run_svn(package, *args, &block) = if args.last.kind_of?(Hash) args.pop else Hash.new end , = Kernel.( , working_directory: package.importdir, retry: true ) = .merge() package.run(:import, Autobuild.tool(:svn), *args, , &block) end |
#source ⇒ String
use #svnroot instead
26 27 28 |
# File 'lib/autobuild/import/svn.rb', line 26 def source svnroot end |
#status(package, only_local = false) ⇒ Package::Status
Returns status information for package
Given that subversion is not a distributed VCS, the only status returned are either Importer::Status::UP_TO_DATE or Importer::Status::SIMPLE_UPDATE. Moreover, if the status is local-only, Package::Status#remote_commits will not be filled (querying the log requires accessing the SVN server)
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/autobuild/import/svn.rb', line 132 def status(package, only_local = false) status = Status.new status.uncommitted_code = has_local_modifications?(package) if only_local status.status = Status::UP_TO_DATE else log = run_svn(package, 'log', '-r', 'BASE:HEAD', '--xml', '.') log = REXML::Document.new(log.join("\n")) missing_revisions = log.elements.enum_for(:each, 'log/logentry'). map do |l| rev = l.attributes['revision'] date = l.elements['date'].first.to_s = l.elements['author'].first.to_s msg = l.elements['msg'].first.to_s.split("\n").first "#{rev} #{DateTime.parse(date)} #{} #{msg}" end status.remote_commits = missing_revisions[1..-1] status.status = if missing_revisions.empty? Status::UP_TO_DATE else Status::SIMPLE_UPDATE end end status end |
#svn_info(package) ⇒ Array<String>
Returns the result of the ‘svn info’ command
It automatically runs svn upgrade if needed
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/autobuild/import/svn.rb', line 191 def svn_info(package) old_lang = ENV['LC_ALL'] ENV['LC_ALL'] = 'C' begin svninfo = run_svn(package, 'info') rescue SubcommandFailed => e if e.output.find { |l| l =~ /svn upgrade/ } # Try svn upgrade and info again run_svn(package, 'upgrade', retry: false) svninfo = run_svn(package, 'info') else raise end end unless svninfo.grep(/is not a working copy/).empty? raise ConfigException.new(package, 'import'), "#{package.importdir} does not appear to be a "\ "Subversion working copy" end svninfo ensure ENV['LC_ALL'] = old_lang end |
#svn_revision(package) ⇒ Integer
Returns the SVN revision of the package
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/autobuild/import/svn.rb', line 63 def svn_revision(package) svninfo = svn_info(package) revision = svninfo.grep(/^Revision: /).first unless revision raise ConfigException.new(package, 'import'), "cannot get SVN information for #{package.importdir}" end revision =~ /Revision: (\d+)/ Integer($1) end |
#svn_url(package) ⇒ String
Returns the URL of the remote SVN repository
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/autobuild/import/svn.rb', line 91 def svn_url(package) svninfo = svn_info(package) url = svninfo.grep(/^URL: /).first unless url raise ConfigException.new(package, 'import'), "cannot get SVN information for #{package.importdir}" end url.chomp =~ /URL: (.+)/ $1 end |
#update(package, options = Hash.new) ⇒ Object
:nodoc:
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/autobuild/import/svn.rb', line 216 def update(package, = Hash.new) # :nodoc: if [:only_local] package.warn "%s: the svn importer does not support local updates, "\ "skipping" return false end url = svn_url(package) if url != svnroot raise ConfigException.new(package, 'import'), "current checkout "\ "found at #{package.importdir} is from #{url}, "\ "was expecting #{svnroot}" end = @options_up.dup if revision if [:reset] || svn_revision(package) < revision << '--revision' << revision elsif revision # Don't update if the current revision is greater-or-equal # than the target revision return false end end run_svn(package, 'up', "--non-interactive", *) true end |
#validate_importdir(package) ⇒ Object
175 176 177 178 179 |
# File 'lib/autobuild/import/svn.rb', line 175 def validate_importdir(package) # This upgrades the local SVN filesystem if needed and checks that # it actually is a SVN repository in the first place svn_info(package) end |
#vcs_fingerprint(package) ⇒ String
fingerprint method returns an unique hash to identify this package, for SVN the revision and URL will be used
79 80 81 82 83 |
# File 'lib/autobuild/import/svn.rb', line 79 def vcs_fingerprint(package) Digest::SHA1.hexdigest( svn_info(package).grep(/^(URL|Revision):/).sort.join("\n") ) end |