gitreport 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/Gemfile.lock +0 -1
- data/VERSION +1 -1
- data/gitreport.gemspec +25 -13
- data/lib/git/author.rb +14 -0
- data/lib/git/base.rb +479 -0
- data/lib/git/branch.rb +104 -0
- data/lib/git/branches.rb +48 -0
- data/lib/git/diff.rb +146 -0
- data/lib/git/index.rb +5 -0
- data/lib/git/lib.rb +720 -0
- data/lib/git/log.rb +117 -0
- data/lib/git/object.rb +273 -0
- data/lib/git/path.rb +27 -0
- data/lib/git/remote.rb +40 -0
- data/lib/git/repository.rb +4 -0
- data/lib/git/stash.rb +27 -0
- data/lib/git/stashes.rb +44 -0
- data/lib/git/status.rb +110 -0
- data/lib/git/working_directory.rb +4 -0
- data/lib/git.rb +156 -0
- metadata +109 -163
data/lib/git/branches.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module Git
|
2
|
+
|
3
|
+
# object that holds all the available branches
|
4
|
+
class Branches
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize(base)
|
8
|
+
@branches = {}
|
9
|
+
|
10
|
+
@base = base
|
11
|
+
|
12
|
+
@base.lib.branches_all.each do |b|
|
13
|
+
@branches[b[0]] = Git::Branch.new(@base, b[0])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def local
|
18
|
+
self.select { |b| !b.remote }
|
19
|
+
end
|
20
|
+
|
21
|
+
def remote
|
22
|
+
self.select { |b| b.remote }
|
23
|
+
end
|
24
|
+
|
25
|
+
# array like methods
|
26
|
+
|
27
|
+
def size
|
28
|
+
@branches.size
|
29
|
+
end
|
30
|
+
|
31
|
+
def each(&block)
|
32
|
+
@branches.values.each(&block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def [](symbol)
|
36
|
+
@branches[symbol.to_s]
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
out = ''
|
41
|
+
@branches.each do |k, b|
|
42
|
+
out << (b.current ? '* ' : ' ') << b.to_s << "\n"
|
43
|
+
end
|
44
|
+
out
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/lib/git/diff.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
module Git
|
2
|
+
|
3
|
+
# object that holds the last X commits on given branch
|
4
|
+
class Diff
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize(base, from = nil, to = nil)
|
8
|
+
@base = base
|
9
|
+
@from = from.to_s
|
10
|
+
@to = to.to_s
|
11
|
+
|
12
|
+
@path = nil
|
13
|
+
@full_diff = nil
|
14
|
+
@full_diff_files = nil
|
15
|
+
@stats = nil
|
16
|
+
end
|
17
|
+
attr_reader :from, :to
|
18
|
+
|
19
|
+
def path(path)
|
20
|
+
@path = path
|
21
|
+
return self
|
22
|
+
end
|
23
|
+
|
24
|
+
def size
|
25
|
+
cache_stats
|
26
|
+
@stats[:total][:files]
|
27
|
+
end
|
28
|
+
|
29
|
+
def lines
|
30
|
+
cache_stats
|
31
|
+
@stats[:total][:lines]
|
32
|
+
end
|
33
|
+
|
34
|
+
def deletions
|
35
|
+
cache_stats
|
36
|
+
@stats[:total][:deletions]
|
37
|
+
end
|
38
|
+
|
39
|
+
def insertions
|
40
|
+
cache_stats
|
41
|
+
@stats[:total][:insertions]
|
42
|
+
end
|
43
|
+
|
44
|
+
def stats
|
45
|
+
cache_stats
|
46
|
+
@stats
|
47
|
+
end
|
48
|
+
|
49
|
+
# if file is provided and is writable, it will write the patch into the file
|
50
|
+
def patch(file = nil)
|
51
|
+
cache_full
|
52
|
+
@full_diff
|
53
|
+
end
|
54
|
+
alias_method :to_s, :patch
|
55
|
+
|
56
|
+
# enumerable methods
|
57
|
+
|
58
|
+
def [](key)
|
59
|
+
process_full
|
60
|
+
@full_diff_files.assoc(key)[1]
|
61
|
+
end
|
62
|
+
|
63
|
+
def each(&block) # :yields: each Git::DiffFile in turn
|
64
|
+
process_full
|
65
|
+
@full_diff_files.map { |file| file[1] }.each(&block)
|
66
|
+
end
|
67
|
+
|
68
|
+
class DiffFile
|
69
|
+
attr_accessor :patch, :path, :mode, :src, :dst, :type
|
70
|
+
@base = nil
|
71
|
+
|
72
|
+
def initialize(base, hash)
|
73
|
+
@base = base
|
74
|
+
@patch = hash[:patch]
|
75
|
+
@path = hash[:path]
|
76
|
+
@mode = hash[:mode]
|
77
|
+
@src = hash[:src]
|
78
|
+
@dst = hash[:dst]
|
79
|
+
@type = hash[:type]
|
80
|
+
@binary = hash[:binary]
|
81
|
+
end
|
82
|
+
|
83
|
+
def binary?
|
84
|
+
!!@binary
|
85
|
+
end
|
86
|
+
|
87
|
+
def blob(type = :dst)
|
88
|
+
if type == :src
|
89
|
+
@base.object(@src) if @src != '0000000'
|
90
|
+
else
|
91
|
+
@base.object(@dst) if @dst != '0000000'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def cache_full
|
99
|
+
unless @full_diff
|
100
|
+
@full_diff = @base.lib.diff_full(@from, @to, {:path_limiter => @path})
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def process_full
|
105
|
+
unless @full_diff_files
|
106
|
+
cache_full
|
107
|
+
@full_diff_files = process_full_diff
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def cache_stats
|
112
|
+
unless @stats
|
113
|
+
@stats = @base.lib.diff_stats(@from, @to, {:path_limiter => @path})
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# break up @diff_full
|
118
|
+
def process_full_diff
|
119
|
+
final = {}
|
120
|
+
current_file = nil
|
121
|
+
@full_diff.split("\n").each do |line|
|
122
|
+
if m = /diff --git a\/(.*?) b\/(.*?)/.match(line)
|
123
|
+
current_file = m[1]
|
124
|
+
final[current_file] = {:patch => line, :path => current_file,
|
125
|
+
:mode => '', :src => '', :dst => '', :type => 'modified'}
|
126
|
+
else
|
127
|
+
if m = /index (.......)\.\.(.......)( ......)*/.match(line)
|
128
|
+
final[current_file][:src] = m[1]
|
129
|
+
final[current_file][:dst] = m[2]
|
130
|
+
final[current_file][:mode] = m[3].strip if m[3]
|
131
|
+
end
|
132
|
+
if m = /(.*?) file mode (......)/.match(line)
|
133
|
+
final[current_file][:type] = m[1]
|
134
|
+
final[current_file][:mode] = m[2]
|
135
|
+
end
|
136
|
+
if m = /^Binary files /.match(line)
|
137
|
+
final[current_file][:binary] = true
|
138
|
+
end
|
139
|
+
final[current_file][:patch] << "\n" + line
|
140
|
+
end
|
141
|
+
end
|
142
|
+
final.map { |e| [e[0], DiffFile.new(@base, e[1])] }
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|