Skip to content

Commit d6222a2

Browse files
ebiedermgitster
authored andcommitted
builtin/cat-file: let the oid determine the output algorithm
Use GET_OID_HASH_ANY when calling get_oid_with_context. This implements the semi-obvious behaviour that specifying a sha1 oid shows the output for a sha1 encoded object, and specifying a sha256 oid shows the output for a sha256 encoded object. This is useful for testing the the conversion of an object to an equivalent object encoded with a different hash function. Signed-off-by: "Eric W. Biederman" <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d7446c8 commit d6222a2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

builtin/cat-file.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
107107
struct object_info oi = OBJECT_INFO_INIT;
108108
struct strbuf sb = STRBUF_INIT;
109109
unsigned flags = OBJECT_INFO_LOOKUP_REPLACE;
110-
unsigned get_oid_flags = GET_OID_RECORD_PATH | GET_OID_ONLY_TO_DIE;
110+
unsigned get_oid_flags =
111+
GET_OID_RECORD_PATH |
112+
GET_OID_ONLY_TO_DIE |
113+
GET_OID_HASH_ANY;
111114
const char *path = force_path;
112115
const int opt_cw = (opt == 'c' || opt == 'w');
113116
if (!path && opt_cw)
@@ -223,7 +226,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
223226
&size);
224227
const char *target;
225228
if (!skip_prefix(buffer, "object ", &target) ||
226-
get_oid_hex(target, &blob_oid))
229+
get_oid_hex_algop(target, &blob_oid,
230+
&hash_algos[oid.algo]))
227231
die("%s not a valid tag", oid_to_hex(&oid));
228232
free(buffer);
229233
} else
@@ -512,7 +516,9 @@ static void batch_one_object(const char *obj_name,
512516
struct expand_data *data)
513517
{
514518
struct object_context ctx;
515-
int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0;
519+
int flags =
520+
GET_OID_HASH_ANY |
521+
(opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0);
516522
enum get_oid_result result;
517523

518524
result = get_oid_with_context(the_repository, obj_name,

0 commit comments

Comments
 (0)