Fossil SCM
Fix the "fossil import" command so that it correctly handles cases where a file is deleted then replaced by a directory with the same name.
Commit
e5a734a19a9826973e1d073b49dc2a16aa2308f9
Parent
5fa4dfc28693c02…
2 files changed
+42
-21
+5
+42
-21
| --- src/import.c | ||
| +++ src/import.c | ||
| @@ -19,10 +19,24 @@ | ||
| 19 | 19 | ** repository. |
| 20 | 20 | */ |
| 21 | 21 | #include "config.h" |
| 22 | 22 | #include "import.h" |
| 23 | 23 | #include <assert.h> |
| 24 | + | |
| 25 | +#if INTERFACE | |
| 26 | +/* | |
| 27 | +** A single file change record. | |
| 28 | +*/ | |
| 29 | +struct ImportFile { | |
| 30 | + char *zName; /* Name of a file */ | |
| 31 | + char *zUuid; /* UUID of the file */ | |
| 32 | + char *zPrior; /* Prior name if the name was changed */ | |
| 33 | + char isFrom; /* True if obtained from the parent */ | |
| 34 | + char isExe; /* True if executable */ | |
| 35 | +}; | |
| 36 | +#endif | |
| 37 | + | |
| 24 | 38 | |
| 25 | 39 | /* |
| 26 | 40 | ** State information about an on-going fast-import parse. |
| 27 | 41 | */ |
| 28 | 42 | static struct { |
| @@ -40,11 +54,11 @@ | ||
| 40 | 54 | int nMerge; /* Number of merge values */ |
| 41 | 55 | int nMergeAlloc; /* Number of slots in azMerge[] */ |
| 42 | 56 | char **azMerge; /* Merge values */ |
| 43 | 57 | int nFile; /* Number of aFile values */ |
| 44 | 58 | int nFileAlloc; /* Number of slots in aFile[] */ |
| 45 | - ManifestFile *aFile; /* Information about files in a commit */ | |
| 59 | + ImportFile *aFile; /* Information about files in a commit */ | |
| 46 | 60 | int fromLoaded; /* True zFrom content loaded into aFile[] */ |
| 47 | 61 | } gg; |
| 48 | 62 | |
| 49 | 63 | /* |
| 50 | 64 | ** A no-op "xFinish" method |
| @@ -74,11 +88,10 @@ | ||
| 74 | 88 | } |
| 75 | 89 | gg.nMerge = 0; |
| 76 | 90 | for(i=0; i<gg.nFile; i++){ |
| 77 | 91 | fossil_free(gg.aFile[i].zName); |
| 78 | 92 | fossil_free(gg.aFile[i].zUuid); |
| 79 | - fossil_free(gg.aFile[i].zPerm); | |
| 80 | 93 | fossil_free(gg.aFile[i].zPrior); |
| 81 | 94 | } |
| 82 | 95 | memset(gg.aFile, 0, gg.nFile*sizeof(gg.aFile[0])); |
| 83 | 96 | gg.nFile = 0; |
| 84 | 97 | if( freeAll ){ |
| @@ -165,15 +178,15 @@ | ||
| 165 | 178 | } |
| 166 | 179 | import_reset(0); |
| 167 | 180 | } |
| 168 | 181 | |
| 169 | 182 | /* |
| 170 | -** Compare two ManifestFile objects for sorting | |
| 183 | +** Compare two ImportFile objects for sorting | |
| 171 | 184 | */ |
| 172 | 185 | static int mfile_cmp(const void *pLeft, const void *pRight){ |
| 173 | - const ManifestFile *pA = (const ManifestFile*)pLeft; | |
| 174 | - const ManifestFile *pB = (const ManifestFile*)pRight; | |
| 186 | + const ImportFile *pA = (const ImportFile*)pLeft; | |
| 187 | + const ImportFile *pB = (const ImportFile*)pRight; | |
| 175 | 188 | return strcmp(pA->zName, pB->zName); |
| 176 | 189 | } |
| 177 | 190 | |
| 178 | 191 | /* |
| 179 | 192 | ** Use data accumulated in gg from a "commit" record to add a new |
| @@ -187,12 +200,12 @@ | ||
| 187 | 200 | blob_zero(&record); |
| 188 | 201 | blob_appendf(&record, "C %F\n", gg.zComment); |
| 189 | 202 | blob_appendf(&record, "D %s\n", gg.zDate); |
| 190 | 203 | for(i=0; i<gg.nFile; i++){ |
| 191 | 204 | blob_appendf(&record, "F %F %s", gg.aFile[i].zName, gg.aFile[i].zUuid); |
| 192 | - if( gg.aFile[i].zPerm && gg.aFile[i].zPerm[0] ){ | |
| 193 | - blob_appendf(&record, " %s\n", gg.aFile[i].zPerm); | |
| 205 | + if( gg.aFile[i].isExe ){ | |
| 206 | + blob_append(&record, " x\n", 3); | |
| 194 | 207 | }else{ |
| 195 | 208 | blob_append(&record, "\n", 1); |
| 196 | 209 | } |
| 197 | 210 | } |
| 198 | 211 | if( gg.zFrom ){ |
| @@ -211,10 +224,11 @@ | ||
| 211 | 224 | blob_appendf(&record, "T *sym-%F *\n", gg.zBranch); |
| 212 | 225 | if( zFromBranch ){ |
| 213 | 226 | blob_appendf(&record, "T -sym-%F *\n", zFromBranch); |
| 214 | 227 | } |
| 215 | 228 | } |
| 229 | + free(zFromBranch); | |
| 216 | 230 | if( gg.zFrom==0 ){ |
| 217 | 231 | blob_appendf(&record, "T +sym-trunk *\n"); |
| 218 | 232 | } |
| 219 | 233 | db_multi_exec("INSERT INTO xbranch(tname, brnm) VALUES(%Q,%Q)", |
| 220 | 234 | gg.zMark, gg.zBranch); |
| @@ -280,12 +294,12 @@ | ||
| 280 | 294 | } |
| 281 | 295 | |
| 282 | 296 | /* |
| 283 | 297 | ** Create a new entry in the gg.aFile[] array |
| 284 | 298 | */ |
| 285 | -static ManifestFile *import_add_file(void){ | |
| 286 | - ManifestFile *pFile; | |
| 299 | +static ImportFile *import_add_file(void){ | |
| 300 | + ImportFile *pFile; | |
| 287 | 301 | if( gg.nFile>=gg.nFileAlloc ){ |
| 288 | 302 | gg.nFileAlloc = gg.nFileAlloc*2 + 100; |
| 289 | 303 | gg.aFile = fossil_realloc(gg.aFile, gg.nFileAlloc*sizeof(gg.aFile[0])); |
| 290 | 304 | } |
| 291 | 305 | pFile = &gg.aFile[gg.nFile++]; |
| @@ -298,11 +312,12 @@ | ||
| 298 | 312 | ** Load all file information out of the gg.zFrom check-in |
| 299 | 313 | */ |
| 300 | 314 | static void import_prior_files(void){ |
| 301 | 315 | Manifest *p; |
| 302 | 316 | int rid; |
| 303 | - ManifestFile *pOld, *pNew; | |
| 317 | + ManifestFile *pOld; | |
| 318 | + ImportFile *pNew; | |
| 304 | 319 | if( gg.fromLoaded ) return; |
| 305 | 320 | gg.fromLoaded = 1; |
| 306 | 321 | if( gg.zFrom==0 ) return; |
| 307 | 322 | rid = fast_uuid_to_rid(gg.zFrom); |
| 308 | 323 | if( rid==0 ) return; |
| @@ -310,22 +325,23 @@ | ||
| 310 | 325 | if( p==0 ) return; |
| 311 | 326 | manifest_file_rewind(p); |
| 312 | 327 | while( (pOld = manifest_file_next(p, 0))!=0 ){ |
| 313 | 328 | pNew = import_add_file(); |
| 314 | 329 | pNew->zName = import_strdup(pOld->zName); |
| 315 | - pNew->zPerm = import_strdup(pOld->zPerm); | |
| 330 | + pNew->isExe = pOld->zPerm && strstr(pOld->zPerm, "x")!=0; | |
| 316 | 331 | pNew->zUuid = import_strdup(pOld->zUuid); |
| 332 | + pNew->isFrom = 1; | |
| 317 | 333 | } |
| 318 | 334 | manifest_destroy(p); |
| 319 | 335 | } |
| 320 | 336 | |
| 321 | 337 | /* |
| 322 | 338 | ** Locate a file in the gg.aFile[] array by its name. Begin the search |
| 323 | 339 | ** with the *pI-th file. Update *pI to be one past the file found. |
| 324 | 340 | ** Do not search past the mx-th file. |
| 325 | 341 | */ |
| 326 | -static ManifestFile *import_find_file(const char *zName, int *pI, int mx){ | |
| 342 | +static ImportFile *import_find_file(const char *zName, int *pI, int mx){ | |
| 327 | 343 | int i = *pI; |
| 328 | 344 | int nName = strlen(zName); |
| 329 | 345 | while( i<mx ){ |
| 330 | 346 | const char *z = gg.aFile[i].zName; |
| 331 | 347 | if( memcmp(zName, z, nName)==0 && (z[nName]==0 || z[nName]=='/') ){ |
| @@ -341,11 +357,11 @@ | ||
| 341 | 357 | /* |
| 342 | 358 | ** Read the git-fast-import format from pIn and insert the corresponding |
| 343 | 359 | ** content into the database. |
| 344 | 360 | */ |
| 345 | 361 | static void git_fast_import(FILE *pIn){ |
| 346 | - ManifestFile *pFile; | |
| 362 | + ImportFile *pFile, *pNew; | |
| 347 | 363 | int i, mx; |
| 348 | 364 | char *z; |
| 349 | 365 | char *zUuid; |
| 350 | 366 | char *zName; |
| 351 | 367 | char *zPerm; |
| @@ -464,23 +480,24 @@ | ||
| 464 | 480 | pFile = import_find_file(zName, &i, gg.nFile); |
| 465 | 481 | if( pFile==0 ){ |
| 466 | 482 | pFile = import_add_file(); |
| 467 | 483 | pFile->zName = import_strdup(zName); |
| 468 | 484 | } |
| 469 | - if( strcmp(zPerm, "100755")==0 ){ | |
| 470 | - pFile->zPerm = mprintf("x"); | |
| 471 | - } | |
| 485 | + pFile->isExe = (strcmp(zPerm, "100755")==0); | |
| 486 | + fossil_free(pFile->zUuid); | |
| 472 | 487 | pFile->zUuid = resolve_committish(zUuid); |
| 488 | + pFile->isFrom = 0; | |
| 473 | 489 | }else |
| 474 | 490 | if( memcmp(zLine, "D ", 2)==0 ){ |
| 475 | 491 | import_prior_files(); |
| 476 | 492 | z = &zLine[2]; |
| 477 | 493 | zName = next_token(&z); |
| 478 | 494 | i = 0; |
| 479 | 495 | while( (pFile = import_find_file(zName, &i, gg.nFile))!=0 ){ |
| 496 | + if( pFile->isFrom==0 ) continue; | |
| 480 | 497 | fossil_free(pFile->zName); |
| 481 | - fossil_free(pFile->zPerm); | |
| 498 | + fossil_free(pFile->zPrior); | |
| 482 | 499 | fossil_free(pFile->zUuid); |
| 483 | 500 | *pFile = gg.aFile[--gg.nFile]; |
| 484 | 501 | i--; |
| 485 | 502 | } |
| 486 | 503 | }else |
| @@ -492,19 +509,21 @@ | ||
| 492 | 509 | zTo = next_token(&z); |
| 493 | 510 | i = 0; |
| 494 | 511 | mx = gg.nFile; |
| 495 | 512 | nFrom = strlen(zFrom); |
| 496 | 513 | while( (pFile = import_find_file(zFrom, &i, mx))!=0 ){ |
| 497 | - ManifestFile *pNew = import_add_file(); | |
| 514 | + if( pFile->isFrom==0 ) continue; | |
| 515 | + pNew = import_add_file(); | |
| 498 | 516 | pFile = &gg.aFile[i-1]; |
| 499 | 517 | if( strlen(pFile->zName)>nFrom ){ |
| 500 | 518 | pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]); |
| 501 | 519 | }else{ |
| 502 | 520 | pNew->zName = import_strdup(pFile->zName); |
| 503 | 521 | } |
| 504 | - pNew->zPerm = import_strdup(pFile->zPerm); | |
| 522 | + pNew->isExe = pFile->isExe; | |
| 505 | 523 | pNew->zUuid = import_strdup(pFile->zUuid); |
| 524 | + pNew->isFrom = 0; | |
| 506 | 525 | } |
| 507 | 526 | }else |
| 508 | 527 | if( memcmp(zLine, "R ", 2)==0 ){ |
| 509 | 528 | int nFrom; |
| 510 | 529 | import_prior_files(); |
| @@ -512,20 +531,22 @@ | ||
| 512 | 531 | zFrom = next_token(&z); |
| 513 | 532 | zTo = next_token(&z); |
| 514 | 533 | i = 0; |
| 515 | 534 | nFrom = strlen(zFrom); |
| 516 | 535 | while( (pFile = import_find_file(zFrom, &i, gg.nFile))!=0 ){ |
| 517 | - ManifestFile *pNew = import_add_file(); | |
| 536 | + if( pFile->isFrom==0 ) continue; | |
| 537 | + pNew = import_add_file(); | |
| 518 | 538 | pFile = &gg.aFile[i-1]; |
| 519 | 539 | if( strlen(pFile->zName)>nFrom ){ |
| 520 | 540 | pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]); |
| 521 | 541 | }else{ |
| 522 | 542 | pNew->zName = import_strdup(pFile->zName); |
| 523 | 543 | } |
| 524 | 544 | pNew->zPrior = pFile->zName; |
| 525 | - pNew->zPerm = pFile->zPerm; | |
| 545 | + pNew->isExe = pFile->isExe; | |
| 526 | 546 | pNew->zUuid = pFile->zUuid; |
| 547 | + pNew->isFrom = 0; | |
| 527 | 548 | gg.nFile--; |
| 528 | 549 | *pFile = *pNew; |
| 529 | 550 | memset(pNew, 0, sizeof(*pNew)); |
| 530 | 551 | } |
| 531 | 552 | fossil_fatal("cannot handle R records, use --full-tree"); |
| 532 | 553 |
| --- src/import.c | |
| +++ src/import.c | |
| @@ -19,10 +19,24 @@ | |
| 19 | ** repository. |
| 20 | */ |
| 21 | #include "config.h" |
| 22 | #include "import.h" |
| 23 | #include <assert.h> |
| 24 | |
| 25 | /* |
| 26 | ** State information about an on-going fast-import parse. |
| 27 | */ |
| 28 | static struct { |
| @@ -40,11 +54,11 @@ | |
| 40 | int nMerge; /* Number of merge values */ |
| 41 | int nMergeAlloc; /* Number of slots in azMerge[] */ |
| 42 | char **azMerge; /* Merge values */ |
| 43 | int nFile; /* Number of aFile values */ |
| 44 | int nFileAlloc; /* Number of slots in aFile[] */ |
| 45 | ManifestFile *aFile; /* Information about files in a commit */ |
| 46 | int fromLoaded; /* True zFrom content loaded into aFile[] */ |
| 47 | } gg; |
| 48 | |
| 49 | /* |
| 50 | ** A no-op "xFinish" method |
| @@ -74,11 +88,10 @@ | |
| 74 | } |
| 75 | gg.nMerge = 0; |
| 76 | for(i=0; i<gg.nFile; i++){ |
| 77 | fossil_free(gg.aFile[i].zName); |
| 78 | fossil_free(gg.aFile[i].zUuid); |
| 79 | fossil_free(gg.aFile[i].zPerm); |
| 80 | fossil_free(gg.aFile[i].zPrior); |
| 81 | } |
| 82 | memset(gg.aFile, 0, gg.nFile*sizeof(gg.aFile[0])); |
| 83 | gg.nFile = 0; |
| 84 | if( freeAll ){ |
| @@ -165,15 +178,15 @@ | |
| 165 | } |
| 166 | import_reset(0); |
| 167 | } |
| 168 | |
| 169 | /* |
| 170 | ** Compare two ManifestFile objects for sorting |
| 171 | */ |
| 172 | static int mfile_cmp(const void *pLeft, const void *pRight){ |
| 173 | const ManifestFile *pA = (const ManifestFile*)pLeft; |
| 174 | const ManifestFile *pB = (const ManifestFile*)pRight; |
| 175 | return strcmp(pA->zName, pB->zName); |
| 176 | } |
| 177 | |
| 178 | /* |
| 179 | ** Use data accumulated in gg from a "commit" record to add a new |
| @@ -187,12 +200,12 @@ | |
| 187 | blob_zero(&record); |
| 188 | blob_appendf(&record, "C %F\n", gg.zComment); |
| 189 | blob_appendf(&record, "D %s\n", gg.zDate); |
| 190 | for(i=0; i<gg.nFile; i++){ |
| 191 | blob_appendf(&record, "F %F %s", gg.aFile[i].zName, gg.aFile[i].zUuid); |
| 192 | if( gg.aFile[i].zPerm && gg.aFile[i].zPerm[0] ){ |
| 193 | blob_appendf(&record, " %s\n", gg.aFile[i].zPerm); |
| 194 | }else{ |
| 195 | blob_append(&record, "\n", 1); |
| 196 | } |
| 197 | } |
| 198 | if( gg.zFrom ){ |
| @@ -211,10 +224,11 @@ | |
| 211 | blob_appendf(&record, "T *sym-%F *\n", gg.zBranch); |
| 212 | if( zFromBranch ){ |
| 213 | blob_appendf(&record, "T -sym-%F *\n", zFromBranch); |
| 214 | } |
| 215 | } |
| 216 | if( gg.zFrom==0 ){ |
| 217 | blob_appendf(&record, "T +sym-trunk *\n"); |
| 218 | } |
| 219 | db_multi_exec("INSERT INTO xbranch(tname, brnm) VALUES(%Q,%Q)", |
| 220 | gg.zMark, gg.zBranch); |
| @@ -280,12 +294,12 @@ | |
| 280 | } |
| 281 | |
| 282 | /* |
| 283 | ** Create a new entry in the gg.aFile[] array |
| 284 | */ |
| 285 | static ManifestFile *import_add_file(void){ |
| 286 | ManifestFile *pFile; |
| 287 | if( gg.nFile>=gg.nFileAlloc ){ |
| 288 | gg.nFileAlloc = gg.nFileAlloc*2 + 100; |
| 289 | gg.aFile = fossil_realloc(gg.aFile, gg.nFileAlloc*sizeof(gg.aFile[0])); |
| 290 | } |
| 291 | pFile = &gg.aFile[gg.nFile++]; |
| @@ -298,11 +312,12 @@ | |
| 298 | ** Load all file information out of the gg.zFrom check-in |
| 299 | */ |
| 300 | static void import_prior_files(void){ |
| 301 | Manifest *p; |
| 302 | int rid; |
| 303 | ManifestFile *pOld, *pNew; |
| 304 | if( gg.fromLoaded ) return; |
| 305 | gg.fromLoaded = 1; |
| 306 | if( gg.zFrom==0 ) return; |
| 307 | rid = fast_uuid_to_rid(gg.zFrom); |
| 308 | if( rid==0 ) return; |
| @@ -310,22 +325,23 @@ | |
| 310 | if( p==0 ) return; |
| 311 | manifest_file_rewind(p); |
| 312 | while( (pOld = manifest_file_next(p, 0))!=0 ){ |
| 313 | pNew = import_add_file(); |
| 314 | pNew->zName = import_strdup(pOld->zName); |
| 315 | pNew->zPerm = import_strdup(pOld->zPerm); |
| 316 | pNew->zUuid = import_strdup(pOld->zUuid); |
| 317 | } |
| 318 | manifest_destroy(p); |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | ** Locate a file in the gg.aFile[] array by its name. Begin the search |
| 323 | ** with the *pI-th file. Update *pI to be one past the file found. |
| 324 | ** Do not search past the mx-th file. |
| 325 | */ |
| 326 | static ManifestFile *import_find_file(const char *zName, int *pI, int mx){ |
| 327 | int i = *pI; |
| 328 | int nName = strlen(zName); |
| 329 | while( i<mx ){ |
| 330 | const char *z = gg.aFile[i].zName; |
| 331 | if( memcmp(zName, z, nName)==0 && (z[nName]==0 || z[nName]=='/') ){ |
| @@ -341,11 +357,11 @@ | |
| 341 | /* |
| 342 | ** Read the git-fast-import format from pIn and insert the corresponding |
| 343 | ** content into the database. |
| 344 | */ |
| 345 | static void git_fast_import(FILE *pIn){ |
| 346 | ManifestFile *pFile; |
| 347 | int i, mx; |
| 348 | char *z; |
| 349 | char *zUuid; |
| 350 | char *zName; |
| 351 | char *zPerm; |
| @@ -464,23 +480,24 @@ | |
| 464 | pFile = import_find_file(zName, &i, gg.nFile); |
| 465 | if( pFile==0 ){ |
| 466 | pFile = import_add_file(); |
| 467 | pFile->zName = import_strdup(zName); |
| 468 | } |
| 469 | if( strcmp(zPerm, "100755")==0 ){ |
| 470 | pFile->zPerm = mprintf("x"); |
| 471 | } |
| 472 | pFile->zUuid = resolve_committish(zUuid); |
| 473 | }else |
| 474 | if( memcmp(zLine, "D ", 2)==0 ){ |
| 475 | import_prior_files(); |
| 476 | z = &zLine[2]; |
| 477 | zName = next_token(&z); |
| 478 | i = 0; |
| 479 | while( (pFile = import_find_file(zName, &i, gg.nFile))!=0 ){ |
| 480 | fossil_free(pFile->zName); |
| 481 | fossil_free(pFile->zPerm); |
| 482 | fossil_free(pFile->zUuid); |
| 483 | *pFile = gg.aFile[--gg.nFile]; |
| 484 | i--; |
| 485 | } |
| 486 | }else |
| @@ -492,19 +509,21 @@ | |
| 492 | zTo = next_token(&z); |
| 493 | i = 0; |
| 494 | mx = gg.nFile; |
| 495 | nFrom = strlen(zFrom); |
| 496 | while( (pFile = import_find_file(zFrom, &i, mx))!=0 ){ |
| 497 | ManifestFile *pNew = import_add_file(); |
| 498 | pFile = &gg.aFile[i-1]; |
| 499 | if( strlen(pFile->zName)>nFrom ){ |
| 500 | pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]); |
| 501 | }else{ |
| 502 | pNew->zName = import_strdup(pFile->zName); |
| 503 | } |
| 504 | pNew->zPerm = import_strdup(pFile->zPerm); |
| 505 | pNew->zUuid = import_strdup(pFile->zUuid); |
| 506 | } |
| 507 | }else |
| 508 | if( memcmp(zLine, "R ", 2)==0 ){ |
| 509 | int nFrom; |
| 510 | import_prior_files(); |
| @@ -512,20 +531,22 @@ | |
| 512 | zFrom = next_token(&z); |
| 513 | zTo = next_token(&z); |
| 514 | i = 0; |
| 515 | nFrom = strlen(zFrom); |
| 516 | while( (pFile = import_find_file(zFrom, &i, gg.nFile))!=0 ){ |
| 517 | ManifestFile *pNew = import_add_file(); |
| 518 | pFile = &gg.aFile[i-1]; |
| 519 | if( strlen(pFile->zName)>nFrom ){ |
| 520 | pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]); |
| 521 | }else{ |
| 522 | pNew->zName = import_strdup(pFile->zName); |
| 523 | } |
| 524 | pNew->zPrior = pFile->zName; |
| 525 | pNew->zPerm = pFile->zPerm; |
| 526 | pNew->zUuid = pFile->zUuid; |
| 527 | gg.nFile--; |
| 528 | *pFile = *pNew; |
| 529 | memset(pNew, 0, sizeof(*pNew)); |
| 530 | } |
| 531 | fossil_fatal("cannot handle R records, use --full-tree"); |
| 532 |
| --- src/import.c | |
| +++ src/import.c | |
| @@ -19,10 +19,24 @@ | |
| 19 | ** repository. |
| 20 | */ |
| 21 | #include "config.h" |
| 22 | #include "import.h" |
| 23 | #include <assert.h> |
| 24 | |
| 25 | #if INTERFACE |
| 26 | /* |
| 27 | ** A single file change record. |
| 28 | */ |
| 29 | struct ImportFile { |
| 30 | char *zName; /* Name of a file */ |
| 31 | char *zUuid; /* UUID of the file */ |
| 32 | char *zPrior; /* Prior name if the name was changed */ |
| 33 | char isFrom; /* True if obtained from the parent */ |
| 34 | char isExe; /* True if executable */ |
| 35 | }; |
| 36 | #endif |
| 37 | |
| 38 | |
| 39 | /* |
| 40 | ** State information about an on-going fast-import parse. |
| 41 | */ |
| 42 | static struct { |
| @@ -40,11 +54,11 @@ | |
| 54 | int nMerge; /* Number of merge values */ |
| 55 | int nMergeAlloc; /* Number of slots in azMerge[] */ |
| 56 | char **azMerge; /* Merge values */ |
| 57 | int nFile; /* Number of aFile values */ |
| 58 | int nFileAlloc; /* Number of slots in aFile[] */ |
| 59 | ImportFile *aFile; /* Information about files in a commit */ |
| 60 | int fromLoaded; /* True zFrom content loaded into aFile[] */ |
| 61 | } gg; |
| 62 | |
| 63 | /* |
| 64 | ** A no-op "xFinish" method |
| @@ -74,11 +88,10 @@ | |
| 88 | } |
| 89 | gg.nMerge = 0; |
| 90 | for(i=0; i<gg.nFile; i++){ |
| 91 | fossil_free(gg.aFile[i].zName); |
| 92 | fossil_free(gg.aFile[i].zUuid); |
| 93 | fossil_free(gg.aFile[i].zPrior); |
| 94 | } |
| 95 | memset(gg.aFile, 0, gg.nFile*sizeof(gg.aFile[0])); |
| 96 | gg.nFile = 0; |
| 97 | if( freeAll ){ |
| @@ -165,15 +178,15 @@ | |
| 178 | } |
| 179 | import_reset(0); |
| 180 | } |
| 181 | |
| 182 | /* |
| 183 | ** Compare two ImportFile objects for sorting |
| 184 | */ |
| 185 | static int mfile_cmp(const void *pLeft, const void *pRight){ |
| 186 | const ImportFile *pA = (const ImportFile*)pLeft; |
| 187 | const ImportFile *pB = (const ImportFile*)pRight; |
| 188 | return strcmp(pA->zName, pB->zName); |
| 189 | } |
| 190 | |
| 191 | /* |
| 192 | ** Use data accumulated in gg from a "commit" record to add a new |
| @@ -187,12 +200,12 @@ | |
| 200 | blob_zero(&record); |
| 201 | blob_appendf(&record, "C %F\n", gg.zComment); |
| 202 | blob_appendf(&record, "D %s\n", gg.zDate); |
| 203 | for(i=0; i<gg.nFile; i++){ |
| 204 | blob_appendf(&record, "F %F %s", gg.aFile[i].zName, gg.aFile[i].zUuid); |
| 205 | if( gg.aFile[i].isExe ){ |
| 206 | blob_append(&record, " x\n", 3); |
| 207 | }else{ |
| 208 | blob_append(&record, "\n", 1); |
| 209 | } |
| 210 | } |
| 211 | if( gg.zFrom ){ |
| @@ -211,10 +224,11 @@ | |
| 224 | blob_appendf(&record, "T *sym-%F *\n", gg.zBranch); |
| 225 | if( zFromBranch ){ |
| 226 | blob_appendf(&record, "T -sym-%F *\n", zFromBranch); |
| 227 | } |
| 228 | } |
| 229 | free(zFromBranch); |
| 230 | if( gg.zFrom==0 ){ |
| 231 | blob_appendf(&record, "T +sym-trunk *\n"); |
| 232 | } |
| 233 | db_multi_exec("INSERT INTO xbranch(tname, brnm) VALUES(%Q,%Q)", |
| 234 | gg.zMark, gg.zBranch); |
| @@ -280,12 +294,12 @@ | |
| 294 | } |
| 295 | |
| 296 | /* |
| 297 | ** Create a new entry in the gg.aFile[] array |
| 298 | */ |
| 299 | static ImportFile *import_add_file(void){ |
| 300 | ImportFile *pFile; |
| 301 | if( gg.nFile>=gg.nFileAlloc ){ |
| 302 | gg.nFileAlloc = gg.nFileAlloc*2 + 100; |
| 303 | gg.aFile = fossil_realloc(gg.aFile, gg.nFileAlloc*sizeof(gg.aFile[0])); |
| 304 | } |
| 305 | pFile = &gg.aFile[gg.nFile++]; |
| @@ -298,11 +312,12 @@ | |
| 312 | ** Load all file information out of the gg.zFrom check-in |
| 313 | */ |
| 314 | static void import_prior_files(void){ |
| 315 | Manifest *p; |
| 316 | int rid; |
| 317 | ManifestFile *pOld; |
| 318 | ImportFile *pNew; |
| 319 | if( gg.fromLoaded ) return; |
| 320 | gg.fromLoaded = 1; |
| 321 | if( gg.zFrom==0 ) return; |
| 322 | rid = fast_uuid_to_rid(gg.zFrom); |
| 323 | if( rid==0 ) return; |
| @@ -310,22 +325,23 @@ | |
| 325 | if( p==0 ) return; |
| 326 | manifest_file_rewind(p); |
| 327 | while( (pOld = manifest_file_next(p, 0))!=0 ){ |
| 328 | pNew = import_add_file(); |
| 329 | pNew->zName = import_strdup(pOld->zName); |
| 330 | pNew->isExe = pOld->zPerm && strstr(pOld->zPerm, "x")!=0; |
| 331 | pNew->zUuid = import_strdup(pOld->zUuid); |
| 332 | pNew->isFrom = 1; |
| 333 | } |
| 334 | manifest_destroy(p); |
| 335 | } |
| 336 | |
| 337 | /* |
| 338 | ** Locate a file in the gg.aFile[] array by its name. Begin the search |
| 339 | ** with the *pI-th file. Update *pI to be one past the file found. |
| 340 | ** Do not search past the mx-th file. |
| 341 | */ |
| 342 | static ImportFile *import_find_file(const char *zName, int *pI, int mx){ |
| 343 | int i = *pI; |
| 344 | int nName = strlen(zName); |
| 345 | while( i<mx ){ |
| 346 | const char *z = gg.aFile[i].zName; |
| 347 | if( memcmp(zName, z, nName)==0 && (z[nName]==0 || z[nName]=='/') ){ |
| @@ -341,11 +357,11 @@ | |
| 357 | /* |
| 358 | ** Read the git-fast-import format from pIn and insert the corresponding |
| 359 | ** content into the database. |
| 360 | */ |
| 361 | static void git_fast_import(FILE *pIn){ |
| 362 | ImportFile *pFile, *pNew; |
| 363 | int i, mx; |
| 364 | char *z; |
| 365 | char *zUuid; |
| 366 | char *zName; |
| 367 | char *zPerm; |
| @@ -464,23 +480,24 @@ | |
| 480 | pFile = import_find_file(zName, &i, gg.nFile); |
| 481 | if( pFile==0 ){ |
| 482 | pFile = import_add_file(); |
| 483 | pFile->zName = import_strdup(zName); |
| 484 | } |
| 485 | pFile->isExe = (strcmp(zPerm, "100755")==0); |
| 486 | fossil_free(pFile->zUuid); |
| 487 | pFile->zUuid = resolve_committish(zUuid); |
| 488 | pFile->isFrom = 0; |
| 489 | }else |
| 490 | if( memcmp(zLine, "D ", 2)==0 ){ |
| 491 | import_prior_files(); |
| 492 | z = &zLine[2]; |
| 493 | zName = next_token(&z); |
| 494 | i = 0; |
| 495 | while( (pFile = import_find_file(zName, &i, gg.nFile))!=0 ){ |
| 496 | if( pFile->isFrom==0 ) continue; |
| 497 | fossil_free(pFile->zName); |
| 498 | fossil_free(pFile->zPrior); |
| 499 | fossil_free(pFile->zUuid); |
| 500 | *pFile = gg.aFile[--gg.nFile]; |
| 501 | i--; |
| 502 | } |
| 503 | }else |
| @@ -492,19 +509,21 @@ | |
| 509 | zTo = next_token(&z); |
| 510 | i = 0; |
| 511 | mx = gg.nFile; |
| 512 | nFrom = strlen(zFrom); |
| 513 | while( (pFile = import_find_file(zFrom, &i, mx))!=0 ){ |
| 514 | if( pFile->isFrom==0 ) continue; |
| 515 | pNew = import_add_file(); |
| 516 | pFile = &gg.aFile[i-1]; |
| 517 | if( strlen(pFile->zName)>nFrom ){ |
| 518 | pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]); |
| 519 | }else{ |
| 520 | pNew->zName = import_strdup(pFile->zName); |
| 521 | } |
| 522 | pNew->isExe = pFile->isExe; |
| 523 | pNew->zUuid = import_strdup(pFile->zUuid); |
| 524 | pNew->isFrom = 0; |
| 525 | } |
| 526 | }else |
| 527 | if( memcmp(zLine, "R ", 2)==0 ){ |
| 528 | int nFrom; |
| 529 | import_prior_files(); |
| @@ -512,20 +531,22 @@ | |
| 531 | zFrom = next_token(&z); |
| 532 | zTo = next_token(&z); |
| 533 | i = 0; |
| 534 | nFrom = strlen(zFrom); |
| 535 | while( (pFile = import_find_file(zFrom, &i, gg.nFile))!=0 ){ |
| 536 | if( pFile->isFrom==0 ) continue; |
| 537 | pNew = import_add_file(); |
| 538 | pFile = &gg.aFile[i-1]; |
| 539 | if( strlen(pFile->zName)>nFrom ){ |
| 540 | pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]); |
| 541 | }else{ |
| 542 | pNew->zName = import_strdup(pFile->zName); |
| 543 | } |
| 544 | pNew->zPrior = pFile->zName; |
| 545 | pNew->isExe = pFile->isExe; |
| 546 | pNew->zUuid = pFile->zUuid; |
| 547 | pNew->isFrom = 0; |
| 548 | gg.nFile--; |
| 549 | *pFile = *pNew; |
| 550 | memset(pNew, 0, sizeof(*pNew)); |
| 551 | } |
| 552 | fossil_fatal("cannot handle R records, use --full-tree"); |
| 553 |
+5
| --- src/manifest.c | ||
| +++ src/manifest.c | ||
| @@ -1472,10 +1472,15 @@ | ||
| 1472 | 1472 | while( db_step(&q)==SQLITE_ROW ){ |
| 1473 | 1473 | int cid = db_column_int(&q, 0); |
| 1474 | 1474 | add_mlink(rid, p, cid, 0); |
| 1475 | 1475 | } |
| 1476 | 1476 | db_finalize(&q); |
| 1477 | + if( p->nParent==0 ){ | |
| 1478 | + for(i=0; i<p->nFile; i++){ | |
| 1479 | + add_one_mlink(rid, 0, p->aFile[i].zUuid, p->aFile[i].zName, 0); | |
| 1480 | + } | |
| 1481 | + } | |
| 1477 | 1482 | db_multi_exec( |
| 1478 | 1483 | "REPLACE INTO event(type,mtime,objid,user,comment," |
| 1479 | 1484 | "bgcolor,euser,ecomment)" |
| 1480 | 1485 | "VALUES('ci'," |
| 1481 | 1486 | " coalesce(" |
| 1482 | 1487 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -1472,10 +1472,15 @@ | |
| 1472 | while( db_step(&q)==SQLITE_ROW ){ |
| 1473 | int cid = db_column_int(&q, 0); |
| 1474 | add_mlink(rid, p, cid, 0); |
| 1475 | } |
| 1476 | db_finalize(&q); |
| 1477 | db_multi_exec( |
| 1478 | "REPLACE INTO event(type,mtime,objid,user,comment," |
| 1479 | "bgcolor,euser,ecomment)" |
| 1480 | "VALUES('ci'," |
| 1481 | " coalesce(" |
| 1482 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -1472,10 +1472,15 @@ | |
| 1472 | while( db_step(&q)==SQLITE_ROW ){ |
| 1473 | int cid = db_column_int(&q, 0); |
| 1474 | add_mlink(rid, p, cid, 0); |
| 1475 | } |
| 1476 | db_finalize(&q); |
| 1477 | if( p->nParent==0 ){ |
| 1478 | for(i=0; i<p->nFile; i++){ |
| 1479 | add_one_mlink(rid, 0, p->aFile[i].zUuid, p->aFile[i].zName, 0); |
| 1480 | } |
| 1481 | } |
| 1482 | db_multi_exec( |
| 1483 | "REPLACE INTO event(type,mtime,objid,user,comment," |
| 1484 | "bgcolor,euser,ecomment)" |
| 1485 | "VALUES('ci'," |
| 1486 | " coalesce(" |
| 1487 |