Fossil SCM
Adding a kind of symbolic name that returns the last checkin of the parent branch merged into the requested branch. For example, if annotate_links forked from trunk, "pbranch:annotate_links" returns the rid of the last time trunk was merged into annotate_links.
Commit
d560953c98c037863297d568163e1ae179bcc9db
Parent
4036b5df51a4be9…
1 file changed
+100
+100
| --- src/name.c | ||
| +++ src/name.c | ||
| @@ -112,10 +112,18 @@ | ||
| 112 | 112 | " WHERE mtime<=julianday(%Q) AND type GLOB '%q'" |
| 113 | 113 | " ORDER BY mtime DESC LIMIT 1", |
| 114 | 114 | &zTag[5], zType); |
| 115 | 115 | return rid; |
| 116 | 116 | } |
| 117 | + | |
| 118 | + if( memcmp(zTag, "pbranch:", 8)==0 ){ | |
| 119 | + int branchRid = symbolic_name_to_rid(&zTag[8], zType); | |
| 120 | + if (branchRid == 0) return 0; | |
| 121 | + rid = get_parent_branch_rid(branchRid); | |
| 122 | + return rid; | |
| 123 | + } | |
| 124 | + | |
| 117 | 125 | if( is_date(zTag) ){ |
| 118 | 126 | rid = db_int(0, |
| 119 | 127 | "SELECT objid FROM event" |
| 120 | 128 | " WHERE mtime<=julianday(%Q) AND type GLOB '%q'" |
| 121 | 129 | " ORDER BY mtime DESC LIMIT 1", |
| @@ -471,5 +479,97 @@ | ||
| 471 | 479 | comment_print(db_column_text(&q,4), 10, 78); |
| 472 | 480 | } |
| 473 | 481 | db_finalize(&q); |
| 474 | 482 | } |
| 475 | 483 | } |
| 484 | + | |
| 485 | +int get_parent_branch_rid(int ridRequested){ | |
| 486 | + Stmt s; | |
| 487 | + const char *branchName; /* Name of the branch requested at rid */ | |
| 488 | + const char *parentBranchName; /* Name of the parent branch */ | |
| 489 | + int rid; | |
| 490 | + | |
| 491 | + /* Get the name of the current branch */ | |
| 492 | + branchName = db_text(0, | |
| 493 | + "SELECT value FROM tagxref" | |
| 494 | + " WHERE tagid=%d" | |
| 495 | + " AND tagxref.tagtype>0" | |
| 496 | + " AND rid=%d", | |
| 497 | + TAG_BRANCH, rid); | |
| 498 | + | |
| 499 | + if ( !branchName ) | |
| 500 | + return 0; | |
| 501 | + | |
| 502 | + /* Find the name of the branch this was forked from */ | |
| 503 | + db_prepare(&s, | |
| 504 | + "SELECT pid, tagxref.value FROM plink JOIN tagxref" | |
| 505 | + " WHERE cid=:rid" | |
| 506 | + " AND isprim=1" | |
| 507 | + " AND tagxref.tagid=%d" | |
| 508 | + " AND tagxref.tagtype>0" | |
| 509 | + " AND tagxref.rid=pid", | |
| 510 | + TAG_BRANCH); | |
| 511 | + | |
| 512 | + rid = ridRequested; | |
| 513 | + while( rid > 0 ) { | |
| 514 | + db_bind_int(&s, ":rid", rid); | |
| 515 | + if ( db_step(&s) == SQLITE_ROW ) { | |
| 516 | + rid = db_column_int(&s, 0); | |
| 517 | + parentBranchName = db_column_text(&s, 1); | |
| 518 | + if ( !parentBranchName ) { | |
| 519 | + rid = 0; | |
| 520 | + break; | |
| 521 | + } | |
| 522 | + | |
| 523 | + if ( fossil_strcmp(parentBranchName, branchName) ) { | |
| 524 | + parentBranchName = fossil_strdup(parentBranchName); | |
| 525 | + break; | |
| 526 | + } | |
| 527 | + }else{ | |
| 528 | + rid = 0; | |
| 529 | + break; | |
| 530 | + } | |
| 531 | + db_reset(&s); | |
| 532 | + } | |
| 533 | + db_finalize(&s); | |
| 534 | + | |
| 535 | + if (rid == 0) | |
| 536 | + return 0; | |
| 537 | + | |
| 538 | + /* Find the last checkin coming from the parent branch */ | |
| 539 | + db_prepare(&s, | |
| 540 | + "SELECT pid, tagxref.value FROM plink JOIN tagxref" | |
| 541 | + " WHERE cid=:rid" | |
| 542 | + " AND tagxref.tagid=%d" | |
| 543 | + " AND tagxref.tagtype>0" | |
| 544 | + " AND tagxref.rid=pid ORDER BY isprim ASC", | |
| 545 | + TAG_BRANCH); | |
| 546 | + | |
| 547 | + rid = ridRequested; | |
| 548 | + while( rid > 0 ) { | |
| 549 | + db_bind_int(&s, ":rid", rid); | |
| 550 | + int found = 0; | |
| 551 | + while ( db_step(&s) == SQLITE_ROW ) { | |
| 552 | + const char *branchNamePid; /* Branch name of the pid */ | |
| 553 | + | |
| 554 | + ++found; | |
| 555 | + rid = db_column_int(&s, 0); | |
| 556 | + branchNamePid = db_column_text(&s, 1); | |
| 557 | + if ( !branchNamePid ) { | |
| 558 | + break; | |
| 559 | + } | |
| 560 | + if ( fossil_strcmp(parentBranchName, branchNamePid)==0 ) { | |
| 561 | + /* Found the last merge from the parent branch */ | |
| 562 | + db_finalize(&s); | |
| 563 | + return rid; | |
| 564 | + } | |
| 565 | + } | |
| 566 | + | |
| 567 | + if (found == 0) { | |
| 568 | + break; | |
| 569 | + } | |
| 570 | + db_reset(&s); | |
| 571 | + } | |
| 572 | + db_finalize(&s); | |
| 573 | + | |
| 574 | + return 0; | |
| 575 | +} | |
| 476 | 576 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -112,10 +112,18 @@ | |
| 112 | " WHERE mtime<=julianday(%Q) AND type GLOB '%q'" |
| 113 | " ORDER BY mtime DESC LIMIT 1", |
| 114 | &zTag[5], zType); |
| 115 | return rid; |
| 116 | } |
| 117 | if( is_date(zTag) ){ |
| 118 | rid = db_int(0, |
| 119 | "SELECT objid FROM event" |
| 120 | " WHERE mtime<=julianday(%Q) AND type GLOB '%q'" |
| 121 | " ORDER BY mtime DESC LIMIT 1", |
| @@ -471,5 +479,97 @@ | |
| 471 | comment_print(db_column_text(&q,4), 10, 78); |
| 472 | } |
| 473 | db_finalize(&q); |
| 474 | } |
| 475 | } |
| 476 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -112,10 +112,18 @@ | |
| 112 | " WHERE mtime<=julianday(%Q) AND type GLOB '%q'" |
| 113 | " ORDER BY mtime DESC LIMIT 1", |
| 114 | &zTag[5], zType); |
| 115 | return rid; |
| 116 | } |
| 117 | |
| 118 | if( memcmp(zTag, "pbranch:", 8)==0 ){ |
| 119 | int branchRid = symbolic_name_to_rid(&zTag[8], zType); |
| 120 | if (branchRid == 0) return 0; |
| 121 | rid = get_parent_branch_rid(branchRid); |
| 122 | return rid; |
| 123 | } |
| 124 | |
| 125 | if( is_date(zTag) ){ |
| 126 | rid = db_int(0, |
| 127 | "SELECT objid FROM event" |
| 128 | " WHERE mtime<=julianday(%Q) AND type GLOB '%q'" |
| 129 | " ORDER BY mtime DESC LIMIT 1", |
| @@ -471,5 +479,97 @@ | |
| 479 | comment_print(db_column_text(&q,4), 10, 78); |
| 480 | } |
| 481 | db_finalize(&q); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | int get_parent_branch_rid(int ridRequested){ |
| 486 | Stmt s; |
| 487 | const char *branchName; /* Name of the branch requested at rid */ |
| 488 | const char *parentBranchName; /* Name of the parent branch */ |
| 489 | int rid; |
| 490 | |
| 491 | /* Get the name of the current branch */ |
| 492 | branchName = db_text(0, |
| 493 | "SELECT value FROM tagxref" |
| 494 | " WHERE tagid=%d" |
| 495 | " AND tagxref.tagtype>0" |
| 496 | " AND rid=%d", |
| 497 | TAG_BRANCH, rid); |
| 498 | |
| 499 | if ( !branchName ) |
| 500 | return 0; |
| 501 | |
| 502 | /* Find the name of the branch this was forked from */ |
| 503 | db_prepare(&s, |
| 504 | "SELECT pid, tagxref.value FROM plink JOIN tagxref" |
| 505 | " WHERE cid=:rid" |
| 506 | " AND isprim=1" |
| 507 | " AND tagxref.tagid=%d" |
| 508 | " AND tagxref.tagtype>0" |
| 509 | " AND tagxref.rid=pid", |
| 510 | TAG_BRANCH); |
| 511 | |
| 512 | rid = ridRequested; |
| 513 | while( rid > 0 ) { |
| 514 | db_bind_int(&s, ":rid", rid); |
| 515 | if ( db_step(&s) == SQLITE_ROW ) { |
| 516 | rid = db_column_int(&s, 0); |
| 517 | parentBranchName = db_column_text(&s, 1); |
| 518 | if ( !parentBranchName ) { |
| 519 | rid = 0; |
| 520 | break; |
| 521 | } |
| 522 | |
| 523 | if ( fossil_strcmp(parentBranchName, branchName) ) { |
| 524 | parentBranchName = fossil_strdup(parentBranchName); |
| 525 | break; |
| 526 | } |
| 527 | }else{ |
| 528 | rid = 0; |
| 529 | break; |
| 530 | } |
| 531 | db_reset(&s); |
| 532 | } |
| 533 | db_finalize(&s); |
| 534 | |
| 535 | if (rid == 0) |
| 536 | return 0; |
| 537 | |
| 538 | /* Find the last checkin coming from the parent branch */ |
| 539 | db_prepare(&s, |
| 540 | "SELECT pid, tagxref.value FROM plink JOIN tagxref" |
| 541 | " WHERE cid=:rid" |
| 542 | " AND tagxref.tagid=%d" |
| 543 | " AND tagxref.tagtype>0" |
| 544 | " AND tagxref.rid=pid ORDER BY isprim ASC", |
| 545 | TAG_BRANCH); |
| 546 | |
| 547 | rid = ridRequested; |
| 548 | while( rid > 0 ) { |
| 549 | db_bind_int(&s, ":rid", rid); |
| 550 | int found = 0; |
| 551 | while ( db_step(&s) == SQLITE_ROW ) { |
| 552 | const char *branchNamePid; /* Branch name of the pid */ |
| 553 | |
| 554 | ++found; |
| 555 | rid = db_column_int(&s, 0); |
| 556 | branchNamePid = db_column_text(&s, 1); |
| 557 | if ( !branchNamePid ) { |
| 558 | break; |
| 559 | } |
| 560 | if ( fossil_strcmp(parentBranchName, branchNamePid)==0 ) { |
| 561 | /* Found the last merge from the parent branch */ |
| 562 | db_finalize(&s); |
| 563 | return rid; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | if (found == 0) { |
| 568 | break; |
| 569 | } |
| 570 | db_reset(&s); |
| 571 | } |
| 572 | db_finalize(&s); |
| 573 | |
| 574 | return 0; |
| 575 | } |
| 576 |