vclog 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,106 @@
1
+ require 'facets/string/indent'
2
+ require 'facets/string/tabto'
3
+ require 'facets/string/margin'
4
+ require 'facets/enumerable/group_by'
5
+
6
+ =begin
7
+
8
+ module VCLog
9
+
10
+ # Extensions for String class.
11
+ # Taken from Facets.
12
+ module String
13
+
14
+ # Provides a margin controlled string.
15
+ #
16
+ # x = %Q{
17
+ # | This
18
+ # | is
19
+ # | margin controlled!
20
+ # }.margin
21
+ #
22
+ #
23
+ # NOTE: This may still need a bit of tweaking.
24
+ #
25
+ # CREDIT: Trans
26
+
27
+ def margin(n=0)
28
+ #d = /\A.*\n\s*(.)/.match( self )[1]
29
+ #d = /\A\s*(.)/.match( self)[1] unless d
30
+ d = ((/\A.*\n\s*(.)/.match(self)) ||
31
+ (/\A\s*(.)/.match(self)))[1]
32
+ return '' unless d
33
+ if n == 0
34
+ gsub(/\n\s*\Z/,'').gsub(/^\s*[#{d}]/, '')
35
+ else
36
+ gsub(/\n\s*\Z/,'').gsub(/^\s*[#{d}]/, ' ' * n)
37
+ end
38
+ end
39
+
40
+ # Preserves relative tabbing.
41
+ # The first non-empty line ends up with n spaces before nonspace.
42
+ #
43
+ # CREDIT: Gavin Sinclair
44
+
45
+ def tabto(n)
46
+ if self =~ /^( *)\S/
47
+ indent(n - $1.length)
48
+ else
49
+ self
50
+ end
51
+ end
52
+
53
+ # Indent left or right by n spaces.
54
+ # (This used to be called #tab and aliased as #indent.)
55
+ #
56
+ # CREDIT: Gavin Sinclair
57
+ # CREDIT: Trans
58
+
59
+ def indent(n)
60
+ if n >= 0
61
+ gsub(/^/, ' ' * n)
62
+ else
63
+ gsub(/^ {0,#{-n}}/, "")
64
+ end
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ class String #:nodoc:
72
+ include VCLog::String
73
+ end
74
+
75
+
76
+ # Core extension
77
+
78
+ module Enumerable
79
+
80
+ unless defined?(group_by) or defined?(::ActiveSupport) # 1.9 or ActiveSupport
81
+
82
+ # #group_by is used to group items in a collection by something they
83
+ # have in common. The common factor is the key in the resulting hash, the
84
+ # array of like elements is the value.
85
+ #
86
+ # (1..5).group_by { |n| n % 3 }
87
+ # #=> { 0 => [3], 1 => [1, 4], 2 => [2,5] }
88
+ #
89
+ # ["I had", 1, "dollar and", 50, "cents"].group_by { |e| e.class }
90
+ # #=> { String => ["I had","dollar and","cents"], Fixnum => [1,50] }
91
+ #
92
+ # CREDIT: Erik Veenstra
93
+
94
+ def group_by #:yield:
95
+ #h = k = e = nil
96
+ r = Hash.new
97
+ each{ |e| (r[yield(e)] ||= []) << e }
98
+ r
99
+ end
100
+
101
+ end
102
+
103
+ end
104
+
105
+ =end
106
+
@@ -0,0 +1,83 @@
1
+ module VCLog
2
+
3
+ class VCS
4
+
5
+ # = DARCS
6
+ #
7
+ # Provide Darcs SCM revision tools.
8
+ #
9
+ # TODO: This needs to be fixed.
10
+ #
11
+ class DARCS
12
+
13
+ ### Is a darcs repository?
14
+ def repository?
15
+ File.directory?('_darcs')
16
+ end
17
+
18
+ ### This is also a module function.
19
+ module_function :repository?
20
+
21
+ ### Cached Changelog.
22
+ def changelog
23
+ @changelog ||= generate_changelog
24
+ end
25
+
26
+ ### Generate Changelog object.
27
+ def generate_changelog
28
+ raise "not a darcs repository" unless repository?
29
+
30
+ log = Changelog.new
31
+
32
+ txt = `darcs changes` #--repo=#{@repository}`
33
+
34
+ txt.each_line do |line|
35
+ case line
36
+ when /^\s*$/
37
+ when /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/
38
+ when /^\s*tagged/
39
+ log << $'
40
+ log << "\n"
41
+ else
42
+ log << line
43
+ log << "\n"
44
+ end
45
+ end
46
+
47
+ return log
48
+ end
49
+
50
+ ### Retrieve the "revision number" from the darcs tree.
51
+ def calculate_version
52
+ raise "not a darcs repository" unless repository?
53
+
54
+ status = info.status
55
+
56
+ changes = `darcs changes`
57
+ count = 0
58
+ tag = "0.0"
59
+
60
+ changes.each("\n\n") do |change|
61
+ head, title, desc = change.split("\n", 3)
62
+ if title =~ /^ \*/
63
+ # Normal change.
64
+ count += 1
65
+ elsif title =~ /tagged (.*)/
66
+ # Tag. We look for these.
67
+ tag = $1
68
+ break
69
+ else
70
+ warn "Unparsable change: #{change}"
71
+ end
72
+ end
73
+ ver = "#{tag}.#{count.to_s}"
74
+
75
+ return ver
76
+ #format_version_stamp(ver, status) # ,released)
77
+ end
78
+
79
+ end
80
+
81
+ end
82
+ end
83
+
@@ -0,0 +1,54 @@
1
+ module VCLog
2
+
3
+ class VCS
4
+
5
+ ### = GIT
6
+ ###
7
+ class GIT
8
+
9
+ def initialize
10
+
11
+ end
12
+
13
+ #
14
+ def changelog
15
+ @changelog ||= generate_changelog
16
+ end
17
+
18
+ #
19
+ def generate_changelog
20
+ log = Changelog.new
21
+
22
+ changelog ||= `git-log`.strip
23
+
24
+ changes = changelog.split(/^commit/m)
25
+
26
+ changes.shift # throw the first (empty) entry away
27
+
28
+ changes.each do |text|
29
+ date, who, rev, msg = nil, nil, nil, []
30
+ text.each_line do |line|
31
+ unless rev
32
+ rev = line.strip
33
+ next
34
+ end
35
+ if md = /^Author:(.*?)$/.match(line)
36
+ who = md[1]
37
+ elsif md = /^Date:(.*?)$/m.match(line)
38
+ date = Time.parse(md[1])
39
+ else
40
+ msg << line.strip
41
+ end
42
+ end
43
+ log.change(date, who, rev, msg.join("\n"))
44
+ end
45
+
46
+ @changelog = log
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
File without changes
@@ -0,0 +1,58 @@
1
+ module VCLog
2
+
3
+ class VCS
4
+
5
+ # = SVN
6
+ #
7
+ # Raw SVN format:
8
+ #
9
+ # ------------------------------------------------------------------------
10
+ # r34 | transami | 2006-08-02 22:10:11 -0400 (Wed, 02 Aug 2006) | 2 lines
11
+ #
12
+ # change foo to work better
13
+ #
14
+ class SVN
15
+
16
+ def initialize
17
+ end
18
+
19
+ ###
20
+ def changelog
21
+ @changelog ||= generate_changelog
22
+ end
23
+
24
+ ###
25
+ def generate_changelog
26
+ log = Changelog.new
27
+
28
+ txt = `svn log`.strip
29
+
30
+ com = txt.split(/^[-]+$/)
31
+
32
+ com.each do |msg|
33
+ msg = msg.strip
34
+
35
+ next if msg.empty?
36
+
37
+ idx = msg.index("\n")
38
+ head = msg.slice!(0...idx)
39
+ rev, who, date, cnt = *head.split('|')
40
+
41
+ rev = rev.strip
42
+ who = who.strip
43
+ msg = msg.strip
44
+
45
+ date = Time.parse(date)
46
+
47
+ log.change(date, who, rev, msg)
48
+ end
49
+
50
+ @changelog = log
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+
data/lib/vclog/vcs.rb ADDED
@@ -0,0 +1,82 @@
1
+ module VCLog
2
+
3
+ require 'time'
4
+ require 'vclog/changelog'
5
+ require 'vclog/vcs/svn'
6
+ require 'vclog/vcs/git'
7
+ #require 'vclog/vcs/hg'
8
+ #require 'vclog/vcs/darcs'
9
+
10
+ # TODO: Might we have a NO-VCS changelog based on
11
+ # LOG: entries in source files?
12
+
13
+ # = Version Control System
14
+ class VCS
15
+
16
+ attr :type
17
+
18
+ def initialize(root=nil)
19
+ @root = root || Dir.pwd
20
+ @type = read_type
21
+ raise ArgumentError, "Not a recognized version control system." unless @type
22
+ end
23
+
24
+ def read_type
25
+ dir = nil
26
+ Dir.chdir(@root) do
27
+ dir = Dir.glob("{.svn,.git,.hg,_darcs}").first
28
+ end
29
+ dir[1..-1] if dir
30
+ end
31
+
32
+ def delegate
33
+ @delegate ||= VCS.const_get(type.upcase).new
34
+ end
35
+
36
+ #
37
+ def method_missing(s, *a, &b)
38
+ delegate.send(s, *a, &b)
39
+ end
40
+
41
+ =begin
42
+ # Write the ChangeLog to file.
43
+
44
+ def write_changelog( log, file )
45
+ if File.directory?(file)
46
+ file = File.join( file, DEFAULT_CHANGELOG_FILE )
47
+ end
48
+ File.open(file,'w+'){ |f| f << log }
49
+ puts "Change log written to #{file}."
50
+ end
51
+
52
+ # Write version stamp to file.
53
+
54
+ def write_version( stamp, file )
55
+ if File.directory?(file)
56
+ file = File.join( file, DEFAULT_VERSION_FILE )
57
+ end
58
+ File.open(file,'w'){ |f| f << stamp }
59
+ puts "#{file} saved."
60
+ end
61
+
62
+ # Format the version stamp.
63
+
64
+ def format_version_stamp( version, status=nil, date=nil )
65
+ if date.respond_to?(:strftime)
66
+ date = date.strftime("%Y-%m-%d")
67
+ else
68
+ date = Time.now.strftime("%Y-%m-%d")
69
+ end
70
+ status = nil if status.to_s.strip.empty?
71
+ stamp = []
72
+ stamp << version
73
+ stamp << status if status
74
+ stamp << "(#{date})"
75
+ stamp.join(' ')
76
+ end
77
+ =end
78
+
79
+ end
80
+
81
+ end
82
+
data/meta/authors ADDED
@@ -0,0 +1 @@
1
+ Trans <transfire@gmail.com>
data/meta/created ADDED
@@ -0,0 +1 @@
1
+ 2006-05-09
data/meta/description ADDED
@@ -0,0 +1 @@
1
+ VCLog is a cross-VCS/SCM ChangeLog generator.
data/meta/homepage ADDED
@@ -0,0 +1 @@
1
+ http://proutils.rubyforge.org/vclog
data/meta/license ADDED
@@ -0,0 +1 @@
1
+ GPL
data/meta/mailinglist ADDED
@@ -0,0 +1 @@
1
+ tigerops-community@rubyforge.org
data/meta/package ADDED
@@ -0,0 +1 @@
1
+ vclog
data/meta/project ADDED
@@ -0,0 +1 @@
1
+ proutils
data/meta/repository ADDED
@@ -0,0 +1,2 @@
1
+ git://rubyforge.org/proutils.git
2
+ gitosis@rubyforge.org:proutils.git
data/meta/requires ADDED
@@ -0,0 +1 @@
1
+ facets > 2.4
data/meta/sitemap ADDED
@@ -0,0 +1 @@
1
+ doc/rdoc: vclog
data/meta/summary ADDED
@@ -0,0 +1 @@
1
+ Cross-VCS/SCM ChangeLog Generator
data/meta/title ADDED
@@ -0,0 +1 @@
1
+ VCLog
data/meta/version ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vclog
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Trans <transfire@gmail.com>
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-05 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: facets
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: VCLog is a cross-VCS/SCM ChangeLog generator.
26
+ email: transfire@gmail.com
27
+ executables:
28
+ - vclog
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ - MANIFEST
34
+ - RELEASE
35
+ - HISTORY
36
+ - COPYING
37
+ files:
38
+ - RELEASE
39
+ - README
40
+ - HISTORY
41
+ - meta/created
42
+ - meta/repository
43
+ - meta/homepage
44
+ - meta/summary
45
+ - meta/package
46
+ - meta/title
47
+ - meta/version
48
+ - meta/license
49
+ - meta/sitemap
50
+ - meta/mailinglist
51
+ - meta/authors
52
+ - meta/requires
53
+ - meta/project
54
+ - meta/description
55
+ - lib/vclog/changelog.rb
56
+ - lib/vclog/core_ext.rb
57
+ - lib/vclog/vcs/darcs.rb
58
+ - lib/vclog/vcs/git.rb
59
+ - lib/vclog/vcs/svn.rb
60
+ - lib/vclog/vcs/hg.rb
61
+ - lib/vclog/vcs.rb
62
+ - bin/vclog
63
+ - COPYING
64
+ - MANIFEST
65
+ has_rdoc: true
66
+ homepage: http://proutils.rubyforge.org/vclog
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --inline-source
72
+ - --title
73
+ - vclog api
74
+ - --main
75
+ - README
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ version:
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ requirements: []
91
+
92
+ rubyforge_project: proutils
93
+ rubygems_version: 1.3.4
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: VCLog is a cross-VCS/SCM ChangeLog generator.
97
+ test_files: []
98
+