peterwald-git 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/git/stream.rb +189 -0
- metadata +2 -1
data/lib/git/stream.rb
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
module Git
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
#====================
|
6
|
+
# Stream Classes
|
7
|
+
#
|
8
|
+
# These classes must support the following methods
|
9
|
+
#
|
10
|
+
# to_s - write the command to the git protocol stream
|
11
|
+
#====================
|
12
|
+
|
13
|
+
class StreamCommit
|
14
|
+
|
15
|
+
|
16
|
+
attr_accessor :branch, :mark, :author, :committer, :message, :ancestor, :changes
|
17
|
+
|
18
|
+
def initialize()
|
19
|
+
@branch = nil
|
20
|
+
@mark = StreamMark.new
|
21
|
+
@author = nil
|
22
|
+
@committer = nil
|
23
|
+
@message = nil
|
24
|
+
@ancestor = nil
|
25
|
+
@changes = []
|
26
|
+
end
|
27
|
+
|
28
|
+
def modify_file(repos_path, data, mode = nil)
|
29
|
+
sfm = StreamFileModify.new(repos_path, data)
|
30
|
+
sfm.mode = mode unless mode == nil
|
31
|
+
changes << sfm
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete_file(repos_path)
|
35
|
+
changes << StreamFileDelete.new(repos_path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def rename_file(repos_path_from, repos_path_to)
|
39
|
+
changes << StreamFileRename.new(repos_path_form, repos_path_to)
|
40
|
+
end
|
41
|
+
|
42
|
+
def copy_file(repos_path_from, repos_path_to)
|
43
|
+
changes << StreamFileCopy.new(repos_path_form, repos_path_to)
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete_all_files()
|
47
|
+
changes << StreamFileDeleteAll.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_s
|
51
|
+
out = "commit refs/heads/#{branch.to_s}\n"
|
52
|
+
out << "mark #{mark}\n"
|
53
|
+
out << "author #{author.name} <#{author.email}> #{author.date.rfc2822}\n" unless author == nil
|
54
|
+
out << "committer #{committer.name} <#{committer.email}> #{committer.date.rfc2822}\n" unless committer == nil
|
55
|
+
if (message == nil)
|
56
|
+
out << StreamData.emit_empty_data
|
57
|
+
else
|
58
|
+
out << StreamData.emit_inline_data(message)
|
59
|
+
end
|
60
|
+
out << "from #{ancestor}\n" unless ancestor == nil
|
61
|
+
changes.each do |c|
|
62
|
+
out << c.to_s
|
63
|
+
end
|
64
|
+
out << "\n"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class StreamMark
|
69
|
+
|
70
|
+
@@mark_counter = 1
|
71
|
+
|
72
|
+
def initialize(id = (@@mark_counter += 1))
|
73
|
+
@id = id
|
74
|
+
end
|
75
|
+
|
76
|
+
def to_s
|
77
|
+
":#{@id}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# This class is used in the filemodify change on the commit stream
|
82
|
+
# At this time only the inline mode data stream is supported
|
83
|
+
class StreamFileModify
|
84
|
+
|
85
|
+
attr_accessor :mode, :repository_path, :inline_data
|
86
|
+
|
87
|
+
def initialize(repository_path, data)
|
88
|
+
@mode = 100644
|
89
|
+
@repository_path = repository_path
|
90
|
+
@inline_data = data
|
91
|
+
end
|
92
|
+
|
93
|
+
def to_s
|
94
|
+
"M #{mode} inline #{repository_path}\n#{StreamData.emit_inline_data(inline_data)}"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class StreamFileDelete
|
99
|
+
|
100
|
+
attr_accessor :repository_path
|
101
|
+
|
102
|
+
def initialize(repository_path)
|
103
|
+
@repository_path = repository_path
|
104
|
+
end
|
105
|
+
|
106
|
+
def to_s
|
107
|
+
"D #{repository_path}\n"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class StreamFileCopy
|
112
|
+
|
113
|
+
attr_accessor :repository_path_from, :repository_path_to
|
114
|
+
|
115
|
+
def initialize(repository_path_from, repository_path_to)
|
116
|
+
@repository_path_from = repository_path_from
|
117
|
+
@repository_path_to = repository_path_to
|
118
|
+
end
|
119
|
+
|
120
|
+
def to_s
|
121
|
+
"C #{repository_path_from} #{repository_path_to}\n"
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
class StreamFileRename
|
127
|
+
|
128
|
+
attr_accessor :repository_path_from, :repository_path_to
|
129
|
+
|
130
|
+
def initialize(repository_path_from,repository_path_to)
|
131
|
+
@repository_path_from = repository_path_from
|
132
|
+
@repository_path_to = repository_path_to
|
133
|
+
end
|
134
|
+
|
135
|
+
def to_s
|
136
|
+
"R #{repository_path_from} #{repository_path_to}\n"
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
class StreamFileDeleteAll
|
142
|
+
|
143
|
+
def to_s
|
144
|
+
"deleteall\n"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# Represents a stream of data bytes in the git stream
|
149
|
+
class StreamData
|
150
|
+
|
151
|
+
def self.emit_inline_data(data_string)
|
152
|
+
"data #{data_string.length}\n#{data_string}\n"
|
153
|
+
end
|
154
|
+
|
155
|
+
def self.emit_empty_data
|
156
|
+
"data 0\n\n"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
#====================
|
161
|
+
# Stream Implementation
|
162
|
+
#====================
|
163
|
+
|
164
|
+
# This is an initial implementation of git fast-import/export streams
|
165
|
+
# It is not complete!
|
166
|
+
class Stream
|
167
|
+
|
168
|
+
attr_reader :commands
|
169
|
+
|
170
|
+
def initialize
|
171
|
+
@commands = []
|
172
|
+
end
|
173
|
+
|
174
|
+
def commit
|
175
|
+
cmt = Git::StreamCommit.new
|
176
|
+
yield cmt
|
177
|
+
commands << cmt
|
178
|
+
end
|
179
|
+
|
180
|
+
def to_s
|
181
|
+
s = ""
|
182
|
+
commands.each do |cmd|
|
183
|
+
s << cmd.to_s
|
184
|
+
end
|
185
|
+
return s
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peterwald-git
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Chacon
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- lib/git/stash.rb
|
39
39
|
- lib/git/stashes.rb
|
40
40
|
- lib/git/status.rb
|
41
|
+
- lib/git/stream.rb
|
41
42
|
- lib/git/working_directory.rb
|
42
43
|
- lib/git.rb
|
43
44
|
- README
|