1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-04-27 07:05:08 +02:00

Merge branch 'jc/retire-get-sha1-hex'

The implementation of "get_sha1_hex()" that reads a hexadecimal
string that spells a full object name has been extended to cope
with any hash function used in the repository, but the "sha1" in
its name survived.  Rename it to get_hash_hex(), a name that is
more consistent within its friends like get_hash_hex_algop().

* jc/retire-get-sha1-hex:
  hex: retire get_sha1_hex()
This commit is contained in:
Junio C Hamano 2023-08-04 10:52:30 -07:00
commit 3365e2675e
4 changed files with 9 additions and 7 deletions

2
hex.c
View File

@ -63,7 +63,7 @@ static int get_hash_hex_algop(const char *hex, unsigned char *hash,
return 0;
}
int get_sha1_hex(const char *hex, unsigned char *sha1)
int get_hash_hex(const char *hex, unsigned char *sha1)
{
return get_hash_hex_algop(hex, sha1, the_hash_algo);
}

10
hex.h
View File

@ -20,14 +20,16 @@ static inline int hex2chr(const char *s)
}
/*
* Try to read a SHA1 in hexadecimal format from the 40 characters
* starting at hex. Write the 20-byte result to sha1 in binary form.
* Try to read a hash (specified by the_hash_algo) in hexadecimal
* format from the 40 (or whatever length the hash algorithm uses)
* characters starting at hex. Write the 20-byte (or the length of
* the hash) result to hash in binary form.
* Return 0 on success. Reading stops if a NUL is encountered in the
* input, so it is safe to pass this function an arbitrary
* null-terminated string.
*/
int get_sha1_hex(const char *hex, unsigned char *sha1);
int get_oid_hex(const char *hex, struct object_id *sha1);
int get_hash_hex(const char *hex, unsigned char *hash);
int get_oid_hex(const char *hex, struct object_id *oid);
/* Like get_oid_hex, but for an arbitrary hash algorithm. */
int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_hash_algo *algop);

View File

@ -751,7 +751,7 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
p->pack_local = local;
p->mtime = st.st_mtime;
if (path_len < the_hash_algo->hexsz ||
get_sha1_hex(path + path_len - the_hash_algo->hexsz, p->hash))
get_hash_hex(path + path_len - the_hash_algo->hexsz, p->hash))
hashclr(p->hash);
return p;
}

View File

@ -204,7 +204,7 @@ static void read_rr(struct repository *r, struct string_list *rr)
const unsigned hexsz = the_hash_algo->hexsz;
/* There has to be the hash, tab, path and then NUL */
if (buf.len < hexsz + 2 || get_sha1_hex(buf.buf, hash))
if (buf.len < hexsz + 2 || get_hash_hex(buf.buf, hash))
die(_("corrupt MERGE_RR"));
if (buf.buf[hexsz] != '.') {