mercurial-ruby 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.4
1
+ 0.7.5
@@ -8,6 +8,9 @@ module Mercurial
8
8
  # look documentation for {Mercurial::BlameFactory BlameFactory}.
9
9
  #
10
10
  class Blame
11
+
12
+ METADATA_RE = /^(.+) (\w{12}): *(\d+): /
13
+ METADATA_AND_CODE_RE = /^(.+) (\w{12}): *(\d+): (.*)$/
11
14
 
12
15
  attr_reader :repository
13
16
  attr_reader :contents
@@ -17,13 +20,29 @@ module Mercurial
17
20
  @contents = data
18
21
  end
19
22
 
23
+ #
24
+ # Returns code only as a String without the usual blame metadata.
25
+ # Useful for code highlighting.
26
+ #
27
+ def contents_without_metadata
28
+ contents.gsub(METADATA_RE, '')
29
+ end
30
+
31
+ #
32
+ # Returns an Array of blame metadata for every line of blame.
33
+ # Does not return code itself.
34
+ #
35
+ def raw_metadata
36
+ contents.scan(METADATA_RE)
37
+ end
38
+
20
39
  #
21
40
  # Returns an array of {Mercurial::BlameLine BlameLine} instances.
22
41
  #
23
42
  def lines
24
43
  [].tap do |result|
25
44
  contents.each do |line|
26
- author, revision, linenum, text = line.scan(/^(.+) (\w{12}): *(\d+): (.*)$/).first
45
+ author, revision, linenum, text = line.scan(METADATA_AND_CODE_RE).first
27
46
  result << BlameLine.new(
28
47
  :author => author,
29
48
  :revision => revision,
@@ -6,7 +6,7 @@ require 'time'
6
6
  #
7
7
  module Mercurial
8
8
 
9
- VERSION = '0.7.4'
9
+ VERSION = '0.7.5'
10
10
 
11
11
  class Error < RuntimeError; end
12
12
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mercurial-ruby}
8
- s.version = "0.7.4"
8
+ s.version = "0.7.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ilya Sabanin"]
data/test/test_blame.rb CHANGED
@@ -24,5 +24,17 @@ describe Mercurial::Blame do
24
24
  lines[3].num.must_equal 4
25
25
  lines[3].contents.must_equal ''
26
26
  end
27
+
28
+ it "should return metadata separately from code" do
29
+ blame = @factory.for_path('diff-test.rb')
30
+ blame.raw_metadata.size.must_equal 26
31
+ blame.raw_metadata[6].must_equal(['ilya', '88b5cc786015', '7'])
32
+ end
33
+
34
+ it "should return code separately from metadata" do
35
+ blame = @factory.for_path('diff-test.rb')
36
+ blame.contents_without_metadata.split("\n").size.must_equal 26
37
+ blame.contents_without_metadata.split("\n")[12].must_equal " helper_method :repository_scope?"
38
+ end
27
39
 
28
40
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mercurial-ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 4
10
- version: 0.7.4
9
+ - 5
10
+ version: 0.7.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ilya Sabanin