Class: Repository::Cvs

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Repository

available_scm, #changesets_for_path, #committer_ids=, #committers, factory, fetch_changesets, #find_committer_user, #latest_changeset, #properties, #relative_path, #root_url=, #scan_changesets_for_issue_ids, scan_changesets_for_issue_ids, #scm, #scm_name, #supports_annotate?, #supports_cat?, #url=

Class Method Details

.scm_nameObject



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

def self.scm_name
  'CVS'
end

Instance Method Details

#cat(path, identifier = nil) ⇒ Object



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

def cat(path, identifier=nil)
  rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
  scm.cat(path, rev.nil? ? nil : rev.committed_on)
end

#diff(path, rev, rev_to) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/models/repository/cvs.rb', line 61

def diff(path, rev, rev_to)
  #convert rev to revision. CVS can't handle changesets here
  diff=[]
  changeset_from=changesets.find_by_revision(rev)
  if rev_to.to_i > 0 
    changeset_to=changesets.find_by_revision(rev_to)
  end
  changeset_from.changes.each() do |change_from|
    
    revision_from=nil
    revision_to=nil      
    
    revision_from=change_from.revision if path.nil? || (change_from.path.starts_with? scm.with_leading_slash(path))
    
    if revision_from
      if changeset_to
        changeset_to.changes.each() do |change_to|
          revision_to=change_to.revision if change_to.path==change_from.path 
        end
      end
      unless revision_to
        revision_to=scm.get_previous_revision(revision_from)
      end
      file_diff = scm.diff(change_from.path, revision_from, revision_to)
      diff = diff + file_diff unless file_diff.nil?
    end
  end
  return diff
end

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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/repository/cvs.rb', line 37

def entries(path=nil, identifier=nil)
  rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
  entries = scm.entries(path, rev.nil? ? nil : rev.committed_on)
  if entries
    entries.each() do |entry|
      unless entry.lastrev.nil? || entry.lastrev.identifier
        change=changes.find_by_revision_and_path( entry.lastrev.revision, scm.with_leading_slash(entry.path) )
        if change
          entry.lastrev.identifier=change.changeset.revision
          entry.lastrev.author=change.changeset.committer
          entry.lastrev.revision=change.revision
          entry.lastrev.branch=change.branch
        end
      end
    end
  end
  entries
end

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



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

def entry(path=nil, identifier=nil)
  rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
  scm.entry(path, rev.nil? ? nil : rev.committed_on)
end

#fetch_changesetsObject



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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'app/models/repository/cvs.rb', line 91

def fetch_changesets
  # some nifty bits to introduce a commit-id with cvs
  # natively cvs doesn't provide any kind of changesets, there is only a revision per file.
  # we now take a guess using the author, the commitlog and the commit-date.
  
  # last one is the next step to take. the commit-date is not equal for all 
  # commits in one changeset. cvs update the commit-date when the *,v file was touched. so
  # we use a small delta here, to merge all changes belonging to _one_ changeset
  time_delta=10.seconds
  
  fetch_since = latest_changeset ? latest_changeset.committed_on : nil
  transaction do
    tmp_rev_num = 1
    scm.revisions('', fetch_since, nil, :with_paths => true) do |revision|
      # only add the change to the database, if it doen't exists. the cvs log
      # is not exclusive at all. 
      unless changes.find_by_path_and_revision(scm.with_leading_slash(revision.paths[0][:path]), revision.paths[0][:revision])
        revision
        cs = changesets.find(:first, :conditions=>{
          :committed_on=>revision.time-time_delta..revision.time+time_delta,
          :committer=>revision.author,
          :comments=>Changeset.normalize_comments(revision.message)
        })
      
        # create a new changeset.... 
        unless cs
          # we use a temporaray revision number here (just for inserting)
          # later on, we calculate a continous positive number
          latest = changesets.find(:first, :order => 'id DESC')
          cs = Changeset.create(:repository => self,
                                :revision => "_#{tmp_rev_num}", 
                                :committer => revision.author, 
                                :committed_on => revision.time,
                                :comments => revision.message)
          tmp_rev_num += 1
        end
      
        #convert CVS-File-States to internal Action-abbrevations
        #default action is (M)odified
        action="M"
        if revision.paths[0][:action]=="Exp" && revision.paths[0][:revision]=="1.1"
          action="A" #add-action always at first revision (= 1.1)
        elsif revision.paths[0][:action]=="dead"
          action="D" #dead-state is similar to Delete
        end
      
        Change.create(:changeset => cs,
        :action => action,
        :path => scm.with_leading_slash(revision.paths[0][:path]),
        :revision => revision.paths[0][:revision],
        :branch => revision.paths[0][:branch]
        )
      end
    end
    
    # Renumber new changesets in chronological order
    changesets.find(:all, :order => 'committed_on ASC, id ASC', :conditions => "revision LIKE '_%'").each do |changeset|
      changeset.update_attribute :revision, next_revision_number
    end
  end # transaction
end

#scm_adapterObject



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

def scm_adapter
  Redmine::Scm::Adapters::CvsAdapter
end