Class: Repository::Git

Inherits:
Repository
  • Object
show all
Defined in:
app/models/repository/git.rb

Constant Summary collapse

ATTRIBUTE_KEY_NAMES =
{
  "url"          => "Path to repository",
}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Repository

available_scm, #cat, #committer_ids=, #committers, #default_branch, #diff, #diff_format_revisions, #entries, #entry, factory, fetch_changesets, #find_committer_user, #latest_changeset, #log_encoding, #password, #password=, #properties, #relative_path, #root_url=, #scan_changesets_for_issue_ids, scan_changesets_for_issue_ids, #scm, #scm_adapter, scm_available, scm_command, #scm_name, scm_version_string, #supports_all_revisions?, #supports_annotate?, #supports_cat?, #url=

Methods included from Redmine::Ciphering

cipher_key, decrypt_text, encrypt_text, included

Class Method Details

.changeset_identifier(changeset) ⇒ Object

Returns the identifier for the given git changeset


45
46
47
# File 'app/models/repository/git.rb', line 45

def self.changeset_identifier(changeset)
  changeset.scmid
end

.format_changeset_identifier(changeset) ⇒ Object

Returns the readable identifier for the given git changeset


50
51
52
# File 'app/models/repository/git.rb', line 50

def self.format_changeset_identifier(changeset)
  changeset.revision[0, 8]
end

.human_attribute_name(attribute_key_name) ⇒ Object


24
25
26
# File 'app/models/repository/git.rb', line 24

def self.human_attribute_name(attribute_key_name)
  ATTRIBUTE_KEY_NAMES[attribute_key_name] || super
end

.scm_adapter_classObject


28
29
30
# File 'app/models/repository/git.rb', line 28

def self.scm_adapter_class
  Redmine::Scm::Adapters::GitAdapter
end

.scm_nameObject


32
33
34
# File 'app/models/repository/git.rb', line 32

def self.scm_name
  'Git'
end

Instance Method Details

#branchesObject


54
55
56
# File 'app/models/repository/git.rb', line 54

def branches
  scm.branches
end

#fetch_changesetsObject

With SCM's that have a sequential commit numbering, redmine is able to be clever and only fetch changesets going forward from the most recent one it knows about. However, with git, you never know if people have merged commits into the middle of the repository history, so we should parse the entire log. Since it's way too slow for large repositories, we only parse 1 week before the last known commit. The repository can still be fully reloaded by calling #clear_changesets before fetching changesets (eg. for offline resync)


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/repository/git.rb', line 77

def fetch_changesets
  c = changesets.find(:first, :order => 'committed_on DESC')
  since = (c ? c.committed_on - 7.days : nil)

  revisions = scm.revisions('', nil, nil, {:all => true, :since => since, :reverse => true})
  return if revisions.nil? || revisions.empty?

  recent_changesets = changesets.find(:all, :conditions => ['committed_on >= ?', since])

  # Clean out revisions that are no longer in git
  recent_changesets.each {|c| c.destroy unless revisions.detect {|r| r.scmid.to_s == c.scmid.to_s }}

  # Subtract revisions that redmine already knows about
  recent_revisions = recent_changesets.map{|c| c.scmid}
  revisions.reject!{|r| recent_revisions.include?(r.scmid)}

  # Save the remaining ones to the database
  unless revisions.nil?
    revisions.each do |rev|
      transaction do
        changeset = Changeset.new(
            :repository => self,
            :revision   => rev.identifier,
            :scmid      => rev.scmid,
            :committer  => rev.author,
            :committed_on => rev.time,
            :comments   => rev.message)

        if changeset.save
          rev.paths.each do |file|
            Change.create(
                :changeset => changeset,
                :action    => file[:action],
                :path      => file[:path])
          end
        end
      end
    end
  end
end

#find_changeset_by_name(name) ⇒ Object


62
63
64
65
66
67
# File 'app/models/repository/git.rb', line 62

def find_changeset_by_name(name)
  return nil if name.nil? || name.empty?
  e = changesets.find(:first, :conditions => ['revision = ?', name.to_s])
  return e if e
  changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"])
end

#latest_changesets(path, rev, limit = 10) ⇒ Object


118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/models/repository/git.rb', line 118

def latest_changesets(path,rev,limit=10)
  revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false)
  return [] if revisions.nil? || revisions.empty?

  changesets.find(
    :all,
    :conditions => [
      "scmid IN (?)",
      revisions.map!{|c| c.scmid}
    ],
    :order => 'committed_on DESC'
  )
end

#repo_log_encodingObject


40
41
42
# File 'app/models/repository/git.rb', line 40

def repo_log_encoding
  'UTF-8'
end

#supports_directory_revisions?Boolean

Returns:

  • (Boolean)

36
37
38
# File 'app/models/repository/git.rb', line 36

def supports_directory_revisions?
  true
end

#tagsObject


58
59
60
# File 'app/models/repository/git.rb', line 58

def tags
  scm.tags
end