Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Refactoring the directory scanning code used by recursive add, extra, and clean. Seems to work but needs more testing prior to folding into trunk. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | experimental |
| Files: | files | file ages | folders |
| SHA1: |
f60f56025c7f6e1407100a46ac5c97ca |
| User & Date: | drh 2011-04-14 18:09:30.139 |
Context
|
2011-04-14
| ||
| 22:41 | Refactoring the "add", "del", and "addremove" commands. ... (check-in: 2b95102592 user: drh tags: experimental) | |
| 18:09 | Refactoring the directory scanning code used by recursive add, extra, and clean. Seems to work but needs more testing prior to folding into trunk. ... (check-in: f60f56025c user: drh tags: experimental) | |
| 14:23 | Factor the glob-pattern matching logic into a separate module. ... (check-in: 289ea2a9b6 user: drh tags: trunk) | |
Changes
Changes to src/add.c.
| ︙ | ︙ | |||
83 84 85 86 87 88 89 |
blob_appendf(&x, "'%s'", z);
}
zAll = blob_str(&x);
}
return zAll;
}
| < < < < < < < < < < < < < < < < < < < < < < < < | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
blob_appendf(&x, "'%s'", z);
}
zAll = blob_str(&x);
}
return zAll;
}
/*
** Add a single file named zName to the VFILE table with vid.
**
** Omit any file whose name is pOmit.
*/
static void add_one_file(
const char *zName, /* Name of file to add */
|
| ︙ | ︙ | |||
158 159 160 161 162 163 164 | } blob_reset(&pathname); } /* ** All content of the zDir directory to the SFILE table. */ | | | | | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
}
blob_reset(&pathname);
}
/*
** All content of the zDir directory to the SFILE table.
*/
void add_directory_content(const char *zDir, Glob *pIgnore){
DIR *d;
int origSize;
struct dirent *pEntry;
Blob path;
blob_zero(&path);
blob_append(&path, zDir, -1);
origSize = blob_size(&path);
d = opendir(zDir);
if( d ){
while( (pEntry=readdir(d))!=0 ){
char *zPath;
if( pEntry->d_name[0]=='.' ){
if( !includeDotFiles ) continue;
if( pEntry->d_name[1]==0 ) continue;
if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
}
blob_appendf(&path, "/%s", pEntry->d_name);
zPath = blob_str(&path);
if( glob_match(pIgnore, zPath) ){
/* Noop */
}else if( file_isdir(zPath)==1 ){
add_directory_content(zPath, pIgnore);
}else if( file_isfile(zPath) ){
db_multi_exec("INSERT INTO sfile VALUES(%Q)", zPath);
}
blob_resize(&path, origSize);
}
closedir(d);
}
blob_reset(&path);
}
/*
** Add all content of a directory.
*/
void add_directory(const char *zDir, int vid, Blob *pOmit, Glob *pIgnore){
Stmt q;
add_directory_content(zDir, pIgnore);
db_prepare(&q, "SELECT x FROM sfile ORDER BY x");
while( db_step(&q)==SQLITE_ROW ){
const char *zName = db_column_text(&q, 0);
add_one_file(zName, vid, pOmit);
}
|
| ︙ | ︙ | |||
219 220 221 222 223 224 225 | ** Make arrangements to add one or more files or directories to the ** current checkout at the next commit. ** ** When adding files or directories recursively, filenames that begin ** with "." are excluded by default. To include such files, add ** the "--dotfiles" option to the command-line. ** | | > | < < | < | | 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
** Make arrangements to add one or more files or directories to the
** current checkout at the next commit.
**
** When adding files or directories recursively, filenames that begin
** with "." are excluded by default. To include such files, add
** the "--dotfiles" option to the command-line.
**
** The --ignore option is a comma-separate list of glob patterns for files
** to be excluded. Example: '*.o,*.obj,*.exe' If the --ignore option
** does not appear on the command line then the "ignore-glob" setting is
** used.
**
** SUMMARY: fossil add ?OPTIONS? FILE1 ?FILE2 ...?
** Options: --dotfiles, --ignore
*/
void add_cmd(void){
int i;
int vid;
const char *zIgnoreFlag;
Blob repo;
Glob *pIgnore; /* Ignore everything matching this glob pattern */
zIgnoreFlag = find_option("ignore",0,1);
includeDotFiles = find_option("dotfiles",0,0)!=0;
db_must_be_within_tree();
if( zIgnoreFlag==0 ){
zIgnoreFlag = db_get("ignore-glob", 0);
}
|
| ︙ | ︙ | |||
257 258 259 260 261 262 263 |
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
#if defined(_WIN32)
db_multi_exec(
"CREATE INDEX IF NOT EXISTS vfile_pathname "
" ON vfile(pathname COLLATE nocase)"
);
#endif
| < < < < | < | | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
#if defined(_WIN32)
db_multi_exec(
"CREATE INDEX IF NOT EXISTS vfile_pathname "
" ON vfile(pathname COLLATE nocase)"
);
#endif
pIgnore = glob_create(zIgnoreFlag);
for(i=2; i<g.argc; i++){
char *zName;
int isDir;
zName = mprintf("%/", g.argv[i]);
isDir = file_isdir(zName);
if( isDir==1 ){
int sz = strlen(zName);
if( sz>0 && zName[sz-1]=='/' ){ zName[sz-1] = 0; }
add_directory(zName, vid, &repo, pIgnore);
}else if( isDir==0 ){
fossil_fatal("not found: %s", zName);
}else if( access(zName, R_OK) ){
fossil_fatal("cannot open %s", zName);
}else{
add_one_file(zName, vid, &repo);
}
free(zName);
}
glob_free(pIgnore);
db_end_transaction(0);
}
/*
** Unmangage a single file.
*/
|
| ︙ | ︙ | |||
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
int isTest = find_option("test",0,0)!=0;
int n;
Stmt q;
int vid;
Blob repo;
int nAdd = 0;
int nDelete = 0;
db_must_be_within_tree();
if( zIgnoreFlag==0 ){
zIgnoreFlag = db_get("ignore-glob", 0);
}
vid = db_lget_int("checkout",0);
if( vid==0 ){
fossil_panic("no checkout to add to");
}
db_begin_transaction();
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
n = strlen(g.zLocalRoot);
blob_init(&path, g.zLocalRoot, n-1);
/* now we read the complete file structure into a temp table */
| > > | > < | < | 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
int isTest = find_option("test",0,0)!=0;
int n;
Stmt q;
int vid;
Blob repo;
int nAdd = 0;
int nDelete = 0;
Glob *pIgnore;
db_must_be_within_tree();
if( zIgnoreFlag==0 ){
zIgnoreFlag = db_get("ignore-glob", 0);
}
vid = db_lget_int("checkout",0);
if( vid==0 ){
fossil_panic("no checkout to add to");
}
db_begin_transaction();
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
n = strlen(g.zLocalRoot);
blob_init(&path, g.zLocalRoot, n-1);
/* now we read the complete file structure into a temp table */
pIgnore = glob_create(zIgnoreFlag);
vfile_scan(&path, blob_size(&path), allFlag, pIgnore);
glob_free(pIgnore);
if( file_tree_name(g.zRepositoryName, &repo, 0) ){
db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
}
/* step 1: search for extra files */
db_prepare(&q,
"SELECT x, %Q || x FROM sfile"
" WHERE x NOT IN (%s)"
" ORDER BY 1",
g.zLocalRoot,
fossil_all_reserved_names()
);
while( db_step(&q)==SQLITE_ROW ){
add_one_file(db_column_text(&q, 1), vid, 0);
nAdd++;
}
db_finalize(&q);
/* step 2: search for missing files */
|
| ︙ | ︙ |
Changes to src/checkin.c.
| ︙ | ︙ | |||
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
Blob path;
Blob repo;
Stmt q;
int n;
const char *zIgnoreFlag = find_option("ignore",0,1);
int allFlag = find_option("dotfiles",0,0)!=0;
int outputManifest;
db_must_be_within_tree();
outputManifest = db_get_boolean("manifest",0);
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
n = strlen(g.zLocalRoot);
blob_init(&path, g.zLocalRoot, n-1);
if( zIgnoreFlag==0 ){
zIgnoreFlag = db_get("ignore-glob", 0);
}
| > > | > < | < | 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
Blob path;
Blob repo;
Stmt q;
int n;
const char *zIgnoreFlag = find_option("ignore",0,1);
int allFlag = find_option("dotfiles",0,0)!=0;
int outputManifest;
Glob *pIgnore;
db_must_be_within_tree();
outputManifest = db_get_boolean("manifest",0);
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
n = strlen(g.zLocalRoot);
blob_init(&path, g.zLocalRoot, n-1);
if( zIgnoreFlag==0 ){
zIgnoreFlag = db_get("ignore-glob", 0);
}
pIgnore = glob_create(zIgnoreFlag);
vfile_scan(&path, blob_size(&path), allFlag, pIgnore);
glob_free(pIgnore);
db_prepare(&q,
"SELECT x FROM sfile"
" WHERE x NOT IN (%s)"
" ORDER BY 1",
fossil_all_reserved_names()
);
if( file_tree_name(g.zRepositoryName, &repo, 0) ){
db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
}
while( db_step(&q)==SQLITE_ROW ){
printf("%s\n", db_column_text(&q, 0));
}
|
| ︙ | ︙ | |||
276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
const char *zIgnoreFlag;
Blob path, repo;
Stmt q;
int n;
allFlag = find_option("force","f",0)!=0;
dotfilesFlag = find_option("dotfiles",0,0)!=0;
zIgnoreFlag = find_option("ignore",0,1);
db_must_be_within_tree();
if( zIgnoreFlag==0 ){
zIgnoreFlag = db_get("ignore-glob", 0);
}
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
n = strlen(g.zLocalRoot);
blob_init(&path, g.zLocalRoot, n-1);
| > > > | > | | | 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
const char *zIgnoreFlag;
Blob path, repo;
Stmt q;
int n;
allFlag = find_option("force","f",0)!=0;
dotfilesFlag = find_option("dotfiles",0,0)!=0;
zIgnoreFlag = find_option("ignore",0,1);
Glob *pIgnore;
db_must_be_within_tree();
if( zIgnoreFlag==0 ){
zIgnoreFlag = db_get("ignore-glob", 0);
}
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
n = strlen(g.zLocalRoot);
blob_init(&path, g.zLocalRoot, n-1);
pIgnore = glob_create(zIgnoreFlag);
vfile_scan(&path, blob_size(&path), dotfilesFlag, pIgnore);
glob_free(pIgnore);
db_prepare(&q,
"SELECT %Q || x FROM sfile"
" WHERE x NOT IN (%s)"
" ORDER BY 1",
g.zLocalRoot, fossil_all_reserved_names()
);
if( file_tree_name(g.zRepositoryName, &repo, 0) ){
db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
}
while( db_step(&q)==SQLITE_ROW ){
if( allFlag ){
unlink(db_column_text(&q, 0));
|
| ︙ | ︙ |
Changes to src/vfile.c.
| ︙ | ︙ | |||
296 297 298 299 300 301 302 | /* ** Load into table SFILE the name of every ordinary file in ** the directory pPath. Omit the first nPrefix characters of ** of pPath when inserting into the SFILE table. ** ** Subdirectories are scanned recursively. | | > > > > > > | > | < > > > > > > > > > > > > > > > > > > | | | | > > > > > > > | 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
/*
** Load into table SFILE the name of every ordinary file in
** the directory pPath. Omit the first nPrefix characters of
** of pPath when inserting into the SFILE table.
**
** Subdirectories are scanned recursively.
** Omit files named in VFILE.
**
** Files whose names begin with "." are omitted unless allFlag is true.
**
** Any files or directories that match the glob pattern pIgnore are
** excluded from the scan. Name matching occurs after the first
** nPrefix characters are elided from the filename.
*/
void vfile_scan(Blob *pPath, int nPrefix, int allFlag, Glob *pIgnore){
DIR *d;
int origSize;
const char *zDir;
struct dirent *pEntry;
int skipAll = 0;
static Stmt ins;
static int depth = 0;
origSize = blob_size(pPath);
if( pIgnore ){
blob_appendf(pPath, "/");
if( glob_match(pIgnore, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
blob_resize(pPath, origSize);
}
if( skipAll ) return;
if( depth==0 ){
db_prepare(&ins,
"INSERT OR IGNORE INTO sfile(x) SELECT :file"
" WHERE NOT EXISTS(SELECT 1 FROM vfile WHERE pathname=:file)"
);
}
depth++;
zDir = blob_str(pPath);
d = opendir(zDir);
if( d ){
while( (pEntry=readdir(d))!=0 ){
char *zPath;
if( pEntry->d_name[0]=='.' ){
if( !allFlag ) continue;
if( pEntry->d_name[1]==0 ) continue;
if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
}
blob_appendf(pPath, "/%s", pEntry->d_name);
zPath = blob_str(pPath);
if( glob_match(pIgnore, &zPath[nPrefix+1]) ){
/* do nothing */
}else if( file_isdir(zPath)==1 ){
vfile_scan(pPath, nPrefix, allFlag, pIgnore);
}else if( file_isfile(zPath) ){
db_bind_text(&ins, ":file", &zPath[nPrefix+1]);
db_step(&ins);
db_reset(&ins);
}
blob_resize(pPath, origSize);
}
closedir(d);
}
depth--;
if( depth==0 ){
db_finalize(&ins);
}
}
/*
** Compute an aggregate MD5 checksum over the disk image of every
** file in vid. The file names are part of the checksum. The resulting
** checksum is the same as is expected on the R-card of a manifest.
**
|
| ︙ | ︙ |