Fossil SCM

Add the -h option to the "ls" command to display file hashes for a specific check-in when in verbose mode.

danield 2025-09-26 11:58 trunk
Commit 4c0ff6ed62b1e3696eaf6d43b071314757ffbbba86f9fa71a4c755d1b3aabc5f
2 files changed +5 -3 +11 -5
+5 -3
--- src/browse.c
+++ src/browse.c
@@ -1038,11 +1038,12 @@
10381038
@ CREATE TABLE IF NOT EXISTS temp.fileage(
10391039
@ fnid INTEGER PRIMARY KEY,
10401040
@ fid INTEGER,
10411041
@ mid INTEGER,
10421042
@ mtime DATETIME,
1043
-@ pathname TEXT
1043
+@ pathname TEXT,
1044
+@ uuid TEXT
10441045
@ );
10451046
@ CREATE VIRTUAL TABLE IF NOT EXISTS temp.foci USING files_of_checkin;
10461047
;
10471048
10481049
static const char zComputeFileAgeRun[] =
@@ -1050,12 +1051,13 @@
10501051
@ ckin(x) AS (VALUES(:ckin)
10511052
@ UNION
10521053
@ SELECT plink.pid
10531054
@ FROM ckin, plink
10541055
@ WHERE plink.cid=ckin.x)
1055
-@ INSERT OR IGNORE INTO fileage(fnid, fid, mid, mtime, pathname)
1056
-@ SELECT filename.fnid, mlink.fid, mlink.mid, event.mtime, filename.name
1056
+@ INSERT OR IGNORE INTO fileage(fnid, fid, mid, mtime, pathname, uuid)
1057
+@ SELECT filename.fnid, mlink.fid, mlink.mid, event.mtime, filename.name,
1058
+@ foci.uuid
10571059
@ FROM foci, filename, blob, mlink, event
10581060
@ WHERE foci.checkinID=:ckin
10591061
@ AND foci.filename GLOB :glob
10601062
@ AND filename.name=foci.filename
10611063
@ AND blob.uuid=foci.uuid
10621064
--- src/browse.c
+++ src/browse.c
@@ -1038,11 +1038,12 @@
1038 @ CREATE TABLE IF NOT EXISTS temp.fileage(
1039 @ fnid INTEGER PRIMARY KEY,
1040 @ fid INTEGER,
1041 @ mid INTEGER,
1042 @ mtime DATETIME,
1043 @ pathname TEXT
 
1044 @ );
1045 @ CREATE VIRTUAL TABLE IF NOT EXISTS temp.foci USING files_of_checkin;
1046 ;
1047
1048 static const char zComputeFileAgeRun[] =
@@ -1050,12 +1051,13 @@
1050 @ ckin(x) AS (VALUES(:ckin)
1051 @ UNION
1052 @ SELECT plink.pid
1053 @ FROM ckin, plink
1054 @ WHERE plink.cid=ckin.x)
1055 @ INSERT OR IGNORE INTO fileage(fnid, fid, mid, mtime, pathname)
1056 @ SELECT filename.fnid, mlink.fid, mlink.mid, event.mtime, filename.name
 
1057 @ FROM foci, filename, blob, mlink, event
1058 @ WHERE foci.checkinID=:ckin
1059 @ AND foci.filename GLOB :glob
1060 @ AND filename.name=foci.filename
1061 @ AND blob.uuid=foci.uuid
1062
--- src/browse.c
+++ src/browse.c
@@ -1038,11 +1038,12 @@
1038 @ CREATE TABLE IF NOT EXISTS temp.fileage(
1039 @ fnid INTEGER PRIMARY KEY,
1040 @ fid INTEGER,
1041 @ mid INTEGER,
1042 @ mtime DATETIME,
1043 @ pathname TEXT,
1044 @ uuid TEXT
1045 @ );
1046 @ CREATE VIRTUAL TABLE IF NOT EXISTS temp.foci USING files_of_checkin;
1047 ;
1048
1049 static const char zComputeFileAgeRun[] =
@@ -1050,12 +1051,13 @@
1051 @ ckin(x) AS (VALUES(:ckin)
1052 @ UNION
1053 @ SELECT plink.pid
1054 @ FROM ckin, plink
1055 @ WHERE plink.cid=ckin.x)
1056 @ INSERT OR IGNORE INTO fileage(fnid, fid, mid, mtime, pathname, uuid)
1057 @ SELECT filename.fnid, mlink.fid, mlink.mid, event.mtime, filename.name,
1058 @ foci.uuid
1059 @ FROM foci, filename, blob, mlink, event
1060 @ WHERE foci.checkinID=:ckin
1061 @ AND foci.filename GLOB :glob
1062 @ AND filename.name=foci.filename
1063 @ AND blob.uuid=foci.uuid
1064
+11 -5
--- src/checkin.c
+++ src/checkin.c
@@ -718,10 +718,11 @@
718718
*/
719719
static void ls_cmd_rev(
720720
const char *zRev, /* Revision string given */
721721
int verboseFlag, /* Verbose flag given */
722722
int showAge, /* Age flag given */
723
+ int showHash, /* Show hash flag given */
723724
int timeOrder, /* Order by time flag given */
724725
int treeFmt /* Show output in the tree format */
725726
){
726727
Stmt q;
727728
char *zOrderBy = "pathname COLLATE nocase";
@@ -763,11 +764,11 @@
763764
}
764765
765766
compute_fileage(rid,0);
766767
db_prepare(&q,
767768
"SELECT datetime(fileage.mtime, toLocal()), fileage.pathname,\n"
768
- " blob.size\n"
769
+ " blob.size, fileage.uuid\n"
769770
" FROM fileage, blob\n"
770771
" WHERE blob.rid=fileage.fid %s\n"
771772
" ORDER BY %s;", blob_sql_text(&where), zOrderBy /*safe-for-%s*/
772773
);
773774
blob_reset(&where);
@@ -778,11 +779,12 @@
778779
const char *zFile = db_column_text(&q,1);
779780
int size = db_column_int(&q,2);
780781
if( treeFmt ){
781782
blob_appendf(&out, "%s\n", zFile);
782783
}else if( verboseFlag ){
783
- fossil_print("%s %7d %s\n", zTime, size, zFile);
784
+ const char *zUuid = mprintf("[%S] ", db_column_text(&q,3));
785
+ fossil_print("%s %7d %s%s\n", zTime, size, showHash ? zUuid :"", zFile);
784786
}else if( showAge ){
785787
fossil_print("%s %s\n", zTime, zFile);
786788
}else{
787789
fossil_print("%s\n", zFile);
788790
}
@@ -811,18 +813,20 @@
811813
** The --age option displays file commit times. Like -r, --age has the
812814
** side effect of making -t sort by commit time, not modification time.
813815
**
814816
** The -v option provides extra information about each file. Without -r,
815817
** -v displays the change status, in the manner of the changes command.
816
-** With -r, -v shows the commit time and size of the checked-in files.
818
+** With -r, -v shows the commit time and size of the checked-in files; in
819
+** this combination, it additionally shows file hashes with -h.
817820
**
818821
** The -t option changes the sort order. Without -t, files are sorted by
819822
** path and name (case insensitive sort if -r). If neither --age nor -r
820823
** are used, -t sorts by modification time, otherwise by commit time.
821824
**
822825
** Options:
823826
** --age Show when each file was committed
827
+** -h With -v and -r, show file hashes
824828
** --hash With -v, verify file status using hashing
825829
** rather than relying on file sizes and mtimes
826830
** -r VERSION The specific check-in to list
827831
** -R|--repository REPO Extract info from repository REPO
828832
** -t Sort output in time order
@@ -840,10 +844,11 @@
840844
int timeOrder;
841845
char *zOrderBy = "pathname";
842846
Blob where;
843847
int i;
844848
int useHash = 0;
849
+ int showHash = 0;
845850
const char *zName;
846851
const char *zRev;
847852
848853
verboseFlag = find_option("verbose","v", 0)!=0;
849854
if( !verboseFlag ){
@@ -852,20 +857,21 @@
852857
showAge = find_option("age",0,0)!=0;
853858
zRev = find_option("r","r",1);
854859
timeOrder = find_option("t","t",0)!=0;
855860
if( verboseFlag ){
856861
useHash = find_option("hash",0,0)!=0;
862
+ showHash = find_option("h","h",0)!=0;
857863
}
858864
treeFmt = find_option("tree",0,0)!=0;
859865
if( treeFmt ){
860866
if( zRev==0 ) zRev = "current";
861867
}
862868
863869
if( zRev!=0 ){
864870
db_find_and_open_repository(0, 0);
865871
verify_all_options();
866
- ls_cmd_rev(zRev,verboseFlag,showAge,timeOrder,treeFmt);
872
+ ls_cmd_rev(zRev,verboseFlag,showAge,showHash,timeOrder,treeFmt);
867873
return;
868874
}else if( find_option("R",0,1)!=0 ){
869875
fossil_fatal("the -r is required in addition to -R");
870876
}
871877
@@ -984,11 +990,11 @@
984990
985991
zRev = find_option("r","r",1);
986992
if( zRev==0 ) zRev = "current";
987993
db_find_and_open_repository(0, 0);
988994
verify_all_options();
989
- ls_cmd_rev(zRev,0,0,0,1);
995
+ ls_cmd_rev(zRev,0,0,0,0,1);
990996
}
991997
992998
/*
993999
** COMMAND: extras
9941000
**
9951001
--- src/checkin.c
+++ src/checkin.c
@@ -718,10 +718,11 @@
718 */
719 static void ls_cmd_rev(
720 const char *zRev, /* Revision string given */
721 int verboseFlag, /* Verbose flag given */
722 int showAge, /* Age flag given */
 
723 int timeOrder, /* Order by time flag given */
724 int treeFmt /* Show output in the tree format */
725 ){
726 Stmt q;
727 char *zOrderBy = "pathname COLLATE nocase";
@@ -763,11 +764,11 @@
763 }
764
765 compute_fileage(rid,0);
766 db_prepare(&q,
767 "SELECT datetime(fileage.mtime, toLocal()), fileage.pathname,\n"
768 " blob.size\n"
769 " FROM fileage, blob\n"
770 " WHERE blob.rid=fileage.fid %s\n"
771 " ORDER BY %s;", blob_sql_text(&where), zOrderBy /*safe-for-%s*/
772 );
773 blob_reset(&where);
@@ -778,11 +779,12 @@
778 const char *zFile = db_column_text(&q,1);
779 int size = db_column_int(&q,2);
780 if( treeFmt ){
781 blob_appendf(&out, "%s\n", zFile);
782 }else if( verboseFlag ){
783 fossil_print("%s %7d %s\n", zTime, size, zFile);
 
784 }else if( showAge ){
785 fossil_print("%s %s\n", zTime, zFile);
786 }else{
787 fossil_print("%s\n", zFile);
788 }
@@ -811,18 +813,20 @@
811 ** The --age option displays file commit times. Like -r, --age has the
812 ** side effect of making -t sort by commit time, not modification time.
813 **
814 ** The -v option provides extra information about each file. Without -r,
815 ** -v displays the change status, in the manner of the changes command.
816 ** With -r, -v shows the commit time and size of the checked-in files.
 
