module RJGit

Constants

DEFAULT_MIME_TYPE
FILE_TYPE
MISSING_TYPE
OBJ_TAG
REG_FILE_TYPE
TREE_TYPE
VERSION

Public Class Methods

actor_type(actor) click to toggle source
# File lib/rjgit_helpers.rb, line 93
def self.actor_type(actor)
  case actor
    when Actor then actor.person_ident
    when org.eclipse.jgit.lib.PersonIdent then actor
    else nil
  end
end
blob_type(blob) click to toggle source
# File lib/rjgit_helpers.rb, line 110
def self.blob_type(blob)
  case blob
    when Blob then blob.jblob
    when org.eclipse.jgit.revwalk.RevBlob then blob
    else nil
  end
end
commit_type(commit) click to toggle source
# File lib/rjgit_helpers.rb, line 126
def self.commit_type(commit)
  case commit
    when Commit then commit.jcommit
    when org.eclipse.jgit.lib.ObjectId then commit
    else nil
  end
end
convert_diff_entries(entries) click to toggle source
# File lib/rjgit_helpers.rb, line 52
def self.convert_diff_entries(entries)
  entries.map do |diff_entry|
    RJGit.diff_entry_to_hash(diff_entry[0], diff_entry[1])
  end
end
delegate_to(klass, delegate_name) click to toggle source
# File lib/rjgit_helpers.rb, line 14
def self.delegate_to(klass, delegate_name)
  java_methods = klass.java_class.declared_instance_methods.map{ |method| method.name.to_sym }
  java_methods.reject! { |jm| jm.to_s.start_with?("lambda$") }
  def_delegators delegate_name, *java_methods
end
diff_entry_to_hash(diff_entry, patch) click to toggle source
# File lib/rjgit_helpers.rb, line 58
def self.diff_entry_to_hash(diff_entry, patch)
  entry = {}
  entry[:changetype] = diff_entry.get_change_type.to_string
  entry[:oldpath] = diff_entry.get_old_path
  entry[:newpath] = diff_entry.get_new_path
  entry[:oldmode] = diff_entry.get_old_mode.get_bits
  entry[:newmode] = diff_entry.get_new_mode.get_bits
  entry[:score] = diff_entry.get_score
  entry[:oldid] = diff_entry.get_old_id.name
  entry[:newid] = diff_entry.get_new_id.name
  entry[:patch] = patch unless patch == nil
  entry
end
get_file_mode(jrepo, jblob, revstring=Constants::HEAD) click to toggle source
# File lib/rjgit_helpers.rb, line 25
def self.get_file_mode(jrepo, jblob, revstring=Constants::HEAD)
  last_commit_hash = jrepo.resolve(revstring)
  return nil if last_commit_hash.nil?
  walk = RevWalk.new(jrepo)
  jcommit = walk.parse_commit(last_commit_hash)
  treewalk = TreeWalk.new(jrepo)
  jtree = jcommit.get_tree
  treewalk.add_tree(jtree)
  treewalk.set_recursive(true)
  while treewalk.next
    jblob_lookup = walk.lookup_blob(treewalk.get_object_id(0))
    if jblob_lookup.get_name == jblob.get_name
      mode = treewalk.get_file_mode(0).get_bits
      return mode
    end
  end
end
get_file_mode_with_path(jrepo, path, jtree) click to toggle source
# File lib/rjgit_helpers.rb, line 20
def self.get_file_mode_with_path(jrepo, path, jtree)
  treewalk = TreeWalk.forPath(jrepo, path, jtree)
  return treewalk.get_file_mode(0).get_bits
end
note_type(note) click to toggle source
# File lib/rjgit_helpers.rb, line 118
def self.note_type(note)
  case note
    when Note then note.jnote
    when org.eclipse.jgit.notes.Note then note
    else nil
  end
end
repository_type(repository) click to toggle source
# File lib/rjgit_helpers.rb, line 85
def self.repository_type(repository)
  case repository
    when Repo then repository.jrepo
    when org.eclipse.jgit.lib.Repository then repository
    else nil
  end
end
stringify(entries) click to toggle source
# File lib/rjgit_helpers.rb, line 43
def self.stringify(entries)
  str = ""
  entries.each do |entry|
    line = entry.values.join("\t")
    str = "#{str}#{line}\n"
  end
  str
end
sym_for_type(type) click to toggle source
# File lib/rjgit_helpers.rb, line 72
def self.sym_for_type(type)
  result = case type
  when Constants::OBJ_BLOB
    :blob
  when Constants::OBJ_TREE
    :tree
  when Constants::OBJ_COMMIT
    :commit
  when Constants::OBJ_TAG
    :tag
  end 
end
tree_type(tree) click to toggle source
# File lib/rjgit_helpers.rb, line 101
def self.tree_type(tree)
  case tree
    when Tree then tree.jtree
    when org.eclipse.jgit.revwalk.RevTree then tree
    when org.eclipse.jgit.lib.ObjectId then tree
    else nil
  end
end
underscore(camel_cased_word) click to toggle source
# File lib/rjgit_helpers.rb, line 6
def self.underscore(camel_cased_word)
  camel_cased_word.to_s.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end
version() click to toggle source
# File lib/rjgit.rb, line 9
def self.version
  VERSION
end