Commit 8444b6dce71d53a44f300d7c023cdd075faaa872

Edward Thomson 2022-01-26T13:07:28

odb_hash*: accept the oid type to hash into The git_odb_hash helper functions should not assume SHA1, and instead should be given the oid type that they're producing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
diff --git a/fuzzers/packfile_fuzzer.c b/fuzzers/packfile_fuzzer.c
index 7f448f6..3d6d9a3 100644
--- a/fuzzers/packfile_fuzzer.c
+++ b/fuzzers/packfile_fuzzer.c
@@ -90,7 +90,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
 	if (git_indexer_append(indexer, data, size, &stats) < 0)
 		goto cleanup;
 	if (append_hash) {
-		if (git_odb_hash(&oid, data, size, GIT_OBJECT_BLOB) < 0) {
+		if (git_odb_hash(&oid, data, size, GIT_OBJECT_BLOB, GIT_OID_SHA1) < 0) {
 			fprintf(stderr, "Failed to compute the SHA1 hash\n");
 			abort();
 		}
diff --git a/include/git2/odb.h b/include/git2/odb.h
index 54c38a4..61e04d1 100644
--- a/include/git2/odb.h
+++ b/include/git2/odb.h
@@ -435,18 +435,24 @@ GIT_EXTERN(int) git_odb_write_multi_pack_index(
 	git_odb *db);
 
 /**
- * Determine the object-ID (sha1 hash) of a data buffer
+ * Determine the object-ID (sha1 or sha256 hash) of a data buffer
  *
- * The resulting SHA-1 OID will be the identifier for the data
- * buffer as if the data buffer it were to written to the ODB.
+ * The resulting OID will be the identifier for the data buffer as if
+ * the data buffer it were to written to the ODB.
  *
  * @param out the resulting object-ID.
  * @param data data to hash
  * @param len size of the data
- * @param type of the data to hash
+ * @param object_type of the data to hash
+ * @param oid_type the oid type to hash to
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_object_t type);
+GIT_EXTERN(int) git_odb_hash(
+	git_oid *out,
+	const void *data,
+	size_t len,
+	git_object_t object_type,
+	git_oid_t oid_type);
 
 /**
  * Read a file from disk and fill a git_oid with the object id
@@ -458,10 +464,15 @@ GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_obj
  *
  * @param out oid structure the result is written into.
  * @param path file to read and determine object id for
- * @param type the type of the object that will be hashed
+ * @param object_type of the data to hash
+ * @param oid_type the oid type to hash to
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_odb_hashfile(git_oid *out, const char *path, git_object_t type);
+GIT_EXTERN(int) git_odb_hashfile(
+	git_oid *out,
+	const char *path,
+	git_object_t object_type,
+	git_oid_t oid_type);
 
 /**
  * Create a copy of an odb_object
diff --git a/src/cli/cmd_hash_object.c b/src/cli/cmd_hash_object.c
index 5cfe914..72fbef9 100644
--- a/src/cli/cmd_hash_object.c
+++ b/src/cli/cmd_hash_object.c
@@ -64,7 +64,7 @@ static int hash_buf(git_odb *odb, git_str *buf, git_object_t type)
 		if (git_odb_write(&oid, odb, buf->ptr, buf->size, type) < 0)
 			return cli_error_git();
 	} else {
-		if (git_odb_hash(&oid, buf->ptr, buf->size, type) < 0)
+		if (git_odb_hash(&oid, buf->ptr, buf->size, type, GIT_OID_SHA1) < 0)
 			return cli_error_git();
 	}
 
diff --git a/src/libgit2/diff_file.c b/src/libgit2/diff_file.c
index 3971655..4d63317 100644
--- a/src/libgit2/diff_file.c
+++ b/src/libgit2/diff_file.c
@@ -162,7 +162,7 @@ int git_diff_file_content__init_from_src(
 			fc->flags |= GIT_DIFF_FLAG__FREE_BLOB;
 		} else {
 			int error;
-			if ((error = git_odb_hash(&fc->file->id, src->buf, src->buflen, GIT_OBJECT_BLOB)) < 0)
+			if ((error = git_odb_hash(&fc->file->id, src->buf, src->buflen, GIT_OBJECT_BLOB, GIT_OID_SHA1)) < 0)
 				return error;
 			fc->file->size = src->buflen;
 			fc->file->id_abbrev = GIT_OID_SHA1_HEXSIZE;
@@ -412,7 +412,8 @@ static int diff_file_content_load_workdir(
 	/* once data is loaded, update OID if we didn't have it previously */
 	if (!error && (fc->file->flags & GIT_DIFF_FLAG_VALID_ID) == 0) {
 		error = git_odb_hash(
-			&fc->file->id, fc->map.data, fc->map.len, GIT_OBJECT_BLOB);
+			&fc->file->id, fc->map.data, fc->map.len,
+			GIT_OBJECT_BLOB, GIT_OID_SHA1);
 		fc->file->flags |= GIT_DIFF_FLAG_VALID_ID;
 	}
 
diff --git a/src/libgit2/diff_generate.c b/src/libgit2/diff_generate.c
index d22c557..a88ce8c 100644
--- a/src/libgit2/diff_generate.c
+++ b/src/libgit2/diff_generate.c
@@ -660,7 +660,7 @@ int git_diff__oid_for_entry(
 			git_error_clear();
 		}
 	} else if (S_ISLNK(mode)) {
-		error = git_odb__hashlink(out, full_path.ptr);
+		error = git_odb__hashlink(out, full_path.ptr, GIT_OID_SHA1);
 		diff->base.perf.oid_calculations++;
 	} else if (!git__is_sizet(entry.file_size)) {
 		git_error_set(GIT_ERROR_NOMEMORY, "file size overflow (for 32-bits) on '%s'",
@@ -675,7 +675,8 @@ int git_diff__oid_for_entry(
 			error = fd;
 		else {
 			error = git_odb__hashfd_filtered(
-				out, fd, (size_t)entry.file_size, GIT_OBJECT_BLOB, fl);
+				out, fd, (size_t)entry.file_size,
+				GIT_OBJECT_BLOB, GIT_OID_SHA1, fl);
 			p_close(fd);
 			diff->base.perf.oid_calculations++;
 		}
diff --git a/src/libgit2/indexer.c b/src/libgit2/indexer.c
index e7ea77e..c35e659 100644
--- a/src/libgit2/indexer.c
+++ b/src/libgit2/indexer.c
@@ -546,7 +546,7 @@ static int hash_and_save(git_indexer *idx, git_rawobj *obj, off64_t entry_start)
 	entry = git__calloc(1, sizeof(*entry));
 	GIT_ERROR_CHECK_ALLOC(entry);
 
-	if (git_odb__hashobj(&oid, obj) < 0) {
+	if (git_odb__hashobj(&oid, obj, GIT_OID_SHA1) < 0) {
 		git_error_set(GIT_ERROR_INDEXER, "failed to hash object");
 		goto on_error;
 	}
diff --git a/src/libgit2/iterator.c b/src/libgit2/iterator.c
index 8b204b0..a8377f7 100644
--- a/src/libgit2/iterator.c
+++ b/src/libgit2/iterator.c
@@ -1281,7 +1281,7 @@ static int filesystem_iterator_entry_hash(
 
 	if (!(error = git_str_joinpath(&fullpath, iter->root, entry->path)) &&
 	    !(error = git_path_validate_str_length(iter->base.repo, &fullpath)))
-		error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB);
+		error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB, GIT_OID_SHA1);
 
 	git_str_dispose(&fullpath);
 	return error;
diff --git a/src/libgit2/object.c b/src/libgit2/object.c
index 61c7b90..3794e5c 100644
--- a/src/libgit2/object.c
+++ b/src/libgit2/object.c
@@ -21,7 +21,6 @@
 
 bool git_object__strict_input_validation = true;
 
-extern int git_odb_hash(git_oid *out, const void *data, size_t len, git_object_t type);
 size_t git_object__size(git_object_t type);
 
 typedef struct {
@@ -87,7 +86,7 @@ int git_object__from_raw(
 	GIT_ERROR_CHECK_ALLOC(object);
 	object->cached.flags = GIT_CACHE_STORE_PARSED;
 	object->cached.type = type;
-	if ((error = git_odb_hash(&object->cached.oid, data, size, type)) < 0)
+	if ((error = git_odb_hash(&object->cached.oid, data, size, type, GIT_OID_SHA1)) < 0)
 		return error;
 
 	/* Parse raw object data */
diff --git a/src/libgit2/odb.c b/src/libgit2/odb.c
index 3a7d08c..787189b 100644
--- a/src/libgit2/odb.c
+++ b/src/libgit2/odb.c
@@ -105,11 +105,12 @@ int git_odb__format_object_header(
 	return 0;
 }
 
-int git_odb__hashobj(git_oid *id, git_rawobj *obj)
+int git_odb__hashobj(git_oid *id, git_rawobj *obj, git_oid_t oid_type)
 {
 	git_str_vec vec[2];
 	char header[64];
 	size_t hdrlen;
+	git_hash_algorithm_t algorithm;
 	int error;
 
 	GIT_ASSERT_ARG(id);
@@ -120,6 +121,11 @@ int git_odb__hashobj(git_oid *id, git_rawobj *obj)
 		return -1;
 	}
 
+	if (!(algorithm = git_oid_algorithm(oid_type))) {
+		git_error_set(GIT_ERROR_INVALID, "unknown oid type");
+		return -1;
+	}
+
 	if (!obj->data && obj->len != 0) {
 		git_error_set(GIT_ERROR_INVALID, "invalid object");
 		return -1;
@@ -134,8 +140,8 @@ int git_odb__hashobj(git_oid *id, git_rawobj *obj)
 	vec[1].data = obj->data;
 	vec[1].len = obj->len;
 
-	id->type = GIT_OID_SHA1;
-	return git_hash_vec(id->id, vec, 2, GIT_HASH_ALGORITHM_SHA1);
+	id->type = oid_type;
+	return git_hash_vec(id->id, vec, 2, algorithm);
 }
 
 
@@ -196,24 +202,35 @@ void git_odb_object_free(git_odb_object *object)
 	git_cached_obj_decref(object);
 }
 
-int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_object_t type)
+int git_odb__hashfd(
+	git_oid *out,
+	git_file fd,
+	size_t size,
+	git_object_t object_type,
+	git_oid_t oid_type)
 {
 	size_t hdr_len;
 	char hdr[64], buffer[GIT_BUFSIZE_FILEIO];
 	git_hash_ctx ctx;
+	git_hash_algorithm_t algorithm;
 	ssize_t read_len = 0;
 	int error = 0;
 
-	if (!git_object_typeisloose(type)) {
+	if (!git_object_typeisloose(object_type)) {
 		git_error_set(GIT_ERROR_INVALID, "invalid object type for hash");
 		return -1;
 	}
 
-	if ((error = git_hash_ctx_init(&ctx, GIT_HASH_ALGORITHM_SHA1)) < 0)
+	if (!(algorithm = git_oid_algorithm(oid_type))) {
+		git_error_set(GIT_ERROR_INVALID, "unknown oid type");
+		return -1;
+	}
+
+	if ((error = git_hash_ctx_init(&ctx, algorithm)) < 0)
 		return error;
 
 	if ((error = git_odb__format_object_header(&hdr_len, hdr,
-		sizeof(hdr), size, type)) < 0)
+		sizeof(hdr), size, object_type)) < 0)
 		goto done;
 
 	if ((error = git_hash_update(&ctx, hdr, hdr_len)) < 0)
@@ -237,7 +254,7 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_object_t type)
 	}
 
 	error = git_hash_final(out->id, &ctx);
-	out->type = GIT_OID_SHA1;
+	out->type = oid_type;
 
 done:
 	git_hash_ctx_cleanup(&ctx);
@@ -245,13 +262,18 @@ done:
 }
 
 int git_odb__hashfd_filtered(
-	git_oid *out, git_file fd, size_t size, git_object_t type, git_filter_list *fl)
+	git_oid *out,
+	git_file fd,
+	size_t size,
+	git_object_t object_type,
+	git_oid_t oid_type,
+	git_filter_list *fl)
 {
 	int error;
 	git_str raw = GIT_STR_INIT;
 
 	if (!fl)
-		return git_odb__hashfd(out, fd, size, type);
+		return git_odb__hashfd(out, fd, size, object_type, oid_type);
 
 	/* size of data is used in header, so we have to read the whole file
 	 * into memory to apply filters before beginning to calculate the hash
@@ -263,7 +285,7 @@ int git_odb__hashfd_filtered(
 		error = git_filter_list__convert_buf(&post, fl, &raw);
 
 		if (!error)
-			error = git_odb_hash(out, post.ptr, post.size, type);
+			error = git_odb_hash(out, post.ptr, post.size, object_type, oid_type);
 
 		git_str_dispose(&post);
 	}
@@ -271,7 +293,7 @@ int git_odb__hashfd_filtered(
 	return error;
 }
 
-int git_odb__hashlink(git_oid *out, const char *path)
+int git_odb__hashlink(git_oid *out, const char *path, git_oid_t oid_type)
 {
 	struct stat st;
 	int size;
@@ -305,20 +327,24 @@ int git_odb__hashlink(git_oid *out, const char *path)
 		GIT_ASSERT(read_len <= size);
 		link_data[read_len] = '\0';
 
-		result = git_odb_hash(out, link_data, read_len, GIT_OBJECT_BLOB);
+		result = git_odb_hash(out, link_data, read_len, GIT_OBJECT_BLOB, oid_type);
 		git__free(link_data);
 	} else {
 		int fd = git_futils_open_ro(path);
 		if (fd < 0)
 			return -1;
-		result = git_odb__hashfd(out, fd, size, GIT_OBJECT_BLOB);
+		result = git_odb__hashfd(out, fd, size, GIT_OBJECT_BLOB, oid_type);
 		p_close(fd);
 	}
 
 	return result;
 }
 
-int git_odb_hashfile(git_oid *out, const char *path, git_object_t type)
+int git_odb_hashfile(
+	git_oid *out,
+	const char *path,
+	git_object_t object_type,
+	git_oid_t oid_type)
 {
 	uint64_t size;
 	int fd, error = 0;
@@ -335,14 +361,19 @@ int git_odb_hashfile(git_oid *out, const char *path, git_object_t type)
 		goto done;
 	}
 
-	error = git_odb__hashfd(out, fd, (size_t)size, type);
+	error = git_odb__hashfd(out, fd, (size_t)size, object_type, oid_type);
 
 done:
 	p_close(fd);
 	return error;
 }
 
-int git_odb_hash(git_oid *id, const void *data, size_t len, git_object_t type)
+int git_odb_hash(
+	git_oid *id,
+	const void *data,
+	size_t len,
+	git_object_t object_type,
+	git_oid_t oid_type)
 {
 	git_rawobj raw;
 
@@ -350,9 +381,9 @@ int git_odb_hash(git_oid *id, const void *data, size_t len, git_object_t type)
 
 	raw.data = (void *)data;
 	raw.len = len;
-	raw.type = type;
+	raw.type = object_type;
 
-	return git_odb__hashobj(id, &raw);
+	return git_odb__hashobj(id, &raw, oid_type);
 }
 
 /**
@@ -1181,8 +1212,11 @@ int git_odb__read_header_or_object(
 	return error;
 }
 
-static int odb_read_1(git_odb_object **out, git_odb *db, const git_oid *id,
-		bool only_refreshed)
+static int odb_read_1(
+	git_odb_object **out,
+	git_odb *db,
+	const git_oid *id,
+	bool only_refreshed)
 {
 	size_t i;
 	git_rawobj raw;
@@ -1226,7 +1260,7 @@ static int odb_read_1(git_odb_object **out, git_odb *db, const git_oid *id,
 		return GIT_ENOTFOUND;
 
 	if (git_odb__strict_hash_verification) {
-		if ((error = git_odb_hash(&hashed, raw.data, raw.len, raw.type)) < 0)
+		if ((error = git_odb_hash(&hashed, raw.data, raw.len, raw.type, GIT_OID_SHA1)) < 0)
 			goto out;
 
 		if (!git_oid_equal(id, &hashed)) {
@@ -1367,7 +1401,7 @@ static int read_prefix_1(git_odb_object **out, git_odb *db,
 	if (git_odb__strict_hash_verification) {
 		git_oid hash;
 
-		if ((error = git_odb_hash(&hash, raw.data, raw.len, raw.type)) < 0)
+		if ((error = git_odb_hash(&hash, raw.data, raw.len, raw.type, GIT_OID_SHA1)) < 0)
 			goto out;
 
 		if (!git_oid_equal(&found_full_oid, &hash)) {
@@ -1466,7 +1500,7 @@ int git_odb_write(
 	GIT_ASSERT_ARG(oid);
 	GIT_ASSERT_ARG(db);
 
-	if ((error = git_odb_hash(oid, data, len, type)) < 0)
+	if ((error = git_odb_hash(oid, data, len, type, GIT_OID_SHA1)) < 0)
 		return error;
 
 	if (git_oid_is_zero(oid))
@@ -1568,7 +1602,7 @@ int git_odb_open_wstream(
 	GIT_ERROR_CHECK_ALLOC(ctx);
 
 	if ((error = git_hash_ctx_init(ctx, GIT_HASH_ALGORITHM_SHA1)) < 0 ||
-		(error = hash_header(ctx, size, type)) < 0)
+	    (error = hash_header(ctx, size, type)) < 0)
 		goto done;
 
 	(*stream)->hash_ctx = ctx;
@@ -1790,10 +1824,11 @@ int git_odb_refresh(struct git_odb *db)
 
 int git_odb__error_mismatch(const git_oid *expected, const git_oid *actual)
 {
-	char expected_oid[GIT_OID_SHA1_HEXSIZE + 1], actual_oid[GIT_OID_SHA1_HEXSIZE + 1];
+	char expected_oid[GIT_OID_MAX_HEXSIZE + 1],
+	     actual_oid[GIT_OID_MAX_HEXSIZE + 1];
 
-	git_oid_tostr(expected_oid, sizeof(expected_oid), expected);
-	git_oid_tostr(actual_oid, sizeof(actual_oid), actual);
+	git_oid_tostr(expected_oid, git_oid_hexsize(expected->type) + 1, expected);
+	git_oid_tostr(actual_oid, git_oid_hexsize(actual->type) + 1, actual);
 
 	git_error_set(GIT_ERROR_ODB, "object hash mismatch - expected %s but got %s",
 		expected_oid, actual_oid);
@@ -1805,7 +1840,7 @@ int git_odb__error_notfound(
 	const char *message, const git_oid *oid, size_t oid_len)
 {
 	if (oid != NULL) {
-		char oid_str[GIT_OID_SHA1_HEXSIZE + 1];
+		char oid_str[GIT_OID_MAX_HEXSIZE + 1];
 		git_oid_tostr(oid_str, oid_len+1, oid);
 		git_error_set(GIT_ERROR_ODB, "object not found - %s (%.*s)",
 			message, (int) oid_len, oid_str);
@@ -1823,7 +1858,7 @@ static int error_null_oid(int error, const char *message)
 
 int git_odb__error_ambiguous(const char *message)
 {
-	git_error_set(GIT_ERROR_ODB, "ambiguous SHA1 prefix - %s", message);
+	git_error_set(GIT_ERROR_ODB, "ambiguous OID prefix - %s", message);
 	return GIT_EAMBIGUOUS;
 }
 
diff --git a/src/libgit2/odb.h b/src/libgit2/odb.h
index 5aa4cc8..c85fa67 100644
--- a/src/libgit2/odb.h
+++ b/src/libgit2/odb.h
@@ -72,7 +72,7 @@ int git_odb__add_default_backends(
  * Hash a git_rawobj internally.
  * The `git_rawobj` is supposed to be previously initialized
  */
-int git_odb__hashobj(git_oid *id, git_rawobj *obj);
+int git_odb__hashobj(git_oid *id, git_rawobj *obj, git_oid_t oid_type);
 
 /*
  * Format the object header such as it would appear in the on-disk object
@@ -89,14 +89,24 @@ int git_odb__format_object_header(size_t *out_len, char *hdr, size_t hdr_size, g
  * The fd is never closed, not even on error. It must be opened and closed
  * by the caller
  */
-int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_object_t type);
+int git_odb__hashfd(
+	git_oid *out,
+	git_file fd,
+	size_t size,
+	git_object_t object_type,
+	git_oid_t oid_type);
 
 /*
  * Hash an open file descriptor applying an array of filters
  * Acts just like git_odb__hashfd with the addition of filters...
  */
 int git_odb__hashfd_filtered(
-	git_oid *out, git_file fd, size_t len, git_object_t type, git_filter_list *fl);
+	git_oid *out,
+	git_file fd,
+	size_t len,
+	git_object_t object_type,
+	git_oid_t oid_type,
+	git_filter_list *fl);
 
 /*
  * Hash a `path`, assuming it could be a POSIX symlink: if the path is a
@@ -106,7 +116,7 @@ int git_odb__hashfd_filtered(
  * The hash type for this call is always `GIT_OBJECT_BLOB` because
  * symlinks may only point to blobs.
  */
-int git_odb__hashlink(git_oid *out, const char *path);
+int git_odb__hashlink(git_oid *out, const char *path, git_oid_t oid_type);
 
 /**
  * Generate a GIT_EMISMATCH error for the ODB.
diff --git a/src/libgit2/reader.c b/src/libgit2/reader.c
index ba97752..0ff9c89 100644
--- a/src/libgit2/reader.c
+++ b/src/libgit2/reader.c
@@ -125,7 +125,7 @@ static int workdir_reader_read(
 		goto done;
 
 	if (out_id || reader->index) {
-		if ((error = git_odb_hash(&id, out->ptr, out->size, GIT_OBJECT_BLOB)) < 0)
+		if ((error = git_odb_hash(&id, out->ptr, out->size, GIT_OBJECT_BLOB, GIT_OID_SHA1)) < 0)
 			goto done;
 	}
 
diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c
index 1312ccc..adff425 100644
--- a/src/libgit2/repository.c
+++ b/src/libgit2/repository.c
@@ -2986,7 +2986,7 @@ int git_repository_hashfile(
 		goto cleanup;
 	}
 
-	error = git_odb__hashfd_filtered(out, fd, (size_t)len, type, fl);
+	error = git_odb__hashfd_filtered(out, fd, (size_t)len, type, GIT_OID_SHA1, fl);
 
 cleanup:
 	if (fd >= 0)
diff --git a/tests/libgit2/checkout/binaryunicode.c b/tests/libgit2/checkout/binaryunicode.c
index 255b6e0..ea2f527 100644
--- a/tests/libgit2/checkout/binaryunicode.c
+++ b/tests/libgit2/checkout/binaryunicode.c
@@ -36,12 +36,12 @@ static void execute_test(void)
 
 	/* Verify that the lenna.jpg file was checked out correctly */
 	cl_git_pass(git_oid_fromstr(&check, "8ab005d890fe53f65eda14b23672f60d9f4ec5a1", GIT_OID_SHA1));
