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>
Jeff King committed
Jun 22, 2015 at 06:45 UTC
44b877e9bc944258db096a0ec57151be7c8cbf66
1 file changed
+23
-16
builtin/cat-file.c
+23
-16
@@ -251,10 +251,31 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
251
}
252
}
253
254
+static void batch_object_write(const char *obj_name, struct batch_options *opt,
255
+ struct expand_data *data)
256
+{
257
+ struct strbuf buf = STRBUF_INIT;
258
+
259
+ if (sha1_object_info_extended(data->sha1, &data->info, LOOKUP_REPLACE_OBJECT) < 0) {
260
+ printf("%s missing\n", obj_name);
261
+ fflush(stdout);
262
+ return;
263
+ }
264
+
265
+ strbuf_expand(&buf, opt->format, expand_format, data);
266
+ strbuf_addch(&buf, '\n');
267
+ batch_write(opt, buf.buf, buf.len);
268
+ strbuf_release(&buf);
269
+
270
+ if (opt->print_contents) {
271
+ print_object_or_die(opt, data);
272
+ batch_write(opt, "\n", 1);
273
+ }
274
+}
275
+
276
static void batch_one_object(const char *obj_name, struct batch_options *opt,
277
struct expand_data *data)
278
{
257
- struct strbuf buf = STRBUF_INIT;
279
struct object_context ctx;
280
int flags = opt->follow_symlinks ? GET_SHA1_FOLLOW_SYMLINKS : 0;
281
enum follow_symlinks_result result;
@@ -294,21 +315,7 @@ static void batch_one_object(const char *obj_name, struct batch_options *opt,
315
return;
316
}
317
297
- if (sha1_object_info_extended(data->sha1, &data->info, LOOKUP_REPLACE_OBJECT) < 0) {
298
- printf("%s missing\n", obj_name);
299
- fflush(stdout);
300
- return;
301
- }
302
-
303
- strbuf_expand(&buf, opt->format, expand_format, data);
304
- strbuf_addch(&buf, '\n');
305
- batch_write(opt, buf.buf, buf.len);
306
- strbuf_release(&buf);
307
-
308
- if (opt->print_contents) {
309
- print_object_or_die(opt, data);
310
- batch_write(opt, "\n", 1);
311
- }
318
+ batch_object_write(obj_name, opt, data);
319
}
320
321
static int batch_objects(struct batch_options *opt)