mercurial-ruby 0.7.4 → 0.7.5
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.
- data/VERSION +1 -1
- data/lib/mercurial-ruby/blame.rb +20 -1
- data/lib/mercurial-ruby.rb +1 -1
- data/mercurial-ruby.gemspec +1 -1
- data/test/test_blame.rb +12 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.5
|
data/lib/mercurial-ruby/blame.rb
CHANGED
@@ -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(
|
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,
|
data/lib/mercurial-ruby.rb
CHANGED
data/mercurial-ruby.gemspec
CHANGED
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:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 5
|
10
|
+
version: 0.7.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ilya Sabanin
|