Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # redMine - project management software
  2. # Copyright (C) 2006-2007 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  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
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require 'redmine/scm/adapters/mercurial_adapter'
  18. class Repository::Mercurial < Repository
  19. attr_protected :root_url
  20. validates_presence_of :url
  21. def scm_adapter
  22. Redmine::Scm::Adapters::MercurialAdapter
  23. end
  24. def self.scm_name
  25. 'Mercurial'
  26. end
  27. def entries(path=nil, identifier=nil)
  28. entries=scm.entries(path, identifier)
  29. if entries
  30. entries.each do |entry|
  31. next unless entry.is_file?
  32. # Set the filesize unless browsing a specific revision
  33. if identifier.nil?
  34. full_path = File.join(root_url, entry.path)
  35. entry.size = File.stat(full_path).size if File.file?(full_path)
  36. end
  37. # Search the DB for the entry's last change
  38. change = changes.find(:first, :conditions => ["path = ?", scm.with_leading_slash(entry.path)], :order => "#{Changeset.table_name}.committed_on DESC")
  39. if change
  40. entry.lastrev.identifier = change.changeset.revision
  41. entry.lastrev.name = change.changeset.revision
  42. entry.lastrev.author = change.changeset.committer
  43. entry.lastrev.revision = change.revision
  44. end
  45. end
  46. end
  47. entries
  48. end
  49. def fetch_changesets
  50. scm_info = scm.info
  51. if scm_info
  52. # latest revision found in database
  53. db_revision = latest_changeset ? latest_changeset.revision.to_i : -1
  54. # latest revision in the repository
  55. latest_revision = scm_info.lastrev
  56. return if latest_revision.nil?
  57. scm_revision = latest_revision.identifier.to_i
  58. if db_revision < scm_revision
  59. logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
  60. identifier_from = db_revision + 1
  61. while (identifier_from <= scm_revision)
  62. # loads changesets by batches of 100
  63. identifier_to = [identifier_from + 99, scm_revision].min
  64. revisions = scm.revisions('', identifier_from, identifier_to, :with_paths => true)
  65. transaction do
  66. revisions.each do |revision|
  67. changeset = Changeset.create(:repository => self,
  68. :revision => revision.identifier,
  69. :scmid => revision.scmid,
  70. :committer => revision.author,
  71. :committed_on => revision.time,
  72. :comments => revision.message)
  73. revision.paths.each do |change|
  74. Change.create(:changeset => changeset,
  75. :action => change[:action],
  76. :path => change[:path],
  77. :from_path => change[:from_path],
  78. :from_revision => change[:from_revision])
  79. end
  80. end
  81. end unless revisions.nil?
  82. identifier_from = identifier_to + 1
  83. end
  84. end
  85. end
  86. end
  87. end