Fossil SCM

use utf8 in stash comment editor on Windows, just like the commit comment editor

jan.nijtmans 2012-10-25 10:27 trunk
Commit fb565614db96487c7b20975a863f252bd2c03d0a
+58
--- src/blob.c
+++ src/blob.c
@@ -1084,5 +1084,63 @@
10841084
void blob_swap( Blob *pLeft, Blob *pRight ){
10851085
Blob swap = *pLeft;
10861086
*pLeft = *pRight;
10871087
*pRight = swap;
10881088
}
1089
+
1090
+/*
1091
+** Strip a possible BOM from the blob. On Windows, if there
1092
+** is either no BOM at all or an (le/be) UTF-16 BOM, a conversion
1093
+** to UTF-8 is done.
1094
+** If useMbcs is false and there is no BOM, the input string
1095
+** is assumed to be UTF-8 already, so no conversion is done.
1096
+*/
1097
+void blob_strip_bom(Blob *pBlob, int useMbcs){
1098
+ static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF };
1099
+#ifdef _WIN32
1100
+ static const unsigned short ubom = 0xfeff;
1101
+ static const unsigned short urbom = 0xfffe;
1102
+#endif /* _WIN32 */
1103
+ char *zUtf8;
1104
+ if( blob_size(pBlob)>2 && memcmp(blob_buffer(pBlob), bom, 3)==0 ) {
1105
+ struct Blob temp;
1106
+ zUtf8 = blob_str(pBlob) + 3;
1107
+ blob_zero(&temp);
1108
+ blob_append(&temp, zUtf8, -1);
1109
+ fossil_mbcs_free(zUtf8);
1110
+ blob_swap(pBlob, &temp);
1111
+ blob_reset(&temp);
1112
+#ifdef _WIN32
1113
+ }else if( blob_size(pBlob)>1 && (blob_size(pBlob)&1)==0
1114
+ && memcmp(blob_buffer(pBlob), &ubom, 2)==0 ) {
1115
+ /* Make sure the blob contains two terminating 0-bytes */
1116
+ blob_append(pBlob, "", 1);
1117
+ zUtf8 = blob_str(pBlob) + 2;
1118
+ zUtf8 = fossil_unicode_to_utf8(zUtf8);
1119
+ blob_zero(pBlob);
1120
+ blob_append(pBlob, zUtf8, -1);
1121
+ fossil_mbcs_free(zUtf8);
1122
+ }else if( blob_size(pBlob)>1 && (blob_size(pBlob)&1)==0
1123
+ && memcmp(blob_buffer(pBlob), &urbom, 2)==0 ) {
1124
+ zUtf8 = blob_buffer(pBlob);
1125
+ unsigned int i = blob_size(pBlob);
1126
+ while( i > 0 ){
1127
+ /* swap bytes of unicode representation */
1128
+ char temp = zUtf8[--i];
1129
+ zUtf8[i] = zUtf8[i-1];
1130
+ zUtf8[--i] = temp;
1131
+ }
1132
+ /* Make sure the blob contains two terminating 0-bytes */
1133
+ blob_append(pBlob, "", 1);
1134
+ zUtf8 = blob_str(pBlob) + 2;
1135
+ zUtf8 = fossil_unicode_to_utf8(zUtf8);
1136
+ blob_zero(pBlob);
1137
+ blob_append(pBlob, zUtf8, -1);
1138
+ fossil_mbcs_free(zUtf8);
1139
+ }else if (useMbcs) {
1140
+ zUtf8 = fossil_mbcs_to_utf8(blob_str(pBlob));
1141
+ blob_zero(pBlob);
1142
+ blob_append(pBlob, zUtf8, -1);
1143
+ fossil_mbcs_free(zUtf8);
1144
+#endif /* _WIN32 */
1145
+ }
1146
+}
10891147
--- src/blob.c
+++ src/blob.c
@@ -1084,5 +1084,63 @@
1084 void blob_swap( Blob *pLeft, Blob *pRight ){
1085 Blob swap = *pLeft;
1086 *pLeft = *pRight;
1087 *pRight = swap;
1088 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1089
--- src/blob.c
+++ src/blob.c
@@ -1084,5 +1084,63 @@
1084 void blob_swap( Blob *pLeft, Blob *pRight ){
1085 Blob swap = *pLeft;
1086 *pLeft = *pRight;
1087 *pRight = swap;
1088 }
1089
1090 /*
1091 ** Strip a possible BOM from the blob. On Windows, if there
1092 ** is either no BOM at all or an (le/be) UTF-16 BOM, a conversion
1093 ** to UTF-8 is done.
1094 ** If useMbcs is false and there is no BOM, the input string
1095 ** is assumed to be UTF-8 already, so no conversion is done.
1096 */
1097 void blob_strip_bom(Blob *pBlob, int useMbcs){
1098 static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF };
1099 #ifdef _WIN32
1100 static const unsigned short ubom = 0xfeff;
1101 static const unsigned short urbom = 0xfffe;
1102 #endif /* _WIN32 */
1103 char *zUtf8;
1104 if( blob_size(pBlob)>2 && memcmp(blob_buffer(pBlob), bom, 3)==0 ) {
1105 struct Blob temp;
1106 zUtf8 = blob_str(pBlob) + 3;
1107 blob_zero(&temp);
1108 blob_append(&temp, zUtf8, -1);
1109 fossil_mbcs_free(zUtf8);
1110 blob_swap(pBlob, &temp);
1111 blob_reset(&temp);
1112 #ifdef _WIN32
1113 }else if( blob_size(pBlob)>1 && (blob_size(pBlob)&1)==0
1114 && memcmp(blob_buffer(pBlob), &ubom, 2)==0 ) {
1115 /* Make sure the blob contains two terminating 0-bytes */
1116 blob_append(pBlob, "", 1);
1117 zUtf8 = blob_str(pBlob) + 2;
1118 zUtf8 = fossil_unicode_to_utf8(zUtf8);
1119 blob_zero(pBlob);
1120 blob_append(pBlob, zUtf8, -1);
1121 fossil_mbcs_free(zUtf8);
1122 }else if( blob_size(pBlob)>1 && (blob_size(pBlob)&1)==0
1123 && memcmp(blob_buffer(pBlob), &urbom, 2)==0 ) {
1124 zUtf8 = blob_buffer(pBlob);
1125 unsigned int i = blob_size(pBlob);
1126 while( i > 0 ){
1127 /* swap bytes of unicode representation */
1128 char temp = zUtf8[--i];
1129 zUtf8[i] = zUtf8[i-1];
1130 zUtf8[--i] = temp;
1131 }
1132 /* Make sure the blob contains two terminating 0-bytes */
1133 blob_append(pBlob, "", 1);
1134 zUtf8 = blob_str(pBlob) + 2;
1135 zUtf8 = fossil_unicode_to_utf8(zUtf8);
1136 blob_zero(pBlob);
1137 blob_append(pBlob, zUtf8, -1);
1138 fossil_mbcs_free(zUtf8);
1139 }else if (useMbcs) {
1140 zUtf8 = fossil_mbcs_to_utf8(blob_str(pBlob));
1141 blob_zero(pBlob);
1142 blob_append(pBlob, zUtf8, -1);
1143 fossil_mbcs_free(zUtf8);
1144 #endif /* _WIN32 */
1145 }
1146 }
1147
+2 -51
--- src/checkin.c
+++ src/checkin.c
@@ -517,10 +517,11 @@
517517
break;
518518
}
519519
blob_append(&reply, zIn, -1);
520520
}
521521
}
522
+ blob_strip_bom(&reply, 1);
522523
blob_remove_cr(&reply);
523524
file_delete(zFile);
524525
free(zFile);
525526
blob_zero(pComment);
526527
while( blob_line(&reply, &line) ){
@@ -1183,10 +1184,11 @@
11831184
blob_zero(&comment);
11841185
blob_append(&comment, zComment, -1);
11851186
}else if( zComFile ){
11861187
blob_zero(&comment);
11871188
blob_read_from_file(&comment, zComFile);
1189
+ blob_strip_bom(&comment, 1);
11881190
}else{
11891191
char *zInit = db_text(0, "SELECT value FROM vvar WHERE name='ci-comment'");
11901192
prepare_commit_comment(&comment, zInit, zBranch, vid, zUserOvrd);
11911193
if( zInit && zInit[0] && fossil_strcmp(zInit, blob_str(&comment))==0 ){
11921194
Blob ans;
@@ -1202,61 +1204,10 @@
12021204
prompt_user("empty check-in comment. continue (y/N)? ", &ans);
12031205
if( blob_str(&ans)[0]!='y' ){
12041206
fossil_exit(1);
12051207
}
12061208
}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 */
12581209
db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment);
12591210
db_end_transaction(0);
12601211
db_begin_transaction();
12611212
}
12621213
12631214
--- src/checkin.c
+++ src/checkin.c
@@ -517,10 +517,11 @@
517 break;
518 }
519 blob_append(&reply, zIn, -1);
520 }
521 }
 
