Fossil SCM
Update the "fossil git export" command so that it remembers the last repository name and reuses it if no repository is specified. Add the --force option.
Commit
fe98905e9ae39e33c86f4e2c4174aacce1fa155efa7a7bd87897f0a1de2aef16
Parent
ac5ae7b733e9892…
1 file changed
+27
-10
+27
-10
| --- src/export.c | ||
| +++ src/export.c | ||
| @@ -1158,10 +1158,11 @@ | ||
| 1158 | 1158 | const char *zDebug = 0; /* Value of the --debug flag */ |
| 1159 | 1159 | const char *zAutoPush = 0; /* Value of the --autopush flag */ |
| 1160 | 1160 | char *zPushUrl; /* URL to sync the mirror to */ |
| 1161 | 1161 | double rEnd; /* time of most recent export */ |
| 1162 | 1162 | int rc; /* Result code */ |
| 1163 | + int bForce; /* Do the export and sync even if no changes*/ | |
| 1163 | 1164 | int fManifest; /* Current "manifest" setting */ |
| 1164 | 1165 | FILE *xCmd; /* Pipe to the "git fast-import" command */ |
| 1165 | 1166 | FILE *pIn, *pOut; /* Git mark files */ |
| 1166 | 1167 | Stmt q; /* Queries */ |
| 1167 | 1168 | char zLine[200]; /* One line of a mark file */ |
| @@ -1172,13 +1173,23 @@ | ||
| 1172 | 1173 | if( zLimit ){ |
| 1173 | 1174 | nLimit = (unsigned int)atoi(zLimit); |
| 1174 | 1175 | if( nLimit<=0 ) fossil_fatal("--limit must be positive"); |
| 1175 | 1176 | } |
| 1176 | 1177 | zAutoPush = find_option("autopush",0,1); |
| 1178 | + bForce = find_option("force","f",0)!=0; | |
| 1177 | 1179 | verify_all_options(); |
| 1178 | - if( g.argc!=4 ){ usage("export MIRROR"); } | |
| 1179 | - zMirror = g.argv[3]; | |
| 1180 | + if( g.argc!=4 && g.argc!=3 ){ usage("export ?MIRROR?"); } | |
| 1181 | + if( g.argc==4 ){ | |
| 1182 | + Blob mirror; | |
| 1183 | + file_canonical_name(g.argv[3], &mirror, 0); | |
| 1184 | + db_set("last-git-export-repo", blob_str(&mirror), 0); | |
| 1185 | + blob_reset(&mirror); | |
| 1186 | + } | |
| 1187 | + zMirror = db_get("last-git-export-repo", 0); | |
| 1188 | + if( zMirror==0 ){ | |
| 1189 | + fossil_fatal("no Git repository specified"); | |
| 1190 | + } | |
| 1180 | 1191 | |
| 1181 | 1192 | /* Make sure the GIT repository directory exists */ |
| 1182 | 1193 | rc = file_mkdir(zMirror, ExtFILE, 0); |
| 1183 | 1194 | if( rc ) fossil_fatal("cannot create directory \"%s\"", zMirror); |
| 1184 | 1195 | |
| @@ -1229,11 +1240,12 @@ | ||
| 1229 | 1240 | } |
| 1230 | 1241 | } |
| 1231 | 1242 | |
| 1232 | 1243 | /* See if there is any work to be done. Exit early if not, before starting |
| 1233 | 1244 | ** the "git fast-import" command. */ |
| 1234 | - if( !db_exists("SELECT 1 FROM event WHERE type IN ('ci','t')" | |
| 1245 | + if( !bForce | |
| 1246 | + && !db_exists("SELECT 1 FROM event WHERE type IN ('ci','t')" | |
| 1235 | 1247 | " AND mtime>coalesce((SELECT value FROM mconfig" |
| 1236 | 1248 | " WHERE key='start'),0.0)") |
| 1237 | 1249 | ){ |
| 1238 | 1250 | fossil_print("no changes\n"); |
| 1239 | 1251 | db_commit_transaction(); |
| @@ -1369,21 +1381,23 @@ | ||
| 1369 | 1381 | fossil_free(zTagCmd); |
| 1370 | 1382 | } |
| 1371 | 1383 | db_finalize(&q); |
| 1372 | 1384 | |
| 1373 | 1385 | /* Update the start time */ |
| 1374 | - db_prepare(&q, "REPLACE INTO mirror.mconfig(key,value) VALUES('start',:x)"); | |
| 1375 | - db_bind_double(&q, ":x", rEnd); | |
| 1376 | - db_step(&q); | |
| 1377 | - db_finalize(&q); | |
| 1386 | + if( rEnd>0.0 ){ | |
| 1387 | + db_prepare(&q, "REPLACE INTO mirror.mconfig(key,value) VALUES('start',:x)"); | |
| 1388 | + db_bind_double(&q, ":x", rEnd); | |
| 1389 | + db_step(&q); | |
| 1390 | + db_finalize(&q); | |
| 1391 | + } | |
| 1378 | 1392 | db_commit_transaction(); |
| 1379 | 1393 | |
| 1380 | 1394 | /* Optionally do a "git push" */ |
| 1381 | 1395 | zPushUrl = db_text(0, "SELECT value FROM mconfig WHERE key='autopush'"); |
| 1382 | 1396 | if( zPushUrl ){ |
| 1383 | 1397 | char *zPushCmd = mprintf("git push --mirror %s", zPushUrl); |
| 1384 | - fossil_print("git push\n"); | |
| 1398 | + fossil_print("%s", zPushCmd); | |
| 1385 | 1399 | fossil_system(zPushCmd); |
| 1386 | 1400 | fossil_free(zPushCmd); |
| 1387 | 1401 | } |
| 1388 | 1402 | } |
| 1389 | 1403 | |
| @@ -1393,19 +1407,21 @@ | ||
| 1393 | 1407 | ** Usage: %fossil git SUBCOMMAND |
| 1394 | 1408 | ** |
| 1395 | 1409 | ** Do incremental import or export operations between Fossil and Git. |
| 1396 | 1410 | ** Subcommands: |
| 1397 | 1411 | ** |
| 1398 | -** fossil git export MIRROR [OPTIONS] | |
| 1412 | +** fossil git export [MIRROR] [OPTIONS] | |
| 1399 | 1413 | ** |
| 1400 | 1414 | ** Write content from the Fossil repository into the Git repository |
| 1401 | 1415 | ** in directory MIRROR. The Git repository is created if it does not |
| 1402 | 1416 | ** already exist. If the Git repository does already exist, then |
| 1403 | 1417 | ** new content added to fossil since the previous export is appended. |
| 1404 | 1418 | ** |
| 1405 | 1419 | ** Repeat this command whenever new checkins are added to the Fossil |
| 1406 | -** repository in order to reflect those changes into the mirror. | |
| 1420 | +** repository in order to reflect those changes into the mirror. If | |
| 1421 | +** the MIRROR option is omitted, the repository from the previous | |
| 1422 | +** invocation is used. | |
| 1407 | 1423 | ** |
| 1408 | 1424 | ** The MIRROR directory will contain a subdirectory named |
| 1409 | 1425 | ** ".mirror_state" that contains information that Fossil needs to |
| 1410 | 1426 | ** do incremental exports. Do not attempt to manage or edit the files |
| 1411 | 1427 | ** in that directory since doing so can disrupt future incremental |
| @@ -1416,10 +1432,11 @@ | ||
| 1416 | 1432 | ** URL is remembered and used on subsequent exports |
| 1417 | 1433 | ** to the same repository. Or if URL is "off" the |
| 1418 | 1434 | ** auto-push mechanism is disabled |
| 1419 | 1435 | ** --debug FILE Write fast-export text to FILE rather than |
| 1420 | 1436 | ** piping it into "git fast-import". |
| 1437 | +** --force|-f Do the export even if nothing has changed | |
| 1421 | 1438 | ** --limit N Add no more than N new check-ins to MIRROR. |
| 1422 | 1439 | ** Useful for debugging |
| 1423 | 1440 | ** |
| 1424 | 1441 | ** fossil git import MIRROR |
| 1425 | 1442 | ** |
| 1426 | 1443 |
| --- src/export.c | |
| +++ src/export.c | |
| @@ -1158,10 +1158,11 @@ | |
| 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 */ |
| 1166 | Stmt q; /* Queries */ |
| 1167 | char zLine[200]; /* One line of a mark file */ |
| @@ -1172,13 +1173,23 @@ | |
| 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 */ |
| 1182 | rc = file_mkdir(zMirror, ExtFILE, 0); |
| 1183 | if( rc ) fossil_fatal("cannot create directory \"%s\"", zMirror); |
| 1184 | |
| @@ -1229,11 +1240,12 @@ | |
| 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(); |
| @@ -1369,21 +1381,23 @@ | |
| 1369 | fossil_free(zTagCmd); |
| 1370 | } |
| 1371 | db_finalize(&q); |
| 1372 | |
| 1373 | /* Update the start time */ |
| 1374 | db_prepare(&q, "REPLACE INTO mirror.mconfig(key,value) VALUES('start',:x)"); |
| 1375 | db_bind_double(&q, ":x", rEnd); |
| 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 | |
| @@ -1393,19 +1407,21 @@ | |
| 1393 | ** Usage: %fossil git SUBCOMMAND |
| 1394 | ** |
| 1395 | ** Do incremental import or export operations between Fossil and Git. |
| 1396 | ** Subcommands: |
| 1397 | ** |
| 1398 | ** fossil git export MIRROR [OPTIONS] |
| 1399 | ** |
| 1400 | ** Write content from the Fossil repository into the Git repository |
| 1401 | ** in directory MIRROR. The Git repository is created if it does not |
| 1402 | ** already exist. If the Git repository does already exist, then |
| 1403 | ** new content added to fossil since the previous export is appended. |
| 1404 | ** |
| 1405 | ** Repeat this command whenever new checkins are added to the Fossil |
| 1406 | ** repository in order to reflect those changes into the mirror. |
| 1407 | ** |
| 1408 | ** The MIRROR directory will contain a subdirectory named |
| 1409 | ** ".mirror_state" that contains information that Fossil needs to |
| 1410 | ** do incremental exports. Do not attempt to manage or edit the files |
| 1411 | ** in that directory since doing so can disrupt future incremental |
| @@ -1416,10 +1432,11 @@ | |
| 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 | ** fossil git import MIRROR |
| 1425 | ** |
| 1426 |
| --- src/export.c | |
| +++ src/export.c | |
| @@ -1158,10 +1158,11 @@ | |
| 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 bForce; /* Do the export and sync even if no changes*/ |
| 1164 | int fManifest; /* Current "manifest" setting */ |
| 1165 | FILE *xCmd; /* Pipe to the "git fast-import" command */ |
| 1166 | FILE *pIn, *pOut; /* Git mark files */ |
| 1167 | Stmt q; /* Queries */ |
| 1168 | char zLine[200]; /* One line of a mark file */ |
| @@ -1172,13 +1173,23 @@ | |
| 1173 | if( zLimit ){ |
| 1174 | nLimit = (unsigned int)atoi(zLimit); |
| 1175 | if( nLimit<=0 ) fossil_fatal("--limit must be positive"); |
| 1176 | } |
| 1177 | zAutoPush = find_option("autopush",0,1); |
| 1178 | bForce = find_option("force","f",0)!=0; |
| 1179 | verify_all_options(); |
| 1180 | if( g.argc!=4 && g.argc!=3 ){ usage("export ?MIRROR?"); } |
| 1181 | if( g.argc==4 ){ |
| 1182 | Blob mirror; |
| 1183 | file_canonical_name(g.argv[3], &mirror, 0); |
| 1184 | db_set("last-git-export-repo", blob_str(&mirror), 0); |
| 1185 | blob_reset(&mirror); |
| 1186 | } |
| 1187 | zMirror = db_get("last-git-export-repo", 0); |
| 1188 | if( zMirror==0 ){ |
| 1189 | fossil_fatal("no Git repository specified"); |
| 1190 | } |
| 1191 | |
| 1192 | /* Make sure the GIT repository directory exists */ |
| 1193 | rc = file_mkdir(zMirror, ExtFILE, 0); |
| 1194 | if( rc ) fossil_fatal("cannot create directory \"%s\"", zMirror); |
| 1195 | |
| @@ -1229,11 +1240,12 @@ | |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | /* See if there is any work to be done. Exit early if not, before starting |
| 1244 | ** the "git fast-import" command. */ |
| 1245 | if( !bForce |
| 1246 | && !db_exists("SELECT 1 FROM event WHERE type IN ('ci','t')" |
| 1247 | " AND mtime>coalesce((SELECT value FROM mconfig" |
| 1248 | " WHERE key='start'),0.0)") |
| 1249 | ){ |
| 1250 | fossil_print("no changes\n"); |
| 1251 | db_commit_transaction(); |
| @@ -1369,21 +1381,23 @@ | |
| 1381 | fossil_free(zTagCmd); |
| 1382 | } |
| 1383 | db_finalize(&q); |
| 1384 | |
| 1385 | /* Update the start time */ |
| 1386 | if( rEnd>0.0 ){ |
| 1387 | db_prepare(&q, "REPLACE INTO mirror.mconfig(key,value) VALUES('start',:x)"); |
| 1388 | db_bind_double(&q, ":x", rEnd); |
| 1389 | db_step(&q); |
| 1390 | db_finalize(&q); |
| 1391 | } |
| 1392 | db_commit_transaction(); |
| 1393 | |
| 1394 | /* Optionally do a "git push" */ |
| 1395 | zPushUrl = db_text(0, "SELECT value FROM mconfig WHERE key='autopush'"); |
| 1396 | if( zPushUrl ){ |
| 1397 | char *zPushCmd = mprintf("git push --mirror %s", zPushUrl); |
| 1398 | fossil_print("%s", zPushCmd); |
| 1399 | fossil_system(zPushCmd); |
| 1400 | fossil_free(zPushCmd); |
| 1401 | } |
| 1402 | } |
| 1403 | |
| @@ -1393,19 +1407,21 @@ | |
| 1407 | ** Usage: %fossil git SUBCOMMAND |
| 1408 | ** |
| 1409 | ** Do incremental import or export operations between Fossil and Git. |
| 1410 | ** Subcommands: |
| 1411 | ** |
| 1412 | ** fossil git export [MIRROR] [OPTIONS] |
| 1413 | ** |
| 1414 | ** Write content from the Fossil repository into the Git repository |
| 1415 | ** in directory MIRROR. The Git repository is created if it does not |
| 1416 | ** already exist. If the Git repository does already exist, then |
| 1417 | ** new content added to fossil since the previous export is appended. |
| 1418 | ** |
| 1419 | ** Repeat this command whenever new checkins are added to the Fossil |
| 1420 | ** repository in order to reflect those changes into the mirror. If |
| 1421 | ** the MIRROR option is omitted, the repository from the previous |
| 1422 | ** invocation is used. |
| 1423 | ** |
| 1424 | ** The MIRROR directory will contain a subdirectory named |
| 1425 | ** ".mirror_state" that contains information that Fossil needs to |
| 1426 | ** do incremental exports. Do not attempt to manage or edit the files |
| 1427 | ** in that directory since doing so can disrupt future incremental |
| @@ -1416,10 +1432,11 @@ | |
| 1432 | ** URL is remembered and used on subsequent exports |
| 1433 | ** to the same repository. Or if URL is "off" the |
| 1434 | ** auto-push mechanism is disabled |
| 1435 | ** --debug FILE Write fast-export text to FILE rather than |
| 1436 | ** piping it into "git fast-import". |
| 1437 | ** --force|-f Do the export even if nothing has changed |
| 1438 | ** --limit N Add no more than N new check-ins to MIRROR. |
| 1439 | ** Useful for debugging |
| 1440 | ** |
| 1441 | ** fossil git import MIRROR |
| 1442 | ** |
| 1443 |