class OhlohScm::Bzr::Activity
Public Instance Methods
Source
# File lib/ohloh_scm/bzr/activity.rb, line 93 def cat_file(commit, diff) cat(commit.token, diff.path) end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 97 def cat_file_parent(commit, diff) first_parent_token = parent_tokens(commit).first cat(first_parent_token, diff.path) if first_parent_token end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 102 def cleanup bzr_client.shutdown end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 60 def commit_count(opts = {}) commit_tokens(opts).size end
Return the number of commits in the repository following after
.
Source
# File lib/ohloh_scm/bzr/activity.rb, line 55 def commit_tokens(opts = {}) commits(opts).map(&:token) end
Return the list of commit tokens following after
.
Source
# File lib/ohloh_scm/bzr/activity.rb, line 42 def commits(opts = {}) after = opts[:after] log = run("#{rev_list_command(opts)} | cat") a = OhlohScm::BzrXmlParser.parse(log) if after && (i = a.index { |commit| commit.token == after }) a[(i + 1)..-1] else a end end
Returns a list of shallow commits (i.e., the diffs are not populated). Not including the diffs is meant to be a memory savings when we encounter massive repositories. If you need all commits including diffs, you should use the each_commit
() iterator, which only holds one commit in memory at a time.
Source
# File lib/ohloh_scm/bzr/activity.rb, line 64 def each_commit(opts = {}) after = opts[:after] skip_commits = !after.nil? # Don't emit any commits until the 'after' resume point passes safe_open_log_file(opts) do |io| OhlohScm::BzrXmlParser.parse(io) do |commit| yield remove_directories(commit) if block_given? && !skip_commits skip_commits = false if commit.token == after end end end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 28 def export(dest_dir, token = head_token) # Unlike other SCMs, Bzr doesn't simply place the contents into dest_dir. # It actually *creates* dest_dir. Since it should already exist at this point, # first we have to delete it. Dir.delete(dest_dir) if File.exist?(dest_dir) run "cd '#{url}' && bzr export --format=dir -r #{to_rev_param(token)} '#{dest_dir}'" end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 24 def export_tag(dest_dir, tag_name) run "cd '#{url}' && bzr export -r #{tag_name} #{dest_dir}" end
rubocop:enable Metrics/MethodLength
Source
# File lib/ohloh_scm/bzr/activity.rb, line 81 def head verbose_commit(head_token) end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 76 def head_token run("bzr log --limit 1 --show-id #{url} 2> /dev/null"\ " | grep ^revision-id | cut -f2 -d' '").strip end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 85 def parent_tokens(commit) bzr_client.parent_tokens(commit.token) end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 89 def parents(commit) parent_tokens(commit).collect { |token| verbose_commit(token) } end
Private Instance Methods
Source
# File lib/ohloh_scm/bzr/activity.rb, line 178 def bzr_client @bzr_client ||= setup_bzr_client end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 160 def cat(revision, path) bzr_client.cat_file(revision, path) end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 166 def escape(path) path.gsub(/[:]/) { |c| '\\' + c }.gsub("'", "''") end
Bzr
doesn’t like it when the filename includes a colon Also, fix the case where the filename includes a single quote
Source
# File lib/ohloh_scm/bzr/activity.rb, line 145 def open_log_file(opts = {}) cmd = "#{rev_list_command(opts)} -v > #{log_filename}" run cmd File.open(log_filename, 'r') { |io| yield io } ensure File.delete(log_filename) if File.exist?(log_filename) end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 155 def remove_directories(commit) commit.diffs.delete_if { |d| d.path[-1..-1] == '/' } commit end
Ohloh tracks only files, not directories. This function removes directories from the commit diffs.
Source
# File lib/ohloh_scm/bzr/activity.rb, line 128 def rev_list_command(opts = {}) after = opts[:after] trunk_only = opts[:trunk_only] ? '--levels=1' : '--include-merges' "cd '#{url}' && bzr xmllog --show-id --forward #{trunk_only} -r #{to_rev_param(after)}.." end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 139 def safe_open_log_file(opts = {}) return '' if opts[:after] && opts[:after] == head_token open_log_file(opts) { |io| yield io } end
Returns a file handle to the log. In our standard, the log should include everything AFTER after
. However, bzr doesn’t work that way; it returns everything after and INCLUDING after
. Therefore, consumers of this file should check for and reject the duplicate commit.
Source
# File lib/ohloh_scm/bzr/activity.rb, line 182 def setup_bzr_client bzr_client = PyBridge::BzrClient.new(url) bzr_client.start bzr_client end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 170 def tag_strings run("cd '#{url}' && bzr tags").split(/\n/) end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 174 def time_string(rev) run("cd '#{url}' && bzr log -r #{rev} | grep 'timestamp:' | sed 's/timestamp://'") end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 115 def to_rev_param(rev = nil) case rev when nil 1 when Integer rev.to_s when /^\d+$/ rev else "'revid:#{rev}'" end end
Source
# File lib/ohloh_scm/bzr/activity.rb, line 109 def verbose_commit(token) cmd = "cd '#{url}' && bzr xmllog --show-id -v --limit 1 -c #{to_rev_param(token)}" log = run(cmd) OhlohScm::BzrXmlParser.parse(log).first end
Returns a single commit, including its diffs