Skip to content
Snippets Groups Projects
Commit 7ec653ff authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Merge pull request #20 from gitlabhq/gitlab-grit-gem

WIP: gitlab-grit gem to replace grit fork
parents e873bb84 ddbc1dd7
No related branches found
No related tags found
No related merge requests found
pkg
.DS_Store
repos/grit/
*.gem
env:
- TRAVIS=true
before_install:
- sudo apt-get install libicu-dev -y
branches:
only:
- 'master'
rvm:
- 1.9.3
- 2.0.0
before_script:
- "bundle install"
script: "bundle exec rake test"
source "http://rubygems.org"
 
gemspec
group :development, :test do
gem 'pry'
gem 'rake'
gem 'posix-spawn', "~> 0.3.6"
gem 'mime-types', "~> 1.15"
gem 'diff-lcs', "~> 1.1"
gem 'mocha', "~> 0.13.2"
gem 'coveralls', require: false
gem 'rspec', '~> 2.11'
end
PATH
remote: .
specs:
gitlab-grit (2.5.0)
charlock_holmes (~> 0.6.9)
diff-lcs (~> 1.1)
mime-types (~> 1.15)
posix-spawn (~> 0.3.6)
GEM
remote: http://rubygems.org/
specs:
charlock_holmes (0.6.9.4)
coderay (1.0.9)
colorize (0.5.8)
coveralls (0.6.2)
colorize
Loading
Loading
@@ -10,18 +21,32 @@ GEM
thor
diff-lcs (1.1.3)
metaclass (0.0.1)
method_source (0.8.1)
mime-types (1.18)
mocha (0.13.2)
metaclass (~> 0.0.1)
multi_json (1.7.2)
posix-spawn (0.3.6)
pry (0.9.12.2)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
rake (0.9.2.2)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (2.13.0)
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
rspec-mocks (~> 2.13.0)
rspec-core (2.13.1)
rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.1)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
slop (3.4.4)
thor (0.18.0)
 
PLATFORMS
Loading
Loading
@@ -30,7 +55,10 @@ PLATFORMS
DEPENDENCIES
coveralls
diff-lcs (~> 1.1)
gitlab-grit!
mime-types (~> 1.15)
mocha (~> 0.13.2)
posix-spawn (~> 0.3.6)
pry
rake
rspec (~> 2.11)
Loading
Loading
@@ -2,48 +2,7 @@ require 'rubygems'
require 'rake'
require 'date'
 
#############################################################################
#
# Helper functions
#
#############################################################################
def name
@name ||= Dir['*.gemspec'].first.split('.').first
end
def version
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
end
def date
Date.today.to_s
end
def rubyforge_project
name
end
def gemspec_file
"#{name}.gemspec"
end
def gem_file
"#{name}-#{version}.gem"
end
def replace_header(head, header_name)
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
end
#############################################################################
#
# Standard tasks
#
#############################################################################
task :default => :test
task default: :test
 
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
Loading
Loading
@@ -52,98 +11,7 @@ Rake::TestTask.new(:test) do |test|
test.verbose = true
end
 
