class VCLog::Adapters::Hg

Mercurial Adapter

Public Instance Methods

email() click to toggle source

User’s email address.

@todo check .hgrc for email.

# File lib/vclog/adapters/hg.rb, line 58
def email
  ENV['HGEMAIL'] || ENV['EMAIL']
end
extract_changes() click to toggle source

Collect changes.

# 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_tags() click to toggle source

Collect tags.

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

# 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
repository()

@deprecated

Alias for: uri
tag(ref, label, date, msg) click to toggle source

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

# 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
uri() click to toggle source

URI of repository.

# File lib/vclog/adapters/hg.rb, line 65
def uri
  @uri ||= `hg showconfig paths.default`.strip
end
Also aliased as: repository
user() click to toggle source

Username.

@todo check .hgrc for user.

# File lib/vclog/adapters/hg.rb, line 49
def user
  ENV['HGUSER'] || ENV['USER']
end
uuid() click to toggle source
# File lib/vclog/adapters/hg.rb, line 75
def uuid
  nil
end

Private Instance Methods

parse_entry(entry) click to toggle source

Parse log entry.

# 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