192
193
extern const struct object_id null_oid;
194
195
-static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
195
+static inline int hashcmp_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
196
{
197
/*
198
* Teach the compiler that there are only two possibilities of hash size
199
* here, so that it can optimize for this case as much as possible.
200
*/
201
- if (the_hash_algo->rawsz == GIT_MAX_RAWSZ)
201
+ if (algop->rawsz == GIT_MAX_RAWSZ)
202
return memcmp(sha1, sha2, GIT_MAX_RAWSZ);
203
return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
204
}
205
206
+static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
207
+{
208
+ return hashcmp_algop(sha1, sha2, the_hash_algo);
209
+}
210
+
211
static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
212
{
208
- return hashcmp(oid1->hash, oid2->hash);
213
+ const struct git_hash_algo *algop;
214
+ if (!oid1->algo)
215
+ algop = the_hash_algo;
216
+ else
217
+ algop = &hash_algos[oid1->algo];
218
+ return hashcmp_algop(oid1->hash, oid2->hash, algop);
219
}
220
211
-static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2)
221
+static inline int hasheq_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
222
{
223
/*
224
* We write this here instead of deferring to hashcmp so that the
225
* compiler can properly inline it and avoid calling memcmp.
226
*/
217
- if (the_hash_algo->rawsz == GIT_MAX_RAWSZ)
227
+ if (algop->rawsz == GIT_MAX_RAWSZ)
228
return !memcmp(sha1, sha2, GIT_MAX_RAWSZ);
229
return !memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
230
}
231
232
+static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2)
233
+{
234
+ return hasheq_algop(sha1, sha2, the_hash_algo);
235
+}
236
+
237
static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
238
{
224
- return hasheq(oid1->hash, oid2->hash);
239
+ const struct git_hash_algo *algop;
240
+ if (!oid1->algo)
241
+ algop = the_hash_algo;
242
+ else
243
+ algop = &hash_algos[oid1->algo];
244
+ return hasheq_algop(oid1->hash, oid2->hash, algop);
245
}
246
247
static inline int is_null_oid(const struct object_id *oid)
257
static inline void oidcpy(struct object_id *dst, const struct object_id *src)
258
{
259
memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ);
260
+ dst->algo = src->algo;
261
}
262
263
static inline struct object_id *oiddup(const struct object_id *src)
275
static inline void oidclr(struct object_id *oid)
276
{
277
memset(oid->hash, 0, GIT_MAX_RAWSZ);
278
+ oid->algo = hash_algo_by_ptr(the_hash_algo);
279
}
280
281
static inline void oidread(struct object_id *oid, const unsigned char *hash)
282
{
283
memcpy(oid->hash, hash, the_hash_algo->rawsz);
284
+ oid->algo = hash_algo_by_ptr(the_hash_algo);
285
}
286
287
static inline int is_empty_blob_sha1(const unsigned char *sha1)
304
return oideq(oid, the_hash_algo->empty_tree);
305
}
306
307
+static inline void oid_set_algo(struct object_id *oid, const struct git_hash_algo *algop)
308
+{
309
+ oid->algo = hash_algo_by_ptr(algop);
310
+}
311
+
312
const char *empty_tree_oid_hex(void);
313
const char *empty_blob_oid_hex(void);
314