You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

darcs.rb 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/darcs_adapter'
  18. class Repository::Darcs < Repository
  19. validates_presence_of :url
  20. def scm_adapter
  21. Redmine::Scm::Adapters::DarcsAdapter
  22. end
  23. def self.scm_name
  24. 'Darcs'
  25. end
  26. def entries(path=nil, identifier=nil)
  27. patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
  28. entries = scm.entries(path, patch.nil? ? nil : patch.scmid)
  29. if entries
  30. entries.each do |entry|
  31. # Search the DB for the entry's last change
  32. changeset = changesets.find_by_scmid(entry.lastrev.scmid) if entry.lastrev && !entry.lastrev.scmid.blank?
  33. if changeset
  34. entry.lastrev.identifier = changeset.revision
  35. entry.lastrev.name = changeset.revision
  36. entry.lastrev.time = changeset.committed_on
  37. entry.lastrev.author = changeset.committer
  38. end
  39. end
  40. end
  41. entries
  42. end
  43. def diff(path, rev, rev_to, type)
  44. patch_from = changesets.find_by_revision(rev)
  45. return nil if patch_from.nil?
  46. patch_to = changesets.find_by_revision(rev_to) if rev_to
  47. if path.blank?
  48. path = patch_from.changes.collect{|change| change.path}.join(' ')
  49. end
  50. patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil, type) : nil
  51. end
  52. def fetch_changesets
  53. scm_info = scm.info
  54. if scm_info
  55. db_last_id = latest_changeset ? latest_changeset.scmid : nil
  56. next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1
  57. # latest revision in the repository
  58. scm_revision = scm_info.lastrev.scmid
  59. unless changesets.find_by_scmid(scm_revision)
  60. revisions = scm.revisions('', db_last_id, nil, :with_path => true)
  61. transaction do
  62. revisions.reverse_each do |revision|
  63. changeset = Changeset.create(:repository => self,
  64. :revision => next_rev,
  65. :scmid => revision.scmid,
  66. :committer => revision.author,
  67. :committed_on => revision.time,
  68. :comments => revision.message)
  69. revision.paths.each do |change|
  70. Change.create(:changeset => changeset,
  71. :action => change[:action],
  72. :path => change[:path],
  73. :from_path => change[:from_path],
  74. :from_revision => change[:from_revision])
  75. end
  76. next_rev += 1
  77. end if revisions
  78. end
  79. end
  80. end
  81. end
  82. end