522 blob_remove_cr(&reply);
523 file_delete(zFile);
524 free(zFile);
525 blob_zero(pComment);
526 while( blob_line(&reply, &line) ){
@@ -1183,10 +1184,11 @@
1183 blob_zero(&comment);
1184 blob_append(&comment, zComment, -1);
1185 }else if( zComFile ){
1186 blob_zero(&comment);
1187 blob_read_from_file(&comment, zComFile);
 
1188 }else{
1189 char *zInit = db_text(0, "SELECT value FROM vvar WHERE name='ci-comment'");
1190 prepare_commit_comment(&comment, zInit, zBranch, vid, zUserOvrd);
1191 if( zInit && zInit[0] && fossil_strcmp(zInit, blob_str(&comment))==0 ){
1192 Blob ans;
@@ -1202,61 +1204,10 @@
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
--- src/checkin.c
+++ src/checkin.c
@@ -517,10 +517,11 @@
517 break;
518 }
519 blob_append(&reply, zIn, -1);
520 }
521 }
522 blob_strip_bom(&reply, 1);
523 blob_remove_cr(&reply);
524 file_delete(zFile);
525 free(zFile);
526 blob_zero(pComment);
527 while( blob_line(&reply, &line) ){
@@ -1183,10 +1184,11 @@
1184 blob_zero(&comment);
1185 blob_append(&comment, zComment, -1);
1186 }else if( zComFile ){
1187 blob_zero(&comment);
1188 blob_read_from_file(&comment, zComFile);
1189 blob_strip_bom(&comment, 1);
1190 }else{
1191 char *zInit = db_text(0, "SELECT value FROM vvar WHERE name='ci-comment'");
1192 prepare_commit_comment(&comment, zInit, zBranch, vid, zUserOvrd);
1193 if( zInit && zInit[0] && fossil_strcmp(zInit, blob_str(&comment))==0 ){
1194 Blob ans;
@@ -1202,61 +1204,10 @@
1204 prompt_user("empty check-in comment. continue (y/N)? ", &ans);
1205 if( blob_str(&ans)[0]!='y' ){
1206 fossil_exit(1);
1207 }
1208 }else{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1209 db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment);
1210 db_end_transaction(0);
1211 db_begin_transaction();
1212 }
1213
1214
--- src/stash.c
+++ src/stash.c
@@ -158,11 +158,16 @@
158158
zComment = find_option("comment", "m", 1);
159159
verify_all_options();
160160
if( zComment==0 ){
161161
Blob prompt; /* Prompt for stash comment */
162162
Blob comment; /* User comment reply */
163
+#ifdef _WIN32
164
+ static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF };
165
+ blob_init(&prompt, (const char *) bom, 3);
166
+#else
163167
blob_zero(&prompt);
168
+#endif
164169
blob_append(&prompt,
165170
"\n"
166171
"# Enter a description of what is being stashed. Lines beginning\n"
167172
"# with \"#\" are ignored. Stash comments are plain text except.\n"
168173
"# newlines are not preserved.\n",
169174
--- src/stash.c
+++ src/stash.c
@@ -158,11 +158,16 @@
158 zComment = find_option("comment", "m", 1);
159 verify_all_options();
160 if( zComment==0 ){
161 Blob prompt; /* Prompt for stash comment */
162 Blob comment; /* User comment reply */
 
 
 
 
163 blob_zero(&prompt);
 
164 blob_append(&prompt,
165 "\n"
166 "# Enter a description of what is being stashed. Lines beginning\n"
167 "# with \"#\" are ignored. Stash comments are plain text except.\n"
168 "# newlines are not preserved.\n",
169
--- src/stash.c
+++ src/stash.c
@@ -158,11 +158,16 @@
158 zComment = find_option("comment", "m", 1);
159 verify_all_options();
160 if( zComment==0 ){
161 Blob prompt; /* Prompt for stash comment */
162 Blob comment; /* User comment reply */
163 #ifdef _WIN32
164 static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF };
165 blob_init(&prompt, (const char *) bom, 3);
166 #else
167 blob_zero(&prompt);
168 #endif
169 blob_append(&prompt,
170 "\n"
171 "# Enter a description of what is being stashed. Lines beginning\n"
172 "# with \"#\" are ignored. Stash comments are plain text except.\n"
173 "# newlines are not preserved.\n",
174

Keyboard Shortcuts

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