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>
This commit is contained in:

committed by
Junio C Hamano

parent
538b152324
commit
1c4675dc57
@ -361,23 +361,25 @@ static char const * const name_rev_usage[] = {
|
|||||||
static void name_rev_line(char *p, struct name_ref_data *data)
|
static void name_rev_line(char *p, struct name_ref_data *data)
|
||||||
{
|
{
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
int forty = 0;
|
int counter = 0;
|
||||||
char *p_start;
|
char *p_start;
|
||||||
|
const unsigned hexsz = the_hash_algo->hexsz;
|
||||||
|
|
||||||
for (p_start = p; *p; p++) {
|
for (p_start = p; *p; p++) {
|
||||||
#define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f'))
|
#define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f'))
|
||||||
if (!ishex(*p))
|
if (!ishex(*p))
|
||||||
forty = 0;
|
counter = 0;
|
||||||
else if (++forty == GIT_SHA1_HEXSZ &&
|
else if (++counter == hexsz &&
|
||||||
!ishex(*(p+1))) {
|
!ishex(*(p+1))) {
|
||||||
struct object_id oid;
|
struct object_id oid;
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
char c = *(p+1);
|
char c = *(p+1);
|
||||||
int p_len = p - p_start + 1;
|
int p_len = p - p_start + 1;
|
||||||
|
|
||||||
forty = 0;
|
counter = 0;
|
||||||
|
|
||||||
*(p+1) = 0;
|
*(p+1) = 0;
|
||||||
if (!get_oid(p - (GIT_SHA1_HEXSZ - 1), &oid)) {
|
if (!get_oid(p - (hexsz - 1), &oid)) {
|
||||||
struct object *o =
|
struct object *o =
|
||||||
lookup_object(the_repository,
|
lookup_object(the_repository,
|
||||||
oid.hash);
|
oid.hash);
|
||||||
@ -390,7 +392,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (data->name_only)
|
if (data->name_only)
|
||||||
printf("%.*s%s", p_len - GIT_SHA1_HEXSZ, p_start, name);
|
printf("%.*s%s", p_len - hexsz, p_start, name);
|
||||||
else
|
else
|
||||||
printf("%.*s (%s)", p_len, p_start, name);
|
printf("%.*s (%s)", p_len, p_start, name);
|
||||||
p_start = p + 1;
|
p_start = p + 1;
|
||||||
|
Reference in New Issue
Block a user