mirror of
https://github.com/git/git
synced 2024-11-04 16:17:49 +00:00
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>
This commit is contained in:
parent
d7446c89b8
commit
d6222a2d05
1 changed files with 9 additions and 3 deletions
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue