Fossil SCM
Merge the changes to use various UTF encodings for win32 check-in comment editor into trunk.
Commit
cc01ec5094264e02489db3636f3cf48c3d101315
Parent
18c310afd84c5c9…
2 files changed
+66
-5
+66
-5
+66
-5
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -477,10 +477,15 @@ | ||
| 477 | 477 | zEditor = fossil_getenv("VISUAL"); |
| 478 | 478 | } |
| 479 | 479 | if( zEditor==0 ){ |
| 480 | 480 | zEditor = fossil_getenv("EDITOR"); |
| 481 | 481 | } |
| 482 | +#ifdef _WIN32 | |
| 483 | + if( zEditor==0 ){ | |
| 484 | + zEditor = mprintf("%s\\notepad.exe", fossil_getenv("SystemRoot")); | |
| 485 | + } | |
| 486 | +#endif | |
| 482 | 487 | if( zEditor==0 ){ |
| 483 | 488 | blob_append(pPrompt, |
| 484 | 489 | "#\n" |
| 485 | 490 | "# Since no default text editor is set using EDITOR or VISUAL\n" |
| 486 | 491 | "# environment variables or the \"fossil set editor\" command,\n" |
| @@ -506,17 +511,14 @@ | ||
| 506 | 511 | blob_read_from_file(&reply, zFile); |
| 507 | 512 | }else{ |
| 508 | 513 | char zIn[300]; |
| 509 | 514 | blob_zero(&reply); |
| 510 | 515 | while( fgets(zIn, sizeof(zIn), stdin)!=0 ){ |
| 511 | - char *zUtf8 = fossil_mbcs_to_utf8(zIn); | |
| 512 | - if( zUtf8[0]=='.' && (zUtf8[1]==0 || zUtf8[1]=='\r' || zUtf8[1]=='\n') ){ | |
| 513 | - fossil_mbcs_free(zUtf8); | |
| 516 | + if( zIn[0]=='.' && (zIn[1]==0 || zIn[1]=='\r' || zIn[1]=='\n') ){ | |
| 514 | 517 | break; |
| 515 | 518 | } |
| 516 | - blob_append(&reply, zUtf8, -1); | |
| 517 | - fossil_mbcs_free(zUtf8); | |
| 519 | + blob_append(&reply, zIn, -1); | |
| 518 | 520 | } |
| 519 | 521 | } |
| 520 | 522 | blob_remove_cr(&reply); |
| 521 | 523 | file_delete(zFile); |
| 522 | 524 | free(zFile); |
| @@ -562,11 +564,19 @@ | ||
| 562 | 564 | const char *zBranch, |
| 563 | 565 | int parent_rid, |
| 564 | 566 | const char *zUserOvrd |
| 565 | 567 | ){ |
| 566 | 568 | Blob prompt; |
| 569 | +#ifdef _WIN32 | |
| 570 | + static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF }; | |
| 571 | + blob_init(&prompt, (const char *) bom, 3); | |
| 572 | + if( zInit && zInit[0]) { | |
| 573 | + blob_append(&prompt, zInit, -1); | |
| 574 | + } | |
| 575 | +#else | |
| 567 | 576 | blob_init(&prompt, zInit, -1); |
| 577 | +#endif | |
| 568 | 578 | blob_append(&prompt, |
| 569 | 579 | "\n" |
| 570 | 580 | "# Enter comments on this check-in. Lines beginning with # are ignored.\n" |
| 571 | 581 | "# The check-in comment follows wiki formatting rules.\n" |
| 572 | 582 | "#\n", -1 |
| @@ -1192,10 +1202,61 @@ | ||
| 1192 | 1202 | prompt_user("empty check-in comment. continue (y/N)? ", &ans); |
| 1193 | 1203 | if( blob_str(&ans)[0]!='y' ){ |
| 1194 | 1204 | fossil_exit(1); |
| 1195 | 1205 | } |
| 1196 | 1206 | }else{ |
| 1207 | +#ifdef _WIN32 | |
| 1208 | + /* On windows, the check-in comment might come back from the editor | |
| 1209 | + ** in various encodings. Try to figure out the encoding and do the | |
| 1210 | + ** right thing. */ | |
| 1211 | + if( zComment==0 ){ | |
| 1212 | + static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF }; | |
| 1213 | + static const unsigned short ubom = 0xfeff; | |
| 1214 | + static const unsigned short urbom = 0xfffe; | |
| 1215 | + if( blob_size(&comment)>2 && memcmp(blob_buffer(&comment), bom, 3)==0 ) { | |
| 1216 | + struct Blob temp; | |
| 1217 | + char *zUtf8 = blob_str(&comment) + 3; | |
| 1218 | + blob_zero(&temp); | |
| 1219 | + blob_append(&temp, zUtf8, -1); | |
| 1220 | + fossil_mbcs_free(zUtf8); | |
| 1221 | + blob_swap(&temp, &comment); | |
| 1222 | + blob_reset(&temp); | |
| 1223 | + }else if( blob_size(&comment)>1 && (blob_size(&comment)&1)==0 | |
| 1224 | + && memcmp(blob_buffer(&comment), &ubom, 2)==0 ) { | |
| 1225 | + char *zUtf8; | |
| 1226 | + /* Make sure the blob contains two terminating 0-bytes */ | |
| 1227 | + blob_append(&comment, "", 1); | |
| 1228 | + zUtf8 = blob_str(&comment) + 2; | |
| 1229 | + zUtf8 = fossil_unicode_to_utf8(zUtf8); | |
| 1230 | + blob_zero(&comment); | |
| 1231 | + blob_append(&comment, zUtf8, -1); | |
| 1232 | + fossil_mbcs_free(zUtf8); | |
| 1233 | + }else if( blob_size(&comment)>1 && (blob_size(&comment)&1)==0 | |
| 1234 | + && memcmp(blob_buffer(&comment), &urbom, 2)==0 ) { | |
| 1235 | + char *zUtf8 = blob_buffer(&comment); | |
| 1236 | + unsigned int i = blob_size(&comment); | |
| 1237 | + while( i > 0 ){ | |
| 1238 | + /* swap bytes of unicode representation */ | |
| 1239 | + char temp = zUtf8[--i]; | |
| 1240 | + zUtf8[i] = zUtf8[i-1]; | |
| 1241 | + zUtf8[--i] = temp; | |
| 1242 | + } | |
| 1243 | + /* Make sure the blob contains two terminating 0-bytes */ | |
| 1244 | + blob_append(&comment, "", 1); | |
| 1245 | + zUtf8 = blob_str(&comment) + 2; | |
| 1246 | + zUtf8 = fossil_unicode_to_utf8(zUtf8); | |
| 1247 | + blob_zero(&comment); | |
| 1248 | + blob_append(&comment, zUtf8, -1); | |
| 1249 | + fossil_mbcs_free(zUtf8); | |
| 1250 | + }else{ | |
| 1251 | + char *zUtf8 = fossil_mbcs_to_utf8(blob_str(&comment)); | |
| 1252 | + blob_zero(&comment); | |
| 1253 | + blob_append(&comment, zUtf8, -1); | |
| 1254 | + fossil_mbcs_free(zUtf8); | |
| 1255 | + } | |
| 1256 | + } | |
| 1257 | +#endif /* _WIN32 */ | |
| 1197 | 1258 | db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment); |
| 1198 | 1259 | db_end_transaction(0); |
| 1199 | 1260 | db_begin_transaction(); |
| 1200 | 1261 | } |
| 1201 | 1262 | |
| 1202 | 1263 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -477,10 +477,15 @@ | |
| 477 | zEditor = fossil_getenv("VISUAL"); |
| 478 | } |
| 479 | if( zEditor==0 ){ |
| 480 | zEditor = fossil_getenv("EDITOR"); |
| 481 | } |
| 482 | if( zEditor==0 ){ |
| 483 | blob_append(pPrompt, |
| 484 | "#\n" |
| 485 | "# Since no default text editor is set using EDITOR or VISUAL\n" |
| 486 | "# environment variables or the \"fossil set editor\" command,\n" |
| @@ -506,17 +511,14 @@ | |
| 506 | blob_read_from_file(&reply, zFile); |
| 507 | }else{ |
| 508 | char zIn[300]; |
| 509 | blob_zero(&reply); |
| 510 | while( fgets(zIn, sizeof(zIn), stdin)!=0 ){ |
| 511 | char *zUtf8 = fossil_mbcs_to_utf8(zIn); |
| 512 | if( zUtf8[0]=='.' && (zUtf8[1]==0 || zUtf8[1]=='\r' || zUtf8[1]=='\n') ){ |
| 513 | fossil_mbcs_free(zUtf8); |
| 514 | break; |
| 515 | } |
| 516 | blob_append(&reply, zUtf8, -1); |
| 517 | fossil_mbcs_free(zUtf8); |
| 518 | } |
| 519 | } |
| 520 | blob_remove_cr(&reply); |
| 521 | file_delete(zFile); |
| 522 | free(zFile); |
| @@ -562,11 +564,19 @@ | |
| 562 | const char *zBranch, |
| 563 | int parent_rid, |
| 564 | const char *zUserOvrd |
| 565 | ){ |
| 566 | Blob prompt; |
| 567 | blob_init(&prompt, zInit, -1); |
| 568 | blob_append(&prompt, |
| 569 | "\n" |
| 570 | "# Enter comments on this check-in. Lines beginning with # are ignored.\n" |
| 571 | "# The check-in comment follows wiki formatting rules.\n" |
| 572 | "#\n", -1 |
| @@ -1192,10 +1202,61 @@ | |
| 1192 | prompt_user("empty check-in comment. continue (y/N)? ", &ans); |
| 1193 | if( blob_str(&ans)[0]!='y' ){ |
| 1194 | fossil_exit(1); |
| 1195 | } |
| 1196 | }else{ |
| 1197 | db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment); |
| 1198 | db_end_transaction(0); |
| 1199 | db_begin_transaction(); |
| 1200 | } |
| 1201 | |
| 1202 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -477,10 +477,15 @@ | |
| 477 | zEditor = fossil_getenv("VISUAL"); |
| 478 | } |
| 479 | if( zEditor==0 ){ |
| 480 | zEditor = fossil_getenv("EDITOR"); |
| 481 | } |
| 482 | #ifdef _WIN32 |
| 483 | if( zEditor==0 ){ |
| 484 | zEditor = mprintf("%s\\notepad.exe", fossil_getenv("SystemRoot")); |
| 485 | } |
| 486 | #endif |
| 487 | if( zEditor==0 ){ |
| 488 | blob_append(pPrompt, |
| 489 | "#\n" |
| 490 | "# Since no default text editor is set using EDITOR or VISUAL\n" |
| 491 | "# environment variables or the \"fossil set editor\" command,\n" |
| @@ -506,17 +511,14 @@ | |
| 511 | blob_read_from_file(&reply, zFile); |
| 512 | }else{ |
| 513 | char zIn[300]; |
| 514 | blob_zero(&reply); |
| 515 | while( fgets(zIn, sizeof(zIn), stdin)!=0 ){ |
| 516 | if( zIn[0]=='.' && (zIn[1]==0 || zIn[1]=='\r' || zIn[1]=='\n') ){ |
| 517 | break; |
| 518 | } |
| 519 | blob_append(&reply, zIn, -1); |
| 520 | } |
| 521 | } |
| 522 | blob_remove_cr(&reply); |
| 523 | file_delete(zFile); |
| 524 | free(zFile); |
| @@ -562,11 +564,19 @@ | |
| 564 | const char *zBranch, |
| 565 | int parent_rid, |
| 566 | const char *zUserOvrd |
| 567 | ){ |
| 568 | Blob prompt; |
| 569 | #ifdef _WIN32 |
| 570 | static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF }; |
| 571 | blob_init(&prompt, (const char *) bom, 3); |
| 572 | if( zInit && zInit[0]) { |
| 573 | blob_append(&prompt, zInit, -1); |
| 574 | } |
| 575 | #else |
| 576 | blob_init(&prompt, zInit, -1); |
| 577 | #endif |
| 578 | blob_append(&prompt, |
| 579 | "\n" |
| 580 | "# Enter comments on this check-in. Lines beginning with # are ignored.\n" |
| 581 | "# The check-in comment follows wiki formatting rules.\n" |
| 582 | "#\n", -1 |
| @@ -1192,10 +1202,61 @@ | |
| 1202 | prompt_user("empty check-in comment. continue (y/N)? ", &ans); |
| 1203 | if( blob_str(&ans)[0]!='y' ){ |
| 1204 | fossil_exit(1); |
| 1205 | } |
| 1206 | }else{ |
| 1207 | #ifdef _WIN32 |
| 1208 | /* On windows, the check-in comment might come back from the editor |
| 1209 | ** in various encodings. Try to figure out the encoding and do the |
| 1210 | ** right thing. */ |
| 1211 | if( zComment==0 ){ |
| 1212 | static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF }; |
| 1213 | static const unsigned short ubom = 0xfeff; |
| 1214 | static const unsigned short urbom = 0xfffe; |
| 1215 | if( blob_size(&comment)>2 && memcmp(blob_buffer(&comment), bom, 3)==0 ) { |
| 1216 | struct Blob temp; |
| 1217 | char *zUtf8 = blob_str(&comment) + 3; |
| 1218 | blob_zero(&temp); |
| 1219 | blob_append(&temp, zUtf8, -1); |
| 1220 | fossil_mbcs_free(zUtf8); |
| 1221 | blob_swap(&temp, &comment); |
| 1222 | blob_reset(&temp); |
| 1223 | }else if( blob_size(&comment)>1 && (blob_size(&comment)&1)==0 |
| 1224 | && memcmp(blob_buffer(&comment), &ubom, 2)==0 ) { |
| 1225 | char *zUtf8; |
| 1226 | /* Make sure the blob contains two terminating 0-bytes */ |
| 1227 | blob_append(&comment, "", 1); |
| 1228 | zUtf8 = blob_str(&comment) + 2; |
| 1229 | zUtf8 = fossil_unicode_to_utf8(zUtf8); |
| 1230 | blob_zero(&comment); |
| 1231 | blob_append(&comment, zUtf8, -1); |
| 1232 | fossil_mbcs_free(zUtf8); |
| 1233 | }else if( blob_size(&comment)>1 && (blob_size(&comment)&1)==0 |
| 1234 | && memcmp(blob_buffer(&comment), &urbom, 2)==0 ) { |
| 1235 | char *zUtf8 = blob_buffer(&comment); |
| 1236 | unsigned int i = blob_size(&comment); |
| 1237 | while( i > 0 ){ |
| 1238 | /* swap bytes of unicode representation */ |
| 1239 | char temp = zUtf8[--i]; |
| 1240 | zUtf8[i] = zUtf8[i-1]; |
| 1241 | zUtf8[--i] = temp; |
| 1242 | } |
| 1243 | /* Make sure the blob contains two terminating 0-bytes */ |
| 1244 | blob_append(&comment, "", 1); |
| 1245 | zUtf8 = blob_str(&comment) + 2; |
| 1246 | zUtf8 = fossil_unicode_to_utf8(zUtf8); |
| 1247 | blob_zero(&comment); |
| 1248 | blob_append(&comment, zUtf8, -1); |
| 1249 | fossil_mbcs_free(zUtf8); |
| 1250 | }else{ |
| 1251 | char *zUtf8 = fossil_mbcs_to_utf8(blob_str(&comment)); |
| 1252 | blob_zero(&comment); |
| 1253 | blob_append(&comment, zUtf8, -1); |
| 1254 | fossil_mbcs_free(zUtf8); |
| 1255 | } |
| 1256 | } |
| 1257 | #endif /* _WIN32 */ |
| 1258 | db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment); |
| 1259 | db_end_transaction(0); |
| 1260 | db_begin_transaction(); |
| 1261 | } |
| 1262 | |
| 1263 |
+66
-5
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -477,10 +477,15 @@ | ||
| 477 | 477 | zEditor = fossil_getenv("VISUAL"); |
| 478 | 478 | } |
| 479 | 479 | if( zEditor==0 ){ |
| 480 | 480 | zEditor = fossil_getenv("EDITOR"); |
| 481 | 481 | } |
| 482 | +#ifdef _WIN32 | |
| 483 | + if( zEditor==0 ){ | |
| 484 | + zEditor = mprintf("%s\\notepad.exe", fossil_getenv("SystemRoot")); | |
| 485 | + } | |
| 486 | +#endif | |
| 482 | 487 | if( zEditor==0 ){ |
| 483 | 488 | blob_append(pPrompt, |
| 484 | 489 | "#\n" |
| 485 | 490 | "# Since no default text editor is set using EDITOR or VISUAL\n" |
| 486 | 491 | "# environment variables or the \"fossil set editor\" command,\n" |
| @@ -506,17 +511,14 @@ | ||
| 506 | 511 | blob_read_from_file(&reply, zFile); |
| 507 | 512 | }else{ |
| 508 | 513 | char zIn[300]; |
| 509 | 514 | blob_zero(&reply); |
| 510 | 515 | while( fgets(zIn, sizeof(zIn), stdin)!=0 ){ |
| 511 | - char *zUtf8 = fossil_mbcs_to_utf8(zIn); | |
| 512 | - if( zUtf8[0]=='.' && (zUtf8[1]==0 || zUtf8[1]=='\r' || zUtf8[1]=='\n') ){ | |
| 513 | - fossil_mbcs_free(zUtf8); | |
| 516 | + if( zIn[0]=='.' && (zIn[1]==0 || zIn[1]=='\r' || zIn[1]=='\n') ){ | |
| 514 | 517 | break; |
| 515 | 518 | } |
| 516 | - blob_append(&reply, zUtf8, -1); | |
| 517 | - fossil_mbcs_free(zUtf8); | |
| 519 | + blob_append(&reply, zIn, -1); | |
| 518 | 520 | } |
| 519 | 521 | } |
| 520 | 522 | blob_remove_cr(&reply); |
| 521 | 523 | file_delete(zFile); |
| 522 | 524 | free(zFile); |
| @@ -562,11 +564,19 @@ | ||
| 562 | 564 | const char *zBranch, |
| 563 | 565 | int parent_rid, |
| 564 | 566 | const char *zUserOvrd |
| 565 | 567 | ){ |
| 566 | 568 | Blob prompt; |
| 569 | +#ifdef _WIN32 | |
| 570 | + static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF }; | |
| 571 | + blob_init(&prompt, (const char *) bom, 3); | |
| 572 | + if( zInit && zInit[0]) { | |
| 573 | + blob_append(&prompt, zInit, -1); | |
| 574 | + } | |
| 575 | +#else | |
| 567 | 576 | blob_init(&prompt, zInit, -1); |
| 577 | +#endif | |
| 568 | 578 | blob_append(&prompt, |
| 569 | 579 | "\n" |
| 570 | 580 | "# Enter comments on this check-in. Lines beginning with # are ignored.\n" |
| 571 | 581 | "# The check-in comment follows wiki formatting rules.\n" |
| 572 | 582 | "#\n", -1 |
| @@ -1192,10 +1202,61 @@ | ||
| 1192 | 1202 | prompt_user("empty check-in comment. continue (y/N)? ", &ans); |
| 1193 | 1203 | if( blob_str(&ans)[0]!='y' ){ |
| 1194 | 1204 | fossil_exit(1); |
| 1195 | 1205 | } |
| 1196 | 1206 | }else{ |
| 1207 | +#ifdef _WIN32 | |
| 1208 | + /* On windows, the check-in comment might come back from the editor | |
| 1209 | + ** in various encodings. Try to figure out the encoding and do the | |
| 1210 | + ** right thing. */ | |
| 1211 | + if( zComment==0 ){ | |
| 1212 | + static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF }; | |
| 1213 | + static const unsigned short ubom = 0xfeff; | |
| 1214 | + static const unsigned short urbom = 0xfffe; | |
| 1215 | + if( blob_size(&comment)>2 && memcmp(blob_buffer(&comment), bom, 3)==0 ) { | |
| 1216 | + struct Blob temp; | |
| 1217 | + char *zUtf8 = blob_str(&comment) + 3; | |
| 1218 | + blob_zero(&temp); | |
| 1219 | + blob_append(&temp, zUtf8, -1); | |
| 1220 | + fossil_mbcs_free(zUtf8); | |
| 1221 | + blob_swap(&temp, &comment); | |
| 1222 | + blob_reset(&temp); | |
| 1223 | + }else if( blob_size(&comment)>1 && (blob_size(&comment)&1)==0 | |
| 1224 | + && memcmp(blob_buffer(&comment), &ubom, 2)==0 ) { | |
| 1225 | + char *zUtf8; | |
| 1226 | + /* Make sure the blob contains two terminating 0-bytes */ | |
| 1227 | + blob_append(&comment, "", 1); | |
| 1228 | + zUtf8 = blob_str(&comment) + 2; | |
| 1229 | + zUtf8 = fossil_unicode_to_utf8(zUtf8); | |
| 1230 | + blob_zero(&comment); | |
| 1231 | + blob_append(&comment, zUtf8, -1); | |
| 1232 | + fossil_mbcs_free(zUtf8); | |
| 1233 | + }else if( blob_size(&comment)>1 && (blob_size(&comment)&1)==0 | |
| 1234 | + && memcmp(blob_buffer(&comment), &urbom, 2)==0 ) { | |
| 1235 | + char *zUtf8 = blob_buffer(&comment); | |
| 1236 | + unsigned int i = blob_size(&comment); | |
| 1237 | + while( i > 0 ){ | |
| 1238 | + /* swap bytes of unicode representation */ | |
| 1239 | + char temp = zUtf8[--i]; | |
| 1240 | + zUtf8[i] = zUtf8[i-1]; | |
| 1241 | + zUtf8[--i] = temp; | |
| 1242 | + } | |
| 1243 | + /* Make sure the blob contains two terminating 0-bytes */ | |
| 1244 | + blob_append(&comment, "", 1); | |
| 1245 | + zUtf8 = blob_str(&comment) + 2; | |
| 1246 | + zUtf8 = fossil_unicode_to_utf8(zUtf8); | |
| 1247 | + blob_zero(&comment); | |
| 1248 | + blob_append(&comment, zUtf8, -1); | |
| 1249 | + fossil_mbcs_free(zUtf8); | |
| 1250 | + }else{ | |
| 1251 | + char *zUtf8 = fossil_mbcs_to_utf8(blob_str(&comment)); | |
| 1252 | + blob_zero(&comment); | |
| 1253 | + blob_append(&comment, zUtf8, -1); | |
| 1254 | + fossil_mbcs_free(zUtf8); | |
| 1255 | + } | |
| 1256 | + } | |
| 1257 | +#endif /* _WIN32 */ | |
| 1197 | 1258 | db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment); |
| 1198 | 1259 | db_end_transaction(0); |
| 1199 | 1260 | db_begin_transaction(); |
| 1200 | 1261 | } |
| 1201 | 1262 | |
| 1202 | 1263 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -477,10 +477,15 @@ | |
| 477 | zEditor = fossil_getenv("VISUAL"); |
| 478 | } |
| 479 | if( zEditor==0 ){ |
| 480 | zEditor = fossil_getenv("EDITOR"); |
| 481 | } |
| 482 | if( zEditor==0 ){ |
| 483 | blob_append(pPrompt, |
| 484 | "#\n" |
| 485 | "# Since no default text editor is set using EDITOR or VISUAL\n" |
| 486 | "# environment variables or the \"fossil set editor\" command,\n" |
| @@ -506,17 +511,14 @@ | |
| 506 | blob_read_from_file(&reply, zFile); |
| 507 | }else{ |
| 508 | char zIn[300]; |
| 509 | blob_zero(&reply); |
| 510 | while( fgets(zIn, sizeof(zIn), stdin)!=0 ){ |
| 511 | char *zUtf8 = fossil_mbcs_to_utf8(zIn); |
| 512 | if( zUtf8[0]=='.' && (zUtf8[1]==0 || zUtf8[1]=='\r' || zUtf8[1]=='\n') ){ |
| 513 | fossil_mbcs_free(zUtf8); |
| 514 | break; |
| 515 | } |
| 516 | blob_append(&reply, zUtf8, -1); |
| 517 | fossil_mbcs_free(zUtf8); |
| 518 | } |
| 519 | } |
| 520 | blob_remove_cr(&reply); |
| 521 | file_delete(zFile); |
| 522 | free(zFile); |
| @@ -562,11 +564,19 @@ | |
| 562 | const char *zBranch, |
| 563 | int parent_rid, |
| 564 | const char *zUserOvrd |
| 565 | ){ |
| 566 | Blob prompt; |
| 567 | blob_init(&prompt, zInit, -1); |
| 568 | blob_append(&prompt, |
| 569 | "\n" |
| 570 | "# Enter comments on this check-in. Lines beginning with # are ignored.\n" |
| 571 | "# The check-in comment follows wiki formatting rules.\n" |
| 572 | "#\n", -1 |
| @@ -1192,10 +1202,61 @@ | |
| 1192 | prompt_user("empty check-in comment. continue (y/N)? ", &ans); |
| 1193 | if( blob_str(&ans)[0]!='y' ){ |
| 1194 | fossil_exit(1); |
| 1195 | } |
| 1196 | }else{ |
| 1197 | db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment); |
| 1198 | db_end_transaction(0); |
| 1199 | db_begin_transaction(); |
| 1200 | } |
| 1201 | |
| 1202 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -477,10 +477,15 @@ | |
| 477 | zEditor = fossil_getenv("VISUAL"); |
| 478 | } |
| 479 | if( zEditor==0 ){ |
| 480 | zEditor = fossil_getenv("EDITOR"); |
| 481 | } |
| 482 | #ifdef _WIN32 |
| 483 | if( zEditor==0 ){ |
| 484 | zEditor = mprintf("%s\\notepad.exe", fossil_getenv("SystemRoot")); |
| 485 | } |
| 486 | #endif |
| 487 | if( zEditor==0 ){ |
| 488 | blob_append(pPrompt, |
| 489 | "#\n" |
| 490 | "# Since no default text editor is set using EDITOR or VISUAL\n" |
| 491 | "# environment variables or the \"fossil set editor\" command,\n" |
| @@ -506,17 +511,14 @@ | |
| 511 | blob_read_from_file(&reply, zFile); |
| 512 | }else{ |
| 513 | char zIn[300]; |
| 514 | blob_zero(&reply); |
| 515 | while( fgets(zIn, sizeof(zIn), stdin)!=0 ){ |
| 516 | if( zIn[0]=='.' && (zIn[1]==0 || zIn[1]=='\r' || zIn[1]=='\n') ){ |
| 517 | break; |
| 518 | } |
| 519 | blob_append(&reply, zIn, -1); |
| 520 | } |
| 521 | } |
| 522 | blob_remove_cr(&reply); |
| 523 | file_delete(zFile); |
| 524 | free(zFile); |
| @@ -562,11 +564,19 @@ | |
| 564 | const char *zBranch, |
| 565 | int parent_rid, |
| 566 | const char *zUserOvrd |
| 567 | ){ |
| 568 | Blob prompt; |
| 569 | #ifdef _WIN32 |
| 570 | static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF }; |
| 571 | blob_init(&prompt, (const char *) bom, 3); |
| 572 | if( zInit && zInit[0]) { |
| 573 | blob_append(&prompt, zInit, -1); |
| 574 | } |
| 575 | #else |
| 576 | blob_init(&prompt, zInit, -1); |
| 577 | #endif |
| 578 | blob_append(&prompt, |
| 579 | "\n" |
| 580 | "# Enter comments on this check-in. Lines beginning with # are ignored.\n" |
| 581 | "# The check-in comment follows wiki formatting rules.\n" |
| 582 | "#\n", -1 |
| @@ -1192,10 +1202,61 @@ | |
| 1202 | prompt_user("empty check-in comment. continue (y/N)? ", &ans); |
| 1203 | if( blob_str(&ans)[0]!='y' ){ |
| 1204 | fossil_exit(1); |
| 1205 | } |
| 1206 | }else{ |
| 1207 | #ifdef _WIN32 |
| 1208 | /* On windows, the check-in comment might come back from the editor |
| 1209 | ** in various encodings. Try to figure out the encoding and do the |
| 1210 | ** right thing. */ |
| 1211 | if( zComment==0 ){ |
| 1212 | static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF }; |
| 1213 | static const unsigned short ubom = 0xfeff; |
| 1214 | static const unsigned short urbom = 0xfffe; |
| 1215 | if( blob_size(&comment)>2 && memcmp(blob_buffer(&comment), bom, 3)==0 ) { |
| 1216 | struct Blob temp; |
| 1217 | char *zUtf8 = blob_str(&comment) + 3; |
| 1218 | blob_zero(&temp); |
| 1219 | blob_append(&temp, zUtf8, -1); |
| 1220 | fossil_mbcs_free(zUtf8); |
| 1221 | blob_swap(&temp, &comment); |
| 1222 | blob_reset(&temp); |
| 1223 | }else if( blob_size(&comment)>1 && (blob_size(&comment)&1)==0 |
| 1224 | && memcmp(blob_buffer(&comment), &ubom, 2)==0 ) { |
| 1225 | char *zUtf8; |
| 1226 | /* Make sure the blob contains two terminating 0-bytes */ |
| 1227 | blob_append(&comment, "", 1); |
| 1228 | zUtf8 = blob_str(&comment) + 2; |
| 1229 | zUtf8 = fossil_unicode_to_utf8(zUtf8); |
| 1230 | blob_zero(&comment); |
| 1231 | blob_append(&comment, zUtf8, -1); |
| 1232 | fossil_mbcs_free(zUtf8); |
| 1233 | }else if( blob_size(&comment)>1 && (blob_size(&comment)&1)==0 |
| 1234 | && memcmp(blob_buffer(&comment), &urbom, 2)==0 ) { |
| 1235 | char *zUtf8 = blob_buffer(&comment); |
| 1236 | unsigned int i = blob_size(&comment); |
| 1237 | while( i > 0 ){ |
| 1238 | /* swap bytes of unicode representation */ |
| 1239 | char temp = zUtf8[--i]; |
| 1240 | zUtf8[i] = zUtf8[i-1]; |
| 1241 | zUtf8[--i] = temp; |
| 1242 | } |
| 1243 | /* Make sure the blob contains two terminating 0-bytes */ |
| 1244 | blob_append(&comment, "", 1); |
| 1245 | zUtf8 = blob_str(&comment) + 2; |
| 1246 | zUtf8 = fossil_unicode_to_utf8(zUtf8); |
| 1247 | blob_zero(&comment); |
| 1248 | blob_append(&comment, zUtf8, -1); |
| 1249 | fossil_mbcs_free(zUtf8); |
| 1250 | }else{ |
| 1251 | char *zUtf8 = fossil_mbcs_to_utf8(blob_str(&comment)); |
| 1252 | blob_zero(&comment); |
| 1253 | blob_append(&comment, zUtf8, -1); |
| 1254 | fossil_mbcs_free(zUtf8); |
| 1255 | } |
| 1256 | } |
| 1257 | #endif /* _WIN32 */ |
| 1258 | db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment); |
| 1259 | db_end_transaction(0); |
| 1260 | db_begin_transaction(); |
| 1261 | } |
| 1262 | |
| 1263 |