817 **
818 ** The -t option changes the sort order. Without -t, files are sorted by
819 ** path and name (case insensitive sort if -r). If neither --age nor -r
820 ** are used, -t sorts by modification time, otherwise by commit time.
821 **
822 ** Options:
823 ** --age Show when each file was committed
 
824 ** --hash With -v, verify file status using hashing
825 ** rather than relying on file sizes and mtimes
826 ** -r VERSION The specific check-in to list
827 ** -R|--repository REPO Extract info from repository REPO
828 ** -t Sort output in time order
@@ -840,10 +844,11 @@
840 int timeOrder;
841 char *zOrderBy = "pathname";
842 Blob where;
843 int i;
844 int useHash = 0;
 
845 const char *zName;
846 const char *zRev;
847
848 verboseFlag = find_option("verbose","v", 0)!=0;
849 if( !verboseFlag ){
@@ -852,20 +857,21 @@
852 showAge = find_option("age",0,0)!=0;
853 zRev = find_option("r","r",1);
854 timeOrder = find_option("t","t",0)!=0;
855 if( verboseFlag ){
856 useHash = find_option("hash",0,0)!=0;
 
857 }
858 treeFmt = find_option("tree",0,0)!=0;
859 if( treeFmt ){
860 if( zRev==0 ) zRev = "current";
861 }
862
863 if( zRev!=0 ){
864 db_find_and_open_repository(0, 0);
865 verify_all_options();
866 ls_cmd_rev(zRev,verboseFlag,showAge,timeOrder,treeFmt);
867 return;
868 }else if( find_option("R",0,1)!=0 ){
869 fossil_fatal("the -r is required in addition to -R");
870 }
871
@@ -984,11 +990,11 @@
984
985 zRev = find_option("r","r",1);
986 if( zRev==0 ) zRev = "current";
987 db_find_and_open_repository(0, 0);
988 verify_all_options();
989 ls_cmd_rev(zRev,0,0,0,1);
990 }
991
992 /*
993 ** COMMAND: extras
994 **
995
--- src/checkin.c
+++ src/checkin.c
@@ -718,10 +718,11 @@
718 */
719 static void ls_cmd_rev(
720 const char *zRev, /* Revision string given */
721 int verboseFlag, /* Verbose flag given */
722 int showAge, /* Age flag given */
723 int showHash, /* Show hash flag given */
724 int timeOrder, /* Order by time flag given */
725 int treeFmt /* Show output in the tree format */
726 ){
727 Stmt q;
728 char *zOrderBy = "pathname COLLATE nocase";
@@ -763,11 +764,11 @@
764 }
765
766 compute_fileage(rid,0);
767 db_prepare(&q,
768 "SELECT datetime(fileage.mtime, toLocal()), fileage.pathname,\n"
769 " blob.size, fileage.uuid\n"
770 " FROM fileage, blob\n"
771 " WHERE blob.rid=fileage.fid %s\n"
772 " ORDER BY %s;", blob_sql_text(&where), zOrderBy /*safe-for-%s*/
773 );
774 blob_reset(&where);
@@ -778,11 +779,12 @@
779 const char *zFile = db_column_text(&q,1);
780 int size = db_column_int(&q,2);
781 if( treeFmt ){
782 blob_appendf(&out, "%s\n", zFile);
783 }else if( verboseFlag ){
784 const char *zUuid = mprintf("[%S] ", db_column_text(&q,3));
785 fossil_print("%s %7d %s%s\n", zTime, size, showHash ? zUuid :"", zFile);
786 }else if( showAge ){
787 fossil_print("%s %s\n", zTime, zFile);
788 }else{
789 fossil_print("%s\n", zFile);
790 }
@@ -811,18 +813,20 @@
813 ** The --age option displays file commit times. Like -r, --age has the
814 ** side effect of making -t sort by commit time, not modification time.
815 **
816 ** The -v option provides extra information about each file. Without -r,
817 ** -v displays the change status, in the manner of the changes command.
818 ** With -r, -v shows the commit time and size of the checked-in files; in
819 ** this combination, it additionally shows file hashes with -h.
820 **
821 ** The -t option changes the sort order. Without -t, files are sorted by
822 ** path and name (case insensitive sort if -r). If neither --age nor -r
823 ** are used, -t sorts by modification time, otherwise by commit time.
824 **
825 ** Options:
826 ** --age Show when each file was committed
827 ** -h With -v and -r, show file hashes
828 ** --hash With -v, verify file status using hashing
829 ** rather than relying on file sizes and mtimes
830 ** -r VERSION The specific check-in to list
831 ** -R|--repository REPO Extract info from repository REPO
832 ** -t Sort output in time order
@@ -840,10 +844,11 @@
844 int timeOrder;
845 char *zOrderBy = "pathname";
846 Blob where;
847 int i;
848 int useHash = 0;
849 int showHash = 0;
850 const char *zName;
851 const char *zRev;
852
853 verboseFlag = find_option("verbose","v", 0)!=0;
854 if( !verboseFlag ){
@@ -852,20 +857,21 @@
857 showAge = find_option("age",0,0)!=0;
858 zRev = find_option("r","r",1);
859 timeOrder = find_option("t","t",0)!=0;
860 if( verboseFlag ){
861 useHash = find_option("hash",0,0)!=0;
862 showHash = find_option("h","h",0)!=0;
863 }
864 treeFmt = find_option("tree",0,0)!=0;
865 if( treeFmt ){
866 if( zRev==0 ) zRev = "current";
867 }
868
869 if( zRev!=0 ){
870 db_find_and_open_repository(0, 0);
871 verify_all_options();
872 ls_cmd_rev(zRev,verboseFlag,showAge,showHash,timeOrder,treeFmt);
873 return;
874 }else if( find_option("R",0,1)!=0 ){
875 fossil_fatal("the -r is required in addition to -R");
876 }
877
@@ -984,11 +990,11 @@
990
991 zRev = find_option("r","r",1);
992 if( zRev==0 ) zRev = "current";
993 db_find_and_open_repository(0, 0);
994 verify_all_options();
995 ls_cmd_rev(zRev,0,0,0,0,1);
996 }
997
998 /*
999 ** COMMAND: extras
1000 **
1001

Keyboard Shortcuts

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