Skip to content

Commit 097c7fa

Browse files
author
Peter Degen-Portnoy
committed
Merge pull request #15 from notalex/OTWO-3206
Otwo 3206
2 parents 17bb968 + 513f636 commit 097c7fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+200
-2077
lines changed

bin/string_encoder

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! /usr/bin/env ruby
2+
# Replaces invalid utf-8 characters with �.
3+
#
4+
# Usage:
5+
# $ cat some_file | string_encoder
6+
7+
while input = gets
8+
if input.to_s.valid_encoding?
9+
puts input
10+
else
11+
puts input.encode('UTF-8', 'binary', invalid: :replace, undef: :replace)
12+
end
13+
end

lib/scm/adapters/abstract_adapter.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ class << self
1313
end
1414
end
1515

16+
# Returns path to the string_encoder binary.
17+
# For use with inline system commands like `run`.
18+
def string_encoder
19+
File.expand_path('../../../../bin/string_encoder', __FILE__)
20+
end
21+
1622
end
1723
end
1824

lib/scm/adapters/cvs/commits.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def open_log_file(opts={})
6363
after = opts[:after]
6464
begin
6565
ensure_host_key
66-
run "cvsnt -d #{self.url} rlog #{opt_branch} #{opt_time(after)} '#{self.module_name}' > #{rlog_filename}"
66+
run "cvsnt -d #{self.url} rlog #{opt_branch} #{opt_time(after)} '#{self.module_name}' | #{ string_encoder } > #{rlog_filename}"
6767
File.open(rlog_filename, 'r') do |file|
6868
yield file
6969
end

lib/scm/adapters/cvs/misc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def ls(path=nil)
6767

6868
def log(most_recent_token=nil)
6969
ensure_host_key
70-
run "cvsnt -d #{self.url} rlog #{opt_branch} #{opt_time(most_recent_token)} '#{self.module_name}'"
70+
run "cvsnt -d #{self.url} rlog #{opt_branch} #{opt_time(most_recent_token)} '#{self.module_name}' | #{ string_encoder }"
7171
end
7272

7373
def checkout(r, local_directory)

lib/scm/adapters/git/commits.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def log(opts={})
8080
if opts[:after] && opts[:after]==self.head_token
8181
'' # Nothing new.
8282
else
83-
run "#{rev_list_command(opts)} | xargs -n 1 #{Scm::Parsers::GitStyledParser.whatchanged}"
83+
run "#{rev_list_command(opts)} | xargs -n 1 #{Scm::Parsers::GitStyledParser.whatchanged} | #{ string_encoder }"
8484
end
8585
else
8686
''
@@ -96,7 +96,7 @@ def open_log_file(opts={})
9696
'' # Nothing new.
9797
else
9898
begin
99-
run "#{rev_list_command(opts)} | xargs -n 1 #{Scm::Parsers::GitStyledParser.whatchanged} > #{log_filename}"
99+
run "#{rev_list_command(opts)} | xargs -n 1 #{Scm::Parsers::GitStyledParser.whatchanged} | #{ string_encoder } > #{log_filename}"
100100
File.open(log_filename, 'r') { |io| yield io }
101101
ensure
102102
File.delete(log_filename) if FileTest.exist?(log_filename)

lib/scm/adapters/git/misc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def checkout
4848

4949
# Returns an array of all branch names
5050
def branches
51-
run("cd '#{self.url}' && git branch").split.collect { |b| b =~ /\b(.+)$/ ; $1 }.compact
51+
run("cd '#{self.url}' && git branch | #{ string_encoder }").split.collect { |b| b =~ /\b(.+)$/ ; $1 }.compact
5252
end
5353

5454
def has_branch?(name=self.branch_name)

lib/scm/adapters/hg/commits.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def commits(opts={})
4444

4545
# Returns a single commit, including its diffs
4646
def verbose_commit(token)
47-
log = run("cd '#{self.url}' && hg log -v -r #{token} --style #{Scm::Parsers::HgStyledParser.verbose_style_path}")
47+
log = run("cd '#{self.url}' && hg log -v -r #{token} --style #{Scm::Parsers::HgStyledParser.verbose_style_path} | #{ string_encoder }")
4848
Scm::Parsers::HgStyledParser.parse(log).first
4949
end
5050

@@ -64,7 +64,7 @@ def each_commit(opts={})
6464
# Not used by Ohloh proper, but handy for debugging and testing
6565
def log(opts={})
6666
after = opts[:after] || 0
67-
run "cd '#{url}' && hg log -f #{trunk_only(opts)} -v -r tip:#{after}"
67+
run "cd '#{url}' && hg log -f #{trunk_only(opts)} -v -r tip:#{after} | #{ string_encoder }"
6868
end
6969

7070
# Returns a file handle to the log.
@@ -78,7 +78,7 @@ def open_log_file(opts={})
7878
# As a time optimization, just create an empty file rather than fetch a log we know will be empty.
7979
File.open(log_filename, 'w') { }
8080
else
81-
run "cd '#{url}' && hg log --verbose #{trunk_only(opts)} -r #{after || 0}:tip --style #{Scm::Parsers::HgStyledParser.verbose_style_path} > #{log_filename}"
81+
run "cd '#{url}' && hg log --verbose #{trunk_only(opts)} -r #{after || 0}:tip --style #{Scm::Parsers::HgStyledParser.verbose_style_path} | #{ string_encoder } > #{log_filename}"
8282
end
8383
File.open(log_filename, 'r') { |io| yield io }
8484
ensure

lib/scm/adapters/hg/misc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def exist?
1010
end
1111

1212
def ls_tree(token)
13-
run("cd '#{path}' && hg manifest -r #{token}").split("\n")
13+
run("cd '#{path}' && hg manifest -r #{token} | #{ string_encoder }").split("\n")
1414
end
1515

1616
def export(dest_dir, token='tip')

test/data/invalid-utf-word

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
������

test/data/sample-content

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
RCS file: /cvsroot/cncms/phparticle212/admin/template.php,v
2+
head: 1.4
3+
branch:
4+
locks: strict
5+
access list:
6+
symbolic names:
7+
pa212: 1.1.1.1
8+
niuboy: 1.1.1
9+
keyword substitution: kv
10+
total revisions: 5; selected revisions: 4
11+
12+
description:
13+
----------------------------
14+
revision 1.4
15+
date: 2006/12/08 12:08:10; author: semirock; state: Exp; lines: +514 -478
16+
����rss.php�ļ�Ĭ����ʾ20ƪ����
17+
18+
----------------------------
19+
revision 1.3
20+
date: 2006/11/22 08:35:59; author: niuboy; state: Exp; lines: +6 -2
21+
no message
22+
----------------------------
23+
revision 1.2
24+
date: 2006/11/19 19:51:28; author: niuboy; state: Exp; lines: +4 -4
25+
no message
26+
27+
----------------------------
28+
revision 1.1
29+
date: 2006/11/11 07:21:46; author: niuboy; state: Exp;
30+
branches: 1.1.1;
31+
Initial revision
32+
=============================================================================

0 commit comments

Comments
 (0)