##// END OF EJS Templates
scm: git: change model report_last_commit() name to extra_report_last_commit() (#7047)....
Toshi MARUYAMA -
r5541:773b2486699b
parent child
Show More
@@ -1,169 +1,169
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 # Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require 'redmine/scm/adapters/git_adapter'
19 19
20 20 class Repository::Git < Repository
21 21 attr_protected :root_url
22 22 validates_presence_of :url
23 23
24 24 def self.human_attribute_name(attribute_key_name)
25 25 attr_name = attribute_key_name
26 26 if attr_name == "url"
27 27 attr_name = "path_to_repository"
28 28 end
29 29 super(attr_name)
30 30 end
31 31
32 32 def self.scm_adapter_class
33 33 Redmine::Scm::Adapters::GitAdapter
34 34 end
35 35
36 36 def self.scm_name
37 37 'Git'
38 38 end
39 39
40 def report_last_commit
40 def extra_report_last_commit
41 41 true
42 42 end
43 43
44 44 def supports_directory_revisions?
45 45 true
46 46 end
47 47
48 48 def repo_log_encoding
49 49 'UTF-8'
50 50 end
51 51
52 52 # Returns the identifier for the given git changeset
53 53 def self.changeset_identifier(changeset)
54 54 changeset.scmid
55 55 end
56 56
57 57 # Returns the readable identifier for the given git changeset
58 58 def self.format_changeset_identifier(changeset)
59 59 changeset.revision[0, 8]
60 60 end
61 61
62 62 def branches
63 63 scm.branches
64 64 end
65 65
66 66 def tags
67 67 scm.tags
68 68 end
69 69
70 70 def find_changeset_by_name(name)
71 71 return nil if name.nil? || name.empty?
72 72 e = changesets.find(:first, :conditions => ['revision = ?', name.to_s])
73 73 return e if e
74 74 changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"])
75 75 end
76 76
77 77 def entries(path=nil, identifier=nil)
78 78 scm.entries(path,
79 79 identifier,
80 options = {:report_last_commit => report_last_commit})
80 options = {:report_last_commit => extra_report_last_commit})
81 81 end
82 82
83 83 # In Git and Mercurial, revisions are not in date order.
84 84 # Mercurial fixed issues.
85 85 # * Redmine Takes Too Long On Large Mercurial Repository
86 86 # http://www.redmine.org/issues/3449
87 87 # * Sorting for changesets might go wrong on Mercurial repos
88 88 # http://www.redmine.org/issues/3567
89 89 # Database revision column is text, so Redmine can not sort by revision.
90 90 # Mercurial has revision number, and revision number guarantees revision order.
91 91 # Mercurial adapter uses "hg log -r 0:tip --limit 10"
92 92 # to get limited revisions from old to new.
93 93 # And Mercurial model stored revisions ordered by database id in database.
94 94 # So, Mercurial can use correct order revisions.
95 95 #
96 96 # But, Git 1.7.3.4 does not support --reverse with -n or --skip.
97 97 #
98 98 # With SCM's that have a sequential commit numbering, redmine is able to be
99 99 # clever and only fetch changesets going forward from the most recent one
100 100 # it knows about.
101 101 # However, with git, you never know if people have merged
102 102 # commits into the middle of the repository history, so we should parse
103 103 # the entire log.
104 104 #
105 105 # Since it's way too slow for large repositories,
106 106 # we only parse 1 week before the last known commit.
107 107 #
108 108 # The repository can still be fully reloaded by calling #clear_changesets
109 109 # before fetching changesets (eg. for offline resync)
110 110 def fetch_changesets
111 111 c = changesets.find(:first, :order => 'committed_on DESC')
112 112 since = (c ? c.committed_on - 7.days : nil)
113 113
114 114 revisions = scm.revisions('', nil, nil, {:all => true, :since => since, :reverse => true})
115 115 return if revisions.nil? || revisions.empty?
116 116
117 117 recent_changesets = changesets.find(:all, :conditions => ['committed_on >= ?', since])
118 118
119 119 # Clean out revisions that are no longer in git
120 120 recent_changesets.each {|c| c.destroy unless revisions.detect {|r| r.scmid.to_s == c.scmid.to_s }}
121 121
122 122 # Subtract revisions that redmine already knows about
123 123 recent_revisions = recent_changesets.map{|c| c.scmid}
124 124 revisions.reject!{|r| recent_revisions.include?(r.scmid)}
125 125
126 126 # Save the remaining ones to the database
127 127 unless revisions.nil?
128 128 revisions.each do |rev|
129 129 transaction do
130 130 save_revision(rev)
131 131 end
132 132 end
133 133 end
134 134 end
135 135
136 136 def save_revision(rev)
137 137 changeset = Changeset.new(
138 138 :repository => self,
139 139 :revision => rev.identifier,
140 140 :scmid => rev.scmid,
141 141 :committer => rev.author,
142 142 :committed_on => rev.time,
143 143 :comments => rev.message
144 144 )
145 145 if changeset.save
146 146 rev.paths.each do |file|
147 147 Change.create(
148 148 :changeset => changeset,
149 149 :action => file[:action],
150 150 :path => file[:path])
151 151 end
152 152 end
153 153 end
154 154 private :save_revision
155 155
156 156 def latest_changesets(path,rev,limit=10)
157 157 revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false)
158 158 return [] if revisions.nil? || revisions.empty?
159 159
160 160 changesets.find(
161 161 :all,
162 162 :conditions => [
163 163 "scmid IN (?)",
164 164 revisions.map!{|c| c.scmid}
165 165 ],
166 166 :order => 'committed_on DESC'
167 167 )
168 168 end
169 169 end
General Comments 0
You need to be logged in to leave comments. Login now