sha1_file.c: move find_cached_object up so sha1_object_info can use it
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Feb 5, 2011 at 21:03 UTC
c597ba801048be45d168b1f6335e91bab165448f
1 file changed
+35
-35
sha1_file.c
+35
-35
@@ -37,6 +37,41 @@ const unsigned char null_sha1[20];
37
38
static int git_open_noatime(const char *name, struct packed_git *p);
39
40
+/*
41
+ * This is meant to hold a *small* number of objects that you would
42
+ * want read_sha1_file() to be able to return, but yet you do not want
43
+ * to write them into the object store (e.g. a browse-only
44
+ * application).
45
+ */
46
+static struct cached_object {
47
+ unsigned char sha1[20];
48
+ enum object_type type;
49
+ void *buf;
50
+ unsigned long size;
51
+} *cached_objects;
52
+static int cached_object_nr, cached_object_alloc;
53
+
54
+static struct cached_object empty_tree = {
55
+ EMPTY_TREE_SHA1_BIN,
56
+ OBJ_TREE,
57
+ "",
58
+ 0
59
+};
60
+
61
+static struct cached_object *find_cached_object(const unsigned char *sha1)
62
+{
63
+ int i;
64
+ struct cached_object *co = cached_objects;
65
+
66
+ for (i = 0; i < cached_object_nr; i++, co++) {
67
+ if (!hashcmp(co->sha1, sha1))
68
+ return co;
69
+ }
70
+ if (!hashcmp(sha1, empty_tree.sha1))
71
+ return &empty_tree;
72
+ return NULL;
73
+}
74
+
75
int safe_create_leading_directories(char *path)
76
{
77
char *pos = path + offset_1st_component(path);
@@ -2033,41 +2068,6 @@ static void *read_packed_sha1(const unsigned char *sha1,
2068
return data;
2069
}
2070
2036
-/*
2037
- * This is meant to hold a *small* number of objects that you would
2038
- * want read_sha1_file() to be able to return, but yet you do not want
2039
- * to write them into the object store (e.g. a browse-only
2040
- * application).
2041
- */
2042
-static struct cached_object {
2043
- unsigned char sha1[20];
2044
- enum object_type type;
2045
- void *buf;
2046
- unsigned long size;
2047
-} *cached_objects;
2048
-static int cached_object_nr, cached_object_alloc;
2049
-
2050
-static struct cached_object empty_tree = {
2051
- EMPTY_TREE_SHA1_BIN,
2052
- OBJ_TREE,
2053
- "",
2054
- 0
2055
-};
2056
-
2057
-static struct cached_object *find_cached_object(const unsigned char *sha1)
2058
-{
2059
- int i;
2060
- struct cached_object *co = cached_objects;
2061
-
2062
- for (i = 0; i < cached_object_nr; i++, co++) {
2063
- if (!hashcmp(co->sha1, sha1))
2064
- return co;
2065
- }
2066
- if (!hashcmp(sha1, empty_tree.sha1))
2067
- return &empty_tree;
2068
- return NULL;
2069
-}
2070
-
2071
int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
2072
unsigned char *sha1)
2073
{