blackwinter-git 1.2.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/README +240 -0
- 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 +157 -0
- data/lib/git/index.rb +5 -0
- data/lib/git/lib.rb +743 -0
- data/lib/git/log.rb +121 -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 +87 -0
data/lib/git/diff.rb
ADDED
@@ -0,0 +1,157 @@
|
|
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 = 'HEAD', to = nil)
|
8
|
+
@base = base
|
9
|
+
@from = from.to_s
|
10
|
+
@to = 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
|
+
def index_stats
|
50
|
+
cache_index_stats
|
51
|
+
@index_stats
|
52
|
+
end
|
53
|
+
|
54
|
+
# if file is provided and is writable, it will write the patch into the file
|
55
|
+
def patch(file = nil)
|
56
|
+
cache_full
|
57
|
+
@full_diff
|
58
|
+
end
|
59
|
+
alias_method :to_s, :patch
|
60
|
+
|
61
|
+
# enumerable methods
|
62
|
+
|
63
|
+
def [](key)
|
64
|
+
process_full
|
65
|
+
@full_diff_files.assoc(key)[1]
|
66
|
+
end
|
67
|
+
|
68
|
+
def each(&block) # :yields: each Git::DiffFile in turn
|
69
|
+
process_full
|
70
|
+
@full_diff_files.map { |file| file[1] }.each(&block)
|
71
|
+
end
|
72
|
+
|
73
|
+
class DiffFile
|
74
|
+
attr_accessor :patch, :path, :mode, :src, :dst, :type
|
75
|
+
@base = nil
|
76
|
+
|
77
|
+
def initialize(base, hash)
|
78
|
+
@base = base
|
79
|
+
@patch = hash[:patch]
|
80
|
+
@path = hash[:path]
|
81
|
+
@mode = hash[:mode]
|
82
|
+
@src = hash[:src]
|
83
|
+
@dst = hash[:dst]
|
84
|
+
@type = hash[:type]
|
85
|
+
@binary = hash[:binary]
|
86
|
+
end
|
87
|
+
|
88
|
+
def binary?
|
89
|
+
!!@binary
|
90
|
+
end
|
91
|
+
|
92
|
+
def blob(type = :dst)
|
93
|
+
if type == :src
|
94
|
+
@base.object(@src) if @src != '0000000'
|
95
|
+
else
|
96
|
+
@base.object(@dst) if @dst != '0000000'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
def cache_full
|
104
|
+
unless @full_diff
|
105
|
+
@full_diff = @base.lib.diff_full(@from, @to, {:path_limiter => @path})
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def process_full
|
110
|
+
unless @full_diff_files
|
111
|
+
cache_full
|
112
|
+
@full_diff_files = process_full_diff
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def cache_stats
|
117
|
+
unless @stats
|
118
|
+
@stats = @base.lib.diff_stats(@from, @to, {:path_limiter => @path})
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def cache_index_stats
|
123
|
+
unless @index_stats
|
124
|
+
@index_stats = @base.lib.diff_index_stats(@from, {:path_limiter => @path})
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# break up @diff_full
|
129
|
+
def process_full_diff
|
130
|
+
final = {}
|
131
|
+
current_file = nil
|
132
|
+
@full_diff.split("\n").each do |line|
|
133
|
+
if m = /diff --git a\/(.*?) b\/(.*?)/.match(line)
|
134
|
+
current_file = m[1]
|
135
|
+
final[current_file] = {:patch => line, :path => current_file,
|
136
|
+
:mode => '', :src => '', :dst => '', :type => 'modified'}
|
137
|
+
else
|
138
|
+
if m = /index (.......)\.\.(.......)( ......)*/.match(line)
|
139
|
+
final[current_file][:src] = m[1]
|
140
|
+
final[current_file][:dst] = m[2]
|
141
|
+
final[current_file][:mode] = m[3].strip if m[3]
|
142
|
+
end
|
143
|
+
if m = /(.*?) file mode (......)/.match(line)
|
144
|
+
final[current_file][:type] = m[1]
|
145
|
+
final[current_file][:mode] = m[2]
|
146
|
+
end
|
147
|
+
if m = /^Binary files /.match(line)
|
148
|
+
final[current_file][:binary] = true
|
149
|
+
end
|
150
|
+
final[current_file][:patch] << "\n" + line
|
151
|
+
end
|
152
|
+
end
|
153
|
+
final.map { |e| [e[0], DiffFile.new(@base, e[1])] }
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
end
|