Fossil SCM

Add the --autopush option to the "fossil git export" command.

drh 2019-03-16 13:06 trunk
Commit ac5ae7b733e9892e895c4781b75cf59ebad182acf0060812f13fa6326c910603
1 file changed +28
+28
--- src/export.c
+++ src/export.c
@@ -1154,10 +1154,12 @@
11541154
int nTotal = 0; /* Total number of check-ins to export */
11551155
char *zMirror; /* Name of the mirror */
11561156
char *z; /* Generic string */
11571157
char *zCmd; /* git command to run as a subprocess */
11581158
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 */
11591161
double rEnd; /* time of most recent export */
11601162
int rc; /* Result code */
11611163
int fManifest; /* Current "manifest" setting */
11621164
FILE *xCmd; /* Pipe to the "git fast-import" command */
11631165
FILE *pIn, *pOut; /* Git mark files */
@@ -1169,10 +1171,11 @@
11691171
zLimit = find_option("limit", 0, 1);
11701172
if( zLimit ){
11711173
nLimit = (unsigned int)atoi(zLimit);
11721174
if( nLimit<=0 ) fossil_fatal("--limit must be positive");
11731175
}
1176
+ zAutoPush = find_option("autopush",0,1);
11741177
verify_all_options();
11751178
if( g.argc!=4 ){ usage("export MIRROR"); }
11761179
zMirror = g.argv[3];
11771180
11781181
/* Make sure the GIT repository directory exists */
@@ -1210,18 +1213,32 @@
12101213
" id INTEGER PRIMARY KEY,\n"
12111214
" uuid TEXT UNIQUE,\n"
12121215
" githash TEXT\n"
12131216
");"
12141217
);
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
+ }
12151231
12161232
/* See if there is any work to be done. Exit early if not, before starting
12171233
** the "git fast-import" command. */
12181234
if( !db_exists("SELECT 1 FROM event WHERE type IN ('ci','t')"
12191235
" AND mtime>coalesce((SELECT value FROM mconfig"
12201236
" WHERE key='start'),0.0)")
12211237
){
12221238
fossil_print("no changes\n");
1239
+ db_commit_transaction();
12231240
return;
12241241
}
12251242
12261243
/* Do we need to include manifest files in the clone? */
12271244
fManifest = db_get_manifest_setting();
@@ -1359,10 +1376,17 @@
13591376
db_step(&q);
13601377
db_finalize(&q);
13611378
db_commit_transaction();
13621379
13631380
/* 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
+ }
13641388
}
13651389
13661390
/*
13671391
** COMMAND: git
13681392
**
@@ -1386,10 +1410,14 @@
13861410
** do incremental exports. Do not attempt to manage or edit the files
13871411
** in that directory since doing so can disrupt future incremental
13881412
** exports.
13891413
**
13901414
** 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
13911419
** --debug FILE Write fast-export text to FILE rather than
13921420
** piping it into "git fast-import".
13931421
** --limit N Add no more than N new check-ins to MIRROR.
13941422
** Useful for debugging
13951423
**
13961424
--- 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

Keyboard Shortcuts

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