Fossil SCM

Use file_tree_name(), not file_canonical_name(), as in Richard's example [c8253f4066] for "fossil ls|changes|status" too. Advantage: 1) a panic when an out-of-tree filename is given on the command line 2) shortcut when any command line argument is "." (or resolves to the top of the tree in any other way)

jan.nijtmans 2013-06-24 08:27 trunk
Commit ae0124439685c1102a904ce08d08afc23e062db3
1 file changed +25 -21
+25 -21
--- src/checkin.c
+++ src/checkin.c
@@ -40,25 +40,27 @@
4040
Stmt q;
4141
int nPrefix = strlen(zPrefix);
4242
int nErr = 0;
4343
Blob rewrittenPathname;
4444
Blob where;
45
- const char *zTreeName;
46
- int i, nRoot;
45
+ const char *zName;
46
+ int i;
4747
4848
blob_zero(&where);
49
- nRoot = (int)strlen(g.zLocalRoot);
50
- blob_zero(&where);
5149
for(i=2; i<g.argc; i++) {
5250
Blob fname;
53
- file_canonical_name(g.argv[i], &fname, 0);
54
- zTreeName = blob_str(&fname)+nRoot;
51
+ file_tree_name(g.argv[i], &fname, 1);
52
+ zName = blob_str(&fname);
53
+ if( fossil_strcmp(zName, ".")==0 ) {
54
+ blob_reset(&where);
55
+ break;
56
+ }
5557
blob_appendf(&where, " %s (pathname=%Q %s) "
5658
"OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
57
- (blob_size(&where)>0) ? "OR" : "AND", zTreeName,
58
- filename_collation(), zTreeName, filename_collation(),
59
- zTreeName, filename_collation());
59
+ (blob_size(&where)>0) ? "OR" : "AND", zName,
60
+ filename_collation(), zName, filename_collation(),
61
+ zName, filename_collation());
6062
}
6163
6264
db_prepare(&q,
6365
"SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)"
6466
" FROM vfile "
@@ -258,11 +260,11 @@
258260
int verboseFlag;
259261
int showAge;
260262
char *zOrderBy = "pathname";
261263
Blob where;
262264
int i;
263
- int nRoot;
265
+ const char *zName;
264266
265267
verboseFlag = find_option("verbose","v", 0)!=0;
266268
if( !verboseFlag ){
267269
verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
268270
}
@@ -276,21 +278,23 @@
276278
zOrderBy = "mtime DESC";
277279
}
278280
}
279281
verify_all_options();
280282
blob_zero(&where);
281
- nRoot = (int)strlen(g.zLocalRoot);
282283
for(i=2; i<g.argc; i++){
283284
Blob fname;
284
- const char *zTreeName;
285
- file_canonical_name(g.argv[i], &fname, 0);
286
- zTreeName = blob_str(&fname)+nRoot;
285
+ file_tree_name(g.argv[i], &fname, 1);
286
+ zName = blob_str(&fname);
287
+ if( fossil_strcmp(zName, ".")==0 ) {
288
+ blob_reset(&where);
289
+ break;
290
+ }
287291
blob_appendf(&where, " %s (pathname=%Q %s) "
288292
"OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
289
- (blob_size(&where)>0) ? "OR" : "WHERE", zTreeName,
290
- filename_collation(), zTreeName, filename_collation(),
291
- zTreeName, filename_collation());
293
+ (blob_size(&where)>0) ? "OR" : "WHERE", zName,
294
+ filename_collation(), zName, filename_collation(),
295
+ zName, filename_collation());
292296
}
293297
vfile_check_signature(vid, 0);
294298
if( showAge ){
295299
db_prepare(&q,
296300
"SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0),"
@@ -338,12 +342,12 @@
338342
}
339343
db_finalize(&q);
340344
}
341345
342346
/*
343
-** Create a TEMP table named SFILE and add all unmanaged files named on the command-line
344
-** to that table. If directories are named, then add all unmanged files contained
347
+** Create a TEMP table named SFILE and add all unmanaged files named on the command-line
348
+** to that table. If directories are named, then add all unmanaged files contained
345349
** underneath those directories. If there are no files or directories named on the
346350
** command-line, then add all unmanaged files anywhere in the checkout.
347351
*/
348352
static void locate_unmanaged_files(
349353
int argc, /* Number of command-line arguments to examine */
@@ -371,13 +375,13 @@
371375
zName = blob_str(&name);
372376
isDir = file_wd_isdir(zName);
373377
if( isDir==1 ){
374378
vfile_scan(&name, nRoot-1, scanFlags, pIgnore1, pIgnore2);
375379
}else if( isDir==0 ){
376
- fossil_warning("not found: %s", zName);
380
+ fossil_warning("not found: %s", &zName[nRoot]);
377381
}else if( file_access(zName, R_OK) ){
378
- fossil_fatal("cannot open %s", zName);
382
+ fossil_fatal("cannot open %s", &zName[nRoot]);
379383
}else{
380384
db_multi_exec(
381385
"INSERT OR IGNORE INTO sfile(x) VALUES(%Q)",
382386
&zName[nRoot]
383387
);
384388
--- src/checkin.c
+++ src/checkin.c
@@ -40,25 +40,27 @@
40 Stmt q;
41 int nPrefix = strlen(zPrefix);
42 int nErr = 0;
43 Blob rewrittenPathname;
44 Blob where;
45 const char *zTreeName;
46 int i, nRoot;
47
48 blob_zero(&where);
49 nRoot = (int)strlen(g.zLocalRoot);
50 blob_zero(&where);
51 for(i=2; i<g.argc; i++) {
52 Blob fname;
53 file_canonical_name(g.argv[i], &fname, 0);
54 zTreeName = blob_str(&fname)+nRoot;
 
 
 
 
55 blob_appendf(&where, " %s (pathname=%Q %s) "
56 "OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
57 (blob_size(&where)>0) ? "OR" : "AND", zTreeName,
58 filename_collation(), zTreeName, filename_collation(),
59 zTreeName, filename_collation());
60 }
61
62 db_prepare(&q,
63 "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)"
64 " FROM vfile "
@@ -258,11 +260,11 @@
258 int verboseFlag;
259 int showAge;
260 char *zOrderBy = "pathname";
261 Blob where;
262 int i;
263 int nRoot;
264
265 verboseFlag = find_option("verbose","v", 0)!=0;
266 if( !verboseFlag ){
267 verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
268 }
@@ -276,21 +278,23 @@
276 zOrderBy = "mtime DESC";
277 }
278 }
279 verify_all_options();
280 blob_zero(&where);
281 nRoot = (int)strlen(g.zLocalRoot);
282 for(i=2; i<g.argc; i++){
283 Blob fname;
284 const char *zTreeName;
285 file_canonical_name(g.argv[i], &fname, 0);
286 zTreeName = blob_str(&fname)+nRoot;
 
 
 
287 blob_appendf(&where, " %s (pathname=%Q %s) "
288 "OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
289 (blob_size(&where)>0) ? "OR" : "WHERE", zTreeName,
290 filename_collation(), zTreeName, filename_collation(),
291 zTreeName, filename_collation());
292 }
293 vfile_check_signature(vid, 0);
294 if( showAge ){
295 db_prepare(&q,
296 "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0),"
@@ -338,12 +342,12 @@
338 }
339 db_finalize(&q);
340 }
341
342 /*
343 ** Create a TEMP table named SFILE and add all unmanaged files named on the command-line
344 ** to that table. If directories are named, then add all unmanged files contained
345 ** underneath those directories. If there are no files or directories named on the
346 ** command-line, then add all unmanaged files anywhere in the checkout.
347 */
348 static void locate_unmanaged_files(
349 int argc, /* Number of command-line arguments to examine */
@@ -371,13 +375,13 @@
371 zName = blob_str(&name);
372 isDir = file_wd_isdir(zName);
373 if( isDir==1 ){
374 vfile_scan(&name, nRoot-1, scanFlags, pIgnore1, pIgnore2);
375 }else if( isDir==0 ){
376 fossil_warning("not found: %s", zName);
377 }else if( file_access(zName, R_OK) ){
378 fossil_fatal("cannot open %s", zName);
379 }else{
380 db_multi_exec(
381 "INSERT OR IGNORE INTO sfile(x) VALUES(%Q)",
382 &zName[nRoot]
383 );
384
--- src/checkin.c
+++ src/checkin.c
@@ -40,25 +40,27 @@
40 Stmt q;
41 int nPrefix = strlen(zPrefix);
42 int nErr = 0;
43 Blob rewrittenPathname;
44 Blob where;
45 const char *zName;
46 int i;
47
48 blob_zero(&where);
 
 
49 for(i=2; i<g.argc; i++) {
50 Blob fname;
51 file_tree_name(g.argv[i], &fname, 1);
52 zName = blob_str(&fname);
53 if( fossil_strcmp(zName, ".")==0 ) {
54 blob_reset(&where);
55 break;
56 }
57 blob_appendf(&where, " %s (pathname=%Q %s) "
58 "OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
59 (blob_size(&where)>0) ? "OR" : "AND", zName,
60 filename_collation(), zName, filename_collation(),
61 zName, filename_collation());
62 }
63
64 db_prepare(&q,
65 "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)"
66 " FROM vfile "
@@ -258,11 +260,11 @@
260 int verboseFlag;
261 int showAge;
262 char *zOrderBy = "pathname";
263 Blob where;
264 int i;
265 const char *zName;
266
267 verboseFlag = find_option("verbose","v", 0)!=0;
268 if( !verboseFlag ){
269 verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
270 }
@@ -276,21 +278,23 @@
278 zOrderBy = "mtime DESC";
279 }
280 }
281 verify_all_options();
282 blob_zero(&where);
 
283 for(i=2; i<g.argc; i++){
284 Blob fname;
285 file_tree_name(g.argv[i], &fname, 1);
286 zName = blob_str(&fname);
287 if( fossil_strcmp(zName, ".")==0 ) {
288 blob_reset(&where);
289 break;
290 }
291 blob_appendf(&where, " %s (pathname=%Q %s) "
292 "OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
293 (blob_size(&where)>0) ? "OR" : "WHERE", zName,
294 filename_collation(), zName, filename_collation(),
295 zName, filename_collation());
296 }
297 vfile_check_signature(vid, 0);
298 if( showAge ){
299 db_prepare(&q,
300 "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0),"
@@ -338,12 +342,12 @@
342 }
343 db_finalize(&q);
344 }
345
346 /*
347 ** Create a TEMP table named SFILE and add all unmanaged files named on the command-line
348 ** to that table. If directories are named, then add all unmanaged files contained
349 ** underneath those directories. If there are no files or directories named on the
350 ** command-line, then add all unmanaged files anywhere in the checkout.
351 */
352 static void locate_unmanaged_files(
353 int argc, /* Number of command-line arguments to examine */
@@ -371,13 +375,13 @@
375 zName = blob_str(&name);
376 isDir = file_wd_isdir(zName);
377 if( isDir==1 ){
378 vfile_scan(&name, nRoot-1, scanFlags, pIgnore1, pIgnore2);
379 }else if( isDir==0 ){
380 fossil_warning("not found: %s", &zName[nRoot]);
381 }else if( file_access(zName, R_OK) ){
382 fossil_fatal("cannot open %s", &zName[nRoot]);
383 }else{
384 db_multi_exec(
385 "INSERT OR IGNORE INTO sfile(x) VALUES(%Q)",
386 &zName[nRoot]
387 );
388

Keyboard Shortcuts

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