##// END OF EJS Templates
Merged r5644 from trunk....
Toshi MARUYAMA -
r5526:4fc2e757f6d0
parent child
Show More
@@ -1,95 +1,110
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 scm_adapter
25 25 Redmine::Scm::Adapters::GitAdapter
26 26 end
27 27
28 28 def self.scm_name
29 29 'Git'
30 30 end
31 31
32 32 # Returns the identifier for the given git changeset
33 33 def self.changeset_identifier(changeset)
34 34 changeset.scmid
35 35 end
36 36
37 37 # Returns the readable identifier for the given git changeset
38 38 def self.format_changeset_identifier(changeset)
39 39 changeset.revision[0, 8]
40 40 end
41 41
42 42 def branches
43 43 scm.branches
44 44 end
45 45
46 46 def tags
47 47 scm.tags
48 48 end
49 49
50 # In Git and Mercurial, revisions are not in date order.
51 # Mercurial fixed issues.
52 # * Redmine Takes Too Long On Large Mercurial Repository
53 # http://www.redmine.org/issues/3449
54 # * Sorting for changesets might go wrong on Mercurial repos
55 # http://www.redmine.org/issues/3567
56 # Database revision column is text, so Redmine can not sort by revision.
57 # Mercurial has revision number, and revision number guarantees revision order.
58 # Mercurial adapter uses "hg log -r 0:tip --limit 10"
59 # to get limited revisions from old to new.
60 # And Mercurial model stored revisions ordered by database id in database.
61 # So, Mercurial can use correct order revisions.
62 #
63 # But, Git 1.7.3.4 does not support --reverse with -n or --skip.
64 #
50 65 # With SCM's that have a sequential commit numbering, redmine is able to be
51 66 # clever and only fetch changesets going forward from the most recent one
52 67 # it knows about.
53 68 # However, with git, you never know if people have merged
54 69 # commits into the middle of the repository history, so we should parse
55 70 # the entire log.
56 71 #
57 72 # Since it's way too slow for large repositories,
58 73 # we only parse 1 week before the last known commit.
59 74 #
60 75 # The repository can still be fully reloaded by calling #clear_changesets
61 76 # before fetching changesets (eg. for offline resync)
62 77 def fetch_changesets
63 78 c = changesets.find(:first, :order => 'committed_on DESC')
64 79 since = (c ? c.committed_on - 7.days : nil)
65 80
66 81 revisions = scm.revisions('', nil, nil, :all => true, :since => since)
67 82 return if revisions.nil? || revisions.empty?
68 83
69 84 recent_changesets = changesets.find(:all, :conditions => ['committed_on >= ?', since])
70 85
71 86 # Clean out revisions that are no longer in git
72 87 recent_changesets.each {|c| c.destroy unless revisions.detect {|r| r.scmid.to_s == c.scmid.to_s }}
73 88
74 89 # Subtract revisions that redmine already knows about
75 90 recent_revisions = recent_changesets.map{|c| c.scmid}
76 91 revisions.reject!{|r| recent_revisions.include?(r.scmid)}
77 92
78 93 # Save the remaining ones to the database
79 94 revisions.each{|r| r.save(self)} unless revisions.nil?
80 95 end
81 96
82 97 def latest_changesets(path,rev,limit=10)
83 98 revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false)
84 99 return [] if revisions.nil? || revisions.empty?
85 100
86 101 changesets.find(
87 102 :all,
88 103 :conditions => [
89 104 "scmid IN (?)",
90 105 revisions.map!{|c| c.scmid}
91 106 ],
92 107 :order => 'committed_on DESC'
93 108 )
94 109 end
95 110 end
General Comments 0
You need to be logged in to leave comments. Login now