Fossil SCM

The "fossil patch diff" command should now emit an error message if there is a repository mismatch or a base artifact is missing.

drh 2021-06-23 19:55 trunk
Commit 962694ada0de586eded1ef61f6c9c13107595694b29f683d4431bb539625af25
1 file changed +53 -6
+53 -6
--- src/patch.c
+++ src/patch.c
@@ -711,25 +711,72 @@
711711
u64 diffFlags /* Other diff flags */
712712
){
713713
Stmt q;
714714
Blob empty;
715715
blob_zero(&empty);
716
+
717
+ /* Check to ensure that the patch against the repository that we
718
+ ** have opened.
719
+ **
720
+ ** To do: If there is a mismatch, should we scan all of the repositories
721
+ ** listed in the global_config table looking for a match?
722
+ */
723
+ if( db_exists(
724
+ "SELECT 1 FROM patch.cfg"
725
+ " WHERE cfg.key='baseline'"
726
+ " AND NOT EXISTS(SELECT 1 FROM blob WHERE uuid=cfg.value)"
727
+ )){
728
+ char *zBaseline;
729
+ db_prepare(&q,
730
+ "SELECT config.value, cfg.value FROM config, cfg"
731
+ " WHERE config.name='project-name'"
732
+ " AND cfg.key='project-name'"
733
+ " AND config.value<>cfg.value"
734
+ );
735
+ if( db_step(&q)==SQLITE_ROW ){
736
+ char *zRepo = fossil_strdup(db_column_text(&q,0));
737
+ char *zPatch = fossil_strdup(db_column_text(&q,1));
738
+ db_finalize(&q);
739
+ fossil_fatal("the patch is against project \"%z\" but you are using "
740
+ "project \"%z\"", zPatch, zRepo);
741
+ }
742
+ db_finalize(&q);
743
+ zBaseline = db_text(0, "SELECT value FROM patch.cfg"
744
+ " WHERE key='baseline'");
745
+ if( zBaseline ){
746
+ fossil_fatal("the baseline of the patch (check-in %S) is not found "
747
+ "in the %s repository", zBaseline, g.zRepositoryName);
748
+ }
749
+ }
750
+
716751
db_prepare(&q,
717752
"SELECT"
718
- " blob.rid," /* 0: rid of the baseline */
753
+ " (SELECT blob.rid FROM blob WHERE blob.uuid=chng.hash),"
719754
" pathname," /* 1: new pathname */
720755
" origname," /* 2: original pathname. Null if not renamed */
721
- " delta" /* 3: delta. NULL if deleted. empty is no change */
722
- " FROM patch.chng, blob WHERE blob.uuid=patch.chng.hash"
756
+ " delta," /* 3: delta. NULL if deleted. empty is no change */
757
+ " hash" /* 4: baseline hash */
758
+ " FROM patch.chng"
723759
" ORDER BY pathname"
724760
);
725761
while( db_step(&q)==SQLITE_ROW ){
726
- int rid = db_column_int(&q, 0);
727
- /* const char *zOrig = db_column_text(&q, 2); */
728
- const char *zName = db_column_text(&q, 1);
762
+ int rid;
763
+ const char *zName;
729764
int isBin1, isBin2;
730765
Blob a, b;
766
+
767
+ if( db_column_type(&q,0)!=SQLITE_INTEGER
768
+ && db_column_type(&q,4)==SQLITE_TEXT
769
+ ){
770
+ char *zUuid = fossil_strdup(db_column_text(&q,4));
771
+ char *zName = fossil_strdup(db_column_text(&q,1));
772
+ db_finalize(&q);
773
+ fossil_fatal("base artifact %S for file \"%s\" not found", zUuid, zName);
774
+ }
775
+ zName = db_column_text(&q, 1);
776
+ rid = db_column_int(&q, 0);
777
+
731778
if( db_column_type(&q,3)==SQLITE_NULL ){
732779
fossil_print("DELETE %s\n", zName);
733780
diff_print_index(zName, diffFlags, 0);
734781
isBin2 = 0;
735782
content_get(rid, &a);
736783
--- src/patch.c
+++ src/patch.c
@@ -711,25 +711,72 @@
711 u64 diffFlags /* Other diff flags */
712 ){
713 Stmt q;
714 Blob empty;
715 blob_zero(&empty);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
716 db_prepare(&q,
717 "SELECT"
718 " blob.rid," /* 0: rid of the baseline */
719 " pathname," /* 1: new pathname */
720 " origname," /* 2: original pathname. Null if not renamed */
721 " delta" /* 3: delta. NULL if deleted. empty is no change */
722 " FROM patch.chng, blob WHERE blob.uuid=patch.chng.hash"
 
723 " ORDER BY pathname"
724 );
725 while( db_step(&q)==SQLITE_ROW ){
726 int rid = db_column_int(&q, 0);
727 /* const char *zOrig = db_column_text(&q, 2); */
728 const char *zName = db_column_text(&q, 1);
729 int isBin1, isBin2;
730 Blob a, b;
 
 
 
 
 
 
 
 
 
 
 
 
731 if( db_column_type(&q,3)==SQLITE_NULL ){
732 fossil_print("DELETE %s\n", zName);
733 diff_print_index(zName, diffFlags, 0);
734 isBin2 = 0;
735 content_get(rid, &a);
736
--- src/patch.c
+++ src/patch.c
@@ -711,25 +711,72 @@
711 u64 diffFlags /* Other diff flags */
712 ){
713 Stmt q;
714 Blob empty;
715 blob_zero(&empty);
716
717 /* Check to ensure that the patch against the repository that we
718 ** have opened.
719 **
720 ** To do: If there is a mismatch, should we scan all of the repositories
721 ** listed in the global_config table looking for a match?
722 */
723 if( db_exists(
724 "SELECT 1 FROM patch.cfg"
725 " WHERE cfg.key='baseline'"
726 " AND NOT EXISTS(SELECT 1 FROM blob WHERE uuid=cfg.value)"
727 )){
728 char *zBaseline;
729 db_prepare(&q,
730 "SELECT config.value, cfg.value FROM config, cfg"
731 " WHERE config.name='project-name'"
732 " AND cfg.key='project-name'"
733 " AND config.value<>cfg.value"
734 );
735 if( db_step(&q)==SQLITE_ROW ){
736 char *zRepo = fossil_strdup(db_column_text(&q,0));
737 char *zPatch = fossil_strdup(db_column_text(&q,1));
738 db_finalize(&q);
739 fossil_fatal("the patch is against project \"%z\" but you are using "
740 "project \"%z\"", zPatch, zRepo);
741 }
742 db_finalize(&q);
743 zBaseline = db_text(0, "SELECT value FROM patch.cfg"
744 " WHERE key='baseline'");
745 if( zBaseline ){
746 fossil_fatal("the baseline of the patch (check-in %S) is not found "
747 "in the %s repository", zBaseline, g.zRepositoryName);
748 }
749 }
750
751 db_prepare(&q,
752 "SELECT"
753 " (SELECT blob.rid FROM blob WHERE blob.uuid=chng.hash),"
754 " pathname," /* 1: new pathname */
755 " origname," /* 2: original pathname. Null if not renamed */
756 " delta," /* 3: delta. NULL if deleted. empty is no change */
757 " hash" /* 4: baseline hash */
758 " FROM patch.chng"
759 " ORDER BY pathname"
760 );
761 while( db_step(&q)==SQLITE_ROW ){
762 int rid;
763 const char *zName;
 
764 int isBin1, isBin2;
765 Blob a, b;
766
767 if( db_column_type(&q,0)!=SQLITE_INTEGER
768 && db_column_type(&q,4)==SQLITE_TEXT
769 ){
770 char *zUuid = fossil_strdup(db_column_text(&q,4));
771 char *zName = fossil_strdup(db_column_text(&q,1));
772 db_finalize(&q);
773 fossil_fatal("base artifact %S for file \"%s\" not found", zUuid, zName);
774 }
775 zName = db_column_text(&q, 1);
776 rid = db_column_int(&q, 0);
777
778 if( db_column_type(&q,3)==SQLITE_NULL ){
779 fossil_print("DELETE %s\n", zName);
780 diff_print_index(zName, diffFlags, 0);
781 isBin2 = 0;
782 content_get(rid, &a);
783

Keyboard Shortcuts

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