vclog 1.9.1 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/{HISTORY.rdoc → History.md} +74 -13
  3. data/License.txt +23 -0
  4. data/{README.rdoc → README.md} +46 -45
  5. data/bin/vclog-news +6 -0
  6. data/lib/vclog/adapters/abstract.rb +3 -8
  7. data/lib/vclog/adapters/git.rb +71 -133
  8. data/lib/vclog/adapters/svn.rb +1 -1
  9. data/lib/vclog/change.rb +8 -8
  10. data/lib/vclog/change_point.rb +0 -1
  11. data/lib/vclog/cli/abstract.rb +2 -2
  12. data/lib/vclog/cli/news.rb +29 -0
  13. data/lib/vclog/config.rb +149 -0
  14. data/lib/vclog/core_ext.rb +14 -101
  15. data/lib/vclog/heuristics.rb +37 -5
  16. data/lib/vclog/history_file.rb +15 -3
  17. data/lib/vclog/metadata.rb +1 -16
  18. data/lib/vclog/repo.rb +27 -55
  19. data/lib/vclog/report.rb +38 -20
  20. data/lib/vclog/tag.rb +19 -6
  21. data/lib/vclog/version.rb +3 -0
  22. data/man/man1/index.txt +1 -0
  23. data/man/man1/vclog-autotag.1.ronn +1 -1
  24. data/man/man1/vclog-bump.1.ronn +1 -1
  25. data/man/man1/vclog-news.1.ronn +25 -0
  26. data/man/man1/vclog-version.1.ronn +1 -1
  27. metadata +109 -108
  28. data/.ruby +0 -61
  29. data/COPYING.rdoc +0 -32
  30. data/features/git.feature +0 -86
  31. data/features/hg.feature +0 -86
  32. data/features/step_definitions/history_steps.rb +0 -29
  33. data/features/step_definitions/repo_steps.rb +0 -72
  34. data/features/support/ae.rb +0 -1
  35. data/features/support/aruba.rb +0 -5
  36. data/features/support/loadpath.rb +0 -2
  37. data/features/support/repo.rb +0 -19
  38. data/features/svn.feature +0 -86
  39. data/lib/vclog.yml +0 -61
  40. data/man/man1/vclog-autotag.1 +0 -29
  41. data/man/man1/vclog-autotag.1.html +0 -117
  42. data/man/man1/vclog-bump.1 +0 -23
  43. data/man/man1/vclog-bump.1.html +0 -111
  44. data/man/man1/vclog-version.1 +0 -16
  45. data/man/man1/vclog-version.1.html +0 -100
  46. data/man/man1/vclog.1 +0 -51
  47. data/man/man1/vclog.1.html +0 -131
  48. data/test/unit/case_metadata.rb +0 -11
  49. data/test/unit/helper.rb +0 -4
data/lib/vclog/change.rb CHANGED
@@ -12,19 +12,19 @@ module VCLog
12
12
  attr_accessor :id
13
13
 
14
14
  # Date/time of commit.
15
- attr_accessor :date
15
+ attr_reader :date
16
16
 
17
17
  # Committer.
18
- attr_accessor :author
18
+ attr_reader :author
19
19
 
20
20
  # Commit message.
21
- attr_accessor :message
21
+ attr_reader :message
22
22
 
23
23
  # List of files changed in the commit.
24
24
  attr_accessor :files
25
25
 
26
26
  # Type of change, as assigned by hueristics.
27
- attr_accessor :type
27
+ attr_reader :type
28
28
 
29
29
  # The priority level of this change, as assigned by hueristics.
30
30
  # This can be `nil`, as Heuristics will always make sure a
@@ -37,7 +37,7 @@ module VCLog
37
37
  # ANSI color to apply. Actually this can be a list
38
38
  # of any support ansi gem terms, but usually it's
39
39
  # just the color term, such as `:red`.
40
- attr_accessor :color
40
+ attr_reader :color
41
41
 
42
42
  # Setup new Change instance.
43
43
  def initialize(data={})
@@ -69,11 +69,11 @@ module VCLog
69
69
  # Set the commit message.
