rjgit 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 447838b49b9eefa69e97d032efd07f2fea46e644
4
- data.tar.gz: eb4c73d1121f3566042ab1fa7d31b008c020eb56
3
+ metadata.gz: aed799412640c7cdcfecf08ca4ecc5f69c692db4
4
+ data.tar.gz: 305deb6503f24888df0b65cffc5870baa1dfdb4d
5
5
  SHA512:
6
- metadata.gz: 05fd1e8028507931b635c5be4b2ca146215611742f4a21c55109bb9b0976fc01e41497ba848a643ec5c6ff075d849e67a038754c29488ff4b232a68db80333f7
7
- data.tar.gz: 4b2ffb2740ada2553aa96c950b5526a49dd20eeeec6627aae26c6ac6b0315568bc6c7b4479e436f29d11f9a3ffa3125f3a406a709682a12481f932024c9eb249
6
+ metadata.gz: e04cca82e0ee0ba500c1249f6054909eb59aea835c76231f9a62ada7be16281306b0ef1b489c5468a7cddb77ba453f2b59f02719e2bbb5c2d9428c644736d3b7
7
+ data.tar.gz: 815a03dc8dc2e8779c464bc2fad1a8b1a198defc27d16889901071785e5348a128ba94efe7cc56051557d6b2c46dd50acf6031b8eeb5b7055d668c1df61073b5
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  # RJGit
2
2
 
3
- Copyright (c) 2013, Team Repotag
3
+ Copyright (c) 2013-2014, Team Repotag
4
4
 
5
5
  (Modified BSD License)
6
6
 
data/README.md CHANGED
@@ -67,6 +67,7 @@ repo.bare? # Is this a bare repository?
67
67
  ```ruby
68
68
  repo.commits('master')
69
69
  repo.commits('959329025f67539fb82e76b02782322fad032821')
70
+ repo.head
70
71
  commit = repo.commits('master').first # a Commit object; try commit.actor, commit.id, etc.
71
72
  # Similarly for getting tags, branches, trees (directories), and blobs (files).
72
73
  ```
@@ -96,7 +97,7 @@ tree.data # List the tree's contents (blobs and trees). Also tree.id, tree.mode,
96
97
  tree.each {|entry| puts entry.inspect} # Loop over the Tree's children (Blobs and Trees)
97
98
  tree.trees # An array of the Tree's child Trees
98
99
  tree.blobs # An array of the Tree's child Blobs
