##// END OF EJS Templates
Introduce virtual MenuNodes (#15880)....
Introduce virtual MenuNodes (#15880). They are characterized by having a blank url. they will only be rendered if the user is authorized to see at least one of its children. they render as links which do nothing when clicked. Patch by Jan Schulz-Hofen. git-svn-id: http://svn.redmine.org/redmine/trunk@15501 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r14856:cda9c63d9c21
r15119:53710d80fc88
Show More
repository.rb
510 lines | 13.9 KiB | text/x-ruby | RubyLexer
Toshi MARUYAMA
scm: code clean up repository model....
r5533 # Redmine - project management software
Jean-Philippe Lang
Updates copyright for 2016....
r14856 # Copyright (C) 2006-2016 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.
Toshi MARUYAMA
scm: code clean up repository model....
r5533 #
Jean-Philippe Lang
svn browser merged in trunk...
r103 # 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.
Toshi MARUYAMA
scm: code clean up repository model....
r5533 #
Jean-Philippe Lang
svn browser merged in trunk...
r103 # 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.
Toshi MARUYAMA
scm: add exception of fetching revisions error in repository model (#5357, #2799, #4741, #8030)....
r5779 class ScmFetchError < Exception; end
Jean-Philippe Lang
svn browser merged in trunk...
r103 class Repository < ActiveRecord::Base
Jean-Philippe Lang
Adds support for SCM/LDAP passwords encryption in the database (#7411)....
r4830 include Redmine::Ciphering
Jean-Philippe Lang
Safe attributes for repositories....
r9693 include Redmine::SafeAttributes
Toshi MARUYAMA
remove trailing white-spaces from app/models/repository.rb...
r10664
Jean-Philippe Lang
Repository Identifier should be frozen (#11109)....
r9898 # Maximum length for repository identifiers
IDENTIFIER_MAX_LENGTH = 255
Toshi MARUYAMA
scm: code clean up repository model....
r5533
Jean-Philippe Lang
svn browser merged in trunk...
r103 belongs_to :project
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 has_many :changesets, lambda{order("#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC")}
Jean-Philippe Lang
Renamed #changes association to #filechanges (clash with AR::Base.changes that triggers errors with Rails 3.2.5)....
r9576 has_many :filechanges, :class_name => 'Change', :through => :changesets
Toshi MARUYAMA
scm: code clean up repository model....
r5533
Toshi MARUYAMA
scm: add "extra_info" column to repositories table and set serialize (#7146, #7047)....
r5642 serialize :extra_info
Jean-Philippe Lang
Fixed that 2 repositories can be created with blank/nil identifier (#19400)....
r13774 before_validation :normalize_identifier
Jean-Philippe Lang
Adds support for multiple repositories per project (#779)....
r8530 before_save :check_default
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
Toshi MARUYAMA
scm: code clean up repository model....
r5533
Jean-Philippe Lang
Adds support for SCM/LDAP passwords encryption in the database (#7411)....
r4830 validates_length_of :password, :maximum => 255, :allow_nil => true
Jean-Philippe Lang
Repository Identifier should be frozen (#11109)....
r9898 validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH, :allow_blank => true
Jean-Philippe Lang
Don't allow 2 repositories with blank identifier (#19400)....
r13760 validates_uniqueness_of :identifier, :scope => :project_id
Jean-Philippe Lang
Repository identifiers can be reserved words (#16564)....
r12852 validates_exclusion_of :identifier, :in => %w(browse show entry raw changes annotate diff statistics graph revisions revision)
Jean-Philippe Lang
Make repository identifier accept underscores (#11192)....
r9692 # donwcase letters, digits, dashes, underscores but not digits only
Jean-Philippe Lang
Use \A and \z in validation regexps....
r10733 validates_format_of :identifier, :with => /\A(?!\d+$)[a-z0-9\-_]*\z/, :allow_blank => true
Jean-Philippe Lang
Ability to disable unused SCM adapters in application settings....
r1493 # Checks if the SCM is enabled when creating a repository
Toshi MARUYAMA
Rails3: replace deprecated 'validate_on_create' to declared validation method at Repository model....
r6597 validate :repo_create_validation, :on => :create
Jean-Philippe Lang
Adds configuration settings to limit valid repository path (#1415)....
r13191 validate :validate_repository_path
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 attr_protected :id
Toshi MARUYAMA
Rails3: replace deprecated 'validate_on_create' to declared validation method at Repository model....
r6597
Jean-Philippe Lang
Safe attributes for repositories....
r9693 safe_attributes 'identifier',
'login',
'password',
'path_encoding',
'log_encoding',
'is_default'
Jean-Philippe Lang
Makes repository url read-only after saving....
r9695 safe_attributes 'url',
:if => lambda {|repository, user| repository.new_record?}
Toshi MARUYAMA
Rails3: replace deprecated 'validate_on_create' to declared validation method at Repository model....
r6597 def repo_create_validation
unless Setting.enabled_scm.include?(self.class.name.demodulize)
errors.add(:type, :invalid)
end
end
Toshi MARUYAMA
scm: update adapter initialize() to use path encoding (#2664, #2274)....
r4821
Jean-Philippe Lang
human_attribute_name accepts optional argument....
r8166 def self.human_attribute_name(attribute_key_name, *args)
Toshi MARUYAMA
Rails3: scm: use .to_s for overriding human_attribute_name parameter at repository model...
r8850 attr_name = attribute_key_name.to_s
Toshi MARUYAMA
scm: use i18n string at commit log encoding setting (#1735)....
r5399 if attr_name == "log_encoding"
attr_name = "commit_logs_encoding"
end
Jean-Philippe Lang
human_attribute_name accepts optional argument....
r8166 super(attr_name, *args)
Toshi MARUYAMA
scm: use i18n string at commit log encoding setting (#1735)....
r5399 end
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
Toshi MARUYAMA
scm: update adapter initialize() to use path encoding (#2664, #2274)....
r4821
Jean-Philippe Lang
Strip repository urls (closes #852)....
r1234 # Removes leading and trailing whitespace
def root_url=(arg)
write_attribute(:root_url, arg ? arg.to_s.strip : nil)
end
Toshi MARUYAMA
scm: code clean up repository model....
r5533
Jean-Philippe Lang
Adds support for SCM/LDAP passwords encryption in the database (#7411)....
r4830 def password
read_ciphered_attribute(:password)
end
Toshi MARUYAMA
scm: code clean up repository model....
r5533
Jean-Philippe Lang
Adds support for SCM/LDAP passwords encryption in the database (#7411)....
r4830 def password=(arg)
write_ciphered_attribute(:password, arg)
end
Jean-Philippe Lang
Strip repository urls (closes #852)....
r1234
Toshi MARUYAMA
scm: add scm command and version methods at repository models (#4273)....
r4702 def scm_adapter
self.class.scm_adapter_class
end
Jean-Philippe Lang
svn browser merged in trunk...
r103 def scm
Jean-Philippe Lang
Skip a bunch of useless "UPDATE repositories SET extra_info = ..." queries when navigating in repositories....
r8538 unless @scm
@scm = self.scm_adapter.new(url, root_url,
Toshi MARUYAMA
scm: update adapter initialize() to use path encoding (#2664, #2274)....
r4821 login, password, path_encoding)
Jean-Philippe Lang
Skip a bunch of useless "UPDATE repositories SET extra_info = ..." queries when navigating in repositories....
r8538 if root_url.blank? && @scm.root_url.present?
update_attribute(:root_url, @scm.root_url)
end
end
Jean-Philippe Lang
fixed problems when svn path doesn't point to the root directory of the repository....
r341 @scm
end
Toshi MARUYAMA
scm: update adapter initialize() to use path encoding (#2664, #2274)....
r4821
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
Toshi MARUYAMA
scm: add scm command and version methods at repository models (#4273)....
r4702
Jean-Philippe Lang
Adds support for multiple repositories per project (#779)....
r8530 def name
Jean-Philippe Lang
Display identifier for the default repository too (#779)....
r8534 if identifier.present?
Jean-Philippe Lang
Adds support for multiple repositories per project (#779)....
r8530 identifier
Jean-Philippe Lang
Display identifier for the default repository too (#779)....
r8534 elsif is_default?
l(:field_repository_is_default)
Jean-Philippe Lang
Adds support for multiple repositories per project (#779)....
r8530 else
scm_name
end
end
Jean-Philippe Lang
Repository Identifier should be frozen (#11109)....
r9898 def identifier=(identifier)
super unless identifier_frozen?
end
def identifier_frozen?
errors[:identifier].blank? && !(new_record? || identifier.blank?)
end
Jean-Philippe Lang
Adds support for multiple repositories per project (#779)....
r8530 def identifier_param
if is_default?
nil
elsif identifier.present?
identifier
else
id.to_s
end
end
def <=>(repository)
if is_default?
-1
elsif repository.is_default?
1
else
Jean-Philippe Lang
Fixed undefined method `<=>' for nil:NilClass when sorting repositories with nil identifiers (#10827)....
r9436 identifier.to_s <=> repository.identifier.to_s
Jean-Philippe Lang
Adds support for multiple repositories per project (#779)....
r8530 end
end
def self.find_by_identifier_param(param)
if param.to_s =~ /^\d+$/
find_by_id(param)
else
find_by_identifier(param)
end
end
Jean-Philippe Lang
Make sure that Repository#extra_info returns a Hash or nil (#16032)....
r12573 # TODO: should return an empty hash instead of nil to avoid many ||{}
def extra_info
h = read_attribute(:extra_info)
h.is_a?(Hash) ? h : nil
end
Toshi MARUYAMA
scm: add a repository model method "merge_extra_info()" to merge "extra_info" serializing hash yaml (#7146, #7047)....
r5646 def merge_extra_info(arg)
h = extra_info || {}
return h if arg.nil?
h.merge!(arg)
write_attribute(:extra_info, h)
end
Toshi MARUYAMA
scm: git: show only filename and filesize if setting of reporting last commit is disable (#8365, #7047)....
r5655 def report_last_commit
true
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
Toshi MARUYAMA
scm: set supporting all revisions or not at scm level....
r5023
def supports_all_revisions?
true
end
Toshi MARUYAMA
scm: code clean up repository model....
r5533
Toshi MARUYAMA
scm: set supporting directory revisions or not at scm level....
r5024 def supports_directory_revisions?
false
end
Toshi MARUYAMA
scm: code clean up repository model....
r5533
Toshi MARUYAMA
scm: model: add method to switch revision graph support or not and set default false (#5501)...
r7596 def supports_revision_graph?
false
end
Jean-Philippe Lang
Fixed: view file at given revision with CVS....
r1539 def entry(path=nil, identifier=nil)
scm.entry(path, identifier)
end
Toshi MARUYAMA
scm: code clean up repository model....
r5533
Toshi MARUYAMA
scm: split Repository#entries (#14361)...
r12479 def scm_entries(path=nil, identifier=nil)
scm.entries(path, identifier)
end
protected :scm_entries
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 def entries(path=nil, identifier=nil)
Toshi MARUYAMA
scm: split Repository#entries (#14361)...
r12479 entries = scm_entries(path, identifier)
Jean-Philippe Lang
Adds a method to load changesets for repository entries....
r9622 load_entries_changesets(entries)
entries
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
Toshi MARUYAMA
scm: return nil at model default_branch and override at git model (#8458, #6713)....
r6010 nil
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735 end
Toshi MARUYAMA
scm: set supporting all revisions or not at scm level....
r5023
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
Toshi MARUYAMA
scm: set supporting all revisions or not at scm level....
r5023
Jean-Philippe Lang
Fixed: view file at given revision with CVS....
r1539 def cat(path, identifier=nil)
scm.cat(path, identifier)
end
Toshi MARUYAMA
scm: set supporting all revisions or not at scm level....
r5023
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
Toshi MARUYAMA
scm: changing two revision diff text at SCM adapter level (#3724)....
r4578
def diff_format_revisions(cs, cs_to, sep=':')
text = ""
text << cs_to.format_identifier + sep if cs_to
text << cs.format_identifier if cs
text
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
Toshi MARUYAMA
scm: use #blank? instead of #nil? || #empty? at Repository#find_changeset_by_name(name) (#7307)....
r4592
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)
Toshi MARUYAMA
scm: use #blank? instead of #nil? || #empty? at Repository#find_changeset_by_name(name) (#7307)....
r4592 return nil if name.blank?
Toshi MARUYAMA
scm: use to_s for revision in find_changeset_by_name method...
r8811 s = name.to_s
Jean-Philippe Lang
Replaces find(:first) calls....
r10701 if s.match(/^\d*$/)
changesets.where("revision = ?", s).first
else
changesets.where("revision LIKE ?", s + '%').first
end
Jean-Philippe Lang
Fixed: RepositoriesController#revision may show wrong revision (#3779)....
r2784 end
Toshi MARUYAMA
scm: use #blank? instead of #nil? || #empty? at Repository#find_changeset_by_name(name) (#7307)....
r4592
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 def latest_changeset
Jean-Philippe Lang
Replaces find(:first) calls....
r10701 @latest_changeset ||= changesets.first
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 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?
Jean-Philippe Lang
Cleanup of finders with :conditions option....
r11733 changesets.
reorder("#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC").
limit(limit).
preload(:user).
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 to_a
Jean-Philippe Lang
SCM:...
r2739 else
Jean-Philippe Lang
Cleanup of finders with :conditions option....
r11733 filechanges.
where("path = ?", path.with_leading_slash).
reorder("#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC").
limit(limit).
preload(:changeset => :user).
collect(&:changeset)
Jean-Philippe Lang
SCM:...
r2739 end
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735 end
Toshi MARUYAMA
scm: code clean up repository model....
r5527
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
Jean-Philippe Lang
Code cleanup....
r13244 @committers ||= Changeset.where(:repository_id => id).uniq.pluck(:committer, :user_id)
Jean-Philippe Lang
Maps repository users to Redmine users (#1383)....
r2004 end
Toshi MARUYAMA
scm: code clean up repository model....
r5527
Jean-Philippe Lang
Maps repository users to Redmine users (#1383)....
r2004 # 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)
Toshi MARUYAMA
Rails4: replace deprecated Relation#update_all at Repository model...
r12271 Changeset.where(["repository_id = ? AND committer = ?", id, committer]).
update_all("user_id = #{new_user_id.nil? ? 'NULL' : new_user_id}")
Jean-Philippe Lang
Maps repository users to Redmine users (#1383)....
r2004 end
end
Toshi MARUYAMA
scm: code clean up repository model....
r5527 @committers = nil
Jean-Philippe Lang
Memorize commit authors to speed up changesets loading....
r3358 @found_committer_users = nil
Jean-Philippe Lang
Maps repository users to Redmine users (#1383)....
r2004 true
else
false
end
end
Toshi MARUYAMA
scm: code clean up repository model....
r5527
Jean-Philippe Lang
Maps repository users to Redmine users (#1383)....
r2004 # 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)
Jean-Philippe Lang
Memorize commit authors to speed up changesets loading....
r3358 unless committer.blank?
@found_committer_users ||= {}
return @found_committer_users[committer] if @found_committer_users.has_key?(committer)
Toshi MARUYAMA
scm: code clean up repository model....
r5527
Jean-Philippe Lang
Memorize commit authors to speed up changesets loading....
r3358 user = nil
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 c = changesets.where(:committer => committer).
includes(:user).references(:user).first
Jean-Philippe Lang
Maps repository users to Redmine users (#1383)....
r2004 if c && c.user
Jean-Philippe Lang
Memorize commit authors to speed up changesets loading....
r3358 user = c.user
Jean-Philippe Lang
Maps repository users to Redmine users (#1383)....
r2004 elsif committer.strip =~ /^([^<]+)(<(.*)>)?$/
username, email = $1.strip, $3
u = User.find_by_login(username)
u ||= User.find_by_mail(email) unless email.blank?
Jean-Philippe Lang
Memorize commit authors to speed up changesets loading....
r3358 user = u
Jean-Philippe Lang
Maps repository users to Redmine users (#1383)....
r2004 end
Jean-Philippe Lang
Memorize commit authors to speed up changesets loading....
r3358 @found_committer_users[committer] = user
user
Jean-Philippe Lang
Maps repository users to Redmine users (#1383)....
r2004 end
end
Toshi MARUYAMA
scm: catch exception of getting command and version in model (#4273)....
r4762
Toshi MARUYAMA
scm: ignore log encoding setting in Subversion and Mercurial (#7597)....
r4842 def repo_log_encoding
Toshi MARUYAMA
scm: add feature of per project repository log encoding setting (#1735)....
r4862 encoding = log_encoding.to_s.strip
Toshi MARUYAMA
scm: ignore log encoding setting in Subversion and Mercurial (#7597)....
r4842 encoding.blank? ? 'UTF-8' : encoding
end
Jean-Philippe Lang
Fixed: Repository.fetch_changesets tries to fetch changesets for archived projects (#4782)....
r3288 # Fetches new changesets for all repositories of active projects
# Can be called periodically by an external script
Jean-Philippe Lang
SVN commits are now stored in the database, and added to the activity view and the search engine....
r374 # eg. ruby script/runner "Repository.fetch_changesets"
def self.fetch_changesets
Jean-Philippe Lang
Adds support for multiple repositories per project (#779)....
r8530 Project.active.has_module(:repository).all.each do |project|
project.repositories.each do |repository|
Toshi MARUYAMA
scm: catch CommandFailed during bulk Repository.fetch_changesets (#4455)....
r4704 begin
Jean-Philippe Lang
Adds support for multiple repositories per project (#779)....
r8530 repository.fetch_changesets
Toshi MARUYAMA
scm: catch CommandFailed during bulk Repository.fetch_changesets (#4455)....
r4704 rescue Redmine::Scm::Adapters::CommandFailed => e
Toshi MARUYAMA
scm: catch exception of getting command and version in model (#4273)....
r4762 logger.error "scm: error during fetching changesets: #{e.message}"
Toshi MARUYAMA
scm: catch CommandFailed during bulk Repository.fetch_changesets (#4455)....
r4704 end
Jean-Philippe Lang
Fixed: Repository.fetch_changesets tries to fetch changesets for archived projects (#4782)....
r3288 end
end
Jean-Philippe Lang
svn browser merged in trunk...
r103 end
Toshi MARUYAMA
scm: catch exception of getting command and version in model (#4273)....
r4762
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
Jean-Philippe Lang
Replaces find(:all) calls....
r10690 all.each(&:scan_changesets_for_issue_ids)
Jean-Philippe Lang
Commit messages are now scanned for referenced or fixed issue IDs....
r470 end
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556
def self.scm_name
'Abstract'
end
Toshi MARUYAMA
scm: code clean up repository model....
r5533
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 def self.available_scm
subclasses.collect {|klass| [klass.scm_name, klass.name]}
end
Toshi MARUYAMA
scm: ignore log encoding setting in Subversion and Mercurial (#7597)....
r4842
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 def self.factory(klass_name, *args)
klass = "Repository::#{klass_name}".constantize
klass.new(*args)
rescue
nil
end
Toshi MARUYAMA
scm: add scm command and version methods at repository models (#4273)....
r4702
def self.scm_adapter_class
nil
end
def self.scm_command
Toshi MARUYAMA
scm: catch exception of getting command and version in model (#4273)....
r4762 ret = ""
begin
ret = self.scm_adapter_class.client_command if self.scm_adapter_class
Toshi MARUYAMA
scm: catch all exceptions to get scm command version in repository model (#8510)....
r5879 rescue Exception => e
Toshi MARUYAMA
scm: catch exception of getting command and version in model (#4273)....
r4762 logger.error "scm: error during get command: #{e.message}"
end
ret
Toshi MARUYAMA
scm: add scm command and version methods at repository models (#4273)....
r4702 end
def self.scm_version_string
Toshi MARUYAMA
scm: catch exception of getting command and version in model (#4273)....
r4762 ret = ""
begin
ret = self.scm_adapter_class.client_version_string if self.scm_adapter_class
Toshi MARUYAMA
scm: catch all exceptions to get scm command version in repository model (#8510)....
r5879 rescue Exception => e
Toshi MARUYAMA
scm: catch exception of getting command and version in model (#4273)....
r4762 logger.error "scm: error during get version string: #{e.message}"
end
ret
Toshi MARUYAMA
scm: add scm command and version methods at repository models (#4273)....
r4702 end
def self.scm_available
Toshi MARUYAMA
scm: catch exception of getting command and version in model (#4273)....
r4762 ret = false
begin
Toshi MARUYAMA
scm: code clean up repository model....
r5533 ret = self.scm_adapter_class.client_available if self.scm_adapter_class
Toshi MARUYAMA
scm: catch all exceptions to get scm command version in repository model (#8510)....
r5879 rescue Exception => e
Toshi MARUYAMA
scm: catch exception of getting command and version in model (#4273)....
r4762 logger.error "scm: error during get scm available: #{e.message}"
end
ret
Toshi MARUYAMA
scm: add scm command and version methods at repository models (#4273)....
r4702 end
Jean-Philippe Lang
Adds support for multiple repositories per project (#779)....
r8530 def set_as_default?
Jean-Philippe Lang
Cleanup of finders with :conditions option....
r11733 new_record? && project && Repository.where(:project_id => project.id).empty?
Jean-Philippe Lang
Adds support for multiple repositories per project (#779)....
r8530 end
Jean-Baptiste Barth
Move some RepositoriesController logic to Repository#stats_by_author (#13487)....
r12997 # Returns a hash with statistics by author in the following form:
# {
# "John Smith" => { :commits => 45, :changes => 324 },
# "Bob" => { ... }
# }
#
# Notes:
# - this hash honnors the users mapping defined for the repository
def stats_by_author
Jean-Baptiste Barth
Fix syntax for ruby 1.8.7 (#13487)....
r13008 commits = Changeset.where("repository_id = ?", id).select("committer, user_id, count(*) as count").group("committer, user_id")
Jean-Baptiste Barth
Optimize committers/users map retrieval for statistic graphs (#13487)....
r13007
#TODO: restore ordering ; this line probably never worked
#commits.to_a.sort! {|x, y| x.last <=> y.last}
Jean-Baptiste Barth
Fix syntax for ruby 1.8.7 (#13487)....
r13008 changes = Change.joins(:changeset).where("#{Changeset.table_name}.repository_id = ?", id).select("committer, user_id, count(*) as count").group("committer, user_id")
Jean-Baptiste Barth
Optimize committers/users map retrieval for statistic graphs (#13487)....
r13007
user_ids = changesets.map(&:user_id).compact.uniq
authors_names = User.where(:id => user_ids).inject({}) do |memo, user|
memo[user.id] = user.to_s
memo
end
Jean-Baptiste Barth
Move some RepositoriesController logic to Repository#stats_by_author (#13487)....
r12997
Jean-Baptiste Barth
Optimize committers/users map retrieval for statistic graphs (#13487)....
r13007 (commits + changes).inject({}) do |hash, element|
mapped_name = element.committer
if username = authors_names[element.user_id.to_i]
mapped_name = username
end
Jean-Baptiste Barth
Honnor committers/users mapping in repository statistics (#13487)....
r12999 hash[mapped_name] ||= { :commits_count => 0, :changes_count => 0 }
Jean-Baptiste Barth
Optimize committers/users map retrieval for statistic graphs (#13487)....
r13007 if element.is_a?(Changeset)
hash[mapped_name][:commits_count] += element.count.to_i
else
hash[mapped_name][:changes_count] += element.count.to_i
end
Jean-Baptiste Barth
Move some RepositoriesController logic to Repository#stats_by_author (#13487)....
r12997 hash
end
end
Jean-Philippe Lang
Don't link multiple changesets from the same commit multiple times (#17931)....
r13063 # Returns a scope of changesets that come from the same commit as the given changeset
# in different repositories that point to the same backend
def same_commits_in_scope(scope, changeset)
scope = scope.joins(:repository).where(:repositories => {:url => url, :root_url => root_url, :type => type})
if changeset.scmid.present?
scope = scope.where(:scmid => changeset.scmid)
else
scope = scope.where(:revision => changeset.revision)
end
scope
end
Jean-Philippe Lang
Adds support for multiple repositories per project (#779)....
r8530 protected
Jean-Philippe Lang
Adds configuration settings to limit valid repository path (#1415)....
r13191 # Validates repository url based against an optional regular expression
# that can be set in the Redmine configuration file.
def validate_repository_path(attribute=:url)
regexp = Redmine::Configuration["scm_#{scm_name.to_s.downcase}_path_regexp"]
if changes[attribute] && regexp.present?
regexp = regexp.to_s.strip.gsub('%project%') {Regexp.escape(project.try(:identifier).to_s)}
unless send(attribute).to_s.match(Regexp.new("\\A#{regexp}\\z"))
errors.add(attribute, :invalid)
end
end
end
Jean-Philippe Lang
Fixed that 2 repositories can be created with blank/nil identifier (#19400)....
r13774 def normalize_identifier
self.identifier = identifier.to_s.strip
end
Jean-Philippe Lang
Adds support for multiple repositories per project (#779)....
r8530 def check_default
if !is_default? && set_as_default?
self.is_default = true
end
if is_default? && is_default_changed?
Toshi MARUYAMA
Rails4: replace deprecated Relation#update_all at Repository model...
r12218 Repository.where(["project_id = ?", project_id]).update_all(["is_default = ?", false])
Jean-Philippe Lang
Adds support for multiple repositories per project (#779)....
r8530 end
end
Jean-Philippe Lang
Adds a method to load changesets for repository entries....
r9622 def load_entries_changesets(entries)
if entries
entries.each do |entry|
if entry.lastrev && entry.lastrev.identifier
entry.changeset = find_changeset_by_name(entry.lastrev.identifier)
end
end
end
end
Jean-Philippe Lang
Strip repository urls (closes #852)....
r1234 private
Toshi MARUYAMA
scm: update adapter initialize() to use path encoding (#2664, #2274)....
r4821
Jean-Philippe Lang
Fixed that changesets parents associations are not deleted when deleting a repository....
r8727 # Deletes repository data
Jean-Philippe Lang
Clear changesets and changes with raw sql when deleting a repository (#1627)....
r1651 def clear_changesets
Toshi MARUYAMA
remove trailing white-spaces from app/models/repository.rb...
r10664 cs = Changeset.table_name
Jean-Philippe Lang
Fixed that changesets parents associations are not deleted when deleting a repository....
r8727 ch = Change.table_name
ci = "#{table_name_prefix}changesets_issues#{table_name_suffix}"
cp = "#{table_name_prefix}changeset_parents#{table_name_suffix}"
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 self.class.connection.delete("DELETE FROM #{ch} WHERE #{ch}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
self.class.connection.delete("DELETE FROM #{ci} WHERE #{ci}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
self.class.connection.delete("DELETE FROM #{cp} WHERE #{cp}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
self.class.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