rjgit 4.1.1.0 → 4.2.0.0

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: de414913f4da2ef534b52b55772135221f7a6e46
4
- data.tar.gz: c70951fb94958a2598ca3fac726eb4ad0b9c092c
3
+ metadata.gz: d56351d6b926d22b1eebd8c8c958b638cb1aef80
4
+ data.tar.gz: 6c5a3308f8fb57d5be9e80617835ab60f84a5ca6
5
5
  SHA512:
6
- metadata.gz: dadcd6702f27e944c87b72f010964927c672be8a3a745d98b7565f0f0ec1d577f94f44a96ea5767e8999a8f384d49fa3a1f4a0d2d164f25c02bcde7bd38aaa9a
7
- data.tar.gz: 21de8076d006644bca2677792dc0e4e2fee493e6c82bc604cbd4d172c6f0e7428574df8875458f68db20dccbedaf75dcb456d02c1a1e84bd2b8a087bdf3de353
6
+ metadata.gz: 07703d7678e79653a27b6d6e605c056b45eb9181fbee56bfe098d889802af1e52a64611786f7c1c43da9e45fb9a2a722344d84aaaf7dd2860164ec2065345fe5
7
+ data.tar.gz: 16fb0eab317a868eb2239e3194d93a8727ead62d8be8e34b7bb0381e9bf66197d37afb4806804f2357e8e83efd0e5eae6b75c93f7354070fd051e8a943ff81eb
data/Gemfile CHANGED
@@ -1,11 +1,12 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem "mime-types", "~> 1.15"
4
- gem "rake", "~> 10.1.0"
3
+ gem "mime-types", "~> 2.6.2"
4
+ gem "rake", "~> 10.4.2"
5
5
 
6
6
  gem 'coveralls', require: false
7
7
 
8
8
  group :test do
9
- gem "rspec", "2.13.0"
9
+ gem "rspec", "~> 3.4.0"
10
+ gem "rspec-collection_matchers", "~> 1.1.2"
10
11
  gem "simplecov"
11
12
  end
data/lib/blob.rb CHANGED
@@ -6,6 +6,7 @@ module RJGit
6
6
  class Blob
7
7
 
8
8
  attr_reader :id, :mode, :name, :path, :jblob
9
+ alias_method :get_name, :id
9
10
  RJGit.delegate_to(RevBlob, :@jblob)
10
11
 
11
12
  def initialize(repository, mode, path, jblob)
data/lib/commit.rb CHANGED
@@ -7,16 +7,9 @@ module RJGit
7
7
 
8
8
  class Commit
9
9
 
10
- attr_reader :id
11
- attr_reader :parents
12
- attr_reader :actor
13
- attr_reader :committer
14
- attr_reader :authored_date
15
- attr_reader :committed_date
16
- attr_reader :message
17
- attr_reader :short_message
18
- attr_reader :jcommit
19
- attr_reader :parent_count
10
+ attr_reader :id, :parents, :actor, :committer, :authored_date, :committed_date
11
+ attr_reader :message, :short_message, :jcommit, :parent_count
12
+ alias_method :get_name, :id
20
13
 
21
14
  RJGit.delegate_to(RevCommit, :@jcommit)
22
15
 
@@ -38,14 +31,16 @@ module RJGit
38
31
  end
39
32
 
40
33
  def parents
41
- @parents ||= @jcommit.get_parents.map {|parent| Commit.new(@jrepo, parent)}
34
+ @parents ||= @jcommit.get_parents.map do |parent|
35
+ RJGit::Commit.new(@jrepo, RevWalk.new(@jrepo).parseCommit(parent.get_id))
36
+ end
42
37
  end
43
38
 
44
39
  def stats
45
40
  df = DiffFormatter.new(DisabledOutputStream::INSTANCE)
46
41
  df.set_repository(@jrepo)
47
42
  df.set_context(0)
48
- parent_commit = @jcommit.parent_count > 0 ? @jcommit.get_parents[0]:nil
43
+ parent_commit = @jcommit.parent_count > 0 ? @jcommit.get_parents[0] : nil
49
44
  entries = df.scan(parent_commit, @jcommit)
50
45
  results = {}
51
46
  total_del = 0
@@ -67,6 +62,24 @@ module RJGit
67
62
  return total_ins, total_del, results
68
63
  end
69
64
 
65
+ def diff(options = {})
66
+ self.diffs(options).join
67
+ end
68
+
69
+ def diffs(options = {context: 2})
70
+ out_stream = ByteArrayOutputStream.new
71
+ formatter = DiffFormatter.new(out_stream)
72
+ formatter.set_repository(@jrepo)
73
+ formatter.set_context(options[:context])
74
+ parent_commit = @jcommit.parent_count > 0 ? @jcommit.get_parents.first : nil
75
+ entries = formatter.scan(parent_commit, @jcommit)
76
+ entries.each do |entry|
77
+ formatter.format(entry)
78
+ out_stream.write('custom_git_delimiter'.to_java_bytes)
79
+ end
80
+ out_stream.to_s.split('custom_git_delimiter')
81
+ end
82
+
70
83
  # Pass an empty array for parents if the commit should have no parents
71
84
  def self.new_with_tree(repository, tree, message, actor, parents = nil)
72
85
  repository = RJGit.repository_type(repository)
@@ -102,8 +115,5 @@ module RJGit
102
115
  end
103
116
  end
104
117
 
105
- def self.diff(repo, a, b = nil, paths = [], options = {})
106
- end
107
-
108
118
  end
109
119
  end
data/lib/git.rb CHANGED
@@ -27,6 +27,14 @@ module RJGit
27
27
  @jgit = Git.new(@jrepo)
28
28
  end
29
29
 
30
+ def logs(refs, options = {})
31
+ logs = []
32
+ refs.each do |ref|
33
+ logs << log(nil, ref, options)
34
+ end
35
+ logs
36
+ end
37
+
30
38
  def log(path = nil, revstring = Constants::HEAD, options = {})
31
39
  ref = jrepo.resolve(revstring)
32
40
  return [] unless ref
@@ -52,9 +60,19 @@ module RJGit
52
60
  logs.addPath(path) if path
53
61
  logs.setMaxCount(options[:max_count]) if options[:max_count]
54
62
  logs.setSkip(options[:skip]) if options[:skip]
55
- # These options need tests
56
- # logs.addRange(options[:since], options[:until]) if (options[:since] && options[:until])
57
- # logs.not(options[:not]) if options[:not]
63
+
64
+ if (options[:since] && options[:until])
65
+ revwalk = RevWalk.new(jrepo)
66
+ since_commit = revwalk.parseCommit(jrepo.resolve(options[:since]))
67
+ until_commit = revwalk.parseCommit(jrepo.resolve(options[:until]))
68
+ logs.addRange(since_commit, until_commit)
69
+ end
70
+ if options[:not]
71
+ revwalk = RevWalk.new(jrepo)
72
+ options[:not].each do |ref|
73
+ logs.not(revwalk.parseCommit(jrepo.resolve(ref)))
74
+ end
75
+ end
58
76
  jcommits = logs.call
59
77
  end
60
78
 
data/lib/rjgit.rb CHANGED
@@ -65,24 +65,36 @@ module RJGit
65
65
  return bytes.to_a.pack('c*').force_encoding('UTF-8')
66
66
  end
67
67
 
68
- def self.ls_tree(repository, tree=nil, options={})
69
- options = {:recursive => false, :print => false, :io => $stdout, :ref => Constants::HEAD}.merge options
68
+ def self.ls_tree(repository, path=nil, treeish=Constants::HEAD, options={})
69
+ options = {recursive: false, print: false, io: $stdout, path_filter: nil}.merge options
70
70
  jrepo = RJGit.repository_type(repository)
71
- return nil unless jrepo
72
- if tree
73
- jtree = RJGit.tree_type(tree)
74
- else
75
- last_commit_hash = jrepo.resolve(options[:ref])
76
- return nil unless last_commit_hash
71
+ ref = treeish.respond_to?(:get_name) ? treeish.get_name : treeish
72
+
73
+ begin
74
+ obj = jrepo.resolve(ref)
77
75
  walk = RevWalk.new(jrepo)
78
- jcommit = walk.parse_commit(last_commit_hash)
79
- jtree = jcommit.get_tree
76
+ revobj = walk.parse_any(obj)
77
+ jtree = case revobj.get_type
78
+ when Constants::OBJ_TREE
79
+ walk.parse_tree(obj)
80
+ when Constants::OBJ_COMMIT
81
+ walk.parse_commit(obj).get_tree
82
+ end
83
+ rescue Java::OrgEclipseJgitErrors::MissingObjectException, Java::JavaLang::IllegalArgumentException, Java::JavaLang::NullPointerException
84
+ return nil
85
+ end
86
+ if path
87
+ treewalk = TreeWalk.forPath(jrepo, path, jtree)
88
+ return nil unless treewalk
89
+ treewalk.enter_subtree
90
+ else
91
+ treewalk = TreeWalk.new(jrepo)
92
+ treewalk.add_tree(jtree)
80
93
  end
