Fossil SCM

Incorporate the "addremove" command (with edits) from the StvPrivateHook2 branch.

drh 2010-11-12 16:37 trunk
Commit ceab53718f40e0a19c5350bed85ddadc2f393f8f
1 file changed +106 -1
+106 -1
--- src/add.c
+++ src/add.c
@@ -44,11 +44,11 @@
4444
|| strcmp(zPath, "_FOSSIL_-shm")==0
4545
|| strcmp(zPath, ".fos")==0
4646
|| strcmp(zPath, ".fos-journal")==0
4747
|| strcmp(zPath, ".fos-wal")==0
4848
|| strcmp(zPath, ".fos-shm")==0
49
- || blob_compare(&pathname, pOmit)==0
49
+ || (pOmit && blob_compare(&pathname, pOmit)==0)
5050
){
5151
fossil_warning("cannot add %s", zPath);
5252
}else{
5353
if( !file_is_simple_pathname(zPath) ){
5454
fossil_fatal("filename contains illegal characters: %s", zPath);
@@ -271,10 +271,115 @@
271271
free(zName);
272272
}
273273
db_multi_exec("DELETE FROM vfile WHERE deleted AND rid=0");
274274
db_end_transaction(0);
275275
}
276
+
277
+/*
278
+** COMMAND: addremove
279
+**
280
+** Usage: %fossil addremove ?--dotfiles? ?--ignore GLOBPATTERN? ?--test?
281
+**
282
+** Do all necessary "add" and "rm" commands to synchronize the repository
283
+** with the content of the working checkout
284
+**
285
+** * All files in the checkout but not in the repository (that is,
286
+** all files displayed using the "extra" command) are added as
287
+** if by the "add" command.
288
+**
289
+** * All files in the repository but missing from the checkout (that is,
290
+** all files that show as MISSING with the "status" command) are
291
+** removed as if by the "rm" command.
292
+**
293
+** The command does not "commit". You must run the "commit" separately
294
+** as a separate step.
295
+**
296
+** Files and directories whose names begin with "." are ignored unless
297
+** the --dotfiles option is used.
298
+**
299
+** The --ignore option overrides the "ignore-glob" setting. See
300
+** documentation on the "setting" command for further information.
301
+**
302
+** The --test option shows what would happen without actually doing anything.
303
+**
304
+** This command can be used to track third party software.
305
+*/
306
+void import_cmd(void){
307
+ Blob path;
308
+ const char *zIgnoreFlag = find_option("ignore",0,1);
309
+ int allFlag = find_option("dotfiles",0,0)!=0;
310
+ int isTest = find_option("test",0,0)!=0;
311
+ int n;
312
+ Stmt q;
313
+ int vid;
314
+ Blob repo;
315
+ int nAdd = 0;
316
+ int nDelete = 0;
317
+
318
+ if( zIgnoreFlag==0 ){
319
+ zIgnoreFlag = db_get("ignore-glob", 0);
320
+ }
321
+ db_must_be_within_tree();
322
+ vid = db_lget_int("checkout",0);
323
+ if( vid==0 ){
324
+ fossil_panic("no checkout to add to");
325
+ }
326
+ db_begin_transaction();
327
+ db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
328
+ n = strlen(g.zLocalRoot);
329
+ blob_init(&path, g.zLocalRoot, n-1);
330
+ /* now we read the complete file structure into a temp table */
331
+ vfile_scan(0, &path, blob_size(&path), allFlag);
332
+ if( file_tree_name(g.zRepositoryName, &repo, 0) ){
333
+ db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
334
+ }
335
+
336
+ /* step 1: search for extra files */
337
+ db_prepare(&q,
338
+ "SELECT x, %Q || x FROM sfile"
339
+ " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
340
+ "'_FOSSIL_-journal','.fos','.fos-journal',"
341
+ "'_FOSSIL_-wal','_FOSSIL_-shm','.fos-wal',"
342
+ "'.fos-shm')"
343
+ " AND NOT %s"
344
+ " ORDER BY 1",
345
+ g.zLocalRoot,
346
+ glob_expr("x", zIgnoreFlag)
347
+ );
348
+ while( db_step(&q)==SQLITE_ROW ){
349
+ add_one_file(db_column_text(&q, 1), vid, 0);
350
+ nAdd++;
351
+ }
352
+ db_finalize(&q);
353
+ /* step 2: search for missing files */
354
+ db_prepare(&q,
355
+ "SELECT pathname,%Q || pathname,deleted FROM vfile"
356
+ " WHERE deleted!=1"
357
+ " ORDER BY 1",
358
+ g.zLocalRoot
359
+ );
360
+ while( db_step(&q)==SQLITE_ROW ){
361
+ const char * zFile;
362
+ const char * zPath;
363
+
364
+ zFile = db_column_text(&q, 0);
365
+ zPath = db_column_text(&q, 1);
366
+ if( !file_isfile(zPath) ){
367
+ if( !isTest ){
368
+ db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zFile);
369
+ }
370
+ printf("DELETED %s\n", zFile);
371
+ nDelete++;
372
+ }
373
+ }
374
+ db_finalize(&q);
375
+ /* show cmmand summary */
376
+ printf("added %d files, deleted %d files\n", nAdd, nDelete);
377
+
378
+ db_end_transaction(isTest);
379
+}
380
+
276381
277382
/*
278383
** Rename a single file.
279384
**
280385
** The original name of the file is zOrig. The new filename is zNew.
281386
--- src/add.c
+++ src/add.c
@@ -44,11 +44,11 @@
44 || strcmp(zPath, "_FOSSIL_-shm")==0
45 || strcmp(zPath, ".fos")==0
46 || strcmp(zPath, ".fos-journal")==0
47 || strcmp(zPath, ".fos-wal")==0
48 || strcmp(zPath, ".fos-shm")==0
49 || blob_compare(&pathname, pOmit)==0
50 ){
51 fossil_warning("cannot add %s", zPath);
52 }else{
53 if( !file_is_simple_pathname(zPath) ){
54 fossil_fatal("filename contains illegal characters: %s", zPath);
@@ -271,10 +271,115 @@
271 free(zName);
272 }
273 db_multi_exec("DELETE FROM vfile WHERE deleted AND rid=0");
274 db_end_transaction(0);
275 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
277 /*
278 ** Rename a single file.
279 **
280 ** The original name of the file is zOrig. The new filename is zNew.
281
--- src/add.c
+++ src/add.c
@@ -44,11 +44,11 @@
44 || strcmp(zPath, "_FOSSIL_-shm")==0
45 || strcmp(zPath, ".fos")==0
46 || strcmp(zPath, ".fos-journal")==0
47 || strcmp(zPath, ".fos-wal")==0
48 || strcmp(zPath, ".fos-shm")==0
49 || (pOmit && blob_compare(&pathname, pOmit)==0)
50 ){
51 fossil_warning("cannot add %s", zPath);
52 }else{
53 if( !file_is_simple_pathname(zPath) ){
54 fossil_fatal("filename contains illegal characters: %s", zPath);
@@ -271,10 +271,115 @@
271 free(zName);
272 }
273 db_multi_exec("DELETE FROM vfile WHERE deleted AND rid=0");
274 db_end_transaction(0);
275 }
276
277 /*
278 ** COMMAND: addremove
279 **
280 ** Usage: %fossil addremove ?--dotfiles? ?--ignore GLOBPATTERN? ?--test?
281 **
282 ** Do all necessary "add" and "rm" commands to synchronize the repository
283 ** with the content of the working checkout
284 **
285 ** * All files in the checkout but not in the repository (that is,
286 ** all files displayed using the "extra" command) are added as
287 ** if by the "add" command.
288 **
289 ** * All files in the repository but missing from the checkout (that is,
290 ** all files that show as MISSING with the "status" command) are
291 ** removed as if by the "rm" command.
292 **
293 ** The command does not "commit". You must run the "commit" separately
294 ** as a separate step.
295 **
296 ** Files and directories whose names begin with "." are ignored unless
297 ** the --dotfiles option is used.
298 **
299 ** The --ignore option overrides the "ignore-glob" setting. See
300 ** documentation on the "setting" command for further information.
301 **
302 ** The --test option shows what would happen without actually doing anything.
303 **
304 ** This command can be used to track third party software.
305 */
306 void import_cmd(void){
307 Blob path;
308 const char *zIgnoreFlag = find_option("ignore",0,1);
309 int allFlag = find_option("dotfiles",0,0)!=0;
310 int isTest = find_option("test",0,0)!=0;
311 int n;
312 Stmt q;
313 int vid;
314 Blob repo;
315 int nAdd = 0;
316 int nDelete = 0;
317
318 if( zIgnoreFlag==0 ){
319 zIgnoreFlag = db_get("ignore-glob", 0);
320 }
321 db_must_be_within_tree();
322 vid = db_lget_int("checkout",0);
323 if( vid==0 ){
324 fossil_panic("no checkout to add to");
325 }
326 db_begin_transaction();
327 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
328 n = strlen(g.zLocalRoot);
329 blob_init(&path, g.zLocalRoot, n-1);
330 /* now we read the complete file structure into a temp table */
331 vfile_scan(0, &path, blob_size(&path), allFlag);
332 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
333 db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
334 }
335
336 /* step 1: search for extra files */
337 db_prepare(&q,
338 "SELECT x, %Q || x FROM sfile"
339 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
340 "'_FOSSIL_-journal','.fos','.fos-journal',"
341 "'_FOSSIL_-wal','_FOSSIL_-shm','.fos-wal',"
342 "'.fos-shm')"
343 " AND NOT %s"
344 " ORDER BY 1",
345 g.zLocalRoot,
346 glob_expr("x", zIgnoreFlag)
347 );
348 while( db_step(&q)==SQLITE_ROW ){
349 add_one_file(db_column_text(&q, 1), vid, 0);
350 nAdd++;
351 }
352 db_finalize(&q);
353 /* step 2: search for missing files */
354 db_prepare(&q,
355 "SELECT pathname,%Q || pathname,deleted FROM vfile"
356 " WHERE deleted!=1"
357 " ORDER BY 1",
358 g.zLocalRoot
359 );
360 while( db_step(&q)==SQLITE_ROW ){
361 const char * zFile;
362 const char * zPath;
363
364 zFile = db_column_text(&q, 0);
365 zPath = db_column_text(&q, 1);
366 if( !file_isfile(zPath) ){
367 if( !isTest ){
368 db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zFile);
369 }
370 printf("DELETED %s\n", zFile);
371 nDelete++;
372 }
373 }
374 db_finalize(&q);
375 /* show cmmand summary */
376 printf("added %d files, deleted %d files\n", nAdd, nDelete);
377
378 db_end_transaction(isTest);
379 }
380
381
382 /*
383 ** Rename a single file.
384 **
385 ** The original name of the file is zOrig. The new filename is zNew.
386

Keyboard Shortcuts

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