rjgit 6.4.0.1 → 6.5.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
  SHA256:
3
- metadata.gz: 6ee86efc7cf49616791f74a2d0781cd3bd2bf4e570d0353c5c71b012b984230a
4
- data.tar.gz: 6a87141e15f7c413f1d1d6205d9e5898e1e8e0d97183569f8bee2807ab0eb9d9
3
+ metadata.gz: 6ffd00cd58355827c9f0e25310905d0634d556f3266189b170ebdf5c725db6d9
4
+ data.tar.gz: ec13041af58650371daba46753ba499260ba3d48ead0c7159c0c3016fbd9eaa9
5
5
  SHA512:
6
- metadata.gz: 6fca1bb945ad86907e0c65d1a7ce726cc6ab0f1c7a49040c52162b5b0f54c6449c67b70c13022954420912d5fba0a4104fbcbbdd563a43fa54ea241551084fb2
7
- data.tar.gz: 3df8fe32b4c38c14515eaa4e0800e21aed95a1106964f49fbe6148c85699a72b4e4296be51c2d210f1e8efd4eda60d2e26205fba0a01e485f8e156330397c630
6
+ metadata.gz: 4dacb2b8c3414b8250c91277815813ada02b7fe6ce010dd2167b1d9d616cecd73f93b84ef51643ee1e5b625bdff58462b720fc6df511018d2637ca93a9dc3a56
7
+ data.tar.gz: de445b74d2ce33b6368ff794607d8c3e294ebc06231320f0e6b2ecd5d18b563f80f9f0567cbcdef2f5ce7005d2680b66b5e876006c800bb71a37f350d67d5d34
data/README.md CHANGED
@@ -6,7 +6,7 @@ RJGit
6
6
  [![Ruby Build](https://github.com/repotag/rjgit/actions/workflows/test.yaml/badge.svg)](https://github.com/repotag/rjgit/actions/workflows/test.yaml)
7
7
  [![Coverage Status](https://coveralls.io/repos/repotag/rjgit/badge.png?branch=master)](https://coveralls.io/r/repotag/rjgit)
8
8
  [![Gem Version](https://badge.fury.io/rb/rjgit.png)](http://badge.fury.io/rb/rjgit)
9
- [![Cutting Edge Dependency Status](https://dometto-cuttingedge.herokuapp.com/github/repotag/rjgit/svg 'Cutting Edge Dependency Status')](https://dometto-cuttingedge.herokuapp.com/github/repotag/rjgit/info)
9
+ [![Cutting Edge Dependency Status](https://cuttingedge.onrender.com/github/repotag/rjgit/svg 'Cutting Edge Dependency Status')](https://cuttingedge.onrender.com/github/repotag/rjgit/info)
10
10
 
11
11
  Summary
12
12
  -------
@@ -15,21 +15,13 @@ RJGit provides a fully featured library for accessing and manipulating git repos
15
15
 
16
16
  Installation
17
17
  ------------
18
- Install the rjgit gem with the command:
18
+
19
+ Install the rjgit gem with:
19
20
 
20
21
  ```sh
21
22
  $ gem install rjgit
22
23
  ```
23
24
 
24
- #### Dependencies for using RJGit:
25
- - JRuby >= 1.7.0
26
- - mime-types >= 1.15
27
-
28
- #### Further dependencies for developing RJGIT:
29
- - rake >= 0.9.2.2
30
- - rspec >= 2.0
31
- - simplecov
32
-
33
25
  #### Version scheme
34
26
 
35
27
  RJGit's version number is the version of jgit used, plus our own patch level counter. For instance, RJGit 4.0.1.0 uses jgit 4.0.1, patch level 0.
@@ -69,18 +61,10 @@ repo.head
69
61
  commit = repo.commits('master').first # a Commit object; try commit.actor, commit.id, etc.
70
62
  ```
71
63
 
72
- ### Getting notes
73
- ```ruby
74
- repo.notes
75
- note = repo.head.note
76
- note.message # the String message of the note
77
- note.annotates # the SHA ID of the object this note is attached to
78
- repo.head.note = "Happy note writing"
79
- repo.head.note_remove
80
- ```
81
-
64
+ ### Getting branches
82
65
 
83
- # Similarly for getting tags, branches, trees (directories), and blobs (files).
66
+ ```ruby
67
+ repo.branches
84
68
  ```
85
69
 
86
70
  ### Finding a single object by SHA
@@ -89,11 +73,43 @@ repo.find('959329025f67539fb82e76b02782322fad032821')
89
73
  repo.find('959329025f67539fb82e76b02782322fad032821', :commit) # Find a specific :commit, :blob, :tree, or :tag
90
74
  ```
91
75
 
92
- ### Logs
76
+ ### Blobs and Trees
93
77
 
94
78
  ```ruby
95
- repo.git.log # Returns an Array of Commits constituting the log for the default branch
96
- repo.git.log("follow-rename.txt", "HEAD", follow: true, list_renames: true) # Log for a specific path, tracking the pathname over renames. Returns an Array of TrackingCommits, which store the tracked filename: [#<RJGit::TrackingCommit:0x773014d3 @tracked_pathname="follow-rename.txt" ...>]
79
+ blob = repo.blob("example/file.txt") # Retrieve a file by filepath, from the HEAD commit...
80
+ blob = repo.blob("example/file.txt", "refs/heads/mybranch') # Retrieve the same file from a different branch
81
+ blob = repo.find("959329025f67539fb82e76b02782322fad032822", :blob) # ...or by SHA
82
+ blob.data # Cat the file; also blob.id, blob.mode, etc.
83
+ tree = repo.tree("example") # Retrieve a tree by filepath...
84
+ tree = repo.find("959329025f67539fb82e76b02782322fad032000", :tree) #...or by SHA
85
+ tree.data # List the tree's contents (blobs and trees). Also tree.id, tree.mode, etc.
86
+ tree.each {|entry| puts entry.inspect} # Loop over the Tree's children (Blobs and Trees)
87
+ tree.find_blob {|entry| entry[:name] == 'foo.txt'} # Find a single blob that matches the block
88
+ tree.find_tree {|entry| entry[:name] == 'mytree' } # Find a single tree that matches the block
89
+ tree.find {|entry| ...} # Find a single entry that matches the block
90
+ tree.find_all {|entry entry[:name].include?('.') } # Find all entries matching the block
91
+ tree.trees # An array of the Tree's child Trees
92
+ tree.blobs # An array of the Tree's child Blobs
93
+ 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.
94
+ ```
95
+
96
+ ### Getting tags
97
+ ```ruby
98
+ tag = repo.tags['example_tag']
99
+ tag.id # tag's object id
100
+ tag.author.name # Etcetera
101
+ some_object = Porcelain.object_for_tag(repo, tag) # Returns the tagged object; e.g. a Commit
102
+ ```
103
+
104
+ ### Getting notes
105
+
106
+ ```ruby
107
+ repo.notes
108
+ note = repo.head.note
109
+ note.message # the String message of the note
110
+ note.annotates # the SHA ID of the object this note is attached to
111
+ repo.head.note = "Happy note writing"
112
+ repo.head.note_remove
97
113
  ```
98
114
 
99
115
  ### Getting diffs
@@ -104,26 +120,11 @@ options = {:old_rev => sha2, :new_rev => sha1, :file_path => "some/path.txt", :p
104
120
  Porcelain.diff(repo, options)
105
121
  ```
106
122
 
107
- ### Getting tags
108
- ```ruby
109
- tag = repo.tags['example_tag']
110
- tag.id # tag's object id
111
- tag.author.name # Etcetera
112
- some_object = Porcelain.object_for_tag(repo, tag) # Returns the tagged object; e.g. a Commit
113
- ```
123
+ ### Logs
114
124
 
115
- ### Blobs and Trees
116
125
  ```ruby
117
- blob = repo.blob("example/file.txt") # Retrieve a file by filepath...
118
- blob = repo.find("959329025f67539fb82e76b02782322fad032822", :blob) # ...or by SHA
119
- blob.data # Cat the file; also blob.id, blob.mode, etc.
120
- tree = repo.tree("example") # Retrieve a tree by filepath...
121
- tree = repo.find("959329025f67539fb82e76b02782322fad032000", :tree) #...or by SHA
122
- tree.data # List the tree's contents (blobs and trees). Also tree.id, tree.mode, etc.
123
- tree.each {|entry| puts entry.inspect} # Loop over the Tree's children (Blobs and Trees)
124
- tree.trees # An array of the Tree's child Trees
125
- tree.blobs # An array of the Tree's child Blobs
126
- 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.
126
+ repo.git.log # Returns an Array of Commits constituting the log for the default branch
127
+ repo.git.log("follow-rename.txt", "HEAD", follow: true, list_renames: true) # Log for a specific path, tracking the pathname over renames. Returns an Array of TrackingCommits, which store the tracked filename: [#<RJGit::TrackingCommit:0x773014d3 @tracked_pathname="follow-rename.txt" ...>]
127
128
  ```
128
129
 
129
130
  ### Creating blobs and trees from scratch
@@ -170,40 +171,24 @@ Contributing
170
171
  1. Create a new branch
171
172
  1. Modify the sources
172
173
  1. Add specs with full coverage for your new code
173
- 1. Make sure the whole test suite passes by running rake
174
+ 1. Make sure the whole test suite passes by running `bundle exec rake`
174
175
  1. Push the branch up to GitHub
175
176
  1. Send us a pull request
176
177
 
177
- Running RSpec tests (the recommended way)
178
- ---------------
179
-
180
- 1. Start the nailgun server
181
- ```
182
- jruby --ng-server &
183
- ```
184
- 1. Run rake against the nailgun instance
185
- ```
186
- jruby --ng -S rake
187
- ```
188
-
189
178
  Authors
190
179
  -------
191
180
 
192
- RJGit is being developed by Team Repotag:
181
+ RJGit is being developed by:
193
182
 
194
- - [Maarten Engelen](https://github.com/maarten)
195
183
  - [Bart Kamphorst](https://github.com/bartkamphorst)
196
184
  - [Dawa Ometto](https://github.com/dometto)
197
- - [Arlette van Wissen](https://github.com/arlettevanwissen)
198
- - [Steven Woudenberg](https://github.com/stevenwoudenberg)
199
185
 
200
- With special thanks to:
201
- - [Patrick Pepels](https://github.com/bluedread)
186
+
202
187
 
203
188
 
204
189
  License
205
190
  -------
206
- Copyright (c) 2011 - 2022, Team Repotag
191
+ Copyright (c) 2011 - 2023, Team Repotag
207
192
 
208
193
  (Modified BSD License)
209
194
 
data/lib/tree.rb CHANGED
@@ -25,14 +25,6 @@ module RJGit
25
25
  RJGit::Porcelain.ls_tree(@jrepo, @path, Constants::HEAD, options={:print => true, :io => strio})
26
26
  @contents = strio.string
27
27
  end
28
-
29
- def contents_array
30
- @contents_ary ||= jtree_entries
31
- end
32
-
33
- def count
34
- contents_array.size
35
- end
36
28
 
37
29
  def recursive_contents_array(limit = nil)
38
30
  if @recursive_contents.nil? || @recursive_contents[:limit] != limit
@@ -46,6 +38,26 @@ module RJGit
46
38
  def recursive_count(limit = nil)
47
39
  recursive_contents_array(limit).size
48
40
  end
41
+
42
+ def find_blob(&block)
43
+ return nil unless block_given?
44
+ _find(:Blob) {|tree_entry| yield tree_entry }
45
+ end
46
+
47
+ def find_tree(&block)
48
+ return nil unless block_given?
49
+ _find(:Tree) {|tree_entry| yield tree_entry }
50
+ end
51
+
52
+ def find(&block)
53
+ return nil unless block_given?
54
+ _find(nil) {|tree_entry| yield tree_entry}
55
+ end
56
+
57
+ def find_all(&block)
58
+ return nil unless block_given?
59
+ _find(nil, true) {|tree_entry| yield tree_entry}
60
+ end
49
61
 
50
62
  def each(&block)
51
63
  contents_array.each(&block)
@@ -64,8 +76,12 @@ module RJGit
64
76
  self
65
77
  else
66
78
  treewalk = TreeWalk.forPath(@jrepo, file, @jtree)
67
- treewalk.nil? ? nil :
68
- wrap_tree_or_blob(treewalk.get_file_mode(0), treewalk.get_path_string, treewalk.get_object_id(0))
79
+ if treewalk
80
+ mode = treewalk.get_file_mode(0)
81
+ wrap_tree_or_blob(obj_type(mode), mode.get_bits, treewalk.get_path_string, treewalk.get_object_id(0))
82
+ else
83
+ nil
84
+ end
69
85
  end
70
86
  end
71
87
 
@@ -104,22 +120,68 @@ module RJGit
104
120
 
105
121
  private
106
122
 
107
- def jtree_entries(options={})
123
+ def contents_array
124
+ @contents_ary ||= jtree_entries
125
+ end
126
+
127
+ def _find(type = nil, multiple = false, &block)
128
+ return nil unless block_given?
129
+ treewalk = init_walk
130
+ results = [] if multiple
131
+
132
+ while treewalk.next
133
+ entry = tree_entry(treewalk)
134
+ next if type && type != entry[:type]
135
+ if yield entry
136
+ result = wrap_tree_or_blob(entry[:type], entry[:mode], entry[:name], entry[:id])
137
+ if multiple
138
+ results << result
139
+ else
140
+ return result
141
+ end
142
+ end
143
+ end
144
+ return results
145
+ end
146
+
147
+ def init_walk(recurse=false)
108
148
  treewalk = TreeWalk.new(@jrepo)
109
149
  treewalk.add_tree(@jtree)
110
- treewalk.set_recursive(true) if options[:recursive]
150
+ treewalk.set_recursive(true) if recurse
151
+ treewalk
152
+ end
153
+
154
+ def tree_entry(treewalk)
155
+ mode = treewalk.get_file_mode(0)
156
+ {
157
+ type: obj_type(mode),
158
+ mode: mode.get_bits,
159
+ name: treewalk.get_path_string,
160
+ id: treewalk.get_object_id(0)
161
+ }
162
+ end
163
+
164
+ def jtree_entries(options = {})
165
+ treewalk = init_walk(options[:recursive])
111
166
  entries = []
112
167
  while treewalk.next
113
- entries << wrap_tree_or_blob(treewalk.get_file_mode(0), treewalk.get_path_string, treewalk.get_object_id(0))
168
+ mode = treewalk.get_file_mode(0)
169
+ type = obj_type(mode)
170
+
171
+ entries << wrap_tree_or_blob(type, mode.get_bits, treewalk.get_path_string, treewalk.get_object_id(0))
172
+
114
173
  break if options[:limit] && entries.size >= options[:limit].to_i
115
174
  end
116
175
  entries
117
176
  end
118
177
 
119
- def wrap_tree_or_blob(mode, path, id)
120
- type = mode.get_object_type == Constants::OBJ_TREE ? RJGit::Tree : RJGit::Blob
178
+ def wrap_tree_or_blob(type, mode, path, id)
121
179
  walk = RevWalk.new(@jrepo)
122
- type.new(@jrepo, mode.get_bits, path, walk.parse_any(id))
180
+ RJGit.const_get(type).new(@jrepo, mode, path, walk.parse_any(id))
181
+ end
182
+
183
+ def obj_type(mode)
184
+ mode.get_object_type == Constants::OBJ_BLOB ? :Blob : :Tree
123
185
  end
124
186
 
125
187
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RJGit
2
- VERSION = "6.4.0.1"
2
+ VERSION = "6.5.0.0"
3
3
  end
metadata CHANGED
@@ -1,18 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.4.0.1
4
+ version: 6.5.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Maarten Engelen
8
7
  - Bart Kamphorst
9
8
  - Dawa Ometto
10
- - Arlette van Wissen
11
- - Steven Woudenberg
12
9
  autorequire:
13
10
  bindir: bin
14
11
  cert_chain: []
15
- date: 2023-01-06 00:00:00.000000000 Z
12
+ date: 2023-03-28 00:00:00.000000000 Z
16
13
  dependencies:
17
14
  - !ruby/object:Gem::Dependency
18
15
  requirement: !ruby/object:Gem::Requirement
@@ -49,7 +46,7 @@ files:
49
46
  - lib/java/jars/bcpkix-jdk15on-168.jar
50
47
  - lib/java/jars/bcprov-jdk15on-168.jar
51
48
  - lib/java/jars/jsch-0.1.55.jar
52
- - lib/java/jars/org.eclipse.jgit-6.4.0.202211300538-r.jar
49
+ - lib/java/jars/org.eclipse.jgit-6.5.0.202303070854-r.jar
53
50
  - lib/java/jars/org.eclipse.jgit.ssh.jsch-6.2.0.202206071550-r.jar
54
51
  - lib/java/jars/slf4j-api-1.7.2.jar
55
52
  - lib/java/jars/slf4j-simple-1.7.12.jar