зеркало из https://github.com/github/grit.git
Where github/github actual is
Pretty clear there's zero fucks for keeping these sync'd up.
This commit is contained in:
Родитель
0cc948995b
Коммит
78f7ce74eb
|
@ -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'
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ require 'grit/status'
|
|||
require 'grit/submodule'
|
||||
require 'grit/blame'
|
||||
require 'grit/merge'
|
||||
require 'grit/rev_list_parser'
|
||||
|
||||
module Grit
|
||||
VERSION = '2.5.0'
|
||||
|
|
|
@ -137,39 +137,15 @@ module Grit
|
|||
# - it broke when 'encoding' was introduced - not sure what else might show up
|
||||
#
|
||||
def self.list_from_string(repo, text)
|
||||
lines = text.split("\n")
|
||||
parser = RevListParser.new(text)
|
||||
parser.entries.map { |entry| bake_from_parser(repo, entry) }
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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.
|
||||
|
|
|
@ -29,7 +29,22 @@ module Grit
|
|||
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+)/)
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'grit/git-ruby/repository'
|
|||
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
|
||||
|
||||
|
|
|
@ -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 @@ module Grit
|
|||
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 @@ module Grit
|
|||
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
|
||||
|
|
|
@ -128,7 +128,7 @@ module Grit
|
|||
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 @@ module Grit
|
|||
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)
|
||||
|
|
|
@ -399,7 +399,7 @@ module Grit
|
|||
# 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)
|
||||
|
|
|
@ -40,8 +40,11 @@ module Grit
|
|||
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`
|
||||
|
|
|
@ -15,6 +15,7 @@ module Grit
|
|||
#
|
||||
# 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
|
||||
|
|
|
@ -194,7 +194,7 @@ class TestCommit < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
# patch_id
|
||||
|
||||
|
||||
def test_patch_id
|
||||
@c = Commit.create(@r, :id => '80f136f500dfdb8c3e8abf4ae716f875f0a1b57f')
|
||||
assert_equal '9450b04e4f83ad0067199c9e9e338197d1835cbb', @c.patch_id
|
||||
|
@ -228,4 +228,23 @@ class TestCommit < Test::Unit::TestCase
|
|||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче