summaryrefslogtreecommitdiffstats
path: root/lib/git/log.rb
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-08 17:07:04 -0800
committerscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-08 17:07:04 -0800
commit1f63953f05a4afe74f881d54f69f77da513939d5 (patch)
tree5fabd81a82d8aa3df0e9cdc10b0ed7f6ff141b8a /lib/git/log.rb
parentb18bca3b853dee6a7bc86f09921aa3b1ee3f3d7b (diff)
downloadthird_party-ruby-git-1f63953f05a4afe74f881d54f69f77da513939d5.tar.gz
third_party-ruby-git-1f63953f05a4afe74f881d54f69f77da513939d5.tar.xz
third_party-ruby-git-1f63953f05a4afe74f881d54f69f77da513939d5.zip
moved the git objects into the object.rb file
Diffstat (limited to 'lib/git/log.rb')
-rw-r--r--lib/git/log.rb62
1 files changed, 56 insertions, 6 deletions
diff --git a/lib/git/log.rb b/lib/git/log.rb
index fab605e..d11a6fa 100644
--- a/lib/git/log.rb
+++ b/lib/git/log.rb
@@ -7,29 +7,79 @@ module Git
@base = nil
@commits = nil
+ @file = nil
+ @count = nil
+ @since = nil
+ @between = nil
+
+ @dirty_flag = nil
+
def initialize(base, count = 30)
+ dirty_log
@base = base
- @commits = @base.lib.log_shas(count)
+ @count = count
+ end
+
+ def file(file)
+ dirty_log
+ @file = file
+ return self
+ end
+
+ def since(date)
+ dirty_log
+ @since = date
+ return self
+ end
+
+ def between(sha1, sha2 = nil)
+ dirty_log
+ @between = [@base.lib.revparse(sha1), @base.lib.revparse(sha2)]
+ return self
+ end
+
+ def to_s
+ self.map { |c| c.sha }.join("\n")
end
+
+ # forces git log to run
+
def size
- @commits.size
+ check_log
+ @commits.size rescue nil
end
def each
+ check_log
@commits.each do |c|
yield c
end
end
def first
- @commits.first
+ check_log
+ @commits.first rescue nil
end
- def to_s
- self.map { |c| c.sha }.join("\n")
- end
+ private
+ def dirty_log
+ @dirty_flag = true
+ end
+
+ def check_log
+ if @dirty_flag
+ run_log
+ @dirty_flag = false
+ end
+ end
+
+ # actually run the 'git log' command
+ def run_log
+ @commits = @base.lib.log_commits(:count => @count, :file => @file, :since => @since, :between => @between)
+ end
+
end
end \ No newline at end of file