* either sha1 or a pointer to a permanently-allocated value. When
* object replacement is suppressed, always return sha1.
*/
-static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)
+static inline const struct object_id *lookup_replace_object(const struct object_id *oid)
{
if (!check_replace_refs)
- return sha1;
- return do_lookup_replace_object(sha1);
+ return oid;
+ return do_lookup_replace_object(oid);
}
-/* Read and unpack a sha1 file into memory, write memory to a sha1 file */
-extern int sha1_object_info(const unsigned char *, unsigned long *);
-extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);
-extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
-extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, struct object_id *oid, unsigned flags);
-extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);
-extern int force_object_loose(const unsigned char *sha1, time_t mtime);
+/* Read and unpack an object file into memory, write memory to an object file */
+extern int oid_object_info(const struct object_id *, unsigned long *);
+
+extern int hash_object_file(const void *buf, unsigned long len,
+ const char *type, struct object_id *oid);
+
+extern int write_object_file(const void *buf, unsigned long len,
+ const char *type, struct object_id *oid);
+
+extern int hash_object_file_literally(const void *buf, unsigned long len,
+ const char *type, struct object_id *oid,
+ unsigned flags);
+
+extern int pretend_object_file(void *, unsigned long, enum object_type,
+ struct object_id *oid);
+
+extern int force_object_loose(const struct object_id *oid, time_t mtime);
+
extern int git_open_cloexec(const char *name, int flags);
#define git_open(name) git_open_cloexec(name, O_RDONLY)
- extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size);
extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
extern int parse_sha1_header(const char *hdr, unsigned long *sizep);
char *get_object_directory(void)
{
- if (!the_repository->objectdir)
+ if (!the_repository->objects->objectdir)
BUG("git environment hasn't been setup");
- return the_repository->objectdir;
+ return the_repository->objects->objectdir;
}
-int odb_mkstemp(struct strbuf *template, const char *pattern)
+int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
{
int fd;
/*
#include "quote.h"
#include "packfile.h"
#include "fetch-object.h"
+ #include "object-store.h"
+/* The maximum size for an object header. */
+#define MAX_HEADER_LEN 32
+
const unsigned char null_sha1[GIT_MAX_RAWSZ];
const struct object_id null_oid;
const struct object_id empty_tree_oid = {
* return value implicitly indicates whether the
* object even exists.
*/
- if (!oi->typep && !oi->typename && !oi->sizep && !oi->contentp) {
+ if (!oi->typep && !oi->type_name && !oi->sizep && !oi->contentp) {
const char *path;
struct stat st;
- if (stat_sha1_file(sha1, &st, &path) < 0)
+ if (stat_sha1_file(r, sha1, &st, &path) < 0)
return -1;
if (oi->disk_sizep)
*oi->disk_sizep = st.st_size;
}
while (1) {
- if (find_pack_entry(real, &e))
+ if (find_pack_entry(real->hash, &e))
break;
+ if (flags & OBJECT_INFO_IGNORE_LOOSE)
+ return -1;
+
/* Most likely it's a loose object. */
- if (!sha1_loose_object_info(real->hash, oi, flags))
- if (!sha1_loose_object_info(the_repository, real, oi, flags))
++ if (!sha1_loose_object_info(the_repository, real->hash, oi, flags))
return 0;
/* Not a loose object; someone else may have just packed it. */
return data;
if (errno && errno != ENOENT)
- die_errno("failed to read object %s", sha1_to_hex(sha1));
+ die_errno("failed to read object %s", oid_to_hex(oid));
/* die if we replaced an object with one that does not exist */
- if (repl != sha1)
+ if (repl != oid)
die("replacement %s not found for %s",
- sha1_to_hex(repl), sha1_to_hex(sha1));
+ oid_to_hex(repl), oid_to_hex(oid));
- if (!stat_sha1_file(repl->hash, &st, &path))
- if (!stat_sha1_file(the_repository, repl, &st, &path))
++ if (!stat_sha1_file(the_repository, repl->hash, &st, &path))
die("loose object %s (stored in %s) is corrupt",
- sha1_to_hex(repl), path);
+ oid_to_hex(repl), path);
- if ((p = has_packed_and_bad(repl)) != NULL)
+ if ((p = has_packed_and_bad(repl->hash)) != NULL)
die("packed object %s (stored in %s) is corrupt",
- sha1_to_hex(repl), p->pack_name);
+ oid_to_hex(repl), p->pack_name);
return NULL;
}
static struct strbuf filename = STRBUF_INIT;
strbuf_reset(&filename);
- sha1_file_name(&filename, oid->hash);
- sha1_file_name(the_repository, &filename, sha1);
++ sha1_file_name(the_repository, &filename, oid->hash);
fd = create_tmpfile(&tmp_file, filename.buf);
if (fd < 0) {
static open_method_decl(loose)
{
- st->u.loose.mapped = map_sha1_file(oid->hash, &st->u.loose.mapsize);
+ st->u.loose.mapped = map_sha1_file(the_repository,
- sha1, &st->u.loose.mapsize);
++ oid->hash, &st->u.loose.mapsize);
if (!st->u.loose.mapped)
return -1;
if ((unpack_sha1_header(&st->z,