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.

drh 2019-03-16 13:23 trunk
Commit fe98905e9ae39e33c86f4e2c4174aacce1fa155efa7a7bd87897f0a1de2aef16
1 file changed +27 -10
+27 -10
--- src/export.c
+++ src/export.c
@@ -1158,10 +1158,11 @@
11581158
const char *zDebug = 0; /* Value of the --debug flag */
11591159
const char *zAutoPush = 0; /* Value of the --autopush flag */
11601160
char *zPushUrl; /* URL to sync the mirror to */
11611161
double rEnd; /* time of most recent export */
11621162
int rc; /* Result code */
1163
+ int bForce; /* Do the export and sync even if no changes*/
11631164
int fManifest; /* Current "manifest" setting */
11641165
FILE *xCmd; /* Pipe to the "git fast-import" command */
11651166
FILE *pIn, *pOut; /* Git mark files */
11661167
Stmt q; /* Queries */
11671168
char zLine[200]; /* One line of a mark file */
@@ -1172,13 +1173,23 @@
11721173
if( zLimit ){
11731174
nLimit = (unsigned int)atoi(zLimit);
11741175
if( nLimit<=0 ) fossil_fatal("--limit must be positive");
11751176
}
11761177
zAutoPush = find_option("autopush",0,1);
1178
+ bForce = find_option("force","f",0)!=0;
11771179
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
+ }
11801191
11811192
/* Make sure the GIT repository directory exists */
11821193
rc = file_mkdir(zMirror, ExtFILE, 0);
11831194
if( rc ) fossil_fatal("cannot create directory \"%s\"", zMirror);
11841195
@@ -1229,11 +1240,12 @@
12291240
}
12301241
}
12311242
12321243
/* See if there is any work to be done. Exit early if not, before starting
12331244
** 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')"
12351247
" AND mtime>coalesce((SELECT value FROM mconfig"
12361248
" WHERE key='start'),0.0)")
12371249
){
12381250
fossil_print("no changes\n");
12391251
db_commit_transaction();
@@ -1369,21 +1381,23 @@
13691381
fossil_free(zTagCmd);
13701382
}
13711383
db_finalize(&q);
13721384
13731385
/* 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
+ }
13781392
db_commit_transaction();
13791393
13801394
/* Optionally do a "git push" */
13811395
zPushUrl = db_text(0, "SELECT value FROM mconfig WHERE key='autopush'");
13821396
if( zPushUrl ){
13831397
char *zPushCmd = mprintf("git push --mirror %s", zPushUrl);
1384
- fossil_print("git push\n");
1398
+ fossil_print("%s", zPushCmd);
13851399
fossil_system(zPushCmd);
13861400
fossil_free(zPushCmd);
13871401
}
13881402
}
13891403
@@ -1393,19 +1407,21 @@
13931407
** Usage: %fossil git SUBCOMMAND
13941408
**
13951409
** Do incremental import or export operations between Fossil and Git.
13961410
** Subcommands:
13971411
**
1398
-** fossil git export MIRROR [OPTIONS]
1412
+** fossil git export [MIRROR] [OPTIONS]
13991413
**
14001414
** Write content from the Fossil repository into the Git repository
14011415
** in directory MIRROR. The Git repository is created if it does not
14021416
** already exist. If the Git repository does already exist, then
14031417
** new content added to fossil since the previous export is appended.
14041418
**
14051419
** 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.
14071423
**
14081424
** The MIRROR directory will contain a subdirectory named
14091425
** ".mirror_state" that contains information that Fossil needs to
14101426
** do incremental exports. Do not attempt to manage or edit the files
14111427
** in that directory since doing so can disrupt future incremental
@@ -1416,10 +1432,11 @@
14161432
** URL is remembered and used on subsequent exports
14171433
** to the same repository. Or if URL is "off" the
14181434
** auto-push mechanism is disabled
14191435
** --debug FILE Write fast-export text to FILE rather than
14201436
** piping it into "git fast-import".
1437
+** --force|-f Do the export even if nothing has changed
14211438
** --limit N Add no more than N new check-ins to MIRROR.
14221439
** Useful for debugging
14231440
**
14241441
** fossil git import MIRROR
14251442
**
14261443
--- 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

Keyboard Shortcuts

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