Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch nick.lloyd-git-interop Excluding Merge-Ins
This is equivalent to a diff from 3ca2bc105a to b2e0fda9e1
|
2016-10-26
| ||
| 21:28 | Fixes for incremental Git import/export. check-in: 27c8985cc1 user: mistachkin tags: trunk | |
|
2016-10-23
| ||
| 02:16 | Fixes for incremental Git import/export. check-in: 9599705c69 user: mistachkin tags: experimental | |
|
2016-10-08
| ||
| 14:06 | Fix a regression introduced in [69668f8c57] that broke export of tags. Closed-Leaf check-in: b2e0fda9e1 user: nick.lloyd tags: nick.lloyd-git-interop | |
| 13:42 | Add missing arguments to Git->Fossil import example. check-in: 880e3fb51f user: nick.lloyd tags: nick.lloyd-git-interop | |
|
2016-09-23
| ||
| 13:53 | Add the help_to_html() routine which transforms plaintext help into HTML for display on web pages. So far it only surrounds the text with <pre>..</pre>. But it can (in theory) be enhanced to do more sophisticated formatting. check-in: 7a69e5db64 user: drh tags: trunk | |
| 07:33 | merge trunk. Update references to OpenSSL 1.1.0a check-in: 85f8133ce7 user: jan.nijtmans tags: openssl-1.1 | |
| 02:40 | Merge updates from trunk. check-in: 98f4ee8f71 user: mistachkin tags: nick.lloyd-git-interop | |
| 02:28 | Merge updates from trunk. check-in: 4f619c020a user: mistachkin tags: seeEnhanced | |
| 02:27 | Merge updates from trunk. check-in: 0934366187 user: mistachkin tags: jan-manifest-tags | |
| 02:10 | Clarify the exact type used for cmdFlags. check-in: 3ca2bc105a user: mistachkin tags: trunk | |
| 02:06 | Missed a couple places with the old OpenSSL version reference. check-in: a29e05d1ef user: mistachkin tags: trunk | |
Changes to src/export.c.
| ︙ | ︙ | |||
130 131 132 133 134 135 136 137 138 139 140 | ); } /* ** create_mark() ** Create a new (mark,rid,uuid) entry for the given rid in the 'xmark' table, ** and return that information as a struct mark_t in *mark. ** This function returns -1 in the case where 'rid' does not exist, otherwise ** it returns 0. ** mark->name is dynamically allocated and is owned by the caller upon return. */ | > > > > | | | > > > > | | | | | | > | | > | > > > > > > > | | | > > > | | < < | > | | > > > > > > > > > > > > > > > > > > > > > > > > > | | | < < < < < < < | < < | 130 131 132 133 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 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 |
);
}
/*
** create_mark()
** Create a new (mark,rid,uuid) entry for the given rid in the 'xmark' table,
** and return that information as a struct mark_t in *mark.
** *unused_mark is a value representing a mark that is free for use--that is,
** it does not appear in the marks file, and has not been used during this
** export run. Specifically, it is the supremum of the set of used marks
** plus one.
** This function returns -1 in the case where 'rid' does not exist, otherwise
** it returns 0.
** mark->name is dynamically allocated and is owned by the caller upon return.
*/
int create_mark(int rid, struct mark_t *mark, unsigned int *unused_mark){
char sid[13];
char *zUuid = rid_to_uuid(rid);
if( !zUuid ){
fossil_trace("Undefined rid=%d\n", rid);
return -1;
}
mark->rid = rid;
sqlite3_snprintf(sizeof(sid), sid, ":%d", *unused_mark);
*unused_mark += 1;
mark->name = fossil_strdup(sid);
sqlite3_snprintf(sizeof(mark->uuid), mark->uuid, "%s", zUuid);
free(zUuid);
insert_commit_xref(mark->rid, mark->name, mark->uuid);
return 0;
}
/*
** mark_name_from_rid()
** Find the mark associated with the given rid. Mark names always start
** with ':', and are pulled from the 'xmark' temporary table.
** If the given rid doesn't have a mark associated with it yet, one is
** created with a value of *unused_mark.
** *unused_mark functions exactly as in create_mark().
** This function returns NULL if the rid does not have an associated UUID,
** (i.e. is not valid). Otherwise, it returns the name of the mark, which is
** dynamically allocated and is owned by the caller of this function.
*/
char * mark_name_from_rid(int rid, unsigned int *unused_mark){
char *zMark = db_text(0, "SELECT tname FROM xmark WHERE trid=%d", rid);
if( zMark==NULL ){
struct mark_t mark;
if( create_mark(rid, &mark, unused_mark)==0 ){
zMark = mark.name;
}else{
return NULL;
}
}
return zMark;
}
/*
** parse_mark()
** Create a new (mark,rid,uuid) entry in the 'xmark' table given a line
** from a marks file. Return the cross-ref information as a struct mark_t
** in *mark.
** This function returns -1 in the case that the line is blank, malformed, or
** the rid/uuid named in 'line' does not match what is in the repository
** database. Otherwise, 0 is returned.
** mark->name is dynamically allocated, and owned by the caller.
*/
int parse_mark(char *line, struct mark_t *mark){
char *cur_tok;
char type_;
cur_tok = strtok(line, " \t");
if( !cur_tok || strlen(cur_tok)<2 ){
return -1;
}
mark->rid = atoi(&cur_tok[1]);
type_ = cur_tok[0];
if( type_!='c' && type_!='b' ){
/* This is probably a blob mark */
mark->name = NULL;
return 0;
}
cur_tok = strtok(NULL, " \t");
if( !cur_tok ){
/* This mark was generated by an older version of Fossil and doesn't
** include the mark name and uuid. create_mark() will name the new mark
** exactly as it was when exported to git, so that we should have a
** valid mapping from git sha1<->mark name<->fossil sha1. */
unsigned int mid;
if( type_=='c' ){
mid = COMMITMARK(mark->rid);
}
else{
mid = BLOBMARK(mark->rid);
}
return create_mark(mark->rid, mark, &mid);
}else{
mark->name = fossil_strdup(cur_tok);
}
cur_tok = strtok(NULL, "\n");
if( !cur_tok || strlen(cur_tok)!=40 ){
free(mark->name);
fossil_trace("Invalid SHA-1 in marks file: %s\n", cur_tok);
return -1;
}else{
sqlite3_snprintf(sizeof(mark->uuid), mark->uuid, "%s", cur_tok);
}
/* make sure that rid corresponds to UUID */
if( fast_uuid_to_rid(mark->uuid)!=mark->rid ){
free(mark->name);
fossil_trace("Non-existent SHA-1 in marks file: %s\n", mark->uuid);
return -1;
}
/* insert a cross-ref into the 'xmark' table */
insert_commit_xref(mark->rid, mark->name, mark->uuid);
return 0;
}
/*
** import_marks()
** Import the marks specified in file 'f' into the 'xmark' table.
** If 'blobs' is non-null, insert all blob marks into it.
** If 'vers' is non-null, insert all commit marks into it.
** If 'unused_marks' is non-null, upon return of this function, all values
** x >= *unused_marks are free to use as marks, i.e. they do not clash with
** any marks appearing in the marks file.
** Each line in the file must be at most 100 characters in length. This
** seems like a reasonable maximum for a 40-character uuid, and 1-13
** character rid.
** The function returns -1 if any of the lines in file 'f' are malformed,
** or the rid/uuid information doesn't match what is in the repository
** database. Otherwise, 0 is returned.
*/
int import_marks(FILE* f, Bag *blobs, Bag *vers, unsigned int *unused_mark){
char line[101];
while(fgets(line, sizeof(line), f)){
struct mark_t mark;
if( strlen(line)==100 && line[99]!='\n' ){
/* line too long */
return -1;
}
if( parse_mark(line, &mark)<0 ){
return -1;
}else if( line[0]=='b' ){
if( blobs!=NULL ){
bag_insert(blobs, mark.rid);
}
}else{
if( vers!=NULL ){
bag_insert(vers, mark.rid);
}
}
if( unused_mark!=NULL ){
unsigned int mid = atoi(mark.name + 1);
if( mid>=*unused_mark ){
*unused_mark = mid + 1;
}
}
free(mark.name);
}
return 0;
}
void export_mark(FILE* f, int rid, char obj_type)
{
unsigned int z = 0;
char *zUuid = rid_to_uuid(rid);
char *zMark;
if( zUuid==NULL ){
fossil_trace("No uuid matching rid=%d when exporting marks\n", rid);
return;
}
/* Since rid is already in the 'xmark' table, the value of z won't be
** used, but pass in a valid pointer just to be safe. */
zMark = mark_name_from_rid(rid, &z);
fprintf(f, "%c%d %s %s\n", obj_type, rid, zMark, zUuid);
free(zMark);
free(zUuid);
}
/*
** If 'blobs' is non-null, it must point to a Bag of blob rids to be
** written to disk. Blob rids are written as 'b<rid>'.
** If 'vers' is non-null, it must point to a Bag of commit rids to be
** written to disk. Commit rids are written as 'c<rid> :<mark> <uuid>'.
** All commit (mark,rid,uuid) tuples are stored in 'xmark' table.
** This function does not fail, but may produce errors if a uuid cannot
** be found for an rid in 'vers'.
*/
void export_marks(FILE* f, Bag *blobs, Bag *vers){
int rid;
if( blobs!=NULL ){
rid = bag_first(blobs);
if( rid!=0 ){
do{
export_mark(f, rid, 'b');
}while( (rid = bag_next(blobs, rid))!=0 );
}
}
if( vers!=NULL ){
rid = bag_first(vers);
if( rid!=0 ){
do{
export_mark(f, rid, 'c');
}while( (rid = bag_next(vers, rid))!=0 );
}
}
}
/*
** COMMAND: export
|
| ︙ | ︙ | |||
334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
**
** See also: import
*/
void export_cmd(void){
Stmt q, q2, q3;
int i;
Bag blobs, vers;
const char *markfile_in;
const char *markfile_out;
bag_init(&blobs);
bag_init(&vers);
find_option("git", 0, 0); /* Ignore the --git option for now */
| > | 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
**
** See also: import
*/
void export_cmd(void){
Stmt q, q2, q3;
int i;
Bag blobs, vers;
unsigned int unused_mark = 1;
const char *markfile_in;
const char *markfile_out;
bag_init(&blobs);
bag_init(&vers);
find_option("git", 0, 0); /* Ignore the --git option for now */
|
| ︙ | ︙ | |||
360 361 362 363 364 365 366 |
FILE *f;
int rid;
f = fossil_fopen(markfile_in, "r");
if( f==0 ){
fossil_fatal("cannot open %s for reading", markfile_in);
}
| | | | | 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 |
FILE *f;
int rid;
f = fossil_fopen(markfile_in, "r");
if( f==0 ){
fossil_fatal("cannot open %s for reading", markfile_in);
}
if( import_marks(f, &blobs, &vers, &unused_mark)<0 ){
fossil_fatal("error importing marks from file: %s\n", markfile_in);
}
db_prepare(&qb, "INSERT OR IGNORE INTO oldblob VALUES (:rid)");
db_prepare(&qc, "INSERT OR IGNORE INTO oldcommit VALUES (:rid)");
rid = bag_first(&blobs);
if( rid!=0 ){
do{
db_bind_int(&qb, ":rid", rid);
db_step(&qb);
db_reset(&qb);
}while((rid = bag_next(&blobs, rid))!=0);
}
rid = bag_first(&vers);
if( rid!=0 ){
do{
db_bind_int(&qc, ":rid", rid);
db_step(&qc);
db_reset(&qc);
}while((rid = bag_next(&vers, rid))!=0);
}
db_finalize(&qb);
|
| ︙ | ︙ | |||
414 415 416 417 418 419 420 421 422 423 424 |
db_prepare(&q2, "INSERT INTO oldblob VALUES (:rid)");
db_prepare(&q3, "SELECT rid FROM newblob WHERE srcid= (:srcid)");
while( db_step(&q)==SQLITE_ROW ){
int rid = db_column_int(&q, 0);
Blob content;
while( !bag_find(&blobs, rid) ){
content_get(rid, &content);
db_bind_int(&q2, ":rid", rid);
db_step(&q2);
db_reset(&q2);
| > > | > | 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
db_prepare(&q2, "INSERT INTO oldblob VALUES (:rid)");
db_prepare(&q3, "SELECT rid FROM newblob WHERE srcid= (:srcid)");
while( db_step(&q)==SQLITE_ROW ){
int rid = db_column_int(&q, 0);
Blob content;
while( !bag_find(&blobs, rid) ){
char *zMark;
content_get(rid, &content);
db_bind_int(&q2, ":rid", rid);
db_step(&q2);
db_reset(&q2);
zMark = mark_name_from_rid(rid, &unused_mark);
printf("blob\nmark %s\ndata %d\n", zMark, blob_size(&content));
free(zMark);
bag_insert(&blobs, rid);
fwrite(blob_buffer(&content), 1, blob_size(&content), stdout);
printf("\n");
blob_reset(&content);
db_bind_int(&q3, ":srcid", rid);
if( db_step(&q3) != SQLITE_ROW ){
|
| ︙ | ︙ | |||
468 469 470 471 472 473 474 |
db_step(&q2);
db_reset(&q2);
if( zBranch==0 ) zBranch = "trunk";
zBr = mprintf("%s", zBranch);
for(i=0; zBr[i]; i++){
if( !fossil_isalnum(zBr[i]) ) zBr[i] = '_';
}
| | | | | | > | > | 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 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 577 578 |
db_step(&q2);
db_reset(&q2);
if( zBranch==0 ) zBranch = "trunk";
zBr = mprintf("%s", zBranch);
for(i=0; zBr[i]; i++){
if( !fossil_isalnum(zBr[i]) ) zBr[i] = '_';
}
zMark = mark_name_from_rid(ckinId, &unused_mark);
printf("commit refs/heads/%s\nmark %s\n", zBr, zMark);
free(zMark);
free(zBr);
printf("committer");
print_person(zUser);
printf(" %s +0000\n", zSecondsSince1970);
if( zComment==0 ) zComment = "null comment";
printf("data %d\n%s\n", (int)strlen(zComment), zComment);
db_prepare(&q3,
"SELECT pid FROM plink"
" WHERE cid=%d AND isprim"
" AND pid IN (SELECT objid FROM event)",
ckinId
);
if( db_step(&q3) == SQLITE_ROW ){
int pid = db_column_int(&q3, 0);
zMark = mark_name_from_rid(pid, &unused_mark);
printf("from %s\n", zMark);
free(zMark);
db_prepare(&q4,
"SELECT pid FROM plink"
" WHERE cid=%d AND NOT isprim"
" AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=pid)"
" ORDER BY pid",
ckinId);
while( db_step(&q4)==SQLITE_ROW ){
zMark = mark_name_from_rid(db_column_int(&q4, 0), &unused_mark);
printf("merge %s\n", zMark);
free(zMark);
}
db_finalize(&q4);
}else{
printf("deleteall\n");
}
db_prepare(&q4,
"SELECT filename.name, mlink.fid, mlink.mperm FROM mlink"
" JOIN filename ON filename.fnid=mlink.fnid"
" WHERE mlink.mid=%d",
ckinId
);
while( db_step(&q4)==SQLITE_ROW ){
const char *zName = db_column_text(&q4,0);
int zNew = db_column_int(&q4,1);
int mPerm = db_column_int(&q4,2);
if( zNew==0 ){
printf("D %s\n", zName);
}else if( bag_find(&blobs, zNew) ){
zMark = mark_name_from_rid(zNew, &unused_mark);
const char *zPerm;
switch( mPerm ){
case PERM_LNK: zPerm = "120000"; break;
case PERM_EXE: zPerm = "100755"; break;
default: zPerm = "100644"; break;
}
printf("M %s %s %s\n", zPerm, zMark, zName);
free(zMark);
}
}
db_finalize(&q4);
db_finalize(&q3);
printf("\n");
}
db_finalize(&q2);
|
| ︙ | ︙ | |||
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
" FROM tagxref JOIN tag USING(tagid)"
" WHERE tagtype=1 AND tagname GLOB 'sym-*'"
);
while( db_step(&q)==SQLITE_ROW ){
const char *zTagname = db_column_text(&q, 0);
char *zEncoded = 0;
int rid = db_column_int(&q, 1);
const char *zSecSince1970 = db_column_text(&q, 2);
int i;
if( rid==0 || !bag_find(&vers, rid) ) continue;
zTagname += 4;
zEncoded = mprintf("%s", zTagname);
for(i=0; zEncoded[i]; i++){
if( !fossil_isalnum(zEncoded[i]) ) zEncoded[i] = '_';
}
printf("tag %s\n", zEncoded);
| > | > | | 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 |
" FROM tagxref JOIN tag USING(tagid)"
" WHERE tagtype=1 AND tagname GLOB 'sym-*'"
);
while( db_step(&q)==SQLITE_ROW ){
const char *zTagname = db_column_text(&q, 0);
char *zEncoded = 0;
int rid = db_column_int(&q, 1);
char *zMark = mark_name_from_rid(rid, &unused_mark);
const char *zSecSince1970 = db_column_text(&q, 2);
int i;
if( rid==0 || !bag_find(&vers, rid) ) continue;
zTagname += 4;
zEncoded = mprintf("%s", zTagname);
for(i=0; zEncoded[i]; i++){
if( !fossil_isalnum(zEncoded[i]) ) zEncoded[i] = '_';
}
printf("tag %s\n", zEncoded);
printf("from %s\n", zMark);
free(zMark);
printf("tagger <tagger> %s +0000\n", zSecSince1970);
printf("data 0\n");
fossil_free(zEncoded);
}
db_finalize(&q);
if( markfile_out!=0 ){
FILE *f;
f = fossil_fopen(markfile_out, "w");
if( f == 0 ){
fossil_fatal("cannot open %s for writing", markfile_out);
}
export_marks(f, &blobs, &vers);
if( ferror(f)!=0 || fclose(f)!=0 ){
fossil_fatal("error while writing %s", markfile_out);
}
}
bag_clear(&blobs);
bag_clear(&vers);
}
|
Changes to src/import.c.
| ︙ | ︙ | |||
1768 1769 1770 1771 1772 1773 1774 |
);
if( markfile_in ){
FILE *f = fossil_fopen(markfile_in, "r");
if( !f ){
fossil_fatal("cannot open %s for reading\n", markfile_in);
}
| | | 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 |
);
if( markfile_in ){
FILE *f = fossil_fopen(markfile_in, "r");
if( !f ){
fossil_fatal("cannot open %s for reading\n", markfile_in);
}
if( import_marks(f, &blobs, NULL, NULL)<0 ){
fossil_fatal("error importing marks from file: %s\n", markfile_in);
}
fclose(f);
}
manifest_crosslink_begin();
git_fast_import(pIn);
|
| ︙ | ︙ | |||
1793 1794 1795 1796 1797 1798 1799 |
Stmt q_marks;
FILE *f;
db_prepare(&q_marks, "SELECT DISTINCT trid FROM xmark");
while( db_step(&q_marks)==SQLITE_ROW ){
rid = db_column_int(&q_marks, 0);
if( db_int(0, "SELECT count(objid) FROM event"
" WHERE objid=%d AND type='ci'", rid)==0 ){
| | | < > | 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 |
Stmt q_marks;
FILE *f;
db_prepare(&q_marks, "SELECT DISTINCT trid FROM xmark");
while( db_step(&q_marks)==SQLITE_ROW ){
rid = db_column_int(&q_marks, 0);
if( db_int(0, "SELECT count(objid) FROM event"
" WHERE objid=%d AND type='ci'", rid)==0 ){
/* Blob marks exported by git aren't saved between runs, so they need
** to be left free for git to re-use in the future.
*/
}else{
bag_insert(&vers, rid);
}
}
db_finalize(&q_marks);
f = fossil_fopen(markfile_out, "w");
if( !f ){
|
| ︙ | ︙ |
Changes to www/inout.wiki.
| ︙ | ︙ | |||
47 48 49 50 51 52 53 | As with the "import" command, the --git option is not required since the git-fast-export file format is currently the only VCS interchange format that Fossil will generate. However, future versions of Fossil might add the ability to generate other VCS interchange formats, and so for compatibility, the use of the --git option recommended. | > > > > > | > > > | > > > | > > > | > > > | > > > | > > > > > > > > > > | > > | > > > > > > > | | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
As with the "import" command, the --git option is not required
since the git-fast-export file format is currently the only VCS interchange
format that Fossil will generate. However,
future versions of Fossil might add the ability to generate other
VCS interchange formats, and so for compatibility, the use of the --git
option recommended.
<h2>Bidirectional Synchronization</h2>
Fossil also has the ability to synchronize with a Git repository via repeated
imports and/or exports. To do this, it uses marks files to store a record of
artifacts which are known by both Git and Fossil to exist at a given point in
time.
To illustrate, consider the example of a remote Fossil repository that a
user wants to import into a local Git repository. First, the user would clone
the remote repository and import it into a new Git repository:
<blockquote><pre>
fossil clone /path/to/remote/repo.fossil repo.fossil
mkdir repo
cd repo
fossil open ../repo.fossil
mkdir ../repo.git
cd ../repo.git
git init .
fossil export --git --export-marks ../repo/fossil.marks \
../repo.fossil | git fast-import \
--export-marks=../repo/git.marks
</pre></blockquote>
Once the import has completed, the user would need to <tt>git checkout
trunk</tt>. At any point after this, new changes can be imported from the
remote Fossil repository:
<blockquote><pre>
cd ../repo
fossil pull
cd ../repo.git
fossil export --git --import-marks ../repo/fossil.marks \
--export-marks ../repo/fossil.marks \
../repo.fossil | git fast-import \
--import-marks=../repo/git.marks \
--export-marks=../repo/git.marks
</pre></blockquote>
Changes in the Git repository can be exported to the Fossil repository and then
pushed to the remote:
<blockquote><pre>
git fast-export --import-marks=../repo/git.marks \
--export-marks=../repo/git.marks --all | fossil import --git \
--incremental --import-marks ../repo/fossil.marks \
--export-marks ../repo/fossil.marks ../repo.fossil
cd ../repo
fossil push
</pre></blockquote>
|