desc "Generate RCov test coverage and open in your browser"
task :coverage do
require 'rcov'
sh "rm -fr coverage"
sh "rcov test/test_*.rb"
sh "open coverage/index.html"
end
require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "#{name} #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
desc "Open an irb session preloaded with this library"
task :console do
sh "irb -rubygems -r ./lib/#{name}.rb"
end
#############################################################################
#
# Custom tasks (add your own tasks here)
#
#############################################################################
desc "Upload site to Rubyforge"
task :site do
sh "scp -r doc/* mojombo@grit.rubyforge.org:/var/www/gforge-projects/grit"
end
#############################################################################
#
# Packaging tasks
#
#############################################################################
task :release => :build do
unless `git branch` =~ /^\* master$/
puts "You must be on the master branch to release!"
exit!
end
sh "git commit --allow-empty -a -m 'Release #{version}'"
sh "git tag v#{version}"
sh "git push origin master"
sh "git push origin v#{version}"
sh "gem push pkg/#{name}-#{version}.gem"
end
task :build => :gemspec do
sh "mkdir -p pkg"
sh "gem build #{gemspec_file}"
sh "mv #{gem_file} pkg"
end
task :gemspec => :validate do
# read spec file and split out manifest section
spec = File.read(gemspec_file)
head, manifest, tail = spec.split(" # = MANIFEST =\n")
# replace name version and date
replace_header(head, :name)
replace_header(head, :version)
replace_header(head, :date)
#comment this out if your rubyforge_project has a different name
replace_header(head, :rubyforge_project)
# determine file list from git ls-files
files = `git ls-files`.
split("\n").
sort.
reject { |file| file =~ /^\./ }.
reject { |file| file =~ /^(rdoc|pkg|test)/ }.
map { |file| " #{file}" }.
join("\n")
# piece file back together and write
manifest = " s.files = %w[\n#{files}\n ]\n"
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
File.open(gemspec_file, 'w') { |io| io.write(spec) }
puts "Updated #{gemspec_file}"
end
task :validate do
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
unless libfiles.empty?
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
exit!
end
unless Dir['VERSION*'].empty?
puts "A `VERSION` file at root level violates Gem best practices."
exit!
end
end
Gem::Specification.new do |s|
s.name = 'gitlab-grit'
s.version = '2.5.1'
s.date = '2013-05-06'
s.license = 'MIT'
s.summary = "Ruby Git bindings."
s.description = "Grit is a Ruby library for extracting information from a git repository in an object oriented manner. GitLab fork"
s.authors = ["Tom Preston-Werner", "Scott Chacon", "Dmitriy Zaporozhets"]
s.email = 'm@gitlabhq.com'
s.homepage = 'http://github.com/gitlabhq/grit'
s.require_paths = %w[lib]
s.rdoc_options = ["--charset=UTF-8"]
s.extra_rdoc_files = %w[README.md LICENSE]
s.files = `git ls-files lib/`.split("\n")
s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
s.add_dependency("charlock_holmes", "~> 0.6.9")
s.add_dependency('posix-spawn', "~> 0.3.6")
s.add_dependency('mime-types', "~> 1.15")
s.add_dependency('diff-lcs', "~> 1.1")
s.add_development_dependency('mocha')
end
Gem::Specification.new do |s|
s.specification_version = 2 if s.respond_to? :specification_version=
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.rubygems_version = '1.3.5'
s.name = 'grit'
s.version = '2.5.0'
s.date = '2013-03-02'
s.rubyforge_project = 'grit'
s.summary = "Ruby Git bindings."
s.description = "Grit is a Ruby library for extracting information from a git repository in an object oriented manner."
s.authors = ["Tom Preston-Werner", "Scott Chacon"]
s.email = 'm@gitlabhq.com'
s.homepage = 'http://github.com/gitlabhq/grit'
s.require_paths = %w[lib]
s.rdoc_options = ["--charset=UTF-8"]
s.extra_rdoc_files = %w[README.md LICENSE]
s.add_dependency('posix-spawn', "~> 0.3.6")
s.add_dependency('mime-types', "~> 1.15")
s.add_dependency('diff-lcs', "~> 1.1")
s.add_development_dependency('mocha')
# = MANIFEST =
s.files = %w[
API.txt
History.txt
LICENSE
PURE_TODO
README.md
Rakefile
benchmarks.rb
benchmarks.txt
examples/ex_add_commit.rb
examples/ex_index.rb
grit.gemspec
lib/grit.rb
lib/grit/actor.rb
lib/grit/blame.rb
lib/grit/blob.rb
lib/grit/commit.rb
lib/grit/commit_stats.rb
lib/grit/config.rb
lib/grit/diff.rb
lib/grit/errors.rb
lib/grit/git-ruby.rb
lib/grit/git-ruby/commit_db.rb
lib/grit/git-ruby/git_object.rb
lib/grit/git-ruby/internal/file_window.rb
lib/grit/git-ruby/internal/loose.rb
lib/grit/git-ruby/internal/pack.rb
lib/grit/git-ruby/internal/raw_object.rb
lib/grit/git-ruby/repository.rb
lib/grit/git.rb
lib/grit/index.rb
lib/grit/lazy.rb
lib/grit/merge.rb
lib/grit/ref.rb
lib/grit/repo.rb
lib/grit/ruby1.9.rb
lib/grit/status.rb
lib/grit/submodule.rb
lib/grit/tag.rb
lib/grit/tree.rb
]
# = MANIFEST =
s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
end
Loading
Loading
@@ -74,3 +74,7 @@ module Grit
VERSION
end
end
# Include grit_ext
require 'charlock_holmes'
require 'grit_ext'
require "charlock_holmes"
require "grit_ext/actor"
require "grit_ext/blob"
require "grit_ext/commit"
require "grit_ext/tree"
require "grit_ext/diff"
require "grit_ext/version"
module GritExt
extend self
def encode!(message)
return nil unless message.respond_to? :force_encoding
# if message is utf-8 encoding, just return it
message.force_encoding("UTF-8")
return message if message.valid_encoding?
# return message if message type is binary
detect = CharlockHolmes::EncodingDetector.detect(message)
return message.force_encoding("BINARY") if detect && detect[:type] == :binary
# encoding message to detect encoding
if detect && detect[:encoding]
message.force_encoding(detect[:encoding])
end
# encode and clean the bad chars
message.replace clean(message)
rescue
encoding = detect ? detect[:encoding] : "unknown"
"--broken encoding: #{encoding}"
end
private
def clean(message)
message.encode("UTF-16BE", :undef => :replace, :invalid => :replace, :replace => "")
.encode("UTF-8")
.gsub("\0".encode("UTF-8"), "")
end
end
module Grit
class Actor
alias_method :old_name, :name
alias_method :old_email, :email
def name
GritExt.encode! old_name
end
def email
GritExt.encode! old_email
end
end
end
module Grit
class Blob
alias_method :old_name, :name
alias_method :old_data, :data
def name
GritExt.encode! old_name
end
def data
GritExt.encode! old_data
end
class << self
alias_method :old_blame, :blame
def blame(repo, commit, file)
old_blame(repo, commit, file).map do |b,lines|
[b, GritExt.encode!(lines.join('\n')).split('\n')]
end
end
end
end
end
module Grit
class Commit
alias_method :old_message, :message
alias_method :old_short_message, :short_message
def message
GritExt.encode! old_message
end
def short_message
GritExt.encode! old_short_message
end
end
end
module Grit
class Diff
def old_path
GritExt.encode! @a_path
end
def new_path
GritExt.encode! @b_path
end
def diff
if @diff.nil?
@diff = ""
else
lines = @diff.lines.to_a
path = GritExt.encode! lines.shift(2).join
body = GritExt.encode! lines.join
@diff = path + body
end
end
end
end
module Grit
class Tag
alias_method :old_message, :message
def message
GritExt.encode! old_message
end
end
end
module Grit
class Tree
alias_method :old_name, :name
def name
GritExt.encode! old_name
end
end
end
module GritExt
extend self
def version
"0.8.1"
end
end
Loading
Loading
@@ -8,7 +8,7 @@ require File.join(File.dirname(__FILE__), *%w[.. lib grit])
require 'rubygems'
require 'test/unit'
require 'mocha/setup'
require 'pry'
 
