about summary refs log tree commit homepage
path: root/t/solver_git.t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-02-21 11:17:58 +0000
committerEric Wong <e@80x24.org>2023-02-21 12:18:04 +0000
commit4ffad9b0a60f40ee9717e22000c233fcba30b30d (patch)
tree970f72ee4a9f4014ec25671c1275c07374fd4c2e /t/solver_git.t
parentf8cfe495cc2b89b5d20535279181fe013caf3cea (diff)
downloadpublic-inbox-4ffad9b0a60f40ee9717e22000c233fcba30b30d.tar.gz
Back in the old days, git didn't store commit encodings
and allowed messages in various encodings to enter history.
Assuming such a commit is UTF-8 trips up s/// operations
on buffers read with the `:utf8' PerlIO layer.  So clear
Perl's internal UTF-8 flag if we end up with something
which isn't valid UTF-8

An example is commit 7eb93c89651c47c8095d476251f2e4314656b292
in git.git ([PATCH] Simplify git script, 2005-09-07)
Diffstat (limited to 't/solver_git.t')
-rw-r--r--t/solver_git.t40
1 files changed, 37 insertions, 3 deletions
diff --git a/t/solver_git.t b/t/solver_git.t
index c65d9785..e8d9feb9 100644
--- a/t/solver_git.t
+++ b/t/solver_git.t
@@ -218,14 +218,13 @@ SKIP: {
         my %oid; # (small|big) => OID
         my $lk = bless { lock_path => $l }, 'PublicInbox::Lock';
         my $acq = $lk->lock_for_scope;
-        my $stamp = "$binfoo/stamp";
+        my $stamp = "$binfoo/stamp-";
         if (open my $fh, '<', $stamp) {
                 %oid = map { chomp; split(/=/, $_) } (<$fh>);
         } else {
                 PublicInbox::Import::init_bare($binfoo);
                 my $cmd = [ qw(git hash-object -w --stdin) ];
                 my $env = { GIT_DIR => $binfoo };
-                open my $fh, '>', "$stamp.$$" or BAIL_OUT;
                 while (my ($label, $size) = each %bin) {
                         pipe(my ($rin, $win)) or BAIL_OUT;
                         my $rout = popen_rd($cmd , $env, { 0 => $rin });
@@ -234,9 +233,33 @@ SKIP: {
                         close $win or BAIL_OUT;
                         chomp(my $x = <$rout>);
                         close $rout or BAIL_OUT "$?";
-                        print $fh "$label=$x\n" or BAIL_OUT;
                         $oid{$label} = $x;
                 }
+
+                open my $null, '<', '/dev/null' or xbail "open /dev/null: $!";
+                my $t = xqx([qw(git mktree)], $env, { 0 => $null });
+                xbail "mktree: $?" if $?;
+                chomp($t);
+                my $non_utf8 = "K\x{e5}g";
+                $env->{GIT_AUTHOR_NAME} = $non_utf8;
+                $env->{GIT_AUTHOR_EMAIL} = 'e@example.com';
+                $env->{GIT_COMMITTER_NAME} = $env->{GIT_AUTHOR_NAME};
+                $env->{GIT_COMMITTER_EMAIL} = $env->{GIT_AUTHOR_EMAIL};
+                my $in = \"$non_utf8\n\nK\x{e5}g\n";
+                my $c = xqx([qw(git commit-tree), $t], $env, { 0 => $in });
+                xbail "commit-tree: $?" if $?;
+                chomp($c);
+                $oid{'iso-8859-1'} = $c;
+
+                $c = xqx([qw(git commit-tree -p), $c, $t], $env, { 0 => $in });
+                xbail "commit-tree: $?" if $?;
+                chomp($c);
+                $oid{'8859-parent'} = $c;
+
+                open my $fh, '>', "$stamp.$$" or BAIL_OUT;
+                while (my ($k, $v) = each %oid) {
+                        print $fh "$k=$v\n" or xbail "print: $!";
+                }
                 close $fh or BAIL_OUT;
                 rename("$stamp.$$", $stamp) or BAIL_OUT;
         }
@@ -331,6 +354,17 @@ EOF
                         open STDERR, '>&', $olderr or xbail "open: $!";
                 is($res->code, 200, 'coderepo summary (binfoo)');
                 ok(!-s "$tmpdir/stderr.log");
+
+                $res = $cb->(GET("/binfoo/$oid{'iso-8859-1'}/s/"));
+                is($res->code, 200, 'ISO-8859-1 commit');
+                like($res->content, qr/K&#229;g/, 'ISO-8859-1 commit message');
+                ok(!-s "$tmpdir/stderr.log", 'nothing in stderr');
+
+                $res = $cb->(GET("/binfoo/$oid{'8859-parent'}/s/"));
+                is($res->code, 200, 'commit w/ ISO-8859-parent');
+                like($res->content, qr/K&#229;g/, 'ISO-8859-1 commit message');
+                ok(!-s "$tmpdir/stderr.log", 'nothing in stderr');
+
                 $res = $cb->(GET('/public-inbox/'));
                 is($res->code, 200, 'coderepo summary (public-inbox)');