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