REPOS_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', 'repos'))
GRIT_REPO = ENV["GRIT_REPO"] || File.join(REPOS_PATH, 'grit')
Loading
Loading
Loading
Loading
@@ -53,7 +53,7 @@ class TestBlob < Test::Unit::TestCase
Git.any_instance.expects(:blame).returns(fixture('blame'))
b = Blob.blame(@r, 'master', 'lib/grit.rb')
assert_equal 13, b.size
assert_equal 25, b.inject(0) { |acc, x| acc + x.last.size }
assert_equal 24, b.inject(0) { |acc, x| acc + x.last.size }
assert_equal b[0].first.object_id, b[9].first.object_id
c = b.first.first
c.expects(:__bake__).times(0)
Loading
Loading
@@ -80,4 +80,4 @@ class TestBlob < Test::Unit::TestCase
@b = Blob.create(@r, :name => 'foo/bar.rb')
assert_equal "bar.rb", @b.basename
end
end
\ No newline at end of file
end
Loading
Loading
@@ -13,7 +13,7 @@ class TestDiff < Test::Unit::TestCase
diffs = Grit::Diff.list_from_string(@r, output)
assert_equal 2, diffs.size
assert_equal 10, diffs.first.diff.split("\n").size
assert_nil diffs.last.diff
assert_equal "", diffs.last.diff
end
 
def test_list_from_string_with_renames
Loading
Loading
# encoding: UTF-8
require File.dirname(__FILE__) + '/helper'
class TestEncoding < Test::Unit::TestCase
def test_nil_message
message = GritExt.encode! nil
assert_equal message, nil
end
def test_binary_message
message = "\xFF\xD8\xFF\xE0"
encoded_message = GritExt.encode!(message)
assert_equal encoded_message.bytes.to_a, message.bytes.to_a
assert_equal message.encoding.name, "UTF-8"
end
def test_invalid_encoding
message = GritExt.encode!("yummy\xE2 \xF0\x9F\x8D\x94 \x9F\x8D\x94")
assert_equal message, "yummy 🍔 "
assert_equal message.encoding.name, "UTF-8"
end
def test_encode_string
message = GritExt.encode!("{foo \xC3 'bar'}")
assert_equal message, "{foo à 'bar'}"
assert_equal message.encoding.name, "UTF-8"
message = "我爱你".encode("GBK")
assert_equal message.encoding.name, "GBK"
GritExt.encode!(message)
assert_equal message, "我爱你"
assert_equal message.encoding.name, "UTF-8"
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment