Merge remote branch 'shadowcat/master'
Tomas Doran [Fri, 18 Dec 2009 20:51:39 +0000 (20:51 +0000)]
* shadowcat/master:
  Fix notabs test
  Decode getpwuid values

Makefile.PL
lib/Gitalist/Git/Object.pm
lib/Gitalist/Git/Project.pm
t/02git_project.t
t/author/notabs.t

index c096f3b..b25b05b 100644 (file)
@@ -63,6 +63,7 @@ author_requires 'Test::Pod' => '1.14';
 author_requires 'Test::Pod::Coverage' => '1.04';
 
 test_requires 'Test::More' => '0.88';
+test_requires 'Test::utf8' => '0.02';
 
 resources bugtracker => 'http://rt.cpan.org/Public/Dist/Display.html?Name=Gitalist';
 resources repository => 'git://git.shadowcat.co.uk/catagits/Gitalist.git';
index de693f3..9cefe6c 100644 (file)
@@ -74,8 +74,8 @@ class Gitalist::Git::Object {
     # via gitweb.pm circa line 1305
     use Fcntl ':mode';
     use constant {
-       S_IFINVALID => 0030000,
-       S_IFGITLINK => 0160000,
+        S_IFINVALID => 0030000,
+        S_IFGITLINK => 0160000,
     };
 
     # submodule/subproject, a commit object reference
index 72909d4..975483f 100644 (file)
@@ -9,6 +9,8 @@ class Gitalist::Git::Project with Gitalist::Git::HasUtils {
     use Moose::Autobox;
     use List::MoreUtils qw/any zip/;
     use DateTime;
+    use Encode qw/decode/;
+    use I18N::Langinfo qw/langinfo CODESET/;
     use Gitalist::Git::Object::Blob;
     use Gitalist::Git::Object::Tree;
     use Gitalist::Git::Object::Commit;
@@ -122,7 +124,7 @@ class Gitalist::Git::Project with Gitalist::Git::HasUtils {
         $sha1 = $self->head_hash($sha1)
             if !$sha1 || $sha1 !~ $SHA1RE;
 
-       my @search_opts;
+        my @search_opts;
         if ($search) {
             $search->{type} = 'grep'
                 if $search->{type} eq 'commit';
@@ -239,7 +241,7 @@ class Gitalist::Git::Project with Gitalist::Git::HasUtils {
     }
 
     method _build_owner {
-        my ($gecos, $name) = (getpwuid $self->path->stat->uid)[6,0];
+        my ($gecos, $name) = map { decode(langinfo(CODESET), $_) } (getpwuid $self->path->stat->uid)[6,0];
         $gecos =~ s/,+$//;
         return length($gecos) ? $gecos : $name;
     }
@@ -282,12 +284,12 @@ class Gitalist::Git::Project with Gitalist::Git::HasUtils {
         my @revlines = $self->run_cmd_list('for-each-ref',
           '--sort=-creatordate',
           '--format=%(objectname) %(objecttype) %(refname) %(*objectname) %(*objecttype) %(subject)%00%(creator)',
-         'refs/tags'
+          'refs/tags'
         );
         my @ret;
         for my $line (@revlines) {
             my($refinfo, $creatorinfo) = split /\0/, $line;
-           my($rev, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
+            my($rev, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
             my($creator, $epoch, $tz) = ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
             $name =~ s!^refs/tags/!!;
 
@@ -305,9 +307,9 @@ class Gitalist::Git::Project with Gitalist::Git::HasUtils {
     }
 
     method _build_references {
-       # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
-       # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
-       my @reflist = $self->run_cmd_list(qw(show-ref --dereference))
+        # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
+        # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
+        my @reflist = $self->run_cmd_list(qw(show-ref --dereference))
             or return;
         my %refs;
         for (@reflist) {
index 0fe47b3..729b9f8 100644 (file)
@@ -3,8 +3,24 @@ use warnings;
 use FindBin qw/$Bin/;
 use Test::More qw/no_plan/;
 use Test::Exception;
+use Test::utf8;
+use Encode qw/decode_utf8/;
 use Data::Dumper;
 
+BEGIN {
+    # Mocking to allow testing regardless of the user's locale
+    require I18N::Langinfo;
+    no warnings 'redefine';
+    *I18N::Langinfo::langinfo = sub($) {
+        return "UTF-8" if $_[0] == I18N::Langinfo::CODESET();
+    };
+    *CORE::GLOBAL::getpwuid = sub {
+        wantarray
+            ? ("test", "x", "1000", "1000", "", "", "T\x{c3}\x{a9}st", "/home/test", "/bin/bash")
+            : "test";
+    };
+}
+
 BEGIN { use_ok 'Gitalist::Git::Project' }
 
 dies_ok {
@@ -59,3 +75,7 @@ like($proj->head_hash('HEAD'), qr/^([0-9a-fA-F]{40})$/, 'head_hash');
     isa_ok($tree[0], 'Gitalist::Git::Object', 'tree element 0');
 }
 
+my $owner = $proj->owner;
+is_flagged_utf8($owner, "Owner name is flagged as utf8");
+is_sane_utf8($owner, "Owner name is not double-encoded");
+is($owner, decode_utf8("T\x{c3}\x{a9}st"),  "Owner name is correct");
index 5f3efe8..693e048 100644 (file)
@@ -1,3 +1,3 @@
 use Test::NoTabs;
-all_perl_files_ok;
+all_perl_files_ok(qw(t lib));