Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 370c926

Browse files
peffgitster
authored andcommitted
cat-file: pass expand_data to print_object_or_die
We currently individually pass the sha1, type, and size fields calculated by sha1_object_info. However, if we pass the whole struct, the called function can make more intelligent decisions about which fields were actually filled by sha1_object_info. This patch takes that first refactoring step, passing the whole struct, so further patches can make those decisions with less noise in their diffs. There should be no functional change to this patch (aside from a minor typo fix in the error message). As a side effect, we can rename the local variables in the function to "type" and "size", since the names are no longer taken. Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d2446df commit 370c926

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

builtin/cat-file.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,25 +193,26 @@ static size_t expand_format(struct strbuf *sb, const char *start, void *data)
193193
return end - start + 1;
194194
}
195195

196-
static void print_object_or_die(int fd, const unsigned char *sha1,
197-
enum object_type type, unsigned long size)
196+
static void print_object_or_die(int fd, struct expand_data *data)
198197
{
199-
if (type == OBJ_BLOB) {
198+
const unsigned char *sha1 = data->sha1;
199+
200+
if (data->type == OBJ_BLOB) {
200201
if (stream_blob_to_fd(fd, sha1, NULL, 0) < 0)
201202
die("unable to stream %s to stdout", sha1_to_hex(sha1));
202203
}
203204
else {
204-
enum object_type rtype;
205-
unsigned long rsize;
205+
enum object_type type;
206+
unsigned long size;
206207
void *contents;
207208

208-
contents = read_sha1_file(sha1, &rtype, &rsize);
209+
contents = read_sha1_file(sha1, &type, &size);
209210
if (!contents)
210211
die("object %s disappeared", sha1_to_hex(sha1));
211-
if (rtype != type)
212+
if (type != data->type)
212213
die("object %s changed type!?", sha1_to_hex(sha1));
213-
if (rsize != size)
214-
die("object %s change size!?", sha1_to_hex(sha1));
214+
if (size != data->size)
215+
die("object %s changed size!?", sha1_to_hex(sha1));
215216

216217
write_or_die(fd, contents, size);
217218
free(contents);
@@ -250,7 +251,7 @@ static int batch_one_object(const char *obj_name, struct batch_options *opt,
250251
strbuf_release(&buf);
251252

252253
if (opt->print_contents) {
253-
print_object_or_die(1, data->sha1, data->type, data->size);
254+
print_object_or_die(1, data);
254255
write_or_die(1, "\n", 1);
255256
}
256257
return 0;

0 commit comments

Comments
 (0)