Fossil SCM

Add the -h/--hash option to the "fossil whatis" command.

drh 2026-02-05 11:55 trunk
Commit 49f93f8e899382e961a32a41b404952844f5072824b92ca3e4bc54d80aa54a0f
1 file changed +13 -3
+13 -3
--- src/name.c
+++ src/name.c
@@ -1131,10 +1131,11 @@
11311131
#if INTERFACE
11321132
#define WHATIS_VERBOSE 0x01 /* Extra output */
11331133
#define WHATIS_BRIEF 0x02 /* Omit unnecessary output */
11341134
#define WHATIS_REPO 0x04 /* Show repository name */
11351135
#define WHATIS_OMIT_UNK 0x08 /* Do not show "unknown" lines */
1136
+#define WHATIS_HASHONLY 0x10 /* Show only the hash */
11361137
#endif
11371138
11381139
/*
11391140
** Generate a description of artifact "rid"
11401141
*/
@@ -1148,11 +1149,13 @@
11481149
" FROM blob, rcvfrom"
11491150
" WHERE rid=%d"
11501151
" AND rcvfrom.rcvid=blob.rcvid",
11511152
rid);
11521153
if( db_step(&q)==SQLITE_ROW ){
1153
- if( flags & WHATIS_VERBOSE ){
1154
+ if( flags & WHATIS_HASHONLY ){
1155
+ fossil_print("%s\n", db_column_text(&q,0));
1156
+ }else if( flags & WHATIS_VERBOSE ){
11541157
fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid);
11551158
fossil_print("size: %d bytes\n", db_column_int(&q,1));
11561159
fossil_print("received: %s from %s\n",
11571160
db_column_text(&q, 2),
11581161
db_column_text(&q, 3));
@@ -1160,10 +1163,11 @@
11601163
fossil_print("artifact: %s\n", db_column_text(&q,0));
11611164
fossil_print("size: %d bytes\n", db_column_int(&q,1));
11621165
}
11631166
}
11641167
db_finalize(&q);
1168
+ if( flags & WHATIS_HASHONLY ) return;
11651169
11661170
/* Report any symbolic tags on this artifact */
11671171
db_prepare(&q,
11681172
"SELECT substr(tagname,5)"
11691173
" FROM tag JOIN tagxref ON tag.tagid=tagxref.tagid"
@@ -1330,11 +1334,11 @@
13301334
if( cnt++ ) fossil_print("%12s---- meaning #%d ----\n", " ", cnt);
13311335
whatis_rid(db_column_int(&q, 0), mFlags);
13321336
}
13331337
db_finalize(&q);
13341338
}else if( rid==0 ){
1335
- if( (mFlags & WHATIS_OMIT_UNK)==0 ){
1339
+ if( (mFlags & (WHATIS_OMIT_UNK|WHATIS_HASHONLY))==0 ){
13361340
/* 0123456789 12 */
13371341
if( zFileName ){
13381342
fossil_print("%-12s%s\n", "name:", zFileName);
13391343
}
13401344
fossil_print("unknown: %s\n", zName);
@@ -1344,11 +1348,13 @@
13441348
fossil_print("\nrepository: %s\n", g.zRepositoryName);
13451349
}
13461350
if( zFileName ){
13471351
zName = zFileName;
13481352
}
1349
- fossil_print("%-12s%s\n", "name:", zName);
1353
+ if( (mFlags & WHATIS_HASHONLY)==0 ){
1354
+ fossil_print("%-12s%s\n", "name:", zName);
1355
+ }
13501356
whatis_rid(rid, mFlags);
13511357
}
13521358
}
13531359
13541360
/*
@@ -1361,10 +1367,11 @@
13611367
** plays.
13621368
**
13631369
** Options:
13641370
** -f|--file Find artifacts with the same hash as file NAME.
13651371
** If NAME is "-", read content from standard input.
1372
+** -h|--hash Show only the hash of matching artifacts.
13661373
** -q|--quiet Show nothing if NAME is not found
13671374
** --type TYPE Only find artifacts of TYPE (one of: 'ci', 't',
13681375
** 'w', 'g', or 'e')
13691376
** -v|--verbose Provide extra information (such as the RID)
13701377
*/
@@ -1374,10 +1381,13 @@
13741381
int i;
13751382
const char *zType = 0;
13761383
db_find_and_open_repository(0,0);
13771384
if( find_option("verbose","v",0)!=0 ){
13781385
mFlags |= WHATIS_VERBOSE;
1386
+ }
1387
+ if( find_option("hash","h",0)!=0 ){
1388
+ mFlags |= WHATIS_HASHONLY;
13791389
}
13801390
if( g.fQuiet ){
13811391
mFlags |= WHATIS_OMIT_UNK | WHATIS_REPO;
13821392
}
13831393
fileFlag = find_option("file","f",0)!=0;
13841394
--- src/name.c
+++ src/name.c
@@ -1131,10 +1131,11 @@
1131 #if INTERFACE
1132 #define WHATIS_VERBOSE 0x01 /* Extra output */
1133 #define WHATIS_BRIEF 0x02 /* Omit unnecessary output */
1134 #define WHATIS_REPO 0x04 /* Show repository name */
1135 #define WHATIS_OMIT_UNK 0x08 /* Do not show "unknown" lines */
 
