Fossil SCM
added experimental IMPORT command
Commit
b37d5f256e207b92d233db367cee793d174fb2f8
Parent
c9df94776183f72…
2 files changed
+93
+6
-1
+93
| --- src/add.c | ||
| +++ src/add.c | ||
| @@ -269,10 +269,103 @@ | ||
| 269 | 269 | blob_reset(&pathname); |
| 270 | 270 | } |
| 271 | 271 | free(zName); |
| 272 | 272 | } |
| 273 | 273 | db_multi_exec("DELETE FROM vfile WHERE deleted AND rid=0"); |
| 274 | + db_end_transaction(0); | |
| 275 | +} | |
| 276 | + | |
| 277 | +/* | |
| 278 | +** COMMAND: import ?--dotfiles? ?--ignore GLOBPATTERN? | |
| 279 | +** | |
| 280 | +** Usage: %fossil import | |
| 281 | +** | |
| 282 | +** If used in a checkout, the current checkout file tree is synchronized | |
| 283 | +** with the repository: | |
| 284 | +** * all files, existing in the file tree but not in the repository | |
| 285 | +** (files displayed using the <a>extra</a> command) | |
| 286 | +** are added to the repository - see also <a>add</a> | |
| 287 | +** * all files, existing in the repository, not existing in the file tree | |
| 288 | +** (files displayed as MISSING using the <a>status</a> command) | |
| 289 | +** are removed from the repository - see also <a>rm</a> | |
| 290 | +** The command does not <a>commit</a>! | |
| 291 | +** | |
| 292 | +** This command can be used to track third party software. | |
| 293 | +*/ | |
| 294 | +void import_cmd(void){ | |
| 295 | + Blob path; | |
| 296 | + const char *zIgnoreFlag = find_option("ignore",0,1); | |
| 297 | + int allFlag = find_option("dotfiles",0,0)!=0; | |
| 298 | + int n; | |
| 299 | + Stmt q; | |
| 300 | + int vid; | |
| 301 | + Blob repo; | |
| 302 | + int addons = 0; | |
| 303 | + int deletes = 0; | |
| 304 | + | |
| 305 | + if( zIgnoreFlag==0 ){ | |
| 306 | + zIgnoreFlag = db_get("ignore-glob", 0); | |
| 307 | + } | |
| 308 | + db_must_be_within_tree(); | |
| 309 | + vid = db_lget_int("checkout",0); | |
| 310 | + if( vid==0 ){ | |
| 311 | + fossil_panic("no checkout to add to"); | |
| 312 | + } | |
| 313 | + db_begin_transaction(); | |
| 314 | + db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)"); | |
| 315 | + n = strlen(g.zLocalRoot); | |
| 316 | + blob_init(&path, g.zLocalRoot, n-1); | |
| 317 | + /* now we read the complete file structure into a temp table */ | |
| 318 | + vfile_scan(0, &path, blob_size(&path), allFlag); | |
| 319 | + if( file_tree_name(g.zRepositoryName, &repo, 0) ){ | |
| 320 | + db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo); | |
| 321 | + } | |
| 322 | + printf("importing checkout root '%s'\ninto repository '%s':\n", | |
| 323 | + g.zLocalRoot,g.zRepositoryName); | |
| 324 | + /* step 1: search for extra files */ | |
| 325 | + db_prepare(&q, | |
| 326 | + "SELECT x, %Q || x FROM sfile" | |
| 327 | + " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_'," | |
| 328 | + "'_FOSSIL_-journal','.fos','.fos-journal'," | |
| 329 | + "'_FOSSIL_-wal','_FOSSIL_-shm','.fos-wal'," | |
| 330 | + "'.fos-shm')" | |
| 331 | + " AND NOT %s" | |
| 332 | + " ORDER BY 1", | |
| 333 | + g.zLocalRoot, | |
| 334 | + glob_expr("x", zIgnoreFlag) | |
| 335 | + ); | |
| 336 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 337 | + Blob omit; | |
| 338 | + | |
| 339 | + blob_zero(&omit); | |
| 340 | + add_one_file(db_column_text(&q, 1), vid, &omit); | |
| 341 | + addons++; | |
| 342 | + } | |
| 343 | + db_finalize(&q); | |
| 344 | + /* step 2: search for missing files */ | |
| 345 | + db_prepare(&q, | |
| 346 | + "SELECT pathname,%Q || pathname,deleted FROM vfile" | |
| 347 | + " WHERE deleted!=1" | |
| 348 | + " ORDER BY 1", | |
| 349 | + g.zLocalRoot | |
| 350 | + ); | |
| 351 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 352 | + const char * zFile; | |
| 353 | + const char * zPath; | |
| 354 | + | |
| 355 | + zFile = db_column_text(&q, 0); | |
| 356 | + zPath = db_column_text(&q, 1); | |
| 357 | + if( !file_isfile(zPath) ){ | |
| 358 | + db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zFile); | |
| 359 | + printf("DELETED %s\n", zFile); | |
| 360 | + deletes--; | |
| 361 | + } | |
| 362 | + } | |
| 363 | + db_finalize(&q); | |
| 364 | + /* show cmmand summary */ | |
| 365 | + printf("added %d files, deleted %d files\n",addons,deletes); | |
| 366 | + | |
| 274 | 367 | db_end_transaction(0); |
| 275 | 368 | } |
| 276 | 369 | |
| 277 | 370 | /* |
| 278 | 371 | ** Rename a single file. |
| 279 | 372 |
| --- src/add.c | |
| +++ src/add.c | |
| @@ -269,10 +269,103 @@ | |
| 269 | blob_reset(&pathname); |
| 270 | } |
| 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 |
| --- src/add.c | |
| +++ src/add.c | |
| @@ -269,10 +269,103 @@ | |
| 269 | blob_reset(&pathname); |
| 270 | } |
| 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: import ?--dotfiles? ?--ignore GLOBPATTERN? |
| 279 | ** |
| 280 | ** Usage: %fossil import |
| 281 | ** |
| 282 | ** If used in a checkout, the current checkout file tree is synchronized |
| 283 | ** with the repository: |
| 284 | ** * all files, existing in the file tree but not in the repository |
| 285 | ** (files displayed using the <a>extra</a> command) |
| 286 | ** are added to the repository - see also <a>add</a> |
| 287 | ** * all files, existing in the repository, not existing in the file tree |
| 288 | ** (files displayed as MISSING using the <a>status</a> command) |
| 289 | ** are removed from the repository - see also <a>rm</a> |
| 290 | ** The command does not <a>commit</a>! |
| 291 | ** |
| 292 | ** This command can be used to track third party software. |
| 293 | */ |
| 294 | void import_cmd(void){ |
| 295 | Blob path; |
| 296 | const char *zIgnoreFlag = find_option("ignore",0,1); |
| 297 | int allFlag = find_option("dotfiles",0,0)!=0; |
| 298 | int n; |
| 299 | Stmt q; |
| 300 | int vid; |
| 301 | Blob repo; |
| 302 | int addons = 0; |
| 303 | int deletes = 0; |
| 304 | |
| 305 | if( zIgnoreFlag==0 ){ |
| 306 | zIgnoreFlag = db_get("ignore-glob", 0); |
| 307 | } |
| 308 | db_must_be_within_tree(); |
| 309 | vid = db_lget_int("checkout",0); |
| 310 | if( vid==0 ){ |
| 311 | fossil_panic("no checkout to add to"); |
| 312 | } |
| 313 | db_begin_transaction(); |
| 314 | db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)"); |
| 315 | n = strlen(g.zLocalRoot); |
| 316 | blob_init(&path, g.zLocalRoot, n-1); |
| 317 | /* now we read the complete file structure into a temp table */ |
| 318 | vfile_scan(0, &path, blob_size(&path), allFlag); |
| 319 | if( file_tree_name(g.zRepositoryName, &repo, 0) ){ |
| 320 | db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo); |
| 321 | } |
| 322 | printf("importing checkout root '%s'\ninto repository '%s':\n", |
| 323 | g.zLocalRoot,g.zRepositoryName); |
| 324 | /* step 1: search for extra files */ |
| 325 | db_prepare(&q, |
| 326 | "SELECT x, %Q || x FROM sfile" |
| 327 | " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_'," |
| 328 | "'_FOSSIL_-journal','.fos','.fos-journal'," |
| 329 | "'_FOSSIL_-wal','_FOSSIL_-shm','.fos-wal'," |
| 330 | "'.fos-shm')" |
| 331 | " AND NOT %s" |
| 332 | " ORDER BY 1", |
| 333 | g.zLocalRoot, |
| 334 | glob_expr("x", zIgnoreFlag) |
| 335 | ); |
| 336 | while( db_step(&q)==SQLITE_ROW ){ |
| 337 | Blob omit; |
| 338 | |
| 339 | blob_zero(&omit); |
| 340 | add_one_file(db_column_text(&q, 1), vid, &omit); |
| 341 | addons++; |
| 342 | } |
| 343 | db_finalize(&q); |
| 344 | /* step 2: search for missing files */ |
| 345 | db_prepare(&q, |
| 346 | "SELECT pathname,%Q || pathname,deleted FROM vfile" |
| 347 | " WHERE deleted!=1" |
| 348 | " ORDER BY 1", |
| 349 | g.zLocalRoot |
| 350 | ); |
| 351 | while( db_step(&q)==SQLITE_ROW ){ |
| 352 | const char * zFile; |
| 353 | const char * zPath; |
| 354 | |
| 355 | zFile = db_column_text(&q, 0); |
| 356 | zPath = db_column_text(&q, 1); |
| 357 | if( !file_isfile(zPath) ){ |
| 358 | db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zFile); |
| 359 | printf("DELETED %s\n", zFile); |
| 360 | deletes--; |
| 361 | } |
| 362 | } |
| 363 | db_finalize(&q); |
| 364 | /* show cmmand summary */ |
| 365 | printf("added %d files, deleted %d files\n",addons,deletes); |
| 366 | |
| 367 | db_end_transaction(0); |
| 368 | } |
| 369 | |
| 370 | /* |
| 371 | ** Rename a single file. |
| 372 |
+6
-1
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -101,11 +101,12 @@ | ||
| 101 | 101 | ** COMMAND: changes |
| 102 | 102 | ** |
| 103 | 103 | ** Usage: %fossil changes |
| 104 | 104 | ** |
| 105 | 105 | ** Report on the edit status of all files in the current checkout. |
| 106 | -** See also the <a>status</a> and <a>extra</a> commands. | |
| 106 | +** | |
| 107 | +** See also the <a>status</a>, <a>extra</a> and <a>import</a> commands. | |
| 107 | 108 | */ |
| 108 | 109 | void changes_cmd(void){ |
| 109 | 110 | Blob report; |
| 110 | 111 | int vid; |
| 111 | 112 | db_must_be_within_tree(); |
| @@ -120,10 +121,12 @@ | ||
| 120 | 121 | ** COMMAND: status |
| 121 | 122 | ** |
| 122 | 123 | ** Usage: %fossil status |
| 123 | 124 | ** |
| 124 | 125 | ** Report on the status of the current checkout. |
| 126 | +** | |
| 127 | +** See also <a>import</a> | |
| 125 | 128 | */ |
| 126 | 129 | void status_cmd(void){ |
| 127 | 130 | int vid; |
| 128 | 131 | db_must_be_within_tree(); |
| 129 | 132 | /* 012345678901234 */ |
| @@ -251,10 +254,12 @@ | ||
| 251 | 254 | ** Print a list of all files in the source tree that are not part of |
| 252 | 255 | ** the current checkout. See also the <a>clean</a> command. |
| 253 | 256 | ** |
| 254 | 257 | ** Files and subdirectories whose names begin with "." are normally |
| 255 | 258 | ** ignored but can be included by adding the --dotfiles option. |
| 259 | +** | |
| 260 | +** See also <a>import</a> | |
| 256 | 261 | */ |
| 257 | 262 | void extra_cmd(void){ |
| 258 | 263 | Blob path; |
| 259 | 264 | Blob repo; |
| 260 | 265 | Stmt q; |
| 261 | 266 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -101,11 +101,12 @@ | |
| 101 | ** COMMAND: changes |
| 102 | ** |
| 103 | ** Usage: %fossil changes |
| 104 | ** |
| 105 | ** Report on the edit status of all files in the current checkout. |
| 106 | ** See also the <a>status</a> and <a>extra</a> commands. |
| 107 | */ |
| 108 | void changes_cmd(void){ |
| 109 | Blob report; |
| 110 | int vid; |
| 111 | db_must_be_within_tree(); |
| @@ -120,10 +121,12 @@ | |
| 120 | ** COMMAND: status |
| 121 | ** |
| 122 | ** Usage: %fossil status |
| 123 | ** |
| 124 | ** Report on the status of the current checkout. |
| 125 | */ |
| 126 | void status_cmd(void){ |
| 127 | int vid; |
| 128 | db_must_be_within_tree(); |
| 129 | /* 012345678901234 */ |
| @@ -251,10 +254,12 @@ | |
| 251 | ** Print a list of all files in the source tree that are not part of |
| 252 | ** the current checkout. See also the <a>clean</a> command. |
| 253 | ** |
| 254 | ** Files and subdirectories whose names begin with "." are normally |
| 255 | ** ignored but can be included by adding the --dotfiles option. |
| 256 | */ |
| 257 | void extra_cmd(void){ |
| 258 | Blob path; |
| 259 | Blob repo; |
| 260 | Stmt q; |
| 261 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -101,11 +101,12 @@ | |
| 101 | ** COMMAND: changes |
| 102 | ** |
| 103 | ** Usage: %fossil changes |
| 104 | ** |
| 105 | ** Report on the edit status of all files in the current checkout. |
| 106 | ** |
| 107 | ** See also the <a>status</a>, <a>extra</a> and <a>import</a> commands. |
| 108 | */ |
| 109 | void changes_cmd(void){ |
| 110 | Blob report; |
| 111 | int vid; |
| 112 | db_must_be_within_tree(); |
| @@ -120,10 +121,12 @@ | |
| 121 | ** COMMAND: status |
| 122 | ** |
| 123 | ** Usage: %fossil status |
| 124 | ** |
| 125 | ** Report on the status of the current checkout. |
| 126 | ** |
| 127 | ** See also <a>import</a> |
| 128 | */ |
| 129 | void status_cmd(void){ |
| 130 | int vid; |
| 131 | db_must_be_within_tree(); |
| 132 | /* 012345678901234 */ |
| @@ -251,10 +254,12 @@ | |
| 254 | ** Print a list of all files in the source tree that are not part of |
| 255 | ** the current checkout. See also the <a>clean</a> command. |
| 256 | ** |
| 257 | ** Files and subdirectories whose names begin with "." are normally |
| 258 | ** ignored but can be included by adding the --dotfiles option. |
| 259 | ** |
| 260 | ** See also <a>import</a> |
| 261 | */ |
| 262 | void extra_cmd(void){ |
| 263 | Blob path; |
| 264 | Blob repo; |
| 265 | Stmt q; |
| 266 |