Browse files

Where github/github actual is

Pretty clear there's zero fucks for keeping these sync'd up.
  • Loading branch information...
1 parent 0cc9489 commit 78f7ce74eb2658f21c156d31e9ee15824143c3d6 @rtomayko rtomayko committed Feb 23, 2013
Showing with 62 additions and 60 deletions.
  1. +1 −1 grit.gemspec
  2. +1 −0 lib/grit.rb
  3. +8 −32 lib/grit/commit.rb
  4. +16 −1 lib/grit/diff.rb
  5. +1 −1 lib/grit/git-ruby.rb
  6. +3 −20 lib/grit/git-ruby/internal/loose.rb
  7. +5 −1 lib/grit/git.rb
  8. +1 −1 lib/grit/repo.rb
  9. +5 −2 lib/grit/tag.rb
  10. +1 −0 lib/grit/tree.rb
  11. +20 −1 test/test_commit.rb
View
2 grit.gemspec
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
s.rubygems_version = '1.3.5'
s.name = 'grit'
- s.version = '2.5.0'
+ s.version = '2.4.2.github'
s.date = '2012-04-22'
s.rubyforge_project = 'grit'
View
1 lib/grit.rb
@@ -47,6 +47,7 @@
require 'grit/submodule'
require 'grit/blame'
require 'grit/merge'
+require 'grit/rev_list_parser'
module Grit
VERSION = '2.5.0'
View
40 lib/grit/commit.rb
@@ -137,39 +137,15 @@ def self.find_all(repo, ref, options = {})
# - it broke when 'encoding' was introduced - not sure what else might show up
#
def self.list_from_string(repo, text)
- lines = text.split("\n")
-
- commits = []
-
- while !lines.empty?
- id = lines.shift.split.last
- tree = lines.shift.split.last
-
- parents = []
- parents << lines.shift.split.last while lines.first =~ /^parent/
-
- author_line = lines.shift
- author_line << lines.shift if lines[0] !~ /^committer /
- author, authored_date = self.actor(author_line)
-
- committer_line = lines.shift
- committer_line << lines.shift if lines[0] && lines[0] != '' && lines[0] !~ /^encoding/
- committer, committed_date = self.actor(committer_line)
-
- # not doing anything with this yet, but it's sometimes there
- encoding = lines.shift.split.last if lines.first =~ /^encoding/
-
- lines.shift
-
- message_lines = []
- message_lines << lines.shift[4..-1] while lines.first =~ /^ {4}/
-
- lines.shift while lines.first && lines.first.empty?
-
- commits << Commit.new(repo, id, parents, tree, author, authored_date, committer, committed_date, message_lines)
- end
+ parser = RevListParser.new(text)
+ parser.entries.map { |entry| bake_from_parser(repo, entry) }
+ end
- commits
+ def self.bake_from_parser(repo, entry)
+ author, authored_date = actor('author ' + entry.author)
+ committer, committed_date = actor('committer ' + entry.committer)
+ new(repo, entry.commit, entry.parents, entry.tree, author, authored_date,
+ committer, committed_date, entry.message_lines)
end
# Show diffs between two trees.
View
17 lib/grit/diff.rb
@@ -29,7 +29,22 @@ def self.list_from_string(repo, text)
diffs = []
while !lines.empty?
- m, a_path, b_path = *lines.shift.match(%r{^diff --git a/(.+?) b/(.+)$})
+ m, q1, a_path, q2, b_path = *lines.shift.match(%r{^diff --git ("?)a/(.+?)\1 ("?)b/(.+?)\3$})
+
+ # If the filename(s) are quoted, they contain special characters that may be escaped.
+ #
+ # While it's possible for systems that are eg. old or badly configured to store
+ # filenames that are not UTF-8 encoded, the most reasonable thing to do is assume
+ # that they are UTF-8 encoded.
+ if !q1.empty? || !q2.empty?
+ a_path = a_path.gsub(/\\([0-9]{3})/){|c| c[1..-1].oct.chr}
+ b_path = b_path.gsub(/\\([0-9]{3})/){|c| c[1..-1].oct.chr}
+
+ # The above gsub returns a string with ASCII-8BIT encoding in Ruby 1.9,
+ # even though a_path and b_path are UTF-8 encoded.
+ a_path.force_encoding( 'UTF-8' ) if a_path.respond_to?( :force_encoding )
+ b_path.force_encoding( 'UTF-8' ) if b_path.respond_to?( :force_encoding )
+ end
if lines.first =~ /^old mode/
m, a_mode = *lines.shift.match(/^old mode (\d+)/)
View
2 lib/grit/git-ruby.rb
@@ -3,7 +3,7 @@
module Grit
# the functions in this module intercept the calls to git binary
- # made by the grit objects and attempts to run them in pure ruby
+ # made buy the grit objects and attempts to run them in pure ruby
# if it will be faster, or if the git binary is not available (!!TODO!!)
module GitRuby
View
23 lib/grit/git-ruby/internal/loose.rb
@@ -12,7 +12,6 @@
require 'zlib'
require 'digest/sha1'
require 'grit/git-ruby/internal/raw_object'
-require 'tempfile'
module Grit
module GitRuby
@@ -61,24 +60,6 @@ def get_raw_object(buf)
return RawObject.new(type, content)
end
- # write an object to a temporary file, then atomically rename it
- # into place; this ensures readers never see a half-written file
- def safe_write(path, content)
- Tempfile.open("tmp_obj_", File.dirname(path), :opt => "wb") do |f|
- f.write content
- f.fsync
- f.close
- begin
- File.link(f.path, path)
- rescue Errno::EEXIST
- # The path already exists; we raced with another process,
- # but it's OK, because by definition the content is the
- # same. So we can just ignore the error.
- end
- f.unlink
- end
- end
-
# currently, I'm using the legacy format because it's easier to do
# this function takes content and a type and writes out the loose object and returns a sha
def put_raw_object(content, type)
@@ -95,7 +76,9 @@ def put_raw_object(content, type)
content = Zlib::Deflate.deflate(store)
FileUtils.mkdir_p(@directory+'/'+sha1[0...2])
- safe_write(path, content)
+ File.open(path, 'wb') do |f|
+ f.write content
+ end
end
return sha1
end
View
6 lib/grit/git.rb
@@ -128,7 +128,7 @@ def fs_read(file)
def fs_write(file, contents)
path = File.join(self.git_dir, file)
FileUtils.mkdir_p(File.dirname(path))
- File.open(path, 'w') do |f|
+ File.open(path, 'wb') do |f|
f.write(contents)
end
end
@@ -351,6 +351,10 @@ def native(cmd, options = {}, *args, &block)
Grit.log(process.out) if Grit.debug
Grit.log(process.err) if Grit.debug
+ if defined? $stats and $stats
+ $stats.timing("git.cmd.#{cmd}", process.runtime * 1000)
+ end
+
status = process.status
if raise_errors && !status.success?
raise CommandFailed.new(argv.join(' '), status.exitstatus, process.err)
View
2 lib/grit/repo.rb
@@ -399,7 +399,7 @@ def fast_forwardable?(to, from)
# The Commits objects that are newer than the specified date.
# Commits are returned in chronological order.
# +start+ is the branch/commit name (default 'master')
- # +since+ is a string representing a date/time
+ # +since+ is a string represeting a date/time
# +extra_options+ is a hash of extra options
#
# Returns Grit::Commit[] (baked)
View
7 lib/grit/tag.rb
@@ -40,8 +40,11 @@ def self.create_tag_object(repo, hash, default_actor = nil)
data << ""
data << hash[:message]
data = data.join("\n")
- sha = repo.git.put_raw_object(data, 'tag')
- { :sha => sha, :size => data.size }
+
+ repo.git.native(:mktag, {
+ :input => data,
+ :raise => true
+ }).chomp
end
# Parses the results from `cat-file -p`
View
1 lib/grit/tree.rb
@@ -15,6 +15,7 @@ class Tree
#
# Returns Grit::Tree (baked)
def self.construct(repo, treeish, paths = [])
+ paths = [] if paths.empty? # paths == ""
output = repo.git.ls_tree({:raise => true}, treeish, *paths)
self.allocate.construct_initialize(repo, treeish, output)
end
View
21 test/test_commit.rb
@@ -194,7 +194,7 @@ def test_to_patch
end
# patch_id
-
+
def test_patch_id
@c = Commit.create(@r, :id => '80f136f500dfdb8c3e8abf4ae716f875f0a1b57f')
assert_equal '9450b04e4f83ad0067199c9e9e338197d1835cbb', @c.patch_id
@@ -228,4 +228,23 @@ def test_to_hash
ensure
ENV["TZ"] = old_tz
end
+
+ # .list_from_string
+
+ def test_list_from_string
+ repo = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git_signed_tag_merged]), :is_bare => true)
+ rev_list = repo.git.rev_list({:pretty => "raw", :all => true})
+ commits = Commit.list_from_string(@r, rev_list)
+
+ assert_equal 4, commits.size
+ end
+
+ def test_list_from_string_with_single_signed_commit
+ sha = '671d0b0a85af271395eb71ff91f942f54681b144'
+ repo = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git_signed_tag_merged]), :is_bare => true)
+ rev_list = repo.git.rev_list({:pretty => "raw", :max_count => 1}, sha)
+ commits = Commit.list_from_string(@r, rev_list)
+
+ assert_equal 1, commits.size
+ end
end

0 comments on commit 78f7ce7

Please sign in to comment.