summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.(none)>2007-11-27 08:06:51 -0800
committerscott Chacon <schacon@agadorsparticus.(none)>2007-11-27 08:06:51 -0800
commit07ebb951368ed31bdaebc2e820c62ced22c8bbe4 (patch)
tree729d483ad8f66cf7907bedbb2d01dec6d2856654
parent3fddf300bd33b356540bee50ae17590ea9b61341 (diff)
downloadthird_party-ruby-git-07ebb951368ed31bdaebc2e820c62ced22c8bbe4.zip
third_party-ruby-git-07ebb951368ed31bdaebc2e820c62ced22c8bbe4.tar.gz
third_party-ruby-git-07ebb951368ed31bdaebc2e820c62ced22c8bbe4.tar.xz
added Matthias and Simon to credits for the gitrb code
fixed an issue with raw object tree formatting added ls_tree implementation in raw git
-rw-r--r--camping/gitweb.rb10
-rw-r--r--lib/git/lib.rb16
-rw-r--r--lib/git/raw/internal/loose.rb10
-rw-r--r--lib/git/raw/internal/mmap.rb10
-rw-r--r--lib/git/raw/internal/object.rb10
-rw-r--r--lib/git/raw/internal/pack.rb10
-rw-r--r--lib/git/raw/object.rb28
-rw-r--r--lib/git/raw/repository.rb19
-rw-r--r--tests/test_helper.rb10
-rw-r--r--tests/units/test_index_ops.rb2
-rw-r--r--tests/units/test_lib.rb9
-rw-r--r--tests/units/test_raw_internals.rb26
12 files changed, 139 insertions, 21 deletions
diff --git a/camping/gitweb.rb b/camping/gitweb.rb
index 8dc40ba..3d1b5d6 100644
--- a/camping/gitweb.rb
+++ b/camping/gitweb.rb
@@ -107,10 +107,7 @@ module GitWeb::Controllers
class Commit < R '/commit/(\d+)/(\w+)'
def get repo_id, sha
@repo = Repository.find repo_id
- logger = Logger.new('/tmp/git.log')
- logger.level = Logger::INFO
-
- @git = Git.bare(@repo.path, :log => logger)
+ @git = Git.bare(@repo.path)
@commit = @git.gcommit(sha)
render :commit
end
@@ -119,7 +116,10 @@ module GitWeb::Controllers
class Tree < R '/tree/(\d+)/(\w+)'
def get repo_id, sha
@repo = Repository.find repo_id
- @git = Git.bare(@repo.path)
+ logger = Logger.new('/tmp/git.log')
+ logger.level = Logger::INFO
+
+ @git = Git.bare(@repo.path, :log => logger)
@tree = @git.gtree(sha)
render :tree
end
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
index 120d9ce..decd6d4 100644
--- a/lib/git/lib.rb
+++ b/lib/git/lib.rb
@@ -183,16 +183,22 @@ module Git
def object_contents(sha)
#command('cat-file', ['-p', sha])
- get_raw_repo.cat_file(revparse(sha))
+ get_raw_repo.cat_file(revparse(sha)).chomp
end
def ls_tree(sha)
data = {'blob' => {}, 'tree' => {}}
- command_lines('ls-tree', sha.to_s).each do |line|
- (info, filenm) = line.split("\t")
- (mode, type, sha) = info.split
- data[type][filenm] = {:mode => mode, :sha => sha}
+
+ get_raw_repo.object(revparse(sha)).entry.each do |e|
+ data[e.format_type][e.name] = {:mode => e.format_mode, :sha => e.sha1}
end
+
+ #command_lines('ls-tree', sha.to_s).each do |line|
+ # (info, filenm) = line.split("\t")
+ # (mode, type, sha) = info.split
+ # data[type][filenm] = {:mode => mode, :sha => sha}
+ #end
+
data
end
diff --git a/lib/git/raw/internal/loose.rb b/lib/git/raw/internal/loose.rb
index d8ec6fb..53d4334 100644
--- a/lib/git/raw/internal/loose.rb
+++ b/lib/git/raw/internal/loose.rb
@@ -1,3 +1,13 @@
+#
+# converted from the gitrb project
+#
+# authors:
+# Matthias Lederhofer <matled@gmx.net>
+# Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
+#
+# provides native ruby access to git objects and pack files
+#
+
require 'zlib'
require 'digest/sha1'
diff --git a/lib/git/raw/internal/mmap.rb b/lib/git/raw/internal/mmap.rb
index 15b5628..78de164 100644
--- a/lib/git/raw/internal/mmap.rb
+++ b/lib/git/raw/internal/mmap.rb
@@ -1,3 +1,13 @@
+#
+# converted from the gitrb project
+#
+# authors:
+# Matthias Lederhofer <matled@gmx.net>
+# Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
+#
+# provides native ruby access to git objects and pack files
+#
+
begin
require 'mmap'
rescue LoadError
diff --git a/lib/git/raw/internal/object.rb b/lib/git/raw/internal/object.rb
index 7f95685..172b917 100644
--- a/lib/git/raw/internal/object.rb
+++ b/lib/git/raw/internal/object.rb
@@ -1,3 +1,13 @@
+#
+# converted from the gitrb project
+#
+# authors:
+# Matthias Lederhofer <matled@gmx.net>
+# Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
+#
+# provides native ruby access to git objects and pack files
+#
+
require 'digest/sha1'
module Git
diff --git a/lib/git/raw/internal/pack.rb b/lib/git/raw/internal/pack.rb
index 6980a98..8d5141e 100644
--- a/lib/git/raw/internal/pack.rb
+++ b/lib/git/raw/internal/pack.rb
@@ -1,3 +1,13 @@
+#
+# converted from the gitrb project
+#
+# authors:
+# Matthias Lederhofer <matled@gmx.net>
+# Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
+#
+# provides native ruby access to git objects and pack files
+#
+
require 'zlib'
require 'git/raw/internal/object'
require 'git/raw/internal/mmap'
diff --git a/lib/git/raw/object.rb b/lib/git/raw/object.rb
index f10d853..5c3969d 100644
--- a/lib/git/raw/object.rb
+++ b/lib/git/raw/object.rb
@@ -1,3 +1,13 @@
+#
+# converted from the gitrb project
+#
+# authors:
+# Matthias Lederhofer <matled@gmx.net>
+# Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
+#
+# provides native ruby access to git objects and pack files
+#
+
require 'digest/sha1'
module Git
@@ -132,6 +142,21 @@ module Git
end
end
+ def format_type
+ case type
+ when :link
+ 'link'
+ when :directory
+ 'tree'
+ when :file
+ 'blob'
+ end
+ end
+
+ def format_mode
+ "%06o" % @mode
+ end
+
def raw
"%o %s\0%s" % [@mode, @name, [@sha1].pack("H*")]
end
@@ -160,8 +185,7 @@ module Git
def raw_content
# TODO: sort correctly
#@entry.sort { |a,b| a.name <=> b.name }.
- @entry.
- collect { |e| e.raw }.join
+ @entry.collect { |e| [[e.format_mode, e.format_type, e.sha1].join(' '), e.name].join("\t") }.join("\n")
end
end
diff --git a/lib/git/raw/repository.rb b/lib/git/raw/repository.rb
index 4a1c897..bd5e971 100644
--- a/lib/git/raw/repository.rb
+++ b/lib/git/raw/repository.rb
@@ -1,3 +1,13 @@
+#
+# converted from the gitrb project
+#
+# authors:
+# Matthias Lederhofer <matled@gmx.net>
+# Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
+#
+# provides native ruby access to git objects and pack files
+#
+
require 'git/raw/internal/object'
require 'git/raw/internal/pack'
require 'git/raw/internal/loose'
@@ -28,9 +38,14 @@ module Git
puts
end
end
-
+
+ def object(sha)
+ o = get_raw_object_by_sha1(sha)
+ c = Git::Raw::Object.from_raw(o)
+ end
+
def cat_file(sha)
- get_raw_object_by_sha1(sha).content rescue nil
+ object(sha).raw_content
end
def log(sha, count = 30)
diff --git a/tests/test_helper.rb b/tests/test_helper.rb
index 9907ffe..e40174a 100644
--- a/tests/test_helper.rb
+++ b/tests/test_helper.rb
@@ -28,6 +28,16 @@ class Test::Unit::TestCase
end
end
+
+ def with_temp_bare
+ in_temp_dir do |path|
+ g = Git.clone(@wbare, 'new')
+ Dir.chdir('new') do
+ yield g
+ end
+ end
+ end
+
def create_temp_repo(clone_path)
filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
@tmp_path = File.join("/tmp/", filename)
diff --git a/tests/units/test_index_ops.rb b/tests/units/test_index_ops.rb
index f92ae9e..dcd8498 100644
--- a/tests/units/test_index_ops.rb
+++ b/tests/units/test_index_ops.rb
@@ -10,7 +10,7 @@ class TestIndexOps < Test::Unit::TestCase
end
def test_add
- in_temp_dir(false) do |path|
+ in_temp_dir do |path|
g = Git.clone(@wbare, 'new')
Dir.chdir('new') do
assert_equal('100644', g.status['example.txt'].mode_index)
diff --git a/tests/units/test_lib.rb b/tests/units/test_lib.rb
index f9170e6..7cbbeef 100644
--- a/tests/units/test_lib.rb
+++ b/tests/units/test_lib.rb
@@ -102,6 +102,15 @@ class TestLib < Test::Unit::TestCase
assert_equal('+refs/heads/*:refs/remotes/working/*', config['fetch'])
end
+
+ def test_ls_tree
+ tree = @lib.ls_tree('94c827875e2cadb8bc8d4cdd900f19aa9e8634c7')
+ assert_equal("3aac4b445017a8fc07502670ec2dbf744213dd48", tree['blob']['example.txt'][:sha])
+ assert_equal("100644", tree['blob']['example.txt'][:mode])
+ assert(tree['tree'])
+ end
+
+
# options this will accept
# :treeish
# :path_limiter
diff --git a/tests/units/test_raw_internals.rb b/tests/units/test_raw_internals.rb
index 1437845..03a7916 100644
--- a/tests/units/test_raw_internals.rb
+++ b/tests/units/test_raw_internals.rb
@@ -9,14 +9,16 @@ class TestRawInternals < Test::Unit::TestCase
end
def test_raw_log
- g = Git.bare(@wbare)
- t_log(g)
+ with_temp_bare do |g|
+ t_log(g)
+ end
end
def test_packed_log
- g = Git.bare(@wbare)
- g.repack
- t_log(g)
+ with_temp_bare do |g|
+ g.repack
+ t_log(g)
+ end
end
def test_commit_object
@@ -26,15 +28,27 @@ class TestRawInternals < Test::Unit::TestCase
assert_equal('test', c.message)
end
+ def test_lstree
+ g = Git.bare(@wbare)
+ c = g.object("v2.5").gtree
+ sha = c.sha
+
+ repo = Git::Raw::Repository.new(@wbare)
+ puts repo.object(sha).inspect
+ end
+
def t_log(g)
c = g.object("v2.5")
sha = c.sha
- repo = Git::Raw::Repository.new(@wbare)
+ repo = Git::Raw::Repository.new(g.repo.path)
raw_out = repo.log(sha)
assert_equal('commit 546bec6f8872efa41d5d97a369f669165ecda0de', raw_out.split("\n").first)
assert_equal('546bec6f8872efa41d5d97a369f669165ecda0de', c.log(30).first.sha)
end
+
+
+
end \ No newline at end of file