Fossil SCM
Add --rename-master option to import --git instead of forcing a naming convention.
Commit
50705503d94438068c5691162e38dbf0585362b5
Parent
bc443729a0ae46a…
1 file changed
+17
-8
+17
-8
| --- src/import.c | ||
| +++ src/import.c | ||
| @@ -513,10 +513,14 @@ | ||
| 513 | 513 | } |
| 514 | 514 | zName[i] = 0; |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | |
| 518 | +static struct{ | |
| 519 | + const char *zMasterName; /* Name of master branch */ | |
| 520 | +} ggit; | |
| 521 | + | |
| 518 | 522 | /* |
| 519 | 523 | ** Read the git-fast-import format from pIn and insert the corresponding |
| 520 | 524 | ** content into the database. |
| 521 | 525 | */ |
| 522 | 526 | static void git_fast_import(FILE *pIn){ |
| @@ -536,14 +540,15 @@ | ||
| 536 | 540 | if( strncmp(zLine, "blob", 4)==0 ){ |
| 537 | 541 | gg.xFinish(); |
| 538 | 542 | gg.xFinish = finish_blob; |
| 539 | 543 | }else |
| 540 | 544 | if( strncmp(zLine, "commit ", 7)==0 ){ |
| 545 | + const char *zRefName; | |
| 541 | 546 | gg.xFinish(); |
| 542 | 547 | gg.xFinish = finish_commit; |
| 543 | 548 | trim_newline(&zLine[7]); |
| 544 | - z = &zLine[7]; | |
| 549 | + zRefName = &zLine[7]; | |
| 545 | 550 | |
| 546 | 551 | /* The argument to the "commit" line might match either of these |
| 547 | 552 | ** patterns: |
| 548 | 553 | ** |
| 549 | 554 | ** (A) refs/heads/BRANCHNAME |
| @@ -559,15 +564,15 @@ | ||
| 559 | 564 | ** last commit that holds that tag. |
| 560 | 565 | ** |
| 561 | 566 | ** None of the above is explained in the git-fast-export |
| 562 | 567 | ** documentation. We had to figure it out via trial and error. |
| 563 | 568 | */ |
| 564 | - for(i=5; i<strlen(z) && z[i]!='/'; i++){} | |
| 565 | - gg.tagCommit = strncmp(&z[5], "tags", 4)==0; /* True for pattern B */ | |
| 566 | - if( z[i+1]!=0 ) z += i+1; | |
| 567 | - if( fossil_strcmp(z, "master")==0 ) z = "trunk"; | |
| 568 | - gg.zBranch = fossil_strdup(z); | |
| 569 | + for(i=5; i<strlen(zRefName) && zRefName[i]!='/'; i++){} | |
| 570 | + gg.tagCommit = strncmp(&zRefName[5], "tags", 4)==0; /* True for pattern B */ | |
| 571 | + if( zRefName[i+1]!=0 ) zRefName += i+1; | |
| 572 | + if( fossil_strcmp(zRefName, "master")==0 ) zRefName = ggit.zMasterName; | |
| 573 | + gg.zBranch = fossil_strdup(zRefName); | |
| 569 | 574 | gg.fromLoaded = 0; |
| 570 | 575 | }else |
| 571 | 576 | if( strncmp(zLine, "tag ", 4)==0 ){ |
| 572 | 577 | gg.xFinish(); |
| 573 | 578 | gg.xFinish = finish_tag; |
| @@ -1545,12 +1550,13 @@ | ||
| 1545 | 1550 | ** |
| 1546 | 1551 | ** The following formats are currently understood by this command |
| 1547 | 1552 | ** |
| 1548 | 1553 | ** --git Import from the git-fast-export file format (default) |
| 1549 | 1554 | ** Options: |
| 1550 | -** --import-marks FILE Restore marks table from FILE | |
| 1551 | -** --export-marks FILE Save marks table to FILE | |
| 1555 | +** --import-marks FILE Restore marks table from FILE | |
| 1556 | +** --export-marks FILE Save marks table to FILE | |
| 1557 | +** --rename-master NAME Renames the master branch to NAME | |
| 1552 | 1558 | ** |
| 1553 | 1559 | ** --svn Import from the svnadmin-dump file format. The default |
| 1554 | 1560 | ** behaviour (unless overridden by --flat) is to treat 3 |
| 1555 | 1561 | ** folders in the SVN root as special, following the |
| 1556 | 1562 | ** common layout of SVN repositories. These are (by |
| @@ -1668,10 +1674,13 @@ | ||
| 1668 | 1674 | gsvn.revFlag = find_option("rev-tags", 0, 0) |
| 1669 | 1675 | || (incrFlag && !find_option("no-rev-tags", 0, 0)); |
| 1670 | 1676 | }else if( gitFlag ){ |
| 1671 | 1677 | markfile_in = find_option("import-marks", 0, 1); |
| 1672 | 1678 | markfile_out = find_option("export-marks", 0, 1); |
| 1679 | + if( !(ggit.zMasterName = find_option("rename-master", 0, 1)) ){ | |
| 1680 | + ggit.zMasterName = "master"; | |
| 1681 | + } | |
| 1673 | 1682 | } |
| 1674 | 1683 | verify_all_options(); |
| 1675 | 1684 | |
| 1676 | 1685 | if( g.argc!=3 && g.argc!=4 ){ |
| 1677 | 1686 | usage("--git|--svn ?OPTIONS? NEW-REPOSITORY ?INPUT-FILE?"); |
| 1678 | 1687 |
| --- src/import.c | |
| +++ src/import.c | |
| @@ -513,10 +513,14 @@ | |
| 513 | } |
| 514 | zName[i] = 0; |
| 515 | } |
| 516 | |
| 517 | |
| 518 | /* |
| 519 | ** Read the git-fast-import format from pIn and insert the corresponding |
| 520 | ** content into the database. |
| 521 | */ |
| 522 | static void git_fast_import(FILE *pIn){ |
| @@ -536,14 +540,15 @@ | |
| 536 | if( strncmp(zLine, "blob", 4)==0 ){ |
| 537 | gg.xFinish(); |
| 538 | gg.xFinish = finish_blob; |
| 539 | }else |
| 540 | if( strncmp(zLine, "commit ", 7)==0 ){ |
| 541 | gg.xFinish(); |
| 542 | gg.xFinish = finish_commit; |
| 543 | trim_newline(&zLine[7]); |
| 544 | z = &zLine[7]; |
| 545 | |
| 546 | /* The argument to the "commit" line might match either of these |
| 547 | ** patterns: |
| 548 | ** |
| 549 | ** (A) refs/heads/BRANCHNAME |
| @@ -559,15 +564,15 @@ | |
| 559 | ** last commit that holds that tag. |
| 560 | ** |
| 561 | ** None of the above is explained in the git-fast-export |
| 562 | ** documentation. We had to figure it out via trial and error. |
| 563 | */ |
| 564 | for(i=5; i<strlen(z) && z[i]!='/'; i++){} |
| 565 | gg.tagCommit = strncmp(&z[5], "tags", 4)==0; /* True for pattern B */ |
| 566 | if( z[i+1]!=0 ) z += i+1; |
| 567 | if( fossil_strcmp(z, "master")==0 ) z = "trunk"; |
| 568 | gg.zBranch = fossil_strdup(z); |
| 569 | gg.fromLoaded = 0; |
| 570 | }else |
| 571 | if( strncmp(zLine, "tag ", 4)==0 ){ |
| 572 | gg.xFinish(); |
| 573 | gg.xFinish = finish_tag; |
| @@ -1545,12 +1550,13 @@ | |
| 1545 | ** |
| 1546 | ** The following formats are currently understood by this command |
| 1547 | ** |
| 1548 | ** --git Import from the git-fast-export file format (default) |
| 1549 | ** Options: |
| 1550 | ** --import-marks FILE Restore marks table from FILE |
| 1551 | ** --export-marks FILE Save marks table to FILE |
| 1552 | ** |
| 1553 | ** --svn Import from the svnadmin-dump file format. The default |
| 1554 | ** behaviour (unless overridden by --flat) is to treat 3 |
| 1555 | ** folders in the SVN root as special, following the |
| 1556 | ** common layout of SVN repositories. These are (by |
| @@ -1668,10 +1674,13 @@ | |
| 1668 | gsvn.revFlag = find_option("rev-tags", 0, 0) |
| 1669 | || (incrFlag && !find_option("no-rev-tags", 0, 0)); |
| 1670 | }else if( gitFlag ){ |
| 1671 | markfile_in = find_option("import-marks", 0, 1); |
| 1672 | markfile_out = find_option("export-marks", 0, 1); |
| 1673 | } |
| 1674 | verify_all_options(); |
| 1675 | |
| 1676 | if( g.argc!=3 && g.argc!=4 ){ |
| 1677 | usage("--git|--svn ?OPTIONS? NEW-REPOSITORY ?INPUT-FILE?"); |
| 1678 |
| --- src/import.c | |
| +++ src/import.c | |
| @@ -513,10 +513,14 @@ | |
| 513 | } |
| 514 | zName[i] = 0; |
| 515 | } |
| 516 | |
| 517 | |
| 518 | static struct{ |
| 519 | const char *zMasterName; /* Name of master branch */ |
| 520 | } ggit; |
| 521 | |
| 522 | /* |
| 523 | ** Read the git-fast-import format from pIn and insert the corresponding |
| 524 | ** content into the database. |
| 525 | */ |
| 526 | static void git_fast_import(FILE *pIn){ |
| @@ -536,14 +540,15 @@ | |
| 540 | if( strncmp(zLine, "blob", 4)==0 ){ |
| 541 | gg.xFinish(); |
| 542 | gg.xFinish = finish_blob; |
| 543 | }else |
| 544 | if( strncmp(zLine, "commit ", 7)==0 ){ |
| 545 | const char *zRefName; |
| 546 | gg.xFinish(); |
| 547 | gg.xFinish = finish_commit; |
| 548 | trim_newline(&zLine[7]); |
| 549 | zRefName = &zLine[7]; |
| 550 | |
| 551 | /* The argument to the "commit" line might match either of these |
| 552 | ** patterns: |
| 553 | ** |
| 554 | ** (A) refs/heads/BRANCHNAME |
| @@ -559,15 +564,15 @@ | |
| 564 | ** last commit that holds that tag. |
| 565 | ** |
| 566 | ** None of the above is explained in the git-fast-export |
| 567 | ** documentation. We had to figure it out via trial and error. |
| 568 | */ |
| 569 | for(i=5; i<strlen(zRefName) && zRefName[i]!='/'; i++){} |
| 570 | gg.tagCommit = strncmp(&zRefName[5], "tags", 4)==0; /* True for pattern B */ |
| 571 | if( zRefName[i+1]!=0 ) zRefName += i+1; |
| 572 | if( fossil_strcmp(zRefName, "master")==0 ) zRefName = ggit.zMasterName; |
| 573 | gg.zBranch = fossil_strdup(zRefName); |
| 574 | gg.fromLoaded = 0; |
| 575 | }else |
| 576 | if( strncmp(zLine, "tag ", 4)==0 ){ |
| 577 | gg.xFinish(); |
| 578 | gg.xFinish = finish_tag; |
| @@ -1545,12 +1550,13 @@ | |
| 1550 | ** |
| 1551 | ** The following formats are currently understood by this command |
| 1552 | ** |
| 1553 | ** --git Import from the git-fast-export file format (default) |
| 1554 | ** Options: |
| 1555 | ** --import-marks FILE Restore marks table from FILE |
| 1556 | ** --export-marks FILE Save marks table to FILE |
| 1557 | ** --rename-master NAME Renames the master branch to NAME |
| 1558 | ** |
| 1559 | ** --svn Import from the svnadmin-dump file format. The default |
| 1560 | ** behaviour (unless overridden by --flat) is to treat 3 |
| 1561 | ** folders in the SVN root as special, following the |
| 1562 | ** common layout of SVN repositories. These are (by |
| @@ -1668,10 +1674,13 @@ | |
| 1674 | gsvn.revFlag = find_option("rev-tags", 0, 0) |
| 1675 | || (incrFlag && !find_option("no-rev-tags", 0, 0)); |
| 1676 | }else if( gitFlag ){ |
| 1677 | markfile_in = find_option("import-marks", 0, 1); |
| 1678 | markfile_out = find_option("export-marks", 0, 1); |
| 1679 | if( !(ggit.zMasterName = find_option("rename-master", 0, 1)) ){ |
| 1680 | ggit.zMasterName = "master"; |
| 1681 | } |
| 1682 | } |
| 1683 | verify_all_options(); |
| 1684 | |
| 1685 | if( g.argc!=3 && g.argc!=4 ){ |
| 1686 | usage("--git|--svn ?OPTIONS? NEW-REPOSITORY ?INPUT-FILE?"); |
| 1687 |