graal 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE CHANGED
File without changes
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ Graal
2
+ =============
3
+
4
+ Simple, read-only (for now), abstraction layer to access git repository
5
+ aiming to support different platforms/backends.
@@ -0,0 +1,11 @@
1
+ require 'graal/exe/backend'
2
+
3
+ module Graal
4
+
5
+ module Backend
6
+
7
+ def self.create(path)
8
+ Exe::Git.new(path)
9
+ end
10
+ end
11
+ end
data/lib/graal/blob.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'graal/tree_blob'
2
+
3
+ module Graal
4
+
5
+ class Blob < TreeBlob
6
+
7
+ def contents
8
+ @backend.blob_contents(hash)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'graal/tree'
2
+ require 'graal/blob'
3
+
4
+ module Graal
5
+
6
+ class Commit < Tree
7
+
8
+ def initialize(backend, revision)
9
+ super(backend, revision, '')
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ module Graal::Backend
2
+
3
+ module Exe
4
+ end
5
+ end
6
+
7
+ require_relative 'git'
@@ -0,0 +1,94 @@
1
+ require 'childprocess'
2
+
3
+ module Graal::Backend::Exe
4
+
5
+ class Git
6
+
7
+ class Result
8
+
9
+ attr_reader :exit_code, :output, :error
10
+
11
+ def initialize(exit_code, output_io, error_io)
12
+ @exit_code = exit_code
13
+ @output = output_io.read
14
+ output_io.close
15
+ @error = error_io.read
16
+ error_io.read
17
+ end
18
+
19
+ def error?
20
+ @exit_code != 0
21
+ end
22
+ end
23
+
24
+ def initialize(repository)
25
+ @repository = repository
26
+ end
27
+
28
+ def run(cmd, *args)
29
+ do_run(['git', cmd, *args])
30
+ end
31
+
32
+ def run_with_pathspec(cmd, *args, pathspec)
33
+ command_line = ['git', cmd, *args]
34
+ unless pathspec.nil?
35
+ command_line << '--'
36
+ command_line << pathspec
37
+ end
38
+ do_run(command_line)
39
+ end
40
+
41
+ def heads
42
+ result = run('branch', '--no-color', '--no-column')
43
+ result.output.gsub(/^[ *]*/, '').split("\n")
44
+ end
45
+
46
+ def tags
47
+ result = run('tag', '--no-column')
48
+ result.output.split("\n")
49
+ end
50
+
51
+ def hash_for(revision, path)
52
+ if path.empty?
53
+ result = run('rev-parse', revision).output.chomp
54
+ else
55
+ result = run('ls-tree', revision, path)
56
+ result.output.split(' ')[2]
57
+ end
58
+ end
59
+
60
+ def child(hash, fullpath)
61
+ result = run('ls-tree', hash, fullpath)
62
+ return result.output.split(" ")[1..2]
63
+ end
64
+
65
+ def children(hash, path)
66
+ gitpath = path
67
+ gitpath += '/' unless path.empty?
68
+ result = run('ls-tree', hash, gitpath)
69
+ return result.output.split("\n").map do |line|
70
+ splitted = line.split(" ")
71
+ [splitted[1], splitted[3], splitted[2]]
72
+ end
73
+ end
74
+
75
+ def blob_contents(hash)
76
+ run('cat-file', '-p', hash).output
77
+ end
78
+
79
+ private
80
+
81
+ def do_run(command_line)
82
+ process = ChildProcess.build(*command_line)
83
+ process.cwd = @repository
84
+ out, process.io.stdout, err, process.io.stderr = *IO.pipe, *IO.pipe
85
+
86
+ process.start
87
+ process.wait
88
+ process.io.stdout.close
89
+ process.io.stderr.close
90
+
91
+ Result.new(process.exit_code, out, err)
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,34 @@
1
+ require 'graal/commit'
2
+
3
+ module Graal
4
+
5
+ class Repository < Commit
6
+
7
+ attr_reader :directory
8
+
9
+ def initialize(repository_path)
10
+ backend = Backend.create repository_path
11
+ super(backend, 'HEAD')
12
+ @directory = repository_path
13
+ end
14
+
15
+ def heads
16
+ @backend.heads
17
+ end
18
+ alias branches heads
19
+
20
+ def tags
21
+ @backend.tags
22
+ end
23
+
24
+ def commit(name)
25
+ Commit.new(@backend, name)
26
+ end
27
+ alias revision commit
28
+ alias rev commit
29
+
30
+ def master
31
+ rev('master')
32
+ end
33
+ end
34
+ end
data/lib/graal/tree.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'graal/tree_blob'
2
+
3
+ module Graal
4
+
5
+ class Tree < TreeBlob
6
+
7
+ def child(child_path)
8
+ fullpath = File.join(@path, child_path)
9
+ fullpath[ 0] = '' if fullpath[ 0] == ?/
10
+ fullpath[-1] = '' if fullpath[-1] == ?/
11
+ type, child_hash = @backend.child(hash, fullpath)
12
+ child_for(type, fullpath, child_hash)
13
+ end
14
+ alias [] child
15
+ alias / child
16
+
17
+ def children
18
+ return Enumerator.new(self, :children) unless block_given?
19
+ @backend.children(hash, @path).each { |data| yield child_for(*data) }
20
+ nil
21
+ end
22
+ alias each_child children
23
+ alias list children
24
+ alias ls children
25
+
26
+ def trees
27
+ return Enumerator.new(self, :trees) unless block_given?
28
+ children = @backend.children(hash, @path).each do |data|
29
+ yield child_for(*data) if data[0] == 'tree'
30
+ end
31
+ nil
32
+ end
33
+ alias each_tree trees
34
+ alias list_trees trees
35
+
36
+ def blobs
37
+ return Enumerator.new(self, :blobs) unless block_given?
38
+ @backend.children(hash, @path).each do |data|
39
+ yield child_for(*data) if data[0] == 'blob'
40
+ end
41
+ nil
42
+ end
43
+ alias each_blob blobs
44
+ alias list_blobs blobs
45
+
46
+ private
47
+
48
+ def child_for(type, fullpath, hash)
49
+ if type == 'tree'
50
+ Tree.new(@backend, @revision, fullpath, hash)
51
+ else
52
+ Blob.new(@backend, @revision, fullpath, hash)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,26 @@
1
+ module Graal
2
+
3
+ class TreeBlob
4
+
5
+ attr_reader :revision, :path
6
+
7
+ def initialize(backend, revision, path, hash = nil)
8
+ @backend = backend
9
+ @revision = revision || 'master'
10
+ @path = path || ''
11
+ @hash = hash
12
+ end
13
+
14
+ def hash
15
+ @hash ||= @backend.hash_for(@revision, @path)
16
+ end
17
+
18
+ def tree?
19
+ is_a? Tree
20
+ end
21
+
22
+ def blob?
23
+ is_a? Blob
24
+ end
25
+ end
26
+ end
data/lib/graal/version.rb CHANGED
@@ -1,4 +1,4 @@
1
- module Graal
2
-
3
- VERSION = '0.0.0'
4
- end
1
+ module Graal
2
+
3
+ VERSION = '0.0.1'
4
+ end
data/lib/graal.rb CHANGED
@@ -1,4 +1,10 @@
1
- require 'graal/version'
2
-
3
- module Graal
4
- end
1
+ require 'graal/version'
2
+ require 'graal/backend'
3
+ require 'graal/repository'
4
+
5
+ module Graal
6
+
7
+ def self.Repository(repository_path)
8
+ Repository.new repository_path
9
+ end
10
+ end
metadata CHANGED
@@ -1,68 +1,106 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
5
- prerelease:
4
+ version: 0.0.1
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ferreira Christopher
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rake
16
- version_requirements: !ruby/object:Gem::Requirement
15
+ name: childprocess
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
17
18
  requirements:
