Fossil SCM

When doing a gdiff between two versions, use the files being diffed as a basis for the temporary filenames that are constructed.

drh 2016-12-23 23:42 trunk merge
Commit 051d0abaacc8b5e71fc135950903ed98a37b210e
3 files changed +23 -10 +12 -18 +6 -5
+23 -10
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -303,12 +303,14 @@
303303
304304
/* Release memory resources */
305305
blob_reset(&out);
306306
}else{
307307
Blob cmd;
308
- char zTemp1[300];
309
- char zTemp2[300];
308
+ Blob temp1;
309
+ Blob temp2;
310
+ Blob prefix1;
311
+ Blob prefix2;
310312
311313
if( !fIncludeBinary ){
312314
if( isBin1 || isBin2 ){
313315
fossil_print("%s",DIFF_CANNOT_COMPUTE_BINARY);
314316
return;
@@ -321,30 +323,41 @@
321323
return;
322324
}
323325
glob_free(pBinary);
324326
}
325327
}
328
+
329
+ /* Construct a prefix for the temporary file names */
330
+ blob_zero(&prefix1);
331
+ blob_zero(&prefix2);
332
+ blob_appendf(&prefix1, "%s-v1", zName);
333
+ blob_appendf(&prefix2, "%s-v2", zName);
326334
327335
/* Construct a temporary file names */
328
- file_tempname(sizeof(zTemp1), zTemp1);
329
- file_tempname(sizeof(zTemp2), zTemp2);
330
- blob_write_to_file(pFile1, zTemp1);
331
- blob_write_to_file(pFile2, zTemp2);
336
+ file_tempname(&temp1, blob_str(&prefix1));
337
+ file_tempname(&temp2, blob_str(&prefix2));
338
+ blob_write_to_file(pFile1, blob_str(&temp1));
339
+ blob_write_to_file(pFile2, blob_str(&temp2));
332340
333341
/* Construct the external diff command */
334342
blob_zero(&cmd);
335343
blob_appendf(&cmd, "%s ", zDiffCmd);
336
- shell_escape(&cmd, zTemp1);
344
+ shell_escape(&cmd, blob_str(&temp1));
337345
blob_append(&cmd, " ", 1);
338
- shell_escape(&cmd, zTemp2);
346
+ shell_escape(&cmd, blob_str(&temp2));
339347
340348
/* Run the external diff command */
341349
fossil_system(blob_str(&cmd));
342350
343351
/* Delete the temporary file and clean up memory used */
344
- file_delete(zTemp1);
345
- file_delete(zTemp2);
352
+ file_delete(blob_str(&temp1));
353
+ file_delete(blob_str(&temp2));
354
+
355
+ blob_reset(&prefix1);
356
+ blob_reset(&prefix2);
357
+ blob_reset(&temp1);
358
+ blob_reset(&temp2);
346359
blob_reset(&cmd);
347360
}
348361
}
349362
350363
/*
351364
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -303,12 +303,14 @@
303
304 /* Release memory resources */
305 blob_reset(&out);
306 }else{
307 Blob cmd;
308 char zTemp1[300];
309 char zTemp2[300];
 
 
310
311 if( !fIncludeBinary ){
312 if( isBin1 || isBin2 ){
313 fossil_print("%s",DIFF_CANNOT_COMPUTE_BINARY);
314 return;
@@ -321,30 +323,41 @@
321 return;
322 }
323 glob_free(pBinary);
324 }
325 }
 
 
 
 
 
 
326
327 /* Construct a temporary file names */
328 file_tempname(sizeof(zTemp1), zTemp1);
329 file_tempname(sizeof(zTemp2), zTemp2);
330 blob_write_to_file(pFile1, zTemp1);
331 blob_write_to_file(pFile2, zTemp2);
332
333 /* Construct the external diff command */
334 blob_zero(&cmd);
335 blob_appendf(&cmd, "%s ", zDiffCmd);
336 shell_escape(&cmd, zTemp1);
337 blob_append(&cmd, " ", 1);
338 shell_escape(&cmd, zTemp2);
339
340 /* Run the external diff command */
341 fossil_system(blob_str(&cmd));
342
343 /* Delete the temporary file and clean up memory used */
344 file_delete(zTemp1);
345 file_delete(zTemp2);
 
 
 
 
 
346 blob_reset(&cmd);
347 }
348 }
349
350 /*
351
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -303,12 +303,14 @@
303
304 /* Release memory resources */
305 blob_reset(&out);
306 }else{
307 Blob cmd;
308 Blob temp1;
309 Blob temp2;
310 Blob prefix1;
311 Blob prefix2;
312
313 if( !fIncludeBinary ){
314 if( isBin1 || isBin2 ){
315 fossil_print("%s",DIFF_CANNOT_COMPUTE_BINARY);
316 return;
@@ -321,30 +323,41 @@
323 return;
324 }
325 glob_free(pBinary);
326 }
327 }
328
329 /* Construct a prefix for the temporary file names */
330 blob_zero(&prefix1);
331 blob_zero(&prefix2);
332 blob_appendf(&prefix1, "%s-v1", zName);
333 blob_appendf(&prefix2, "%s-v2", zName);
334
335 /* Construct a temporary file names */
336 file_tempname(&temp1, blob_str(&prefix1));
337 file_tempname(&temp2, blob_str(&prefix2));
338 blob_write_to_file(pFile1, blob_str(&temp1));
339 blob_write_to_file(pFile2, blob_str(&temp2));
340
341 /* Construct the external diff command */
342 blob_zero(&cmd);
343 blob_appendf(&cmd, "%s ", zDiffCmd);
344 shell_escape(&cmd, blob_str(&temp1));
345 blob_append(&cmd, " ", 1);
346 shell_escape(&cmd, blob_str(&temp2));
347
348 /* Run the external diff command */
349 fossil_system(blob_str(&cmd));
350
351 /* Delete the temporary file and clean up memory used */
352 file_delete(blob_str(&temp1));
353 file_delete(blob_str(&temp2));
354
355 blob_reset(&prefix1);
356 blob_reset(&prefix2);
357 blob_reset(&temp1);
358 blob_reset(&temp2);
359 blob_reset(&cmd);
360 }
361 }
362
363 /*
364
+12 -18
--- src/file.c
+++ src/file.c
@@ -1251,13 +1251,13 @@
12511251
blob_set(pPath, "/");
12521252
}
12531253
}
12541254
12551255
/*
1256
-** Construct a random temporary filename into zBuf[].
1256
+** Construct a random temporary filename into pBuf starting with zPrefix.
12571257
*/
1258
-void file_tempname(int nBuf, char *zBuf){
1258
+void file_tempname(Blob *pBuf, const char *zPrefix){
12591259
#if defined(_WIN32)
12601260
const char *azDirs[] = {
12611261
0, /* GetTempPath */
12621262
0, /* TEMP */
12631263
0, /* TMP */
@@ -1274,13 +1274,14 @@
12741274
#endif
12751275
static const unsigned char zChars[] =
12761276
"abcdefghijklmnopqrstuvwxyz"
12771277
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
12781278
"0123456789";
1279
- unsigned int i, j;
1279
+ unsigned int i;
12801280
const char *zDir = ".";
12811281
int cnt = 0;
1282
+ char zRand[16];
12821283
12831284
#if defined(_WIN32)
12841285
wchar_t zTmpPath[MAX_PATH];
12851286
12861287
if( GetTempPathW(MAX_PATH, zTmpPath) ){
@@ -1297,27 +1298,20 @@
12971298
if( !file_isdir(azDirs[i]) ) continue;
12981299
zDir = azDirs[i];
12991300
break;
13001301
}
13011302
1302
- /* Check that the output buffer is large enough for the temporary file
1303
- ** name. If it is not, return SQLITE_ERROR.
1304
- */
1305
- if( (strlen(zDir) + 17) >= (size_t)nBuf ){
1306
- fossil_fatal("insufficient space for temporary filename");
1307
- }
1308
-
13091303
do{
1304
+ blob_zero(pBuf);
13101305
if( cnt++>20 ) fossil_panic("cannot generate a temporary filename");
1311
- sqlite3_snprintf(nBuf-17, zBuf, "%s/", zDir);
1312
- j = (int)strlen(zBuf);
1313
- sqlite3_randomness(15, &zBuf[j]);
1314
- for(i=0; i<15; i++, j++){
1315
- zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
1316
- }
1317
- zBuf[j] = 0;
1318
- }while( file_size(zBuf)>=0 );
1306
+ sqlite3_randomness(15, zRand);
1307
+ for(i=0; i<15; i++){
1308
+ zRand[i] = (char)zChars[ ((unsigned char)zRand[i])%(sizeof(zChars)-1) ];
1309
+ }
1310
+ zRand[15] = 0;
1311
+ blob_appendf(pBuf, "%s/%s.%s", zDir, zPrefix ? zPrefix : "", zRand);
1312
+ }while( file_size(blob_str(pBuf))>=0 );
13191313
13201314
#if defined(_WIN32)
13211315
fossil_path_free((char *)azDirs[0]);
13221316
fossil_path_free((char *)azDirs[1]);
13231317
fossil_path_free((char *)azDirs[2]);
13241318
--- src/file.c
+++ src/file.c
@@ -1251,13 +1251,13 @@
1251 blob_set(pPath, "/");
1252 }
1253 }
1254
1255 /*
1256 ** Construct a random temporary filename into zBuf[].
1257 */
1258 void file_tempname(int nBuf, char *zBuf){
1259 #if defined(_WIN32)
1260 const char *azDirs[] = {
1261 0, /* GetTempPath */
1262 0, /* TEMP */
1263 0, /* TMP */
@@ -1274,13 +1274,14 @@
1274 #endif
1275 static const unsigned char zChars[] =
1276 "abcdefghijklmnopqrstuvwxyz"
1277 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1278 "0123456789";
1279 unsigned int i, j;
1280 const char *zDir = ".";
1281 int cnt = 0;
 
1282
1283 #if defined(_WIN32)
1284 wchar_t zTmpPath[MAX_PATH];
1285
1286 if( GetTempPathW(MAX_PATH, zTmpPath) ){
@@ -1297,27 +1298,20 @@
1297 if( !file_isdir(azDirs[i]) ) continue;
1298 zDir = azDirs[i];
1299 break;
1300 }
1301
1302 /* Check that the output buffer is large enough for the temporary file
1303 ** name. If it is not, return SQLITE_ERROR.
1304 */
1305 if( (strlen(zDir) + 17) >= (size_t)nBuf ){
1306 fossil_fatal("insufficient space for temporary filename");
1307 }
1308
1309 do{
 
1310 if( cnt++>20 ) fossil_panic("cannot generate a temporary filename");
1311 sqlite3_snprintf(nBuf-17, zBuf, "%s/", zDir);
1312 j = (int)strlen(zBuf);
1313 sqlite3_randomness(15, &zBuf[j]);
1314 for(i=0; i<15; i++, j++){
1315 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
1316 }
1317 zBuf[j] = 0;
1318 }while( file_size(zBuf)>=0 );
1319
1320 #if defined(_WIN32)
1321 fossil_path_free((char *)azDirs[0]);
1322 fossil_path_free((char *)azDirs[1]);
1323 fossil_path_free((char *)azDirs[2]);
1324
--- src/file.c
+++ src/file.c
@@ -1251,13 +1251,13 @@
1251 blob_set(pPath, "/");
1252 }
1253 }
1254
1255 /*
1256 ** Construct a random temporary filename into pBuf starting with zPrefix.
1257 */
1258 void file_tempname(Blob *pBuf, const char *zPrefix){
1259 #if defined(_WIN32)
1260 const char *azDirs[] = {
1261 0, /* GetTempPath */
1262 0, /* TEMP */
1263 0, /* TMP */
@@ -1274,13 +1274,14 @@
1274 #endif
1275 static const unsigned char zChars[] =
1276 "abcdefghijklmnopqrstuvwxyz"
1277 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1278 "0123456789";
1279 unsigned int i;
1280 const char *zDir = ".";
1281 int cnt = 0;
1282 char zRand[16];
1283
1284 #if defined(_WIN32)
1285 wchar_t zTmpPath[MAX_PATH];
1286
1287 if( GetTempPathW(MAX_PATH, zTmpPath) ){
@@ -1297,27 +1298,20 @@
1298 if( !file_isdir(azDirs[i]) ) continue;
1299 zDir = azDirs[i];
1300 break;
1301 }
1302
 
 
 
 
 
 
 
1303 do{
1304 blob_zero(pBuf);
1305 if( cnt++>20 ) fossil_panic("cannot generate a temporary filename");
1306 sqlite3_randomness(15, zRand);
1307 for(i=0; i<15; i++){
1308 zRand[i] = (char)zChars[ ((unsigned char)zRand[i])%(sizeof(zChars)-1) ];
1309 }
1310 zRand[15] = 0;
1311 blob_appendf(pBuf, "%s/%s.%s", zDir, zPrefix ? zPrefix : "", zRand);
1312 }while( file_size(blob_str(pBuf))>=0 );
 
1313
1314 #if defined(_WIN32)
1315 fossil_path_free((char *)azDirs[0]);
1316 fossil_path_free((char *)azDirs[1]);
1317 fossil_path_free((char *)azDirs[2]);
1318
+6 -5
--- src/merge.c
+++ src/merge.c
@@ -737,19 +737,20 @@
737737
if( !zFullOldPath ){
738738
zFullOldPath = mprintf("%s%s", g.zLocalRoot, zOldName);
739739
}
740740
zFullNewPath = mprintf("%s%s", g.zLocalRoot, zNewName);
741741
if( file_wd_size(zFullNewPath)>=0 ){
742
- char zTmpPath[300];
743
- file_tempname(sizeof(zTmpPath), zTmpPath);
742
+ Blob tmpPath;
743
+ file_tempname(&tmpPath, "");
744744
db_multi_exec("INSERT INTO tmprn(fn,tmpfn) VALUES(%Q,%Q)",
745
- zNewName, zTmpPath);
745
+ zNewName, blob_str(&tmpPath));
746746
if( file_wd_islink(zFullNewPath) ){
747
- symlink_copy(zFullNewPath, zTmpPath);
747
+ symlink_copy(zFullNewPath, blob_str(&tmpPath));
748748
}else{
749
- file_copy(zFullNewPath, zTmpPath);
749
+ file_copy(zFullNewPath, blob_str(&tmpPath));
750750
}
751
+ blob_reset(&tmpPath);
751752
}
752753
if( file_wd_islink(zFullOldPath) ){
753754
symlink_copy(zFullOldPath, zFullNewPath);
754755
}else{
755756
file_copy(zFullOldPath, zFullNewPath);
756757
--- src/merge.c
+++ src/merge.c
@@ -737,19 +737,20 @@
737 if( !zFullOldPath ){
738 zFullOldPath = mprintf("%s%s", g.zLocalRoot, zOldName);
739 }
740 zFullNewPath = mprintf("%s%s", g.zLocalRoot, zNewName);
741 if( file_wd_size(zFullNewPath)>=0 ){
742 char zTmpPath[300];
743 file_tempname(sizeof(zTmpPath), zTmpPath);
744 db_multi_exec("INSERT INTO tmprn(fn,tmpfn) VALUES(%Q,%Q)",
745 zNewName, zTmpPath);
746 if( file_wd_islink(zFullNewPath) ){
747 symlink_copy(zFullNewPath, zTmpPath);
748 }else{
749 file_copy(zFullNewPath, zTmpPath);
750 }
 
751 }
752 if( file_wd_islink(zFullOldPath) ){
753 symlink_copy(zFullOldPath, zFullNewPath);
754 }else{
755 file_copy(zFullOldPath, zFullNewPath);
756
--- src/merge.c
+++ src/merge.c
@@ -737,19 +737,20 @@
737 if( !zFullOldPath ){
738 zFullOldPath = mprintf("%s%s", g.zLocalRoot, zOldName);
739 }
740 zFullNewPath = mprintf("%s%s", g.zLocalRoot, zNewName);
741 if( file_wd_size(zFullNewPath)>=0 ){
742 Blob tmpPath;
743 file_tempname(&tmpPath, "");
744 db_multi_exec("INSERT INTO tmprn(fn,tmpfn) VALUES(%Q,%Q)",
745 zNewName, blob_str(&tmpPath));
746 if( file_wd_islink(zFullNewPath) ){
747 symlink_copy(zFullNewPath, blob_str(&tmpPath));
748 }else{
749 file_copy(zFullNewPath, blob_str(&tmpPath));
750 }
751 blob_reset(&tmpPath);
752 }
753 if( file_wd_islink(zFullOldPath) ){
754 symlink_copy(zFullOldPath, zFullNewPath);
755 }else{
756 file_copy(zFullOldPath, zFullNewPath);
757

Keyboard Shortcuts

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