Class: Repository::Bazaar

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

Class Method Summary

Instance Method Summary

Methods inherited from

available_scm, #branches, #cat, #committer_ids=, #committers, #default_branch, #diff, #entry, factory, fetch_changesets, #find_changeset_by_name, #find_committer_user, #latest_changeset, #latest_changesets, #properties, #relative_path, #root_url=, #scan_changesets_for_issue_ids, scan_changesets_for_issue_ids, #scm, #scm_name, #supports_annotate?, #supports_cat?, #tags, #url=

Methods inherited from ActiveRecord::Base

quoted_table_name

Class Method Details

+ (Object) scm_name



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

def self.scm_name
  'Bazaar'
end

Instance Method Details

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



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/repository/bazaar.rb', line 32

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



55
56
57
58
59
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
# File 'app/models/repository/bazaar.rb', line 55

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

- (Object) scm_adapter



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

def scm_adapter
  Redmine::Scm::Adapters::BazaarAdapter
end