Fossil SCM

Enhance the "fossil git export" command so that it also exports tags as lightweight Git tags.

drh 2019-03-16 00:26 mirror-cmd
Commit 4f19d67b02aeffc6d26e997b4455deac5fd2edc2a3bf8085394174e0ab14b1c6
1 file changed +38 -6
+38 -6
--- src/export.c
+++ src/export.c
@@ -1207,17 +1207,17 @@
12071207
" Value ANY\n"
12081208
") WITHOUT ROWID;\n"
12091209
"CREATE TABLE IF NOT EXISTS mirror.mmark(\n"
12101210
" id INTEGER PRIMARY KEY,\n"
12111211
" uuid TEXT UNIQUE,\n"
1212
- " githash TEXT UNIQUE\n"
1212
+ " githash TEXT\n"
12131213
");"
12141214
);
12151215
12161216
/* See if there is any work to be done. Exit early if not, before starting
12171217
** 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')"
12191219
" AND mtime>coalesce((SELECT value FROM mconfig"
12201220
" WHERE key='start'),0.0)")
12211221
){
12221222
fossil_print("no changes\n");
12231223
return;
@@ -1279,14 +1279,10 @@
12791279
if( rMTime>rEnd ) rEnd = rMTime;
12801280
gitmirror_send_checkin(xCmd, rid, zUuid, &nLimit, fManifest);
12811281
printf("\r%d/%d ", nTotal-nLimit, nTotal);
12821282
fflush(stdout);
12831283
}
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);
12881284
db_finalize(&q);
12891285
fprintf(xCmd, "done\n");
12901286
if( zDebug ){
12911287
if( xCmd!=stdout ) fclose(xCmd);
12921288
}else{
@@ -1315,19 +1311,55 @@
13151311
for(k=j; fossil_isalnum(zLine[k]); k++){}
13161312
zLine[k] = 0;
13171313
db_bind_text(&q, ":githash", &zLine[j]);
13181314
db_step(&q);
13191315
db_reset(&q);
1316
+ zLine[k] = '\n';
13201317
fputs(zLine, pIn);
13211318
}
13221319
db_finalize(&q);
13231320
fclose(pOut);
13241321
fclose(pIn);
13251322
file_delete(".mirror_state/out");
13261323
}else{
13271324
fossil_fatal("git fast-import didn't generate a marks file!");
13281325
}
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);
13291361
db_commit_transaction();
13301362
13311363
/* Optionally do a "git push" */
13321364
}
13331365
13341366
--- 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

Keyboard Shortcuts

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