18
- - - ! '>='
19
+ - - ~>
19
20
  - !ruby/object:Gem::Version
20
- version: !binary |-
21
- MA==
21
+ version: 0.3.6
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
22
25
  none: false
23
- requirement: !ruby/object:Gem::Requirement
24
26
  requirements:
25
- - - ! '>='
27
+ - - ~>
26
28
  - !ruby/object:Gem::Version
27
- version: !binary |-
28
- MA==
29
+ version: 0.3.6
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
29
33
  none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 10.0.2
38
+ type: :development
30
39
  prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 10.0.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.10
31
54
  type: :development
32
- description: To be announced
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.10
62
+ description: ! " Simple, read-only (for now), abstraction layer to access git
63
+ repository\n aiming to support different platforms/backends.\n"
33
64
  email: contact@aumgn.fr
34
65
  executables: []
35
66
  extensions: []
36
67
  extra_rdoc_files: []
37
68
  files:
38
- - lib/graal.rb
39
- - lib/graal/version.rb
69
+ - README.md
40
70
  - LICENSE
71
+ - lib/graal/backend.rb
72
+ - lib/graal/blob.rb
73
+ - lib/graal/commit.rb
74
+ - lib/graal/exe/backend.rb
75
+ - lib/graal/exe/git.rb
76
+ - lib/graal/repository.rb
77
+ - lib/graal/tree.rb
78
+ - lib/graal/tree_blob.rb
79
+ - lib/graal/version.rb
80
+ - lib/graal.rb
41
81
  homepage: http://graal.aumgn.fr
42
82
  licenses:
43
83
  - MIT
44
- post_install_message:
84
+ post_install_message:
45
85
  rdoc_options: []
46
86
  require_paths:
47
87
  - lib
48
88
  required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
49
90
  requirements:
50
91
  - - ! '>='
51
92
  - !ruby/object:Gem::Version
52
- version: !binary |-
53
- MA==
54
- none: false
93
+ version: '0'
55
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
56
96
  requirements:
57
97
  - - ! '>='
58
98
  - !ruby/object:Gem::Version
59
- version: !binary |-
60
- MA==
61
- none: false
99
+ version: '0'
62
100
  requirements: []
63
- rubyforge_project:
101
+ rubyforge_project:
64
102
  rubygems_version: 1.8.24
65
- signing_key:
103
+ signing_key:
66
104
  specification_version: 3
67
- summary: TBA
105
+ summary: Git Ruby A* Abstraction Layer
68
106
  test_files: []