Skip to content

Commit 1c49391

Browse files
newrengitster
authored andcommitted
fast-export: avoid stripping encoding header if we cannot reencode
When fast-export encounters a commit with an 'encoding' header, it tries to reencode in utf-8 and then drops the encoding header. However, if it fails to reencode in utf-8 because e.g. one of the characters in the commit message was invalid in the old encoding, then we need to retain the original encoding or otherwise we lose information needed to understand all the other (valid) characters in the original commit message. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 23495a3 commit 1c49391

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

builtin/fast-export.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,12 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
642642
printf("commit %s\nmark :%"PRIu32"\n", refname, last_idnum);
643643
if (show_original_ids)
644644
printf("original-oid %s\n", oid_to_hex(&commit->object.oid));
645-
printf("%.*s\n%.*s\ndata %u\n%s",
645+
printf("%.*s\n%.*s\n",
646646
(int)(author_end - author), author,
647-
(int)(committer_end - committer), committer,
647+
(int)(committer_end - committer), committer);
648+
if (!reencoded && encoding)
649+
printf("encoding %s\n", encoding);
650+
printf("data %u\n%s",
648651
(unsigned)(reencoded
649652
? strlen(reencoded) : message
650653
? strlen(message) : 0),

t/t9350-fast-export.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,20 @@ test_expect_success 'iso-8859-7' '
109109
grep $(printf "\317\200") actual)
110110
'
111111

112+
test_expect_success 'encoding preserved if reencoding fails' '
113+
114+
test_when_finished "git reset --hard HEAD~1" &&
115+
test_config i18n.commitencoding iso-8859-7 &&
116+
echo rosten >file &&
117+
git commit -s -m "$(printf "Pi: \360; Invalid: \377")" file &&
118+
git fast-export wer^..wer >iso-8859-7.fi &&
119+
sed "s/wer/i18n-invalid/" iso-8859-7.fi |
120+
(cd new &&
121+
git fast-import &&
122+
git cat-file commit i18n-invalid >actual &&
123+
grep ^encoding actual)
124+
'
125+
112126
test_expect_success 'import/export-marks' '
113127
114128
git checkout -b marks master &&

0 commit comments

Comments
 (0)