1136 #endif
1137
1138 /*
1139 ** Generate a description of artifact "rid"
1140 */
@@ -1148,11 +1149,13 @@
1148 " FROM blob, rcvfrom"
1149 " WHERE rid=%d"
1150 " AND rcvfrom.rcvid=blob.rcvid",
1151 rid);
1152 if( db_step(&q)==SQLITE_ROW ){
1153 if( flags & WHATIS_VERBOSE ){
 
 
1154 fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid);
1155 fossil_print("size: %d bytes\n", db_column_int(&q,1));
1156 fossil_print("received: %s from %s\n",
1157 db_column_text(&q, 2),
1158 db_column_text(&q, 3));
@@ -1160,10 +1163,11 @@
1160 fossil_print("artifact: %s\n", db_column_text(&q,0));
1161 fossil_print("size: %d bytes\n", db_column_int(&q,1));
1162 }
1163 }
1164 db_finalize(&q);
 
1165
1166 /* Report any symbolic tags on this artifact */
1167 db_prepare(&q,
1168 "SELECT substr(tagname,5)"
1169 " FROM tag JOIN tagxref ON tag.tagid=tagxref.tagid"
@@ -1330,11 +1334,11 @@
1330 if( cnt++ ) fossil_print("%12s---- meaning #%d ----\n", " ", cnt);
1331 whatis_rid(db_column_int(&q, 0), mFlags);
1332 }
1333 db_finalize(&q);
1334 }else if( rid==0 ){
1335 if( (mFlags & WHATIS_OMIT_UNK)==0 ){
1336 /* 0123456789 12 */
1337 if( zFileName ){
1338 fossil_print("%-12s%s\n", "name:", zFileName);
1339 }
1340 fossil_print("unknown: %s\n", zName);
@@ -1344,11 +1348,13 @@
1344 fossil_print("\nrepository: %s\n", g.zRepositoryName);
1345 }
1346 if( zFileName ){
1347 zName = zFileName;
1348 }
1349 fossil_print("%-12s%s\n", "name:", zName);
 
 
1350 whatis_rid(rid, mFlags);
1351 }
1352 }
1353
1354 /*
@@ -1361,10 +1367,11 @@
1361 ** plays.
1362 **
1363 ** Options:
1364 ** -f|--file Find artifacts with the same hash as file NAME.
1365 ** If NAME is "-", read content from standard input.
 
1366 ** -q|--quiet Show nothing if NAME is not found
1367 ** --type TYPE Only find artifacts of TYPE (one of: 'ci', 't',
1368 ** 'w', 'g', or 'e')
1369 ** -v|--verbose Provide extra information (such as the RID)
1370 */
@@ -1374,10 +1381,13 @@
1374 int i;
1375 const char *zType = 0;
1376 db_find_and_open_repository(0,0);
1377 if( find_option("verbose","v",0)!=0 ){
1378 mFlags |= WHATIS_VERBOSE;
 
 
 
1379 }
1380 if( g.fQuiet ){
1381 mFlags |= WHATIS_OMIT_UNK | WHATIS_REPO;
1382 }
1383 fileFlag = find_option("file","f",0)!=0;
1384
--- src/name.c
+++ src/name.c
@@ -1131,10 +1131,11 @@
1131 #if INTERFACE
1132 #define WHATIS_VERBOSE 0x01 /* Extra output */
1133 #define WHATIS_BRIEF 0x02 /* Omit unnecessary output */
1134 #define WHATIS_REPO 0x04 /* Show repository name */
1135 #define WHATIS_OMIT_UNK 0x08 /* Do not show "unknown" lines */
1136 #define WHATIS_HASHONLY 0x10 /* Show only the hash */
1137 #endif
1138
1139 /*
1140 ** Generate a description of artifact "rid"
1141 */
@@ -1148,11 +1149,13 @@
1149 " FROM blob, rcvfrom"
1150 " WHERE rid=%d"
1151 " AND rcvfrom.rcvid=blob.rcvid",
1152 rid);
1153 if( db_step(&q)==SQLITE_ROW ){
1154 if( flags & WHATIS_HASHONLY ){
1155 fossil_print("%s\n", db_column_text(&q,0));
1156 }else if( flags & WHATIS_VERBOSE ){
1157 fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid);
1158 fossil_print("size: %d bytes\n", db_column_int(&q,1));
1159 fossil_print("received: %s from %s\n",
1160 db_column_text(&q, 2),
1161 db_column_text(&q, 3));
@@ -1160,10 +1163,11 @@
1163 fossil_print("artifact: %s\n", db_column_text(&q,0));
1164 fossil_print("size: %d bytes\n", db_column_int(&q,1));
1165 }
1166 }
1167 db_finalize(&q);
1168 if( flags & WHATIS_HASHONLY ) return;
1169
1170 /* Report any symbolic tags on this artifact */
1171 db_prepare(&q,
1172 "SELECT substr(tagname,5)"
1173 " FROM tag JOIN tagxref ON tag.tagid=tagxref.tagid"
@@ -1330,11 +1334,11 @@
1334 if( cnt++ ) fossil_print("%12s---- meaning #%d ----\n", " ", cnt);
1335 whatis_rid(db_column_int(&q, 0), mFlags);
1336 }
1337 db_finalize(&q);
1338 }else if( rid==0 ){
1339 if( (mFlags & (WHATIS_OMIT_UNK|WHATIS_HASHONLY))==0 ){
1340 /* 0123456789 12 */
1341 if( zFileName ){
1342 fossil_print("%-12s%s\n", "name:", zFileName);
1343 }
1344 fossil_print("unknown: %s\n", zName);
@@ -1344,11 +1348,13 @@
1348 fossil_print("\nrepository: %s\n", g.zRepositoryName);
1349 }
1350 if( zFileName ){
1351 zName = zFileName;
1352 }
1353 if( (mFlags & WHATIS_HASHONLY)==0 ){
1354 fossil_print("%-12s%s\n", "name:", zName);
1355 }
1356 whatis_rid(rid, mFlags);
1357 }
1358 }
1359
1360 /*
@@ -1361,10 +1367,11 @@
1367 ** plays.
1368 **
1369 ** Options:
1370 ** -f|--file Find artifacts with the same hash as file NAME.
1371 ** If NAME is "-", read content from standard input.
1372 ** -h|--hash Show only the hash of matching artifacts.
1373 ** -q|--quiet Show nothing if NAME is not found
1374 ** --type TYPE Only find artifacts of TYPE (one of: 'ci', 't',
1375 ** 'w', 'g', or 'e')
1376 ** -v|--verbose Provide extra information (such as the RID)
1377 */
@@ -1374,10 +1381,13 @@
1381 int i;
1382 const char *zType = 0;
1383 db_find_and_open_repository(0,0);
1384 if( find_option("verbose","v",0)!=0 ){
1385 mFlags |= WHATIS_VERBOSE;
1386 }
1387 if( find_option("hash","h",0)!=0 ){
1388 mFlags |= WHATIS_HASHONLY;
1389 }
1390 if( g.fQuiet ){
1391 mFlags |= WHATIS_OMIT_UNK | WHATIS_REPO;
1392 }
1393 fileFlag = find_option("file","f",0)!=0;
1394

Keyboard Shortcuts

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