mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
cat-file: split batch_one_object into two stages
There are really two things going on in this function: 1. We convert the name we got on stdin to a sha1. 2. We look up and print information on the sha1. Let's split out the second half so that we can call it separately. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
82330950d9
commit
44b877e9bc
|
@ -251,10 +251,31 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
|
|||
}
|
||||
}
|
||||
|
||||
static void batch_object_write(const char *obj_name, struct batch_options *opt,
|
||||
struct expand_data *data)
|
||||
{
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
|
||||
if (sha1_object_info_extended(data->sha1, &data->info, LOOKUP_REPLACE_OBJECT) < 0) {
|
||||
printf("%s missing\n", obj_name);
|
||||
fflush(stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
strbuf_expand(&buf, opt->format, expand_format, data);
|
||||
strbuf_addch(&buf, '\n');
|
||||
batch_write(opt, buf.buf, buf.len);
|
||||
strbuf_release(&buf);
|
||||
|
||||
if (opt->print_contents) {
|
||||
print_object_or_die(opt, data);
|
||||
batch_write(opt, "\n", 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void batch_one_object(const char *obj_name, struct batch_options *opt,
|
||||
struct expand_data *data)
|
||||
{
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
struct object_context ctx;
|
||||
int flags = opt->follow_symlinks ? GET_SHA1_FOLLOW_SYMLINKS : 0;
|
||||
enum follow_symlinks_result result;
|
||||
|
@ -294,21 +315,7 @@ static void batch_one_object(const char *obj_name, struct batch_options *opt,
|
|||
return;
|
||||
}
|
||||
|
||||
if (sha1_object_info_extended(data->sha1, &data->info, LOOKUP_REPLACE_OBJECT) < 0) {
|
||||
printf("%s missing\n", obj_name);
|
||||
fflush(stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
strbuf_expand(&buf, opt->format, expand_format, data);
|
||||
strbuf_addch(&buf, '\n');
|
||||
batch_write(opt, buf.buf, buf.len);
|
||||
strbuf_release(&buf);
|
||||
|
||||
if (opt->print_contents) {
|
||||
print_object_or_die(opt, data);
|
||||
batch_write(opt, "\n", 1);
|
||||
}
|
||||
batch_object_write(obj_name, opt, data);
|
||||
}
|
||||
|
||||
static int batch_objects(struct batch_options *opt)
|
||||
|
|
Loading…
Reference in a new issue