diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2023-10-02 02:40:27 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-10-02 21:57:40 (GMT) |
commit | d6222a2d05c93b22d5ef19b7361f7b1ef2964eb4 (patch) | |
tree | 3ea25fc1bc7bdb7191b92cf17540651d663da9e4 | |
parent | d7446c89b8ed57f1fa0a5b2ea5e4b7e5fcb7d9cd (diff) | |
download | git-d6222a2d05c93b22d5ef19b7361f7b1ef2964eb4.zip git-d6222a2d05c93b22d5ef19b7361f7b1ef2964eb4.tar.gz git-d6222a2d05c93b22d5ef19b7361f7b1ef2964eb4.tar.bz2 |
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" <ebiederm@xmission.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | builtin/cat-file.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 694c853..e615d1f 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -107,7 +107,10 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, struct object_info oi = OBJECT_INFO_INIT; struct strbuf sb = STRBUF_INIT; unsigned flags = OBJECT_INFO_LOOKUP_REPLACE; - unsigned get_oid_flags = GET_OID_RECORD_PATH | GET_OID_ONLY_TO_DIE; + unsigned get_oid_flags = + GET_OID_RECORD_PATH | + GET_OID_ONLY_TO_DIE | + GET_OID_HASH_ANY; const char *path = force_path; const int opt_cw = (opt == 'c' || opt == 'w'); if (!path && opt_cw) @@ -223,7 +226,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, &size); const char *target; if (!skip_prefix(buffer, "object ", &target) || - get_oid_hex(target, &blob_oid)) + get_oid_hex_algop(target, &blob_oid, + &hash_algos[oid.algo])) die("%s not a valid tag", oid_to_hex(&oid)); free(buffer); } else @@ -512,7 +516,9 @@ static void batch_one_object(const char *obj_name, struct expand_data *data) { struct object_context ctx; - int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0; + int flags = + GET_OID_HASH_ANY | + (opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0); enum get_oid_result result; result = get_oid_with_context(the_repository, obj_name, |