Fossil SCM
Add the --autopush option to the "fossil git export" command.
Commit
ac5ae7b733e9892e895c4781b75cf59ebad182acf0060812f13fa6326c910603
Parent
ced33d1abf21659…
1 file changed
+28
+28
| --- src/export.c | ||
| +++ src/export.c | ||
| @@ -1154,10 +1154,12 @@ | ||
| 1154 | 1154 | int nTotal = 0; /* Total number of check-ins to export */ |
| 1155 | 1155 | char *zMirror; /* Name of the mirror */ |
| 1156 | 1156 | char *z; /* Generic string */ |
| 1157 | 1157 | char *zCmd; /* git command to run as a subprocess */ |
| 1158 | 1158 | const char *zDebug = 0; /* Value of the --debug flag */ |
| 1159 | + const char *zAutoPush = 0; /* Value of the --autopush flag */ | |
| 1160 | + char *zPushUrl; /* URL to sync the mirror to */ | |
| 1159 | 1161 | double rEnd; /* time of most recent export */ |
| 1160 | 1162 | int rc; /* Result code */ |
| 1161 | 1163 | int fManifest; /* Current "manifest" setting */ |
| 1162 | 1164 | FILE *xCmd; /* Pipe to the "git fast-import" command */ |
| 1163 | 1165 | FILE *pIn, *pOut; /* Git mark files */ |
| @@ -1169,10 +1171,11 @@ | ||
| 1169 | 1171 | zLimit = find_option("limit", 0, 1); |
| 1170 | 1172 | if( zLimit ){ |
| 1171 | 1173 | nLimit = (unsigned int)atoi(zLimit); |
| 1172 | 1174 | if( nLimit<=0 ) fossil_fatal("--limit must be positive"); |
| 1173 | 1175 | } |
| 1176 | + zAutoPush = find_option("autopush",0,1); | |
| 1174 | 1177 | verify_all_options(); |
| 1175 | 1178 | if( g.argc!=4 ){ usage("export MIRROR"); } |
| 1176 | 1179 | zMirror = g.argv[3]; |
| 1177 | 1180 | |
| 1178 | 1181 | /* Make sure the GIT repository directory exists */ |
| @@ -1210,18 +1213,32 @@ | ||
| 1210 | 1213 | " id INTEGER PRIMARY KEY,\n" |
| 1211 | 1214 | " uuid TEXT UNIQUE,\n" |
| 1212 | 1215 | " githash TEXT\n" |
| 1213 | 1216 | ");" |
| 1214 | 1217 | ); |
| 1218 | + | |
| 1219 | + /* Change the autopush setting if the --autopush flag is present */ | |
| 1220 | + if( zAutoPush ){ | |
| 1221 | + if( is_false(zAutoPush) ){ | |
| 1222 | + db_multi_exec("DELETE FROM mirror.mconfig WHERE key='autopush'"); | |
| 1223 | + }else{ | |
| 1224 | + db_multi_exec( | |
| 1225 | + "REPLACE INTO mirror.mconfig(key,value)" | |
| 1226 | + "VALUES('autopush',%Q)", | |
| 1227 | + zAutoPush | |
| 1228 | + ); | |
| 1229 | + } | |
| 1230 | + } | |
| 1215 | 1231 | |
| 1216 | 1232 | /* See if there is any work to be done. Exit early if not, before starting |
| 1217 | 1233 | ** the "git fast-import" command. */ |
| 1218 | 1234 | if( !db_exists("SELECT 1 FROM event WHERE type IN ('ci','t')" |
| 1219 | 1235 | " AND mtime>coalesce((SELECT value FROM mconfig" |
| 1220 | 1236 | " WHERE key='start'),0.0)") |
| 1221 | 1237 | ){ |
| 1222 | 1238 | fossil_print("no changes\n"); |
| 1239 | + db_commit_transaction(); | |
| 1223 | 1240 | return; |
| 1224 | 1241 | } |
| 1225 | 1242 | |
| 1226 | 1243 | /* Do we need to include manifest files in the clone? */ |
| 1227 | 1244 | fManifest = db_get_manifest_setting(); |
| @@ -1359,10 +1376,17 @@ | ||
| 1359 | 1376 | db_step(&q); |
| 1360 | 1377 | db_finalize(&q); |
| 1361 | 1378 | db_commit_transaction(); |
| 1362 | 1379 | |
| 1363 | 1380 | /* Optionally do a "git push" */ |
| 1381 | + zPushUrl = db_text(0, "SELECT value FROM mconfig WHERE key='autopush'"); | |
| 1382 | + if( zPushUrl ){ | |
| 1383 | + char *zPushCmd = mprintf("git push --mirror %s", zPushUrl); | |
| 1384 | + fossil_print("git push\n"); | |
| 1385 | + fossil_system(zPushCmd); | |
| 1386 | + fossil_free(zPushCmd); | |
| 1387 | + } | |
| 1364 | 1388 | } |
| 1365 | 1389 | |
| 1366 | 1390 | /* |
| 1367 | 1391 | ** COMMAND: git |
| 1368 | 1392 | ** |
| @@ -1386,10 +1410,14 @@ | ||
| 1386 | 1410 | ** do incremental exports. Do not attempt to manage or edit the files |
| 1387 | 1411 | ** in that directory since doing so can disrupt future incremental |
| 1388 | 1412 | ** exports. |
| 1389 | 1413 | ** |
| 1390 | 1414 | ** Options: |
| 1415 | +** --autopush URL Automatically do a 'git push' to URL. The | |
| 1416 | +** URL is remembered and used on subsequent exports | |
| 1417 | +** to the same repository. Or if URL is "off" the | |
| 1418 | +** auto-push mechanism is disabled | |
| 1391 | 1419 | ** --debug FILE Write fast-export text to FILE rather than |
| 1392 | 1420 | ** piping it into "git fast-import". |
| 1393 | 1421 | ** --limit N Add no more than N new check-ins to MIRROR. |
| 1394 | 1422 | ** Useful for debugging |
| 1395 | 1423 | ** |
| 1396 | 1424 |
| --- src/export.c | |
| +++ src/export.c | |
| @@ -1154,10 +1154,12 @@ | |
| 1154 | int nTotal = 0; /* Total number of check-ins to export */ |
| 1155 | char *zMirror; /* Name of the mirror */ |
| 1156 | char *z; /* Generic string */ |
| 1157 | char *zCmd; /* git command to run as a subprocess */ |
| 1158 | const char *zDebug = 0; /* Value of the --debug flag */ |
| 1159 | double rEnd; /* time of most recent export */ |
| 1160 | int rc; /* Result code */ |
| 1161 | int fManifest; /* Current "manifest" setting */ |
| 1162 | FILE *xCmd; /* Pipe to the "git fast-import" command */ |
| 1163 | FILE *pIn, *pOut; /* Git mark files */ |
| @@ -1169,10 +1171,11 @@ | |
| 1169 | zLimit = find_option("limit", 0, 1); |
| 1170 | if( zLimit ){ |
| 1171 | nLimit = (unsigned int)atoi(zLimit); |
| 1172 | if( nLimit<=0 ) fossil_fatal("--limit must be positive"); |
| 1173 | } |
| 1174 | verify_all_options(); |
| 1175 | if( g.argc!=4 ){ usage("export MIRROR"); } |
| 1176 | zMirror = g.argv[3]; |
| 1177 | |
| 1178 | /* Make sure the GIT repository directory exists */ |
| @@ -1210,18 +1213,32 @@ | |
| 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; |
| 1224 | } |
| 1225 | |
| 1226 | /* Do we need to include manifest files in the clone? */ |
| 1227 | fManifest = db_get_manifest_setting(); |
| @@ -1359,10 +1376,17 @@ | |
| 1359 | db_step(&q); |
| 1360 | db_finalize(&q); |
| 1361 | db_commit_transaction(); |
| 1362 | |
| 1363 | /* Optionally do a "git push" */ |
| 1364 | } |
| 1365 | |
| 1366 | /* |
| 1367 | ** COMMAND: git |
| 1368 | ** |
| @@ -1386,10 +1410,14 @@ | |
| 1386 | ** do incremental exports. Do not attempt to manage or edit the files |
| 1387 | ** in that directory since doing so can disrupt future incremental |
| 1388 | ** exports. |
| 1389 | ** |
| 1390 | ** Options: |
| 1391 | ** --debug FILE Write fast-export text to FILE rather than |
| 1392 | ** piping it into "git fast-import". |
| 1393 | ** --limit N Add no more than N new check-ins to MIRROR. |
| 1394 | ** Useful for debugging |
| 1395 | ** |
| 1396 |
| --- src/export.c | |
| +++ src/export.c | |
| @@ -1154,10 +1154,12 @@ | |
| 1154 | int nTotal = 0; /* Total number of check-ins to export */ |
| 1155 | char *zMirror; /* Name of the mirror */ |
| 1156 | char *z; /* Generic string */ |
| 1157 | char *zCmd; /* git command to run as a subprocess */ |
| 1158 | const char *zDebug = 0; /* Value of the --debug flag */ |
| 1159 | const char *zAutoPush = 0; /* Value of the --autopush flag */ |
| 1160 | char *zPushUrl; /* URL to sync the mirror to */ |
| 1161 | double rEnd; /* time of most recent export */ |
| 1162 | int rc; /* Result code */ |
| 1163 | int fManifest; /* Current "manifest" setting */ |
| 1164 | FILE *xCmd; /* Pipe to the "git fast-import" command */ |
| 1165 | FILE *pIn, *pOut; /* Git mark files */ |
| @@ -1169,10 +1171,11 @@ | |
| 1171 | zLimit = find_option("limit", 0, 1); |
| 1172 | if( zLimit ){ |
| 1173 | nLimit = (unsigned int)atoi(zLimit); |
| 1174 | if( nLimit<=0 ) fossil_fatal("--limit must be positive"); |
| 1175 | } |
| 1176 | zAutoPush = find_option("autopush",0,1); |
| 1177 | verify_all_options(); |
| 1178 | if( g.argc!=4 ){ usage("export MIRROR"); } |
| 1179 | zMirror = g.argv[3]; |
| 1180 | |
| 1181 | /* Make sure the GIT repository directory exists */ |
| @@ -1210,18 +1213,32 @@ | |
| 1213 | " id INTEGER PRIMARY KEY,\n" |
| 1214 | " uuid TEXT UNIQUE,\n" |
| 1215 | " githash TEXT\n" |
| 1216 | ");" |
| 1217 | ); |
| 1218 | |
| 1219 | /* Change the autopush setting if the --autopush flag is present */ |
| 1220 | if( zAutoPush ){ |
| 1221 | if( is_false(zAutoPush) ){ |
| 1222 | db_multi_exec("DELETE FROM mirror.mconfig WHERE key='autopush'"); |
| 1223 | }else{ |
| 1224 | db_multi_exec( |
| 1225 | "REPLACE INTO mirror.mconfig(key,value)" |
| 1226 | "VALUES('autopush',%Q)", |
| 1227 | zAutoPush |
| 1228 | ); |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | /* See if there is any work to be done. Exit early if not, before starting |
| 1233 | ** the "git fast-import" command. */ |
| 1234 | if( !db_exists("SELECT 1 FROM event WHERE type IN ('ci','t')" |
| 1235 | " AND mtime>coalesce((SELECT value FROM mconfig" |
| 1236 | " WHERE key='start'),0.0)") |
| 1237 | ){ |
| 1238 | fossil_print("no changes\n"); |
| 1239 | db_commit_transaction(); |
| 1240 | return; |
| 1241 | } |
| 1242 | |
| 1243 | /* Do we need to include manifest files in the clone? */ |
| 1244 | fManifest = db_get_manifest_setting(); |
| @@ -1359,10 +1376,17 @@ | |
| 1376 | db_step(&q); |
| 1377 | db_finalize(&q); |
| 1378 | db_commit_transaction(); |
| 1379 | |
| 1380 | /* Optionally do a "git push" */ |
| 1381 | zPushUrl = db_text(0, "SELECT value FROM mconfig WHERE key='autopush'"); |
| 1382 | if( zPushUrl ){ |
| 1383 | char *zPushCmd = mprintf("git push --mirror %s", zPushUrl); |
| 1384 | fossil_print("git push\n"); |
| 1385 | fossil_system(zPushCmd); |
| 1386 | fossil_free(zPushCmd); |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | /* |
| 1391 | ** COMMAND: git |
| 1392 | ** |
| @@ -1386,10 +1410,14 @@ | |
| 1410 | ** do incremental exports. Do not attempt to manage or edit the files |
| 1411 | ** in that directory since doing so can disrupt future incremental |
| 1412 | ** exports. |
| 1413 | ** |
| 1414 | ** Options: |
| 1415 | ** --autopush URL Automatically do a 'git push' to URL. The |
| 1416 | ** URL is remembered and used on subsequent exports |
| 1417 | ** to the same repository. Or if URL is "off" the |
| 1418 | ** auto-push mechanism is disabled |
| 1419 | ** --debug FILE Write fast-export text to FILE rather than |
| 1420 | ** piping it into "git fast-import". |
| 1421 | ** --limit N Add no more than N new check-ins to MIRROR. |
| 1422 | ** Useful for debugging |
| 1423 | ** |
| 1424 |