annotate .svn/pristine/55/550aea64d9d567b8fd19eb6154f19d0a52250270.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 # Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com
Chris@909 4 #
Chris@909 5 # This program is free software; you can redistribute it and/or
Chris@909 6 # modify it under the terms of the GNU General Public License
Chris@909 7 # as published by the Free Software Foundation; either version 2
Chris@909 8 # of the License, or (at your option) any later version.
Chris@909 9 #
Chris@909 10 # This program is distributed in the hope that it will be useful,
Chris@909 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 13 # GNU General Public License for more details.
Chris@909 14 #
Chris@909 15 # You should have received a copy of the GNU General Public License
Chris@909 16 # along with this program; if not, write to the Free Software
Chris@909 17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 18
Chris@909 19 require 'redmine/scm/adapters/git_adapter'
Chris@909 20
Chris@909 21 class Repository::Git < Repository
Chris@909 22 attr_protected :root_url
Chris@909 23 validates_presence_of :url
Chris@909 24
Chris@909 25 def self.human_attribute_name(attribute_key_name)
Chris@909 26 attr_name = attribute_key_name
Chris@909 27 if attr_name == "url"
Chris@909 28 attr_name = "path_to_repository"
Chris@909 29 end
Chris@909 30 super(attr_name)
Chris@909 31 end
Chris@909 32
Chris@909 33 def self.scm_adapter_class
Chris@909 34 Redmine::Scm::Adapters::GitAdapter
Chris@909 35 end
Chris@909 36
Chris@909 37 def self.scm_name
Chris@909 38 'Git'
Chris@909 39 end
Chris@909 40
Chris@909 41 def report_last_commit
Chris@909 42 extra_report_last_commit
Chris@909 43 end
Chris@909 44
Chris@909 45 def extra_report_last_commit
Chris@909 46 return false if extra_info.nil?
Chris@909 47 v = extra_info["extra_report_last_commit"]
Chris@909 48 return false if v.nil?
Chris@909 49 v.to_s != '0'
Chris@909 50 end
Chris@909 51
Chris@909 52 def supports_directory_revisions?
Chris@909 53 true
Chris@909 54 end
Chris@909 55
Chris@909 56 def supports_revision_graph?
Chris@909 57 true
Chris@909 58 end
Chris@909 59
Chris@909 60 def repo_log_encoding
Chris@909 61 'UTF-8'
Chris@909 62 end
Chris@909 63
Chris@909 64 # Returns the identifier for the given git changeset
Chris@909 65 def self.changeset_identifier(changeset)
Chris@909 66 changeset.scmid
Chris@909 67 end
Chris@909 68
Chris@909 69 # Returns the readable identifier for the given git changeset
Chris@909 70 def self.format_changeset_identifier(changeset)
Chris@909 71 changeset.revision[0, 8]
Chris@909 72 end
Chris@909 73
Chris@909 74 def branches
Chris@909 75 scm.branches
Chris@909 76 end
Chris@909 77
Chris@909 78 def tags
Chris@909 79 scm.tags
Chris@909 80 end
Chris@909 81
Chris@909 82 def default_branch
Chris@909 83 scm.default_branch
Chris@909 84 rescue Exception => e
Chris@909 85 logger.error "git: error during get default branch: #{e.message}"
Chris@909 86 nil
Chris@909 87 end
Chris@909 88
Chris@909 89 def find_changeset_by_name(name)
Chris@909 90 return nil if name.nil? || name.empty?
Chris@909 91 e = changesets.find(:first, :conditions => ['revision = ?', name.to_s])
Chris@909 92 return e if e
Chris@909 93 changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"])
Chris@909 94 end
Chris@909 95
Chris@909 96 def entries(path=nil, identifier=nil)
Chris@909 97 scm.entries(path,
Chris@909 98 identifier,
Chris@909 99 options = {:report_last_commit => extra_report_last_commit})
Chris@909 100 end
Chris@909 101
Chris@909 102 # With SCMs that have a sequential commit numbering,
Chris@909 103 # such as Subversion and Mercurial,
Chris@909 104 # Redmine is able to be clever and only fetch changesets
Chris@909 105 # going forward from the most recent one it knows about.
Chris@909 106 #
Chris@909 107 # However, Git does not have a sequential commit numbering.
Chris@909 108 #
Chris@909 109 # In order to fetch only new adding revisions,
Chris@909 110 # Redmine needs to parse revisions per branch.
Chris@909 111 # Branch "last_scmid" is for this requirement.
Chris@909 112 #
Chris@909 113 # In Git and Mercurial, revisions are not in date order.
Chris@909 114 # Redmine Mercurial fixed issues.
Chris@909 115 # * Redmine Takes Too Long On Large Mercurial Repository
Chris@909 116 # http://www.redmine.org/issues/3449
Chris@909 117 # * Sorting for changesets might go wrong on Mercurial repos
Chris@909 118 # http://www.redmine.org/issues/3567
Chris@909 119 #
Chris@909 120 # Database revision column is text, so Redmine can not sort by revision.
Chris@909 121 # Mercurial has revision number, and revision number guarantees revision order.
Chris@909 122 # Redmine Mercurial model stored revisions ordered by database id to database.
Chris@909 123 # So, Redmine Mercurial model can use correct ordering revisions.
Chris@909 124 #
Chris@909 125 # Redmine Mercurial adapter uses "hg log -r 0:tip --limit 10"
Chris@909 126 # to get limited revisions from old to new.
Chris@909 127 # But, Git 1.7.3.4 does not support --reverse with -n or --skip.
Chris@909 128 #
Chris@909 129 # The repository can still be fully reloaded by calling #clear_changesets
Chris@909 130 # before fetching changesets (eg. for offline resync)
Chris@909 131 def fetch_changesets
Chris@909 132 scm_brs = branches
Chris@909 133 return if scm_brs.nil? || scm_brs.empty?
Chris@909 134 h1 = extra_info || {}
Chris@909 135 h = h1.dup
Chris@909 136 h["branches"] ||= {}
Chris@909 137 h["db_consistent"] ||= {}
Chris@909 138 if changesets.count == 0
Chris@909 139 h["db_consistent"]["ordering"] = 1
Chris@909 140 merge_extra_info(h)
Chris@909 141 self.save
Chris@909 142 elsif ! h["db_consistent"].has_key?("ordering")
Chris@909 143 h["db_consistent"]["ordering"] = 0
Chris@909 144 merge_extra_info(h)
Chris@909 145 self.save
Chris@909 146 end
Chris@909 147 scm_brs.each do |br1|
Chris@909 148 br = br1.to_s
Chris@909 149 from_scmid = nil
Chris@909 150 from_scmid = h["branches"][br]["last_scmid"] if h["branches"][br]
Chris@909 151 h["branches"][br] ||= {}
Chris@909 152 scm.revisions('', from_scmid, br, {:reverse => true}) do |rev|
Chris@909 153 db_rev = find_changeset_by_name(rev.revision)
Chris@909 154 transaction do
Chris@909 155 if db_rev.nil?
Chris@909 156 db_saved_rev = save_revision(rev)
Chris@909 157 parents = {}
Chris@909 158 parents[db_saved_rev] = rev.parents unless rev.parents.nil?
Chris@909 159 parents.each do |ch, chparents|
Chris@909 160 ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact
Chris@909 161 end
Chris@909 162 end
Chris@909 163 h["branches"][br]["last_scmid"] = rev.scmid
Chris@909 164 merge_extra_info(h)
Chris@909 165 self.save
Chris@909 166 end
Chris@909 167 end
Chris@909 168 end
Chris@909 169 end
Chris@909 170
Chris@909 171 def save_revision(rev)
Chris@909 172 changeset = Changeset.new(
Chris@909 173 :repository => self,
Chris@909 174 :revision => rev.identifier,
Chris@909 175 :scmid => rev.scmid,
Chris@909 176 :committer => rev.author,
Chris@909 177 :committed_on => rev.time,
Chris@909 178 :comments => rev.message
Chris@909 179 )
Chris@909 180 if changeset.save
Chris@909 181 rev.paths.each do |file|
Chris@909 182 Change.create(
Chris@909 183 :changeset => changeset,
Chris@909 184 :action => file[:action],
Chris@909 185 :path => file[:path])
Chris@909 186 end
Chris@909 187 end
Chris@909 188 changeset
Chris@909 189 end
Chris@909 190 private :save_revision
Chris@909 191
Chris@909 192 def latest_changesets(path,rev,limit=10)
Chris@909 193 revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false)
Chris@909 194 return [] if revisions.nil? || revisions.empty?
Chris@909 195
Chris@909 196 changesets.find(
Chris@909 197 :all,
Chris@909 198 :conditions => [
Chris@909 199 "scmid IN (?)",
Chris@909 200 revisions.map!{|c| c.scmid}
Chris@909 201 ],
Chris@909 202 :order => 'committed_on DESC'
Chris@909 203 )
Chris@909 204 end
Chris@909 205 end