From mboxrd@z Thu Jan 1 00:00:00 1970 From: Junio C Hamano Subject: [PATCH v3 04/19] apply: refactor read_file_or_gitlink() Date: Wed, 13 Jun 2012 12:32:45 -0700 Message-ID: <1339615980-19727-5-git-send-email-gitster@pobox.com> References: <1339615980-19727-1-git-send-email-gitster@pobox.com> To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Wed Jun 13 21:34:10 2012 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SetKT-0001oS-Nr for gcvg-git-2@plane.gmane.org; Wed, 13 Jun 2012 21:34:10 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754757Ab2FMTdN (ORCPT ); Wed, 13 Jun 2012 15:33:13 -0400 Received: from b-pb-sasl-quonix.pobox.com ([208.72.237.35]:65351 "EHLO smtp.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754744Ab2FMTdL (ORCPT ); Wed, 13 Jun 2012 15:33:11 -0400 Received: from smtp.pobox.com (unknown [127.0.0.1]) by b-sasl-quonix.pobox.com (Postfix) with ESMTP id BA01D86FA for ; Wed, 13 Jun 2012 15:33:10 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references; s=sasl; bh=qbeR s+Wr1wOv+r497tnqFfncBYI=; b=NneooQYrZLYen238AhIbwaZDRBXfXjpWMNN5 g0as4zPeQ9xdse+h10RMi0Lw/5rvP/pFsk7jAVQvgiTajjT1PbHs1j4Phtebbu+p l9b8pEJOGkGHjj0yqybOpf1yagHnXC6D4XRuI0/aeYJWLg4BRe30D36JvKbYYD+3 sex8BS0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references; q=dns; s=sasl; b=ooJNrx qI3mx/lfyLJYa+N1QydKuhPRRspcSCjoWaZz9bx1O6brKAkE6ZxCHBed8Xys9oZK CoZTzKaCDYPmjxKdpWFCLVEzLc6eGrhnq4XoN6ZilVGIU7LAvxnxOXLbPgdLqsTH AFUsDSW93xUWqNyS7rqlllXJmuTl0/I04BywM= Received: from b-pb-sasl-quonix.pobox.com (unknown [127.0.0.1]) by b-sasl-quonix.pobox.com (Postfix) with ESMTP id 9CDE886F8 for ; Wed, 13 Jun 2012 15:33:10 -0400 (EDT) Received: from pobox.com (unknown [98.234.214.94]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by b-sasl-quonix.pobox.com (Postfix) with ESMTPSA id 25A3B86F7 for ; Wed, 13 Jun 2012 15:33:10 -0400 (EDT) X-Mailer: git-send-email 1.7.11.rc3.30.g3bdace2 In-Reply-To: <1339615980-19727-1-git-send-email-gitster@pobox.com> X-Pobox-Relay-ID: 9BCC1934-B58E-11E1-AC26-FC762E706CDE-77302942!b-pb-sasl-quonix.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Reading a blob out of the object store does not have to require that the caller has a cache entry for it. Create a read_blob_object() helper function that takes the object name and mode, and use it to reimplement the original function as a thin wrapper to it. Signed-off-by: Junio C Hamano --- builtin/apply.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index e2b0942..3199691 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -2930,20 +2930,17 @@ static int apply_fragments(struct image *img, struct patch *patch) return 0; } -static int read_file_or_gitlink(struct cache_entry *ce, struct strbuf *buf) +static int read_blob_object(struct strbuf *buf, const unsigned char *sha1, unsigned mode) { - if (!ce) - return 0; - - if (S_ISGITLINK(ce->ce_mode)) { + if (S_ISGITLINK(mode)) { strbuf_grow(buf, 100); - strbuf_addf(buf, "Subproject commit %s\n", sha1_to_hex(ce->sha1)); + strbuf_addf(buf, "Subproject commit %s\n", sha1_to_hex(sha1)); } else { enum object_type type; unsigned long sz; char *result; - result = read_sha1_file(ce->sha1, &type, &sz); + result = read_sha1_file(sha1, &type, &sz); if (!result) return -1; /* XXX read_sha1_file NUL-terminates */ @@ -2952,6 +2949,13 @@ static int read_file_or_gitlink(struct cache_entry *ce, struct strbuf *buf) return 0; } +static int read_file_or_gitlink(struct cache_entry *ce, struct strbuf *buf) +{ + if (!ce) + return 0; + return read_blob_object(buf, ce->sha1, ce->ce_mode); +} + static struct patch *in_fn_table(const char *name) { struct string_list_item *item; -- 1.7.11.rc3.30.g3bdace2