-	cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/lenna.jpg", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/lenna.jpg", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_assert_equal_oid(&oid, &check);
 
 	/* Verify that the text file was checked out correctly */
 	cl_git_pass(git_oid_fromstr(&check, "965b223880dd4249e2c66a0cc0b4cffe1dc40f5a", GIT_OID_SHA1));
-	cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/utf16_withbom_noeol_crlf.txt", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/utf16_withbom_noeol_crlf.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_assert_equal_oid(&oid, &check);
 }
 
diff --git a/tests/libgit2/object/raw/hash.c b/tests/libgit2/object/raw/hash.c
index 28bfb1d..e0d3d95 100644
--- a/tests/libgit2/object/raw/hash.c
+++ b/tests/libgit2/object/raw/hash.c
@@ -8,11 +8,11 @@
 
 static void hash_object_pass(git_oid *oid, git_rawobj *obj)
 {
-	cl_git_pass(git_odb_hash(oid, obj->data, obj->len, obj->type));
+	cl_git_pass(git_odb_hash(oid, obj->data, obj->len, obj->type, GIT_OID_SHA1));
 }
 static void hash_object_fail(git_oid *oid, git_rawobj *obj)
 {
-	cl_git_fail(git_odb_hash(oid, obj->data, obj->len, obj->type));
+	cl_git_fail(git_odb_hash(oid, obj->data, obj->len, obj->type, GIT_OID_SHA1));
 }
 
 static char *hello_id = "22596363b3de40b06f981fb85d82312e8c0ed511";
