Fossil SCM
Add the -h/--hash option to the "fossil whatis" command.
Commit
49f93f8e899382e961a32a41b404952844f5072824b92ca3e4bc54d80aa54a0f
Parent
12036a362cdde66…
1 file changed
+13
-3
+13
-3
| --- src/name.c | ||
| +++ src/name.c | ||
| @@ -1131,10 +1131,11 @@ | ||
| 1131 | 1131 | #if INTERFACE |
| 1132 | 1132 | #define WHATIS_VERBOSE 0x01 /* Extra output */ |
| 1133 | 1133 | #define WHATIS_BRIEF 0x02 /* Omit unnecessary output */ |
| 1134 | 1134 | #define WHATIS_REPO 0x04 /* Show repository name */ |
| 1135 | 1135 | #define WHATIS_OMIT_UNK 0x08 /* Do not show "unknown" lines */ |
| 1136 | +#define WHATIS_HASHONLY 0x10 /* Show only the hash */ | |
| 1136 | 1137 | #endif |
| 1137 | 1138 | |
| 1138 | 1139 | /* |
| 1139 | 1140 | ** Generate a description of artifact "rid" |
| 1140 | 1141 | */ |
| @@ -1148,11 +1149,13 @@ | ||
| 1148 | 1149 | " FROM blob, rcvfrom" |
| 1149 | 1150 | " WHERE rid=%d" |
| 1150 | 1151 | " AND rcvfrom.rcvid=blob.rcvid", |
| 1151 | 1152 | rid); |
| 1152 | 1153 | 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 ){ | |
| 1154 | 1157 | fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid); |
| 1155 | 1158 | fossil_print("size: %d bytes\n", db_column_int(&q,1)); |
| 1156 | 1159 | fossil_print("received: %s from %s\n", |
| 1157 | 1160 | db_column_text(&q, 2), |
| 1158 | 1161 | db_column_text(&q, 3)); |
| @@ -1160,10 +1163,11 @@ | ||
| 1160 | 1163 | fossil_print("artifact: %s\n", db_column_text(&q,0)); |
| 1161 | 1164 | fossil_print("size: %d bytes\n", db_column_int(&q,1)); |
| 1162 | 1165 | } |
| 1163 | 1166 | } |
| 1164 | 1167 | db_finalize(&q); |
| 1168 | + if( flags & WHATIS_HASHONLY ) return; | |
| 1165 | 1169 | |
| 1166 | 1170 | /* Report any symbolic tags on this artifact */ |
| 1167 | 1171 | db_prepare(&q, |
| 1168 | 1172 | "SELECT substr(tagname,5)" |
| 1169 | 1173 | " FROM tag JOIN tagxref ON tag.tagid=tagxref.tagid" |
| @@ -1330,11 +1334,11 @@ | ||
| 1330 | 1334 | if( cnt++ ) fossil_print("%12s---- meaning #%d ----\n", " ", cnt); |
| 1331 | 1335 | whatis_rid(db_column_int(&q, 0), mFlags); |
| 1332 | 1336 | } |
| 1333 | 1337 | db_finalize(&q); |
| 1334 | 1338 | }else if( rid==0 ){ |
| 1335 | - if( (mFlags & WHATIS_OMIT_UNK)==0 ){ | |
| 1339 | + if( (mFlags & (WHATIS_OMIT_UNK|WHATIS_HASHONLY))==0 ){ | |
| 1336 | 1340 | /* 0123456789 12 */ |
| 1337 | 1341 | if( zFileName ){ |
| 1338 | 1342 | fossil_print("%-12s%s\n", "name:", zFileName); |
| 1339 | 1343 | } |
| 1340 | 1344 | fossil_print("unknown: %s\n", zName); |
| @@ -1344,11 +1348,13 @@ | ||
| 1344 | 1348 | fossil_print("\nrepository: %s\n", g.zRepositoryName); |
| 1345 | 1349 | } |
| 1346 | 1350 | if( zFileName ){ |
| 1347 | 1351 | zName = zFileName; |
| 1348 | 1352 | } |
| 1349 | - fossil_print("%-12s%s\n", "name:", zName); | |
| 1353 | + if( (mFlags & WHATIS_HASHONLY)==0 ){ | |
| 1354 | + fossil_print("%-12s%s\n", "name:", zName); | |
| 1355 | + } | |
| 1350 | 1356 | whatis_rid(rid, mFlags); |
| 1351 | 1357 | } |
| 1352 | 1358 | } |
| 1353 | 1359 | |
| 1354 | 1360 | /* |
| @@ -1361,10 +1367,11 @@ | ||
| 1361 | 1367 | ** plays. |
| 1362 | 1368 | ** |
| 1363 | 1369 | ** Options: |
| 1364 | 1370 | ** -f|--file Find artifacts with the same hash as file NAME. |
| 1365 | 1371 | ** If NAME is "-", read content from standard input. |
| 1372 | +** -h|--hash Show only the hash of matching artifacts. | |
| 1366 | 1373 | ** -q|--quiet Show nothing if NAME is not found |
| 1367 | 1374 | ** --type TYPE Only find artifacts of TYPE (one of: 'ci', 't', |
| 1368 | 1375 | ** 'w', 'g', or 'e') |
| 1369 | 1376 | ** -v|--verbose Provide extra information (such as the RID) |
| 1370 | 1377 | */ |
| @@ -1374,10 +1381,13 @@ | ||
| 1374 | 1381 | int i; |
| 1375 | 1382 | const char *zType = 0; |
| 1376 | 1383 | db_find_and_open_repository(0,0); |
| 1377 | 1384 | if( find_option("verbose","v",0)!=0 ){ |
| 1378 | 1385 | mFlags |= WHATIS_VERBOSE; |
| 1386 | + } | |
| 1387 | + if( find_option("hash","h",0)!=0 ){ | |
| 1388 | + mFlags |= WHATIS_HASHONLY; | |
| 1379 | 1389 | } |
| 1380 | 1390 | if( g.fQuiet ){ |
| 1381 | 1391 | mFlags |= WHATIS_OMIT_UNK | WHATIS_REPO; |
| 1382 | 1392 | } |
| 1383 | 1393 | fileFlag = find_option("file","f",0)!=0; |
| 1384 | 1394 |
| --- 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 |