Chris@0
|
1 # redMine - project management software
|
Chris@0
|
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
|
Chris@0
|
3 # Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@0
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@0
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@0
|
18 require 'redmine/scm/adapters/git_adapter'
|
Chris@0
|
19
|
Chris@0
|
20 class Repository::Git < Repository
|
Chris@0
|
21 attr_protected :root_url
|
Chris@0
|
22 validates_presence_of :url
|
Chris@0
|
23
|
Chris@0
|
24 def scm_adapter
|
Chris@0
|
25 Redmine::Scm::Adapters::GitAdapter
|
Chris@0
|
26 end
|
Chris@0
|
27
|
Chris@0
|
28 def self.scm_name
|
Chris@0
|
29 'Git'
|
Chris@0
|
30 end
|
Chris@0
|
31
|
Chris@117
|
32 # Returns the identifier for the given git changeset
|
Chris@117
|
33 def self.changeset_identifier(changeset)
|
Chris@117
|
34 changeset.scmid
|
Chris@117
|
35 end
|
Chris@117
|
36
|
Chris@117
|
37 # Returns the readable identifier for the given git changeset
|
Chris@117
|
38 def self.format_changeset_identifier(changeset)
|
Chris@117
|
39 changeset.revision[0, 8]
|
Chris@117
|
40 end
|
Chris@117
|
41
|
Chris@0
|
42 def branches
|
Chris@0
|
43 scm.branches
|
Chris@0
|
44 end
|
Chris@0
|
45
|
Chris@0
|
46 def tags
|
Chris@0
|
47 scm.tags
|
Chris@0
|
48 end
|
Chris@0
|
49
|
Chris@0
|
50 # With SCM's that have a sequential commit numbering, redmine is able to be
|
Chris@0
|
51 # clever and only fetch changesets going forward from the most recent one
|
Chris@0
|
52 # it knows about. However, with git, you never know if people have merged
|
Chris@0
|
53 # commits into the middle of the repository history, so we should parse
|
Chris@0
|
54 # the entire log. Since it's way too slow for large repositories, we only
|
Chris@0
|
55 # parse 1 week before the last known commit.
|
Chris@0
|
56 # The repository can still be fully reloaded by calling #clear_changesets
|
Chris@0
|
57 # before fetching changesets (eg. for offline resync)
|
Chris@0
|
58 def fetch_changesets
|
Chris@0
|
59 c = changesets.find(:first, :order => 'committed_on DESC')
|
Chris@0
|
60 since = (c ? c.committed_on - 7.days : nil)
|
Chris@0
|
61
|
Chris@0
|
62 revisions = scm.revisions('', nil, nil, :all => true, :since => since)
|
Chris@0
|
63 return if revisions.nil? || revisions.empty?
|
Chris@0
|
64
|
Chris@0
|
65 recent_changesets = changesets.find(:all, :conditions => ['committed_on >= ?', since])
|
Chris@0
|
66
|
Chris@0
|
67 # Clean out revisions that are no longer in git
|
Chris@0
|
68 recent_changesets.each {|c| c.destroy unless revisions.detect {|r| r.scmid.to_s == c.scmid.to_s }}
|
Chris@0
|
69
|
Chris@0
|
70 # Subtract revisions that redmine already knows about
|
Chris@0
|
71 recent_revisions = recent_changesets.map{|c| c.scmid}
|
Chris@0
|
72 revisions.reject!{|r| recent_revisions.include?(r.scmid)}
|
Chris@0
|
73
|
Chris@0
|
74 # Save the remaining ones to the database
|
Chris@0
|
75 revisions.each{|r| r.save(self)} unless revisions.nil?
|
Chris@0
|
76 end
|
Chris@0
|
77
|
Chris@0
|
78 def latest_changesets(path,rev,limit=10)
|
Chris@0
|
79 revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false)
|
Chris@0
|
80 return [] if revisions.nil? || revisions.empty?
|
Chris@0
|
81
|
Chris@0
|
82 changesets.find(
|
Chris@0
|
83 :all,
|
Chris@0
|
84 :conditions => [
|
Chris@0
|
85 "scmid IN (?)",
|
Chris@0
|
86 revisions.map!{|c| c.scmid}
|
Chris@0
|
87 ],
|
Chris@0
|
88 :order => 'committed_on DESC'
|
Chris@0
|
89 )
|
Chris@0
|
90 end
|
Chris@0
|
91 end
|