99
- Porcelain::ls_tree(repo, repo.tree("example"), :print => true, :recursive => true, :branch => 'mybranch') # Outputs the Tree's contents to $stdout. Faster for recursive listing than Tree#each. Passing nil as the second argument lists the entire repository. Branch defaults to HEAD.
100
+ Porcelain::ls_tree(repo, repo.tree("example"), :print => true, :recursive => true, :ref => 'mybranch') # Outputs the Tree's contents to $stdout. Faster for recursive listing than Tree#each. Passing nil as the second argument lists the entire repository. ref defaults to HEAD.
100
101
  ```
101
102
 
102
103
  ### Creating blobs and trees from scratch
@@ -160,7 +161,7 @@ jruby --ng -S rake
160
161
 
161
162
  License
162
163
  -------
163
- Copyright (c) 2011 - 2013, Team Repotag
164
+ Copyright (c) 2011 - 2014, Team Repotag
164
165
 
165
166
  (Modified BSD License)
166
167
 
data/lib/blob.rb CHANGED
@@ -56,7 +56,7 @@ module RJGit
56
56
  repository = RJGit.repository_type(repository)
57
57
  blob_id = RJGit::Plumbing::TreeBuilder.new(repository).write_blob(contents, true)
58
58
  walk = RevWalk.new(repository)
59
- Blob.new(repository, FileMode::REGULAR_FILE, nil, walk.lookup_blob(blob_id))
59
+ Blob.new(repository, REG_FILE_TYPE, nil, walk.lookup_blob(blob_id))
60
60
  end
61
61
 
62
62
  # Finds a particular Blob in repository matching file_path
data/lib/commit.rb CHANGED
@@ -25,13 +25,14 @@ module RJGit
25
25
  @actor = Actor.new_from_person_ident(@jcommit.get_author_ident)
26
26
  @committer = Actor.new_from_person_ident(@jcommit.get_committer_ident)
27
27
  @committed_date = Time.at(@jcommit.commit_time)
28
+ @authored_date = Time.at(@jcommit.get_author_ident.when.time/1000)
28
29
  @message = @jcommit.get_full_message
29
30
  @short_message = @jcommit.get_short_message
30
31
  @parent_count = @jcommit.get_parent_count
31
32
  end
32
33
 
33
34
  def tree
34
- @tree ||= Tree.new(@jrepo, FileMode::TREE, nil, @jcommit.get_tree)
35
+ @tree ||= Tree.new(@jrepo, TREE_TYPE, nil, @jcommit.get_tree)
35
36
  end
36
37
 
37
38
  def parents
data/lib/git.rb CHANGED
@@ -3,6 +3,7 @@ module RJGit
3
3
  import 'java.io.ByteArrayInputStream'
4
4
  import 'java.io.FileInputStream'
5
5
 
6
+ import 'org.eclipse.jgit.lib.Constants'
6
7
  import 'org.eclipse.jgit.api.Git'
7
8
  import 'org.eclipse.jgit.api.AddCommand'
8
9
  import 'org.eclipse.jgit.api.RmCommand'
@@ -23,8 +24,13 @@ module RJGit
23
24
  @jgit = Git.new(@jrepo)
24
25
  end
25
26
 
26
- def log
27
+ def log(path = nil, revstring = Constants::HEAD, options = {})
27
28
  logs = @jgit.log
29
+ ref = jrepo.resolve(revstring)
30
+ logs.add(ref)
31
+ logs.addPath(path) if path
32
+ logs.setMaxCount(options[:max_count]) if options[:max_count]
33
+ logs.setSkip(options[:skip]) if options[:skip]
28
34
  commits = Array.new
29
35
  logs.call.each do |jcommit|
30
36
  commits << Commit.new(jrepo, jcommit)
@@ -41,8 +47,16 @@ module RJGit
41
47
  array
42
48
  end
43
49
 
44
- def commit(message)
45
- Commit.new(jrepo, @jgit.commit.set_message(message).call)
50
+ def commit(message, options = {})
51
+ commit_cmd = @jgit.commit.set_message(message)
52
+ commit_cmd.set_all(options[:all]) unless options[:all].nil?
53
+ commit_cmd.set_amend(options[:amend]) unless options[:amend].nil?
54
+ commit_cmd.set_author(options[:author].person_ident) unless options[:author].nil?
55
+ commit_cmd.set_committer(options[:committer].person_ident) unless options[:committer].nil?
56
+ commit_cmd.set_insert_change_id(options[:insert_change_id]) unless options[:insert_change_id].nil?
57
+ options[:only_paths].each {|path| commit_cmd.set_only(path)} unless options[:only_paths].nil?
58
+ commit_cmd.set_reflog_comment(options[:reflog_comment]) unless options[:reflog_comment].nil?
59
+ Commit.new(jrepo, commit_cmd.call)
46
60
  end
47
61
 
48
62
  def clone(remote, local, options = {})
@@ -121,8 +135,10 @@ module RJGit
121
135
  @jgit.branch_rename.set_old_name(old_name).set_new_name(new_name).call
122
136
  end
123
137
 
124
- def checkout(branch_name, options = {})
138
+ def checkout(branch_name = "master", options = {})
125
139
  checkout_command = @jgit.checkout.set_name(branch_name)
140
+ checkout_command.set_start_point(options[:commit])
141
+ options[:paths].each {|path| checkout_command.add_path(path)} if options[:path]
126
142
  checkout_command.set_create_branch(true) if options[:create]
127
143
  checkout_command.set_force(true) if options[:force]
128
144
  result = {}
data/lib/repo.rb CHANGED
@@ -155,8 +155,8 @@ module RJGit
155
155
  @git.remove(file_pattern)
156
156
  end
157
157
 
158
- def commit(message)
159
- @git.commit(message)
158
+ def commit(message, options = {})
159
+ @git.commit(message, options)
160
160
  end
161
161
 
162
162
  def clean(options = {})
@@ -211,12 +211,12 @@ module RJGit
211
211
 
212
212
  def update_ref(commit, force = false, ref = "refs/heads/#{Constants::MASTER}")
213
213
  ref_updater = @jrepo.updateRef(ref)
214
+ ref_updater.setForceUpdate(force)
214
215
  ref_updater.setNewObjectId(RJGit.commit_type(commit))
215
- msg = force ? :update : :forceUpdate
216
- ref_updater.send(msg).to_string
216
+ ref_updater.update.to_string
217
217
  end
218
218
 
219
- # Update the info files required for fetching files over the dump-HTTP protocol
219
+ # Update the info files required for fetching files over the dumb-HTTP protocol
220
220
  def update_server_info
221
221
  # First update the $GIT_DIR/refs/info file
222
222
  refs = @jrepo.get_all_refs # Note: JGit will include directories under $GIT_DIR/refs/heads that start with a '.' in its search for refs. Filter these out in LocalRefWriter?
data/lib/rjgit.rb CHANGED
@@ -32,6 +32,9 @@ module RJGit
32
32
  import 'org.eclipse.jgit.api.BlameCommand'
33
33
  import 'org.eclipse.jgit.blame.BlameGenerator'
34
34
  import 'org.eclipse.jgit.blame.BlameResult'
35
+ import 'org.eclipse.jgit.treewalk.CanonicalTreeParser'
36
+ import 'org.eclipse.jgit.diff.DiffFormatter'
37
+
35
38
 
36
39
  # http://wiki.eclipse.org/JGit/User_Guide#Porcelain_API
37
40
  def self.add(repository, file_pattern)
@@ -63,13 +66,13 @@ module RJGit
63
66
  end
64
67
 
65
68
  def self.ls_tree(repository, tree=nil, options={})
66
- options = {:recursive => false, :print => false, :io => $stdout, :branch => Constants::HEAD}.merge(options)
69
+ options = {:recursive => false, :print => false, :io => $stdout, :ref => Constants::HEAD}.merge options
67
70
  jrepo = RJGit.repository_type(repository)
68
71
  return nil unless jrepo
69
72
  if tree
70
73
  jtree = RJGit.tree_type(tree)
71
74
  else
72
- last_commit_hash = jrepo.resolve(options[:branch])
75
+ last_commit_hash = jrepo.resolve(options[:ref])
73
76
  return nil unless last_commit_hash
74
77
  walk = RevWalk.new(jrepo)
75
78
  jcommit = walk.parse_commit(last_commit_hash)
@@ -77,6 +80,7 @@ module RJGit
77
80
  end
78
81
  treewalk = TreeWalk.new(jrepo)
79
82
  treewalk.set_recursive(options[:recursive])
83
+ treewalk.set_filter(PathFilter.create(options[:file_path])) if options[:file_path]
80
84
  treewalk.add_tree(jtree)
81
85
  entries = []
82
86
  while treewalk.next
@@ -115,18 +119,42 @@ module RJGit
115
119
  end
116
120
 
117
121
  def self.diff(repository, options = {})
118
- options = {:namestatus => false}.merge(options)
122
+ options = {:namestatus => false, :patch => false}.merge(options)
119
123
  git = repository.git.jgit
124
+ repo = RJGit.repository_type(repository)
120
125
  diff_command = git.diff
121
- diff_command.set_old_tree(old_tree) if options[:old_tree]
122
- diff_command.set_new_tree(new_tree) if options[:new_tree]
123
- diff_command.set_path_filter(PathFilter.create(file_path)) if options[:file_path]
126
+ if options[:old_rev] then
127
+ reader = repo.new_object_reader
128
+ old_tree = repo.resolve("#{options[:old_rev]}^{tree}")
129
+ old_tree_iter = CanonicalTreeParser.new
130
+ old_tree_iter.reset(reader, old_tree)
131
+ diff_command.set_old_tree(old_tree_iter)
132
+ end
133
+ if options[:new_rev] then
134
+ reader = repo.new_object_reader unless reader
135
+ new_tree = repo.resolve("#{options[:new_rev]}^{tree}")
136
+ new_tree_iter = CanonicalTreeParser.new
137
+ new_tree_iter.reset(reader, new_tree)
138
+ diff_command.set_new_tree(new_tree_iter)
139
+ end
140
+ diff_command.set_path_filter(PathFilter.create(options[:file_path])) if options[:file_path]
124
141
  diff_command.set_show_name_and_status_only(true) if options[:namestatus]
125
142
  diff_command.set_cached(true) if options[:cached]
126
143
  diff_entries = diff_command.call
127
144
  diff_entries = diff_entries.to_array.to_ary
128
- diff_entries = RJGit.convert_diff_entries(diff_entries)
129
- return diff_entries
145
+ if options[:patch] then
146
+ result = []
147
+ out_stream = ByteArrayOutputStream.new
148
+ formatter = DiffFormatter.new(out_stream)
149
+ formatter.set_repository(repo)
150
+ diff_entries.each do |diff_entry|
151
+ formatter.format(diff_entry)
152
+ result.push [diff_entry, out_stream.to_string]
153
+ out_stream.reset
154
+ end
155
+ end
156
+ diff_entries = options[:patch] ? result : diff_entries.map {|entry| [entry]}
157
+ RJGit.convert_diff_entries(diff_entries)
130
158
  end
131
159
 
132
160
  end
@@ -149,7 +177,7 @@ module RJGit
149
177
  end
150
178
 
151
179
  def object_inserter
152
- @jrepo.newObjectInserter
180
+ @object_inserter ||= @jrepo.newObjectInserter
153
181
  end
154
182
 
155
183
  def init_log
@@ -169,9 +197,10 @@ module RJGit
169
197
 
170
198
  def build_tree(start_tree, treemap = nil, flush = false)
171
199
  existing_trees = {}
200
+ untouched_objects = {}
172
201
  formatter = TreeFormatter.new
173
202
  treemap ||= self.treemap
174
-
203
+
175
204
  if start_tree then
176
205
  treewalk = TreeWalk.new(@jrepo)
177
206
  treewalk.add_tree(start_tree)
@@ -185,30 +214,38 @@ module RJGit
185
214
  existing_trees[filename] = treewalk.get_object_id(0) if kind == :tree
186
215
  end
187
216
  else
188
- mode = treewalk.isSubtree ? FileMode::TREE : FileMode::REGULAR_FILE
189
- formatter.append(filename.to_java_string, treewalk.get_file_mode(0), treewalk.get_object_id(0))
217
+ mode = treewalk.get_file_mode(0)
218
+ filename = "#{filename}/" if mode == FileMode::TREE
219
+ untouched_objects[filename] = [mode, treewalk.get_object_id(0)]
190
220
  end
191
221
  end
192
222
  end
193
223
 
194
- treemap.each do |object_name, data|
224
+ sorted_treemap = treemap.inject({}) {|h, (k,v)| v.is_a?(Hash) ? h["#{k}/"] = v : h[k] = v; h }.merge(untouched_objects).sort
225
+
226
+ sorted_treemap.each do |object_name, data|
195
227
  case data
196
- when String
197
- blobid = write_blob(data)
198
- formatter.append(object_name.to_java_string, FileMode::REGULAR_FILE, blobid)
199
- @log[:added] << [:blob, object_name, blobid]
228
+ when Array
229
+ object_name = object_name[0...-1] if data[0] == FileMode::TREE
230
+ formatter.append(object_name.to_java_string, data[0], data[1])
200
231
  when Hash
232
+ object_name = object_name[0...-1]
201
233
  next_tree = build_tree(existing_trees[object_name], data)
202
234
  formatter.append(object_name.to_java_string, FileMode::TREE, next_tree)
203
235
  @log[:added] << [:tree, object_name, next_tree] unless only_contains_deletions(data)
236
+ when String
237
+ blobid = write_blob(data)
238
+ formatter.append(object_name.to_java_string, FileMode::REGULAR_FILE, blobid)
239
+ @log[:added] << [:blob, object_name, blobid]
204
240
  end
205
241
  end
206
242
 
207
- result = object_inserter.insert(formatter)
243
+ object_inserter.insert(formatter)
208
244
  end
209
245
 
210
246
  def write_blob(contents, flush = false)
211
247
  blobid = object_inserter.insert(Constants::OBJ_BLOB, contents.to_java_bytes)
248
+ object_inserter.flush if flush
212
249
  blobid
213
250
  end
214
251
 
@@ -220,7 +257,7 @@ module RJGit
220
257
  attr_accessor :treemap, :current_tree
221
258
  attr_reader :jrepo
222
259
 
223
- def initialize(repository, branch = nil)
260
+ def initialize(repository)
224
261
  @treemap = {}
225
262
  @jrepo = RJGit.repository_type(repository)
226
263
  @treebuilder = TreeBuilder.new(@jrepo)
@@ -272,10 +309,13 @@ module RJGit
272
309
  elsif parents
273
310
  commit_builder.addParentId(RJGit.commit_type(parents))
274
311
  end
275
- @treebuilder.object_inserter.insert(commit_builder)
312
+ result = @treebuilder.object_inserter.insert(commit_builder)
313
+ @treebuilder.object_inserter.flush
314
+ result
276
315
  end
277
316
 
278
- def commit(message, author, parents = nil, ref = "refs/heads/#{Constants::MASTER}")
317
+ def commit(message, author, parents = nil, ref = nil, force = false)
318
+ ref = ref ? ref : "refs/heads/#{Constants::MASTER}"
279
319
  @current_tree = @current_tree ? RJGit.tree_type(@current_tree) : @jrepo.resolve("refs/heads/#{Constants::MASTER}^{tree}")
280
320
  @treebuilder.treemap = @treemap
281
321
  new_tree = @treebuilder.build_tree(@current_tree)
@@ -287,17 +327,22 @@ module RJGit
287
327
  # Point ref to the newest commit
288
328
  ru = @jrepo.updateRef(ref)
289
329
  ru.setNewObjectId(new_head)
290
- res = ru.forceUpdate.to_string
291
-
330
+ ru.setForceUpdate(force)
331
+ ru.setRefLogIdent(author.person_ident)
332
+ ru.setRefLogMessage("commit: #{message}", false)
333
+ res = ru.update.to_string
334
+
335
+ @treebuilder.object_inserter.release
292
336
  @current_tree = new_tree
293
337
  @treemap = {}
294
338
  log = @treebuilder.log
295
339
  @treebuilder.init_log
296
- return res, log
340
+ sha = ObjectId.to_string(new_head)
341
+ return res, log, sha
297
342
  end
298
343
 
299
344
  def self.successful?(result)
300
- ["NEW", "FAST_FORWARD"].include?(result)
345
+ ["NEW", "FAST_FORWARD", "FORCED"].include?(result)
301
346
  end
302
347
 
303
348
  end
data/lib/rjgit_helpers.rb CHANGED
@@ -50,21 +50,22 @@ module RJGit
50
50
 
51
51
  def self.convert_diff_entries(entries)
52
52
  entries.map do |diff_entry|
53
- RJGit. diff_entry_to_hash(diff_entry)
53
+ RJGit.diff_entry_to_hash(diff_entry[0], diff_entry[1])
54
54
  end
55
55
  end
56
56
 
57
- def self.diff_entry_to_hash(diff_entry)
57
+ def self.diff_entry_to_hash(diff_entry, patch)
58
58
  entry = {}
59
59
  entry[:changetype] = diff_entry.get_change_type.to_string
60
60
  entry[:oldpath] = diff_entry.get_old_path
61
61
  entry[:newpath] = diff_entry.get_new_path
62
- entry[:oldmode] = diff_entry.get_old_mode.get_bits
63
- entry[:newmode] = diff_entry.get_new_mode.get_bits
64
- entry[:score] = diff_entry.get_score
65
- entry[:oldid] = diff_entry.get_old_id.name
66
- entry[:newid] = diff_entry.get_new_id.name
67
- entry
62
+ entry[:oldmode] = diff_entry.get_old_mode.get_bits
63
+ entry[:newmode] = diff_entry.get_new_mode.get_bits
64
+ entry[:score] = diff_entry.get_score
65
+ entry[:oldid] = diff_entry.get_old_id.name
66
+ entry[:newid] = diff_entry.get_new_id.name
67
+ entry[:patch] = patch unless patch == nil
68
+ entry
68
69
  end
69
70
 
70
71
  def self.sym_for_type(type)
data/lib/tree.rb CHANGED
@@ -64,7 +64,7 @@ module RJGit
64
64
  new_tree = tree_builder.build_tree(base_tree, hashmap, true)
65
65
  walk = RevWalk.new(jrepo)
66
66
  new_tree = walk.lookup_tree(new_tree)
67
- Tree.new(jrepo, FileMode::TREE, nil, new_tree)
67
+ Tree.new(jrepo, TREE_TYPE, nil, new_tree)
68
68
  end
69
69
 
70
70
  def self.find_tree(repository, file_path, revstring=Constants::HEAD)
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RJGit
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maarten Engelen
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-12-21 00:00:00.000000000 Z
15
+ date: 2014-10-28 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: mime-types
@@ -35,12 +35,17 @@ extensions: []
35
35
  extra_rdoc_files:
36
36
  - README.md
37
37
  files:
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
38
41
  - lib/actor.rb
39
42
  - lib/blob.rb
40
43
  - lib/commit.rb
41
44
  - lib/config.rb
42
45
  - lib/constants.rb
43
46
  - lib/git.rb
47
+ - lib/java/jars/jsch-0.1.49.jar
48
+ - lib/java/jars/org.eclipse.jgit-3.5.1.201410131835-r.jar
44
49
  - lib/repo.rb
45
50
  - lib/rjgit.rb
46
51
  - lib/rjgit_helpers.rb
@@ -48,11 +53,6 @@ files:
48
53
  - lib/transport.rb
49
54
  - lib/tree.rb
50
55
  - lib/version.rb
51
- - README.md
52
- - LICENSE
53
- - Gemfile
54
- - lib/java/jars/jsch-0.1.49.jar
55
- - lib/java/jars/org.eclipse.jgit-3.2.0.201312181205-r.jar
56
56
  homepage: https://github.com/repotag/rjgit
57
57
  licenses:
58
58
  - Modified BSD
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
- rubygems_version: 2.1.9
78
+ rubygems_version: 2.2.2
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: JRuby wrapper around the JGit library.