Commit 0ee02c02 authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 363371: It is hard to determine which row has a failed encoding, with recode.pl --guess

Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=justdave, a=justdave
parent c712d457
...@@ -251,6 +251,13 @@ foreach my $table ($dbh->bz_table_list_real) { ...@@ -251,6 +251,13 @@ foreach my $table ($dbh->bz_table_list_real) {
my $data = shift @result; my $data = shift @result;
my $digest = md5_base64($data); my $digest = md5_base64($data);
my @primary_keys = reverse split(',', $pk);
# We copy the array so that we can pop things from it without
# affecting the original.
my @pk_data = @result;
my $pk_line = join (', ',
map { "$_ = " . pop @pk_data } @primary_keys);
my $encoding; my $encoding;
if ($switch{'guess'}) { if ($switch{'guess'}) {
$encoding = do_guess($data); $encoding = do_guess($data);
...@@ -261,7 +268,8 @@ foreach my $table ($dbh->bz_table_list_real) { ...@@ -261,7 +268,8 @@ foreach my $table ($dbh->bz_table_list_real) {
&& !is_valid_utf8($data)) && !is_valid_utf8($data))
{ {
my $truncated = trunc($data); my $truncated = trunc($data);
print "Failed to guess: Key: $digest", print "Row: [$pk_line]\n",
"Failed to guess: Key: $digest",
" DATA: $truncated\n"; " DATA: $truncated\n";
} }
...@@ -283,7 +291,8 @@ foreach my $table ($dbh->bz_table_list_real) { ...@@ -283,7 +291,8 @@ foreach my $table ($dbh->bz_table_list_real) {
if ($encoding && !grep($_ eq $encoding, IGNORE_ENCODINGS)) { if ($encoding && !grep($_ eq $encoding, IGNORE_ENCODINGS)) {
my $decoded = encode('utf8', decode($encoding, $data)); my $decoded = encode('utf8', decode($encoding, $data));
if ($switch{'dry-run'} && $data ne $decoded) { if ($switch{'dry-run'} && $data ne $decoded) {
print "From: [" . trunc($data) . "] Key: $digest\n", print "Row: [$pk_line]\n",
"From: [" . trunc($data) . "] Key: $digest\n",
"To: [" . trunc($decoded) . "]", "To: [" . trunc($decoded) . "]",
" Encoding : $encoding\n"; " Encoding : $encoding\n";
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment