Module: RJGit

Extended by:
Forwardable
Defined in:
lib/git.rb,
lib/tag.rb,
lib/blob.rb,
lib/note.rb,
lib/repo.rb,
lib/tree.rb,
lib/actor.rb,
lib/rjgit.rb,
lib/commit.rb,
lib/config.rb,
lib/version.rb,
lib/constants.rb,
lib/transport.rb,
lib/rjgit_helpers.rb

Defined Under Namespace

Modules: Plumbing, Porcelain Classes: Actor, Blob, Commit, Configuration, LocalRefWriter, Note, PatchApplyException, RJGitPack, RJGitReceivePack, RJGitUploadPack, Repo, RubyGit, Tag, TrackingCommit, Tree

Constant Summary collapse

VERSION =
"6.4.0.1"
TREE_TYPE =
0040000
0120000
FILE_TYPE =
0100000
0160000
MISSING_TYPE =
0000000
REG_FILE_TYPE =
0100644
DEFAULT_MIME_TYPE =
"text/plain"
OBJ_TAG =
4

Class Method Summary collapse

Class Method Details

.actor_type(actor) ⇒ Object



93
94
95
96
97
98
99
# 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) ⇒ Object



110
111
112
113
114
115
116
# 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) ⇒ Object



126
127
128
129
130
131
132
# 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) ⇒ Object



52
53
54
55
56
# 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) ⇒ Object



14
15
16
17
18
# 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) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# 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) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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) ⇒ Object



20
21
22
23
# 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) ⇒ Object



118
119
120
121
122
123
124
# 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) ⇒ Object



85
86
87
88
89
90
91
# 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) ⇒ Object



43
44
45
46
47
48
49
50
# 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) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# 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) ⇒ Object



101
102
103
104
105
106
107
108
# 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) ⇒ Object



6
7
8
9
10
11
12
# 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

.versionObject



9
10
11
# File 'lib/rjgit.rb', line 9

def self.version
  VERSION
end