Fossil SCM

Simplify vfile_dir_scan and make sure nested calls do not alter the path added to the dscan_temp table.

mistachkin 2013-09-30 13:30 UTC cleanEmptyDirs
Commit 4f2bad8396b3b83387575aaca34f0a77d9d746b4
1 file changed +4 -7
+4 -7
--- src/vfile.c
+++ src/vfile.c
@@ -563,11 +563,11 @@
563563
" x TEXT PRIMARY KEY %s, y INTEGER)",
564564
filename_collation());
565565
db_prepare(&ins,
566566
"INSERT OR IGNORE INTO dscan_temp(x, y) SELECT :file, :count"
567567
" WHERE NOT EXISTS(SELECT 1 FROM vfile WHERE"
568
- " pathname GLOB :pattern %s)", filename_collation()
568
+ " pathname GLOB :file || '/*' %s)", filename_collation()
569569
);
570570
db_prepare(&upd,
571571
"UPDATE OR IGNORE dscan_temp SET y = coalesce(y, 0) + 1"
572572
" WHERE x=:file %s",
573573
filename_collation()
@@ -595,21 +595,18 @@
595595
glob_match(pIgnore2, &zPath[nPrefix+1]) ||
596596
glob_match(pIgnore3, &zPath[nPrefix+1]) ){
597597
/* do nothing */
598598
}else if( file_wd_isdir(zPath)==1 ){
599599
if( (scanFlags & SCAN_NESTED) || !vfile_top_of_checkout(zPath) ){
600
- Blob dirPattern;
600
+ char *zSavePath = mprintf("%s", zPath);
601601
int count = vfile_dir_scan(pPath, nPrefix, scanFlags, pIgnore1,
602602
pIgnore2, pIgnore3);
603
- blob_init(&dirPattern, &zPath[nPrefix+1], -1);
604
- blob_appendf(&dirPattern, "*");
605
- db_bind_text(&ins, ":file", &zPath[nPrefix+1]);
603
+ db_bind_text(&ins, ":file", &zSavePath[nPrefix+1]);
606604
db_bind_int(&ins, ":count", count);
607
- db_bind_text(&ins, ":pattern", blob_str(&dirPattern));
608605
db_step(&ins);
609606
db_reset(&ins);
610
- blob_reset(&dirPattern);
607
+ fossil_free(zSavePath);
611608
result += count; /* found X normal files? */
612609
}
613610
}else if( file_wd_isfile_or_link(zPath) ){
614611
db_bind_text(&upd, ":file", zOrigPath);
615612
db_step(&upd);
616613
--- src/vfile.c
+++ src/vfile.c
@@ -563,11 +563,11 @@
563 " x TEXT PRIMARY KEY %s, y INTEGER)",
564 filename_collation());
565 db_prepare(&ins,
566 "INSERT OR IGNORE INTO dscan_temp(x, y) SELECT :file, :count"
567 " WHERE NOT EXISTS(SELECT 1 FROM vfile WHERE"
568 " pathname GLOB :pattern %s)", filename_collation()
569 );
570 db_prepare(&upd,
571 "UPDATE OR IGNORE dscan_temp SET y = coalesce(y, 0) + 1"
572 " WHERE x=:file %s",
573 filename_collation()
@@ -595,21 +595,18 @@
595 glob_match(pIgnore2, &zPath[nPrefix+1]) ||
596 glob_match(pIgnore3, &zPath[nPrefix+1]) ){
597 /* do nothing */
598 }else if( file_wd_isdir(zPath)==1 ){
599 if( (scanFlags & SCAN_NESTED) || !vfile_top_of_checkout(zPath) ){
600 Blob dirPattern;
601 int count = vfile_dir_scan(pPath, nPrefix, scanFlags, pIgnore1,
602 pIgnore2, pIgnore3);
603 blob_init(&dirPattern, &zPath[nPrefix+1], -1);
604 blob_appendf(&dirPattern, "*");
605 db_bind_text(&ins, ":file", &zPath[nPrefix+1]);
606 db_bind_int(&ins, ":count", count);
607 db_bind_text(&ins, ":pattern", blob_str(&dirPattern));
608 db_step(&ins);
609 db_reset(&ins);
610 blob_reset(&dirPattern);
611 result += count; /* found X normal files? */
612 }
613 }else if( file_wd_isfile_or_link(zPath) ){
614 db_bind_text(&upd, ":file", zOrigPath);
615 db_step(&upd);
616
--- src/vfile.c
+++ src/vfile.c
@@ -563,11 +563,11 @@
563 " x TEXT PRIMARY KEY %s, y INTEGER)",
564 filename_collation());
565 db_prepare(&ins,
566 "INSERT OR IGNORE INTO dscan_temp(x, y) SELECT :file, :count"
567 " WHERE NOT EXISTS(SELECT 1 FROM vfile WHERE"
568 " pathname GLOB :file || '/*' %s)", filename_collation()
569 );
570 db_prepare(&upd,
571 "UPDATE OR IGNORE dscan_temp SET y = coalesce(y, 0) + 1"
572 " WHERE x=:file %s",
573 filename_collation()
@@ -595,21 +595,18 @@
595 glob_match(pIgnore2, &zPath[nPrefix+1]) ||
596 glob_match(pIgnore3, &zPath[nPrefix+1]) ){
597 /* do nothing */
598 }else if( file_wd_isdir(zPath)==1 ){
599 if( (scanFlags & SCAN_NESTED) || !vfile_top_of_checkout(zPath) ){
600 char *zSavePath = mprintf("%s", zPath);
601 int count = vfile_dir_scan(pPath, nPrefix, scanFlags, pIgnore1,
602 pIgnore2, pIgnore3);
603 db_bind_text(&ins, ":file", &zSavePath[nPrefix+1]);
 
 
604 db_bind_int(&ins, ":count", count);
 
605 db_step(&ins);
606 db_reset(&ins);
607 fossil_free(zSavePath);
608 result += count; /* found X normal files? */
609 }
610 }else if( file_wd_isfile_or_link(zPath) ){
611 db_bind_text(&upd, ":file", zOrigPath);
612 db_step(&upd);
613

Keyboard Shortcuts

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