lib/vclog/vcs.rb in vclog-1.1 vs lib/vclog/vcs.rb in vclog-1.2
- old
+ new
@@ -1,45 +1,117 @@
module VCLog
require 'time'
require 'vclog/changelog'
- require 'vclog/vcs/svn'
- require 'vclog/vcs/git'
- #require 'vclog/vcs/hg'
- #require 'vclog/vcs/darcs'
+ require 'vclog/history'
+ require 'vclog/change'
+ require 'vclog/tag'
# TODO: Might we have a NO-VCS changelog based on
# LOG: entries in source files?
# = Version Control System
class VCS
- attr :type
-
- def initialize(root=nil)
- @root = root || Dir.pwd
- @type = read_type
- raise ArgumentError, "Not a recognized version control system." unless @type
+ def self.factory(root=nil)
+ root = root || Dir.pwd
+ type = read_type(root)
+ raise ArgumentError, "Not a recognized version control system." unless type
+ VCS.const_get(type.upcase).new(root)
end
- def read_type
+ def self.read_type(root)
dir = nil
- Dir.chdir(@root) do
+ Dir.chdir(root) do
dir = Dir.glob("{.svn,.git,.hg,_darcs}").first
end
dir[1..-1] if dir
end
- def delegate
- @delegate ||= VCS.const_get(type.upcase).new
+ attr :root
+
+ #
+ def initialize(root)
+ @root = File.expand_path(root)
end
+ def tags
+ @tags ||= extract_tags.map{ |t| Tag===t ? t : Tag.new(*t) }
+ end
+
+ def changes
+ @changes ||= extract_changes.map{ |c| Change===c ? c : Change.new(*c) }
+ end
+
#
- def method_missing(s, *a, &b)
- delegate.send(s, *a, &b)
+ def extract_tags
+ raise "Not Implemented"
end
+ #
+ def extract_changes
+ raise "Not Implemented"
+ end
+
+ #
+ def changelog
+ ChangeLog.new(changes)
+ end
+
+ #
+ def history(opts={})
+ @history ||= History.new(self, opts)
+ end
+
+ # Provides a bumped version number.
+ def bump(part=nil)
+ return part unless ['major', 'minor', 'patch', ''].include?(part.to_s)
+
+ if tags.last
+ v = tags.last.name # TODO: ensure the latest version
+ else
+ v = '0.0.0'
+ end
+ v = v.split(/\W/) # TODO: preserve split chars
+ case part.to_s
+ when 'major'
+ v[0] = v[0].succ
+ (1..(v.size-1)).each{ |i| v[i] = '0' }
+ v.join('.')
+ when 'minor'
+ v[1] = '0' unless v[1]
+ v[1] = v[1].succ
+ (2..(v.size-1)).each{ |i| v[i] = '0' }
+ v.join('.')
+ when 'patch'
+ v[1] = '0' unless v[1]
+ v[2] = '0' unless v[2]
+ v[2] = v[2].succ
+ (3..(v.size-1)).each{ |i| v[i] = '0' }
+ v.join('.')
+ else
+ v[-1] = '0' unless v[-1]
+ v[-1] = v[-1].succ
+ v.join('.')
+ end
+ end
+
+ private
+
+ # Looks for a "[type]" indicator at the end of the message.
+ def split_type(note)
+ note = note.strip
+ if md = /\A.*?\[(.*?)\]\s*$/.match(note)
+ t = md[1].strip.downcase
+ n = note.sub(/\[#{md[1]}\]\s*$/, "")
+ else
+ n, t = note, nil
+ end
+ n.gsub!(/^\s*?\n/m,'') # remove blank lines
+ return n, t
+ end
+
=begin
# Write the ChangeLog to file.
def write_changelog( log, file )
if File.directory?(file)
@@ -75,8 +147,13 @@
stamp.join(' ')
end
=end
end
+
+ require 'vclog/vcs/svn'
+ require 'vclog/vcs/git'
+ #require 'vclog/vcs/hg'
+ #require 'vclog/vcs/darcs'
end