81
- treewalk = TreeWalk.new(jrepo)
82
94
  treewalk.set_recursive(options[:recursive])
83
- treewalk.set_filter(PathFilter.create(options[:file_path])) if options[:file_path]
84
- treewalk.add_tree(jtree)
95
+ treewalk.set_filter(PathFilter.create(options[:path_filter])) if options[:path_filter]
85
96
  entries = []
97
+
86
98
  while treewalk.next
87
99
  entry = {}
88
100
  mode = treewalk.get_file_mode(0)
@@ -93,8 +105,8 @@ module RJGit
93
105
  entries << entry
94
106
  end
95
107
  options[:io].puts RJGit.stringify(entries) if options[:print]
96
- return entries
97
- end
108
+ entries
109
+ end
98
110
 
99
111
  def self.blame(repository, file_path, options={})
100
112
  options = {:print => false, :io => $stdout}.merge(options)
@@ -200,15 +212,14 @@ module RJGit
200
212
  untouched_objects = {}
201
213
  formatter = TreeFormatter.new
202
214
  treemap ||= self.treemap
203
-
204
- if start_tree then
215
+ if start_tree
205
216
  treewalk = TreeWalk.new(@jrepo)
206
217
  treewalk.add_tree(start_tree)
207
218
  while treewalk.next
208
219
  filename = treewalk.get_name_string
209
- if treemap.keys.include?(filename) then
220
+ if treemap.keys.include?(filename)
210
221
  kind = treewalk.isSubtree ? :tree : :blob
211
- if treemap[filename] == false then
222
+ if treemap[filename] == false
212
223
  @log[:deleted] << [kind, filename, treewalk.get_object_id(0)]
213
224
  else
214
225
  existing_trees[filename] = treewalk.get_object_id(0) if kind == :tree
@@ -220,9 +231,8 @@ module RJGit
220
231
  end
221
232
  end
222
233
  end
223
-
224
- sorted_treemap = treemap.inject({}) {|h, (k,v)| v.is_a?(Hash) ? h["#{k}/"] = v : h[k] = v; h }.merge(untouched_objects).sort
225
234
 
235
+ sorted_treemap = treemap.inject({}) {|h, (k,v)| v.is_a?(Hash) ? h["#{k}/"] = v : h[k] = v; h }.merge(untouched_objects).sort
226
236
  sorted_treemap.each do |object_name, data|
227
237
  case data
228
238
  when Array
@@ -239,7 +249,6 @@ module RJGit
239
249
  @log[:added] << [:blob, object_name, blobid]
240
250
  end
241
251
  end
242
-
243
252
  object_inserter.insert(formatter)
244
253
  end
245
254
 
@@ -349,5 +358,3 @@ module RJGit
349
358
  end
350
359
 
351
360
  end
352
-
353
-
data/lib/tag.rb CHANGED
@@ -6,6 +6,7 @@ module RJGit
6
6
  class Tag
7
7
 
8
8
  attr_reader :id, :jtag
9
+ alias_method :get_name, :id
9
10
  RJGit.delegate_to(RevTag, :@jtag)
10
11
 
11
12
  def initialize(jtag)
data/lib/tree.rb CHANGED
@@ -5,7 +5,8 @@ module RJGit
5
5
 
6
6
  class Tree
7
7
 
8
- attr_reader :contents, :id, :mode, :name, :repo, :jtree
8
+ attr_reader :contents, :id, :mode, :name, :repo, :path, :jtree
9
+ alias_method :get_name, :id
9
10
  RJGit.delegate_to(RevTree, :@jtree)
10
11
  include Enumerable
11
12
 
@@ -21,19 +22,29 @@ module RJGit
21
22
  def data
22
23
  return @contents if @contents
23
24
  strio = StringIO.new
24
- RJGit::Porcelain.ls_tree(@jrepo, @jtree, options={:print => true, :io => strio})
25
+ RJGit::Porcelain.ls_tree(@jrepo, @path, Constants::HEAD, options={:print => true, :io => strio})
25
26
  @contents = strio.string
26
27
  end
27
28
 
28
29
  def contents_array
29
- return @contents_ary if @contents_ary
30
- results = []
31
- RJGit::Porcelain.ls_tree(@jrepo, @jtree).each do |item|
32
- walk = RevWalk.new(@jrepo)
33
- results << Tree.new(@jrepo, item[:mode], item[:path], walk.lookup_tree(ObjectId.from_string(item[:id]))) if item[:type] == 'tree'
34
- results << Blob.new(@jrepo, item[:mode], item[:path], walk.lookup_blob(ObjectId.from_string(item[:id]))) if item[:type] == 'blob'
30
+ @contents_ary ||= jtree_entries
31
+ end
32
+
33
+ def count
34
+ contents_array.size
35
+ end
36
+
37
+ def recursive_contents_array(limit = nil)
38
+ if @recursive_contents.nil? || @recursive_contents[:limit] != limit
39
+ @recursive_contents = {}
40
+ @recursive_contents[:objects] = jtree_entries({recursive: true, limit: limit})
41
+ @recursive_contents[:limit] = limit
35
42
  end
