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.

drh 2021-01-05 23:47 trunk
Commit 4c384ba2f4be30916819059f17f1cf6f3ab787560dcb06610eebe8b89751c2a2
1 file changed +29 -2
+29 -2
--- src/export.c
+++ src/export.c
@@ -862,10 +862,15 @@
862862
#define VERB_ERROR 1
863863
#define VERB_NORMAL 2
864864
#define VERB_EXTRA 3
865865
static int gitmirror_verbosity = VERB_NORMAL;
866866
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
+
867872
/*
868873
** Output routine that depends on verbosity
869874
*/
870875
static void gitmirror_message(int iLevel, const char *zFormat, ...){
871876
va_list ap;
@@ -1149,11 +1154,11 @@
11491154
"SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=%d",
11501155
TAG_BRANCH, rid
11511156
);
11521157
if( fossil_strcmp(zBranch,"trunk")==0 ){
11531158
fossil_free(zBranch);
1154
- zBranch = mprintf("master");
1159
+ zBranch = mprintf("%s",gitmirror_mainbranch);
11551160
}else if( zBranch==0 ){
11561161
zBranch = mprintf("unknown");
11571162
}else{
11581163
gitmirror_sanitize_name(zBranch);
11591164
}
@@ -1294,10 +1299,11 @@
12941299
char *zMirror; /* Name of the mirror */
12951300
char *z; /* Generic string */
12961301
char *zCmd; /* git command to run as a subprocess */
12971302
const char *zDebug = 0; /* Value of the --debug flag */
12981303
const char *zAutoPush = 0; /* Value of the --autopush flag */
1304
+ const char *zMainBr = 0; /* Value of the --mainbranch flag */
12991305
char *zPushUrl; /* URL to sync the mirror to */
13001306
double rEnd; /* time of most recent export */
13011307
int rc; /* Result code */
13021308
int bForce; /* Do the export and sync even if no changes*/
13031309
int bNeedRepack = 0; /* True if we should run repack at the end */
@@ -1314,10 +1320,11 @@
13141320
if( zLimit ){
13151321
nLimit = (unsigned int)atoi(zLimit);
13161322
if( nLimit<=0 ) fossil_fatal("--limit must be positive");
13171323
}
13181324
zAutoPush = find_option("autopush",0,1);
1325
+ zMainBr = find_option("mainbranch",0,1);
13191326
bForce = find_option("force","f",0)!=0;
13201327
bIfExists = find_option("if-mirrored",0,0)!=0;
13211328
gitmirror_verbosity = VERB_NORMAL;
13221329
while( find_option("quiet","q",0)!=0 ){ gitmirror_verbosity--; }
13231330
while( find_option("verbose","v",0)!=0 ){ gitmirror_verbosity++; }
@@ -1405,10 +1412,19 @@
14051412
"VALUES('autopush',%Q)",
14061413
zAutoPush
14071414
);
14081415
}
14091416
}
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
+ }
14101426
14111427
/* See if there is any work to be done. Exit early if not, before starting
14121428
** the "git fast-import" command. */
14131429
if( !bForce
14141430
&& !db_exists("SELECT 1 FROM event WHERE type IN ('ci','t')"
@@ -1520,10 +1536,14 @@
15201536
}
15211537
db_multi_exec(
15221538
"CREATE INDEX IF NOT EXISTS mirror.mmarkx1 ON mmark(githash);"
15231539
);
15241540
1541
+ /* Recover the saved name of the main branch */
1542
+ gitmirror_mainbranch = db_text("master",
1543
+ "SELECT value FROM mconfig WHERE key='mainbranch'");
1544
+
15251545
/* Do any tags that have been created since the start time */
15261546
db_prepare(&q,
15271547
"SELECT substr(tagname,5), githash"
15281548
" FROM (SELECT tagxref.tagid AS xtagid, tagname, rid, max(mtime) AS mtime"
15291549
" FROM tagxref JOIN tag ON tag.tagid=tagxref.tagid"
@@ -1569,11 +1589,11 @@
15691589
char *zBrname = fossil_strdup(db_column_text(&q,0));
15701590
const char *zObj = db_column_text(&q,2);
15711591
char *zRefCmd;
15721592
if( fossil_strcmp(zBrname,"trunk")==0 ){
15731593
fossil_free(zBrname);
1574
- zBrname = fossil_strdup("master");
1594
+ zBrname = fossil_strdup(gitmirror_mainbranch);
15751595
}else{
15761596
gitmirror_sanitize_name(zBrname);
15771597
}
15781598
zRefCmd = mprintf("git update-ref \"refs/heads/%s\" %$", zBrname, zObj);
15791599
fossil_free(zBrname);
@@ -1651,17 +1671,20 @@
16511671
fossil_print("Autopush: off\n");
16521672
}else{
16531673
UrlData url;
16541674
url_parse_local(z, 0, &url);
16551675
fossil_print("Autopush: %s\n", url.canonical);
1676
+ fossil_free(z);
16561677
}
16571678
n = db_int(0,
16581679
"SELECT count(*) FROM event"
16591680
" WHERE type='ci'"
16601681
" AND mtime>coalesce((SELECT value FROM mconfig"
16611682
" WHERE key='start'),0.0)"
16621683
);
1684
+ z = db_text("master", "SELECT value FROM mconfig WHERE key='mainbranch'");
1685
+ fossil_print("Main-Branch: %s\n",z);
16631686
if( n==0 ){
16641687
fossil_print("Status: up-to-date\n");
16651688
}else{
16661689
fossil_print("Status: %d check-in%s awaiting export\n",
16671690
n, n==1 ? "" : "s");
@@ -1706,10 +1729,14 @@
17061729
** piping it into "git fast-import".
17071730
** --force|-f Do the export even if nothing has changed
17081731
** --if-mirrored No-op if the mirror does not already exist.
17091732
** --limit N Add no more than N new check-ins to MIRROR.
17101733
** 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.
17111738
** --quiet|-q Reduce output. Repeat for even less output.
17121739
** --verbose|-v More output.
17131740
**
17141741
** > fossil git import MIRROR
17151742
**
17161743
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button