From: Martin Koegler <mkoegler@auto.tuwien.ac.at>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org, Martin Koegler <mkoegler@auto.tuwien.ac.at>
Subject: [PATCH 2/5] add get_sha1_with_mode
Date: Sun, 22 Apr 2007 18:43:57 +0200 [thread overview]
Message-ID: <11772602402479-git-send-email-mkoegler@auto.tuwien.ac.at> (raw)
In-Reply-To: <1177260240326-git-send-email-mkoegler@auto.tuwien.ac.at>
get_sha1_with_mode basically behaves as get_sha1. It has an additional
parameter for storing the mode of the object. This parameter may be NULL.
If the mode can not be determinded, it stores S_IFINVALID.
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
---
cache.h | 1 +
sha1_name.c | 11 ++++++++++-
2 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/cache.h b/cache.h
index d425c26..a9ae3f8 100644
--- a/cache.h
+++ b/cache.h
@@ -320,6 +320,7 @@ static inline unsigned int hexval(unsigned int c)
#define DEFAULT_ABBREV 7
extern int get_sha1(const char *str, unsigned char *sha1);
+extern int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode);
extern int get_sha1_hex(const char *hex, unsigned char *sha1);
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
extern int read_ref(const char *filename, unsigned char *sha1);
diff --git a/sha1_name.c b/sha1_name.c
index 267ea3f..1349c0a 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -643,11 +643,18 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
*/
int get_sha1(const char *name, unsigned char *sha1)
{
+ return get_sha1_with_mode(name, sha1, NULL);
+}
+
+int get_sha1_with_mode(const char *name, unsigned char *sha1, unsigned* mode)
+{
int ret, bracket_depth;
unsigned unused;
int namelen = strlen(name);
const char *cp;
+ if (mode)
+ *mode = S_IFINVALID;
prepare_alt_odb();
ret = get_sha1_1(name, namelen, sha1);
if (!ret)
@@ -685,6 +692,8 @@ int get_sha1(const char *name, unsigned char *sha1)
break;
if (ce_stage(ce) == stage) {
hashcpy(sha1, ce->sha1);
+ if (mode)
+ *mode = ntohl(ce->ce_mode);
return 0;
}
pos++;
@@ -703,7 +712,7 @@ int get_sha1(const char *name, unsigned char *sha1)
unsigned char tree_sha1[20];
if (!get_sha1_1(name, cp-name, tree_sha1))
return get_tree_entry(tree_sha1, cp+1, sha1,
- &unused);
+ mode ? mode : &unused);
}
return ret;
}
--
1.5.1.1.206.g4a12-dirty
next prev parent reply other threads:[~2007-04-22 16:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-22 16:43 [PATCH 1/5] Add S_IFINVALID mode Martin Koegler
2007-04-22 16:43 ` Martin Koegler [this message]
2007-04-22 16:43 ` [PATCH 3/5] add add_object_array_with_mode Martin Koegler
2007-04-22 16:43 ` [PATCH 4/5] store mode in rev_list, if <tree>:<filename> syntax is used Martin Koegler
2007-04-22 16:44 ` [PATCH 5/5] use mode of the tree in git-diff, if <tree>:<file> " Martin Koegler
2007-04-23 2:33 ` [PATCH 2/5] add get_sha1_with_mode Junio C Hamano
2007-04-22 17:47 ` [PATCH 1/5] Add S_IFINVALID mode 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=11772602402479-git-send-email-mkoegler@auto.tuwien.ac.at \
--to=mkoegler@auto.tuwien.ac.at \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/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).