Class: Repository

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

Overview

redMine - project management software Copyright (C) 2006-2007 Jean-Philippe Lang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Direct Known Subclasses

Repository::Bazaar, Repository::Cvs, Repository::Darcs, Repository::Filesystem, Repository::Git, Repository::Mercurial, Repository::Subversion

Defined Under Namespace

Classes: Bazaar, Cvs, Darcs, Filesystem, Git, Mercurial, Subversion

Class Method Summary

Instance Method Summary

Methods inherited from ActiveRecord::Base

quoted_table_name

Class Method Details

+ (Object) available_scm



189
190
191
# File 'app/models/repository.rb', line 189

def self.available_scm
  subclasses.collect {|klass| [klass.scm_name, klass.name]}
end

+ (Object) factory(klass_name, *args)



193
194
195
196
197
198
# File 'app/models/repository.rb', line 193

def self.factory(klass_name, *args)
  klass = "Repository::#{klass_name}".constantize
  klass.new(*args)
rescue
  nil
end

+ (Object) fetch_changesets

Fetches new changesets for all repositories of active projects Can be called periodically by an external script eg. ruby script/runner "Repository.fetch_changesets"



172
173
174
175
176
177
178
# File 'app/models/repository.rb', line 172

def self.fetch_changesets
  Project.active.has_module(:repository).find(:all, :include => :repository).each do |project|
    if project.repository
      project.repository.fetch_changesets
    end
  end
end

+ (Object) scan_changesets_for_issue_ids

scan changeset comments to find related and fixed issues for all repositories



181
182
183
# File 'app/models/repository.rb', line 181

def self.scan_changesets_for_issue_ids
  find(:all).each(&:scan_changesets_for_issue_ids)
end

+ (Object) scm_name



185
186
187
# File 'app/models/repository.rb', line 185

def self.scm_name
  'Abstract'
end

Instance Method Details

- (Object) branches



66
67
68
# File 'app/models/repository.rb', line 66

def branches
  scm.branches
end

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



82
83
84
# File 'app/models/repository.rb', line 82

def cat(path, identifier=nil)
  scm.cat(path, identifier)
end

- (Object) committer_ids=(h)

Maps committers username to a user ids



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'app/models/repository.rb', line 129

def committer_ids=(h)
  if h.is_a?(Hash)
    committers.each do |committer, user_id|
      new_user_id = h[committer]
      if new_user_id && (new_user_id.to_i != user_id.to_i)
        new_user_id = (new_user_id.to_i > 0 ? new_user_id.to_i : nil)
        Changeset.update_all("user_id = #{ new_user_id.nil? ? 'NULL' : new_user_id }", ["repository_id = ? AND committer = ?", id, committer])
      end
    end
    @committers = nil
    @found_committer_users = nil
    true
  else
    false
  end
end

- (Object) committers

Returns an array of committers usernames and associated user_id



124
125
126
# File 'app/models/repository.rb', line 124

def committers
  @committers ||= Changeset.connection.select_rows("SELECT DISTINCT committer, user_id FROM #{Changeset.table_name} WHERE repository_id = #{id}")
end

- (Object) default_branch



74
75
76
# File 'app/models/repository.rb', line 74

def default_branch
  scm.default_branch
end

- (Object) diff(path, rev, rev_to)



86
87
88
# File 'app/models/repository.rb', line 86

def diff(path, rev, rev_to)
  scm.diff(path, rev, rev_to)
end

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



62
63
64
# File 'app/models/repository.rb', line 62

def entries(path=nil, identifier=nil)
  scm.entries(path, identifier)
end

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



58
59
60
# File 'app/models/repository.rb', line 58

def entry(path=nil, identifier=nil)
  scm.entry(path, identifier)
end

- (Object) find_changeset_by_name(name)

Finds and returns a revision with a number or the beginning of a hash



96
97
98
# File 'app/models/repository.rb', line 96

def find_changeset_by_name(name)
  changesets.find(:first, :conditions => (name.match(/^\d*$/) ? ["revision = ?", name.to_s] : ["revision LIKE ?", name + '%']))
end

- (Object) find_committer_user(committer)

Returns the Redmine User corresponding to the given committer It will return nil if the committer is not yet mapped and if no User with the same username or email was found



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'app/models/repository.rb', line 149

def find_committer_user(committer)
  unless committer.blank?
    @found_committer_users ||= {}
    return @found_committer_users[committer] if @found_committer_users.has_key?(committer)
    
    user = nil
    c = changesets.find(:first, :conditions => {:committer => committer}, :include => :user)
    if c && c.user
      user = c.user
    elsif committer.strip =~ /^([^<]+)(<(.*)>)?$/
      username,  = $1.strip, $3
      u = User.(username)
      u ||= User.find_by_mail() unless .blank?
      user = u
    end
    @found_committer_users[committer] = user
    user
  end
end

- (Object) latest_changeset



100
101
102
# File 'app/models/repository.rb', line 100

def latest_changeset
  @latest_changeset ||= changesets.find(:first)
end

- (Object) latest_changesets(path, rev, limit = 10)

Returns the latest changesets for path Default behaviour is to search in cached changesets



106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/models/repository.rb', line 106

def latest_changesets(path, rev, limit=10)
  if path.blank?
    changesets.find(:all, :include => :user,
                          :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
                          :limit => limit)
  else
    changes.find(:all, :include => {:changeset => :user}, 
                       :conditions => ["path = ?", path.with_leading_slash],
                       :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
                       :limit => limit).collect(&:changeset)
  end
end

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



78
79
80
# File 'app/models/repository.rb', line 78

def properties(path, identifier=nil)
  scm.properties(path, identifier)
end

- (Object) relative_path(path)

Returns a path relative to the url of the repository



91
92
93
# File 'app/models/repository.rb', line 91

def relative_path(path)
  path
end

- (Object) root_url=(arg)

Removes leading and trailing whitespace



36
37
38
# File 'app/models/repository.rb', line 36

def root_url=(arg)
  write_attribute(:root_url, arg ? arg.to_s.strip : nil)
end

- (Object) scan_changesets_for_issue_ids



119
120
121
# File 'app/models/repository.rb', line 119

def scan_changesets_for_issue_ids
  self.changesets.each(&:scan_comment_for_issue_ids)
end

- (Object) scm



40
41
42
43
44
# File 'app/models/repository.rb', line 40

def scm
  @scm ||= self.scm_adapter.new url, root_url, , password
  update_attribute(:root_url, @scm.root_url) if root_url.blank?
  @scm
end

- (Object) scm_name



46
47
48
# File 'app/models/repository.rb', line 46

def scm_name
  self.class.scm_name
end

- (Boolean) supports_annotate?

Returns:

  • (Boolean)


54
55
56
# File 'app/models/repository.rb', line 54

def supports_annotate?
  scm.supports_annotate?
end

- (Boolean) supports_cat?

Returns:

  • (Boolean)


50
51
52
# File 'app/models/repository.rb', line 50

def supports_cat?
  scm.supports_cat?
end

- (Object) tags



70
71
72
# File 'app/models/repository.rb', line 70

def tags
  scm.tags
end

- (Object) url=(arg)

Removes leading and trailing whitespace



31
32
33
# File 'app/models/repository.rb', line 31

def url=(arg)
  write_attribute(:url, arg ? arg.to_s.strip : nil)
end