Fossil SCM

Add the "fossil synclog" command to display syncing history.

drh 2021-12-20 12:32 synclog
Commit dc861e5f2b9edb295c94e2ade318f45ee213623d68a5fc3964b81a641dc2c932
1 file changed +83
+83
--- src/sync.c
+++ src/sync.c
@@ -743,5 +743,88 @@
743743
db_multi_exec("VACUUM repository INTO %Q", zDest);
744744
zFullName = file_canonical_name_dup(zDest);
745745
sync_log_entry("this", zFullName, 0, "backup");
746746
fossil_free(zFullName);
747747
}
748
+
749
+/*
750
+** COMMAND: synclog
751
+**
752
+** Usage: %fossil synclog
753
+**
754
+** Show other repositories with which this repository has pushed or pulled,
755
+** together with the time since the most recent push or pull.
756
+*/
757
+void synclog_cmd(void){
758
+ Stmt q;
759
+ int cnt;
760
+ const int nIndent = 3;
761
+ db_find_and_open_repository(0,0);
762
+ db_prepare(&q,
763
+ "WITH allpull(xfrom,xto,xtime) AS MATERIALIZED (\n"
764
+ " SELECT sfrom, sto, max(stime) FROM synclog GROUP BY 1\n"
765
+ "),\n"
766
+ "pull(level, url, mtime, ex) AS (\n"
767
+ " SELECT 0, xfrom, xtime, '|this|' || xfrom || '|'\n"
768
+ " FROM allpull WHERE xto='this'\n"
769
+ " UNION\n"
770
+ " SELECT level+1, xfrom, xtime, ex || xfrom || '|'\n"
771
+ " FROM pull, allpull\n"
772
+ " WHERE xto=url\n"
773
+ " AND ex NOT GLOB ('*|' || xfrom || '|*')\n"
774
+ " ORDER BY 1 DESC, 3 DESC\n"
775
+ ")\n"
776
+ "SELECT level, url, julianday() - julianday(mtime,'auto') FROM pull"
777
+ );
778
+ cnt = 0;
779
+ fossil_print("PULL:\n");
780
+ while( db_step(&q)==SQLITE_ROW ){
781
+ int iLevel = (db_column_int(&q,0)+1)*nIndent;
782
+ const char *zUrl = db_column_text(&q,1);
783
+ double rTimeAgo = db_column_double(&q,2);
784
+ if( rTimeAgo*86400.0<=2.0 ){
785
+ fossil_print("%.*c%s (current)\n", iLevel, ' ', zUrl);
786
+ }else{
787
+ char *zAgo = human_readable_age(rTimeAgo);
788
+ fossil_print("%.*c%s (%z ago)\n", iLevel, ' ', zUrl, zAgo);
789
+ }
790
+ cnt++;
791
+ }
792
+ db_finalize(&q);
793
+ if( cnt==0 ){
794
+ fossil_print(" (none)\n");
795
+ }
796
+ db_prepare(&q,
797
+ "WITH allpush(xfrom,xto,xtime) AS MATERIALIZED (\n"
798
+ " SELECT sfrom, sto, max(stime) FROM synclog GROUP BY 2\n"
799
+ "),\n"
800
+ "push(level, url, mtime, ex) AS (\n"
801
+ " SELECT 0, xto, xtime, '|this|' || xto || '|'\n"
802
+ " FROM allpush WHERE xfrom='this'\n"
803
+ " UNION\n"
804
+ " SELECT level+1, xto, xtime, ex || xto || '|'\n"
805
+ " FROM push, allpush\n"
806
+ " WHERE xfrom=url\n"
807
+ " AND ex NOT GLOB ('*|' || xto || '|*')\n"
808
+ " ORDER BY 1 DESC, 3 DESC\n"
809
+ ")\n"
810
+ "SELECT level, url, julianday() - julianday(mtime,'auto') FROM push"
811
+ );
812
+ cnt = 0;
813
+ fossil_print("PUSH:\n");
814
+ while( db_step(&q)==SQLITE_ROW ){
815
+ int iLevel = (db_column_int(&q,0)+1)*nIndent;
816
+ const char *zUrl = db_column_text(&q,1);
817
+ double rTimeAgo = db_column_double(&q,2);
818
+ if( rTimeAgo*86400.0<=2.0 ){
819
+ fossil_print("%.*c%s (current)\n", iLevel, ' ', zUrl);
820
+ }else{
821
+ char *zAgo = human_readable_age(rTimeAgo);
822
+ fossil_print("%.*c%s (%z ago)\n", iLevel, ' ', zUrl, zAgo);
823
+ }
824
+ cnt++;
825
+ }
826
+ db_finalize(&q);
827
+ if( cnt==0 ){
828
+ fossil_print(" (none)\n");
829
+ }
830
+}
748831
--- src/sync.c
+++ src/sync.c
@@ -743,5 +743,88 @@
743 db_multi_exec("VACUUM repository INTO %Q", zDest);
744 zFullName = file_canonical_name_dup(zDest);
745 sync_log_entry("this", zFullName, 0, "backup");
746 fossil_free(zFullName);
747 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
748
--- src/sync.c
+++ src/sync.c
@@ -743,5 +743,88 @@
743 db_multi_exec("VACUUM repository INTO %Q", zDest);
744 zFullName = file_canonical_name_dup(zDest);
745 sync_log_entry("this", zFullName, 0, "backup");
746 fossil_free(zFullName);
747 }
748
749 /*
750 ** COMMAND: synclog
751 **
752 ** Usage: %fossil synclog
753 **
754 ** Show other repositories with which this repository has pushed or pulled,
755 ** together with the time since the most recent push or pull.
756 */
757 void synclog_cmd(void){
758 Stmt q;
759 int cnt;
760 const int nIndent = 3;
761 db_find_and_open_repository(0,0);
762 db_prepare(&q,
763 "WITH allpull(xfrom,xto,xtime) AS MATERIALIZED (\n"
764 " SELECT sfrom, sto, max(stime) FROM synclog GROUP BY 1\n"
765 "),\n"
766 "pull(level, url, mtime, ex) AS (\n"
767 " SELECT 0, xfrom, xtime, '|this|' || xfrom || '|'\n"
768 " FROM allpull WHERE xto='this'\n"
769 " UNION\n"
770 " SELECT level+1, xfrom, xtime, ex || xfrom || '|'\n"
771 " FROM pull, allpull\n"
772 " WHERE xto=url\n"
773 " AND ex NOT GLOB ('*|' || xfrom || '|*')\n"
774 " ORDER BY 1 DESC, 3 DESC\n"
775 ")\n"
776 "SELECT level, url, julianday() - julianday(mtime,'auto') FROM pull"
777 );
778 cnt = 0;
779 fossil_print("PULL:\n");
780 while( db_step(&q)==SQLITE_ROW ){
781 int iLevel = (db_column_int(&q,0)+1)*nIndent;
782 const char *zUrl = db_column_text(&q,1);
783 double rTimeAgo = db_column_double(&q,2);
784 if( rTimeAgo*86400.0<=2.0 ){
785 fossil_print("%.*c%s (current)\n", iLevel, ' ', zUrl);
786 }else{
787 char *zAgo = human_readable_age(rTimeAgo);
788 fossil_print("%.*c%s (%z ago)\n", iLevel, ' ', zUrl, zAgo);
789 }
790 cnt++;
791 }
792 db_finalize(&q);
793 if( cnt==0 ){
794 fossil_print(" (none)\n");
795 }
796 db_prepare(&q,
797 "WITH allpush(xfrom,xto,xtime) AS MATERIALIZED (\n"
798 " SELECT sfrom, sto, max(stime) FROM synclog GROUP BY 2\n"
799 "),\n"
800 "push(level, url, mtime, ex) AS (\n"
801 " SELECT 0, xto, xtime, '|this|' || xto || '|'\n"
802 " FROM allpush WHERE xfrom='this'\n"
803 " UNION\n"
804 " SELECT level+1, xto, xtime, ex || xto || '|'\n"
805 " FROM push, allpush\n"
806 " WHERE xfrom=url\n"
807 " AND ex NOT GLOB ('*|' || xto || '|*')\n"
808 " ORDER BY 1 DESC, 3 DESC\n"
809 ")\n"
810 "SELECT level, url, julianday() - julianday(mtime,'auto') FROM push"
811 );
812 cnt = 0;
813 fossil_print("PUSH:\n");
814 while( db_step(&q)==SQLITE_ROW ){
815 int iLevel = (db_column_int(&q,0)+1)*nIndent;
816 const char *zUrl = db_column_text(&q,1);
817 double rTimeAgo = db_column_double(&q,2);
818 if( rTimeAgo*86400.0<=2.0 ){
819 fossil_print("%.*c%s (current)\n", iLevel, ' ', zUrl);
820 }else{
821 char *zAgo = human_readable_age(rTimeAgo);
822 fossil_print("%.*c%s (%z ago)\n", iLevel, ' ', zUrl, zAgo);
823 }
824 cnt++;
825 }
826 db_finalize(&q);
827 if( cnt==0 ){
828 fossil_print(" (none)\n");
829 }
830 }
831

Keyboard Shortcuts

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