Fossil SCM

C

jan.nijtmans 2012-09-25 14:10 trunk
Commit 3a20d89d953ba96e5eb5784dfed03f5fb76f0f12
1 file changed +53 -8
+53 -8
--- src/checkin.c
+++ src/checkin.c
@@ -486,19 +486,28 @@
486486
"# environment variables or the \"fossil set editor\" command,\n"
487487
"# and because no check-in comment was specified using the \"-m\"\n"
488488
"# or \"-M\" command-line options, you will need to enter the\n"
489489
"# check-in comment below. Type \".\" on a line by itself when\n"
490490
"# you are done:\n", -1);
491
- zFile = mprintf("-");
491
+ zFile = NULL;
492492
}else{
493493
zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'",
494494
g.zLocalRoot);
495495
}
496496
#if defined(_WIN32)
497497
blob_add_cr(&text);
498498
#endif
499
- blob_write_to_file(&text, zFile);
499
+ if( zEditor || fossil_utf8_to_console(blob_buffer(&text), blob_size(&text), 0) < 0) {
500
+ /* We have an external editor or else we cannot write it directly to the
501
+ * (windows) console, so write it to stdout in mbcs encoding. */
502
+ struct Blob temp;
503
+ zComment = fossil_utf8_to_mbcs(blob_str(&text));
504
+ blob_set(&temp, zComment);
505
+ blob_write_to_file(&temp, zFile);
506
+ blob_zero(&temp);
507
+ fossil_mbcs_free(zComment);
508
+ }
500509
if( zEditor ){
501510
zCmd = mprintf("%s \"%s\"", zEditor, zFile);
502511
fossil_print("%s\n", zCmd);
503512
if( fossil_system(zCmd) ){
504513
fossil_panic("editor aborted");
@@ -507,22 +516,21 @@
507516
blob_read_from_file(&text, zFile);
508517
}else{
509518
char zIn[300];
510519
blob_reset(&text);
511520
while( fgets(zIn, sizeof(zIn), stdin)!=0 ){
512
- char *zUtf8 = fossil_mbcs_to_utf8(zIn);
513
- if( zUtf8[0]=='.' && (zUtf8[1]==0 || zUtf8[1]=='\r' || zUtf8[1]=='\n') ){
514
- fossil_mbcs_free(zUtf8);
521
+ if( zIn[0]=='.' && (zIn[1]==0 || zIn[1]=='\r' || zIn[1]=='\n') ){
515522
break;
516523
}
517524
blob_append(&text, zIn, -1);
518
- fossil_mbcs_free(zUtf8);
519525
}
520526
}
521527
blob_remove_cr(&text);
522
- file_delete(zFile);
523
- free(zFile);
528
+ if( zFile ) {
529
+ file_delete(zFile);
530
+ fossil_free(zFile);
531
+ }
524532
blob_zero(pComment);
525533
while( blob_line(&text, &line) ){
526534
int i, n;
527535
char *z;
528536
n = blob_size(&line);
@@ -1143,10 +1151,47 @@
11431151
prompt_user("empty check-in comment. continue (y/N)? ", &ans);
11441152
if( blob_str(&ans)[0]!='y' ){
11451153
fossil_exit(1);
11461154
}
11471155
}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
+ 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
+ }
11481193
db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment);
11491194
db_end_transaction(0);
11501195
db_begin_transaction();
11511196
}
11521197
11531198
--- src/checkin.c
+++ src/checkin.c
@@ -486,19 +486,28 @@
486 "# environment variables or the \"fossil set editor\" command,\n"
487 "# and because no check-in comment was specified using the \"-m\"\n"
488 "# or \"-M\" command-line options, you will need to enter the\n"
489 "# check-in comment below. Type \".\" on a line by itself when\n"
490 "# you are done:\n", -1);
491 zFile = mprintf("-");
492 }else{
493 zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'",
494 g.zLocalRoot);
495 }
496 #if defined(_WIN32)
497 blob_add_cr(&text);
498 #endif
499 blob_write_to_file(&text, zFile);
 
 
 
 
 
 
 
 
 
