Class: Darcs::PatchInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/darcs/patchinfo.rb

Overview

This class holds the patch’s name, log, author, date, and other meta-info.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, name, author, log = nil, inverted = false) ⇒ PatchInfo

Returns a new instance of PatchInfo.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/darcs/patchinfo.rb', line 9

def initialize(date, name, author, log = nil, inverted = false)
  if date.kind_of?(String)
    @date = parse_date(date)
  else
    @date = date
  end
  @name = name
  @author = author
  @log = log
  @inverted = inverted
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



21
22
23
# File 'lib/darcs/patchinfo.rb', line 21

def author
  @author
end

#dateObject (readonly)

Returns the value of attribute date.



21
22
23
# File 'lib/darcs/patchinfo.rb', line 21

def date
  @date
end

#logObject (readonly)

Returns the value of attribute log.



21
22
23
# File 'lib/darcs/patchinfo.rb', line 21

def log
  @log
end

#nameObject (readonly)

Returns the value of attribute name.



21
22
23
# File 'lib/darcs/patchinfo.rb', line 21

def name
  @name
end

Class Method Details

.read(f) ⇒ Object

Reads a patch from a stream using the inventory format



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/darcs/patchinfo.rb', line 27

def self.read(f)
  line = f.gets
  return nil if line.nil?
  if line[0..0] != '['
    raise "Invalid inventory entry (starts with \"#{line[0..-2]}\")"
  end

  name = line[1..-2]
  line = f.readline
  raise "Invalid inventory entry" if !line[/^(.*)\*\*([0-9]{14})\]?\s*$/]
  author = $1
  date = $2
  log = nil
  if !line[/\]\s*$/]
    log = ""
    log += line[1..-1] while !((line = f.readline) =~ /^\]/)
  end

  return self.new(date, name, author, log)
end

Instance Method Details

#filenameObject

Retrieve the patch’s name



54
55
56
57
58
59
60
# File 'lib/darcs/patchinfo.rb', line 54

def filename
  author_hash = SHA1.new(author).to_s[0..4]
  hash = SHA1.new(name + author + timestamp +
                  (log.nil? ? '' : log.gsub(/\n/, '')) +
                  (inverted? ? 't' : 'f'))
  "#{timestamp}-#{author_hash}-#{hash}.gz"
end

#inverted?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/darcs/patchinfo.rb', line 22

def inverted?
  @inverted
end

#timestampObject

Retrieve the patch’s date in string timestamp format



49
50
51
# File 'lib/darcs/patchinfo.rb', line 49

def timestamp
  date.strftime("%Y%m%d%H%M%S") 
end

#to_sObject



62
63
64
65
66
67
68
# File 'lib/darcs/patchinfo.rb', line 62

def to_s
  if log
    the_log = log.gsub(/[\n\s]+$/, '').gsub(/\n/, "\n ")
  end
  "[#{name}\n#{author}**#{timestamp}" +
  (log.nil? ? '' : "\n " + the_log + "\n") + "]"
end