Class: VCLog::Adapters::Hg

Inherits:
Abstract show all
Defined in:
lib/vclog/adapters/hg.rb

Overview

Mercurial Adapter

Instance Attribute Summary

Attributes inherited from Abstract

#config, #heuristics, #root

Instance Method Summary collapse

Methods inherited from Abstract

#change_by_date, #change_points, #changes, #initialize, #initialize_framework, #tag?, #tags, #tempfile, #version, #version_tag?

Constructor Details

This class inherits a constructor from VCLog::Adapters::Abstract

Instance Method Details

#emailObject

TODO:

check .hgrc for email.

User’s email address.



58
59
60
# File 'lib/vclog/adapters/hg.rb', line 58

def email
  ENV['HGEMAIL'] || ENV['EMAIL']
end

#extract_changesObject

Collect changes.



14
15
16
17
18
19
20
21
22
23
# File 'lib/vclog/adapters/hg.rb', line 14

def extract_changes
  list = []
  changelog = `hg log -v`.strip
  changes = changelog.split("\n\n\n")
  changes.each do |entry|
    settings = parse_entry(entry)
    list << Change.new(settings)
  end
  list
end

#extract_tagsObject

TODO:

Extract first commit prior to tag and provide it with Tag object.

Collect tags.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vclog/adapters/hg.rb', line 30

def extract_tags
  list = []
  if File.exist?('.hgtags')
    File.readlines('.hgtags').each do |line|
      rev, tag = line.strip.split(' ')
      entry = `hg log -v -r #{rev}`.strip
      settings = parse_entry(entry)
      settings[:name] = tag
      list << Tag.new(settings)
    end
  end
  list
end

#parse_entry(entry) ⇒ Object (private)

Parse log entry.



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
# File 'lib/vclog/adapters/hg.rb', line 97

def parse_entry(entry)
  settings = {}

  entry.strip!

  if md = /^changeset:(.*?)$/.match(entry)
    settings[:id] = md[1].strip
  end

  if md = /^date:(.*?)$/.match(entry)
    settings[:date] = Time.parse(md[1].strip)
  end

  if md = /^user:(.*?)$/.match(entry)
    settings[:who] = md[1].strip
  end

  if md = /^files:(.*?)$/.match(entry)
    settings[:files] = md[1].strip.split(' ')
  end

  if md = /^description:(.*?)\Z/m.match(entry)
    settings[:msg] = md[1].strip
  end

  return settings
end

#tag(ref, label, date, msg) ⇒ Object

TODO: Will multi-line messages work okay this way?



82
83
84
85
86
87
88
89
90
# File 'lib/vclog/adapters/hg.rb', line 82

def tag(ref, label, date, msg)
  file = tempfile("message", msg)
  date = date.strftime('%Y-%m-%d') unless String===date

  cmd  = %[hg tag -r #{ref} -d #{date} -m "$(cat #{file})" #{label}]

  puts cmd if $DEBUG
  `#{cmd}` unless $DRYRUN
end

#uriObject Also known as: repository

URI of repository.



65
66
67
# File 'lib/vclog/adapters/hg.rb', line 65

def uri
  @uri ||= `hg showconfig paths.default`.strip
end

#userObject

TODO:

check .hgrc for user.

Username.



49
50
51
# File 'lib/vclog/adapters/hg.rb', line 49

def user
  ENV['HGUSER'] || ENV['USER']
end

#uuidObject



75
76
77
# File 'lib/vclog/adapters/hg.rb', line 75

def uuid
  nil
end