Mercurial > hg > soundsoftware-site
comparison app/models/repository/git.rb @ 0:513646585e45
* Import Redmine trunk SVN rev 3859
| author | Chris Cannam |
|---|---|
| date | Fri, 23 Jul 2010 15:52:44 +0100 |
| parents | |
| children | 7c48bad7d85d af80e5618e9b |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:513646585e45 |
|---|---|
| 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. | |
| 8 # | |
| 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. | |
| 13 # | |
| 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. | |
| 17 | |
| 18 require 'redmine/scm/adapters/git_adapter' | |
| 19 | |
| 20 class Repository::Git < Repository | |
| 21 attr_protected :root_url | |
| 22 validates_presence_of :url | |
| 23 | |
| 24 def scm_adapter | |
| 25 Redmine::Scm::Adapters::GitAdapter | |
| 26 end | |
| 27 | |
| 28 def self.scm_name | |
| 29 'Git' | |
| 30 end | |
| 31 | |
| 32 def branches | |
| 33 scm.branches | |
| 34 end | |
| 35 | |
| 36 def tags | |
| 37 scm.tags | |
| 38 end | |
| 39 | |
| 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 should parse | |
| 44 # the entire log. Since it's way too slow for large repositories, we only | |
| 45 # parse 1 week before the last known commit. | |
| 46 # The repository can still be fully reloaded by calling #clear_changesets | |
| 47 # before fetching changesets (eg. for offline resync) | |
| 48 def fetch_changesets | |
| 49 c = changesets.find(:first, :order => 'committed_on DESC') | |
| 50 since = (c ? c.committed_on - 7.days : nil) | |
| 51 | |
| 52 revisions = scm.revisions('', nil, nil, :all => true, :since => since) | |
| 53 return if revisions.nil? || revisions.empty? | |
| 54 | |
| 55 recent_changesets = changesets.find(:all, :conditions => ['committed_on >= ?', since]) | |
| 56 | |
| 57 # Clean out revisions that are no longer in git | |
| 58 recent_changesets.each {|c| c.destroy unless revisions.detect {|r| r.scmid.to_s == c.scmid.to_s }} | |
| 59 | |
| 60 # Subtract revisions that redmine already knows about | |
| 61 recent_revisions = recent_changesets.map{|c| c.scmid} | |
| 62 revisions.reject!{|r| recent_revisions.include?(r.scmid)} | |
| 63 | |
| 64 # Save the remaining ones to the database | |
| 65 revisions.each{|r| r.save(self)} unless revisions.nil? | |
| 66 end | |
| 67 | |
| 68 def latest_changesets(path,rev,limit=10) | |
| 69 revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false) | |
| 70 return [] if revisions.nil? || revisions.empty? | |
| 71 | |
| 72 changesets.find( | |
| 73 :all, | |
| 74 :conditions => [ | |
| 75 "scmid IN (?)", | |
| 76 revisions.map!{|c| c.scmid} | |
| 77 ], | |
| 78 :order => 'committed_on DESC' | |
| 79 ) | |
| 80 end | |
| 81 end |
