Fossil SCM
Isolate the logic used to figure out the text encoding of the check-in comment coming back from the users editor into windows-only code.
Commit
397c990400d39b6ba81df035836464c5ec5250ab
Parent
7724ea65018d5a2…
1 file changed
+14
-15
+14
-15
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -1151,12 +1151,15 @@ | ||
| 1151 | 1151 | prompt_user("empty check-in comment. continue (y/N)? ", &ans); |
| 1152 | 1152 | if( blob_str(&ans)[0]!='y' ){ |
| 1153 | 1153 | fossil_exit(1); |
| 1154 | 1154 | } |
| 1155 | 1155 | }else{ |
| 1156 | - /* If the comment comes from the command line, it is utf-8 already. */ | |
| 1157 | - if( zComment == 0 ) { | |
| 1156 | +#ifdef _WIN32 | |
| 1157 | + /* On windows, the check-in comment might come back from the editor | |
| 1158 | + ** in various encodings. Try to figure out the encoding and do the | |
| 1159 | + ** right thing. */ | |
| 1160 | + if( zComment==0 ){ | |
| 1158 | 1161 | static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF }; |
| 1159 | 1162 | static const unsigned short ubom = 0xfeff; |
| 1160 | 1163 | static const unsigned short urbom = 0xfffe; |
| 1161 | 1164 | if( blob_size(&comment)>2 && memcmp(blob_buffer(&comment), bom, 3)==0 ) { |
| 1162 | 1165 | struct Blob temp; |
| @@ -1163,35 +1166,31 @@ | ||
| 1163 | 1166 | char *zUtf8 = blob_str(&comment) + 3; |
| 1164 | 1167 | blob_set(&temp, zUtf8); |
| 1165 | 1168 | fossil_mbcs_free(zUtf8); |
| 1166 | 1169 | blob_swap(&temp, &comment); |
| 1167 | 1170 | blob_reset(&temp); |
| 1168 | - } else if( blob_size(&comment)>1 && (blob_size(&comment)&1)==0 | |
| 1171 | + }else if( blob_size(&comment)>1 && (blob_size(&comment)&1)==0 | |
| 1169 | 1172 | && memcmp(blob_buffer(&comment), &ubom, 2)==0 ) { |
| 1170 | -#ifdef _WIN32 | |
| 1171 | 1173 | char *zUtf8; |
| 1172 | 1174 | /* Make sure the blob contains two terminating 0-bytes */ |
| 1173 | 1175 | blob_append(&comment, "", 1); |
| 1174 | 1176 | zUtf8 = blob_str(&comment) + 2; |
| 1175 | 1177 | zUtf8 = fossil_unicode_to_utf8(zUtf8); |
| 1176 | 1178 | blob_zero(&comment); |
| 1177 | 1179 | blob_set(&comment, zUtf8); |
| 1178 | 1180 | fossil_mbcs_free(zUtf8); |
| 1179 | -#else | |
| 1180 | - fossil_fatal("unicode bom (le) not (yet) implemented"); | |
| 1181 | -#endif | |
| 1182 | - } else if( blob_size(&comment)>1 && memcmp(blob_buffer(&comment), &urbom, 2)==0 ) { | |
| 1181 | + }else if( blob_size(&comment)>1 | |
| 1182 | + && memcmp(blob_buffer(&comment), &urbom, 2)==0 ){ | |
| 1183 | 1183 | fossil_fatal("unicode bom (be) not (yet) implemented"); |
| 1184 | -#ifdef _WIN32 | |
| 1185 | - } else { | |
| 1186 | - char *zUtf8 = fossil_mbcs_to_utf8(blob_str(&comment)); | |
| 1187 | - blob_zero(&comment); | |
| 1188 | - blob_set(&comment, zUtf8); | |
| 1189 | - fossil_mbcs_free(zUtf8); | |
| 1190 | -#endif | |
| 1184 | + }else{ | |
| 1185 | + char *zUtf8 = fossil_mbcs_to_utf8(blob_str(&comment)); | |
| 1186 | + blob_zero(&comment); | |
| 1187 | + blob_set(&comment, zUtf8); | |
| 1188 | + fossil_mbcs_free(zUtf8); | |
| 1191 | 1189 | } |
| 1192 | 1190 | } |
| 1191 | +#endif /* _WIN32 */ | |
| 1193 | 1192 | db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment); |
| 1194 | 1193 | db_end_transaction(0); |
| 1195 | 1194 | db_begin_transaction(); |
| 1196 | 1195 | } |
| 1197 | 1196 | |
| 1198 | 1197 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -1151,12 +1151,15 @@ | |
| 1151 | prompt_user("empty check-in comment. continue (y/N)? ", &ans); |
| 1152 | if( blob_str(&ans)[0]!='y' ){ |
| 1153 | fossil_exit(1); |
| 1154 | } |
| 1155 | }else{ |
| 1156 | /* If the comment comes from the command line, it is utf-8 already. */ |
| 1157 | if( zComment == 0 ) { |
| 1158 | static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF }; |
| 1159 | static const unsigned short ubom = 0xfeff; |
| 1160 | static const unsigned short urbom = 0xfffe; |
| 1161 | if( blob_size(&comment)>2 && memcmp(blob_buffer(&comment), bom, 3)==0 ) { |
| 1162 | struct Blob temp; |
| @@ -1163,35 +1166,31 @@ | |
| 1163 | char *zUtf8 = blob_str(&comment) + 3; |
| 1164 | blob_set(&temp, zUtf8); |
| 1165 | fossil_mbcs_free(zUtf8); |
| 1166 | blob_swap(&temp, &comment); |
| 1167 | blob_reset(&temp); |
| 1168 | } else if( blob_size(&comment)>1 && (blob_size(&comment)&1)==0 |
| 1169 | && memcmp(blob_buffer(&comment), &ubom, 2)==0 ) { |
| 1170 | #ifdef _WIN32 |
| 1171 | char *zUtf8; |
| 1172 | /* Make sure the blob contains two terminating 0-bytes */ |
| 1173 | blob_append(&comment, "", 1); |
| 1174 | zUtf8 = blob_str(&comment) + 2; |
| 1175 | zUtf8 = fossil_unicode_to_utf8(zUtf8); |
| 1176 | blob_zero(&comment); |
| 1177 | blob_set(&comment, zUtf8); |
| 1178 | fossil_mbcs_free(zUtf8); |
| 1179 | #else |
| 1180 | fossil_fatal("unicode bom (le) not (yet) implemented"); |
| 1181 | #endif |
| 1182 | } else if( blob_size(&comment)>1 && memcmp(blob_buffer(&comment), &urbom, 2)==0 ) { |
| 1183 | fossil_fatal("unicode bom (be) not (yet) implemented"); |
| 1184 | #ifdef _WIN32 |
| 1185 | } else { |
| 1186 | char *zUtf8 = fossil_mbcs_to_utf8(blob_str(&comment)); |
| 1187 | blob_zero(&comment); |
| 1188 | blob_set(&comment, zUtf8); |
| 1189 | fossil_mbcs_free(zUtf8); |
| 1190 | #endif |
| 1191 | } |
| 1192 | } |
| 1193 | db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment); |
| 1194 | db_end_transaction(0); |
| 1195 | db_begin_transaction(); |
| 1196 | } |
| 1197 | |
| 1198 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -1151,12 +1151,15 @@ | |
| 1151 | prompt_user("empty check-in comment. continue (y/N)? ", &ans); |
| 1152 | if( blob_str(&ans)[0]!='y' ){ |
| 1153 | fossil_exit(1); |
| 1154 | } |
| 1155 | }else{ |
| 1156 | #ifdef _WIN32 |
| 1157 | /* On windows, the check-in comment might come back from the editor |
| 1158 | ** in various encodings. Try to figure out the encoding and do the |
| 1159 | ** right thing. */ |
| 1160 | if( zComment==0 ){ |
| 1161 | static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF }; |
| 1162 | static const unsigned short ubom = 0xfeff; |
| 1163 | static const unsigned short urbom = 0xfffe; |
| 1164 | if( blob_size(&comment)>2 && memcmp(blob_buffer(&comment), bom, 3)==0 ) { |
| 1165 | struct Blob temp; |
| @@ -1163,35 +1166,31 @@ | |
| 1166 | char *zUtf8 = blob_str(&comment) + 3; |
| 1167 | blob_set(&temp, zUtf8); |
| 1168 | fossil_mbcs_free(zUtf8); |
| 1169 | blob_swap(&temp, &comment); |
| 1170 | blob_reset(&temp); |
| 1171 | }else if( blob_size(&comment)>1 && (blob_size(&comment)&1)==0 |
| 1172 | && memcmp(blob_buffer(&comment), &ubom, 2)==0 ) { |
| 1173 | char *zUtf8; |
| 1174 | /* Make sure the blob contains two terminating 0-bytes */ |
| 1175 | blob_append(&comment, "", 1); |
| 1176 | zUtf8 = blob_str(&comment) + 2; |
| 1177 | zUtf8 = fossil_unicode_to_utf8(zUtf8); |
| 1178 | blob_zero(&comment); |
| 1179 | blob_set(&comment, zUtf8); |
| 1180 | fossil_mbcs_free(zUtf8); |
| 1181 | }else if( blob_size(&comment)>1 |
| 1182 | && memcmp(blob_buffer(&comment), &urbom, 2)==0 ){ |
| 1183 | fossil_fatal("unicode bom (be) not (yet) implemented"); |
| 1184 | }else{ |
| 1185 | char *zUtf8 = fossil_mbcs_to_utf8(blob_str(&comment)); |
| 1186 | blob_zero(&comment); |
| 1187 | blob_set(&comment, zUtf8); |
| 1188 | fossil_mbcs_free(zUtf8); |
| 1189 | } |
| 1190 | } |
| 1191 | #endif /* _WIN32 */ |
| 1192 | db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment); |
| 1193 | db_end_transaction(0); |
| 1194 | db_begin_transaction(); |
| 1195 | } |
| 1196 | |
| 1197 |