To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / models / repository / bazaar.rb @ 1298:4f746d8966dd

History | View | Annotate | Download (4.4 KB)

1 441:cbce1fd3b1b7 Chris
# Redmine - project management software
2 1295:622f24f53b42 Chris
# Copyright (C) 2006-2013  Jean-Philippe Lang
3 0:513646585e45 Chris
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8 441:cbce1fd3b1b7 Chris
#
9 0:513646585e45 Chris
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13 441:cbce1fd3b1b7 Chris
#
14 0:513646585e45 Chris
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18 1136:51d7f3e06556 chris
require_dependency 'redmine/scm/adapters/bazaar_adapter'
19 0:513646585e45 Chris
20
class Repository::Bazaar < Repository
21
  attr_protected :root_url
22 245:051f544170fe Chris
  validates_presence_of :url, :log_encoding
23 0:513646585e45 Chris
24 1115:433d4f72a19b Chris
  def self.human_attribute_name(attribute_key_name, *args)
25
    attr_name = attribute_key_name.to_s
26 441:cbce1fd3b1b7 Chris
    if attr_name == "url"
27
      attr_name = "path_to_repository"
28
    end
29 1115:433d4f72a19b Chris
    super(attr_name, *args)
30 245:051f544170fe Chris
  end
31
32
  def self.scm_adapter_class
33 0:513646585e45 Chris
    Redmine::Scm::Adapters::BazaarAdapter
34
  end
35 245:051f544170fe Chris
36 0:513646585e45 Chris
  def self.scm_name
37
    'Bazaar'
38
  end
39 245:051f544170fe Chris
40 1115:433d4f72a19b Chris
  def entry(path=nil, identifier=nil)
41
    scm.bzr_path_encodig = log_encoding
42
    scm.entry(path, identifier)
43
  end
44
45
  def cat(path, identifier=nil)
46
    scm.bzr_path_encodig = log_encoding
47
    scm.cat(path, identifier)
48
  end
49
50
  def annotate(path, identifier=nil)
51
    scm.bzr_path_encodig = log_encoding
52
    scm.annotate(path, identifier)
53
  end
54
55
  def diff(path, rev, rev_to)
56
    scm.bzr_path_encodig = log_encoding
57
    scm.diff(path, rev, rev_to)
58
  end
59
60 0:513646585e45 Chris
  def entries(path=nil, identifier=nil)
61 1115:433d4f72a19b Chris
    scm.bzr_path_encodig = log_encoding
62 0:513646585e45 Chris
    entries = scm.entries(path, identifier)
63
    if entries
64
      entries.each do |e|
65
        next if e.lastrev.revision.blank?
66
        # Set the filesize unless browsing a specific revision
67
        if identifier.nil? && e.is_file?
68
          full_path = File.join(root_url, e.path)
69
          e.size = File.stat(full_path).size if File.file?(full_path)
70
        end
71 441:cbce1fd3b1b7 Chris
        c = Change.find(
72
               :first,
73
               :include    => :changeset,
74
               :conditions => [
75
                   "#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?",
76
                   e.lastrev.revision,
77
                   id
78
                   ],
79
               :order => "#{Changeset.table_name}.revision DESC")
80 0:513646585e45 Chris
        if c
81
          e.lastrev.identifier = c.changeset.revision
82 441:cbce1fd3b1b7 Chris
          e.lastrev.name       = c.changeset.revision
83
          e.lastrev.author     = c.changeset.committer
84 0:513646585e45 Chris
        end
85
      end
86
    end
87 1115:433d4f72a19b Chris
    load_entries_changesets(entries)
88
    entries
89 0:513646585e45 Chris
  end
90 441:cbce1fd3b1b7 Chris
91 0:513646585e45 Chris
  def fetch_changesets
92 1115:433d4f72a19b Chris
    scm.bzr_path_encodig = log_encoding
93 0:513646585e45 Chris
    scm_info = scm.info
94
    if scm_info
95
      # latest revision found in database
96
      db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
97
      # latest revision in the repository
98
      scm_revision = scm_info.lastrev.identifier.to_i
99
      if db_revision < scm_revision
100
        logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
101
        identifier_from = db_revision + 1
102
        while (identifier_from <= scm_revision)
103
          # loads changesets by batches of 200
104
          identifier_to = [identifier_from + 199, scm_revision].min
105 1115:433d4f72a19b Chris
          revisions = scm.revisions('', identifier_to, identifier_from)
106 0:513646585e45 Chris
          transaction do
107
            revisions.reverse_each do |revision|
108 441:cbce1fd3b1b7 Chris
              changeset = Changeset.create(:repository   => self,
109
                                           :revision     => revision.identifier,
110
                                           :committer    => revision.author,
111 0:513646585e45 Chris
                                           :committed_on => revision.time,
112 441:cbce1fd3b1b7 Chris
                                           :scmid        => revision.scmid,
113
                                           :comments     => revision.message)
114
115 0:513646585e45 Chris
              revision.paths.each do |change|
116
                Change.create(:changeset => changeset,
117 441:cbce1fd3b1b7 Chris
                              :action    => change[:action],
118
                              :path      => change[:path],
119
                              :revision  => change[:revision])
120 0:513646585e45 Chris
              end
121
            end
122
          end unless revisions.nil?
123
          identifier_from = identifier_to + 1
124
        end
125
      end
126
    end
127
  end
128
end