36
- @contents_ary = results
43
+ @recursive_contents[:objects]
44
+ end
45
+
46
+ def recursive_count(limit = nil)
47
+ recursive_contents_array(limit).size
37
48
  end
38
49
 
39
50
  def each(&block)
@@ -41,20 +52,17 @@ module RJGit
41
52
  end
42
53
 
43
54
  def blobs
44
- contents_array.select {|x| x.is_a?(Blob)}
55
+ @content_blobs ||= contents_array.select {|x| x.is_a?(Blob)}
45
56
  end
46
57
 
47
58
  def trees
48
- contents_array.select {|x| x.is_a?(Tree)}
59
+ @content_trees ||= contents_array.select {|x| x.is_a?(Tree)}
49
60
  end
50
61
 
51
- # From Grit
52
62
  def /(file)
53
- if file =~ /\//
54
- file.split("/").inject(self) { |acc, x| acc/x } rescue nil
55
- else
56
- self.contents_array.find { |c| c.name == file }
57
- end
63
+ treewalk = TreeWalk.forPath(@jrepo, file, @jtree)
64
+ treewalk.nil? ? nil :
65
+ wrap_tree_or_blob(treewalk.get_file_mode(0), treewalk.get_path_string, treewalk.get_object_id(0))
58
66
  end
59
67
 
60
68
  def self.new_from_hashmap(repository, hashmap, base_tree = nil)
@@ -70,11 +78,11 @@ module RJGit
70
78
  def self.find_tree(repository, file_path, revstring=Constants::HEAD)
71
79
  jrepo = RJGit.repository_type(repository)
72
80
  return nil if jrepo.nil?
73
- last_commit_hash = jrepo.resolve(revstring)
74
- return nil if last_commit_hash.nil?
81
+ last_commit = jrepo.resolve(revstring)
82
+ return nil if last_commit.nil?
75
83
 
76
84
  walk = RevWalk.new(jrepo)
77
- commit = walk.parse_commit(last_commit_hash)
85
+ commit = walk.parse_commit(last_commit)
78
86
  treewalk = TreeWalk.new(jrepo)
79
87
  jtree = commit.get_tree
80
88
  treewalk.add_tree(jtree)
@@ -89,6 +97,26 @@ module RJGit
89
97
  nil
90
98
  end
91
99
  end
100
+
101
+ private
102
+
103
+ def jtree_entries(options={})
104
+ treewalk = TreeWalk.new(@jrepo)
105
+ treewalk.add_tree(@jtree)
106
+ treewalk.set_recursive(true) if options[:recursive]
107
+ entries = []
108
+ while treewalk.next
109
+ entries << wrap_tree_or_blob(treewalk.get_file_mode(0), treewalk.get_path_string, treewalk.get_object_id(0))
110
+ break if options[:limit] && entries.size >= options[:limit].to_i
111
+ end
112
+ entries
113
+ end
114
+
115
+ def wrap_tree_or_blob(mode, path, id)
116
+ type = mode.get_object_type == Constants::OBJ_TREE ? RJGit::Tree : RJGit::Blob
117
+ walk = RevWalk.new(@jrepo)
118
+ type.new(@jrepo, mode.get_bits, path, walk.parse_any(id))
119
+ end
92
120
 
93
121
  end
94
122
 
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RJGit
2
- VERSION = "4.1.1.0"
2
+ VERSION = "4.2.0.0"
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: 4.1.1.0
4
+ version: 4.2.0.0
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: 2015-11-17 00:00:00.000000000 Z
15
+ date: 2016-01-25 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: mime-types
@@ -45,7 +45,7 @@ files:
45
45
  - lib/constants.rb
46
46
  - lib/git.rb
47
47
  - lib/java/jars/jsch-0.1.49.jar
48
- - lib/java/jars/org.eclipse.jgit-4.1.1.201511131810-r.jar
48
+ - lib/java/jars/org.eclipse.jgit-4.2.0.201601211800-r.jar
49
49
  - lib/java/jars/slf4j-api-1.7.2.jar
50
50
  - lib/java/jars/slf4j-simple-1.7.12.jar
51
51
  - lib/repo.rb