From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 5/5] read_sha1_file(): allow selective bypassing of replacement mechanism
Date: Sun, 15 May 2011 12:54:54 -0700 [thread overview]
Message-ID: <1305489294-14341-6-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1305489294-14341-1-git-send-email-gitster@pobox.com>
The way "object replacement" mechanism was tucked to the read_sha1_file()
interface was suboptimal in a couple of ways:
- Callers that want it to die with useful diagnosis upon seeing a corrupt
object does not have a way to say that they do not want any object
replacement.
- Callers who do not want it to die but want to handle the errors
themselves are told to arrange to call read_object(), but the function
does not use the replacement mechanism, and also it is a file scope
static function that not many callers can call to begin with.
This adds a read_sha1_file_extended() that takes a set of flags; the
callers of read_sha1_file() passes a flag READ_SHA1_FILE_REPLACE to ask
for object replacement mechanism to kick in.
Later, we could add another flag bit to tell the function to return an
error instead of dying and then remove the misguided "call read_object()
yourself".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
cache.h | 7 ++++++-
sha1_file.c | 10 ++++++----
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/cache.h b/cache.h
index c10a91d..5f1f5c3 100644
--- a/cache.h
+++ b/cache.h
@@ -757,7 +757,12 @@ int daemon_avoid_alias(const char *path);
int offset_1st_component(const char *path);
/* object replacement */
-extern void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size);
+#define READ_SHA1_FILE_REPLACE 1
+extern void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag);
+static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
+{
+ return read_sha1_file_extended(sha1, type, size, READ_SHA1_FILE_REPLACE);
+}
extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)
{
diff --git a/sha1_file.c b/sha1_file.c
index 5d80feb..7e6e976 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2206,14 +2206,16 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,
* deal with them should arrange to call read_object() and give error
* messages themselves.
*/
-void *read_sha1_file(const unsigned char *sha1,
- enum object_type *type,
- unsigned long *size)
+void *read_sha1_file_extended(const unsigned char *sha1,
+ enum object_type *type,
+ unsigned long *size,
+ unsigned flag)
{
- const unsigned char *repl = lookup_replace_object(sha1);
void *data;
char *path;
const struct packed_git *p;
+ const unsigned char *repl = (flag & READ_SHA1_FILE_REPLACE)
+ ? lookup_replace_object(sha1) : sha1;
errno = 0;
data = read_object(repl, type, size);
--
1.7.5.1.334.gdfd07
prev parent reply other threads:[~2011-05-15 19:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-15 19:54 [PATCH 0/5] Updates to replace-object API Junio C Hamano
2011-05-15 19:54 ` [PATCH 1/5] Declare lookup_replace_object() in cache.h, not in commit.h Junio C Hamano
2011-05-15 19:54 ` [PATCH 2/5] t6050: make sure we test not just commit replacement Junio C Hamano
2011-05-15 19:54 ` [PATCH 3/5] read_sha1_file(): get rid of read_sha1_file_repl() madness Junio C Hamano
2011-05-15 19:54 ` [PATCH 4/5] inline lookup_replace_object() calls Junio C Hamano
2011-05-15 19:54 ` Junio C Hamano [this message]
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=1305489294-14341-6-git-send-email-gitster@pobox.com \
--to=gitster@pobox.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).