Skip to content

Commit e5c744e

Browse files
bk2204gitster
authored andcommitted
hash: use uint32_t for object_id algorithm
We currently use an int for this value, but we'll define this structure from Rust in a future commit and we want to ensure that our data types are exactly identical. To make that possible, use a uint32_t for the hash algorithm. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0c9aee5 commit e5c744e

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

hash.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ const char *empty_tree_oid_hex(const struct git_hash_algo *algop)
241241
return oid_to_hex_r(buf, algop->empty_tree);
242242
}
243243

244-
int hash_algo_by_name(const char *name)
244+
uint32_t hash_algo_by_name(const char *name)
245245
{
246246
if (!name)
247247
return GIT_HASH_UNKNOWN;
@@ -251,15 +251,15 @@ int hash_algo_by_name(const char *name)
251251
return GIT_HASH_UNKNOWN;
252252
}
253253

254-
int hash_algo_by_id(uint32_t format_id)
254+
uint32_t hash_algo_by_id(uint32_t format_id)
255255
{
256256
for (size_t i = 1; i < GIT_HASH_NALGOS; i++)
257257
if (format_id == hash_algos[i].format_id)
258258
return i;
259259
return GIT_HASH_UNKNOWN;
260260
}
261261

262-
int hash_algo_by_length(size_t len)
262+
uint32_t hash_algo_by_length(size_t len)
263263
{
264264
for (size_t i = 1; i < GIT_HASH_NALGOS; i++)
265265
if (len == hash_algos[i].rawsz)

hash.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *s
211211

212212
struct object_id {
213213
unsigned char hash[GIT_MAX_RAWSZ];
214-
int algo; /* XXX requires 4-byte alignment */
214+
uint32_t algo; /* XXX requires 4-byte alignment */
215215
};
216216

217217
#define GET_OID_QUIETLY 01
@@ -344,13 +344,13 @@ static inline void git_hash_final_oid(struct object_id *oid, struct git_hash_ctx
344344
* Return a GIT_HASH_* constant based on the name. Returns GIT_HASH_UNKNOWN if
345345
* the name doesn't match a known algorithm.
346346
*/
347-
int hash_algo_by_name(const char *name);
347+
uint32_t hash_algo_by_name(const char *name);
348348
/* Identical, except based on the format ID. */
349-
int hash_algo_by_id(uint32_t format_id);
349+
uint32_t hash_algo_by_id(uint32_t format_id);
350350
/* Identical, except based on the length. */
351-
int hash_algo_by_length(size_t len);
351+
uint32_t hash_algo_by_length(size_t len);
352352
/* Identical, except for a pointer to struct git_hash_algo. */
353-
static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
353+
static inline uint32_t hash_algo_by_ptr(const struct git_hash_algo *p)
354354
{
355355
size_t i;
356356
for (i = 0; i < GIT_HASH_NALGOS; i++) {

oidtree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct oidtree_iter_data {
1010
oidtree_iter fn;
1111
void *arg;
1212
size_t *last_nibble_at;
13-
int algo;
13+
uint32_t algo;
1414
uint8_t last_byte;
1515
};
1616

repository.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct repository *the_repository = &the_repo;
3939
static void set_default_hash_algo(struct repository *repo)
4040
{
4141
const char *hash_name;
42-
int algo;
42+
uint32_t algo;
4343

4444
hash_name = getenv("GIT_TEST_DEFAULT_HASH_ALGO");
4545
if (!hash_name)
@@ -186,12 +186,12 @@ void repo_set_gitdir(struct repository *repo,
186186
repo->gitdir, "index");
187187
}
188188

189-
void repo_set_hash_algo(struct repository *repo, int hash_algo)
189+
void repo_set_hash_algo(struct repository *repo, uint32_t hash_algo)
190190
{
191191
repo->hash_algo = &hash_algos[hash_algo];
192192
}
193193

194-
void repo_set_compat_hash_algo(struct repository *repo, int algo)
194+
void repo_set_compat_hash_algo(struct repository *repo, uint32_t algo)
195195
{
196196
#ifdef WITH_RUST
197197
if (hash_algo_by_ptr(repo->hash_algo) == algo)

repository.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ struct set_gitdir_args {
193193
void repo_set_gitdir(struct repository *repo, const char *root,
194194
const struct set_gitdir_args *extra_args);
195195
void repo_set_worktree(struct repository *repo, const char *path);
196-
void repo_set_hash_algo(struct repository *repo, int algo);
197-
void repo_set_compat_hash_algo(struct repository *repo, int compat_algo);
196+
void repo_set_hash_algo(struct repository *repo, uint32_t algo);
197+
void repo_set_compat_hash_algo(struct repository *repo, uint32_t compat_algo);
198198
void repo_set_ref_storage_format(struct repository *repo,
199199
enum ref_storage_format format);
200200
void initialize_repository(struct repository *repo);

serve.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
static int advertise_sid = -1;
1616
static int advertise_object_info = -1;
17-
static int client_hash_algo = GIT_HASH_SHA1_LEGACY;
17+
static uint32_t client_hash_algo = GIT_HASH_SHA1_LEGACY;
1818

1919
static int always_advertise(struct repository *r UNUSED,
2020
struct strbuf *value UNUSED)

0 commit comments

Comments
 (0)