Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | The "fossil import" command works well enough to import the Git self-hosting repository. There are still issues and no doubt many bugs yet to be found. But this is a good start. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
6c827ff02e9b14f6c2659e25ec5d1dcf |
| User & Date: | drh 2010-11-10 00:43:32.000 |
Context
|
2010-11-10
| ||
| 01:43 | Tweak check-in times slightly so that parents always come before their children. ... (check-in: 0e87f42762 user: drh tags: trunk) | |
| 00:43 | The "fossil import" command works well enough to import the Git self-hosting repository. There are still issues and no doubt many bugs yet to be found. But this is a good start. ... (check-in: 6c827ff02e user: drh tags: trunk) | |
|
2010-11-09
| ||
| 18:15 | Partial implementation of the "fossil import" command. It is incomplete and does not work. ... (check-in: ba837f5e88 user: drh tags: trunk) | |
Changes
Changes to src/import.c.
| ︙ | ︙ | |||
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
char *zFrom; /* from value */
int nMerge; /* Number of merge values */
int nMergeAlloc; /* Number of slots in azMerge[] */
char **azMerge; /* Merge values */
int nFile; /* Number of aFile values */
int nFileAlloc; /* Number of slots in aFile[] */
ManifestFile *aFile; /* Information about files in a commit */
} gg;
/*
** A no-op "xFinish" method
*/
static void finish_noop(void){}
| > | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
char *zFrom; /* from value */
int nMerge; /* Number of merge values */
int nMergeAlloc; /* Number of slots in azMerge[] */
char **azMerge; /* Merge values */
int nFile; /* Number of aFile values */
int nFileAlloc; /* Number of slots in aFile[] */
ManifestFile *aFile; /* Information about files in a commit */
int fromLoaded; /* True zFrom content loaded into aFile[] */
} gg;
/*
** A no-op "xFinish" method
*/
static void finish_noop(void){}
|
| ︙ | ︙ | |||
147 148 149 150 151 152 153 |
** Use data accumulated in gg from a "tag" record to add a new
** control artifact to the BLOB table.
*/
static void finish_tag(void){
Blob record, cksum;
if( gg.zDate && gg.zTag && gg.zFrom && gg.zUser ){
blob_zero(&record);
| | > > > > > > > > > | > > > > > > > > > | > | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > | | 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 186 187 188 189 190 191 192 193 194 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 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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 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 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 |
** Use data accumulated in gg from a "tag" record to add a new
** control artifact to the BLOB table.
*/
static void finish_tag(void){
Blob record, cksum;
if( gg.zDate && gg.zTag && gg.zFrom && gg.zUser ){
blob_zero(&record);
blob_appendf(&record, "D %s\n", gg.zDate);
blob_appendf(&record, "T +%F %s\n", gg.zTag, gg.zFrom);
blob_appendf(&record, "U %F\n", gg.zUser);
md5sum_blob(&record, &cksum);
blob_appendf(&record, "Z %b\n", &cksum);
fast_insert_content(&record, 0);
blob_reset(&record);
blob_reset(&cksum);
}
import_reset(0);
}
/*
** Compare two ManifestFile objects for sorting
*/
static int mfile_cmp(const void *pLeft, const void *pRight){
const ManifestFile *pA = (const ManifestFile*)pLeft;
const ManifestFile *pB = (const ManifestFile*)pRight;
return strcmp(pA->zName, pB->zName);
}
/*
** Use data accumulated in gg from a "commit" record to add a new
** manifest artifact to the BLOB table.
*/
static void finish_commit(void){
int i;
Blob record, cksum;
qsort(gg.aFile, gg.nFile, sizeof(gg.aFile[0]), mfile_cmp);
blob_zero(&record);
blob_appendf(&record, "C %F\n", gg.zComment);
blob_appendf(&record, "D %s\n", gg.zDate);
for(i=0; i<gg.nFile; i++){
blob_appendf(&record, "F %F %s", gg.aFile[i].zName, gg.aFile[i].zUuid);
if( gg.aFile[i].zPerm && gg.aFile[i].zPerm[0] ){
blob_appendf(&record, " %s\n", gg.aFile[i].zPerm);
}else{
blob_append(&record, "\n", 1);
}
}
if( gg.zFrom ){
blob_appendf(&record, "P %s", gg.zFrom);
for(i=0; i<gg.nMerge; i++){
blob_appendf(&record, " %s", gg.azMerge[i]);
}
blob_append(&record, "\n", 1);
}
blob_appendf(&record, "U %F\n", gg.zUser);
md5sum_blob(&record, &cksum);
blob_appendf(&record, "Z %b\n", &cksum);
fast_insert_content(&record, gg.zMark);
blob_reset(&record);
blob_reset(&cksum);
import_reset(0);
import_reset(0);
}
/*
** Turn the first \n in the input string into a \000
*/
static void trim_newline(char *z){
while( z[0] && z[0]!='\n' ){ z++; }
z[0] = 0;
}
/*
** Duplicate a string.
*/
static char *import_strdup(const char *zOrig){
char *z = 0;
if( zOrig ){
int n = strlen(zOrig);
z = fossil_malloc( n+1 );
memcpy(z, zOrig, n+1);
}
return z;
}
/*
** Get a token from a line of text. Return a pointer to the first
** character of the token and zero-terminate the token. Make
** *pzIn point to the first character past the end of the zero
** terminator, or at the zero-terminator at EOL.
*/
static char *next_token(char **pzIn){
char *z = *pzIn;
int i;
if( z[0]==0 ) return z;
for(i=0; z[i] && z[i]!=' ' && z[i]!='\n'; i++){}
if( z[i] ){
z[i] = 0;
*pzIn = &z[i+1];
}else{
*pzIn = &z[i];
}
return z;
}
/*
** Convert a "mark" or "committish" into the UUID.
*/
static char *resolve_committish(const char *zCommittish){
char *zRes;
zRes = db_text(0, "SELECT tuuid FROM xtag WHERE tname=%Q", zCommittish);
return zRes;
}
/*
** Create a new entry in the gg.aFile[] array
*/
static ManifestFile *import_add_file(void){
ManifestFile *pFile;
if( gg.nFile>=gg.nFileAlloc ){
gg.nFileAlloc = gg.nFileAlloc*2 + 100;
gg.aFile = fossil_realloc(gg.aFile, gg.nFileAlloc*sizeof(gg.aFile[0]));
}
pFile = &gg.aFile[gg.nFile++];
memset(pFile, 0, sizeof(*pFile));
return pFile;
}
/*
** Load all file information out of the gg.zFrom check-in
*/
static void import_prior_files(void){
Manifest *p;
int rid;
ManifestFile *pOld, *pNew;
if( gg.fromLoaded ) return;
gg.fromLoaded = 1;
if( gg.zFrom==0 ) return;
rid = fast_uuid_to_rid(gg.zFrom);
if( rid==0 ) return;
p = manifest_get(rid, CFTYPE_MANIFEST);
if( p==0 ) return;
manifest_file_rewind(p);
while( (pOld = manifest_file_next(p, 0))!=0 ){
pNew = import_add_file();
pNew->zName = import_strdup(pOld->zName);
pNew->zPerm = import_strdup(pOld->zPerm);
pNew->zUuid = import_strdup(pOld->zUuid);
}
manifest_destroy(p);
}
/*
** Locate a file in the gg.aFile[] array by its name. Begin the search
** with the *pI-th file. Update *pI to be one past the file found.
** Do not search past the mx-th file.
*/
static ManifestFile *import_find_file(const char *zName, int *pI, int mx){
int i = *pI;
int nName = strlen(zName);
while( i<mx ){
const char *z = gg.aFile[i].zName;
if( memcmp(zName, z, nName)==0 && (z[nName]==0 || z[nName]=='/') ){
*pI = i+1;
return &gg.aFile[i];
}
i++;
}
return 0;
}
/*
** Read the git-fast-import format from pIn and insert the corresponding
** content into the database.
*/
static void git_fast_import(FILE *pIn){
ManifestFile *pFile;
int i, mx;
char *z;
char *zUuid;
char *zName;
char *zPerm;
char *zFrom;
char *zTo;
char zLine[1000];
gg.xFinish = finish_noop;
while( fgets(zLine, sizeof(zLine), pIn) ){
if( zLine[0]=='\n' || zLine[0]=='#' ) continue;
if( memcmp(zLine, "blob", 4)==0 ){
gg.xFinish();
gg.xFinish = finish_blob;
}else
if( memcmp(zLine, "commit ", 7)==0 ){
gg.xFinish();
gg.xFinish = finish_commit;
trim_newline(&zLine[7]);
z = &zLine[7];
for(i=strlen(z)-1; i>=0 && z[i]!='/'; i--){}
if( z[i+1]!=0 ) z += i+1;
gg.zBranch = import_strdup(z);
gg.fromLoaded = 0;
}else
if( memcmp(zLine, "tag ", 4)==0 ){
gg.xFinish();
gg.xFinish = finish_tag;
trim_newline(&zLine[4]);
gg.zTag = import_strdup(&zLine[4]);
}else
if( memcmp(zLine, "reset ", 4)==0 ){
gg.xFinish();
}else
if( memcmp(zLine, "checkpoint", 10)==0 ){
gg.xFinish();
}else
|
| ︙ | ︙ | |||
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
if( gg.nData ){
int got;
gg.aData = fossil_malloc( gg.nData+1 );
got = fread(gg.aData, 1, gg.nData, pIn);
if( got!=gg.nData ){
fossil_fatal("short read: got %d of %d bytes", got, gg.nData);
}
if( gg.zComment==0 && gg.xFinish==finish_commit ){
gg.zComment = gg.aData;
gg.aData = 0;
gg.nData = 0;
}
}
}else
if( memcmp(zLine, "author ", 7)==0 ){
/* No-op */
}else
if( memcmp(zLine, "mark ", 5)==0 ){
trim_newline(&zLine[5]);
fossil_free(gg.zMark);
| > | | < < < | | | 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 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 |
if( gg.nData ){
int got;
gg.aData = fossil_malloc( gg.nData+1 );
got = fread(gg.aData, 1, gg.nData, pIn);
if( got!=gg.nData ){
fossil_fatal("short read: got %d of %d bytes", got, gg.nData);
}
gg.aData[got] = 0;
if( gg.zComment==0 && gg.xFinish==finish_commit ){
gg.zComment = gg.aData;
gg.aData = 0;
gg.nData = 0;
}
}
}else
if( memcmp(zLine, "author ", 7)==0 ){
/* No-op */
}else
if( memcmp(zLine, "mark ", 5)==0 ){
trim_newline(&zLine[5]);
fossil_free(gg.zMark);
gg.zMark = import_strdup(&zLine[5]);
}else
if( memcmp(zLine, "tagger ", 7)==0 || memcmp(zLine, "committer ",10)==0 ){
sqlite3_int64 secSince1970;
for(i=0; zLine[i] && zLine[i]!='<'; i++){}
if( zLine[i]==0 ) goto malformed_line;
z = &zLine[i+1];
for(i=i+1; zLine[i] && zLine[i]!='>'; i++){}
if( zLine[i]==0 ) goto malformed_line;
zLine[i] = 0;
fossil_free(gg.zUser);
gg.zUser = import_strdup(z);
secSince1970 = 0;
for(i=i+2; fossil_isdigit(zLine[i]); i++){
secSince1970 = secSince1970*10 + zLine[i] - '0';
}
fossil_free(gg.zDate);
gg.zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", secSince1970);
gg.zDate[10] = 'T';
}else
if( memcmp(zLine, "from ", 5)==0 ){
|
| ︙ | ︙ | |||
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
gg.nMergeAlloc = gg.nMergeAlloc*2 + 10;
gg.azMerge = fossil_realloc(gg.azMerge, gg.nMergeAlloc*sizeof(char*));
}
gg.azMerge[gg.nMerge] = resolve_committish(&zLine[5]);
if( gg.azMerge[gg.nMerge] ) gg.nMerge++;
}else
if( memcmp(zLine, "M ", 2)==0 ){
}else
if( memcmp(zLine, "D ", 2)==0 ){
}else
if( memcmp(zLine, "C ", 2)==0 ){
}else
if( memcmp(zLine, "R ", 2)==0 ){
}else
if( memcmp(zLine, "deleteall", 9)==0 ){
}else
if( memcmp(zLine, "N ", 2)==0 ){
}else
{
goto malformed_line;
}
}
gg.xFinish();
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
gg.nMergeAlloc = gg.nMergeAlloc*2 + 10;
gg.azMerge = fossil_realloc(gg.azMerge, gg.nMergeAlloc*sizeof(char*));
}
gg.azMerge[gg.nMerge] = resolve_committish(&zLine[5]);
if( gg.azMerge[gg.nMerge] ) gg.nMerge++;
}else
if( memcmp(zLine, "M ", 2)==0 ){
import_prior_files();
z = &zLine[2];
zPerm = next_token(&z);
zUuid = next_token(&z);
zName = next_token(&z);
i = 0;
pFile = import_find_file(zName, &i, gg.nFile);
if( pFile==0 ){
pFile = import_add_file();
pFile->zName = import_strdup(zName);
}
if( strcmp(zPerm, "100755")==0 ){
pFile->zPerm = mprintf("x");
}
pFile->zUuid = resolve_committish(zUuid);
}else
if( memcmp(zLine, "D ", 2)==0 ){
import_prior_files();
z = &zLine[2];
zName = next_token(&z);
i = 0;
while( (pFile = import_find_file(zName, &i, gg.nFile))!=0 ){
fossil_free(pFile->zName);
fossil_free(pFile->zPerm);
fossil_free(pFile->zUuid);
*pFile = gg.aFile[--gg.nFile];
i--;
}
}else
if( memcmp(zLine, "C ", 2)==0 ){
int nFrom;
import_prior_files();
z = &zLine[2];
zFrom = next_token(&z);
zTo = next_token(&z);
i = 0;
mx = gg.nFile;
nFrom = strlen(zFrom);
while( (pFile = import_find_file(zFrom, &i, mx))!=0 ){
ManifestFile *pNew = import_add_file();
pFile = &gg.aFile[i-1];
if( strlen(pFile->zName)>nFrom ){
pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
}else{
pNew->zName = import_strdup(pFile->zName);
}
pNew->zPerm = import_strdup(pFile->zPerm);
pNew->zUuid = import_strdup(pFile->zUuid);
}
}else
if( memcmp(zLine, "R ", 2)==0 ){
int nFrom;
import_prior_files();
z = &zLine[2];
zFrom = next_token(&z);
zTo = next_token(&z);
i = 0;
nFrom = strlen(zFrom);
while( (pFile = import_find_file(zFrom, &i, gg.nFile))!=0 ){
ManifestFile *pNew = import_add_file();
pFile = &gg.aFile[i-1];
if( strlen(pFile->zName)>nFrom ){
pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
}else{
pNew->zName = import_strdup(pFile->zName);
}
pNew->zPrior = pFile->zName;
pNew->zPerm = pFile->zPerm;
pNew->zUuid = pFile->zUuid;
gg.nFile--;
*pFile = *pNew;
memset(pNew, 0, sizeof(*pNew));
}
fossil_fatal("cannot handle R records, use --full-tree");
}else
if( memcmp(zLine, "deleteall", 9)==0 ){
gg.fromLoaded = 1;
}else
if( memcmp(zLine, "N ", 2)==0 ){
/* No-op */
}else
{
goto malformed_line;
}
}
gg.xFinish();
|
| ︙ | ︙ | |||
329 330 331 332 333 334 335 |
**
** Read text generated by the git-fast-export command and use it to
** construct a new Fossil repository named by the NEW-REPOSITORY
** argument. The get-fast-export text is read from standard input.
*/
void git_import_cmd(void){
char *zPassword;
| | | > > > > > | > > < | 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
**
** Read text generated by the git-fast-export command and use it to
** construct a new Fossil repository named by the NEW-REPOSITORY
** argument. The get-fast-export text is read from standard input.
*/
void git_import_cmd(void){
char *zPassword;
FILE *pIn;
if( g.argc!=3 && g.argc!=4 ){
usage("REPOSITORY-NAME");
}
if( g.argc==4 ){
pIn = fopen(g.argv[3], "rb");
}else{
pIn = stdin;
}
db_create_repository(g.argv[2]);
db_open_repository(g.argv[2]);
db_open_config(0);
db_multi_exec(
"ATTACH ':memory:' AS mem1;"
"CREATE TABLE mem1.xtag(tname TEXT UNIQUE, trid INT, tuuid TEXT);"
);
db_begin_transaction();
db_initial_setup(0, 0, 1);
git_fast_import(pIn);
db_end_transaction(0);
db_begin_transaction();
printf("Rebuilding repository meta-data...\n");
rebuild_db(0, 1);
verify_cancel();
db_end_transaction(0);
printf("Vacuuming..."); fflush(stdout);
db_multi_exec("VACUUM");
printf(" ok\n");
printf("project-id: %s\n", db_get("project-code", 0));
printf("server-id: %s\n", db_get("server-code", 0));
zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
printf("admin-user: %s (password is \"%s\")\n", g.zLogin, zPassword);
}
|