##// END OF EJS Templates
scm: update locales of whether reporting last commit for files and directories in project setting (#8365, #7047)....
scm: update locales of whether reporting last commit for files and directories in project setting (#8365, #7047). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5774 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r5648:d21b35d32a73
r5654:625b7d905181
Show More
git.rb
173 lines | 5.4 KiB | text/x-ruby | RubyLexer
Toshi MARUYAMA
scm: git: code clean up model....
r5630 # Redmine - project management software
# Copyright (C) 2006-2011 Jean-Philippe Lang
Jean-Philippe Lang
Merged Git support branch (r1200 to r1226)....
r1222 # Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com
Toshi MARUYAMA
scm: git: code clean up model....
r5630 #
Jean-Philippe Lang
Merged Git support branch (r1200 to r1226)....
r1222 # 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: git: code clean up model....
r5630 #
Jean-Philippe Lang
Merged Git support branch (r1200 to r1226)....
r1222 # 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: git: code clean up model....
r5630 #
Jean-Philippe Lang
Merged Git support branch (r1200 to r1226)....
r1222 # 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.
require 'redmine/scm/adapters/git_adapter'
class Repository::Git < Repository
attr_protected :root_url
validates_presence_of :url
Toshi MARUYAMA
scm: add scm specific human_attribute_name for input validation....
r4855 def self.human_attribute_name(attribute_key_name)
Toshi MARUYAMA
scm: use i18n string at 'Path to repository' setting in Mercurial, Git, Bazaar and Darcs....
r5409 attr_name = attribute_key_name
if attr_name == "url"
attr_name = "path_to_repository"
end
super(attr_name)
Toshi MARUYAMA
scm: add scm specific human_attribute_name for input validation....
r4855 end
Toshi MARUYAMA
scm: add scm command and version methods at repository models (#4273)....
r4702 def self.scm_adapter_class
Jean-Philippe Lang
Merged Git support branch (r1200 to r1226)....
r1222 Redmine::Scm::Adapters::GitAdapter
end
Toshi MARUYAMA
scm: add scm command and version methods at repository models (#4273)....
r4702
Jean-Philippe Lang
Merged Git support branch (r1200 to r1226)....
r1222 def self.scm_name
'Git'
end
Toshi MARUYAMA
scm: git: change model report_last_commit() name to extra_report_last_commit() (#7047)....
r5541 def extra_report_last_commit
Toshi MARUYAMA
scm: git: get "extra_report_last_commit" value from extra_info (#8365, #7047)....
r5648 return false if extra_info.nil?
v = extra_info["extra_report_last_commit"]
return false if v.nil?
v.to_s != '0'
Toshi MARUYAMA
scm: git: add the model method whether reporting last commit in repository tree (#7047)....
r5536 end
Toshi MARUYAMA
scm: set supporting directory revisions or not at scm level....
r5024 def supports_directory_revisions?
true
end
Toshi MARUYAMA
scm: git: use --encoding=UTF-8 in "git log" (#3396)....
r4844 def repo_log_encoding
'UTF-8'
end
Toshi MARUYAMA
Changing revision label and identifier at SCM adapter level (#3724, #6092)...
r4493 # Returns the identifier for the given git changeset
def self.changeset_identifier(changeset)
changeset.scmid
end
# Returns the readable identifier for the given git changeset
def self.format_changeset_identifier(changeset)
changeset.revision[0, 8]
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
Toshi MARUYAMA
scm: git: implement find_changeset_by_name (#7047)....
r4731 def find_changeset_by_name(name)
return nil if name.nil? || name.empty?
e = changesets.find(:first, :conditions => ['revision = ?', name.to_s])
return e if e
changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"])
end
Toshi MARUYAMA
scm: git: override entries() in model for browsing tree performance (#7047)....
r5535 def entries(path=nil, identifier=nil)
Toshi MARUYAMA
scm: git: use the model value of whether reporting last commit in repository tree (#7047)....
r5537 scm.entries(path,
identifier,
Toshi MARUYAMA
scm: git: change model report_last_commit() name to extra_report_last_commit() (#7047)....
r5541 options = {:report_last_commit => extra_report_last_commit})
Toshi MARUYAMA
scm: git: override entries() in model for browsing tree performance (#7047)....
r5535 end
Toshi MARUYAMA
scm: git: add comments of revision order in fetch_changesets()....
r5524 # In Git and Mercurial, revisions are not in date order.
# Mercurial fixed issues.
# * Redmine Takes Too Long On Large Mercurial Repository
# http://www.redmine.org/issues/3449
Toshi MARUYAMA
scm: git: code clean up model....
r5630 # * Sorting for changesets might go wrong on Mercurial repos
Toshi MARUYAMA
scm: git: add comments of revision order in fetch_changesets()....
r5524 # http://www.redmine.org/issues/3567
# Database revision column is text, so Redmine can not sort by revision.
# Mercurial has revision number, and revision number guarantees revision order.
# Mercurial adapter uses "hg log -r 0:tip --limit 10"
# to get limited revisions from old to new.
# And Mercurial model stored revisions ordered by database id in database.
# So, Mercurial can use correct order revisions.
#
# But, Git 1.7.3.4 does not support --reverse with -n or --skip.
#
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735 # With SCM's that have a sequential commit numbering, redmine is able to be
# clever and only fetch changesets going forward from the most recent one
Toshi MARUYAMA
scm: git: rearrange fetch_changesets() comment....
r5523 # it knows about.
# However, with git, you never know if people have merged
Jean-Philippe Lang
Do not parse the entire git log to fetch new commits (takes several minutes for a few thousands commits), but only 1 week before the last known commit (#4547, #4716)....
r3280 # commits into the middle of the repository history, so we should parse
Toshi MARUYAMA
scm: git: rearrange fetch_changesets() comment....
r5523 # the entire log.
#
# Since it's way too slow for large repositories,
# we only parse 1 week before the last known commit.
#
Jean-Philippe Lang
Do not parse the entire git log to fetch new commits (takes several minutes for a few thousands commits), but only 1 week before the last known commit (#4547, #4716)....
r3280 # The repository can still be fully reloaded by calling #clear_changesets
# before fetching changesets (eg. for offline resync)
Jean-Philippe Lang
Merged Git support branch (r1200 to r1226)....
r1222 def fetch_changesets
Jean-Philippe Lang
Do not parse the entire git log to fetch new commits (takes several minutes for a few thousands commits), but only 1 week before the last known commit (#4547, #4716)....
r3280 c = changesets.find(:first, :order => 'committed_on DESC')
since = (c ? c.committed_on - 7.days : nil)
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735
Toshi MARUYAMA
scm: git: insert revisions to database with reverse commit order (#7821, #5357)....
r4953 revisions = scm.revisions('', nil, nil, {:all => true, :since => since, :reverse => true})
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735 return if revisions.nil? || revisions.empty?
Jean-Philippe Lang
Do not parse the entire git log to fetch new commits (takes several minutes for a few thousands commits), but only 1 week before the last known commit (#4547, #4716)....
r3280 recent_changesets = changesets.find(:all, :conditions => ['committed_on >= ?', since])
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735
# Clean out revisions that are no longer in git
Jean-Philippe Lang
Do not parse the entire git log to fetch new commits (takes several minutes for a few thousands commits), but only 1 week before the last known commit (#4547, #4716)....
r3280 recent_changesets.each {|c| c.destroy unless revisions.detect {|r| r.scmid.to_s == c.scmid.to_s }}
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735
# Subtract revisions that redmine already knows about
Jean-Philippe Lang
Do not parse the entire git log to fetch new commits (takes several minutes for a few thousands commits), but only 1 week before the last known commit (#4547, #4716)....
r3280 recent_revisions = recent_changesets.map{|c| c.scmid}
revisions.reject!{|r| recent_revisions.include?(r.scmid)}
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735
# Save the remaining ones to the database
Toshi MARUYAMA
scm: git: move saving changesets from adapter to model (#3396)....
r4839 unless revisions.nil?
revisions.each do |rev|
transaction do
Toshi MARUYAMA
scm: git: fix indent in model....
r5532 save_revision(rev)
Toshi MARUYAMA
scm: git: refactor saving a revision in model....
r5504 end
end
end
end
def save_revision(rev)
changeset = Changeset.new(
:repository => self,
:revision => rev.identifier,
:scmid => rev.scmid,
Toshi MARUYAMA
scm: git: code clean up model....
r5630 :committer => rev.author,
Toshi MARUYAMA
scm: git: move saving changesets from adapter to model (#3396)....
r4839 :committed_on => rev.time,
Toshi MARUYAMA
scm: git: refactor saving a revision in model....
r5504 :comments => rev.message
)
if changeset.save
rev.paths.each do |file|
Change.create(
Toshi MARUYAMA
scm: git: move saving changesets from adapter to model (#3396)....
r4839 :changeset => changeset,
:action => file[:action],
:path => file[:path])
end
end
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735 end
Toshi MARUYAMA
scm: git: refactor saving a revision in model....
r5504 private :save_revision
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735
def latest_changesets(path,rev,limit=10)
revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false)
return [] if revisions.nil? || revisions.empty?
Jean-Philippe Lang
Merged Git support branch (r1200 to r1226)....
r1222
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735 changesets.find(
Toshi MARUYAMA
scm: git: code clean up model....
r5630 :all,
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735 :conditions => [
Toshi MARUYAMA
scm: git: code clean up model....
r5630 "scmid IN (?)",
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735 revisions.map!{|c| c.scmid}
],
:order => 'committed_on DESC'
)
Jean-Philippe Lang
Merged Git support branch (r1200 to r1226)....
r1222 end
end