diff --git a/tests/libgit2/repo/hashfile.c b/tests/libgit2/repo/hashfile.c
index e23bb77..f835439 100644
--- a/tests/libgit2/repo/hashfile.c
+++ b/tests/libgit2/repo/hashfile.c
@@ -20,19 +20,19 @@ void test_repo_hashfile__simple(void)
 	git_str full = GIT_STR_INIT;
 
 	/* hash with repo relative path */
-	cl_git_pass(git_odb_hashfile(&a, "status/current_file", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "status/current_file", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, "current_file", GIT_OBJECT_BLOB, NULL));
 	cl_assert_equal_oid(&a, &b);
 
 	cl_git_pass(git_str_joinpath(&full, git_repository_workdir(_repo), "current_file"));
 
 	/* hash with full path */
-	cl_git_pass(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJECT_BLOB, NULL));
 	cl_assert_equal_oid(&a, &b);
 
 	/* hash with invalid type */
-	cl_git_fail(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_ANY));
+	cl_git_fail(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_ANY, GIT_OID_SHA1));
 	cl_git_fail(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJECT_OFS_DELTA, NULL));
 
 	git_str_dispose(&full);
@@ -59,64 +59,64 @@ void test_repo_hashfile__filtered_in_workdir(void)
 	cl_git_mkfile("status/testfile.bin", "other\r\nstuff\r\n");
 
 	/* not equal hashes because of filtering */
