Module: RJGit

Extended by:
Forwardable
Defined in:
lib/git.rb,
lib/tag.rb,
lib/blob.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, RJGitPack, RJGitReceivePack, RJGitUploadPack, Repo, RubyGit, Tag, Tree

Constant Summary collapse

VERSION =
"4.5.0.0"
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


92
93
94
95
96
97
98
# File 'lib/rjgit_helpers.rb', line 92

def self.actor_type(actor)
  person_ident = case actor
    when Actor then actor.person_ident
    when org.eclipse.jgit.lib.PersonIdent then actor
    else nil
  end
end

.blob_type(blob) ⇒ Object


109
110
111
112
113
114
115
# File 'lib/rjgit_helpers.rb', line 109

def self.blob_type(blob)
  blobobj = case blob
    when Blob then blob.jblob
    when org.eclipse.jgit.revwalk.RevBlob then blob
    else nil
  end
end

.commit_type(commit) ⇒ Object


117
118
119
120
121
122
123
# File 'lib/rjgit_helpers.rb', line 117

def self.commit_type(commit)
  commitobj = case commit
    when Commit then commit.jcommit
    when org.eclipse.jgit.lib.ObjectId then commit
    else nil
  end
end

.convert_diff_entries(entries) ⇒ Object


51
52
53
54
55
# File 'lib/rjgit_helpers.rb', line 51

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
# 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 }
  def_delegators delegate_name, *java_methods
end

.diff_entry_to_hash(diff_entry, patch) ⇒ Object


57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rjgit_helpers.rb', line 57

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


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rjgit_helpers.rb', line 24

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


19
20
21
22
# File 'lib/rjgit_helpers.rb', line 19

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

.repository_type(repository) ⇒ Object


84
85
86
87
88
89
90
# File 'lib/rjgit_helpers.rb', line 84

def self.repository_type(repository)
  repo = case repository
    when Repo then repository.jrepo
    when org.eclipse.jgit.lib.Repository then repository
    else nil
  end
end

.stringify(entries) ⇒ Object


42
43
44
45
46
47
48
49
# File 'lib/rjgit_helpers.rb', line 42

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


71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rjgit_helpers.rb', line 71

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


100
101
102
103
104
105
106
107
# File 'lib/rjgit_helpers.rb', line 100

def self.tree_type(tree)
  treeobj = 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


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

def self.version
  VERSION
end