Class: Repository::Mercurial

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

Overview

Since:

  • 0.5.1

Constant Summary collapse

FETCH_AT_ONCE =

number of changesets to fetch at once

100

Constants inherited from Repository

IDENTIFIER_MAX_LENGTH

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Repository

#<=>, available_scm, #branches, #cat, #committer_ids=, #committers, #default_branch, #diff, #entries, #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, #report_last_commit, 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?, #tags, #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 Mercurial changeset

Since:

  • 1.2.0



65
66
67
# File 'app/models/repository/mercurial.rb', line 65

def self.changeset_identifier(changeset)
  changeset.scmid
end

.format_changeset_identifier(changeset) ⇒ Object

Returns the readable identifier for the given mercurial changeset

Since:

  • 1.2.0



60
61
62
# File 'app/models/repository/mercurial.rb', line 60

def self.format_changeset_identifier(changeset)
  "#{changeset.revision}:#{changeset.scmid[0, 12]}"
end

.human_attribute_name(attribute_key_name, *args) ⇒ Object

Since:

  • 1.2.0



31
32
33
34
35
36
37
# File 'app/models/repository/mercurial.rb', line 31

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



39
40
41
# File 'app/models/repository/mercurial.rb', line 39

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

.scm_nameObject



43
44
45
# File 'app/models/repository/mercurial.rb', line 43

def self.scm_name
  'Mercurial'
end

Instance Method Details

#diff_format_revisions(cs, cs_to, sep = ':') ⇒ Object

Since:

  • 1.2.0



69
70
71
# File 'app/models/repository/mercurial.rb', line 69

def diff_format_revisions(cs, cs_to, sep=':')
  super(cs, cs_to, ' ')
end

#entry(path = nil, identifier = nil) ⇒ Object

Since:

  • 2.5.0



80
81
82
83
84
85
# File 'app/models/repository/mercurial.rb', line 80

def entry(path=nil, identifier=nil)
  entry = scm.entry(path, identifier)
  return nil if entry.nil?
  modify_entry_lastrev_identifier(entry)
  entry
end

#fetch_changesetsObject



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'app/models/repository/mercurial.rb', line 178

def fetch_changesets
  return if scm.info.nil?
  scm_rev = scm.info.lastrev.revision.to_i
  db_rev  = latest_changeset ? latest_changeset.revision.to_i : -1
  return unless db_rev < scm_rev  # already up-to-date

  logger.debug "Fetching changesets for repository #{url}" if logger
  (db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i|
    scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re|
      transaction do
        parents = (re.parents || []).collect do |rp|
          find_changeset_by_name(scmid_for_inserting_db(rp))
        end.compact
        cs = Changeset.create(:repository   => self,
                              :revision     => re.revision,
                              :scmid        => scmid_for_inserting_db(re.scmid),
                              :committer    => re.author,
                              :committed_on => re.time,
                              :comments     => re.message,
                              :parents      => parents)
        unless cs.new_record?
          re.paths.each do |e|
            if from_revision = e[:from_revision]
              e[:from_revision] = scmid_for_inserting_db(from_revision)
            end
            cs.create_change(e)
          end
        end
      end
    end
  end
end

#find_changeset_by_name(name) ⇒ Object

Finds and returns a revision with a number or the beginning of a hash

Since:

  • 1.2.0



96
97
98
99
100
101
102
103
104
105
106
# File 'app/models/repository/mercurial.rb', line 96

def find_changeset_by_name(name)
  return nil if name.blank?
  s = name.to_s
  if /[^\d]/ =~ s or s.size > 8
    cs = changesets.where(:scmid => s).first
  else
    cs = changesets.find_by(:revision => s)
  end
  return cs if cs
  changesets.where('scmid LIKE ?', "#{s}%").first
end

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

Returns the latest changesets for path; sorted by revision number

Because :order => 'id DESC' is defined at 'has_many', there is no need to set 'order'. But, MySQL test fails. Sqlite3 and PostgreSQL pass. Is this MySQL bug?

Since:

  • 1.1.0



115
116
117
118
119
120
121
122
123
# File 'app/models/repository/mercurial.rb', line 115

def latest_changesets(path, rev, limit=10)
  changesets.
    includes(:user).
    where(latest_changesets_cond(path, rev, limit)).
    references(:user).
    limit(limit).
    order("#{Changeset.table_name}.id DESC").
    to_a
end

#nodes_in_branch(rev, branch_limit) ⇒ Object

Since:

  • 2.5.0



136
137
138
139
140
# File 'app/models/repository/mercurial.rb', line 136

def nodes_in_branch(rev, branch_limit)
  scm.nodes_in_branch(rev, :limit => branch_limit).collect do |b|
    scmid_for_inserting_db(b)
  end
end

#repo_log_encodingObject

Since:

  • 1.2.0



55
56
57
# File 'app/models/repository/mercurial.rb', line 55

def repo_log_encoding
  'UTF-8'
end

#scmid_for_inserting_db(scmid) ⇒ Object

Since:

  • 2.5.0



132
133
134
# File 'app/models/repository/mercurial.rb', line 132

def scmid_for_inserting_db(scmid)
  is_short_id_in_db? ? scmid[0, 12] : scmid
end

#supports_directory_revisions?Boolean

Returns:

  • (Boolean)

Since:

  • 1.2.0



47
48
49
# File 'app/models/repository/mercurial.rb', line 47

def supports_directory_revisions?
  true
end

#supports_revision_graph?Boolean

Returns:

  • (Boolean)

Since:

  • 1.3.0



51
52
53
# File 'app/models/repository/mercurial.rb', line 51

def supports_revision_graph?
  true
end

#tag_scmid(rev) ⇒ Object

Since:

  • 2.5.0



142
143
144
145
# File 'app/models/repository/mercurial.rb', line 142

def tag_scmid(rev)
  scmid = scm.tagmap[rev]
  scmid.nil? ? nil : scmid_for_inserting_db(scmid)
end