Class: Mercurial::ChangedFileFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/mercurial-ruby/factories/changed_file_factory.rb

Constant Summary collapse

FILE_COPY_SEPARATOR =
'->'

Class Method Summary collapse

Class Method Details

.delete_hg_artefacts(files) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mercurial-ruby/factories/changed_file_factory.rb', line 24

def self.delete_hg_artefacts(files)
  #
  # For unknown reason Mercurial post duplicated 
  # entries for moved and copied files. First as
  # a pair of A and D operations, then as C.
  #
  files.reverse.each do |file|
    if file.copied?
      add = files.find{|f| f.added? && f.name == file.name}
      delete = files.find{|f| f.deleted? && f.name == file.initial_name}

      if add && delete
        file.mode_letter = 'R'
        files.delete_at(files.index(add))
        files.delete_at(files.index(delete))

      elsif add
        files.delete_at(files.index(add))
      end
    end
  end
  files
end

.new_from_hg(str) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mercurial-ruby/factories/changed_file_factory.rb', line 7

def self.new_from_hg(str)
  if str.include?(FILE_COPY_SEPARATOR)
    copied_file = str.split(FILE_COPY_SEPARATOR)
    initial_name = copied_file.first[2..-1]
    name = copied_file[1]
  else
    initial_name = nil
    name = str[2..-1]
  end

  Mercurial::ChangedFile.new(
    :initial_name => initial_name,
    :name         => name,
    :mode         => str[0..0]
  )
end