Permalink
Browse files

pulled in changes from github

  • Loading branch information...
1 parent a92a84f commit c7f1990597b63aeded4f81ebd3fb29e0aded5606 @schacon schacon committed Jul 9, 2008
View
@@ -2,3 +2,4 @@ coverage
pkg/*.tgz
doc
test/specifics.rb
+test.rb
View
@@ -36,7 +36,7 @@ def initialize(repo, id, parents, tree, author, authored_date, committer, commit
end
def id_abbrev
- @id_abbrev ||= @repo.git.rev_parse({:short => true}, self.id).chomp
+ @id_abbrev ||= @repo.git.rev_parse({}, self.id).chomp[0, 7]
end
# Create an unbaked Commit containing just the specified attributes
@@ -84,7 +84,7 @@ def self.count(repo, ref)
# Returns Grit::Commit[] (baked)
def self.find_all(repo, ref, options = {})
allowed_options = [:max_count, :skip, :since]
-
+
default_options = {:pretty => "raw"}
actual_options = default_options.merge(options)
@@ -93,15 +93,21 @@ def self.find_all(repo, ref, options = {})
else
output = repo.git.rev_list(actual_options.merge(:all => true))
end
-
+
self.list_from_string(repo, output)
+ rescue Grit::GitRuby::Repository::NoSuchShaFound
+ []
end
# Parse out commit information into an array of baked Commit objects
# +repo+ is the Repo
# +text+ is the text output from the git command (raw format)
#
# Returns Grit::Commit[] (baked)
+ #
+ # really should re-write this to be more accepting of non-standard commit messages
+ # - it broke when 'encoding' was introduced - not sure what else might show up
+ #
def self.list_from_string(repo, text)
lines = text.split("\n")
@@ -117,6 +123,9 @@ def self.list_from_string(repo, text)
author, authored_date = self.actor(lines.shift)
committer, committed_date = self.actor(lines.shift)
+ # not doing anything with this yet, but it's sometimes there
+ encoding = lines.shift.split.last if lines.first =~ /^encoding/
+
lines.shift
message_lines = []
View
@@ -16,7 +16,7 @@ def cat_file(options, ref)
elsif options[:s]
file_size(ref)
elsif options[:p]
- ruby_git.cat_file(ref)
+ try_run { ruby_git.cat_file(ref) }
end
end
@@ -28,7 +28,7 @@ def ls_tree(options, treeish, *paths)
# git diff --full-index 'ec037431382e83c3e95d4f2b3d145afbac8ea55d' 'f1ec1aea10986159456846b8a05615b87828d6c6'
def diff(options, sha1, sha2)
- ruby_git.diff(sha1, sha2, options)
+ try_run { ruby_git.diff(sha1, sha2, options) }
end
def rev_list(options, ref = 'master')
@@ -44,7 +44,12 @@ def rev_list(options, ref = 'master')
return method_missing('rev-list', options, ref)
end
else
- return ruby_git.rev_list(rev_parse({}, ref), options)
+ aref = rev_parse({}, ref)
+ if aref.is_a? Array
+ return method_missing('rev-list', options, ref)
+ else
+ return try_run { ruby_git.rev_list(aref, options) }
+ end
end
end
@@ -67,19 +72,29 @@ def rev_parse(options, string)
head = File.join(@git_dir, 'refs', 'tags', string)
return File.read(head).chomp if File.file?(head)
- ## !! check packed-refs file, too !!
+ ## check packed-refs file, too
+ packref = File.join(@git_dir, 'packed-refs')
+ if File.file?(packref)
+ File.readlines(packref).each do |line|
+ if m = /^(\w{40}) (.*?)$/.match(line)
+ next if !Regexp.new(string + '$').match(m[2])
+ return m[1].chomp
+ end
+ end
+ end
+
## !! more - partials and such !!
# revert to calling git - grr
- return method_missing('rev-parse', {}, string)
+ return method_missing('rev-parse', {}, string).chomp
end
def file_size(ref)
- ruby_git.cat_file_size(ref).to_s
+ try_run { ruby_git.cat_file_size(ref).to_s }
end
def file_type(ref)
- ruby_git.cat_file_type(ref)
+ try_run { ruby_git.cat_file_type(ref).to_s }
end
def blame_tree(commit, path = nil)
@@ -101,6 +116,26 @@ def ruby_git
private
+ def try_run
+ ret = ''
+ Timeout.timeout(self.class.git_timeout) do
+ ret = yield
+ end
+ @bytes_read += ret.size
+
+ #if @bytes_read > 5242880 # 5.megabytes
+ # bytes = @bytes_read
+ # @bytes_read = 0
+ # raise Grit::Git::GitTimeout.new(command, bytes)
+ #end
+
+ ret
+ rescue Timeout::Error => e
+ bytes = @bytes_read
+ @bytes_read = 0
+ raise Grit::Git::GitTimeout.new(command, bytes)
+ end
+
def looking_for(commit, path = nil)
tree_sha = ruby_git.get_subtree(rev_parse({}, commit), path)
@@ -14,11 +14,13 @@
module Grit
module GitRuby
- # class for author/committer/tagger lines
class FileIndex
class IndexFileNotFound < StandardError
end
+
+ class UnsupportedRef < StandardError
+ end
attr_reader :files
@@ -45,6 +47,8 @@ def count(commit_sha)
end
def commits_from(commit_sha)
+ raise UnsupportedRef if commit_sha.is_a? Array
+
already = {}
final = []
left_to_do = [commit_sha]
@@ -61,7 +65,11 @@ def commits_from(commit_sha)
end if commit
end
- final
+ sort_commits(final)
+ end
+
+ def sort_commits(sha_array)
+ sha_array.sort { |a, b| @commit_order[b] <=> @commit_order[a] }
end
# returns files changed at commit sha
@@ -109,13 +117,15 @@ def read_index
f = File.new(@index_file)
@sha_count = 0
@commit_index = {}
+ @commit_order = {}
@all_files = {}
while line = f.gets
if /^(\w{40})/.match(line)
shas = line.scan(/(\w{40})/)
current_sha = shas.shift.first
parents = shas.map { |sha| sha.first }
@commit_index[current_sha] = {:files => [], :parents => parents }
+ @commit_order[current_sha] = @sha_count
@sha_count += 1
else
file_name = line.chomp
Oops, something went wrong.

0 comments on commit c7f1990

Please sign in to comment.