-	cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_BLOB, NULL));
 	cl_assert(git_oid_cmp(&a, &b));
 
 	/* not equal hashes because of filtering when specified by absolute path */
-	cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, NULL));
 	cl_assert(git_oid_cmp(&a, &b));
 
 	/* equal hashes because filter is binary */
-	cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJECT_BLOB, NULL));
 	cl_assert_equal_oid(&a, &b);
 
 	/* equal hashes because filter is binary when specified by absolute path */
-	cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, NULL));
 	cl_assert_equal_oid(&a, &b);
 
 	/* equal hashes when 'as_file' points to binary filtering */
-	cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_BLOB, "foo.bin"));
 	cl_assert_equal_oid(&a, &b);
 
 	/* equal hashes when 'as_file' points to binary filtering (absolute path) */
-	cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, "foo.bin"));
 	cl_assert_equal_oid(&a, &b);
 
 	/* not equal hashes when 'as_file' points to text filtering */
-	cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJECT_BLOB, "foo.txt"));
 	cl_assert(git_oid_cmp(&a, &b));
 
 	/* not equal hashes when 'as_file' points to text filtering */
-	cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, "foo.txt"));
 	cl_assert(git_oid_cmp(&a, &b));
 
 	/* equal hashes when 'as_file' is empty and turns off filtering */
