* [PATCH 1/2] sha1_file.c: move find_cached_object up so sha1_object_info can use it
@ 2011-02-05 14:03 Nguyễn Thái Ngọc Duy
2011-02-05 14:03 ` [PATCH 2/2] sha1_object_info: examine cached_object store too Nguyễn Thái Ngọc Duy
0 siblings, 1 reply; 2+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2011-02-05 14:03 UTC (permalink / raw)
To: git, Junio C Hamano; +Cc: Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
sha1_file.c | 70 +++++++++++++++++++++++++++++-----------------------------
1 files changed, 35 insertions(+), 35 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index d86a8db..9fd7e16 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -37,6 +37,41 @@ const unsigned char null_sha1[20];
static int git_open_noatime(const char *name, struct packed_git *p);
+/*
+ * This is meant to hold a *small* number of objects that you would
+ * want read_sha1_file() to be able to return, but yet you do not want
+ * to write them into the object store (e.g. a browse-only
+ * application).
+ */
+static struct cached_object {
+ unsigned char sha1[20];
+ enum object_type type;
+ void *buf;
+ unsigned long size;
+} *cached_objects;
+static int cached_object_nr, cached_object_alloc;
+
+static struct cached_object empty_tree = {
+ EMPTY_TREE_SHA1_BIN,
+ OBJ_TREE,
+ "",
+ 0
+};
+
+static struct cached_object *find_cached_object(const unsigned char *sha1)
+{
+ int i;
+ struct cached_object *co = cached_objects;
+
+ for (i = 0; i < cached_object_nr; i++, co++) {
+ if (!hashcmp(co->sha1, sha1))
+ return co;
+ }
+ if (!hashcmp(sha1, empty_tree.sha1))
+ return &empty_tree;
+ return NULL;
+}
+
int safe_create_leading_directories(char *path)
{
char *pos = path + offset_1st_component(path);
@@ -2033,41 +2068,6 @@ static void *read_packed_sha1(const unsigned char *sha1,
return data;
}
-/*
- * This is meant to hold a *small* number of objects that you would
- * want read_sha1_file() to be able to return, but yet you do not want
- * to write them into the object store (e.g. a browse-only
- * application).
- */
-static struct cached_object {
- unsigned char sha1[20];
- enum object_type type;
- void *buf;
- unsigned long size;
-} *cached_objects;
-static int cached_object_nr, cached_object_alloc;
-
-static struct cached_object empty_tree = {
- EMPTY_TREE_SHA1_BIN,
- OBJ_TREE,
- "",
- 0
-};
-
-static struct cached_object *find_cached_object(const unsigned char *sha1)
-{
- int i;
- struct cached_object *co = cached_objects;
-
- for (i = 0; i < cached_object_nr; i++, co++) {
- if (!hashcmp(co->sha1, sha1))
- return co;
- }
- if (!hashcmp(sha1, empty_tree.sha1))
- return &empty_tree;
- return NULL;
-}
-
int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
unsigned char *sha1)
{
--
1.7.3.4.878.g439c7
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] sha1_object_info: examine cached_object store too
2011-02-05 14:03 [PATCH 1/2] sha1_file.c: move find_cached_object up so sha1_object_info can use it Nguyễn Thái Ngọc Duy
@ 2011-02-05 14:03 ` Nguyễn Thái Ngọc Duy
0 siblings, 0 replies; 2+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2011-02-05 14:03 UTC (permalink / raw)
To: git, Junio C Hamano; +Cc: Nguyễn Thái Ngọc Duy
Cached object store was added in d66b37b (Add pretend_sha1_file()
interface. - 2007-02-04) as a way to temporarily inject some objects
to object store.
But only read_sha1_file() knows about this store. While it will return
an object from this store, sha1_object_info() will happily say
"object not found".
Teach sha1_object_info() about the cached store for consistency.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
"git mktree" does not accept empty tree as it should do because of this.
sha1_file.c | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index 9fd7e16..0b830c8 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2020,9 +2020,17 @@ static int sha1_loose_object_info(const unsigned char *sha1, unsigned long *size
int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
{
+ struct cached_object *co;
struct pack_entry e;
int status;
+ co = find_cached_object(sha1);
+ if (co) {
+ if (sizep)
+ *sizep = co->size;
+ return co->type;
+ }
+
if (!find_pack_entry(sha1, &e)) {
/* Most likely it's a loose object. */
status = sha1_loose_object_info(sha1, sizep);
--
1.7.3.4.878.g439c7
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-02-05 14:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-05 14:03 [PATCH 1/2] sha1_file.c: move find_cached_object up so sha1_object_info can use it Nguyễn Thái Ngọc Duy
2011-02-05 14:03 ` [PATCH 2/2] sha1_object_info: examine cached_object store too Nguyễn Thái Ngọc Duy
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).