Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Modified to use UTF-8 encoding. (Works with Ruby 2.0) #161

Closed
wants to merge 9 commits into from

2 participants

@harrycheung
  • Set encoding of strings to be UTF-8 and force encodings when making string comparisons.
  • Updated ruby version check for 2.0
  • Fixed deprecated warnings
  • Fixed test for OSX version of git
  • Tested on 1.9.3-p194 and 2.0.0
@harrycheung

Just noticed tests under 1.9.3 aren't working. I'll put in a better fix for cross-version compatibility.

harrycheung added some commits
@harrycheung harrycheung Modified grit to use utf-8 as it's default encoding.
- Magic encoding comment was added to the top of loose.rb and pack.rb
- Encoding is forced on anything that is read for comparison against a string.
5add0c3
@harrycheung harrycheung Remove an erroneous comment. d83ff8d
@harrycheung

Tests work for both 1.9.3 and 2.0.0.

@bkeepers
Collaborator

Grit is no longer maintained. See #183 and check out libgit2/rugged.

@bkeepers bkeepers closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 18, 2013
  1. @harrycheung
Commits on Mar 19, 2013
  1. @harrycheung

    Modified RE in test to accept OSX version of git. For example, "git v…

    harrycheung authored
    …ersion 1.7.9.6 (Apple Git-31.1)".
  2. @harrycheung
  3. @harrycheung

    Tests now work with Ruby 2.0.0. Since strings are defaulted to UTF-8,…

    harrycheung authored
    … things were breaking since a UTF-8 constant was being compared to an ASCII file read. Forcing the constant to be ASCII fixes this.
  4. @harrycheung
  5. @harrycheung
  6. @harrycheung
Commits on Mar 23, 2013
  1. @harrycheung

    Modified grit to use utf-8 as it's default encoding.

    harrycheung authored
    - Magic encoding comment was added to the top of loose.rb and pack.rb
    - Encoding is forced on anything that is read for comparison against a string.
  2. @harrycheung
This page is out of date. Refresh to see the latest.
View
2  Rakefile
@@ -60,7 +60,7 @@ task :coverage do
sh "open coverage/index.html"
end
-require 'rake/rdoctask'
+require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "#{name} #{version}"
View
4 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.5.1'
s.date = '2012-04-22'
s.rubyforge_project = 'grit'
@@ -62,7 +62,7 @@ Gem::Specification.new do |s|
lib/grit/merge.rb
lib/grit/ref.rb
lib/grit/repo.rb
- lib/grit/ruby1.9.rb
+ lib/grit/ruby.rb
lib/grit/status.rb
lib/grit/submodule.rb
lib/grit/tag.rb
View
6 lib/grit.rb
@@ -24,8 +24,8 @@
end
end
-# ruby 1.9 compatibility
-require 'grit/ruby1.9'
+# ruby 1.9+ compatibility
+require 'grit/ruby'
# internal requires
require 'grit/lazy'
@@ -49,7 +49,7 @@
require 'grit/merge'
module Grit
- VERSION = '2.5.0'
+ VERSION = '2.5.1'
class << self
# Set +debug+ to true to log all git calls and responses
View
3  lib/grit/git-ruby/internal/loose.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
#
# converted from the gitrb project
#
@@ -97,7 +98,7 @@ def put_raw_object(content, type)
path = @directory+'/'+sha1[0...2]+'/'+sha1[2..40]
if !File.exists?(path)
- content = Zlib::Deflate.deflate(store)
+ content = Zlib::Deflate.deflate(store).force_encoding("UTF-8")
FileUtils.mkdir_p(@directory+'/'+sha1[0...2])
safe_write(path, content)
View
5 lib/grit/git-ruby/internal/pack.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
#
# converted from the gitrb project
#
@@ -57,7 +58,9 @@ def with_idx(index_file = nil)
end
# read header
- sig = idxfile.read(4)
+ # File.read return a ASCII-8BIT encoded string. Since we're comparing
+ # sig against a source file string we force the encoding on it to UTF-8.
+ sig = idxfile.read(4).force_encoding("UTF-8")
ver = idxfile.read(4).unpack("N")[0]
if sig == PACK_IDX_SIGNATURE
View
2  lib/grit/ruby1.9.rb → lib/grit/ruby.rb
@@ -1,5 +1,5 @@
class String
- if ((defined? RUBY_VERSION) && (RUBY_VERSION[0..2] == "1.9"))
+ if ((defined? RUBY_VERSION) && (RUBY_VERSION[0..2] >= "1.9"))
def getord(offset); self[offset].ord; end
else
alias :getord :[]
View
2  test/helper.rb
@@ -3,7 +3,7 @@
require 'rubygems'
require 'test/unit'
gem "mocha", ">=0"
-require 'mocha'
+require 'mocha/setup'
GRIT_REPO = ENV["GRIT_REPO"] || File.expand_path(File.join(File.dirname(__FILE__), '..'))
View
2  test/test_git.rb
@@ -10,7 +10,7 @@ def teardown
end
def test_method_missing
- assert_match(/^git version [\w\.]*$/, @git.version)
+ assert_match(/^git version [\w\.]*[\w\.\-\(\) ]*$/, @git.version)
end
def test_logs_stderr
Something went wrong with that request. Please try again.