public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Karthik Nayak <karthik.188@gmail•com>
Cc: git@vger•kernel.org
Subject: Re: [PATCH v2 2/3] sha1_file: implement changes for "cat-file --literally -t"
Date: Wed, 04 Mar 2015 12:58:23 -0800	[thread overview]
Message-ID: <xmqqy4nc7a4w.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1425377556-25332-1-git-send-email-karthik.188@gmail.com> (Karthik Nayak's message of "Tue, 3 Mar 2015 15:42:36 +0530")

Karthik Nayak <karthik.188@gmail•com> writes:

> add "sha1_object_info_literally()" which is to be used when
> the "literally" option is given to get the type of object
> and print it, using "sha1_object_info_extended()".
>
> add "unpack_sha1_header_literally()" to unpack sha headers
> which may be greater than 32 bytes, which is the threshold
> for a regular object header.
>
> modify "sha1_loose_object_info()" to include a flag argument
> and also include changes to call "unpack_sha1_header_literally()"
> when the literally flag is passed. Also copies the obtained
> type to the typename field of object_info.
>
> modify "sha1_object_info_extended()" to call the function
> "sha1_loose_object_info()" with flags.
>
> Signed-off-by: Karthik Nayak <karthik.188@gmail•com>
> ---
>  sha1_file.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 77 insertions(+), 7 deletions(-)
>
> diff --git a/sha1_file.c b/sha1_file.c
> index 69a60ec..1068ca0 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -1564,6 +1564,36 @@ int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long ma
>  	return git_inflate(stream, 0);
>  }
>  
> +static int unpack_sha1_header_literally(git_zstream *stream, unsigned char *map,
> +					unsigned long mapsize,
> +					struct strbuf *header)
> +{
> +...
> +}

Looks suspiciously familiar...

> +int sha1_object_info_literally(const unsigned char *sha1)
> +{
> +	enum object_type type;
> +	struct strbuf sb = STRBUF_INIT;
> +	struct object_info oi = {NULL};
> +
> +	oi.typename = &sb;
> +	oi.typep = &type;
> +	if (sha1_object_info_extended(sha1, &oi, LOOKUP_LITERALLY) < 0)
> +		return -1;
> +	if (*oi.typep > 0)
> +		printf("%s\n", typename(*oi.typep));
> +	else
> +		printf("%s\n", oi.typename->buf);
> +	strbuf_release(oi.typename);
> +	return 0;
> +}
> +

NAK.

Please don't add end-user facing final output to sha1_file.c;
instead have the caller use a helper function like this one to
extract necessary information and perform the end-user interaction
there.

  reply	other threads:[~2015-03-04 20:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-03 10:10 [PATCH v2 0/3] cat-file: add "--literally" option karthik nayak
2015-03-03 10:11 ` [PATCH v2 1/3] cache: modify for "cat-file --literally -t" Karthik Nayak
2015-03-03 10:12 ` [PATCH v2 2/3] sha1_file: implement changes " Karthik Nayak
2015-03-04 20:58   ` Junio C Hamano [this message]
2015-03-05  1:26     ` karthik nayak
2015-03-05  6:25       ` Junio C Hamano
2015-03-03 10:13 ` [PATCH v2 3/3] cat-file: add "--literally" option Karthik Nayak

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=xmqqy4nc7a4w.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=karthik.188@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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