Fossil SCM

Make full use of the new file_tempname() in "fossil diff" with both --from and --to options. Improve file_tempname() to allow for a suggested differentiator tag.

drh 2019-04-25 14:28 trunk
Commit 1dd2527f2ace937e2ad5857b4041430059c738b61231eafb1e4caef907f3cd05
+1 -1
--- src/checkin.c
+++ src/checkin.c
@@ -1209,11 +1209,11 @@
12091209
if( g.zLocalRoot!=0 ){
12101210
file_relative_name(g.zLocalRoot, &fname, 1);
12111211
zFile = db_text(0, "SELECT '%qci-comment-'||hex(randomblob(6))||'.txt'",
12121212
blob_str(&fname));
12131213
}else{
1214
- file_tempname(&fname, "ci-comment");
1214
+ file_tempname(&fname, "ci-comment",0);
12151215
zFile = mprintf("%s", blob_str(&fname));
12161216
}
12171217
blob_reset(&fname);
12181218
}
12191219
#if defined(_WIN32)
12201220
--- src/checkin.c
+++ src/checkin.c
@@ -1209,11 +1209,11 @@
1209 if( g.zLocalRoot!=0 ){
1210 file_relative_name(g.zLocalRoot, &fname, 1);
1211 zFile = db_text(0, "SELECT '%qci-comment-'||hex(randomblob(6))||'.txt'",
1212 blob_str(&fname));
1213 }else{
1214 file_tempname(&fname, "ci-comment");
1215 zFile = mprintf("%s", blob_str(&fname));
1216 }
1217 blob_reset(&fname);
1218 }
1219 #if defined(_WIN32)
1220
--- src/checkin.c
+++ src/checkin.c
@@ -1209,11 +1209,11 @@
1209 if( g.zLocalRoot!=0 ){
1210 file_relative_name(g.zLocalRoot, &fname, 1);
1211 zFile = db_text(0, "SELECT '%qci-comment-'||hex(randomblob(6))||'.txt'",
1212 blob_str(&fname));
1213 }else{
1214 file_tempname(&fname, "ci-comment",0);
1215 zFile = mprintf("%s", blob_str(&fname));
1216 }
1217 blob_reset(&fname);
1218 }
1219 #if defined(_WIN32)
1220
+3 -13
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -245,11 +245,11 @@
245245
blob_reset(&file2);
246246
}
247247
248248
/* Construct a temporary file to hold pFile1 based on the name of
249249
** zFile2 */
250
- file_tempname(&nameFile1, zFile2);
250
+ file_tempname(&nameFile1, zFile2, "orig");
251251
blob_write_to_file(pFile1, blob_str(&nameFile1));
252252
253253
/* Construct the external diff command */
254254
blob_zero(&cmd);
255255
blob_append(&cmd, zDiffCmd, -1);
@@ -312,12 +312,10 @@
312312
blob_reset(&out);
313313
}else{
314314
Blob cmd;
315315
Blob temp1;
316316
Blob temp2;
317
- Blob prefix1;
318
- Blob prefix2;
319317
320318
if( !fIncludeBinary ){
321319
if( isBin1 || isBin2 ){
322320
fossil_print("%s",DIFF_CANNOT_COMPUTE_BINARY);
323321
return;
@@ -331,19 +329,13 @@
331329
}
332330
glob_free(pBinary);
333331
}
334332
}
335333
336
- /* Construct a prefix for the temporary file names */
337
- blob_zero(&prefix1);
338
- blob_zero(&prefix2);
339
- blob_appendf(&prefix1, "%s-v1", zName);
340
- blob_appendf(&prefix2, "%s-v2", zName);
341
-
342334
/* Construct a temporary file names */
343
- file_tempname(&temp1, blob_str(&prefix1));
344
- file_tempname(&temp2, blob_str(&prefix2));
335
+ file_tempname(&temp1, zName, "before");
336
+ file_tempname(&temp2, zName, "after");
345337
blob_write_to_file(pFile1, blob_str(&temp1));
346338
blob_write_to_file(pFile2, blob_str(&temp2));
347339
348340
/* Construct the external diff command */
349341
blob_zero(&cmd);
@@ -356,12 +348,10 @@
356348
357349
/* Delete the temporary file and clean up memory used */
358350
file_delete(blob_str(&temp1));
359351
file_delete(blob_str(&temp2));
360352
361
- blob_reset(&prefix1);
362
- blob_reset(&prefix2);
363353
blob_reset(&temp1);
364354
blob_reset(&temp2);
365355
blob_reset(&cmd);
366356
}
367357
}
368358
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -245,11 +245,11 @@
245 blob_reset(&file2);
246 }
247
248 /* Construct a temporary file to hold pFile1 based on the name of
249 ** zFile2 */
250 file_tempname(&nameFile1, zFile2);
251 blob_write_to_file(pFile1, blob_str(&nameFile1));
252
253 /* Construct the external diff command */
254 blob_zero(&cmd);
255 blob_append(&cmd, zDiffCmd, -1);
@@ -312,12 +312,10 @@
312 blob_reset(&out);
313 }else{
314 Blob cmd;
315 Blob temp1;
316 Blob temp2;
317 Blob prefix1;
318 Blob prefix2;
319
320 if( !fIncludeBinary ){
321 if( isBin1 || isBin2 ){
322 fossil_print("%s",DIFF_CANNOT_COMPUTE_BINARY);
323 return;
@@ -331,19 +329,13 @@
331 }
332 glob_free(pBinary);
333 }
334 }
335
336 /* Construct a prefix for the temporary file names */
337 blob_zero(&prefix1);
338 blob_zero(&prefix2);
339 blob_appendf(&prefix1, "%s-v1", zName);
340 blob_appendf(&prefix2, "%s-v2", zName);
341
342 /* Construct a temporary file names */
343 file_tempname(&temp1, blob_str(&prefix1));
344 file_tempname(&temp2, blob_str(&prefix2));
345 blob_write_to_file(pFile1, blob_str(&temp1));
346 blob_write_to_file(pFile2, blob_str(&temp2));
347
348 /* Construct the external diff command */
349 blob_zero(&cmd);
@@ -356,12 +348,10 @@
356
357 /* Delete the temporary file and clean up memory used */
358 file_delete(blob_str(&temp1));
359 file_delete(blob_str(&temp2));
360
361 blob_reset(&prefix1);
362 blob_reset(&prefix2);
363 blob_reset(&temp1);
364 blob_reset(&temp2);
365 blob_reset(&cmd);
366 }
367 }
368
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -245,11 +245,11 @@
245 blob_reset(&file2);
246 }
247
248 /* Construct a temporary file to hold pFile1 based on the name of
249 ** zFile2 */
250 file_tempname(&nameFile1, zFile2, "orig");
251 blob_write_to_file(pFile1, blob_str(&nameFile1));
252
253 /* Construct the external diff command */
254 blob_zero(&cmd);
255 blob_append(&cmd, zDiffCmd, -1);
@@ -312,12 +312,10 @@
312 blob_reset(&out);
313 }else{
314 Blob cmd;
315 Blob temp1;
316 Blob temp2;
 
 
317
318 if( !fIncludeBinary ){
319 if( isBin1 || isBin2 ){
320 fossil_print("%s",DIFF_CANNOT_COMPUTE_BINARY);
321 return;
@@ -331,19 +329,13 @@
329 }
330 glob_free(pBinary);
331 }
332 }
333
 
 
 
 
 
 
334 /* Construct a temporary file names */
335 file_tempname(&temp1, zName, "before");
336 file_tempname(&temp2, zName, "after");
337 blob_write_to_file(pFile1, blob_str(&temp1));
338 blob_write_to_file(pFile2, blob_str(&temp2));
339
340 /* Construct the external diff command */
341 blob_zero(&cmd);
@@ -356,12 +348,10 @@
348
349 /* Delete the temporary file and clean up memory used */
350 file_delete(blob_str(&temp1));
351 file_delete(blob_str(&temp2));
352
 
 
353 blob_reset(&temp1);
354 blob_reset(&temp2);
355 blob_reset(&cmd);
356 }
357 }
358
+19 -9
--- src/file.c
+++ src/file.c
@@ -1463,12 +1463,16 @@
14631463
/*
14641464
** Construct a random temporary filename into pBuf where the name of
14651465
** the temporary file is derived from zBasis. The suffix on the temp
14661466
** file is the same as the suffix on zBasis, and the temp file has
14671467
** the root of zBasis in its name.
1468
+**
1469
+** If zTag is not NULL, then try to create the temp-file using zTag
1470
+** as a differentiator. If that fails, or if zTag is NULL, then use
1471
+** a bunch of random characters as the tag.
14681472
*/
1469
-void file_tempname(Blob *pBuf, const char *zBasis){
1473
+void file_tempname(Blob *pBuf, const char *zBasis, const char *zTag){
14701474
#if defined(_WIN32)
14711475
const char *azDirs[] = {
14721476
0, /* GetTempPath */
14731477
0, /* TEMP */
14741478
0, /* TMP */
@@ -1541,16 +1545,20 @@
15411545
zBasis = "fossil";
15421546
}
15431547
do{
15441548
blob_zero(pBuf);
15451549
if( cnt++>20 ) fossil_panic("cannot generate a temporary filename");
1546
- sqlite3_randomness(15, zRand);
1547
- for(i=0; i<15; i++){
1548
- zRand[i] = (char)zChars[ ((unsigned char)zRand[i])%(sizeof(zChars)-1) ];
1550
+ if( zTag==0 ){
1551
+ sqlite3_randomness(15, zRand);
1552
+ for(i=0; i<15; i++){
1553
+ zRand[i] = (char)zChars[ ((unsigned char)zRand[i])%(sizeof(zChars)-1) ];
1554
+ }
1555
+ zRand[15] = 0;
1556
+ zTag = zRand;
15491557
}
1550
- zRand[15] = 0;
1551
- blob_appendf(pBuf, "%s/%.*s~%s%s", zDir, nBasis, zBasis, zRand, zSuffix);
1558
+ blob_appendf(pBuf, "%s/%.*s~%s%s", zDir, nBasis, zBasis, zTag, zSuffix);
1559
+ zTag = 0;
15521560
}while( file_size(blob_str(pBuf), ExtFILE)>=0 );
15531561
15541562
#if defined(_WIN32)
15551563
fossil_path_free((char *)azDirs[0]);
15561564
fossil_path_free((char *)azDirs[1]);
@@ -1582,28 +1590,30 @@
15821590
}
15831591
15841592
15851593
/*
15861594
** COMMAND: test-tempname
1587
-** Usage: fossil test-name [--time SUFFIX] BASENAME ...
1595
+** Usage: fossil test-name [--time SUFFIX] [--tag NAME] BASENAME ...
15881596
**
15891597
** Generate temporary filenames derived from BASENAME. Use the --time
1590
-** option to generate temp names based on the time of day.
1598
+** option to generate temp names based on the time of day. If --tag NAME
1599
+** is specified, try to use NAME as the differentiator in the temp file.
15911600
*/
15921601
void file_test_tempname(void){
15931602
int i;
15941603
const char *zSuffix = find_option("time",0,1);
15951604
Blob x = BLOB_INITIALIZER;
15961605
char *z;
1606
+ const char *zTag = find_option("tag",0,1);
15971607
verify_all_options();
15981608
for(i=2; i<g.argc; i++){
15991609
if( zSuffix ){
16001610
z = file_time_tempname(g.argv[i], zSuffix);
16011611
fossil_print("%s\n", z);
16021612
fossil_free(z);
16031613
}else{
1604
- file_tempname(&x, g.argv[i]);
1614
+ file_tempname(&x, g.argv[i], zTag);
16051615
fossil_print("%s\n", blob_str(&x));
16061616
blob_reset(&x);
16071617
}
16081618
}
16091619
}
16101620
--- src/file.c
+++ src/file.c
@@ -1463,12 +1463,16 @@
1463 /*
1464 ** Construct a random temporary filename into pBuf where the name of
1465 ** the temporary file is derived from zBasis. The suffix on the temp
1466 ** file is the same as the suffix on zBasis, and the temp file has
1467 ** the root of zBasis in its name.
 
 
 
 
1468 */
1469 void file_tempname(Blob *pBuf, const char *zBasis){
1470 #if defined(_WIN32)
1471 const char *azDirs[] = {
1472 0, /* GetTempPath */
1473 0, /* TEMP */
1474 0, /* TMP */
@@ -1541,16 +1545,20 @@
1541 zBasis = "fossil";
1542 }
1543 do{
1544 blob_zero(pBuf);
1545 if( cnt++>20 ) fossil_panic("cannot generate a temporary filename");
1546 sqlite3_randomness(15, zRand);
1547 for(i=0; i<15; i++){
1548 zRand[i] = (char)zChars[ ((unsigned char)zRand[i])%(sizeof(zChars)-1) ];
 
 
 
 
1549 }
1550 zRand[15] = 0;
1551 blob_appendf(pBuf, "%s/%.*s~%s%s", zDir, nBasis, zBasis, zRand, zSuffix);
1552 }while( file_size(blob_str(pBuf), ExtFILE)>=0 );
1553
1554 #if defined(_WIN32)
1555 fossil_path_free((char *)azDirs[0]);
1556 fossil_path_free((char *)azDirs[1]);
@@ -1582,28 +1590,30 @@
1582 }
1583
1584
1585 /*
1586 ** COMMAND: test-tempname
1587 ** Usage: fossil test-name [--time SUFFIX] BASENAME ...
1588 **
1589 ** Generate temporary filenames derived from BASENAME. Use the --time
1590 ** option to generate temp names based on the time of day.
 
1591 */
1592 void file_test_tempname(void){
1593 int i;
1594 const char *zSuffix = find_option("time",0,1);
1595 Blob x = BLOB_INITIALIZER;
1596 char *z;
 
1597 verify_all_options();
1598 for(i=2; i<g.argc; i++){
1599 if( zSuffix ){
1600 z = file_time_tempname(g.argv[i], zSuffix);
1601 fossil_print("%s\n", z);
1602 fossil_free(z);
1603 }else{
1604 file_tempname(&x, g.argv[i]);
1605 fossil_print("%s\n", blob_str(&x));
1606 blob_reset(&x);
1607 }
1608 }
1609 }
1610
--- src/file.c
+++ src/file.c
@@ -1463,12 +1463,16 @@
1463 /*
1464 ** Construct a random temporary filename into pBuf where the name of
1465 ** the temporary file is derived from zBasis. The suffix on the temp
1466 ** file is the same as the suffix on zBasis, and the temp file has
1467 ** the root of zBasis in its name.
1468 **
1469 ** If zTag is not NULL, then try to create the temp-file using zTag
1470 ** as a differentiator. If that fails, or if zTag is NULL, then use
1471 ** a bunch of random characters as the tag.
1472 */
1473 void file_tempname(Blob *pBuf, const char *zBasis, const char *zTag){
1474 #if defined(_WIN32)
1475 const char *azDirs[] = {
1476 0, /* GetTempPath */
1477 0, /* TEMP */
1478 0, /* TMP */
@@ -1541,16 +1545,20 @@
1545 zBasis = "fossil";
1546 }
1547 do{
1548 blob_zero(pBuf);
1549 if( cnt++>20 ) fossil_panic("cannot generate a temporary filename");
1550 if( zTag==0 ){
1551 sqlite3_randomness(15, zRand);
1552 for(i=0; i<15; i++){
1553 zRand[i] = (char)zChars[ ((unsigned char)zRand[i])%(sizeof(zChars)-1) ];
1554 }
1555 zRand[15] = 0;
1556 zTag = zRand;
1557 }
1558 blob_appendf(pBuf, "%s/%.*s~%s%s", zDir, nBasis, zBasis, zTag, zSuffix);
1559 zTag = 0;
1560 }while( file_size(blob_str(pBuf), ExtFILE)>=0 );
1561
1562 #if defined(_WIN32)
1563 fossil_path_free((char *)azDirs[0]);
1564 fossil_path_free((char *)azDirs[1]);
@@ -1582,28 +1590,30 @@
1590 }
1591
1592
1593 /*
1594 ** COMMAND: test-tempname
1595 ** Usage: fossil test-name [--time SUFFIX] [--tag NAME] BASENAME ...
1596 **
1597 ** Generate temporary filenames derived from BASENAME. Use the --time
1598 ** option to generate temp names based on the time of day. If --tag NAME
1599 ** is specified, try to use NAME as the differentiator in the temp file.
1600 */
1601 void file_test_tempname(void){
1602 int i;
1603 const char *zSuffix = find_option("time",0,1);
1604 Blob x = BLOB_INITIALIZER;
1605 char *z;
1606 const char *zTag = find_option("tag",0,1);
1607 verify_all_options();
1608 for(i=2; i<g.argc; i++){
1609 if( zSuffix ){
1610 z = file_time_tempname(g.argv[i], zSuffix);
1611 fossil_print("%s\n", z);
1612 fossil_free(z);
1613 }else{
1614 file_tempname(&x, g.argv[i], zTag);
1615 fossil_print("%s\n", blob_str(&x));
1616 blob_reset(&x);
1617 }
1618 }
1619 }
1620
+1 -1
--- src/merge.c
+++ src/merge.c
@@ -752,11 +752,11 @@
752752
zFullOldPath = mprintf("%s%s", g.zLocalRoot, zOldName);
753753
}
754754
zFullNewPath = mprintf("%s%s", g.zLocalRoot, zNewName);
755755
if( file_size(zFullNewPath, RepoFILE)>=0 ){
756756
Blob tmpPath;
757
- file_tempname(&tmpPath, "");
757
+ file_tempname(&tmpPath, "", 0);
758758
db_multi_exec("INSERT INTO tmprn(fn,tmpfn) VALUES(%Q,%Q)",
759759
zNewName, blob_str(&tmpPath));
760760
if( file_islink(zFullNewPath) ){
761761
symlink_copy(zFullNewPath, blob_str(&tmpPath));
762762
}else{
763763
--- src/merge.c
+++ src/merge.c
@@ -752,11 +752,11 @@
752 zFullOldPath = mprintf("%s%s", g.zLocalRoot, zOldName);
753 }
754 zFullNewPath = mprintf("%s%s", g.zLocalRoot, zNewName);
755 if( file_size(zFullNewPath, RepoFILE)>=0 ){
756 Blob tmpPath;
757 file_tempname(&tmpPath, "");
758 db_multi_exec("INSERT INTO tmprn(fn,tmpfn) VALUES(%Q,%Q)",
759 zNewName, blob_str(&tmpPath));
760 if( file_islink(zFullNewPath) ){
761 symlink_copy(zFullNewPath, blob_str(&tmpPath));
762 }else{
763
--- src/merge.c
+++ src/merge.c
@@ -752,11 +752,11 @@
752 zFullOldPath = mprintf("%s%s", g.zLocalRoot, zOldName);
753 }
754 zFullNewPath = mprintf("%s%s", g.zLocalRoot, zNewName);
755 if( file_size(zFullNewPath, RepoFILE)>=0 ){
756 Blob tmpPath;
757 file_tempname(&tmpPath, "", 0);
758 db_multi_exec("INSERT INTO tmprn(fn,tmpfn) VALUES(%Q,%Q)",
759 zNewName, blob_str(&tmpPath));
760 if( file_islink(zFullNewPath) ){
761 symlink_copy(zFullNewPath, blob_str(&tmpPath));
762 }else{
763

Keyboard Shortcuts

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