From: Karthik Nayak <karthik.188@gmail.com>
To: git@vger.kernel.org
Cc: Karthik Nayak <karthik.188@gmail.com>
Subject: [PATCH 1/2] sha1_file: Add sha1_object_type_literally and export it.
Date: Wed, 25 Feb 2015 16:37:40 +0530 [thread overview]
Message-ID: <1424862460-13514-1-git-send-email-karthik.188@gmail.com> (raw)
In-Reply-To: <54EDACC9.5080204@gmail.com>
sha1_object_type_literally takes a sha value and
gives the type of the given loose object, used by
git cat-file -t --literally.
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
cache.h | 1 +
sha1_file.c | 27 +++++++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/cache.h b/cache.h
index 4d02efc..48086b9 100644
--- a/cache.h
+++ b/cache.h
@@ -872,6 +872,7 @@ extern int git_open_noatime(const char *name);
extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size);
extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
extern int parse_sha1_header(const char *hdr, unsigned long *sizep);
+extern int sha1_object_type_literally(const unsigned char *sha1, char *type);
/* global flag to enable extra checks when accessing packed objects */
extern int do_check_packed_object_crc;
diff --git a/sha1_file.c b/sha1_file.c
index 69a60ec..34b4810 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2635,6 +2635,33 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
return type;
}
+int sha1_object_type_literally(const unsigned char *sha1, char *type)
+{
+ int status = 0;
+ unsigned long mapsize;
+ void *map;
+ git_zstream stream;
+ char hdr[32];
+ int i;
+
+ map = map_sha1_file(sha1, &mapsize);
+ if (!map)
+ return -1;
+ if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
+ status = error("unable to unpack %s header",
+ sha1_to_hex(sha1));
+
+ for (i = 0; i < 32; i++) {
+ if (hdr[i] == ' ') {
+ type[i] = '\0';
+ break;
+ }
+ type[i] = hdr[i];
+ }
+
+ return status;
+}
+
static void *read_packed_sha1(const unsigned char *sha1,
enum object_type *type, unsigned long *size)
{
--
2.3.1.129.g11acff1.dirty
next prev parent reply other threads:[~2015-02-25 11:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-25 11:06 [PATCH 0/2] cat-file --literally karthik nayak
2015-02-25 11:07 ` Karthik Nayak [this message]
2015-02-25 18:22 ` [PATCH 1/2] sha1_file: Add sha1_object_type_literally and export it David Turner
2015-02-25 19:59 ` karthik nayak
2015-02-25 20:15 ` David Turner
2015-02-25 21:32 ` Junio C Hamano
2015-02-25 22:44 ` Junio C Hamano
2015-02-25 21:55 ` Eric Sunshine
2015-02-26 15:07 ` Karthik Nayak
2015-02-25 11:08 ` [PATCH 2/2] cat-file: add --literally option Karthik Nayak
2015-02-25 22:14 ` Eric Sunshine
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=1424862460-13514-1-git-send-email-karthik.188@gmail.com \
--to=karthik.188@gmail.com \
--cc=git@vger.kernel.org \
/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).