Fossil SCM
Attempt to add the --mainbranch option to the "fossil git export" command. This does not appear to be working. Need advice from a Git expert.
Commit
4c384ba2f4be30916819059f17f1cf6f3ab787560dcb06610eebe8b89751c2a2
Parent
baa40a00e862db8…
1 file changed
+29
-2
+29
-2
| --- src/export.c | ||
| +++ src/export.c | ||
| @@ -862,10 +862,15 @@ | ||
| 862 | 862 | #define VERB_ERROR 1 |
| 863 | 863 | #define VERB_NORMAL 2 |
| 864 | 864 | #define VERB_EXTRA 3 |
| 865 | 865 | static int gitmirror_verbosity = VERB_NORMAL; |
| 866 | 866 | |
| 867 | +/* The main branch in the Git repository. The "trunk" branch of | |
| 868 | +** Fossil is renamed to be this branch name. | |
| 869 | +*/ | |
| 870 | +static const char *gitmirror_mainbranch = "master"; | |
| 871 | + | |
| 867 | 872 | /* |
| 868 | 873 | ** Output routine that depends on verbosity |
| 869 | 874 | */ |
| 870 | 875 | static void gitmirror_message(int iLevel, const char *zFormat, ...){ |
| 871 | 876 | va_list ap; |
| @@ -1149,11 +1154,11 @@ | ||
| 1149 | 1154 | "SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=%d", |
| 1150 | 1155 | TAG_BRANCH, rid |
| 1151 | 1156 | ); |
| 1152 | 1157 | if( fossil_strcmp(zBranch,"trunk")==0 ){ |
| 1153 | 1158 | fossil_free(zBranch); |
| 1154 | - zBranch = mprintf("master"); | |
| 1159 | + zBranch = mprintf("%s",gitmirror_mainbranch); | |
| 1155 | 1160 | }else if( zBranch==0 ){ |
| 1156 | 1161 | zBranch = mprintf("unknown"); |
| 1157 | 1162 | }else{ |
| 1158 | 1163 | gitmirror_sanitize_name(zBranch); |
| 1159 | 1164 | } |
| @@ -1294,10 +1299,11 @@ | ||
| 1294 | 1299 | char *zMirror; /* Name of the mirror */ |
| 1295 | 1300 | char *z; /* Generic string */ |
| 1296 | 1301 | char *zCmd; /* git command to run as a subprocess */ |
| 1297 | 1302 | const char *zDebug = 0; /* Value of the --debug flag */ |
| 1298 | 1303 | const char *zAutoPush = 0; /* Value of the --autopush flag */ |
| 1304 | + const char *zMainBr = 0; /* Value of the --mainbranch flag */ | |
| 1299 | 1305 | char *zPushUrl; /* URL to sync the mirror to */ |
| 1300 | 1306 | double rEnd; /* time of most recent export */ |
| 1301 | 1307 | int rc; /* Result code */ |
| 1302 | 1308 | int bForce; /* Do the export and sync even if no changes*/ |
| 1303 | 1309 | int bNeedRepack = 0; /* True if we should run repack at the end */ |
| @@ -1314,10 +1320,11 @@ | ||
| 1314 | 1320 | if( zLimit ){ |
| 1315 | 1321 | nLimit = (unsigned int)atoi(zLimit); |
| 1316 | 1322 | if( nLimit<=0 ) fossil_fatal("--limit must be positive"); |
| 1317 | 1323 | } |
| 1318 | 1324 | zAutoPush = find_option("autopush",0,1); |
| 1325 | + zMainBr = find_option("mainbranch",0,1); | |
| 1319 | 1326 | bForce = find_option("force","f",0)!=0; |
| 1320 | 1327 | bIfExists = find_option("if-mirrored",0,0)!=0; |
| 1321 | 1328 | gitmirror_verbosity = VERB_NORMAL; |
| 1322 | 1329 | while( find_option("quiet","q",0)!=0 ){ gitmirror_verbosity--; } |
| 1323 | 1330 | while( find_option("verbose","v",0)!=0 ){ gitmirror_verbosity++; } |
| @@ -1405,10 +1412,19 @@ | ||
| 1405 | 1412 | "VALUES('autopush',%Q)", |
| 1406 | 1413 | zAutoPush |
| 1407 | 1414 | ); |
| 1408 | 1415 | } |
| 1409 | 1416 | } |
| 1417 | + | |
| 1418 | + /* Change the mainbranch setting if the --mainbranch flag is present */ | |
| 1419 | + if( zMainBr && zMainBr[0] ){ | |
| 1420 | + db_multi_exec( | |
| 1421 | + "REPLACE INTO mirror.mconfig(key,value)" | |
| 1422 | + "VALUES('mainbranch',%Q)", | |
| 1423 | + zMainBr | |
| 1424 | + ); | |
| 1425 | + } | |
| 1410 | 1426 | |
| 1411 | 1427 | /* See if there is any work to be done. Exit early if not, before starting |
| 1412 | 1428 | ** the "git fast-import" command. */ |
| 1413 | 1429 | if( !bForce |
| 1414 | 1430 | && !db_exists("SELECT 1 FROM event WHERE type IN ('ci','t')" |
| @@ -1520,10 +1536,14 @@ | ||
| 1520 | 1536 | } |
| 1521 | 1537 | db_multi_exec( |
| 1522 | 1538 | "CREATE INDEX IF NOT EXISTS mirror.mmarkx1 ON mmark(githash);" |
| 1523 | 1539 | ); |
| 1524 | 1540 | |
| 1541 | + /* Recover the saved name of the main branch */ | |
| 1542 | + gitmirror_mainbranch = db_text("master", | |
| 1543 | + "SELECT value FROM mconfig WHERE key='mainbranch'"); | |
| 1544 | + | |
| 1525 | 1545 | /* Do any tags that have been created since the start time */ |
| 1526 | 1546 | db_prepare(&q, |
| 1527 | 1547 | "SELECT substr(tagname,5), githash" |
| 1528 | 1548 | " FROM (SELECT tagxref.tagid AS xtagid, tagname, rid, max(mtime) AS mtime" |
| 1529 | 1549 | " FROM tagxref JOIN tag ON tag.tagid=tagxref.tagid" |
| @@ -1569,11 +1589,11 @@ | ||
| 1569 | 1589 | char *zBrname = fossil_strdup(db_column_text(&q,0)); |
| 1570 | 1590 | const char *zObj = db_column_text(&q,2); |
| 1571 | 1591 | char *zRefCmd; |
| 1572 | 1592 | if( fossil_strcmp(zBrname,"trunk")==0 ){ |
| 1573 | 1593 | fossil_free(zBrname); |
| 1574 | - zBrname = fossil_strdup("master"); | |
| 1594 | + zBrname = fossil_strdup(gitmirror_mainbranch); | |
| 1575 | 1595 | }else{ |
| 1576 | 1596 | gitmirror_sanitize_name(zBrname); |
| 1577 | 1597 | } |
| 1578 | 1598 | zRefCmd = mprintf("git update-ref \"refs/heads/%s\" %$", zBrname, zObj); |
| 1579 | 1599 | fossil_free(zBrname); |
| @@ -1651,17 +1671,20 @@ | ||
| 1651 | 1671 | fossil_print("Autopush: off\n"); |
| 1652 | 1672 | }else{ |
| 1653 | 1673 | UrlData url; |
| 1654 | 1674 | url_parse_local(z, 0, &url); |
| 1655 | 1675 | fossil_print("Autopush: %s\n", url.canonical); |
| 1676 | + fossil_free(z); | |
| 1656 | 1677 | } |
| 1657 | 1678 | n = db_int(0, |
| 1658 | 1679 | "SELECT count(*) FROM event" |
| 1659 | 1680 | " WHERE type='ci'" |
| 1660 | 1681 | " AND mtime>coalesce((SELECT value FROM mconfig" |
| 1661 | 1682 | " WHERE key='start'),0.0)" |
| 1662 | 1683 | ); |
| 1684 | + z = db_text("master", "SELECT value FROM mconfig WHERE key='mainbranch'"); | |
| 1685 | + fossil_print("Main-Branch: %s\n",z); | |
| 1663 | 1686 | if( n==0 ){ |
| 1664 | 1687 | fossil_print("Status: up-to-date\n"); |
| 1665 | 1688 | }else{ |
| 1666 | 1689 | fossil_print("Status: %d check-in%s awaiting export\n", |
| 1667 | 1690 | n, n==1 ? "" : "s"); |
| @@ -1706,10 +1729,14 @@ | ||
| 1706 | 1729 | ** piping it into "git fast-import". |
| 1707 | 1730 | ** --force|-f Do the export even if nothing has changed |
| 1708 | 1731 | ** --if-mirrored No-op if the mirror does not already exist. |
| 1709 | 1732 | ** --limit N Add no more than N new check-ins to MIRROR. |
| 1710 | 1733 | ** Useful for debugging |
| 1734 | +** --mainbranch NAME Use NAME as the name of the main branch in Git. | |
| 1735 | +** The "trunk" branch of the Fossil repository is | |
| 1736 | +** mapped into this name. "master" is used if | |
| 1737 | +** this option is omitted. | |
| 1711 | 1738 | ** --quiet|-q Reduce output. Repeat for even less output. |
| 1712 | 1739 | ** --verbose|-v More output. |
| 1713 | 1740 | ** |
| 1714 | 1741 | ** > fossil git import MIRROR |
| 1715 | 1742 | ** |
| 1716 | 1743 |
| --- src/export.c | |
| +++ src/export.c | |
| @@ -862,10 +862,15 @@ | |
| 862 | #define VERB_ERROR 1 |
| 863 | #define VERB_NORMAL 2 |
| 864 | #define VERB_EXTRA 3 |
| 865 | static int gitmirror_verbosity = VERB_NORMAL; |
| 866 | |
| 867 | /* |
| 868 | ** Output routine that depends on verbosity |
| 869 | */ |
| 870 | static void gitmirror_message(int iLevel, const char *zFormat, ...){ |
| 871 | va_list ap; |
| @@ -1149,11 +1154,11 @@ | |
| 1149 | "SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=%d", |
| 1150 | TAG_BRANCH, rid |
| 1151 | ); |
| 1152 | if( fossil_strcmp(zBranch,"trunk")==0 ){ |
| 1153 | fossil_free(zBranch); |
| 1154 | zBranch = mprintf("master"); |
| 1155 | }else if( zBranch==0 ){ |
| 1156 | zBranch = mprintf("unknown"); |
| 1157 | }else{ |
| 1158 | gitmirror_sanitize_name(zBranch); |
| 1159 | } |
| @@ -1294,10 +1299,11 @@ | |
| 1294 | char *zMirror; /* Name of the mirror */ |
| 1295 | char *z; /* Generic string */ |
| 1296 | char *zCmd; /* git command to run as a subprocess */ |
| 1297 | const char *zDebug = 0; /* Value of the --debug flag */ |
| 1298 | const char *zAutoPush = 0; /* Value of the --autopush flag */ |
| 1299 | char *zPushUrl; /* URL to sync the mirror to */ |
| 1300 | double rEnd; /* time of most recent export */ |
| 1301 | int rc; /* Result code */ |
| 1302 | int bForce; /* Do the export and sync even if no changes*/ |
| 1303 | int bNeedRepack = 0; /* True if we should run repack at the end */ |
| @@ -1314,10 +1320,11 @@ | |
| 1314 | if( zLimit ){ |
| 1315 | nLimit = (unsigned int)atoi(zLimit); |
| 1316 | if( nLimit<=0 ) fossil_fatal("--limit must be positive"); |
| 1317 | } |
| 1318 | zAutoPush = find_option("autopush",0,1); |
| 1319 | bForce = find_option("force","f",0)!=0; |
| 1320 | bIfExists = find_option("if-mirrored",0,0)!=0; |
| 1321 | gitmirror_verbosity = VERB_NORMAL; |
| 1322 | while( find_option("quiet","q",0)!=0 ){ gitmirror_verbosity--; } |
| 1323 | while( find_option("verbose","v",0)!=0 ){ gitmirror_verbosity++; } |
| @@ -1405,10 +1412,19 @@ | |
| 1405 | "VALUES('autopush',%Q)", |
| 1406 | zAutoPush |
| 1407 | ); |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | /* See if there is any work to be done. Exit early if not, before starting |
| 1412 | ** the "git fast-import" command. */ |
| 1413 | if( !bForce |
| 1414 | && !db_exists("SELECT 1 FROM event WHERE type IN ('ci','t')" |
| @@ -1520,10 +1536,14 @@ | |
| 1520 | } |
| 1521 | db_multi_exec( |
| 1522 | "CREATE INDEX IF NOT EXISTS mirror.mmarkx1 ON mmark(githash);" |
| 1523 | ); |
| 1524 | |
| 1525 | /* Do any tags that have been created since the start time */ |
| 1526 | db_prepare(&q, |
| 1527 | "SELECT substr(tagname,5), githash" |
| 1528 | " FROM (SELECT tagxref.tagid AS xtagid, tagname, rid, max(mtime) AS mtime" |
| 1529 | " FROM tagxref JOIN tag ON tag.tagid=tagxref.tagid" |
| @@ -1569,11 +1589,11 @@ | |
| 1569 | char *zBrname = fossil_strdup(db_column_text(&q,0)); |
| 1570 | const char *zObj = db_column_text(&q,2); |
| 1571 | char *zRefCmd; |
| 1572 | if( fossil_strcmp(zBrname,"trunk")==0 ){ |
| 1573 | fossil_free(zBrname); |
| 1574 | zBrname = fossil_strdup("master"); |
| 1575 | }else{ |
| 1576 | gitmirror_sanitize_name(zBrname); |
| 1577 | } |
| 1578 | zRefCmd = mprintf("git update-ref \"refs/heads/%s\" %$", zBrname, zObj); |
| 1579 | fossil_free(zBrname); |
| @@ -1651,17 +1671,20 @@ | |
| 1651 | fossil_print("Autopush: off\n"); |
| 1652 | }else{ |
| 1653 | UrlData url; |
| 1654 | url_parse_local(z, 0, &url); |
| 1655 | fossil_print("Autopush: %s\n", url.canonical); |
| 1656 | } |
| 1657 | n = db_int(0, |
| 1658 | "SELECT count(*) FROM event" |
| 1659 | " WHERE type='ci'" |
| 1660 | " AND mtime>coalesce((SELECT value FROM mconfig" |
| 1661 | " WHERE key='start'),0.0)" |
| 1662 | ); |
| 1663 | if( n==0 ){ |
| 1664 | fossil_print("Status: up-to-date\n"); |
| 1665 | }else{ |
| 1666 | fossil_print("Status: %d check-in%s awaiting export\n", |
| 1667 | n, n==1 ? "" : "s"); |
| @@ -1706,10 +1729,14 @@ | |
| 1706 | ** piping it into "git fast-import". |
| 1707 | ** --force|-f Do the export even if nothing has changed |
| 1708 | ** --if-mirrored No-op if the mirror does not already exist. |
| 1709 | ** --limit N Add no more than N new check-ins to MIRROR. |
| 1710 | ** Useful for debugging |
| 1711 | ** --quiet|-q Reduce output. Repeat for even less output. |
| 1712 | ** --verbose|-v More output. |
| 1713 | ** |
| 1714 | ** > fossil git import MIRROR |
| 1715 | ** |
| 1716 |
| --- src/export.c | |
| +++ src/export.c | |
| @@ -862,10 +862,15 @@ | |
| 862 | #define VERB_ERROR 1 |
| 863 | #define VERB_NORMAL 2 |
| 864 | #define VERB_EXTRA 3 |
| 865 | static int gitmirror_verbosity = VERB_NORMAL; |
| 866 | |
| 867 | /* The main branch in the Git repository. The "trunk" branch of |
| 868 | ** Fossil is renamed to be this branch name. |
| 869 | */ |
| 870 | static const char *gitmirror_mainbranch = "master"; |
| 871 | |
| 872 | /* |
| 873 | ** Output routine that depends on verbosity |
| 874 | */ |
| 875 | static void gitmirror_message(int iLevel, const char *zFormat, ...){ |
| 876 | va_list ap; |
| @@ -1149,11 +1154,11 @@ | |
| 1154 | "SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=%d", |
| 1155 | TAG_BRANCH, rid |
| 1156 | ); |
| 1157 | if( fossil_strcmp(zBranch,"trunk")==0 ){ |
| 1158 | fossil_free(zBranch); |
| 1159 | zBranch = mprintf("%s",gitmirror_mainbranch); |
| 1160 | }else if( zBranch==0 ){ |
| 1161 | zBranch = mprintf("unknown"); |
| 1162 | }else{ |
| 1163 | gitmirror_sanitize_name(zBranch); |
| 1164 | } |
| @@ -1294,10 +1299,11 @@ | |
| 1299 | char *zMirror; /* Name of the mirror */ |
| 1300 | char *z; /* Generic string */ |
| 1301 | char *zCmd; /* git command to run as a subprocess */ |
| 1302 | const char *zDebug = 0; /* Value of the --debug flag */ |
| 1303 | const char *zAutoPush = 0; /* Value of the --autopush flag */ |
| 1304 | const char *zMainBr = 0; /* Value of the --mainbranch flag */ |
| 1305 | char *zPushUrl; /* URL to sync the mirror to */ |
| 1306 | double rEnd; /* time of most recent export */ |
| 1307 | int rc; /* Result code */ |
| 1308 | int bForce; /* Do the export and sync even if no changes*/ |
| 1309 | int bNeedRepack = 0; /* True if we should run repack at the end */ |
| @@ -1314,10 +1320,11 @@ | |
| 1320 | if( zLimit ){ |
| 1321 | nLimit = (unsigned int)atoi(zLimit); |
| 1322 | if( nLimit<=0 ) fossil_fatal("--limit must be positive"); |
| 1323 | } |
| 1324 | zAutoPush = find_option("autopush",0,1); |
| 1325 | zMainBr = find_option("mainbranch",0,1); |
| 1326 | bForce = find_option("force","f",0)!=0; |
| 1327 | bIfExists = find_option("if-mirrored",0,0)!=0; |
| 1328 | gitmirror_verbosity = VERB_NORMAL; |
| 1329 | while( find_option("quiet","q",0)!=0 ){ gitmirror_verbosity--; } |
| 1330 | while( find_option("verbose","v",0)!=0 ){ gitmirror_verbosity++; } |
| @@ -1405,10 +1412,19 @@ | |
| 1412 | "VALUES('autopush',%Q)", |
| 1413 | zAutoPush |
| 1414 | ); |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | /* Change the mainbranch setting if the --mainbranch flag is present */ |
| 1419 | if( zMainBr && zMainBr[0] ){ |
| 1420 | db_multi_exec( |
| 1421 | "REPLACE INTO mirror.mconfig(key,value)" |
| 1422 | "VALUES('mainbranch',%Q)", |
| 1423 | zMainBr |
| 1424 | ); |
| 1425 | } |
| 1426 | |
| 1427 | /* See if there is any work to be done. Exit early if not, before starting |
| 1428 | ** the "git fast-import" command. */ |
| 1429 | if( !bForce |
| 1430 | && !db_exists("SELECT 1 FROM event WHERE type IN ('ci','t')" |
| @@ -1520,10 +1536,14 @@ | |
| 1536 | } |
| 1537 | db_multi_exec( |
| 1538 | "CREATE INDEX IF NOT EXISTS mirror.mmarkx1 ON mmark(githash);" |
| 1539 | ); |
| 1540 | |
| 1541 | /* Recover the saved name of the main branch */ |
| 1542 | gitmirror_mainbranch = db_text("master", |
| 1543 | "SELECT value FROM mconfig WHERE key='mainbranch'"); |
| 1544 | |
| 1545 | /* Do any tags that have been created since the start time */ |
| 1546 | db_prepare(&q, |
| 1547 | "SELECT substr(tagname,5), githash" |
| 1548 | " FROM (SELECT tagxref.tagid AS xtagid, tagname, rid, max(mtime) AS mtime" |
| 1549 | " FROM tagxref JOIN tag ON tag.tagid=tagxref.tagid" |
| @@ -1569,11 +1589,11 @@ | |
| 1589 | char *zBrname = fossil_strdup(db_column_text(&q,0)); |
| 1590 | const char *zObj = db_column_text(&q,2); |
| 1591 | char *zRefCmd; |
| 1592 | if( fossil_strcmp(zBrname,"trunk")==0 ){ |
| 1593 | fossil_free(zBrname); |
| 1594 | zBrname = fossil_strdup(gitmirror_mainbranch); |
| 1595 | }else{ |
| 1596 | gitmirror_sanitize_name(zBrname); |
| 1597 | } |
| 1598 | zRefCmd = mprintf("git update-ref \"refs/heads/%s\" %$", zBrname, zObj); |
| 1599 | fossil_free(zBrname); |
| @@ -1651,17 +1671,20 @@ | |
| 1671 | fossil_print("Autopush: off\n"); |
| 1672 | }else{ |
| 1673 | UrlData url; |
| 1674 | url_parse_local(z, 0, &url); |
| 1675 | fossil_print("Autopush: %s\n", url.canonical); |
| 1676 | fossil_free(z); |
| 1677 | } |
| 1678 | n = db_int(0, |
| 1679 | "SELECT count(*) FROM event" |
| 1680 | " WHERE type='ci'" |
| 1681 | " AND mtime>coalesce((SELECT value FROM mconfig" |
| 1682 | " WHERE key='start'),0.0)" |
| 1683 | ); |
| 1684 | z = db_text("master", "SELECT value FROM mconfig WHERE key='mainbranch'"); |
| 1685 | fossil_print("Main-Branch: %s\n",z); |
| 1686 | if( n==0 ){ |
| 1687 | fossil_print("Status: up-to-date\n"); |
| 1688 | }else{ |
| 1689 | fossil_print("Status: %d check-in%s awaiting export\n", |
| 1690 | n, n==1 ? "" : "s"); |
| @@ -1706,10 +1729,14 @@ | |
| 1729 | ** piping it into "git fast-import". |
| 1730 | ** --force|-f Do the export even if nothing has changed |
| 1731 | ** --if-mirrored No-op if the mirror does not already exist. |
| 1732 | ** --limit N Add no more than N new check-ins to MIRROR. |
| 1733 | ** Useful for debugging |
| 1734 | ** --mainbranch NAME Use NAME as the name of the main branch in Git. |
| 1735 | ** The "trunk" branch of the Fossil repository is |
| 1736 | ** mapped into this name. "master" is used if |
| 1737 | ** this option is omitted. |
| 1738 | ** --quiet|-q Reduce output. Repeat for even less output. |
| 1739 | ** --verbose|-v More output. |
| 1740 | ** |
| 1741 | ** > fossil git import MIRROR |
| 1742 | ** |
| 1743 |