Class: Repository::Bazaar

Inherits:
Repository
  • Object
show all
Defined in:
app/models/repository/bazaar.rb

Constant Summary

ATTRIBUTE_KEY_NAMES =
{
  "url"          => "Root directory",
  "log_encoding" => "Commit messages encoding",
}

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Repository

available_scm, #branches, #cat, #committer_ids=, #committers, #default_branch, #diff, #diff_format_revisions, #entry, factory, fetch_changesets, #find_changeset_by_name, #find_committer_user, #latest_changeset, #latest_changesets, #log_encoding, #password, #password=, #properties, #relative_path, #repo_log_encoding, #root_url=, scan_changesets_for_issue_ids, #scan_changesets_for_issue_ids, #scm, #scm_adapter, scm_available, scm_command, #scm_name, scm_version_string, #supports_all_revisions?, #supports_annotate?, #supports_cat?, #supports_directory_revisions?, #tags, #url=

Methods included from Redmine::Ciphering

cipher_key, decrypt_text, encrypt_text, included

Class Method Details

+ (Object) human_attribute_name(attribute_key_name)



25
26
27
# File 'app/models/repository/bazaar.rb', line 25

def self.human_attribute_name(attribute_key_name)
  ATTRIBUTE_KEY_NAMES[attribute_key_name] || super
end

+ (Object) scm_adapter_class



29
30
31
# File 'app/models/repository/bazaar.rb', line 29

def self.scm_adapter_class
  Redmine::Scm::Adapters::BazaarAdapter
end

+ (Object) scm_name



33
34
35
# File 'app/models/repository/bazaar.rb', line 33

def self.scm_name
  'Bazaar'
end

Instance Method Details

- (Object) entries(path = nil, identifier = nil)



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/repository/bazaar.rb', line 37

def entries(path=nil, identifier=nil)
  entries = scm.entries(path, identifier)
  if entries
    entries.each do |e|
      next if e.lastrev.revision.blank?
      # Set the filesize unless browsing a specific revision
      if identifier.nil? && e.is_file?
        full_path = File.join(root_url, e.path)
        e.size = File.stat(full_path).size if File.file?(full_path)
      end
      c = Change.find(:first,
                      :include => :changeset,
                      :conditions => ["#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?", e.lastrev.revision, id],
                      :order => "#{Changeset.table_name}.revision DESC")
      if c
        e.lastrev.identifier = c.changeset.revision
        e.lastrev.name = c.changeset.revision
        e.lastrev.author = c.changeset.committer
      end
    end
  end
end

- (Object) fetch_changesets



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/models/repository/bazaar.rb', line 60

def fetch_changesets
  scm_info = scm.info
  if scm_info
    # latest revision found in database
    db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
    # latest revision in the repository
    scm_revision = scm_info.lastrev.identifier.to_i
    if db_revision < scm_revision
      logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
      identifier_from = db_revision + 1
      while (identifier_from <= scm_revision)
        # loads changesets by batches of 200
        identifier_to = [identifier_from + 199, scm_revision].min
        revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
        transaction do
          revisions.reverse_each do |revision|
            changeset = Changeset.create(:repository => self,
                                         :revision => revision.identifier,
                                         :committer => revision.author,
                                         :committed_on => revision.time,
                                         :scmid => revision.scmid,
                                         :comments => revision.message)

            revision.paths.each do |change|
              Change.create(:changeset => changeset,
                            :action => change[:action],
                            :path => change[:path],
                            :revision => change[:revision])
            end
          end
        end unless revisions.nil?
        identifier_from = identifier_to + 1
      end
    end
  end
end