-	cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_BLOB, ""));
 	cl_assert_equal_oid(&a, &b);
 
-	cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJECT_BLOB, ""));
 	cl_assert_equal_oid(&a, &b);
 
-	cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, ""));
 	cl_assert_equal_oid(&a, &b);
 
-	cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, ""));
 	cl_assert_equal_oid(&a, &b);
 
 	/* some hash type failures */
-	cl_git_fail(git_odb_hashfile(&a, "status/testfile.txt", 0));
+	cl_git_fail(git_odb_hashfile(&a, "status/testfile.txt", 0, GIT_OID_SHA1));
 	cl_git_fail(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_ANY, NULL));
 
 	git_str_dispose(&txt);
@@ -144,12 +144,12 @@ void test_repo_hashfile__filtered_outside_workdir(void)
 	cl_git_mkfile("absolute/testfile.bin", "other\r\nstuff\r\n");
 
 	/* not equal hashes because of filtering */
-	cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.txt", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, "testfile.txt"));
 	cl_assert(git_oid_cmp(&a, &b));
 
 	/* equal hashes because filter is binary */
-	cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.bin", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, "testfile.bin"));
 	cl_assert_equal_oid(&a, &b);
 
@@ -157,11 +157,11 @@ void test_repo_hashfile__filtered_outside_workdir(void)
 	 * equal hashes because no filtering occurs for absolute paths outside the working
 	 * directory unless as_path is specified
 	 */
-	cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.txt", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, NULL));
 	cl_assert_equal_oid(&a, &b);
 
-	cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.bin", GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, NULL));
 	cl_assert_equal_oid(&a, &b);
 
diff --git a/tests/libgit2/status/single.c b/tests/libgit2/status/single.c
index a95d3d0..dfba8f4 100644
--- a/tests/libgit2/status/single.c
+++ b/tests/libgit2/status/single.c
@@ -21,7 +21,7 @@ void test_status_single__hash_single_file(void)
 	cl_git_mkfile(file_name, file_contents);
 	cl_set_cleanup(&cleanup__remove_file, (void *)file_name);
 
-	cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_assert_equal_oid(&expected_id, &actual_id);
 }
 
@@ -39,7 +39,7 @@ void test_status_single__hash_single_empty_file(void)
 	cl_git_mkfile(file_name, file_contents);
 	cl_set_cleanup(&cleanup__remove_file, (void *)file_name);
 
-	cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJECT_BLOB));
+	cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJECT_BLOB, GIT_OID_SHA1));
 	cl_assert_equal_oid(&expected_id, &actual_id);
 }