Fossil SCM

Consistently use /dev/null in diff output for added and deleted files.

preben 2023-10-05 11:57 trunk
Commit 200dcdcd37f97c6099490c934f98e805a9d21d35b6bbdfb5e63f0baab9a9d58c
+6
--- src/diff.c
+++ src/diff.c
@@ -48,10 +48,16 @@
4848
#define DIFF_DEBUG 0x00020000 /* Debugging diff output */
4949
#define DIFF_RAW 0x00040000 /* Raw triples - for debugging */
5050
#define DIFF_TCL 0x00080000 /* For the --tk option */
5151
#define DIFF_INCBINARY 0x00100000 /* The --diff-binary option */
5252
#define DIFF_SHOW_VERS 0x00200000 /* Show compared versions */
53
+/*
54
+** Per file information that may influence output.
55
+*/
56
+#define DIFF_FILE_ADDED 0x40000000 /* Added or rename destination */
57
+#define DIFF_FILE_DELETED 0x80000000 /* Deleted or rename source */
58
+#define DIFF_FILE_MASK 0xc0000000 /* Used for clearing file flags */
5359
5460
/*
5561
** These error messages are shared in multiple locations. They are defined
5662
** here for consistency.
5763
*/
5864
--- src/diff.c
+++ src/diff.c
@@ -48,10 +48,16 @@
48 #define DIFF_DEBUG 0x00020000 /* Debugging diff output */
49 #define DIFF_RAW 0x00040000 /* Raw triples - for debugging */
50 #define DIFF_TCL 0x00080000 /* For the --tk option */
51 #define DIFF_INCBINARY 0x00100000 /* The --diff-binary option */
52 #define DIFF_SHOW_VERS 0x00200000 /* Show compared versions */
 
 
 
 
 
 
53
54 /*
55 ** These error messages are shared in multiple locations. They are defined
56 ** here for consistency.
57 */
58
--- src/diff.c
+++ src/diff.c
@@ -48,10 +48,16 @@
48 #define DIFF_DEBUG 0x00020000 /* Debugging diff output */
49 #define DIFF_RAW 0x00040000 /* Raw triples - for debugging */
50 #define DIFF_TCL 0x00080000 /* For the --tk option */
51 #define DIFF_INCBINARY 0x00100000 /* The --diff-binary option */
52 #define DIFF_SHOW_VERS 0x00200000 /* Show compared versions */
53 /*
54 ** Per file information that may influence output.
55 */
56 #define DIFF_FILE_ADDED 0x40000000 /* Added or rename destination */
57 #define DIFF_FILE_DELETED 0x80000000 /* Deleted or rename source */
58 #define DIFF_FILE_MASK 0xc0000000 /* Used for clearing file flags */
59
60 /*
61 ** These error messages are shared in multiple locations. They are defined
62 ** here for consistency.
63 */
64
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -161,10 +161,13 @@
161161
const char *zRight, /* Name of the right file */
162162
DiffConfig *pCfg, /* Diff configuration */
163163
Blob *pOut /* Write to this blob, or stdout of this is NULL */
164164
){
165165
u64 diffFlags = pCfg->diffFlags;
166
+ /* Standardize on /dev/null, regardless of platform. */
167
+ if( pCfg->diffFlags & DIFF_FILE_ADDED ) zLeft = "/dev/null";
168
+ if( pCfg->diffFlags & DIFF_FILE_DELETED ) zRight = "/dev/null";
166169
if( diffFlags & (DIFF_BRIEF|DIFF_RAW) ){
167170
/* no-op */
168171
}else if( diffFlags & DIFF_DEBUG ){
169172
blob_appendf(pOut, "FILE-LEFT %s\nFILE-RIGHT %s\n", zLeft, zRight);
170173
}else if( diffFlags & DIFF_WEBPAGE ){
@@ -714,26 +717,31 @@
714717
}else{
715718
blob_set(&fname, g.zLocalRoot);
716719
blob_append(&fname, zPathname, -1);
717720
}
718721
zFullName = blob_str(&fname);
722
+ pCfg->diffFlags &= (~DIFF_FILE_MASK);
719723
if( isDeleted ){
720724
if( !isNumStat ){ fossil_print("DELETED %s\n", zPathname); }
725
+ pCfg->diffFlags |= DIFF_FILE_DELETED;
721726
if( !asNewFile ){ showDiff = 0; zFullName = NULL_DEVICE; }
722727
}else if( file_access(zFullName, F_OK) ){
723728
if( !isNumStat ){ fossil_print("MISSING %s\n", zPathname); }
724729
if( !asNewFile ){ showDiff = 0; }
725730
}else if( isNew ){
726731
if( !isNumStat ){ fossil_print("ADDED %s\n", zPathname); }
732
+ pCfg->diffFlags |= DIFF_FILE_ADDED;
727733
srcid = 0;
728734
if( !asNewFile ){ showDiff = 0; }
729735
}else if( isChnged==3 ){
730736
if( !isNumStat ){ fossil_print("ADDED_BY_MERGE %s\n", zPathname); }
737
+ pCfg->diffFlags |= DIFF_FILE_ADDED;
731738
srcid = 0;
732739
if( !asNewFile ){ showDiff = 0; }
733740
}else if( isChnged==5 ){
734741
if( !isNumStat ){ fossil_print("ADDED_BY_INTEGRATE %s\n", zPathname); }
742
+ pCfg->diffFlags |= DIFF_FILE_ADDED;
735743
srcid = 0;
736744
if( !asNewFile ){ showDiff = 0; }
737745
}
738746
if( showDiff ){
739747
Blob content;
@@ -875,15 +883,17 @@
875883
}else if( pToFile==0 ){
876884
cmp = -1;
877885
}else{
878886
cmp = fossil_strcmp(pFromFile->zName, pToFile->zName);
879887
}
888
+ pCfg->diffFlags &= (~DIFF_FILE_MASK);
880889
if( cmp<0 ){
881890
if( file_dir_match(pFileDir, pFromFile->zName) ){
882891
if( (pCfg->diffFlags & (DIFF_NUMSTAT|DIFF_HTML))==0 ){
883892
fossil_print("DELETED %s\n", pFromFile->zName);
884893
}
894
+ pCfg->diffFlags |= DIFF_FILE_DELETED;
885895
if( asNewFlag ){
886896
diff_manifest_entry(pFromFile, 0, pCfg);
887897
}
888898
}
889899
pFromFile = manifest_file_next(pFrom,0);
@@ -891,10 +901,11 @@
891901
if( file_dir_match(pFileDir, pToFile->zName) ){
892902
if( (pCfg->diffFlags &
893903
(DIFF_NUMSTAT|DIFF_HTML|DIFF_TCL|DIFF_JSON))==0 ){
894904
fossil_print("ADDED %s\n", pToFile->zName);
895905
}
906
+ pCfg->diffFlags |= DIFF_FILE_ADDED;
896907
if( asNewFlag ){
897908
diff_manifest_entry(0, pToFile, pCfg);
898909
}
899910
}
900911
pToFile = manifest_file_next(pTo,0);
901912
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -161,10 +161,13 @@
161 const char *zRight, /* Name of the right file */
162 DiffConfig *pCfg, /* Diff configuration */
163 Blob *pOut /* Write to this blob, or stdout of this is NULL */
164 ){
165 u64 diffFlags = pCfg->diffFlags;
 
 
 
166 if( diffFlags & (DIFF_BRIEF|DIFF_RAW) ){
167 /* no-op */
168 }else if( diffFlags & DIFF_DEBUG ){
169 blob_appendf(pOut, "FILE-LEFT %s\nFILE-RIGHT %s\n", zLeft, zRight);
170 }else if( diffFlags & DIFF_WEBPAGE ){
@@ -714,26 +717,31 @@
714 }else{
715 blob_set(&fname, g.zLocalRoot);
716 blob_append(&fname, zPathname, -1);
717 }
718 zFullName = blob_str(&fname);
 
719 if( isDeleted ){
720 if( !isNumStat ){ fossil_print("DELETED %s\n", zPathname); }
 
721 if( !asNewFile ){ showDiff = 0; zFullName = NULL_DEVICE; }
722 }else if( file_access(zFullName, F_OK) ){
723 if( !isNumStat ){ fossil_print("MISSING %s\n", zPathname); }
724 if( !asNewFile ){ showDiff = 0; }
725 }else if( isNew ){
726 if( !isNumStat ){ fossil_print("ADDED %s\n", zPathname); }
 
727 srcid = 0;
728 if( !asNewFile ){ showDiff = 0; }
729 }else if( isChnged==3 ){
730 if( !isNumStat ){ fossil_print("ADDED_BY_MERGE %s\n", zPathname); }
 
731 srcid = 0;
732 if( !asNewFile ){ showDiff = 0; }
733 }else if( isChnged==5 ){
734 if( !isNumStat ){ fossil_print("ADDED_BY_INTEGRATE %s\n", zPathname); }
 
735 srcid = 0;
736 if( !asNewFile ){ showDiff = 0; }
737 }
738 if( showDiff ){
739 Blob content;
@@ -875,15 +883,17 @@
875 }else if( pToFile==0 ){
876 cmp = -1;
877 }else{
878 cmp = fossil_strcmp(pFromFile->zName, pToFile->zName);
879 }
 
880 if( cmp<0 ){
881 if( file_dir_match(pFileDir, pFromFile->zName) ){
882 if( (pCfg->diffFlags & (DIFF_NUMSTAT|DIFF_HTML))==0 ){
883 fossil_print("DELETED %s\n", pFromFile->zName);
884 }
 
885 if( asNewFlag ){
886 diff_manifest_entry(pFromFile, 0, pCfg);
887 }
888 }
889 pFromFile = manifest_file_next(pFrom,0);
@@ -891,10 +901,11 @@
891 if( file_dir_match(pFileDir, pToFile->zName) ){
892 if( (pCfg->diffFlags &
893 (DIFF_NUMSTAT|DIFF_HTML|DIFF_TCL|DIFF_JSON))==0 ){
894 fossil_print("ADDED %s\n", pToFile->zName);
895 }
 
896 if( asNewFlag ){
897 diff_manifest_entry(0, pToFile, pCfg);
898 }
899 }
900 pToFile = manifest_file_next(pTo,0);
901
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -161,10 +161,13 @@
161 const char *zRight, /* Name of the right file */
162 DiffConfig *pCfg, /* Diff configuration */
163 Blob *pOut /* Write to this blob, or stdout of this is NULL */
164 ){
165 u64 diffFlags = pCfg->diffFlags;
166 /* Standardize on /dev/null, regardless of platform. */
167 if( pCfg->diffFlags & DIFF_FILE_ADDED ) zLeft = "/dev/null";
168 if( pCfg->diffFlags & DIFF_FILE_DELETED ) zRight = "/dev/null";
169 if( diffFlags & (DIFF_BRIEF|DIFF_RAW) ){
170 /* no-op */
171 }else if( diffFlags & DIFF_DEBUG ){
172 blob_appendf(pOut, "FILE-LEFT %s\nFILE-RIGHT %s\n", zLeft, zRight);
173 }else if( diffFlags & DIFF_WEBPAGE ){
@@ -714,26 +717,31 @@
717 }else{
718 blob_set(&fname, g.zLocalRoot);
719 blob_append(&fname, zPathname, -1);
720 }
721 zFullName = blob_str(&fname);
722 pCfg->diffFlags &= (~DIFF_FILE_MASK);
723 if( isDeleted ){
724 if( !isNumStat ){ fossil_print("DELETED %s\n", zPathname); }
725 pCfg->diffFlags |= DIFF_FILE_DELETED;
726 if( !asNewFile ){ showDiff = 0; zFullName = NULL_DEVICE; }
727 }else if( file_access(zFullName, F_OK) ){
728 if( !isNumStat ){ fossil_print("MISSING %s\n", zPathname); }
729 if( !asNewFile ){ showDiff = 0; }
730 }else if( isNew ){
731 if( !isNumStat ){ fossil_print("ADDED %s\n", zPathname); }
732 pCfg->diffFlags |= DIFF_FILE_ADDED;
733 srcid = 0;
734 if( !asNewFile ){ showDiff = 0; }
735 }else if( isChnged==3 ){
736 if( !isNumStat ){ fossil_print("ADDED_BY_MERGE %s\n", zPathname); }
737 pCfg->diffFlags |= DIFF_FILE_ADDED;
738 srcid = 0;
739 if( !asNewFile ){ showDiff = 0; }
740 }else if( isChnged==5 ){
741 if( !isNumStat ){ fossil_print("ADDED_BY_INTEGRATE %s\n", zPathname); }
742 pCfg->diffFlags |= DIFF_FILE_ADDED;
743 srcid = 0;
744 if( !asNewFile ){ showDiff = 0; }
745 }
746 if( showDiff ){
747 Blob content;
@@ -875,15 +883,17 @@
883 }else if( pToFile==0 ){
884 cmp = -1;
885 }else{
886 cmp = fossil_strcmp(pFromFile->zName, pToFile->zName);
887 }
888 pCfg->diffFlags &= (~DIFF_FILE_MASK);
889 if( cmp<0 ){
890 if( file_dir_match(pFileDir, pFromFile->zName) ){
891 if( (pCfg->diffFlags & (DIFF_NUMSTAT|DIFF_HTML))==0 ){
892 fossil_print("DELETED %s\n", pFromFile->zName);
893 }
894 pCfg->diffFlags |= DIFF_FILE_DELETED;
895 if( asNewFlag ){
896 diff_manifest_entry(pFromFile, 0, pCfg);
897 }
898 }
899 pFromFile = manifest_file_next(pFrom,0);
@@ -891,10 +901,11 @@
901 if( file_dir_match(pFileDir, pToFile->zName) ){
902 if( (pCfg->diffFlags &
903 (DIFF_NUMSTAT|DIFF_HTML|DIFF_TCL|DIFF_JSON))==0 ){
904 fossil_print("ADDED %s\n", pToFile->zName);
905 }
906 pCfg->diffFlags |= DIFF_FILE_ADDED;
907 if( asNewFlag ){
908 diff_manifest_entry(0, pToFile, pCfg);
909 }
910 }
911 pToFile = manifest_file_next(pTo,0);
912
--- src/patch.c
+++ src/patch.c
@@ -799,19 +799,22 @@
799799
}
800800
}
801801
zName = db_column_text(&q, 1);
802802
rid = db_column_int(&q, 0);
803803
804
+ pCfg->diffFlags &= (~DIFF_FILE_MASK);
804805
if( db_column_type(&q,3)==SQLITE_NULL ){
805806
if( !bWebpage ) fossil_print("DELETE %s\n", zName);
807
+ pCfg->diffFlags |= DIFF_FILE_DELETED;
806808
diff_print_index(zName, pCfg, 0);
807809
content_get(rid, &a);
808810
diff_file_mem(&a, &empty, zName, pCfg);
809811
}else if( rid==0 ){
810812
db_ephemeral_blob(&q, 3, &a);
811813
blob_uncompress(&a, &a);
812814
if( !bWebpage ) fossil_print("ADDED %s\n", zName);
815
+ pCfg->diffFlags |= DIFF_FILE_ADDED;
813816
diff_print_index(zName, pCfg, 0);
814817
diff_file_mem(&empty, &a, zName, pCfg);
815818
blob_reset(&a);
816819
}else if( db_column_bytes(&q, 3)>0 ){
817820
Blob delta;
818821
--- src/patch.c
+++ src/patch.c
@@ -799,19 +799,22 @@
799 }
800 }
801 zName = db_column_text(&q, 1);
802 rid = db_column_int(&q, 0);
803
 
804 if( db_column_type(&q,3)==SQLITE_NULL ){
805 if( !bWebpage ) fossil_print("DELETE %s\n", zName);
 
806 diff_print_index(zName, pCfg, 0);
807 content_get(rid, &a);
808 diff_file_mem(&a, &empty, zName, pCfg);
809 }else if( rid==0 ){
810 db_ephemeral_blob(&q, 3, &a);
811 blob_uncompress(&a, &a);
812 if( !bWebpage ) fossil_print("ADDED %s\n", zName);
 
813 diff_print_index(zName, pCfg, 0);
814 diff_file_mem(&empty, &a, zName, pCfg);
815 blob_reset(&a);
816 }else if( db_column_bytes(&q, 3)>0 ){
817 Blob delta;
818
--- src/patch.c
+++ src/patch.c
@@ -799,19 +799,22 @@
799 }
800 }
801 zName = db_column_text(&q, 1);
802 rid = db_column_int(&q, 0);
803
804 pCfg->diffFlags &= (~DIFF_FILE_MASK);
805 if( db_column_type(&q,3)==SQLITE_NULL ){
806 if( !bWebpage ) fossil_print("DELETE %s\n", zName);
807 pCfg->diffFlags |= DIFF_FILE_DELETED;
808 diff_print_index(zName, pCfg, 0);
809 content_get(rid, &a);
810 diff_file_mem(&a, &empty, zName, pCfg);
811 }else if( rid==0 ){
812 db_ephemeral_blob(&q, 3, &a);
813 blob_uncompress(&a, &a);
814 if( !bWebpage ) fossil_print("ADDED %s\n", zName);
815 pCfg->diffFlags |= DIFF_FILE_ADDED;
816 diff_print_index(zName, pCfg, 0);
817 diff_file_mem(&empty, &a, zName, pCfg);
818 blob_reset(&a);
819 }else if( db_column_bytes(&q, 3)>0 ){
820 Blob delta;
821
--- src/stash.c
+++ src/stash.c
@@ -427,17 +427,20 @@
427427
int isLink = db_column_int(&q, 3);
428428
const char *zOrig = db_column_text(&q, 4);
429429
const char *zNew = db_column_text(&q, 5);
430430
char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
431431
Blob a, b;
432
+ pCfg->diffFlags &= (~DIFF_FILE_MASK);
432433
if( rid==0 ){
433434
db_ephemeral_blob(&q, 6, &a);
434435
if( !bWebpage ) fossil_print("ADDED %s\n", zNew);
436
+ pCfg->diffFlags |= DIFF_FILE_ADDED;
435437
diff_print_index(zNew, pCfg, 0);
436438
diff_file_mem(&empty, &a, zNew, pCfg);
437439
}else if( isRemoved ){
438440
if( !bWebpage) fossil_print("DELETE %s\n", zOrig);
441
+ pCfg->diffFlags |= DIFF_FILE_DELETED;
439442
diff_print_index(zNew, pCfg, 0);
440443
if( fBaseline ){
441444
content_get(rid, &a);
442445
diff_file_mem(&a, &empty, zOrig, pCfg);
443446
}
444447
--- src/stash.c
+++ src/stash.c
@@ -427,17 +427,20 @@
427 int isLink = db_column_int(&q, 3);
428 const char *zOrig = db_column_text(&q, 4);
429 const char *zNew = db_column_text(&q, 5);
430 char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
431 Blob a, b;
 
432 if( rid==0 ){
433 db_ephemeral_blob(&q, 6, &a);
434 if( !bWebpage ) fossil_print("ADDED %s\n", zNew);
 
435 diff_print_index(zNew, pCfg, 0);
436 diff_file_mem(&empty, &a, zNew, pCfg);
437 }else if( isRemoved ){
438 if( !bWebpage) fossil_print("DELETE %s\n", zOrig);
 
439 diff_print_index(zNew, pCfg, 0);
440 if( fBaseline ){
441 content_get(rid, &a);
442 diff_file_mem(&a, &empty, zOrig, pCfg);
443 }
444
--- src/stash.c
+++ src/stash.c
@@ -427,17 +427,20 @@
427 int isLink = db_column_int(&q, 3);
428 const char *zOrig = db_column_text(&q, 4);
429 const char *zNew = db_column_text(&q, 5);
430 char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
431 Blob a, b;
432 pCfg->diffFlags &= (~DIFF_FILE_MASK);
433 if( rid==0 ){
434 db_ephemeral_blob(&q, 6, &a);
435 if( !bWebpage ) fossil_print("ADDED %s\n", zNew);
436 pCfg->diffFlags |= DIFF_FILE_ADDED;
437 diff_print_index(zNew, pCfg, 0);
438 diff_file_mem(&empty, &a, zNew, pCfg);
439 }else if( isRemoved ){
440 if( !bWebpage) fossil_print("DELETE %s\n", zOrig);
441 pCfg->diffFlags |= DIFF_FILE_DELETED;
442 diff_print_index(zNew, pCfg, 0);
443 if( fBaseline ){
444 content_get(rid, &a);
445 diff_file_mem(&a, &empty, zOrig, pCfg);
446 }
447

Keyboard Shortcuts

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