/*
* Put in `buf` the name of the file in the local object database that
- * would be used to store a loose object with the specified sha1.
+ * would be used to store a loose object with the specified oid.
*/
- const char *loose_object_path(struct repository *r, struct strbuf *buf, const unsigned char *sha1);
+ const char *loose_object_path(struct repository *r, struct strbuf *buf,
+ const struct object_id *oid);
- void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);
+ void *map_loose_object(struct repository *r, const struct object_id *oid,
+ unsigned long *size);
-extern void *read_object_file_extended(const struct object_id *oid,
+extern void *read_object_file_extended(struct repository *r,
+ const struct object_id *oid,
enum object_type *type,
unsigned long *size, int lookup_replace);
-static inline void *read_object_file(const struct object_id *oid, enum object_type *type, unsigned long *size)
+static inline void *repo_read_object_file(struct repository *r,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size)
{
- return read_object_file_extended(oid, type, size, 1);
+ return read_object_file_extended(r, oid, type, size, 1);
}
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define read_object_file(oid, type, size) repo_read_object_file(the_repository, oid, type, size)
+#endif
/* Read and unpack an object file into memory, write memory to an object file */
int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
unsigned long *size,
void **contents);
--/*
- * Convenience for sha1_object_info_extended() with a NULL struct
- * Convenience for oid_object_info_extended() with a NULL struct
-- * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
-- * nonzero flags to also set other flags.
-- */
- int repo_has_sha1_file_with_flags(struct repository *r,
- const unsigned char *sha1, int flags);
- static inline int repo_has_sha1_file(struct repository *r,
- const unsigned char *sha1)
-int has_object_file_with_flags(const struct object_id *oid, int flags);
-static inline int has_object_file(const struct object_id *oid)
--{
- return repo_has_sha1_file_with_flags(r, sha1, 0);
- return has_object_file_with_flags(oid, 0);
--}
-
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define has_sha1_file_with_flags(sha1, flags) repo_has_sha1_file_with_flags(the_repository, sha1, flags)
+#define has_sha1_file(sha1) repo_has_sha1_file(the_repository, sha1)
+#endif
+
+/* Same as the above, except for struct object_id. */
+int repo_has_object_file(struct repository *r, const struct object_id *oid);
+int repo_has_object_file_with_flags(struct repository *r,
+ const struct object_id *oid, int flags);
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define has_object_file(oid) repo_has_object_file(the_repository, oid)
+#define has_object_file_with_flags(oid, flags) repo_has_object_file_with_flags(the_repository, oid, flags)
+#endif
/*
* Return true iff an alternate object database has a loose object
return oid_to_hex_r(buf, the_hash_algo->empty_blob);
}
+int hash_algo_by_name(const char *name)
+{
+ int i;
+ if (!name)
+ return GIT_HASH_UNKNOWN;
+ for (i = 1; i < GIT_HASH_NALGOS; i++)
+ if (!strcmp(name, hash_algos[i].name))
+ return i;
+ return GIT_HASH_UNKNOWN;
+}
+
+int hash_algo_by_id(uint32_t format_id)
+{
+ int i;
+ for (i = 1; i < GIT_HASH_NALGOS; i++)
+ if (format_id == hash_algos[i].format_id)
+ return i;
+ return GIT_HASH_UNKNOWN;
+}
+
+
/*
* 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
+ * want read_object_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).
*/
return type;
}
-static void *read_object(const struct object_id *oid, enum object_type *type,
+static void *read_object(struct repository *r,
- const unsigned char *sha1,
- enum object_type *type,
++ const struct object_id *oid, enum object_type *type,
unsigned long *size)
{
- struct object_id oid;
struct object_info oi = OBJECT_INFO_INIT;
void *content;
oi.typep = type;
oi.sizep = size;
oi.contentp = &content;
- hashcpy(oid.hash, sha1);
-
- if (oid_object_info_extended(r, &oid, &oi, 0) < 0)
- if (oid_object_info_extended(the_repository, oid, &oi, 0) < 0)
++ if (oid_object_info_extended(r, oid, &oi, 0) < 0)
return NULL;
return content;
}
const char *path;
struct stat st;
const struct object_id *repl = lookup_replace ?
- lookup_replace_object(the_repository, oid) : oid;
+ lookup_replace_object(r, oid) : oid;
errno = 0;
- data = read_object(r, repl->hash, type, size);
- data = read_object(repl, type, size);
++ data = read_object(r, repl, type, size);
if (data)
return data;
die(_("replacement %s not found for %s"),
oid_to_hex(repl), oid_to_hex(oid));
- if (!stat_sha1_file(r, repl->hash, &st, &path))
- if (!stat_loose_object(the_repository, repl, &st, &path))
++ if (!stat_loose_object(r, repl, &st, &path))
die(_("loose object %s (stored in %s) is corrupt"),
oid_to_hex(repl), path);
if (has_loose_object(oid))
return 0;
- buf = read_object(the_repository, oid->hash, &type, &len);
- buf = read_object(oid, &type, &len);
++ buf = read_object(the_repository, oid, &type, &len);
if (!buf)
- return error(_("cannot read sha1_file for %s"), oid_to_hex(oid));
+ return error(_("cannot read object for %s"), oid_to_hex(oid));
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(type), (uintmax_t)len) + 1;
ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime);
free(buf);
return ret;
}
- int repo_has_sha1_file_with_flags(struct repository *r,
- const unsigned char *sha1, int flags)
-int has_object_file_with_flags(const struct object_id *oid, int flags)
++int repo_has_object_file_with_flags(struct repository *r,
++ const struct object_id *oid, int flags)
{
- struct object_id oid;
if (!startup_info->have_repository)
return 0;
- hashcpy(oid.hash, sha1);
- return oid_object_info_extended(r, &oid, NULL,
- return oid_object_info_extended(the_repository, oid, NULL,
++ return oid_object_info_extended(r, oid, NULL,
flags | OBJECT_INFO_SKIP_CACHED) >= 0;
}
- return repo_has_sha1_file(r, oid->hash);
- }
-
- int repo_has_object_file_with_flags(struct repository *r,
- const struct object_id *oid, int flags)
- {
- return repo_has_sha1_file_with_flags(r, oid->hash, flags);
+int repo_has_object_file(struct repository *r,
+ const struct object_id *oid)
+{
++ return repo_has_object_file_with_flags(r, oid, 0);
+}
+
static void check_tree(const void *buf, size_t size)
{
struct tree_desc desc;