lib/autoproj/autobuild.rb in autoproj-2.0.0.b6 vs lib/autoproj/autobuild.rb in autoproj-2.0.0.b7
- old
+ new
@@ -536,38 +536,121 @@
def user_config(key)
Autoproj.config.get(key)
end
class Autobuild::Git
- # get version information from the importer
- def snapshot(package, target_dir = nil)
+ # Get version information
+ #
+ # @option options [Boolean] local (true) whether the snapshot should access
+ # the remote repository to determine if the local commit is there, and
+ # determine what would be the best remote branch, or stick to information
+ # that is present locally
+ # @option options [Boolean] exact_state (true) whether the snapshot should
+ # point to a specific commit (either with a tag or with a commit ID), or
+ # only override the branch
+ # @return [Hash] the snapshot information, in a format that can be used by
+ # {#relocate}
+ def snapshot(package, target_dir = nil, options = Hash.new)
+ options = Kernel.validate_options options,
+ local: true,
+ exact_state: true
+
+ if options[:local]
+ snapshot_local(package, exact_state: options[:exact_state])
+ else
+ snapshot_against_remote(package, exact_state: options[:exact_state])
+ end
+ end
+
+ def normalize_branch_name(name)
+ if name =~ /^refs\/heads\//
+ return name
+ else
+ "refs/heads/#{name}"
+ end
+ end
+
+ # Returns true if the given snapshot information is different from the
+ # configured importer state
+ #
+ # It tests only against the parameters returned by {#snapshot}
+ def snapshot_overrides?(snapshot)
+ # We have to normalize the branch and tag names
+ if snapshot_local = (snapshot['local_branch'] || snapshot['branch'])
+ snapshot_local = normalize_branch_name(snapshot_local)
+ local_branch = normalize_branch_name(self.local_branch)
+ return true if snapshot_local != local_branch
+ end
+ if snapshot_remote = (snapshot['remote_branch'] || snapshot['branch'])
+ snapshot_remote = normalize_branch_name(snapshot_remote)
+ remote_branch = normalize_branch_name(self.remote_branch)
+ return true if snapshot_remote != remote_branch
+ end
+ if snapshot_id = snapshot['commit']
+ return true if self.commit != snapshot_id
+ end
+ false
+ end
+
+ # @api private
+ def snapshot_against_remote(package, options = Hash.new)
+ info = Hash['tag' => nil, 'commit' => nil]
+ remote_revname = describe_commit_on_remote(package, 'HEAD', tags: options[:exact_state])
+
+ case remote_revname
+ when /^refs\/heads\/(.*)/
+ remote_branch = $1
+ if local_branch == remote_branch
+ info['branch'] = local_branch
+ else
+ info['local_branch'] = local_branch
+ info['remote_branch'] = remote_branch
+ end
+ when /^refs\/tags\/(.*)/
+ info['tag'] = $1
+ else
+ info['local_branch'] = local_branch
+ info['remote_branch'] = remote_revname
+ end
+
+ if options[:exact_state] && !info['tag']
+ info['commit'] = rev_parse(package, 'HEAD')
+ end
+ info
+ end
+
+ # @api private
+ def snapshot_local(package, options = Hash.new)
info = Hash.new
if local_branch != remote_branch
info['local_branch'] = local_branch
info['remote_branch'] = remote_branch
else
info['branch'] = branch
end
-
- begin
- tag = run_git_bare(package, 'describe', '--tags', '--exact-match', 'HEAD').first.strip
- info.merge('tag' => tag.encode('UTF-8'), 'commit' => nil)
- rescue Autobuild::SubcommandFailed
- head_commit = rev_parse(package, 'HEAD')
- info.merge('tag' => nil, 'commit' => head_commit.encode('UTF-8'))
+
+ if options[:exact_state]
+ has_tag, described = describe_rev(package, 'HEAD')
+ if has_tag
+ info.merge('tag' => described, 'commit' => nil)
+ else
+ info.merge('tag' => nil, 'commit' => described)
+ end
+ else
+ info
end
end
end
class Autobuild::SVN
- def snapshot(package, target_dir = nil)
+ def snapshot(package, target_dir = nil, options = Hash.new)
version = svn_revision(package)
Hash['revision' => version]
end
end
class Autobuild::ArchiveImporter
- def snapshot(package, target_dir = nil)
+ def snapshot(package, target_dir = nil, options = Hash.new)
result = Hash[
'mode' => mode,
'no_subdirectory' => !has_subdirectory?,
'archive_dir' => archive_dir || tardir]