Class: Repository::Git

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

Overview

Since:

  • 0.7.0

Constant Summary

Constants inherited from Repository

IDENTIFIER_MAX_LENGTH

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Repository

#<=>, available_scm, #cat, #committer_ids=, #committers, #diff, #diff_format_revisions, #entries, #entry, #extra_info, factory, fetch_changesets, find_by_identifier_param, #find_committer_user, #identifier=, #identifier_frozen?, #identifier_param, #latest_changeset, #merge_extra_info, #name, #password, #password=, #properties, #relative_path, #repo_create_validation, repository_class, #root_url=, #same_commits_in_scope, scan_changesets_for_issue_ids, #scan_changesets_for_issue_ids, #scm, #scm_adapter, scm_available, scm_command, #scm_name, scm_version_string, #set_as_default?, #stats_by_author, #supports_all_revisions?, #supports_annotate?, #supports_cat?, #url=

Methods included from Redmine::SafeAttributes

#delete_unsafe_attributes, #safe_attribute?, #safe_attribute_names, #safe_attributes=

Methods included from Redmine::Ciphering

cipher_key, decrypt_text, encrypt_text, logger

Class Method Details

.changeset_identifier(changeset) ⇒ Object

Returns the identifier for the given git changeset

Since:

  • 1.1.0



66
67
68
# File 'app/models/repository/git.rb', line 66

def self.changeset_identifier(changeset)
  changeset.scmid
end

.format_changeset_identifier(changeset) ⇒ Object

Returns the readable identifier for the given git changeset

Since:

  • 1.1.0



71
72
73
# File 'app/models/repository/git.rb', line 71

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

.human_attribute_name(attribute_key_name, *args) ⇒ Object

Since:

  • 1.2.0



26
27
28
29
30
31
32
# File 'app/models/repository/git.rb', line 26

def self.human_attribute_name(attribute_key_name, *args)
  attr_name = attribute_key_name.to_s
  if attr_name == "url"
    attr_name = "path_to_repository"
  end
  super(attr_name, *args)
end

.scm_adapter_classObject

Since:

  • 1.2.0



34
35
36
# File 'app/models/repository/git.rb', line 34

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

.scm_nameObject



38
39
40
# File 'app/models/repository/git.rb', line 38

def self.scm_name
  'Git'
end

Instance Method Details

#branchesObject

Since:

  • 0.9.0



75
76
77
# File 'app/models/repository/git.rb', line 75

def branches
  scm.branches
end

#default_branchObject

Since:

  • 1.2.1



83
84
85
86
87
88
# File 'app/models/repository/git.rb', line 83

def default_branch
  scm.default_branch
rescue Exception => e
  logger.error "git: error during get default branch: #{e.message}"
  nil
end

#fetch_changesetsObject

With SCMs that have a sequential commit numbering, such as Subversion and Mercurial, Redmine is able to be clever and only fetch changesets going forward from the most recent one it knows about.

However, Git does not have a sequential commit numbering.

In order to fetch only new adding revisions, Redmine needs to save “heads”.

In Git and Mercurial, revisions are not in date order. Redmine Mercurial fixed issues.

* Redmine Takes Too Long On Large Mercurial Repository
  http://www.redmine.org/issues/3449
* Sorting for changesets might go wrong on Mercurial repos
  http://www.redmine.org/issues/3567

Database revision column is text, so Redmine can not sort by revision. Mercurial has revision number, and revision number guarantees revision order. Redmine Mercurial model stored revisions ordered by database id to database. So, Redmine Mercurial model can use correct ordering revisions.

Redmine Mercurial adapter uses “hg log -r 0:tip –limit 10” to get limited revisions from old to new. But, Git 1.7.3.4 does not support –reverse with -n or –skip.

The repository can still be fully reloaded by calling #clear_changesets before fetching changesets (eg. for offline resync)



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'app/models/repository/git.rb', line 130

def fetch_changesets
  scm_brs = branches
  return if scm_brs.nil? || scm_brs.empty?

  h1 = extra_info || {}
  h  = h1.dup
  repo_heads = scm_brs.map{ |br| br.scmid }
  h["heads"] ||= []
  prev_db_heads = h["heads"].dup
  if prev_db_heads.empty?
    prev_db_heads += heads_from_branches_hash
  end
  return if prev_db_heads.sort == repo_heads.sort

  h["db_consistent"]  ||= {}
  if ! changesets.exists?
    h["db_consistent"]["ordering"] = 1
    merge_extra_info(h)
    self.save
  elsif ! h["db_consistent"].has_key?("ordering")
    h["db_consistent"]["ordering"] = 0
    merge_extra_info(h)
    self.save
  end
  save_revisions(prev_db_heads, repo_heads)
end

#find_changeset_by_name(name) ⇒ Object

Since:

  • 1.2.0



90
91
92
93
94
95
# File 'app/models/repository/git.rb', line 90

def find_changeset_by_name(name)
  if name.present?
    changesets.find_by(:revision => name.to_s) ||
      changesets.where('scmid LIKE ?', "#{name}%").first
  end
end

#heads_from_branches_hashObject

Since:

  • 1.4.0



235
236
237
238
239
240
# File 'app/models/repository/git.rb', line 235

def heads_from_branches_hash
  h1 = extra_info || {}
  h  = h1.dup
  h["branches"] ||= {}
  h['branches'].map{|br, hs| hs['last_scmid']}
end

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

Since:

  • 0.9.0



242
243
244
245
246
# File 'app/models/repository/git.rb', line 242

def latest_changesets(path,rev,limit=10)
  revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false)
  return [] if revisions.nil? || revisions.empty?
  changesets.where(:scmid => revisions.map {|c| c.scmid}).to_a
end

#repo_log_encodingObject

Since:

  • 1.2.0



61
62
63
# File 'app/models/repository/git.rb', line 61

def repo_log_encoding
  'UTF-8'
end

#report_last_commitObject

Since:

  • 1.2.0



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

def report_last_commit
  return false if extra_info.nil?
  v = extra_info["extra_report_last_commit"]
  return false if v.nil?
  v.to_s != '0'
end

#report_last_commit=(arg) ⇒ Object

Since:

  • 3.4.0



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

def report_last_commit=(arg)
  merge_extra_info "extra_report_last_commit" => arg
end

#supports_directory_revisions?Boolean

Returns:

  • (Boolean)

Since:

  • 1.2.0



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

def supports_directory_revisions?
  true
end

#supports_revision_graph?Boolean

Returns:

  • (Boolean)

Since:

  • 1.3.0



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

def supports_revision_graph?
  true
end

#tagsObject

Since:

  • 0.9.0



79
80
81
# File 'app/models/repository/git.rb', line 79

def tags
  scm.tags
end