Fossil SCM

Warn during add, addremove and stash if there are filename that are equal after Unicode case folding, eg Ärger.txt and ärger.txt. Also prevent "fossil mv ä.txt Ä.txt". From libfossil Unicode work.

danshearer 2026-11-16 11:57 UTC unicode-fixes
Commit 3155374b8969527880e5ca3a0e2a2b9b6f28ce1ea9a945b8fb783c4025090fa2
+5 -1
--- src/add.c
+++ src/add.c
@@ -241,10 +241,11 @@
241241
}
242242
nAdd += add_one_file(zToAdd, vid);
243243
}
244244
db_finalize(&loop);
245245
blob_reset(&repoName);
246
+ if( nAdd ) vfile_warn_case_collisions(vid);
246247
return nAdd;
247248
}
248249
249250
/*
250251
** Resets the ADDED/DELETED state of a check-out, such that all
@@ -915,11 +916,14 @@
915916
fossil_fatal("cannot rename '%s' to '%s' since the delete of '%s' has "
916917
"not yet been committed", zOrig, zNew, zNew);
917918
}
918919
}
919920
if( moveFiles ){
920
- if( file_size(zNew, ExtFILE) != -1 ){
921
+ if( file_size(zNew, ExtFILE) != -1
922
+ && (filenames_are_case_sensitive()
923
+ || fossil_unicode_stricmp(zOrig, zNew)!=0)
924
+ ){
921925
fossil_fatal("cannot rename '%s' to '%s' on disk since another file"
922926
" named '%s' already exists", zOrig, zNew, zNew);
923927
}
924928
}
925929
fossil_print("RENAME %s %s\n", zOrig, zNew);
926930
--- src/add.c
+++ src/add.c
@@ -241,10 +241,11 @@
241 }
242 nAdd += add_one_file(zToAdd, vid);
243 }
244 db_finalize(&loop);
245 blob_reset(&repoName);
 
246 return nAdd;
247 }
248
249 /*
250 ** Resets the ADDED/DELETED state of a check-out, such that all
@@ -915,11 +916,14 @@
915 fossil_fatal("cannot rename '%s' to '%s' since the delete of '%s' has "
916 "not yet been committed", zOrig, zNew, zNew);
917 }
918 }
919 if( moveFiles ){
920 if( file_size(zNew, ExtFILE) != -1 ){
 
 
 
921 fossil_fatal("cannot rename '%s' to '%s' on disk since another file"
922 " named '%s' already exists", zOrig, zNew, zNew);
923 }
924 }
925 fossil_print("RENAME %s %s\n", zOrig, zNew);
926
--- src/add.c
+++ src/add.c
@@ -241,10 +241,11 @@
241 }
242 nAdd += add_one_file(zToAdd, vid);
243 }
244 db_finalize(&loop);
245 blob_reset(&repoName);
246 if( nAdd ) vfile_warn_case_collisions(vid);
247 return nAdd;
248 }
249
250 /*
251 ** Resets the ADDED/DELETED state of a check-out, such that all
@@ -915,11 +916,14 @@
916 fossil_fatal("cannot rename '%s' to '%s' since the delete of '%s' has "
917 "not yet been committed", zOrig, zNew, zNew);
918 }
919 }
920 if( moveFiles ){
921 if( file_size(zNew, ExtFILE) != -1
922 && (filenames_are_case_sensitive()
923 || fossil_unicode_stricmp(zOrig, zNew)!=0)
924 ){
925 fossil_fatal("cannot rename '%s' to '%s' on disk since another file"
926 " named '%s' already exists", zOrig, zNew, zNew);
927 }
928 }
929 fossil_print("RENAME %s %s\n", zOrig, zNew);
930
+3
--- src/db.c
+++ src/db.c
@@ -1642,10 +1642,13 @@
16421642
sqlite3_create_function(db, "url_nouser", 1, SQLITE_UTF8, 0,
16431643
url_nouser_func,0,0);
16441644
sqlite3_create_function(db, "chat_msg_from_event", 4,
16451645
SQLITE_UTF8 | SQLITE_INNOCUOUS, 0,
16461646
chat_msg_from_event, 0, 0);
1647
+ sqlite3_create_function(db, "unicode_casefold", 1,
1648
+ SQLITE_UTF8|SQLITE_DETERMINISTIC, 0,
1649
+ unicode_casefold_sqlfunc,0,0);
16471650
sqlite3_create_function(db, "inode", 1, SQLITE_UTF8, 0,
16481651
file_inode_sql_func,0,0);
16491652
sqlite3_create_function(db, "artifact_to_json", 1, SQLITE_UTF8, 0,
16501653
artifact_to_json_sql_func,0,0);
16511654
sqlite3_create_function(db, "unicode_contains", 2,
16521655
--- src/db.c
+++ src/db.c
@@ -1642,10 +1642,13 @@
1642 sqlite3_create_function(db, "url_nouser", 1, SQLITE_UTF8, 0,
1643 url_nouser_func,0,0);
1644 sqlite3_create_function(db, "chat_msg_from_event", 4,
1645 SQLITE_UTF8 | SQLITE_INNOCUOUS, 0,
1646 chat_msg_from_event, 0, 0);
 
 
 
1647 sqlite3_create_function(db, "inode", 1, SQLITE_UTF8, 0,
1648 file_inode_sql_func,0,0);
1649 sqlite3_create_function(db, "artifact_to_json", 1, SQLITE_UTF8, 0,
1650 artifact_to_json_sql_func,0,0);
1651 sqlite3_create_function(db, "unicode_contains", 2,
1652
--- src/db.c
+++ src/db.c
@@ -1642,10 +1642,13 @@
1642 sqlite3_create_function(db, "url_nouser", 1, SQLITE_UTF8, 0,
1643 url_nouser_func,0,0);
1644 sqlite3_create_function(db, "chat_msg_from_event", 4,
1645 SQLITE_UTF8 | SQLITE_INNOCUOUS, 0,
1646 chat_msg_from_event, 0, 0);
1647 sqlite3_create_function(db, "unicode_casefold", 1,
1648 SQLITE_UTF8|SQLITE_DETERMINISTIC, 0,
1649 unicode_casefold_sqlfunc,0,0);
1650 sqlite3_create_function(db, "inode", 1, SQLITE_UTF8, 0,
1651 file_inode_sql_func,0,0);
1652 sqlite3_create_function(db, "artifact_to_json", 1, SQLITE_UTF8, 0,
1653 artifact_to_json_sql_func,0,0);
1654 sqlite3_create_function(db, "unicode_contains", 2,
1655
+49
--- src/file.c
+++ src/file.c
@@ -1161,10 +1161,59 @@
11611161
if( z[2]=='.' && (z[3]=='/' || z[3]==0) ) return 0;
11621162
}
11631163
}
11641164
return 1;
11651165
}
1166
+
1167
+/*
1168
+** Compare two filenames, ignoring case with Unicode case folding.
1169
+** Return 0 if they are equal.
1170
+**
1171
+** Fossil's case-insensitive filename handling (filename_collation())
1172
+** folds only the ASCII letters A to Z. NTFS and APFS fold letters in
1173
+** all cased scripts, so names such as "Ärger.txt" and "ärger.txt"
1174
+** are different to Fossil but the same file on those systems.
1175
+** Folding tables differ from each other and also from Unicode, so
1176
+** so this comparison is more of a guide than conforming to any single
1177
+** standard.
1178
+*/
1179
+int fossil_unicode_stricmp(const char *zA, const char *zB){
1180
+ const unsigned char *a = (const unsigned char*)zA;
1181
+ const unsigned char *b = (const unsigned char*)zB;
1182
+ while( *a && *b ){
1183
+ u32 ca = fossil_utf8_read(&a);
1184
+ u32 cb = fossil_utf8_read(&b);
1185
+ if( ca!=cb ){
1186
+ int fa = unicode_fold((int)ca, 0);
1187
+ int fb = unicode_fold((int)cb, 0);
1188
+ if( fa!=fb ) return fa<fb ? -1 : 1;
1189
+ }
1190
+ }
1191
+ return (*a!=0) - (*b!=0);
1192
+}
1193
+
1194
+/*
1195
+** Implementation of the SQL function unicode_casefold(TEXT). It returns
1196
+** a BLOB of the code points of TEXT after Unicode case folding, so two
1197
+** filenames that differ only in letter case give equal results. The
1198
+** result is for comparison purpose only.
1199
+*/
1200
+void unicode_casefold_sqlfunc(
1201
+ sqlite3_context *context,
1202
+ int argc,
1203
+ sqlite3_value **argv
1204
+){
1205
+ const unsigned char *z = sqlite3_value_text(argv[0]);
1206
+ u32 *a;
1207
+ int n = 0;
1208
+ if( z==0 ) return;
1209
+ a = fossil_malloc( (sqlite3_value_bytes(argv[0])+1)*sizeof(u32) );
1210
+ while( *z ){
1211
+ a[n++] = (u32)unicode_fold((int)fossil_utf8_read(&z), 0);
1212
+ }
1213
+ sqlite3_result_blob(context, a, n*(int)sizeof(u32), fossil_free);
1214
+}
11661215
11671216
/*
11681217
** If the last component of the pathname in z[0]..z[j-1] is something
11691218
** other than ".." then back it out and return true. If the last
11701219
** component is empty or if it is ".." then return false.
11711220
--- src/file.c
+++ src/file.c
@@ -1161,10 +1161,59 @@
1161 if( z[2]=='.' && (z[3]=='/' || z[3]==0) ) return 0;
1162 }
1163 }
1164 return 1;
1165 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1166
1167 /*
1168 ** If the last component of the pathname in z[0]..z[j-1] is something
1169 ** other than ".." then back it out and return true. If the last
1170 ** component is empty or if it is ".." then return false.
1171
--- src/file.c
+++ src/file.c
@@ -1161,10 +1161,59 @@
1161 if( z[2]=='.' && (z[3]=='/' || z[3]==0) ) return 0;
1162 }
1163 }
1164 return 1;
1165 }
1166
1167 /*
1168 ** Compare two filenames, ignoring case with Unicode case folding.
1169 ** Return 0 if they are equal.
1170 **
1171 ** Fossil's case-insensitive filename handling (filename_collation())
1172 ** folds only the ASCII letters A to Z. NTFS and APFS fold letters in
1173 ** all cased scripts, so names such as "Ärger.txt" and "ärger.txt"
1174 ** are different to Fossil but the same file on those systems.
1175 ** Folding tables differ from each other and also from Unicode, so
1176 ** so this comparison is more of a guide than conforming to any single
1177 ** standard.
1178 */
1179 int fossil_unicode_stricmp(const char *zA, const char *zB){
1180 const unsigned char *a = (const unsigned char*)zA;
1181 const unsigned char *b = (const unsigned char*)zB;
1182 while( *a && *b ){
1183 u32 ca = fossil_utf8_read(&a);
1184 u32 cb = fossil_utf8_read(&b);
1185 if( ca!=cb ){
1186 int fa = unicode_fold((int)ca, 0);
1187 int fb = unicode_fold((int)cb, 0);
1188 if( fa!=fb ) return fa<fb ? -1 : 1;
1189 }
1190 }
1191 return (*a!=0) - (*b!=0);
1192 }
1193
1194 /*
1195 ** Implementation of the SQL function unicode_casefold(TEXT). It returns
1196 ** a BLOB of the code points of TEXT after Unicode case folding, so two
1197 ** filenames that differ only in letter case give equal results. The
1198 ** result is for comparison purpose only.
1199 */
1200 void unicode_casefold_sqlfunc(
1201 sqlite3_context *context,
1202 int argc,
1203 sqlite3_value **argv
1204 ){
1205 const unsigned char *z = sqlite3_value_text(argv[0]);
1206 u32 *a;
1207 int n = 0;
1208 if( z==0 ) return;
1209 a = fossil_malloc( (sqlite3_value_bytes(argv[0])+1)*sizeof(u32) );
1210 while( *z ){
1211 a[n++] = (u32)unicode_fold((int)fossil_utf8_read(&z), 0);
1212 }
1213 sqlite3_result_blob(context, a, n*(int)sizeof(u32), fossil_free);
1214 }
1215
1216 /*
1217 ** If the last component of the pathname in z[0]..z[j-1] is something
1218 ** other than ".." then back it out and return true. If the last
1219 ** component is empty or if it is ".." then return false.
1220
+22
--- src/vfile.c
+++ src/vfile.c
@@ -280,10 +280,32 @@
280280
}
281281
db_finalize(&q);
282282
if( nErr ) fossil_fatal("abort due to prior errors");
283283
db_end_transaction(0);
284284
}
285
+
286
+/*
287
+** Warn about files in check-out vid whose names differ only in letter
288
+** case, using Unicode case folding. On Windows, macOS and other
289
+** systems with case-insensitive filenames, a check-out can hold only
290
+** one file of each group.
291
+*/
292
+void vfile_warn_case_collisions(int vid){
293
+ Stmt q;
294
+ db_prepare(&q,
295
+ "SELECT group_concat(pathname, ', ') FROM ("
296
+ " SELECT pathname, unicode_casefold(pathname) AS k FROM vfile"
297
+ " WHERE vid=%d AND NOT deleted ORDER BY pathname)"
298
+ " GROUP BY k HAVING count(*)>1", vid);
299
+ while( db_step(&q)==SQLITE_ROW ){
300
+ fossil_warning("WARNING: these filenames differ only in letter case,"
301
+ " so a check-out on a case-insensitive file system"
302
+ " can hold only one of them: %s",
303
+ db_column_text(&q, 0));
304
+ }
305
+ db_finalize(&q);
306
+}
285307
286308
/*
287309
** For a case-insenstive checkout, abort if two pathnames we are about
288310
** to write differ only letter case. These would be just one file on
289311
** disk so one will otherwise get overwritten.
290312
--- src/vfile.c
+++ src/vfile.c
@@ -280,10 +280,32 @@
280 }
281 db_finalize(&q);
282 if( nErr ) fossil_fatal("abort due to prior errors");
283 db_end_transaction(0);
284 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
286 /*
287 ** For a case-insenstive checkout, abort if two pathnames we are about
288 ** to write differ only letter case. These would be just one file on
289 ** disk so one will otherwise get overwritten.
290
--- src/vfile.c
+++ src/vfile.c
@@ -280,10 +280,32 @@
280 }
281 db_finalize(&q);
282 if( nErr ) fossil_fatal("abort due to prior errors");
283 db_end_transaction(0);
284 }
285
286 /*
287 ** Warn about files in check-out vid whose names differ only in letter
288 ** case, using Unicode case folding. On Windows, macOS and other
289 ** systems with case-insensitive filenames, a check-out can hold only
290 ** one file of each group.
291 */
292 void vfile_warn_case_collisions(int vid){
293 Stmt q;
294 db_prepare(&q,
295 "SELECT group_concat(pathname, ', ') FROM ("
296 " SELECT pathname, unicode_casefold(pathname) AS k FROM vfile"
297 " WHERE vid=%d AND NOT deleted ORDER BY pathname)"
298 " GROUP BY k HAVING count(*)>1", vid);
299 while( db_step(&q)==SQLITE_ROW ){
300 fossil_warning("WARNING: these filenames differ only in letter case,"
301 " so a check-out on a case-insensitive file system"
302 " can hold only one of them: %s",
303 db_column_text(&q, 0));
304 }
305 db_finalize(&q);
306 }
307
308 /*
309 ** For a case-insenstive checkout, abort if two pathnames we are about
310 ** to write differ only letter case. These would be just one file on
311 ** disk so one will otherwise get overwritten.
312

Keyboard Shortcuts

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