summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-08 11:22:46 -0800
committerscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-08 11:22:46 -0800
commitb18bca3b853dee6a7bc86f09921aa3b1ee3f3d7b (patch)
tree718f1b6451f5a9dd9b8cb844fa3d3e9f32400d50 /lib
parent169381bbce998807c119f291d69b8ae1d8fb5785 (diff)
downloadthird_party-ruby-git-b18bca3b853dee6a7bc86f09921aa3b1ee3f3d7b.tar.gz
third_party-ruby-git-b18bca3b853dee6a7bc86f09921aa3b1ee3f3d7b.tar.xz
third_party-ruby-git-b18bca3b853dee6a7bc86f09921aa3b1ee3f3d7b.zip
added log functions
Diffstat (limited to 'lib')
-rw-r--r--lib/git.rb10
-rw-r--r--lib/git/base.rb9
-rw-r--r--lib/git/commit.rb4
-rw-r--r--lib/git/lib.rb22
-rw-r--r--lib/git/log.rb35
-rw-r--r--lib/git/object.rb16
6 files changed, 92 insertions, 4 deletions
diff --git a/lib/git.rb b/lib/git.rb
index 2e372d0..c8e14ad 100644
--- a/lib/git.rb
+++ b/lib/git.rb
@@ -6,16 +6,19 @@ $:.unshift(File.dirname(__FILE__)) unless
require 'git/base'
require 'git/path'
-#require 'git/lib'
+require 'git/lib'
require 'git/repository'
require 'git/index'
require 'git/working_directory'
-=begin
+require 'git/log'
require 'git/object'
-require 'git/object/commit'
+require 'git/commit'
+
+=begin
+
require 'git/object/blob'
require 'git/object/tree'
require 'git/object/tag'
@@ -24,7 +27,6 @@ require 'git/author'
require 'git/ref'
require 'git/file'
-require 'git/log'
require 'git/sha'
require 'git/diff'
diff --git a/lib/git/base.rb b/lib/git/base.rb
index 6eb3455..c943b86 100644
--- a/lib/git/base.rb
+++ b/lib/git/base.rb
@@ -49,6 +49,15 @@ module Git
@index
end
+
+ def log(count = 30)
+ Git::Log.new(self, count)
+ end
+
+ def lib
+ Git::Lib.new(self)
+ end
+
private
def is_git_dir(dir)
diff --git a/lib/git/commit.rb b/lib/git/commit.rb
new file mode 100644
index 0000000..1cd5d1d
--- /dev/null
+++ b/lib/git/commit.rb
@@ -0,0 +1,4 @@
+module Git
+ class Commit < Git::Object
+ end
+end \ No newline at end of file
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
new file mode 100644
index 0000000..3df049c
--- /dev/null
+++ b/lib/git/lib.rb
@@ -0,0 +1,22 @@
+module Git
+ class Lib
+
+ @base = nil
+
+ def initialize(base)
+ @base = base
+ end
+
+ def log_shas(count)
+ command('log', "-#{count} --pretty=oneline").split("\n").map { |l| Git::Commit.new(l.split.first) }
+ end
+
+ private
+
+ def command(cmd, opts)
+ ENV['GIT_DIR'] = @base.repo.path
+ `git #{cmd} #{opts}`
+ end
+
+ end
+end \ No newline at end of file
diff --git a/lib/git/log.rb b/lib/git/log.rb
new file mode 100644
index 0000000..fab605e
--- /dev/null
+++ b/lib/git/log.rb
@@ -0,0 +1,35 @@
+module Git
+
+ # object that holds the last X commits on given branch
+ class Log
+ include Enumerable
+
+ @base = nil
+ @commits = nil
+
+ def initialize(base, count = 30)
+ @base = base
+ @commits = @base.lib.log_shas(count)
+ end
+
+ def size
+ @commits.size
+ end
+
+ def each
+ @commits.each do |c|
+ yield c
+ end
+ end
+
+ def first
+ @commits.first
+ end
+
+ def to_s
+ self.map { |c| c.sha }.join("\n")
+ end
+
+ end
+
+end \ No newline at end of file
diff --git a/lib/git/object.rb b/lib/git/object.rb
new file mode 100644
index 0000000..0252fdb
--- /dev/null
+++ b/lib/git/object.rb
@@ -0,0 +1,16 @@
+module Git
+ class Object
+ attr_accessor :sha, :type
+
+ def initialize(sha)
+ @sha = sha
+ end
+
+ def cat_file
+ end
+
+ def raw
+ end
+
+ end
+end \ No newline at end of file