1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 # Copyright (C) 2007 Patrick Aljord patcito@Ĺ‹mail.com
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 require 'redmine/scm/adapters/git_adapter'
20 class Repository::Git < Repository
21 attr_protected :root_url
22 validates_presence_of :url
25 Redmine::Scm::Adapters::GitAdapter
40 # With SCM's that have a sequential commit numbering, redmine is able to be
41 # clever and only fetch changesets going forward from the most recent one
42 # it knows about. However, with git, you never know if people have merged
43 # commits into the middle of the repository history, so we always have to
44 # parse the entire log.
46 # Save ourselves an expensive operation if we're already up to date
47 return if scm.num_revisions == changesets.count
49 revisions = scm.revisions('', nil, nil, :all => true)
50 return if revisions.nil? || revisions.empty?
52 # Find revisions that redmine knows about already
53 existing_revisions = changesets.find(:all).map!{|c| c.scmid}
55 # Clean out revisions that are no longer in git
56 Changeset.delete_all(["scmid NOT IN (?) AND repository_id = (?)", revisions.map{|r| r.scmid}, self.id])
58 # Subtract revisions that redmine already knows about
59 revisions.reject!{|r| existing_revisions.include?(r.scmid)}
61 # Save the remaining ones to the database
62 revisions.each{|r| r.save(self)} unless revisions.nil?
65 def latest_changesets(path,rev,limit=10)
66 revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false)
67 return [] if revisions.nil? || revisions.empty?
73 revisions.map!{|c| c.scmid}
75 :order => 'committed_on DESC'