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.

drh 2012-09-25 16:19 use-utf8-in-win-external-editor
Commit 397c990400d39b6ba81df035836464c5ec5250ab
1 file changed +14 -15
+14 -15
--- src/checkin.c
+++ src/checkin.c
@@ -1151,12 +1151,15 @@
11511151
prompt_user("empty check-in comment. continue (y/N)? ", &ans);
11521152
if( blob_str(&ans)[0]!='y' ){
11531153
fossil_exit(1);
11541154
}
11551155
}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 ){
11581161
static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF };
11591162
static const unsigned short ubom = 0xfeff;
11601163
static const unsigned short urbom = 0xfffe;
11611164
if( blob_size(&comment)>2 && memcmp(blob_buffer(&comment), bom, 3)==0 ) {
11621165
struct Blob temp;
@@ -1163,35 +1166,31 @@
11631166
char *zUtf8 = blob_str(&comment) + 3;
11641167
blob_set(&temp, zUtf8);
11651168
fossil_mbcs_free(zUtf8);
11661169
blob_swap(&temp, &comment);
11671170
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
11691172
&& memcmp(blob_buffer(&comment), &ubom, 2)==0 ) {
1170
-#ifdef _WIN32
11711173
char *zUtf8;
11721174
/* Make sure the blob contains two terminating 0-bytes */
11731175
blob_append(&comment, "", 1);
11741176
zUtf8 = blob_str(&comment) + 2;
11751177
zUtf8 = fossil_unicode_to_utf8(zUtf8);
11761178
blob_zero(&comment);
11771179
blob_set(&comment, zUtf8);
11781180
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 ){
11831183
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);
11911189
}
11921190
}
1191
+#endif /* _WIN32 */
11931192
db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment);
11941193
db_end_transaction(0);
11951194
db_begin_transaction();
11961195
}
11971196
11981197
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button