Fossil SCM

Enhance the "fossil git export" so that it works for repositories that use a single artifact as both an ordinary file and as a check-in manifest.

drh 2019-04-22 14:22 trunk
Commit fdde65e7f1497f6512593adfd7b84b0735280714878fb7b6d7a161587bb856a3
1 file changed +34 -11
+34 -11
--- src/export.c
+++ src/export.c
@@ -952,17 +952,18 @@
952952
** then create the mark.
953953
**
954954
** The string returned is obtained from fossil_malloc() and should
955955
** be freed by the caller.
956956
*/
957
-static char *gitmirror_find_mark(const char *zUuid, int bCreate){
957
+static char *gitmirror_find_mark(const char *zUuid, int isFile, int bCreate){
958958
static Stmt sFind, sIns;
959959
db_static_prepare(&sFind,
960960
"SELECT coalesce(githash,printf(':%%d',id))"
961
- " FROM mirror.mmark WHERE uuid=:uuid"
961
+ " FROM mirror.mmark WHERE uuid=:uuid AND isfile=:isfile"
962962
);
963963
db_bind_text(&sFind, ":uuid", zUuid);
964
+ db_bind_int(&sFind, ":isfile", isFile!=0);
964965
if( db_step(&sFind)==SQLITE_ROW ){
965966
char *zMark = fossil_strdup(db_column_text(&sFind, 0));
966967
db_reset(&sFind);
967968
return zMark;
968969
}
@@ -969,13 +970,14 @@
969970
db_reset(&sFind);
970971
if( !bCreate ){
971972
return 0;
972973
}
973974
db_static_prepare(&sIns,
974
- "INSERT INTO mirror.mmark(uuid) VALUES(:uuid)"
975
+ "INSERT INTO mirror.mmark(uuid,isfile) VALUES(:uuid,:isfile)"
975976
);
976977
db_bind_text(&sIns, ":uuid", zUuid);
978
+ db_bind_int(&sIns, ":isfile", isFile!=0);
977979
db_step(&sIns);
978980
db_reset(&sIns);
979981
return mprintf(":%d", db_last_insert_rowid());
980982
}
981983
@@ -1016,11 +1018,11 @@
10161018
}else{
10171019
return 1;
10181020
}
10191021
}
10201022
}
1021
- zMark = gitmirror_find_mark(zUuid, 1);
1023
+ zMark = gitmirror_find_mark(zUuid, 1, 1);
10221024
if( zMark[0]==':' ){
10231025
fprintf(xCmd, "blob\nmark %s\ndata %d\n", zMark, blob_size(&data));
10241026
fwrite(blob_buffer(&data), 1, blob_size(&data), xCmd);
10251027
fprintf(xCmd, "\n");
10261028
}
@@ -1071,11 +1073,11 @@
10711073
}
10721074
10731075
/* Check to see if any parent logins have not yet been processed, and
10741076
** if so, create them */
10751077
for(i=0; i<pMan->nParent; i++){
1076
- char *zPMark = gitmirror_find_mark(pMan->azParent[i], 0);
1078
+ char *zPMark = gitmirror_find_mark(pMan->azParent[i], 0, 0);
10771079
if( zPMark==0 ){
10781080
int prid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q",
10791081
pMan->azParent[i]);
10801082
int rc = gitmirror_send_checkin(xCmd, prid, pMan->azParent[i],
10811083
pnLimit, fManifest);
@@ -1129,11 +1131,11 @@
11291131
}
11301132
11311133
/* Export the check-in */
11321134
fprintf(xCmd, "commit refs/heads/%s\n", zBranch);
11331135
fossil_free(zBranch);
1134
- zMark = gitmirror_find_mark(zUuid,1);
1136
+ zMark = gitmirror_find_mark(zUuid,0,1);
11351137
fprintf(xCmd, "mark %s\n", zMark);
11361138
fossil_free(zMark);
11371139
fprintf(xCmd, "committer %s <%[email protected]> %lld +0000\n",
11381140
pMan->zUser, pMan->zUser,
11391141
(sqlite3_int64)((pMan->rDate-2440587.5)*86400.0)
@@ -1145,11 +1147,11 @@
11451147
blob_appendf(&comment, "\n\nFossilOrigin-Name: %s", zUuid);
11461148
fprintf(xCmd, "data %d\n%s\n", blob_size(&comment), blob_str(&comment));
11471149
blob_reset(&comment);
11481150
iParent = -1; /* Which ancestor is the primary parent */
11491151
for(i=0; i<pMan->nParent; i++){
1150
- char *zOther = gitmirror_find_mark(pMan->azParent[i], 0);
1152
+ char *zOther = gitmirror_find_mark(pMan->azParent[i],0,0);
11511153
if( zOther==0 ) continue;
11521154
if( iParent<0 ){
11531155
iParent = i;
11541156
fprintf(xCmd, "from %s\n", zOther);
11551157
}else{
@@ -1180,11 +1182,11 @@
11801182
}
11811183
db_prepare(&q,
11821184
"SELECT x.filename, x.perm,"
11831185
" coalesce(mmark.githash,printf(':%%d',mmark.id))"
11841186
" FROM (%s) AS x, mirror.mmark"
1185
- " WHERE mmark.uuid=x.uuid",
1187
+ " WHERE mmark.uuid=x.uuid AND isfile",
11861188
blob_sql_text(&sql)
11871189
);
11881190
blob_reset(&sql);
11891191
while( db_step(&q)==SQLITE_ROW ){
11901192
const char *zFilename = db_column_text(&q,0);
@@ -1308,14 +1310,35 @@
13081310
" key TEXT PRIMARY KEY,\n"
13091311
" Value ANY\n"
13101312
") WITHOUT ROWID;\n"
13111313
"CREATE TABLE IF NOT EXISTS mirror.mmark(\n"
13121314
" id INTEGER PRIMARY KEY,\n"
1313
- " uuid TEXT UNIQUE,\n"
1314
- " githash TEXT\n"
1315
+ " uuid TEXT,\n"
1316
+ " isfile BOOLEAN,\n"
1317
+ " githash TEXT,\n"
1318
+ " UNIQUE(uuid,isfile)\n"
13151319
");"
13161320
);
1321
+ if( !db_table_has_column("mirror","mmark","isfile") ){
1322
+ db_multi_exec(
1323
+ "ALTER TABLE mirror.mmark RENAME TO mmark_old;"
1324
+ "CREATE TABLE IF NOT EXISTS mirror.mmark(\n"
1325
+ " id INTEGER PRIMARY KEY,\n"
1326
+ " uuid TEXT,\n"
1327
+ " isfile BOOLEAN,\n"
1328
+ " githash TEXT,\n"
1329
+ " UNIQUE(uuid,isfile)\n"
1330
+ ");"
1331
+ "INSERT INTO mirror.mmark(id,uuid,githash,isfile)"
1332
+ " SELECT id,uuid,githash,"
1333
+ " EXISTS(SELECT 1 FROM repository.event, repository.blob"
1334
+ " WHERE objid=blob.rid"
1335
+ " AND blob.uuid=mmark_old.uuid)"
1336
+ " FROM mirror.mmark_old;\n"
1337
+ "DROP TABLE mirror.mmark_old;\n"
1338
+ );
1339
+ }
13171340
13181341
/* Change the autopush setting if the --autopush flag is present */
13191342
if( zAutoPush ){
13201343
if( is_false(zAutoPush) ){
13211344
db_multi_exec("DELETE FROM mirror.mconfig WHERE key='autopush'");
@@ -1375,11 +1398,11 @@
13751398
"INSERT INTO tomirror "
13761399
"SELECT objid, mtime, blob.uuid FROM event, blob\n"
13771400
" WHERE type='ci'"
13781401
" AND mtime>coalesce((SELECT value FROM mconfig WHERE key='start'),0.0)"
13791402
" AND blob.rid=event.objid"
1380
- " AND blob.uuid NOT IN (SELECT uuid FROM mirror.mmark);"
1403
+ " AND blob.uuid NOT IN (SELECT uuid FROM mirror.mmark WHERE NOT isfile);"
13811404
);
13821405
nTotal = db_int(0, "SELECT count(*) FROM tomirror");
13831406
if( nLimit<nTotal ){
13841407
nTotal = nLimit;
13851408
}else if( nLimit>nTotal ){
13861409
--- src/export.c
+++ src/export.c
@@ -952,17 +952,18 @@
952 ** then create the mark.
953 **
954 ** The string returned is obtained from fossil_malloc() and should
955 ** be freed by the caller.
956 */
957 static char *gitmirror_find_mark(const char *zUuid, int bCreate){
958 static Stmt sFind, sIns;
959 db_static_prepare(&sFind,
960 "SELECT coalesce(githash,printf(':%%d',id))"
961 " FROM mirror.mmark WHERE uuid=:uuid"
962 );
963 db_bind_text(&sFind, ":uuid", zUuid);
 
964 if( db_step(&sFind)==SQLITE_ROW ){
965 char *zMark = fossil_strdup(db_column_text(&sFind, 0));
966 db_reset(&sFind);
967 return zMark;
968 }
@@ -969,13 +970,14 @@
969 db_reset(&sFind);
970 if( !bCreate ){
971 return 0;
972 }
973 db_static_prepare(&sIns,
974 "INSERT INTO mirror.mmark(uuid) VALUES(:uuid)"
975 );
976 db_bind_text(&sIns, ":uuid", zUuid);
 
977 db_step(&sIns);
978 db_reset(&sIns);
979 return mprintf(":%d", db_last_insert_rowid());
980 }
981
@@ -1016,11 +1018,11 @@
1016 }else{
1017 return 1;
1018 }
1019 }
1020 }
1021 zMark = gitmirror_find_mark(zUuid, 1);
1022 if( zMark[0]==':' ){
1023 fprintf(xCmd, "blob\nmark %s\ndata %d\n", zMark, blob_size(&data));
1024 fwrite(blob_buffer(&data), 1, blob_size(&data), xCmd);
1025 fprintf(xCmd, "\n");
1026 }
@@ -1071,11 +1073,11 @@
1071 }
1072
1073 /* Check to see if any parent logins have not yet been processed, and
1074 ** if so, create them */
1075 for(i=0; i<pMan->nParent; i++){
1076 char *zPMark = gitmirror_find_mark(pMan->azParent[i], 0);
1077 if( zPMark==0 ){
1078 int prid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q",
1079 pMan->azParent[i]);
1080 int rc = gitmirror_send_checkin(xCmd, prid, pMan->azParent[i],
1081 pnLimit, fManifest);
@@ -1129,11 +1131,11 @@
1129 }
1130
1131 /* Export the check-in */
1132 fprintf(xCmd, "commit refs/heads/%s\n", zBranch);
1133 fossil_free(zBranch);
1134 zMark = gitmirror_find_mark(zUuid,1);
1135 fprintf(xCmd, "mark %s\n", zMark);
1136 fossil_free(zMark);
1137 fprintf(xCmd, "committer %s <%[email protected]> %lld +0000\n",
1138 pMan->zUser, pMan->zUser,
1139 (sqlite3_int64)((pMan->rDate-2440587.5)*86400.0)
@@ -1145,11 +1147,11 @@
1145 blob_appendf(&comment, "\n\nFossilOrigin-Name: %s", zUuid);
1146 fprintf(xCmd, "data %d\n%s\n", blob_size(&comment), blob_str(&comment));
1147 blob_reset(&comment);
1148 iParent = -1; /* Which ancestor is the primary parent */
1149 for(i=0; i<pMan->nParent; i++){
1150 char *zOther = gitmirror_find_mark(pMan->azParent[i], 0);
1151 if( zOther==0 ) continue;
1152 if( iParent<0 ){
1153 iParent = i;
1154 fprintf(xCmd, "from %s\n", zOther);
1155 }else{
@@ -1180,11 +1182,11 @@
1180 }
1181 db_prepare(&q,
1182 "SELECT x.filename, x.perm,"
1183 " coalesce(mmark.githash,printf(':%%d',mmark.id))"
1184 " FROM (%s) AS x, mirror.mmark"
1185 " WHERE mmark.uuid=x.uuid",
1186 blob_sql_text(&sql)
1187 );
1188 blob_reset(&sql);
1189 while( db_step(&q)==SQLITE_ROW ){
1190 const char *zFilename = db_column_text(&q,0);
@@ -1308,14 +1310,35 @@
1308 " key TEXT PRIMARY KEY,\n"
1309 " Value ANY\n"
1310 ") WITHOUT ROWID;\n"
1311 "CREATE TABLE IF NOT EXISTS mirror.mmark(\n"
1312 " id INTEGER PRIMARY KEY,\n"
1313 " uuid TEXT UNIQUE,\n"
1314 " githash TEXT\n"
 
 
1315 ");"
1316 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1317
1318 /* Change the autopush setting if the --autopush flag is present */
1319 if( zAutoPush ){
1320 if( is_false(zAutoPush) ){
1321 db_multi_exec("DELETE FROM mirror.mconfig WHERE key='autopush'");
@@ -1375,11 +1398,11 @@
1375 "INSERT INTO tomirror "
1376 "SELECT objid, mtime, blob.uuid FROM event, blob\n"
1377 " WHERE type='ci'"
1378 " AND mtime>coalesce((SELECT value FROM mconfig WHERE key='start'),0.0)"
1379 " AND blob.rid=event.objid"
1380 " AND blob.uuid NOT IN (SELECT uuid FROM mirror.mmark);"
1381 );
1382 nTotal = db_int(0, "SELECT count(*) FROM tomirror");
1383 if( nLimit<nTotal ){
1384 nTotal = nLimit;
1385 }else if( nLimit>nTotal ){
1386
--- src/export.c
+++ src/export.c
@@ -952,17 +952,18 @@
952 ** then create the mark.
953 **
954 ** The string returned is obtained from fossil_malloc() and should
955 ** be freed by the caller.
956 */
957 static char *gitmirror_find_mark(const char *zUuid, int isFile, int bCreate){
958 static Stmt sFind, sIns;
959 db_static_prepare(&sFind,
960 "SELECT coalesce(githash,printf(':%%d',id))"
961 " FROM mirror.mmark WHERE uuid=:uuid AND isfile=:isfile"
962 );
963 db_bind_text(&sFind, ":uuid", zUuid);
964 db_bind_int(&sFind, ":isfile", isFile!=0);
965 if( db_step(&sFind)==SQLITE_ROW ){
966 char *zMark = fossil_strdup(db_column_text(&sFind, 0));
967 db_reset(&sFind);
968 return zMark;
969 }
@@ -969,13 +970,14 @@
970 db_reset(&sFind);
971 if( !bCreate ){
972 return 0;
973 }
974 db_static_prepare(&sIns,
975 "INSERT INTO mirror.mmark(uuid,isfile) VALUES(:uuid,:isfile)"
976 );
977 db_bind_text(&sIns, ":uuid", zUuid);
978 db_bind_int(&sIns, ":isfile", isFile!=0);
979 db_step(&sIns);
980 db_reset(&sIns);
981 return mprintf(":%d", db_last_insert_rowid());
982 }
983
@@ -1016,11 +1018,11 @@
1018 }else{
1019 return 1;
1020 }
1021 }
1022 }
1023 zMark = gitmirror_find_mark(zUuid, 1, 1);
1024 if( zMark[0]==':' ){
1025 fprintf(xCmd, "blob\nmark %s\ndata %d\n", zMark, blob_size(&data));
1026 fwrite(blob_buffer(&data), 1, blob_size(&data), xCmd);
1027 fprintf(xCmd, "\n");
1028 }
@@ -1071,11 +1073,11 @@
1073 }
1074
1075 /* Check to see if any parent logins have not yet been processed, and
1076 ** if so, create them */
1077 for(i=0; i<pMan->nParent; i++){
1078 char *zPMark = gitmirror_find_mark(pMan->azParent[i], 0, 0);
1079 if( zPMark==0 ){
1080 int prid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q",
1081 pMan->azParent[i]);
1082 int rc = gitmirror_send_checkin(xCmd, prid, pMan->azParent[i],
1083 pnLimit, fManifest);
@@ -1129,11 +1131,11 @@
1131 }
1132
1133 /* Export the check-in */
1134 fprintf(xCmd, "commit refs/heads/%s\n", zBranch);
1135 fossil_free(zBranch);
1136 zMark = gitmirror_find_mark(zUuid,0,1);
1137 fprintf(xCmd, "mark %s\n", zMark);
1138 fossil_free(zMark);
1139 fprintf(xCmd, "committer %s <%[email protected]> %lld +0000\n",
1140 pMan->zUser, pMan->zUser,
1141 (sqlite3_int64)((pMan->rDate-2440587.5)*86400.0)
@@ -1145,11 +1147,11 @@
1147 blob_appendf(&comment, "\n\nFossilOrigin-Name: %s", zUuid);
1148 fprintf(xCmd, "data %d\n%s\n", blob_size(&comment), blob_str(&comment));
1149 blob_reset(&comment);
1150 iParent = -1; /* Which ancestor is the primary parent */
1151 for(i=0; i<pMan->nParent; i++){
1152 char *zOther = gitmirror_find_mark(pMan->azParent[i],0,0);
1153 if( zOther==0 ) continue;
1154 if( iParent<0 ){
1155 iParent = i;
1156 fprintf(xCmd, "from %s\n", zOther);
1157 }else{
@@ -1180,11 +1182,11 @@
1182 }
1183 db_prepare(&q,
1184 "SELECT x.filename, x.perm,"
1185 " coalesce(mmark.githash,printf(':%%d',mmark.id))"
1186 " FROM (%s) AS x, mirror.mmark"
1187 " WHERE mmark.uuid=x.uuid AND isfile",
1188 blob_sql_text(&sql)
1189 );
1190 blob_reset(&sql);
1191 while( db_step(&q)==SQLITE_ROW ){
1192 const char *zFilename = db_column_text(&q,0);
@@ -1308,14 +1310,35 @@
1310 " key TEXT PRIMARY KEY,\n"
1311 " Value ANY\n"
1312 ") WITHOUT ROWID;\n"
1313 "CREATE TABLE IF NOT EXISTS mirror.mmark(\n"
1314 " id INTEGER PRIMARY KEY,\n"
1315 " uuid TEXT,\n"
1316 " isfile BOOLEAN,\n"
1317 " githash TEXT,\n"
1318 " UNIQUE(uuid,isfile)\n"
1319 ");"
1320 );
1321 if( !db_table_has_column("mirror","mmark","isfile") ){
1322 db_multi_exec(
1323 "ALTER TABLE mirror.mmark RENAME TO mmark_old;"
1324 "CREATE TABLE IF NOT EXISTS mirror.mmark(\n"
1325 " id INTEGER PRIMARY KEY,\n"
1326 " uuid TEXT,\n"
1327 " isfile BOOLEAN,\n"
1328 " githash TEXT,\n"
1329 " UNIQUE(uuid,isfile)\n"
1330 ");"
1331 "INSERT INTO mirror.mmark(id,uuid,githash,isfile)"
1332 " SELECT id,uuid,githash,"
1333 " EXISTS(SELECT 1 FROM repository.event, repository.blob"
1334 " WHERE objid=blob.rid"
1335 " AND blob.uuid=mmark_old.uuid)"
1336 " FROM mirror.mmark_old;\n"
1337 "DROP TABLE mirror.mmark_old;\n"
1338 );
1339 }
1340
1341 /* Change the autopush setting if the --autopush flag is present */
1342 if( zAutoPush ){
1343 if( is_false(zAutoPush) ){
1344 db_multi_exec("DELETE FROM mirror.mconfig WHERE key='autopush'");
@@ -1375,11 +1398,11 @@
1398 "INSERT INTO tomirror "
1399 "SELECT objid, mtime, blob.uuid FROM event, blob\n"
1400 " WHERE type='ci'"
1401 " AND mtime>coalesce((SELECT value FROM mconfig WHERE key='start'),0.0)"
1402 " AND blob.rid=event.objid"
1403 " AND blob.uuid NOT IN (SELECT uuid FROM mirror.mmark WHERE NOT isfile);"
1404 );
1405 nTotal = db_int(0, "SELECT count(*) FROM tomirror");
1406 if( nLimit<nTotal ){
1407 nTotal = nLimit;
1408 }else if( nLimit>nTotal ){
1409

Keyboard Shortcuts

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