lib/vclog/adapters/hg.rb in vclog-1.8.2 vs lib/vclog/adapters/hg.rb in vclog-1.9.0
- old
+ new
@@ -1,93 +1,129 @@
require 'vclog/adapters/abstract'
module VCLog
-module Adapters
- # = Mercurial Adapter
- #
- # TODO: maybe use Amp gem for future version.
- class Hg < Abstract
+ module Adapters
- # Collect changes.
- def extract_changes
- list = []
- changelog = `hg log -v`.strip
- changes = changelog.split("\n\n\n")
- changes.each do |entry|
- id, date, who, msg = *parse_entry(entry)
- list << Change.new(:id=>id, :date=>date, :who=>who, :msg=>msg)
+ # Mercurial Adapter
+ #
+ class Hg < Abstract
+
+ #
+ # Collect changes.
+ #
+ 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
- list
- end
- # Collect tags.
- 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
- rev, date, who, msg, type = parse_entry(entry)
- list << Tag.new(:name=>tag, :id=>rev, :date=>date, :who=>who, :msg=>msg)
+ #
+ # Collect tags.
+ #
+ # @todo Extract first commit prior to tag and provide it with Tag object.
+ #
+ 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
- list
- end
- # TODO: check .hgrc
- def user
- ENV['HGUSER'] || ENV['USER']
- end
+ #
+ # Username.
+ #
+ # @todo check .hgrc for user.
+ #
+ def user
+ ENV['HGUSER'] || ENV['USER']
+ end
- #
- def email
- ENV['HGEMAIL'] || ENV['EMAIL']
- end
+ #
+ # User's email address.
+ #
+ # @todo check .hgrc for email.
+ #
+ def email
+ ENV['HGEMAIL'] || ENV['EMAIL']
+ end
- #
- def repository
- @repository ||= `hg showconfig paths.default`.strip
- end
+ #
+ # URI of repository.
+ #
+ def uri
+ @uri ||= `hg showconfig paths.default`.strip
+ end
- #
- def uuid
- nil
- end
+ # @deprecated
+ alias_method :repository, :uri
- # TODO: Will multi-line messages work okay this way?
- def tag(ref, label, date, msg)
- file = tempfile("message", msg)
- date = date.strftime('%Y-%m-%d') unless String===date
+ #
+ #
+ #
+ def uuid
+ nil
+ end
- cmd = %[hg tag -r #{ref} -d #{date} -m "$(cat #{file})" #{label}]
+ #
+ # TODO: Will multi-line messages work okay this way?
+ #
+ def tag(ref, label, date, msg)
+ file = tempfile("message", msg)
+ date = date.strftime('%Y-%m-%d') unless String===date
- puts cmd if $DEBUG
- `#{cmd}` unless $DRYRUN
- end
+ cmd = %[hg tag -r #{ref} -d #{date} -m "$(cat #{file})" #{label}]
- private
+ puts cmd if $DEBUG
+ `#{cmd}` unless $DRYRUN
+ end
+ private
+
+ #
+ # Parse log entry.
+ #
def parse_entry(entry)
- rev, date, who, msg = nil, nil, nil, nil
+ settings = {}
+
entry.strip!
+
if md = /^changeset:(.*?)$/.match(entry)
- rev = md[1].strip
+ settings[:id] = md[1].strip
end
+
if md = /^date:(.*?)$/.match(entry)
- date = md[1].strip
+ settings[:date] = Time.parse(md[1].strip)
end
+
if md = /^user:(.*?)$/.match(entry)
- who = md[1].strip
+ 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)
- msg = md[1].strip
+ settings[:msg] = md[1].strip
end
- date = Time.parse(date)
- #msg, type = *split_type(msg)
- return rev, date, who, msg
+
+ return settings
end
+ end
+
end
-end
end