rjgit 6.4.0.0 → 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: 5cf23697cf088e1ad377026269d1a8af6ffd616a6e4e9fa7039be442ab5c8df9
4
- data.tar.gz: 302078c9082f0abfe79378252869be2afc4b54a4196511275d4d800cd3f0e093
3
+ metadata.gz: 6ffd00cd58355827c9f0e25310905d0634d556f3266189b170ebdf5c725db6d9
4
+ data.tar.gz: ec13041af58650371daba46753ba499260ba3d48ead0c7159c0c3016fbd9eaa9
5
5
  SHA512:
6
- metadata.gz: cc7dbe650511932d321571dfbadc6f786a0695db2ce73e9ae70a1e6af7ae6ef167af071ea83672a0090493323e7bd756b0daef58c3663317c36a48044860b954
7
- data.tar.gz: cf50e8bb4b4bbc06f722fe201a91373e3b1e18fdee2868476807a17c9e180f94851882d951f2771df4cbe65bc230d79af4fab07f28cb9a0d8c493748f24e62d7
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.
@@ -67,7 +59,12 @@ repo.commits('master')
67
59
  repo.commits('959329025f67539fb82e76b02782322fad032821')
68
60
  repo.head
69
61
  commit = repo.commits('master').first # a Commit object; try commit.actor, commit.id, etc.
70
- # Similarly for getting tags, branches, trees (directories), and blobs (files).
62
+ ```
63
+
64
+ ### Getting branches
65
+
66
+ ```ruby
67
+ repo.branches
71
68
  ```
72
69
 
73
70
  ### Finding a single object by SHA
@@ -76,11 +73,43 @@ repo.find('959329025f67539fb82e76b02782322fad032821')
76
73
  repo.find('959329025f67539fb82e76b02782322fad032821', :commit) # Find a specific :commit, :blob, :tree, or :tag
77
74
  ```
78
75
 
79
- ### Logs
76
+ ### Blobs and Trees
80
77
 
81
78
  ```ruby
82
- repo.git.log # Returns an Array of Commits constituting the log for the default branch
83
- 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
84
113
  ```
85
114
 
86
115
  ### Getting diffs
@@ -91,26 +120,11 @@ options = {:old_rev => sha2, :new_rev => sha1, :file_path => "some/path.txt", :p
91
120
  Porcelain.diff(repo, options)
92
121
  ```
93
122
 
94
- ### Getting tags
95
- ```ruby
96
- tag = repo.tags['example_tag']
97
- tag.id # tag's object id
98
- tag.author.name # Etcetera
99
- some_object = Porcelain.object_for_tag(repo, tag) # Returns the tagged object; e.g. a Commit
100
- ```
123
+ ### Logs
101
124
 
102
- ### Blobs and Trees
103
125
  ```ruby
104
- blob = repo.blob("example/file.txt") # Retrieve a file by filepath...
105
- blob = repo.find("959329025f67539fb82e76b02782322fad032822", :blob) # ...or by SHA
106
- blob.data # Cat the file; also blob.id, blob.mode, etc.
107
- tree = repo.tree("example") # Retrieve a tree by filepath...
108
- tree = repo.find("959329025f67539fb82e76b02782322fad032000", :tree) #...or by SHA
109
- tree.data # List the tree's contents (blobs and trees). Also tree.id, tree.mode, etc.
110
- tree.each {|entry| puts entry.inspect} # Loop over the Tree's children (Blobs and Trees)
111
- tree.trees # An array of the Tree's child Trees
112
- tree.blobs # An array of the Tree's child Blobs
113
- 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" ...>]
114
128
  ```
115
129
 
116
130
  ### Creating blobs and trees from scratch
@@ -157,40 +171,24 @@ Contributing
157
171
  1. Create a new branch
158
172
  1. Modify the sources
159
173
  1. Add specs with full coverage for your new code
160
- 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`
161
175
  1. Push the branch up to GitHub
162
176
  1. Send us a pull request
163
177
 
164
- Running RSpec tests (the recommended way)
165
- ---------------
166
-
167
- 1. Start the nailgun server
168
- ```
169
- jruby --ng-server &
170
- ```
171
- 1. Run rake against the nailgun instance
172
- ```
173
- jruby --ng -S rake
174
- ```
175
-
176
178
  Authors
177
179
  -------
178
180
 
179
- RJGit is being developed by Team Repotag:
181
+ RJGit is being developed by:
180
182
 
181
- - [Maarten Engelen](https://github.com/maarten)
182
183
  - [Bart Kamphorst](https://github.com/bartkamphorst)
183
184
  - [Dawa Ometto](https://github.com/dometto)
184
- - [Arlette van Wissen](https://github.com/arlettevanwissen)
185
- - [Steven Woudenberg](https://github.com/stevenwoudenberg)
186
185
 
187
- With special thanks to:
188
- - [Patrick Pepels](https://github.com/bluedread)
186
+
189
187
 
190
188
 
191
189
  License
192
190
  -------
193
- Copyright (c) 2011 - 2022, Team Repotag
191
+ Copyright (c) 2011 - 2023, Team Repotag
194
192
 
195
193
  (Modified BSD License)
196
194
 
data/lib/commit.rb CHANGED
@@ -4,6 +4,7 @@ module RJGit
4
4
  import 'org.eclipse.jgit.revwalk.RevCommit'
5
5
  import 'org.eclipse.jgit.diff.DiffFormatter'
6
6
  import 'org.eclipse.jgit.util.io.DisabledOutputStream'
7
+ import 'org.eclipse.jgit.api.Git'
7
8
 
8
9
  class Commit
9
10
 
@@ -30,6 +31,20 @@ module RJGit
30
31
  @tree ||= Tree.new(@jrepo, TREE_TYPE, nil, @jcommit.get_tree)
31
32
  end
32
33
 
34
+ def note(ref=Note::DEFAULT_REF)
35
+ jnote = Git.new(@jrepo).notes_show().set_notes_ref(ref).setObjectId(@jcommit).call()
36
+ jnote ? Note.new(@jrepo, jnote) : nil
37
+ end
38
+
39
+ def note=(message, ref=Note::DEFAULT_REF)
40
+ Note.new(@jrepo, Git.new(@jrepo).notes_add.set_message(message).set_notes_ref(ref).setObjectId(@jcommit).call())
41
+ end
42
+
43
+ def remove_note(ref=Note::DEFAULT_REF)
44
+ Git.new(@jrepo).notes_remove.set_notes_ref(ref).setObjectId(@jcommit).call()
45
+ return nil
46
+ end
47
+
33
48
  def parents
34
49
  @parents ||= @jcommit.get_parents.map do |parent|
35
50
  RJGit::Commit.new(@jrepo, RevWalk.new(@jrepo).parseCommit(parent.get_id))
data/lib/note.rb ADDED
@@ -0,0 +1,18 @@
1
+ module RJGit
2
+
3
+ class Note
4
+ attr_reader :jnote, :message, :annotates
5
+ DEFAULT_REF = "refs/notes/commits"
6
+
7
+ def initialize(repository, note)
8
+ @jrepo = RJGit.repository_type(repository)
9
+ @jnote = RJGit.note_type(note)
10
+ @message = @jrepo.open(@jnote.getData()).get_bytes.to_a.pack('c*').force_encoding('UTF-8')
11
+ @annotates = @jnote.to_s[5..44]
12
+ end
13
+
14
+ def to_s
15
+ @message
16
+ end
17
+ end
18
+ end
data/lib/repo.rb CHANGED
@@ -216,6 +216,12 @@ module RJGit
216
216
  def tree(file_path, revstring=Constants::HEAD)
217
217
  Tree.find_tree(@jrepo, file_path, revstring)
218
218
  end
219
+
220
+ def notes(ref=Note::DEFAULT_REF)
221
+ @git.jgit.notes_list().set_notes_ref(ref).call().to_a.map do |jnote|
222
+ Note.new(@jrepo, jnote)
223
+ end
224
+ end
219
225
 
220
226
  def update_ref(commit, force = false, ref = "refs/heads/#{Constants::MASTER}")
221
227
  ref_updater = @jrepo.updateRef(ref)
data/lib/rjgit_helpers.rb CHANGED
@@ -83,7 +83,7 @@ module RJGit
83
83
  end
84
84
 
85
85
  def self.repository_type(repository)
86
- repo = case repository
86
+ case repository
87
87
  when Repo then repository.jrepo
88
88
  when org.eclipse.jgit.lib.Repository then repository
89
89
  else nil
@@ -91,7 +91,7 @@ module RJGit
91
91
  end
92
92
 
93
93
  def self.actor_type(actor)
94
- person_ident = case actor
94
+ case actor
95
95
  when Actor then actor.person_ident
96
96
  when org.eclipse.jgit.lib.PersonIdent then actor
97
97
  else nil
@@ -99,7 +99,7 @@ module RJGit
99
99
  end
100
100
 
101
101
  def self.tree_type(tree)
102
- treeobj = case tree
102
+ case tree
103
103
  when Tree then tree.jtree
104
104
  when org.eclipse.jgit.revwalk.RevTree then tree
105
105
  when org.eclipse.jgit.lib.ObjectId then tree
@@ -108,15 +108,23 @@ module RJGit
108
108
  end
109
109
 
110
110
  def self.blob_type(blob)
111
- blobobj = case blob
111
+ case blob
112
112
  when Blob then blob.jblob
113
113
  when org.eclipse.jgit.revwalk.RevBlob then blob
114
114
  else nil
115
115
  end
116
116
  end
117
117
 
118
+ def self.note_type(note)
119
+ case note
120
+ when Note then note.jnote
121
+ when org.eclipse.jgit.notes.Note then note
122
+ else nil
123
+ end
124
+ end
125
+
118
126
  def self.commit_type(commit)
119
- commitobj = case commit
127
+ case commit
120
128
  when Commit then commit.jcommit
121
129
  when org.eclipse.jgit.lib.ObjectId then commit
122
130
  else nil
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.0"
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.0
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,10 +46,11 @@ 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
53
+ - lib/note.rb
56
54
  - lib/repo.rb
57
55
  - lib/rjgit.rb
58
56
  - lib/rjgit_helpers.rb