500 if( zEditor ){
501 zCmd = mprintf("%s \"%s\"", zEditor, zFile);
502 fossil_print("%s\n", zCmd);
503 if( fossil_system(zCmd) ){
504 fossil_panic("editor aborted");
@@ -507,22 +516,21 @@
507 blob_read_from_file(&text, zFile);
508 }else{
509 char zIn[300];
510 blob_reset(&text);
511 while( fgets(zIn, sizeof(zIn), stdin)!=0 ){
512 char *zUtf8 = fossil_mbcs_to_utf8(zIn);
513 if( zUtf8[0]=='.' && (zUtf8[1]==0 || zUtf8[1]=='\r' || zUtf8[1]=='\n') ){
514 fossil_mbcs_free(zUtf8);
515 break;
516 }
517 blob_append(&text, zIn, -1);
518 fossil_mbcs_free(zUtf8);
519 }
520 }
521 blob_remove_cr(&text);
522 file_delete(zFile);
523 free(zFile);
 
 
524 blob_zero(pComment);
525 while( blob_line(&text, &line) ){
526 int i, n;
527 char *z;
528 n = blob_size(&line);
@@ -1143,10 +1151,47 @@
1143 prompt_user("empty check-in comment. continue (y/N)? ", &ans);
1144 if( blob_str(&ans)[0]!='y' ){
1145 fossil_exit(1);
1146 }
1147 }else{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1148 db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment);
1149 db_end_transaction(0);
1150 db_begin_transaction();
1151 }
1152
1153
--- src/checkin.c
+++ src/checkin.c
@@ -486,19 +486,28 @@
486 "# environment variables or the \"fossil set editor\" command,\n"
487 "# and because no check-in comment was specified using the \"-m\"\n"
488 "# or \"-M\" command-line options, you will need to enter the\n"
489 "# check-in comment below. Type \".\" on a line by itself when\n"
490 "# you are done:\n", -1);
491 zFile = NULL;
492 }else{
493 zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'",
494 g.zLocalRoot);
495 }
496 #if defined(_WIN32)
497 blob_add_cr(&text);
498 #endif
499 if( zEditor || fossil_utf8_to_console(blob_buffer(&text), blob_size(&text), 0) < 0) {
500 /* We have an external editor or else we cannot write it directly to the
501 * (windows) console, so write it to stdout in mbcs encoding. */
502 struct Blob temp;
503 zComment = fossil_utf8_to_mbcs(blob_str(&text));
504 blob_set(&temp, zComment);
505 blob_write_to_file(&temp, zFile);
506 blob_zero(&temp);
507 fossil_mbcs_free(zComment);
508 }
509 if( zEditor ){
510 zCmd = mprintf("%s \"%s\"", zEditor, zFile);
511 fossil_print("%s\n", zCmd);
512 if( fossil_system(zCmd) ){
513 fossil_panic("editor aborted");
@@ -507,22 +516,21 @@
516 blob_read_from_file(&text, zFile);
517 }else{
518 char zIn[300];
519 blob_reset(&text);
520 while( fgets(zIn, sizeof(zIn), stdin)!=0 ){
521 if( zIn[0]=='.' && (zIn[1]==0 || zIn[1]=='\r' || zIn[1]=='\n') ){
 
 
522 break;
523 }
524 blob_append(&text, zIn, -1);
 
525 }
526 }
527 blob_remove_cr(&text);
528 if( zFile ) {
529 file_delete(zFile);
530 fossil_free(zFile);
531 }
532 blob_zero(pComment);
533 while( blob_line(&text, &line) ){
534 int i, n;
535 char *z;
536 n = blob_size(&line);
@@ -1143,10 +1151,47 @@
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 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

Keyboard Shortcuts

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