Fossil SCM
Enhance the "fossil git export" command so that it also exports tags as lightweight Git tags.
Commit
4f19d67b02aeffc6d26e997b4455deac5fd2edc2a3bf8085394174e0ab14b1c6
Parent
c4f9b177f4dfa18…
1 file changed
+38
-6
+38
-6
| --- src/export.c | ||
| +++ src/export.c | ||
| @@ -1207,17 +1207,17 @@ | ||
| 1207 | 1207 | " Value ANY\n" |
| 1208 | 1208 | ") WITHOUT ROWID;\n" |
| 1209 | 1209 | "CREATE TABLE IF NOT EXISTS mirror.mmark(\n" |
| 1210 | 1210 | " id INTEGER PRIMARY KEY,\n" |
| 1211 | 1211 | " uuid TEXT UNIQUE,\n" |
| 1212 | - " githash TEXT UNIQUE\n" | |
| 1212 | + " githash TEXT\n" | |
| 1213 | 1213 | ");" |
| 1214 | 1214 | ); |
| 1215 | 1215 | |
| 1216 | 1216 | /* See if there is any work to be done. Exit early if not, before starting |
| 1217 | 1217 | ** the "git fast-import" command. */ |
| 1218 | - if( !db_exists("SELECT 1 FROM event WHERE type='ci'" | |
| 1218 | + if( !db_exists("SELECT 1 FROM event WHERE type IN ('ci','t')" | |
| 1219 | 1219 | " AND mtime>coalesce((SELECT value FROM mconfig" |
| 1220 | 1220 | " WHERE key='start'),0.0)") |
| 1221 | 1221 | ){ |
| 1222 | 1222 | fossil_print("no changes\n"); |
| 1223 | 1223 | return; |
| @@ -1279,14 +1279,10 @@ | ||
| 1279 | 1279 | if( rMTime>rEnd ) rEnd = rMTime; |
| 1280 | 1280 | gitmirror_send_checkin(xCmd, rid, zUuid, &nLimit, fManifest); |
| 1281 | 1281 | printf("\r%d/%d ", nTotal-nLimit, nTotal); |
| 1282 | 1282 | fflush(stdout); |
| 1283 | 1283 | } |
| 1284 | - db_finalize(&q); | |
| 1285 | - db_prepare(&q, "REPLACE INTO mirror.mconfig(key,value) VALUES('start',:x)"); | |
| 1286 | - db_bind_double(&q, ":x", rEnd); | |
| 1287 | - db_step(&q); | |
| 1288 | 1284 | db_finalize(&q); |
| 1289 | 1285 | fprintf(xCmd, "done\n"); |
| 1290 | 1286 | if( zDebug ){ |
| 1291 | 1287 | if( xCmd!=stdout ) fclose(xCmd); |
| 1292 | 1288 | }else{ |
| @@ -1315,19 +1311,55 @@ | ||
| 1315 | 1311 | for(k=j; fossil_isalnum(zLine[k]); k++){} |
| 1316 | 1312 | zLine[k] = 0; |
| 1317 | 1313 | db_bind_text(&q, ":githash", &zLine[j]); |
| 1318 | 1314 | db_step(&q); |
| 1319 | 1315 | db_reset(&q); |
| 1316 | + zLine[k] = '\n'; | |
| 1320 | 1317 | fputs(zLine, pIn); |
| 1321 | 1318 | } |
| 1322 | 1319 | db_finalize(&q); |
| 1323 | 1320 | fclose(pOut); |
| 1324 | 1321 | fclose(pIn); |
| 1325 | 1322 | file_delete(".mirror_state/out"); |
| 1326 | 1323 | }else{ |
| 1327 | 1324 | fossil_fatal("git fast-import didn't generate a marks file!"); |
| 1328 | 1325 | } |
| 1326 | + db_multi_exec( | |
| 1327 | + "CREATE INDEX IF NOT EXISTS mirror.mmarkx1 ON mmark(githash);" | |
| 1328 | + ); | |
| 1329 | + | |
| 1330 | + /* Do any tags that have been created since the start time */ | |
| 1331 | + db_prepare(&q, | |
| 1332 | + "SELECT substr(tagname,5), githash" | |
| 1333 | + " FROM (SELECT tagxref.tagid AS xtagid, tagname, rid, max(mtime) AS mtime" | |
| 1334 | + " FROM tagxref JOIN tag ON tag.tagid=tagxref.tagid" | |
| 1335 | + " WHERE tag.tagname GLOB 'sym-*'" | |
| 1336 | + " AND tagxref.tagtype=1" | |
| 1337 | + " AND tagxref.mtime > coalesce((SELECT value FROM mconfig" | |
| 1338 | + " WHERE key='start'),0.0)" | |
| 1339 | + " GROUP BY tagxref.tagid) AS tx" | |
| 1340 | + " JOIN blob ON tx.rid=blob.rid" | |
| 1341 | + " JOIN mmark ON mmark.uuid=blob.uuid;" | |
| 1342 | + ); | |
| 1343 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 1344 | + char *zTagname = fossil_strdup(db_column_text(&q,0)); | |
| 1345 | + const char *zObj = db_column_text(&q,1); | |
| 1346 | + char *zTagCmd; | |
| 1347 | + gitmirror_sanitize_name(zTagname); | |
| 1348 | + zTagCmd = mprintf("git tag -f \"%s\" %s", zTagname, zObj); | |
| 1349 | + fossil_free(zTagname); | |
| 1350 | + fossil_print("%s\n", zTagCmd); | |
| 1351 | + fossil_system(zTagCmd); | |
| 1352 | + fossil_free(zTagCmd); | |
| 1353 | + } | |
| 1354 | + db_finalize(&q); | |
| 1355 | + | |
| 1356 | + /* Update the start time */ | |
| 1357 | + db_prepare(&q, "REPLACE INTO mirror.mconfig(key,value) VALUES('start',:x)"); | |
| 1358 | + db_bind_double(&q, ":x", rEnd); | |
| 1359 | + db_step(&q); | |
| 1360 | + db_finalize(&q); | |
| 1329 | 1361 | db_commit_transaction(); |
| 1330 | 1362 | |
| 1331 | 1363 | /* Optionally do a "git push" */ |
| 1332 | 1364 | } |
| 1333 | 1365 | |
| 1334 | 1366 |
| --- src/export.c | |
| +++ src/export.c | |
| @@ -1207,17 +1207,17 @@ | |
| 1207 | " Value ANY\n" |
| 1208 | ") WITHOUT ROWID;\n" |
| 1209 | "CREATE TABLE IF NOT EXISTS mirror.mmark(\n" |
| 1210 | " id INTEGER PRIMARY KEY,\n" |
| 1211 | " uuid TEXT UNIQUE,\n" |
| 1212 | " githash TEXT UNIQUE\n" |
| 1213 | ");" |
| 1214 | ); |
| 1215 | |
| 1216 | /* See if there is any work to be done. Exit early if not, before starting |
| 1217 | ** the "git fast-import" command. */ |
| 1218 | if( !db_exists("SELECT 1 FROM event WHERE type='ci'" |
| 1219 | " AND mtime>coalesce((SELECT value FROM mconfig" |
| 1220 | " WHERE key='start'),0.0)") |
| 1221 | ){ |
| 1222 | fossil_print("no changes\n"); |
| 1223 | return; |
| @@ -1279,14 +1279,10 @@ | |
| 1279 | if( rMTime>rEnd ) rEnd = rMTime; |
| 1280 | gitmirror_send_checkin(xCmd, rid, zUuid, &nLimit, fManifest); |
| 1281 | printf("\r%d/%d ", nTotal-nLimit, nTotal); |
| 1282 | fflush(stdout); |
| 1283 | } |
| 1284 | db_finalize(&q); |
| 1285 | db_prepare(&q, "REPLACE INTO mirror.mconfig(key,value) VALUES('start',:x)"); |
| 1286 | db_bind_double(&q, ":x", rEnd); |
| 1287 | db_step(&q); |
| 1288 | db_finalize(&q); |
| 1289 | fprintf(xCmd, "done\n"); |
| 1290 | if( zDebug ){ |
| 1291 | if( xCmd!=stdout ) fclose(xCmd); |
| 1292 | }else{ |
| @@ -1315,19 +1311,55 @@ | |
| 1315 | for(k=j; fossil_isalnum(zLine[k]); k++){} |
| 1316 | zLine[k] = 0; |
| 1317 | db_bind_text(&q, ":githash", &zLine[j]); |
| 1318 | db_step(&q); |
| 1319 | db_reset(&q); |
| 1320 | fputs(zLine, pIn); |
| 1321 | } |
| 1322 | db_finalize(&q); |
| 1323 | fclose(pOut); |
| 1324 | fclose(pIn); |
| 1325 | file_delete(".mirror_state/out"); |
| 1326 | }else{ |
| 1327 | fossil_fatal("git fast-import didn't generate a marks file!"); |
| 1328 | } |
| 1329 | db_commit_transaction(); |
| 1330 | |
| 1331 | /* Optionally do a "git push" */ |
| 1332 | } |
| 1333 | |
| 1334 |
| --- src/export.c | |
| +++ src/export.c | |
| @@ -1207,17 +1207,17 @@ | |
| 1207 | " Value ANY\n" |
| 1208 | ") WITHOUT ROWID;\n" |
| 1209 | "CREATE TABLE IF NOT EXISTS mirror.mmark(\n" |
| 1210 | " id INTEGER PRIMARY KEY,\n" |
| 1211 | " uuid TEXT UNIQUE,\n" |
| 1212 | " githash TEXT\n" |
| 1213 | ");" |
| 1214 | ); |
| 1215 | |
| 1216 | /* See if there is any work to be done. Exit early if not, before starting |
| 1217 | ** the "git fast-import" command. */ |
| 1218 | if( !db_exists("SELECT 1 FROM event WHERE type IN ('ci','t')" |
| 1219 | " AND mtime>coalesce((SELECT value FROM mconfig" |
| 1220 | " WHERE key='start'),0.0)") |
| 1221 | ){ |
| 1222 | fossil_print("no changes\n"); |
| 1223 | return; |
| @@ -1279,14 +1279,10 @@ | |
| 1279 | if( rMTime>rEnd ) rEnd = rMTime; |
| 1280 | gitmirror_send_checkin(xCmd, rid, zUuid, &nLimit, fManifest); |
| 1281 | printf("\r%d/%d ", nTotal-nLimit, nTotal); |
| 1282 | fflush(stdout); |
| 1283 | } |
| 1284 | db_finalize(&q); |
| 1285 | fprintf(xCmd, "done\n"); |
| 1286 | if( zDebug ){ |
| 1287 | if( xCmd!=stdout ) fclose(xCmd); |
| 1288 | }else{ |
| @@ -1315,19 +1311,55 @@ | |
| 1311 | for(k=j; fossil_isalnum(zLine[k]); k++){} |
| 1312 | zLine[k] = 0; |
| 1313 | db_bind_text(&q, ":githash", &zLine[j]); |
| 1314 | db_step(&q); |
| 1315 | db_reset(&q); |
| 1316 | zLine[k] = '\n'; |
| 1317 | fputs(zLine, pIn); |
| 1318 | } |
| 1319 | db_finalize(&q); |
| 1320 | fclose(pOut); |
| 1321 | fclose(pIn); |
| 1322 | file_delete(".mirror_state/out"); |
| 1323 | }else{ |
| 1324 | fossil_fatal("git fast-import didn't generate a marks file!"); |
| 1325 | } |
| 1326 | db_multi_exec( |
| 1327 | "CREATE INDEX IF NOT EXISTS mirror.mmarkx1 ON mmark(githash);" |
| 1328 | ); |
| 1329 | |
| 1330 | /* Do any tags that have been created since the start time */ |
| 1331 | db_prepare(&q, |
| 1332 | "SELECT substr(tagname,5), githash" |
| 1333 | " FROM (SELECT tagxref.tagid AS xtagid, tagname, rid, max(mtime) AS mtime" |
| 1334 | " FROM tagxref JOIN tag ON tag.tagid=tagxref.tagid" |
| 1335 | " WHERE tag.tagname GLOB 'sym-*'" |
| 1336 | " AND tagxref.tagtype=1" |
| 1337 | " AND tagxref.mtime > coalesce((SELECT value FROM mconfig" |
| 1338 | " WHERE key='start'),0.0)" |
| 1339 | " GROUP BY tagxref.tagid) AS tx" |
| 1340 | " JOIN blob ON tx.rid=blob.rid" |
| 1341 | " JOIN mmark ON mmark.uuid=blob.uuid;" |
| 1342 | ); |
| 1343 | while( db_step(&q)==SQLITE_ROW ){ |
| 1344 | char *zTagname = fossil_strdup(db_column_text(&q,0)); |
| 1345 | const char *zObj = db_column_text(&q,1); |
| 1346 | char *zTagCmd; |
| 1347 | gitmirror_sanitize_name(zTagname); |
| 1348 | zTagCmd = mprintf("git tag -f \"%s\" %s", zTagname, zObj); |
| 1349 | fossil_free(zTagname); |
| 1350 | fossil_print("%s\n", zTagCmd); |
| 1351 | fossil_system(zTagCmd); |
| 1352 | fossil_free(zTagCmd); |
| 1353 | } |
| 1354 | db_finalize(&q); |
| 1355 | |
| 1356 | /* Update the start time */ |
| 1357 | db_prepare(&q, "REPLACE INTO mirror.mconfig(key,value) VALUES('start',:x)"); |
| 1358 | db_bind_double(&q, ":x", rEnd); |
| 1359 | db_step(&q); |
| 1360 | db_finalize(&q); |
| 1361 | db_commit_transaction(); |
| 1362 | |
| 1363 | /* Optionally do a "git push" */ |
| 1364 | } |
| 1365 | |
| 1366 |