builtin/name-rev: make hash-size independent
Use the_hash_algo when parsing instead of GIT_SHA1_HEXSZ so that this function works with any size hash. Rename the variable forty to counter, as this is a better name and is independent of the hash size. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Feb 19, 2019 at 00:05 UTC
1c4675dc57b96f108adcfebb1fcfd67128ae856e
1 file changed
+8
-6
builtin/name-rev.c
+8
-6
@@ -361,23 +361,25 @@ static char const * const name_rev_usage[] = {
361
static void name_rev_line(char *p, struct name_ref_data *data)
362
{
363
struct strbuf buf = STRBUF_INIT;
364
- int forty = 0;
364
+ int counter = 0;
365
char *p_start;
366
+ const unsigned hexsz = the_hash_algo->hexsz;
367
+
368
for (p_start = p; *p; p++) {
369
#define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f'))
370
if (!ishex(*p))
369
- forty = 0;
370
- else if (++forty == GIT_SHA1_HEXSZ &&
371
+ counter = 0;
372
+ else if (++counter == hexsz &&
373
!ishex(*(p+1))) {
374
struct object_id oid;
375
const char *name = NULL;
376
char c = *(p+1);
377
int p_len = p - p_start + 1;
378
377
- forty = 0;
379
+ counter = 0;
380
381
*(p+1) = 0;
380
- if (!get_oid(p - (GIT_SHA1_HEXSZ - 1), &oid)) {
382
+ if (!get_oid(p - (hexsz - 1), &oid)) {
383
struct object *o =
384
lookup_object(the_repository,
385
oid.hash);
@@ -390,7 +392,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
392
continue;
393
394
if (data->name_only)
393
- printf("%.*s%s", p_len - GIT_SHA1_HEXSZ, p_start, name);
395
+ printf("%.*s%s", p_len - hexsz, p_start, name);
396
else
397
printf("%.*s (%s)", p_len, p_start, name);
398
p_start = p + 1;