70
70
  #
71
71
  def message=(msg)
72
- @message = msg
72
+ @message = msg = msg.to_s
73
73
 
74
74
  lines = msg.lines.to_a
75
- @summary = lines.first.strip
76
- @details = lines[1..-1].join('').strip
75
+ @summary = lines.first.to_s.strip
76
+ @details = lines.drop(1).join('').strip
77
77
 
78
78
  msg
79
79
  end
@@ -42,7 +42,6 @@ module VCLog
42
42
  if @change.respond_to?(s)
43
43
  @change.send(s,*a,&b)
44
44
  else
45
- p caller
46
45
  super(s,*a,&b)
47
46
  end
48
47
  end
@@ -21,8 +21,8 @@ module VCLog
21
21
  if $DEBUG
22
22
  raise err
23
23
  else
24
- puts err.message
25
- exit -1
24
+ $stderr.puts err.message
25
+ exit(-1)
26
26
  end
27
27
  end
28
28
 
@@ -0,0 +1,29 @@
1
+ require 'vclog/cli/abstract'
2
+
3
+ module VCLog::CLI
4
+
5
+ #
6
+ class News < Abstract
7
+
8
+ #
9
+ def self.terms
10
+ ['news']
11
+ end
12
+
13
+ #
14
+ def parser
15
+ super do |opt|
16
+ opt.banner = "Usage: vclog-news"
17
+ opt.separator(" ")
18
+ opt.separator("Display first release note from history file.")
19
+ end
20
+ end
21
+
22
+ #
23
+ def execute
24
+ puts repo.history_file.news #(version)
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,149 @@
1
+ require 'vclog/heuristics'
2
+
3
+ module VCLog
4
+
5
+ # Get/set master configruation(s).
6
+ def self.configure(&block)
7
+ @config ||= []
8
+ @config << block if block
9
+ @config
10
+ end
11
+
12
+ # Encapsulates configuration settings for running vclog.
13
+ #
14
+ # We recommend putting vclog configuration in a project's `etc/vclog.rb`
15
+ # file. For Rails projects, however, `config/vclog.rb` can be used. If
16
+ # usig a subdirectory is not suitable to a project then simply using
17
+ # the more traditional `.vclog` file works too.
18
+ #
19
+ class Config
20
+
21
+ # File glob for identifying the project's root directory.
22
+ #
23
+ # NOTE: SVN support is limited to repos with a trunk directory.
24
+ ROOT_GLOB = "{.git,.hg,_darcs,.svn/trunk}"
25
+
26
+ #
27
+ # Default vclog config file glob looks for these possible matches:
28
+ #
29
+ # * vclog.rb
30
+ # * etc/vclog.rb
31
+ # * config/vclog.rb
32
+ #
33
+ # The configuration file can also be a hidden dot file if preferred:
34
+ #
35
+ # * .vclog
36
+ # * .etc/vclog.rb
37
+ # * .config/vclog.rb
38
+ #
39
+ # Root files have precedence over files in subdirectories, and the `.rb`
40
+ # file extension is optional in all cases.
41
+ #
42
+ FILE_GLOBS = [ '{,.}vclog{,.rb}', '{.,}{etc/,config/}vclog{,.rb}' ]
43
+
44
+ #
45
+ #
46
+ #
47
+ def initialize(options={})
48
+ @root = options[:root] || lookup_root
49
+ @level = options[:level] || 0
50
+ @force = options[:force] || false
51
+ @version = options[:version]
52
+ end
53
+
54
+ #
55
+ # Project's root directory.
56
+ #
57
+ attr :root
58
+
59
+ #
60
+ # Default change level.
61
+ #
62
+ def level
63
+ heuristics.level
64
+ end
65
+
66
+ #
67
+ # Force mode active?
68
+ #
69
+ def force?
70
+ @force
71
+ end
72
+
73
+ #
74
+ # Indicates the version of HEAD.
75
+ #
76
+ def version
77
+ @version
78
+ end
79
+
80
+ #
81
+ # Load heuristics.
82
+ #
83
+ def heuristics
84
+ @heuristics ||= (
85
+ if file
86
+ Heuristics.load(file)
87
+ else
88
+ h = Heuristics.new
89
+ if config = VCLog.configure
90
+ config.each{ |c| c.call(h) }
91
+ end
92
+ h
93
+ end
94
+ )
95
+ end
96
+
97
+ #
98
+ # Which version control system?
99
+ #
100
+ def vcs_type
101
+ @vcs_type ||= (
102
+ dir = nil
103
+ Dir.chdir(root) do
104
+ dir = Dir.glob("{.git,.hg,.svn,_darcs}").first
105
+ end
106
+ dir[1..-1] if dir
107
+ )
108
+ end
109
+
110
+ #
111
+ # The vclog config file.
112
+ #
113
+ def file
114
+ FILE_GLOBS.each do |glob|
115
+ found = Dir.glob(File.join(root, glob)).find{ |f| File.file?(f) }
116
+ return found if found
117
+ end
118
+ nil
119
+ end
120
+
121
+ #
122
+ # Find project root. This searches up from the current working
123
+ # directory for a source control manager directory.
124
+ #
125
+ # * `.git/`
126
+ # * `.hg/`
127
+ # * `_darcs/`
128
+ # * `.svn/trunk`
129
+ #
130
+ # If all else fails the current directory is returned.
131
+ #
132
+ def lookup_root
133
+ root = nil
134
+ dir = Dir.pwd
135
+ loop do
136
+ if Dir.glob(File.join(dir, ROOT_GLOB)).first
137
+ root = dir
138
+ break
139
+ end
140
+ parent = File.dirname(dir)
141
+ break if parent == dir
142
+ dir = parent
143
+ end
144
+ root || Dir.pwd
145
+ end
146
+
147
+ end
148
+
149
+ end
@@ -1,108 +1,21 @@
1
+ require 'ostruct'
1
2
  require 'facets/string/fold'
2
- require 'facets/string/indent'
3
- require 'facets/string/tabto'
4
- require 'facets/string/margin'
5
- require 'facets/enumerable/group_by'
6
3
  require 'facets/kernel/ask'
7
4
 
8
- =begin
9
-
10
- module VCLog
11
-
12
- # Extensions for String class.
13
- # Taken from Facets.
14
- module String
15
-
16
- # Provides a margin controlled string.
17
- #
18
- # x = %Q{
19
- # | This
20
- # | is
21
- # | margin controlled!
22
- # }.margin
23
- #
24
- #
25
- # NOTE: This may still need a bit of tweaking.
26
- #
27
- # CREDIT: Trans
28
-
29
- def margin(n=0)
30
- #d = /\A.*\n\s*(.)/.match( self )[1]
31
- #d = /\A\s*(.)/.match( self)[1] unless d
32
- d = ((/\A.*\n\s*(.)/.match(self)) ||
33
- (/\A\s*(.)/.match(self)))[1]
34
- return '' unless d
35
- if n == 0
36
- gsub(/\n\s*\Z/,'').gsub(/^\s*[#{d}]/, '')
37
- else
38
- gsub(/\n\s*\Z/,'').gsub(/^\s*[#{d}]/, ' ' * n)
39
- end
40
- end
41
-
42
- # Preserves relative tabbing.
43
- # The first non-empty line ends up with n spaces before nonspace.
44
- #
45
- # CREDIT: Gavin Sinclair
46
-
47
- def tabto(n)
48
- if self =~ /^( *)\S/
49
- indent(n - $1.length)
50
- else
51
- self
52
- end
53
- end
54
-
55
- # Indent left or right by n spaces.
56
- # (This used to be called #tab and aliased as #indent.)
57
- #
58
- # CREDIT: Gavin Sinclair
59
- # CREDIT: Trans
60
-
61
- def indent(n)
62
- if n >= 0
63
- gsub(/^/, ' ' * n)
64
- else
65
- gsub(/^ {0,#{-n}}/, "")
66
- end
67
- end
68
-
69
- end
70
-
71
- end
72
-
73
- class String #:nodoc:
74
- include VCLog::String
5
+ class OpenStruct
6
+ method_undef(:type) if method_defined?(:type)
75
7
  end
76
8
 
77
-
78
- # Core extension
79
-
80
- module Enumerable
81
-
82
- unless defined?(group_by) or defined?(::ActiveSupport) # 1.9 or ActiveSupport
83
-
84
- # #group_by is used to group items in a collection by something they
85
- # have in common. The common factor is the key in the resulting hash, the
86
- # array of like elements is the value.
87
- #
88
- # (1..5).group_by { |n| n % 3 }
89
- # #=> { 0 => [3], 1 => [1, 4], 2 => [2,5] }
90
- #
91
- # ["I had", 1, "dollar and", 50, "cents"].group_by { |e| e.class }
92
- # #=> { String => ["I had","dollar and","cents"], Fixnum => [1,50] }
93
- #
94
- # CREDIT: Erik Veenstra
95
-
96
- def group_by #:yield:
97
- #h = k = e = nil
98
- r = Hash.new
99
- each{ |e| (r[yield(e)] ||= []) << e }
100
- r
9
+ class String
10
+ # Indent the text so its first line with any content starts at column
11
+ # +n+, keeping the relative indentation of the lines after it. Facets
12
+ # had this until 4.0.
13
+ def tabto(n)
14
+ lead = self[/^([ \t]*)\S/, 1].to_s.size
15
+ if n >= lead
16
+ gsub(/^(?=.)/, ' ' * (n - lead))
17
+ else
18
+ gsub(/^[ \t]{0,#{lead - n}}/, '')
101
19
  end
102
-
103
- end
104
-
20
+ end unless method_defined?(:tabto)
105
21
  end
106
-
107
- =end
108
-
@@ -8,6 +8,7 @@ module VCLog
8
8
  #
9
9
  class Heuristics
10
10
 
11
+ #
11
12
  # Load heuristics from a designated file.
12
13
  #
13
14
  # @param [String] file
@@ -18,7 +19,19 @@ module VCLog
18
19
  new{ instance_eval(File.read(file), file) }
19
20
  end
20
21
 
21
- # Setup new heurtistics set.
22
+ #
23
+ # Load heuristics given a script.
24
+ #
25
+ # @param [String] script
26
+ # Configuration script.
27
+ #
28
+ def self.eval(script, file='(eval)', line=0)
29
+ new{ instance_eval(script, file, line) }
30
+ end
31
+
32
+ #
33
+ # Initialize new heurtistics set.
34
+ #
22
35
  def initialize(&block)
23
36
  @rules = []
24
37
 
@@ -34,6 +47,7 @@ module VCLog
34
47
  end
35
48
  end
36
49
 
50
+ #
37
51
  # Apply heuristics to a commit.
38
52
  #
39
53
  # @param [Change] commit
@@ -57,13 +71,17 @@ module VCLog
57
71
  commit.color = color
58
72
  end
59
73
 
74
+ #
60
75
  # Define a new rule.
76
+ #
61
77
  def on(pattern=nil, &block)
62
78
  @rules << Rule.new(pattern, &block)
63
79
  end
64
80
 
81
+ #
65
82
  # Convenience method for setting-up commit types, which can
66
83
  # be easily assigned, setting both label and level in one go.
84
+ #
67
85
  def type(type, level, label)
68
86
  @types[type.to_sym] = Type.new(type, level, label)
69
87
  end
@@ -71,6 +89,7 @@ module VCLog
71
89
  # @deprecated
72
90
  alias_method :set, :type
73
91
 
92
+ #
74
93
  # Access to defined types.
75
94
  #
76
95
  # @example
@@ -78,6 +97,7 @@ module VCLog
78
97
  #
79
98
  attr :types
80
99
 
100
+ #
81
101
  # Set color list. The center element cooresponds to `level=0`.
82
102
  # Elements before the center are incrementally higher levels
83
103
  # and those after are lower.
@@ -89,7 +109,17 @@ module VCLog
89
109
  @colors = list
90
110
  end
91
111
 
112
+ #
113
+ # Set default level.
114
+ #
115
+ def level(integer=nil)
116
+ @level = integer.to_i if integer
117
+ @level
118
+ end
119
+
120
+ #
92
121
  # Default settings.
122
+ #
93
123
  def default
94
124
  type :major, 3, "Major Enhancements"
95
125
  type :minor, 2, "Minor Enhancements"
@@ -99,30 +129,32 @@ module VCLog
99
129
  type :test, -2, "Test/Spec Adjustments"
100
130
  type :admin, -3, "Administrative Changes"
101
131
 
102
- on /\A(\w+):/ do |commit, md|
132
+ on(/\A(\w+):/) do |commit, md|
103
133
  type = md[1].to_sym
104
134
  commit.type = type
105
135
  commit.message = commit.message.sub(md[0],'').strip
106
136
  true
107
137
  end
108
138
 
109
- on /\[(\w+)\]\s*$/ do |commit, md|
139
+ on(/\[(\w+)\]\s*$/) do |commit, md|
110
140
  type = md[1].to_sym
111
141
  commit.type = type
112
142
  commit.message = commit.message.sub(md[0],'').strip
113
143
  true
114
144
  end
115
145
 
116
- on /updated? (README|PROFILE|PACKAGE|VERSION|MANIFEST)/ do |commit|
146
+ on(/updated? (README|PROFILE|PACKAGE|VERSION|MANIFEST)/) do |commit|
117
147
  commit.type = :admin
118
148
  end
119
149
 
120
- on /(bump|bumped|prepare) version/ do |commit|
150
+ on(/(bump|bumped|prepare) version/) do |commit|
121
151
  commit.type = :admin
122
152
  end
123
153
  end
124
154
 
155
+ #
125
156
  # Work on next-gen default heuristics.
157
+ #
126
158
  def default2
127
159
  type :major, 3, "Major Enhancements"
128
160
  type :minor, 2, "Minor Enhancements"
@@ -6,7 +6,7 @@ module VCLog
6
6
  #
7
7
  class HistoryFile
8
8
 
9
- FILE = '{HISTORY,HISTORY.*}'
9
+ FILE = /\Ahistory(\.\w+)?\z/i
10
10
 
11
11
  LINE = /^[=#]/
12
12
  VERS = /(\d+[._])+\d+/
@@ -20,14 +20,15 @@ module VCLog
20
20
 
21
21
  # Setup new HistoryFile instance.
22
22
  def initialize(source=nil)
23
+ source = source.to_s
23
24
  if File.file?(source)
24
25
  @file = source
25
26
  @root = File.dirname(source)
26
27
  elsif File.directory?(source)
27
- @file = Dir.glob(File.join(source,FILE), CASEFOLD).first
28
+ @file = find(source)
28
29
  @root = source
29
30
  else
30
- @file = Dir.glob(FILE).first
31
+ @file = find(Dir.pwd)
31
32
  @root = Dir.pwd
32
33
  end
33
34
  raise "no history file" unless @file
@@ -35,6 +36,12 @@ module VCLog
35
36
  @tags = extract_tags
36
37
  end
37
38
 
39
+ # Find the history file in a directory, whatever its case.
40
+ def find(dir)
41
+ name = Dir.children(dir).sort.find{ |f| FILE =~ f && File.file?(File.join(dir, f)) }
42
+ name && File.join(dir, name)
43
+ end
44
+
38
45
  # Parse history file.
39
46
  def extract_tags
40
47
  tags = []
@@ -59,6 +66,11 @@ module VCLog
59
66
  end
60
67
  end
61
68
 
69
+ #
70
+ def news
71
+ tags.first.message
72
+ end
73
+
62
74
  end
63
75
 
64
76
  end
@@ -1,16 +1 @@
1
- module VCLog
2
-
3
- def self.metadata
4
- @metadata ||= (
5
- require 'yaml'
6
- YAML.load_file(File.dirname(__FILE__) + '/../vclog.yml')
7
- )
8
- end
9
-
10
- def self.const_missing(name)
11
- key = name.to_s.downcase
12
- metadata.key?(key) ? metadata[key] : super(name)
13
- end
14
-
15
- end
16
-
1
+ require 'vclog/version'