##// END OF EJS Templates
Adds workflow copy functionality (#1727)....
Adds workflow copy functionality (#1727). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3154 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r2789:4e811bebd1eb
r3040:5c6ce51ec9f1
Show More
repository.rb
204 lines | 6.2 KiB | text/x-ruby | RubyLexer
Jean-Philippe Lang
svn browser merged in trunk...
r103 # redMine - project management software
Jean-Philippe Lang
SVN commits are now stored in the database, and added to the activity view and the search engine....
r374 # Copyright (C) 2006-2007 Jean-Philippe Lang
Jean-Philippe Lang
svn browser merged in trunk...
r103 #
# 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.
class Repository < ActiveRecord::Base
belongs_to :project
Jean-Philippe Lang
Clear changesets and changes with raw sql when deleting a repository (#1627)....
r1651 has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377 has_many :changes, :through => :changesets
Jean-Philippe Lang
Ability to disable unused SCM adapters in application settings....
r1493
Jean-Philippe Lang
Clear changesets and changes with raw sql when deleting a repository (#1627)....
r1651 # Raw SQL to delete changesets and changes in the database
# has_many :changesets, :dependent => :destroy is too slow for big repositories
before_destroy :clear_changesets
Jean-Philippe Lang
Ability to disable unused SCM adapters in application settings....
r1493 # Checks if the SCM is enabled when creating a repository
Jean-Philippe Lang
Merged Rails 2.2 branch. Redmine now requires Rails 2.2.2....
r2430 validate_on_create { |r| r.errors.add(:type, :invalid) unless Setting.enabled_scm.include?(r.class.name.demodulize) }
Jean-Philippe Lang
Ability to disable unused SCM adapters in application settings....
r1493
Jean-Philippe Lang
Strip repository urls (closes #852)....
r1234 # Removes leading and trailing whitespace
def url=(arg)
write_attribute(:url, arg ? arg.to_s.strip : nil)
end
# Removes leading and trailing whitespace
def root_url=(arg)
write_attribute(:root_url, arg ? arg.to_s.strip : nil)
end
Jean-Philippe Lang
svn browser merged in trunk...
r103 def scm
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 @scm ||= self.scm_adapter.new url, root_url, login, password
Jean-Philippe Lang
fixed problems when svn path doesn't point to the root directory of the repository....
r341 update_attribute(:root_url, @scm.root_url) if root_url.blank?
@scm
end
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 def scm_name
self.class.scm_name
Jean-Philippe Lang
SVN commits are now stored in the database, and added to the activity view and the search engine....
r374 end
Jean-Philippe Lang
Added Darcs basic support....
r570 def supports_cat?
scm.supports_cat?
end
Jean-Philippe Lang
Added Annotate/Blame view for Subversion, CVS and Mercurial repositories....
r934
def supports_annotate?
scm.supports_annotate?
end
Jean-Philippe Lang
Added Darcs basic support....
r570
Jean-Philippe Lang
Fixed: view file at given revision with CVS....
r1539 def entry(path=nil, identifier=nil)
scm.entry(path, identifier)
end
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 def entries(path=nil, identifier=nil)
scm.entries(path, identifier)
Jean-Philippe Lang
added pagination on revisions list...
r378 end
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735
def branches
scm.branches
end
def tags
scm.tags
end
def default_branch
scm.default_branch
end
Jean-Philippe Lang
added pagination on revisions list...
r378
Jean-Philippe Lang
Display svn properties in the browser, svn >= 1.5.0 only (#1581)....
r1613 def properties(path, identifier=nil)
scm.properties(path, identifier)
end
Jean-Philippe Lang
Fixed: view file at given revision with CVS....
r1539 def cat(path, identifier=nil)
scm.cat(path, identifier)
end
Jean-Philippe Lang
Move unified diff parser out of the scm abstract adapter so it can be reused for viewing attached diffs (#1403)....
r1499 def diff(path, rev, rev_to)
scm.diff(path, rev, rev_to)
Jean-Philippe Lang
SVN commits are now stored in the database, and added to the activity view and the search engine....
r374 end
Jean-Philippe Lang
Fixed: View differences for individual file of a changeset fails if the subversion repository URL doesn't point to the repository root (#1209, #1262, #1275)....
r1432 # Returns a path relative to the url of the repository
def relative_path(path)
path
end
Jean-Philippe Lang
Fixed: RepositoriesController#revision may show wrong revision (#3779)....
r2784 # Finds and returns a revision with a number or the beginning of a hash
def find_changeset_by_name(name)
Jean-Philippe Lang
Fixes Repository#find_changeset_by_name with PostgreSQL (#3937)....
r2789 changesets.find(:first, :conditions => (name.match(/^\d*$/) ? ["revision = ?", name.to_s] : ["revision LIKE ?", name + '%']))
Jean-Philippe Lang
Fixed: RepositoriesController#revision may show wrong revision (#3779)....
r2784 end
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 def latest_changeset
@latest_changeset ||= changesets.find(:first)
end
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735
Jean-Philippe Lang
SCM:...
r2739 # Returns the latest changesets for +path+
# Default behaviour is to search in cached changesets
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
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735 end
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556
Jean-Philippe Lang
Commit messages are now scanned for referenced or fixed issue IDs....
r470 def scan_changesets_for_issue_ids
self.changesets.each(&:scan_comment_for_issue_ids)
end
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735
Jean-Philippe Lang
Maps repository users to Redmine users (#1383)....
r2004 # Returns an array of committers usernames and associated user_id
def committers
@committers ||= Changeset.connection.select_rows("SELECT DISTINCT committer, user_id FROM #{Changeset.table_name} WHERE repository_id = #{id}")
end
# Maps committers username to a user ids
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
true
else
false
end
end
# 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
def find_committer_user(committer)
if committer
c = changesets.find(:first, :conditions => {:committer => committer}, :include => :user)
if c && c.user
c.user
elsif committer.strip =~ /^([^<]+)(<(.*)>)?$/
username, email = $1.strip, $3
u = User.find_by_login(username)
u ||= User.find_by_mail(email) unless email.blank?
u
end
end
end
Jean-Philippe Lang
SVN commits are now stored in the database, and added to the activity view and the search engine....
r374 # fetch new changesets for all repositories
# can be called periodically by an external script
# eg. ruby script/runner "Repository.fetch_changesets"
def self.fetch_changesets
find(:all).each(&:fetch_changesets)
Jean-Philippe Lang
svn browser merged in trunk...
r103 end
Jean-Philippe Lang
Commit messages are now scanned for referenced or fixed issue IDs....
r470
# scan changeset comments to find related and fixed issues for all repositories
def self.scan_changesets_for_issue_ids
find(:all).each(&:scan_changesets_for_issue_ids)
end
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556
def self.scm_name
'Abstract'
end
def self.available_scm
subclasses.collect {|klass| [klass.scm_name, klass.name]}
end
def self.factory(klass_name, *args)
klass = "Repository::#{klass_name}".constantize
klass.new(*args)
rescue
nil
end
Jean-Philippe Lang
Strip repository urls (closes #852)....
r1234
private
def before_save
# Strips url and root_url
url.strip!
root_url.strip!
true
end
Jean-Philippe Lang
Clear changesets and changes with raw sql when deleting a repository (#1627)....
r1651
def clear_changesets
Jean-Philippe Lang
Removes hardcoded table names in Repository#clear_changesets....
r2619 cs, ch, ci = Changeset.table_name, Change.table_name, "#{table_name_prefix}changesets_issues#{table_name_suffix}"
connection.delete("DELETE FROM #{ch} WHERE #{ch}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
connection.delete("DELETE FROM #{ci} WHERE #{ci}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
connection.delete("DELETE FROM #{cs} WHERE #{cs}.repository_id = #{id}")
Jean-Philippe Lang
Clear changesets and changes with raw sql when deleting a repository (#1627)....
r1651 end
Jean-Philippe Lang
svn browser merged in trunk...
r103 end