git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Samuel Bronson <naesten@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	git@vger.kernel.org, Jonathan Nieder <jrnieder@gmail.com>
Subject: [PATCH 1/2] cat-file: pass expand_data to print_object_or_die
Date: Wed, 11 Dec 2013 19:56:45 +0800	[thread overview]
Message-ID: <20131211115642.GA10594@sigill.intra.peff.net> (raw)
In-Reply-To: <20131211115458.GA10561@sigill.intra.peff.net>

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 actualled
filled by sha1_object_info.

As a side effect, we can rename the local variables in the
function to "type" and "size", since the names are no longer
taken.

There should be no functional change to this patch.

Signed-off-by: Jeff King <peff@peff.net>
---
I split this out mostly to keep the noise out of the follow-on diff.

 builtin/cat-file.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index b2ca775..1434afb 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -193,25 +193,26 @@ static size_t expand_format(struct strbuf *sb, const char *start, void *data)
 	return end - start + 1;
 }
 
-static void print_object_or_die(int fd, const unsigned char *sha1,
-				enum object_type type, unsigned long size)
+static void print_object_or_die(int fd, struct expand_data *data)
 {
-	if (type == OBJ_BLOB) {
+	const unsigned char *sha1 = data->sha1;
+
+	if (data->type == OBJ_BLOB) {
 		if (stream_blob_to_fd(fd, sha1, NULL, 0) < 0)
 			die("unable to stream %s to stdout", sha1_to_hex(sha1));
 	}
 	else {
-		enum object_type rtype;
-		unsigned long rsize;
+		enum object_type type;
+		unsigned long size;
 		void *contents;
 
-		contents = read_sha1_file(sha1, &rtype, &rsize);
+		contents = read_sha1_file(sha1, &type, &size);
 		if (!contents)
 			die("object %s disappeared", sha1_to_hex(sha1));
-		if (rtype != type)
+		if (type != data->type)
 			die("object %s changed type!?", sha1_to_hex(sha1));
-		if (rsize != size)
-			die("object %s change size!?", sha1_to_hex(sha1));
+		if (size != data->size)
+			die("object %s changed size!?", sha1_to_hex(sha1));
 
 		write_or_die(fd, contents, size);
 		free(contents);
@@ -250,7 +251,7 @@ static int batch_one_object(const char *obj_name, struct batch_options *opt,
 	strbuf_release(&buf);
 
 	if (opt->print_contents) {
-		print_object_or_die(1, data->sha1, data->type, data->size);
+		print_object_or_die(1, data);
 		write_or_die(1, "\n", 1);
 	}
 	return 0;
-- 
1.8.5.524.g6743da6

  reply	other threads:[~2013-12-11 11:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-11  4:37 [BUG] "echo HEAD | git cat-file --batch=''" fails catastrophically Samuel Bronson
2013-12-11 11:54 ` Jeff King
2013-12-11 11:56   ` Jeff King [this message]
2013-12-11 20:11     ` [PATCH 1/2] cat-file: pass expand_data to print_object_or_die Jonathan Nieder
2013-12-11 23:01       ` Jeff King
2013-12-12  3:03         ` Junio C Hamano
2013-12-11 11:58   ` [PATCH 2/2] cat-file: handle --batch format with missing type/size Jeff King
2013-12-11 20:42     ` Jonathan Nieder
2013-12-11 23:15       ` Jeff King
2013-12-11 23:31         ` Jonathan Nieder
2013-12-12  3:05         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131211115642.GA10594@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=naesten@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).