Fossil SCM

With external diff command, use /dev/null for added or deleted files. Implemented for Unix as I am unsure how Windows diff tools would deal with NUL.

preben 2023-10-05 13:26 diff-deleted-files
Commit fd359387ca9cf45729a3084fdb6eb6c006ea024e9e6936e21f06a79dd851119f
1 file changed +38
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -500,14 +500,34 @@
500500
return;
501501
}
502502
blob_reset(&file2);
503503
}
504504
505
+#if defined(_WIN32)
506
+ /* TODO: How would a (common?) diff program on Windows react to NUL? */
505507
/* Construct a temporary file to hold pFile1 based on the name of
506508
** zFile2 */
507509
file_tempname(&nameFile1, zFile2, "orig");
508510
blob_write_to_file(pFile1, blob_str(&nameFile1));
511
+#else
512
+ if( pCfg->diffFlags & DIFF_FILE_ADDED ){
513
+ blob_init(&nameFile1, NULL_DEVICE, -1);
514
+ }else{
515
+ if( pCfg->diffFlags & DIFF_FILE_DELETED ){
516
+ /* Indicate a deleted file as /dev/null on Unix.
517
+ ** For Windows, depends on how the diff tool handles NUL.
518
+ */
519
+ blob_init(&nameFile1, zFile2, -1);
520
+ zFile2 = NULL_DEVICE;
521
+ }else{
522
+ /* Construct a temporary file to hold pFile1 based on the name of
523
+ ** zFile2 */
524
+ file_tempname(&nameFile1, zFile2, "orig");
525
+ }
526
+ blob_write_to_file(pFile1, blob_str(&nameFile1));
527
+ }
528
+#endif
509529
510530
/* Construct the external diff command */
511531
blob_zero(&cmd);
512532
blob_append(&cmd, pCfg->zDiffCmd, -1);
513533
if( pCfg->diffFlags & DIFF_INVERT ){
@@ -581,15 +601,33 @@
581601
}
582602
glob_free(pBinary);
583603
}
584604
}
585605
606
+#if defined(_WIN32)
607
+ /* TODO: How would a (common?) diff program on Windows react to NUL? */
586608
/* Construct a temporary file names */
587609
file_tempname(&temp1, zName, "before");
588610
file_tempname(&temp2, zName, "after");
589611
blob_write_to_file(pFile1, blob_str(&temp1));
590612
blob_write_to_file(pFile2, blob_str(&temp2));
613
+#else
614
+ if( pCfg->diffFlags & DIFF_FILE_ADDED ){
615
+ blob_init(&temp1, NULL_DEVICE, -1);
616
+ blob_init(&temp2, zName, -1);
617
+ blob_write_to_file(pFile2, blob_str(&temp2));
618
+ }else if( pCfg->diffFlags & DIFF_FILE_DELETED ){
619
+ blob_init(&temp1, zName, -1);
620
+ blob_init(&temp2, NULL_DEVICE, -1);
621
+ blob_write_to_file(pFile1, blob_str(&temp1));
622
+ }else{
623
+ file_tempname(&temp1, zName, "before");
624
+ file_tempname(&temp2, zName, "after");
625
+ blob_write_to_file(pFile1, blob_str(&temp1));
626
+ blob_write_to_file(pFile2, blob_str(&temp2));
627
+ }
628
+#endif
591629
592630
/* Construct the external diff command */
593631
blob_zero(&cmd);
594632
blob_append(&cmd, pCfg->zDiffCmd, -1);
595633
blob_append_escaped_arg(&cmd, blob_str(&temp1), 1);
596634
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -500,14 +500,34 @@
500 return;
501 }
502 blob_reset(&file2);
503 }
504
 
 
505 /* Construct a temporary file to hold pFile1 based on the name of
506 ** zFile2 */
507 file_tempname(&nameFile1, zFile2, "orig");
508 blob_write_to_file(pFile1, blob_str(&nameFile1));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509
510 /* Construct the external diff command */
511 blob_zero(&cmd);
512 blob_append(&cmd, pCfg->zDiffCmd, -1);
513 if( pCfg->diffFlags & DIFF_INVERT ){
@@ -581,15 +601,33 @@
581 }
582 glob_free(pBinary);
583 }
584 }
585
 
 
586 /* Construct a temporary file names */
587 file_tempname(&temp1, zName, "before");
588 file_tempname(&temp2, zName, "after");
589 blob_write_to_file(pFile1, blob_str(&temp1));
590 blob_write_to_file(pFile2, blob_str(&temp2));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
591
592 /* Construct the external diff command */
593 blob_zero(&cmd);
594 blob_append(&cmd, pCfg->zDiffCmd, -1);
595 blob_append_escaped_arg(&cmd, blob_str(&temp1), 1);
596
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -500,14 +500,34 @@
500 return;
501 }
502 blob_reset(&file2);
503 }
504
505 #if defined(_WIN32)
506 /* TODO: How would a (common?) diff program on Windows react to NUL? */
507 /* Construct a temporary file to hold pFile1 based on the name of
508 ** zFile2 */
509 file_tempname(&nameFile1, zFile2, "orig");
510 blob_write_to_file(pFile1, blob_str(&nameFile1));
511 #else
512 if( pCfg->diffFlags & DIFF_FILE_ADDED ){
513 blob_init(&nameFile1, NULL_DEVICE, -1);
514 }else{
515 if( pCfg->diffFlags & DIFF_FILE_DELETED ){
516 /* Indicate a deleted file as /dev/null on Unix.
517 ** For Windows, depends on how the diff tool handles NUL.
518 */
519 blob_init(&nameFile1, zFile2, -1);
520 zFile2 = NULL_DEVICE;
521 }else{
522 /* Construct a temporary file to hold pFile1 based on the name of
523 ** zFile2 */
524 file_tempname(&nameFile1, zFile2, "orig");
525 }
526 blob_write_to_file(pFile1, blob_str(&nameFile1));
527 }
528 #endif
529
530 /* Construct the external diff command */
531 blob_zero(&cmd);
532 blob_append(&cmd, pCfg->zDiffCmd, -1);
533 if( pCfg->diffFlags & DIFF_INVERT ){
@@ -581,15 +601,33 @@
601 }
602 glob_free(pBinary);
603 }
604 }
605
606 #if defined(_WIN32)
607 /* TODO: How would a (common?) diff program on Windows react to NUL? */
608 /* Construct a temporary file names */
609 file_tempname(&temp1, zName, "before");
610 file_tempname(&temp2, zName, "after");
611 blob_write_to_file(pFile1, blob_str(&temp1));
612 blob_write_to_file(pFile2, blob_str(&temp2));
613 #else
614 if( pCfg->diffFlags & DIFF_FILE_ADDED ){
615 blob_init(&temp1, NULL_DEVICE, -1);
616 blob_init(&temp2, zName, -1);
617 blob_write_to_file(pFile2, blob_str(&temp2));
618 }else if( pCfg->diffFlags & DIFF_FILE_DELETED ){
619 blob_init(&temp1, zName, -1);
620 blob_init(&temp2, NULL_DEVICE, -1);
621 blob_write_to_file(pFile1, blob_str(&temp1));
622 }else{
623 file_tempname(&temp1, zName, "before");
624 file_tempname(&temp2, zName, "after");
625 blob_write_to_file(pFile1, blob_str(&temp1));
626 blob_write_to_file(pFile2, blob_str(&temp2));
627 }
628 #endif
629
630 /* Construct the external diff command */
631 blob_zero(&cmd);
632 blob_append(&cmd, pCfg->zDiffCmd, -1);
633 blob_append_escaped_arg(&cmd, blob_str(&temp1), 1);
634

Keyboard Shortcuts

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