Merge branch 'bc/object-id'

Conversion from uchar[20] to struct object_id continues.

* bc/object-id: (36 commits)
  convert: convert to struct object_id
  sha1_file: introduce a constant for max header length
  Convert lookup_replace_object to struct object_id
  sha1_file: convert read_sha1_file to struct object_id
  sha1_file: convert read_object_with_reference to object_id
  tree-walk: convert tree entry functions to object_id
  streaming: convert istream internals to struct object_id
  tree-walk: convert get_tree_entry_follow_symlinks internals to object_id
  builtin/notes: convert static functions to object_id
  builtin/fmt-merge-msg: convert remaining code to object_id
  sha1_file: convert sha1_object_info* to object_id
  Convert remaining callers of sha1_object_info_extended to object_id
  packfile: convert unpack_entry to struct object_id
  sha1_file: convert retry_bad_packed_offset to struct object_id
  sha1_file: convert assert_sha1_type to object_id
  builtin/mktree: convert to struct object_id
  streaming: convert open_istream to use struct object_id
  sha1_file: convert check_sha1_signature to struct object_id
  sha1_file: convert read_loose_object to use struct object_id
  builtin/index-pack: convert struct ref_delta_entry to object_id
  ...
This commit is contained in:
Junio C Hamano
2018-04-10 08:25:45 +09:00
111 changed files with 609 additions and 594 deletions

View File

@@ -3180,7 +3180,7 @@ static int apply_binary(struct apply_state *state,
unsigned long size; unsigned long size;
char *result; char *result;
result = read_sha1_file(oid.hash, &type, &size); result = read_object_file(&oid, &type, &size);
if (!result) if (!result)
return error(_("the necessary postimage %s for " return error(_("the necessary postimage %s for "
"'%s' cannot be read"), "'%s' cannot be read"),
@@ -3242,7 +3242,7 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
unsigned long sz; unsigned long sz;
char *result; char *result;
result = read_sha1_file(oid->hash, &type, &sz); result = read_object_file(oid, &type, &sz);
if (!result) if (!result)
return -1; return -1;
/* XXX read_sha1_file NUL-terminates */ /* XXX read_sha1_file NUL-terminates */

View File

@@ -111,7 +111,7 @@ static void write_trailer(void)
* queues up writes, so that all our write(2) calls write exactly one * queues up writes, so that all our write(2) calls write exactly one
* full block; pads writes to RECORDSIZE * full block; pads writes to RECORDSIZE
*/ */
static int stream_blocked(const unsigned char *sha1) static int stream_blocked(const struct object_id *oid)
{ {
struct git_istream *st; struct git_istream *st;
enum object_type type; enum object_type type;
@@ -119,9 +119,9 @@ static int stream_blocked(const unsigned char *sha1)
char buf[BLOCKSIZE]; char buf[BLOCKSIZE];
ssize_t readlen; ssize_t readlen;
st = open_istream(sha1, &type, &sz, NULL); st = open_istream(oid, &type, &sz, NULL);
if (!st) if (!st)
return error("cannot stream blob %s", sha1_to_hex(sha1)); return error("cannot stream blob %s", oid_to_hex(oid));
for (;;) { for (;;) {
readlen = read_istream(st, buf, sizeof(buf)); readlen = read_istream(st, buf, sizeof(buf));
if (readlen <= 0) if (readlen <= 0)
@@ -218,7 +218,7 @@ static void prepare_header(struct archiver_args *args,
} }
static void write_extended_header(struct archiver_args *args, static void write_extended_header(struct archiver_args *args,
const unsigned char *sha1, const struct object_id *oid,
const void *buffer, unsigned long size) const void *buffer, unsigned long size)
{ {
struct ustar_header header; struct ustar_header header;
@@ -226,14 +226,14 @@ static void write_extended_header(struct archiver_args *args,
memset(&header, 0, sizeof(header)); memset(&header, 0, sizeof(header));
*header.typeflag = TYPEFLAG_EXT_HEADER; *header.typeflag = TYPEFLAG_EXT_HEADER;
mode = 0100666; mode = 0100666;
xsnprintf(header.name, sizeof(header.name), "%s.paxheader", sha1_to_hex(sha1)); xsnprintf(header.name, sizeof(header.name), "%s.paxheader", oid_to_hex(oid));
prepare_header(args, &header, mode, size); prepare_header(args, &header, mode, size);
write_blocked(&header, sizeof(header)); write_blocked(&header, sizeof(header));
write_blocked(buffer, size); write_blocked(buffer, size);
} }
static int write_tar_entry(struct archiver_args *args, static int write_tar_entry(struct archiver_args *args,
const unsigned char *sha1, const struct object_id *oid,
const char *path, size_t pathlen, const char *path, size_t pathlen,
unsigned int mode) unsigned int mode)
{ {
@@ -257,7 +257,7 @@ static int write_tar_entry(struct archiver_args *args,
mode = (mode | ((mode & 0100) ? 0777 : 0666)) & ~tar_umask; mode = (mode | ((mode & 0100) ? 0777 : 0666)) & ~tar_umask;
} else { } else {
return error("unsupported file mode: 0%o (SHA1: %s)", return error("unsupported file mode: 0%o (SHA1: %s)",
mode, sha1_to_hex(sha1)); mode, oid_to_hex(oid));
} }
if (pathlen > sizeof(header.name)) { if (pathlen > sizeof(header.name)) {
size_t plen = get_path_prefix(path, pathlen, size_t plen = get_path_prefix(path, pathlen,
@@ -268,7 +268,7 @@ static int write_tar_entry(struct archiver_args *args,
memcpy(header.name, path + plen + 1, rest); memcpy(header.name, path + plen + 1, rest);
} else { } else {
xsnprintf(header.name, sizeof(header.name), "%s.data", xsnprintf(header.name, sizeof(header.name), "%s.data",
sha1_to_hex(sha1)); oid_to_hex(oid));
strbuf_append_ext_header(&ext_header, "path", strbuf_append_ext_header(&ext_header, "path",
path, pathlen); path, pathlen);
} }
@@ -276,14 +276,14 @@ static int write_tar_entry(struct archiver_args *args,
memcpy(header.name, path, pathlen); memcpy(header.name, path, pathlen);
if (S_ISREG(mode) && !args->convert && if (S_ISREG(mode) && !args->convert &&
sha1_object_info(sha1, &size) == OBJ_BLOB && oid_object_info(oid, &size) == OBJ_BLOB &&
size > big_file_threshold) size > big_file_threshold)
buffer = NULL; buffer = NULL;
else if (S_ISLNK(mode) || S_ISREG(mode)) { else if (S_ISLNK(mode) || S_ISREG(mode)) {
enum object_type type; enum object_type type;
buffer = sha1_file_to_archive(args, path, sha1, old_mode, &type, &size); buffer = object_file_to_archive(args, path, oid, old_mode, &type, &size);
if (!buffer) if (!buffer)
return error("cannot read %s", sha1_to_hex(sha1)); return error("cannot read %s", oid_to_hex(oid));
} else { } else {
buffer = NULL; buffer = NULL;
size = 0; size = 0;
@@ -292,7 +292,7 @@ static int write_tar_entry(struct archiver_args *args,
if (S_ISLNK(mode)) { if (S_ISLNK(mode)) {
if (size > sizeof(header.linkname)) { if (size > sizeof(header.linkname)) {
xsnprintf(header.linkname, sizeof(header.linkname), xsnprintf(header.linkname, sizeof(header.linkname),
"see %s.paxheader", sha1_to_hex(sha1)); "see %s.paxheader", oid_to_hex(oid));
strbuf_append_ext_header(&ext_header, "linkpath", strbuf_append_ext_header(&ext_header, "linkpath",
buffer, size); buffer, size);
} else } else
@@ -308,7 +308,7 @@ static int write_tar_entry(struct archiver_args *args,
prepare_header(args, &header, mode, size_in_header); prepare_header(args, &header, mode, size_in_header);
if (ext_header.len > 0) { if (ext_header.len > 0) {
write_extended_header(args, sha1, ext_header.buf, write_extended_header(args, oid, ext_header.buf,
ext_header.len); ext_header.len);
} }
strbuf_release(&ext_header); strbuf_release(&ext_header);
@@ -317,7 +317,7 @@ static int write_tar_entry(struct archiver_args *args,
if (buffer) if (buffer)
write_blocked(buffer, size); write_blocked(buffer, size);
else else
err = stream_blocked(sha1); err = stream_blocked(oid);
} }
free(buffer); free(buffer);
return err; return err;

View File

@@ -276,7 +276,7 @@ static int entry_is_binary(const char *path, const void *buffer, size_t size)
#define STREAM_BUFFER_SIZE (1024 * 16) #define STREAM_BUFFER_SIZE (1024 * 16)
static int write_zip_entry(struct archiver_args *args, static int write_zip_entry(struct archiver_args *args,
const unsigned char *sha1, const struct object_id *oid,
const char *path, size_t pathlen, const char *path, size_t pathlen,
unsigned int mode) unsigned int mode)
{ {
@@ -314,7 +314,7 @@ static int write_zip_entry(struct archiver_args *args,
if (pathlen > 0xffff) { if (pathlen > 0xffff) {
return error("path too long (%d chars, SHA1: %s): %s", return error("path too long (%d chars, SHA1: %s): %s",
(int)pathlen, sha1_to_hex(sha1), path); (int)pathlen, oid_to_hex(oid), path);
} }
if (S_ISDIR(mode) || S_ISGITLINK(mode)) { if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
@@ -325,7 +325,7 @@ static int write_zip_entry(struct archiver_args *args,
compressed_size = 0; compressed_size = 0;
buffer = NULL; buffer = NULL;
} else if (S_ISREG(mode) || S_ISLNK(mode)) { } else if (S_ISREG(mode) || S_ISLNK(mode)) {
enum object_type type = sha1_object_info(sha1, &size); enum object_type type = oid_object_info(oid, &size);
method = 0; method = 0;
attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) : attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :
@@ -337,18 +337,18 @@ static int write_zip_entry(struct archiver_args *args,
if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert && if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert &&
size > big_file_threshold) { size > big_file_threshold) {
stream = open_istream(sha1, &type, &size, NULL); stream = open_istream(oid, &type, &size, NULL);
if (!stream) if (!stream)
return error("cannot stream blob %s", return error("cannot stream blob %s",
sha1_to_hex(sha1)); oid_to_hex(oid));
flags |= ZIP_STREAM; flags |= ZIP_STREAM;
out = buffer = NULL; out = buffer = NULL;
} else { } else {
buffer = sha1_file_to_archive(args, path, sha1, mode, buffer = object_file_to_archive(args, path, oid, mode,
&type, &size); &type, &size);
if (!buffer) if (!buffer)
return error("cannot read %s", return error("cannot read %s",
sha1_to_hex(sha1)); oid_to_hex(oid));
crc = crc32(crc, buffer, size); crc = crc32(crc, buffer, size);
is_binary = entry_is_binary(path_without_prefix, is_binary = entry_is_binary(path_without_prefix,
buffer, size); buffer, size);
@@ -357,7 +357,7 @@ static int write_zip_entry(struct archiver_args *args,
compressed_size = (method == 0) ? size : 0; compressed_size = (method == 0) ? size : 0;
} else { } else {
return error("unsupported file mode: 0%o (SHA1: %s)", mode, return error("unsupported file mode: 0%o (SHA1: %s)", mode,
sha1_to_hex(sha1)); oid_to_hex(oid));
} }
if (creator_version > max_creator_version) if (creator_version > max_creator_version)

View File

@@ -63,8 +63,8 @@ static void format_subst(const struct commit *commit,
free(to_free); free(to_free);
} }
void *sha1_file_to_archive(const struct archiver_args *args, void *object_file_to_archive(const struct archiver_args *args,
const char *path, const unsigned char *sha1, const char *path, const struct object_id *oid,
unsigned int mode, enum object_type *type, unsigned int mode, enum object_type *type,
unsigned long *sizep) unsigned long *sizep)
{ {
@@ -72,7 +72,7 @@ void *sha1_file_to_archive(const struct archiver_args *args,
const struct commit *commit = args->convert ? args->commit : NULL; const struct commit *commit = args->convert ? args->commit : NULL;
path += args->baselen; path += args->baselen;
buffer = read_sha1_file(sha1, type, sizep); buffer = read_object_file(oid, type, sizep);
if (buffer && S_ISREG(mode)) { if (buffer && S_ISREG(mode)) {
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
size_t size = 0; size_t size = 0;
@@ -121,7 +121,7 @@ static int check_attr_export_subst(const struct attr_check *check)
return check && ATTR_TRUE(check->items[1].value); return check && ATTR_TRUE(check->items[1].value);
} }
static int write_archive_entry(const unsigned char *sha1, const char *base, static int write_archive_entry(const struct object_id *oid, const char *base,
int baselen, const char *filename, unsigned mode, int stage, int baselen, const char *filename, unsigned mode, int stage,
void *context) void *context)
{ {
@@ -153,7 +153,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
if (S_ISDIR(mode) || S_ISGITLINK(mode)) { if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
if (args->verbose) if (args->verbose)
fprintf(stderr, "%.*s\n", (int)path.len, path.buf); fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
err = write_entry(args, sha1, path.buf, path.len, mode); err = write_entry(args, oid, path.buf, path.len, mode);
if (err) if (err)
return err; return err;
return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0); return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
@@ -161,7 +161,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
if (args->verbose) if (args->verbose)
fprintf(stderr, "%.*s\n", (int)path.len, path.buf); fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
return write_entry(args, sha1, path.buf, path.len, mode); return write_entry(args, oid, path.buf, path.len, mode);
} }
static void queue_directory(const unsigned char *sha1, static void queue_directory(const unsigned char *sha1,
@@ -191,14 +191,14 @@ static int write_directory(struct archiver_context *c)
d->path[d->len - 1] = '\0'; /* no trailing slash */ d->path[d->len - 1] = '\0'; /* no trailing slash */
ret = ret =
write_directory(c) || write_directory(c) ||
write_archive_entry(d->oid.hash, d->path, d->baselen, write_archive_entry(&d->oid, d->path, d->baselen,
d->path + d->baselen, d->mode, d->path + d->baselen, d->mode,
d->stage, c) != READ_TREE_RECURSIVE; d->stage, c) != READ_TREE_RECURSIVE;
free(d); free(d);
return ret ? -1 : 0; return ret ? -1 : 0;
} }
static int queue_or_write_archive_entry(const unsigned char *sha1, static int queue_or_write_archive_entry(const struct object_id *oid,
struct strbuf *base, const char *filename, struct strbuf *base, const char *filename,
unsigned mode, int stage, void *context) unsigned mode, int stage, void *context)
{ {
@@ -224,14 +224,14 @@ static int queue_or_write_archive_entry(const unsigned char *sha1,
if (check_attr_export_ignore(check)) if (check_attr_export_ignore(check))
return 0; return 0;
queue_directory(sha1, base, filename, queue_directory(oid->hash, base, filename,
mode, stage, c); mode, stage, c);
return READ_TREE_RECURSIVE; return READ_TREE_RECURSIVE;
} }
if (write_directory(c)) if (write_directory(c))
return -1; return -1;
return write_archive_entry(sha1, base->buf, base->len, filename, mode, return write_archive_entry(oid, base->buf, base->len, filename, mode,
stage, context); stage, context);
} }
@@ -250,7 +250,7 @@ int write_archive_entries(struct archiver_args *args,
len--; len--;
if (args->verbose) if (args->verbose)
fprintf(stderr, "%.*s\n", (int)len, args->base); fprintf(stderr, "%.*s\n", (int)len, args->base);
err = write_entry(args, args->tree->object.oid.hash, args->base, err = write_entry(args, &args->tree->object.oid, args->base,
len, 040777); len, 040777);
if (err) if (err)
return err; return err;
@@ -303,7 +303,7 @@ static const struct archiver *lookup_archiver(const char *name)
return NULL; return NULL;
} }
static int reject_entry(const unsigned char *sha1, struct strbuf *base, static int reject_entry(const struct object_id *oid, struct strbuf *base,
const char *filename, unsigned mode, const char *filename, unsigned mode,
int stage, void *context) int stage, void *context)
{ {
@@ -397,8 +397,8 @@ static void parse_treeish_arg(const char **argv,
unsigned int mode; unsigned int mode;
int err; int err;
err = get_tree_entry(tree->object.oid.hash, prefix, err = get_tree_entry(&tree->object.oid, prefix, &tree_oid,
tree_oid.hash, &mode); &mode);
if (err || !S_ISDIR(mode)) if (err || !S_ISDIR(mode))
die("current working directory is untracked"); die("current working directory is untracked");

View File

@@ -31,7 +31,7 @@ extern void init_tar_archiver(void);
extern void init_zip_archiver(void); extern void init_zip_archiver(void);
typedef int (*write_archive_entry_fn_t)(struct archiver_args *args, typedef int (*write_archive_entry_fn_t)(struct archiver_args *args,
const unsigned char *sha1, const struct object_id *oid,
const char *path, size_t pathlen, const char *path, size_t pathlen,
unsigned int mode); unsigned int mode);
@@ -39,8 +39,8 @@ extern int write_archive_entries(struct archiver_args *args, write_archive_entry
extern int write_archive(int argc, const char **argv, const char *prefix, const char *name_hint, int remote); extern int write_archive(int argc, const char **argv, const char *prefix, const char *name_hint, int remote);
const char *archive_format_from_filename(const char *filename); const char *archive_format_from_filename(const char *filename);
extern void *sha1_file_to_archive(const struct archiver_args *args, extern void *object_file_to_archive(const struct archiver_args *args,
const char *path, const unsigned char *sha1, const char *path, const struct object_id *oid,
unsigned int mode, enum object_type *type, unsigned int mode, enum object_type *type,
unsigned long *sizep); unsigned long *sizep);

View File

@@ -132,7 +132,8 @@ static void show_list(const char *debug, int counted, int nr,
unsigned flags = commit->object.flags; unsigned flags = commit->object.flags;
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
char *buf = read_sha1_file(commit->object.oid.hash, &type, &size); char *buf = read_object_file(&commit->object.oid, &type,
&size);
const char *subject_start; const char *subject_start;
int subject_len; int subject_len;

14
blame.c
View File

@@ -80,8 +80,8 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
struct object_id blob_oid; struct object_id blob_oid;
unsigned mode; unsigned mode;
if (!get_tree_entry(commit_oid->hash, path, blob_oid.hash, &mode) && if (!get_tree_entry(commit_oid, path, &blob_oid, &mode) &&
sha1_object_info(blob_oid.hash, NULL) == OBJ_BLOB) oid_object_info(&blob_oid, NULL) == OBJ_BLOB)
return; return;
} }
@@ -297,7 +297,7 @@ static void fill_origin_blob(struct diff_options *opt,
textconv_object(o->path, o->mode, &o->blob_oid, 1, &file->ptr, &file_size)) textconv_object(o->path, o->mode, &o->blob_oid, 1, &file->ptr, &file_size))
; ;
else else
file->ptr = read_sha1_file(o->blob_oid.hash, &type, file->ptr = read_object_file(&o->blob_oid, &type,
&file_size); &file_size);
file->size = file_size; file->size = file_size;
@@ -502,11 +502,9 @@ static int fill_blob_sha1_and_mode(struct blame_origin *origin)
{ {
if (!is_null_oid(&origin->blob_oid)) if (!is_null_oid(&origin->blob_oid))
return 0; return 0;
if (get_tree_entry(origin->commit->object.oid.hash, if (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
origin->path,
origin->blob_oid.hash, &origin->mode))
goto error_out; goto error_out;
if (sha1_object_info(origin->blob_oid.hash, NULL) != OBJ_BLOB) if (oid_object_info(&origin->blob_oid, NULL) != OBJ_BLOB)
goto error_out; goto error_out;
return 0; return 0;
error_out: error_out:
@@ -1831,7 +1829,7 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
&sb->final_buf_size)) &sb->final_buf_size))
; ;
else else
sb->final_buf = read_sha1_file(o->blob_oid.hash, &type, sb->final_buf = read_object_file(&o->blob_oid, &type,
&sb->final_buf_size); &sb->final_buf_size);
if (!sb->final_buf) if (!sb->final_buf)

View File

@@ -1550,7 +1550,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
discard_cache(); discard_cache();
read_cache_from(index_path); read_cache_from(index_path);
if (write_index_as_tree(orig_tree.hash, &the_index, index_path, 0, NULL)) if (write_index_as_tree(&orig_tree, &the_index, index_path, 0, NULL))
return error(_("Repository lacks necessary blobs to fall back on 3-way merge.")); return error(_("Repository lacks necessary blobs to fall back on 3-way merge."));
say(state, stdout, _("Using index info to reconstruct a base tree...")); say(state, stdout, _("Using index info to reconstruct a base tree..."));
@@ -1575,7 +1575,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
return error(_("Did you hand edit your patch?\n" return error(_("Did you hand edit your patch?\n"
"It does not apply to blobs recorded in its index.")); "It does not apply to blobs recorded in its index."));
if (write_index_as_tree(their_tree.hash, &the_index, index_path, 0, NULL)) if (write_index_as_tree(&their_tree, &the_index, index_path, 0, NULL))
return error("could not write tree"); return error("could not write tree");
say(state, stdout, _("Falling back to patching base and 3-way merge...")); say(state, stdout, _("Falling back to patching base and 3-way merge..."));
@@ -1626,7 +1626,7 @@ static void do_commit(const struct am_state *state)
if (run_hook_le(NULL, "pre-applypatch", NULL)) if (run_hook_le(NULL, "pre-applypatch", NULL))
exit(1); exit(1);
if (write_cache_as_tree(tree.hash, 0, NULL)) if (write_cache_as_tree(&tree, 0, NULL))
die(_("git write-tree failed to write a tree")); die(_("git write-tree failed to write a tree"));
if (!get_oid_commit("HEAD", &parent)) { if (!get_oid_commit("HEAD", &parent)) {
@@ -2004,7 +2004,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
if (fast_forward_to(head_tree, head_tree, 1)) if (fast_forward_to(head_tree, head_tree, 1))
return -1; return -1;
if (write_cache_as_tree(index.hash, 0, NULL)) if (write_cache_as_tree(&index, 0, NULL))
return -1; return -1;
index_tree = parse_tree_indirect(&index); index_tree = parse_tree_indirect(&index);

View File

@@ -499,7 +499,7 @@ static int read_ancestry(const char *graft_file)
static int update_auto_abbrev(int auto_abbrev, struct blame_origin *suspect) static int update_auto_abbrev(int auto_abbrev, struct blame_origin *suspect)
{ {
const char *uniq = find_unique_abbrev(suspect->commit->object.oid.hash, const char *uniq = find_unique_abbrev(&suspect->commit->object.oid,
auto_abbrev); auto_abbrev);
int len = strlen(uniq); int len = strlen(uniq);
if (auto_abbrev < len) if (auto_abbrev < len)
@@ -655,7 +655,7 @@ static int is_a_rev(const char *name)
if (get_oid(name, &oid)) if (get_oid(name, &oid))
return 0; return 0;
return OBJ_NONE < sha1_object_info(oid.hash, NULL); return OBJ_NONE < oid_object_info(&oid, NULL);
} }
int cmd_blame(int argc, const char **argv, const char *prefix) int cmd_blame(int argc, const char **argv, const char *prefix)

View File

@@ -273,7 +273,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
bname.buf, bname.buf,
(flags & REF_ISBROKEN) ? "broken" (flags & REF_ISBROKEN) ? "broken"
: (flags & REF_ISSYMREF) ? target : (flags & REF_ISSYMREF) ? target
: find_unique_abbrev(oid.hash, DEFAULT_ABBREV)); : find_unique_abbrev(&oid, DEFAULT_ABBREV));
} }
delete_branch_config(bname.buf); delete_branch_config(bname.buf);

View File

@@ -32,7 +32,7 @@ static int filter_object(const char *path, unsigned mode,
{ {
enum object_type type; enum object_type type;
*buf = read_sha1_file(oid->hash, &type, size); *buf = read_object_file(oid, &type, size);
if (!*buf) if (!*buf)
return error(_("cannot read object %s '%s'"), return error(_("cannot read object %s '%s'"),
oid_to_hex(oid), path); oid_to_hex(oid), path);
@@ -77,7 +77,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
switch (opt) { switch (opt) {
case 't': case 't':
oi.type_name = &sb; oi.type_name = &sb;
if (sha1_object_info_extended(oid.hash, &oi, flags) < 0) if (oid_object_info_extended(&oid, &oi, flags) < 0)
die("git cat-file: could not get object info"); die("git cat-file: could not get object info");
if (sb.len) { if (sb.len) {
printf("%s\n", sb.buf); printf("%s\n", sb.buf);
@@ -88,7 +88,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
case 's': case 's':
oi.sizep = &size; oi.sizep = &size;
if (sha1_object_info_extended(oid.hash, &oi, flags) < 0) if (oid_object_info_extended(&oid, &oi, flags) < 0)
die("git cat-file: could not get object info"); die("git cat-file: could not get object info");
printf("%lu\n", size); printf("%lu\n", size);
return 0; return 0;
@@ -116,7 +116,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
/* else fallthrough */ /* else fallthrough */
case 'p': case 'p':
type = sha1_object_info(oid.hash, NULL); type = oid_object_info(&oid, NULL);
if (type < 0) if (type < 0)
die("Not a valid object name %s", obj_name); die("Not a valid object name %s", obj_name);
@@ -130,7 +130,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
if (type == OBJ_BLOB) if (type == OBJ_BLOB)
return stream_blob_to_fd(1, &oid, NULL, 0); return stream_blob_to_fd(1, &oid, NULL, 0);
buf = read_sha1_file(oid.hash, &type, &size); buf = read_object_file(&oid, &type, &size);
if (!buf) if (!buf)
die("Cannot read object %s", obj_name); die("Cannot read object %s", obj_name);
@@ -140,8 +140,9 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
case 0: case 0:
if (type_from_string(exp_type) == OBJ_BLOB) { if (type_from_string(exp_type) == OBJ_BLOB) {
struct object_id blob_oid; struct object_id blob_oid;
if (sha1_object_info(oid.hash, NULL) == OBJ_TAG) { if (oid_object_info(&oid, NULL) == OBJ_TAG) {
char *buffer = read_sha1_file(oid.hash, &type, &size); char *buffer = read_object_file(&oid, &type,
&size);
const char *target; const char *target;
if (!skip_prefix(buffer, "object ", &target) || if (!skip_prefix(buffer, "object ", &target) ||
get_oid_hex(target, &blob_oid)) get_oid_hex(target, &blob_oid))
@@ -150,7 +151,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
} else } else
oidcpy(&blob_oid, &oid); oidcpy(&blob_oid, &oid);
if (sha1_object_info(blob_oid.hash, NULL) == OBJ_BLOB) if (oid_object_info(&blob_oid, NULL) == OBJ_BLOB)
return stream_blob_to_fd(1, &blob_oid, NULL, 0); return stream_blob_to_fd(1, &blob_oid, NULL, 0);
/* /*
* we attempted to dereference a tag to a blob * we attempted to dereference a tag to a blob
@@ -159,7 +160,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
* fall-back to the usual case. * fall-back to the usual case.
*/ */
} }
buf = read_object_with_reference(oid.hash, exp_type, &size, NULL); buf = read_object_with_reference(&oid, exp_type, &size, NULL);
break; break;
default: default:
@@ -304,7 +305,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
enum object_type type; enum object_type type;
if (!textconv_object(data->rest, 0100644, oid, if (!textconv_object(data->rest, 0100644, oid,
1, &contents, &size)) 1, &contents, &size))
contents = read_sha1_file(oid->hash, &type, contents = read_object_file(oid,
&type,
&size); &size);
if (!contents) if (!contents)
die("could not convert '%s' %s", die("could not convert '%s' %s",
@@ -321,7 +323,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
unsigned long size; unsigned long size;
void *contents; void *contents;
contents = read_sha1_file(oid->hash, &type, &size); contents = read_object_file(oid, &type, &size);
if (!contents) if (!contents)
die("object %s disappeared", oid_to_hex(oid)); die("object %s disappeared", oid_to_hex(oid));
if (type != data->type) if (type != data->type)
@@ -340,7 +342,7 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
if (!data->skip_object_info && if (!data->skip_object_info &&
sha1_object_info_extended(data->oid.hash, &data->info, oid_object_info_extended(&data->oid, &data->info,
OBJECT_INFO_LOOKUP_REPLACE) < 0) { OBJECT_INFO_LOOKUP_REPLACE) < 0) {
printf("%s missing\n", printf("%s missing\n",
obj_name ? obj_name : oid_to_hex(&data->oid)); obj_name ? obj_name : oid_to_hex(&data->oid));

View File

@@ -66,7 +66,7 @@ static int post_checkout_hook(struct commit *old_commit, struct commit *new_comm
} }
static int update_some(const unsigned char *sha1, struct strbuf *base, static int update_some(const struct object_id *oid, struct strbuf *base,
const char *pathname, unsigned mode, int stage, void *context) const char *pathname, unsigned mode, int stage, void *context)
{ {
int len; int len;
@@ -78,7 +78,7 @@ static int update_some(const unsigned char *sha1, struct strbuf *base,
len = base->len + strlen(pathname); len = base->len + strlen(pathname);
ce = xcalloc(1, cache_entry_size(len)); ce = xcalloc(1, cache_entry_size(len));
hashcpy(ce->oid.hash, sha1); oidcpy(&ce->oid, oid);
memcpy(ce->name, base->buf, base->len); memcpy(ce->name, base->buf, base->len);
memcpy(ce->name + base->len, pathname, len - base->len); memcpy(ce->name + base->len, pathname, len - base->len);
ce->ce_flags = create_ce_flags(0) | CE_UPDATE; ce->ce_flags = create_ce_flags(0) | CE_UPDATE;
@@ -405,10 +405,10 @@ static void describe_detached_head(const char *msg, struct commit *commit)
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb); pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
if (print_sha1_ellipsis()) { if (print_sha1_ellipsis()) {
fprintf(stderr, "%s %s... %s\n", msg, fprintf(stderr, "%s %s... %s\n", msg,
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf); find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV), sb.buf);
} else { } else {
fprintf(stderr, "%s %s %s\n", msg, fprintf(stderr, "%s %s %s\n", msg,
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf); find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV), sb.buf);
} }
strbuf_release(&sb); strbuf_release(&sb);
} }
@@ -720,7 +720,7 @@ static int add_pending_uninteresting_ref(const char *refname,
static void describe_one_orphan(struct strbuf *sb, struct commit *commit) static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
{ {
strbuf_addstr(sb, " "); strbuf_addstr(sb, " ");
strbuf_add_unique_abbrev(sb, commit->object.oid.hash, DEFAULT_ABBREV); strbuf_add_unique_abbrev(sb, &commit->object.oid, DEFAULT_ABBREV);
strbuf_addch(sb, ' '); strbuf_addch(sb, ' ');
if (!parse_commit(commit)) if (!parse_commit(commit))
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb); pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
@@ -778,7 +778,7 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
" git branch <new-branch-name> %s\n\n", " git branch <new-branch-name> %s\n\n",
/* Give ngettext() the count */ /* Give ngettext() the count */
lost), lost),
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV)); find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV));
} }
/* /*

View File

@@ -58,7 +58,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
usage(commit_tree_usage); usage(commit_tree_usage);
if (get_oid_commit(argv[i], &oid)) if (get_oid_commit(argv[i], &oid))
die("Not a valid object name %s", argv[i]); die("Not a valid object name %s", argv[i]);
assert_sha1_type(oid.hash, OBJ_COMMIT); assert_oid_type(&oid, OBJ_COMMIT);
new_parent(lookup_commit(&oid), &parents); new_parent(lookup_commit(&oid), &parents);
continue; continue;
} }

View File

@@ -285,7 +285,7 @@ static void append_name(struct commit_name *n, struct strbuf *dst)
static void append_suffix(int depth, const struct object_id *oid, struct strbuf *dst) static void append_suffix(int depth, const struct object_id *oid, struct strbuf *dst)
{ {
strbuf_addf(dst, "-%d-g%s", depth, find_unique_abbrev(oid->hash, abbrev)); strbuf_addf(dst, "-%d-g%s", depth, find_unique_abbrev(oid, abbrev));
} }
static void describe_commit(struct object_id *oid, struct strbuf *dst) static void describe_commit(struct object_id *oid, struct strbuf *dst)
@@ -383,7 +383,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
if (!match_cnt) { if (!match_cnt) {
struct object_id *cmit_oid = &cmit->object.oid; struct object_id *cmit_oid = &cmit->object.oid;
if (always) { if (always) {
strbuf_add_unique_abbrev(dst, cmit_oid->hash, abbrev); strbuf_add_unique_abbrev(dst, cmit_oid, abbrev);
if (suffix) if (suffix)
strbuf_addstr(dst, suffix); strbuf_addstr(dst, suffix);
return; return;
@@ -502,7 +502,7 @@ static void describe(const char *arg, int last_one)
if (cmit) if (cmit)
describe_commit(&oid, &sb); describe_commit(&oid, &sb);
else if (sha1_object_info(oid.hash, NULL) == OBJ_BLOB) else if (oid_object_info(&oid, NULL) == OBJ_BLOB)
describe_blob(oid, &sb); describe_blob(oid, &sb);
else else
die(_("%s is neither a commit nor blob"), arg); die(_("%s is neither a commit nor blob"), arg);

View File

@@ -306,7 +306,7 @@ static char *get_symlink(const struct object_id *oid, const char *path)
} else { } else {
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
data = read_sha1_file(oid->hash, &type, &size); data = read_object_file(oid, &type, &size);
if (!data) if (!data)
die(_("could not read object %s for symlink %s"), die(_("could not read object %s for symlink %s"),
oid_to_hex(oid), path); oid_to_hex(oid), path);

View File

@@ -237,10 +237,10 @@ static void export_blob(const struct object_id *oid)
object = (struct object *)lookup_blob(oid); object = (struct object *)lookup_blob(oid);
eaten = 0; eaten = 0;
} else { } else {
buf = read_sha1_file(oid->hash, &type, &size); buf = read_object_file(oid, &type, &size);
if (!buf) if (!buf)
die ("Could not read blob %s", oid_to_hex(oid)); die ("Could not read blob %s", oid_to_hex(oid));
if (check_sha1_signature(oid->hash, buf, size, type_name(type)) < 0) if (check_object_signature(oid, buf, size, type_name(type)) < 0)
die("sha1 mismatch in blob %s", oid_to_hex(oid)); die("sha1 mismatch in blob %s", oid_to_hex(oid));
object = parse_object_buffer(oid, type, size, buf, &eaten); object = parse_object_buffer(oid, type, size, buf, &eaten);
} }
@@ -682,7 +682,7 @@ static void handle_tag(const char *name, struct tag *tag)
return; return;
} }
buf = read_sha1_file(tag->object.oid.hash, &type, &size); buf = read_object_file(&tag->object.oid, &type, &size);
if (!buf) if (!buf)
die ("Could not read tag %s", oid_to_hex(&tag->object.oid)); die ("Could not read tag %s", oid_to_hex(&tag->object.oid));
message = memmem(buf, size, "\n\n", 2); message = memmem(buf, size, "\n\n", 2);
@@ -947,7 +947,7 @@ static void import_marks(char *input_file)
if (last_idnum < mark) if (last_idnum < mark)
last_idnum = mark; last_idnum = mark;
type = sha1_object_info(oid.hash, NULL); type = oid_object_info(&oid, NULL);
if (type < 0) if (type < 0)
die("object not found: %s", oid_to_hex(&oid)); die("object not found: %s", oid_to_hex(&oid));

View File

@@ -637,7 +637,7 @@ static int update_local_ref(struct ref *ref,
struct branch *current_branch = branch_get(NULL); struct branch *current_branch = branch_get(NULL);
const char *pretty_ref = prettify_refname(ref->name); const char *pretty_ref = prettify_refname(ref->name);
type = sha1_object_info(ref->new_oid.hash, NULL); type = oid_object_info(&ref->new_oid, NULL);
if (type < 0) if (type < 0)
die(_("object %s not found"), oid_to_hex(&ref->new_oid)); die(_("object %s not found"), oid_to_hex(&ref->new_oid));
@@ -708,9 +708,9 @@ static int update_local_ref(struct ref *ref,
if (in_merge_bases(current, updated)) { if (in_merge_bases(current, updated)) {
struct strbuf quickref = STRBUF_INIT; struct strbuf quickref = STRBUF_INIT;
int r; int r;
strbuf_add_unique_abbrev(&quickref, current->object.oid.hash, DEFAULT_ABBREV); strbuf_add_unique_abbrev(&quickref, &current->object.oid, DEFAULT_ABBREV);
strbuf_addstr(&quickref, ".."); strbuf_addstr(&quickref, "..");
strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash, DEFAULT_ABBREV); strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV);
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) && if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
(recurse_submodules != RECURSE_SUBMODULES_ON)) (recurse_submodules != RECURSE_SUBMODULES_ON))
check_for_new_submodule_commits(&ref->new_oid); check_for_new_submodule_commits(&ref->new_oid);
@@ -723,9 +723,9 @@ static int update_local_ref(struct ref *ref,
} else if (force || ref->force) { } else if (force || ref->force) {
struct strbuf quickref = STRBUF_INIT; struct strbuf quickref = STRBUF_INIT;
int r; int r;
strbuf_add_unique_abbrev(&quickref, current->object.oid.hash, DEFAULT_ABBREV); strbuf_add_unique_abbrev(&quickref, &current->object.oid, DEFAULT_ABBREV);
strbuf_addstr(&quickref, "..."); strbuf_addstr(&quickref, "...");
strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash, DEFAULT_ABBREV); strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV);
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) && if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
(recurse_submodules != RECURSE_SUBMODULES_ON)) (recurse_submodules != RECURSE_SUBMODULES_ON))
check_for_new_submodule_commits(&ref->new_oid); check_for_new_submodule_commits(&ref->new_oid);

View File

@@ -485,10 +485,10 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
struct strbuf tagbuf = STRBUF_INIT; struct strbuf tagbuf = STRBUF_INIT;
for (i = 0; i < origins.nr; i++) { for (i = 0; i < origins.nr; i++) {
unsigned char *sha1 = origins.items[i].util; struct object_id *oid = origins.items[i].util;
enum object_type type; enum object_type type;
unsigned long size, len; unsigned long size, len;
char *buf = read_sha1_file(sha1, &type, &size); char *buf = read_object_file(oid, &type, &size);
struct strbuf sig = STRBUF_INIT; struct strbuf sig = STRBUF_INIT;
if (!buf || type != OBJ_TAG) if (!buf || type != OBJ_TAG)

View File

@@ -65,7 +65,7 @@ static const char *printable_type(struct object *obj)
const char *ret; const char *ret;
if (obj->type == OBJ_NONE) { if (obj->type == OBJ_NONE) {
enum object_type type = sha1_object_info(obj->oid.hash, NULL); enum object_type type = oid_object_info(&obj->oid, NULL);
if (type > 0) if (type > 0)
object_as_type(obj, type, 0); object_as_type(obj, type, 0);
} }
@@ -513,7 +513,7 @@ static struct object *parse_loose_object(const struct object_id *oid,
unsigned long size; unsigned long size;
int eaten; int eaten;
if (read_loose_object(path, oid->hash, &type, &size, &contents) < 0) if (read_loose_object(path, oid, &type, &size, &contents) < 0)
return NULL; return NULL;
if (!contents && type != OBJ_BLOB) if (!contents && type != OBJ_BLOB)

View File

@@ -306,7 +306,7 @@ static void *lock_and_read_oid_file(const struct object_id *oid, enum object_typ
void *data; void *data;
grep_read_lock(); grep_read_lock();
data = read_sha1_file(oid->hash, type, size); data = read_object_file(oid, type, size);
grep_read_unlock(); grep_read_unlock();
return data; return data;
} }
@@ -452,7 +452,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
object = parse_object_or_die(oid, oid_to_hex(oid)); object = parse_object_or_die(oid, oid_to_hex(oid));
grep_read_lock(); grep_read_lock();
data = read_object_with_reference(object->oid.hash, tree_type, data = read_object_with_reference(&object->oid, tree_type,
&size, NULL); &size, NULL);
grep_read_unlock(); grep_read_unlock();
@@ -614,7 +614,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
int hit, len; int hit, len;
grep_read_lock(); grep_read_lock();
data = read_object_with_reference(obj->oid.hash, tree_type, data = read_object_with_reference(&obj->oid, tree_type,
&size, NULL); &size, NULL);
grep_read_unlock(); grep_read_unlock();

View File

@@ -59,7 +59,7 @@ struct ofs_delta_entry {
}; };
struct ref_delta_entry { struct ref_delta_entry {
unsigned char sha1[20]; struct object_id oid;
int obj_no; int obj_no;
}; };
@@ -222,7 +222,7 @@ static unsigned check_object(struct object *obj)
if (!(obj->flags & FLAG_CHECKED)) { if (!(obj->flags & FLAG_CHECKED)) {
unsigned long size; unsigned long size;
int type = sha1_object_info(obj->oid.hash, &size); int type = oid_object_info(&obj->oid, &size);
if (type <= 0) if (type <= 0)
die(_("did not receive expected object %s"), die(_("did not receive expected object %s"),
oid_to_hex(&obj->oid)); oid_to_hex(&obj->oid));
@@ -672,18 +672,18 @@ static void find_ofs_delta_children(off_t offset,
*last_index = last; *last_index = last;
} }
static int compare_ref_delta_bases(const unsigned char *sha1, static int compare_ref_delta_bases(const struct object_id *oid1,
const unsigned char *sha2, const struct object_id *oid2,
enum object_type type1, enum object_type type1,
enum object_type type2) enum object_type type2)
{ {
int cmp = type1 - type2; int cmp = type1 - type2;
if (cmp) if (cmp)
return cmp; return cmp;
return hashcmp(sha1, sha2); return oidcmp(oid1, oid2);
} }
static int find_ref_delta(const unsigned char *sha1, enum object_type type) static int find_ref_delta(const struct object_id *oid, enum object_type type)
{ {
int first = 0, last = nr_ref_deltas; int first = 0, last = nr_ref_deltas;
@@ -692,7 +692,7 @@ static int find_ref_delta(const unsigned char *sha1, enum object_type type)
struct ref_delta_entry *delta = &ref_deltas[next]; struct ref_delta_entry *delta = &ref_deltas[next];
int cmp; int cmp;
cmp = compare_ref_delta_bases(sha1, delta->sha1, cmp = compare_ref_delta_bases(oid, &delta->oid,
type, objects[delta->obj_no].type); type, objects[delta->obj_no].type);
if (!cmp) if (!cmp)
return next; return next;
@@ -705,11 +705,11 @@ static int find_ref_delta(const unsigned char *sha1, enum object_type type)
return -first-1; return -first-1;
} }
static void find_ref_delta_children(const unsigned char *sha1, static void find_ref_delta_children(const struct object_id *oid,
int *first_index, int *last_index, int *first_index, int *last_index,
enum object_type type) enum object_type type)
{ {
int first = find_ref_delta(sha1, type); int first = find_ref_delta(oid, type);
int last = first; int last = first;
int end = nr_ref_deltas - 1; int end = nr_ref_deltas - 1;
@@ -718,9 +718,9 @@ static void find_ref_delta_children(const unsigned char *sha1,
*last_index = -1; *last_index = -1;
return; return;
} }
while (first > 0 && !hashcmp(ref_deltas[first - 1].sha1, sha1)) while (first > 0 && !oidcmp(&ref_deltas[first - 1].oid, oid))
--first; --first;
while (last < end && !hashcmp(ref_deltas[last + 1].sha1, sha1)) while (last < end && !oidcmp(&ref_deltas[last + 1].oid, oid))
++last; ++last;
*first_index = first; *first_index = first;
*last_index = last; *last_index = last;
@@ -772,7 +772,7 @@ static int check_collison(struct object_entry *entry)
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
data.entry = entry; data.entry = entry;
data.st = open_istream(entry->idx.oid.hash, &type, &size, NULL); data.st = open_istream(&entry->idx.oid, &type, &size, NULL);
if (!data.st) if (!data.st)
return -1; return -1;
if (size != entry->size || type != entry->type) if (size != entry->size || type != entry->type)
@@ -811,12 +811,12 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
enum object_type has_type; enum object_type has_type;
unsigned long has_size; unsigned long has_size;
read_lock(); read_lock();
has_type = sha1_object_info(oid->hash, &has_size); has_type = oid_object_info(oid, &has_size);
if (has_type < 0) if (has_type < 0)
die(_("cannot read existing object info %s"), oid_to_hex(oid)); die(_("cannot read existing object info %s"), oid_to_hex(oid));
if (has_type != type || has_size != size) if (has_type != type || has_size != size)
die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid)); die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
has_data = read_sha1_file(oid->hash, &has_type, &has_size); has_data = read_object_file(oid, &has_type, &has_size);
read_unlock(); read_unlock();
if (!data) if (!data)
data = new_data = get_data_from_pack(obj_entry); data = new_data = get_data_from_pack(obj_entry);
@@ -992,7 +992,7 @@ static struct base_data *find_unresolved_deltas_1(struct base_data *base,
struct base_data *prev_base) struct base_data *prev_base)
{ {
if (base->ref_last == -1 && base->ofs_last == -1) { if (base->ref_last == -1 && base->ofs_last == -1) {
find_ref_delta_children(base->obj->idx.oid.hash, find_ref_delta_children(&base->obj->idx.oid,
&base->ref_first, &base->ref_last, &base->ref_first, &base->ref_last,
OBJ_REF_DELTA); OBJ_REF_DELTA);
@@ -1076,7 +1076,7 @@ static int compare_ref_delta_entry(const void *a, const void *b)
const struct ref_delta_entry *delta_a = a; const struct ref_delta_entry *delta_a = a;
const struct ref_delta_entry *delta_b = b; const struct ref_delta_entry *delta_b = b;
return hashcmp(delta_a->sha1, delta_b->sha1); return oidcmp(&delta_a->oid, &delta_b->oid);
} }
static void resolve_base(struct object_entry *obj) static void resolve_base(struct object_entry *obj)
@@ -1142,7 +1142,7 @@ static void parse_pack_objects(unsigned char *hash)
ofs_delta++; ofs_delta++;
} else if (obj->type == OBJ_REF_DELTA) { } else if (obj->type == OBJ_REF_DELTA) {
ALLOC_GROW(ref_deltas, nr_ref_deltas + 1, ref_deltas_alloc); ALLOC_GROW(ref_deltas, nr_ref_deltas + 1, ref_deltas_alloc);
hashcpy(ref_deltas[nr_ref_deltas].sha1, ref_delta_oid.hash); oidcpy(&ref_deltas[nr_ref_deltas].oid, &ref_delta_oid);
ref_deltas[nr_ref_deltas].obj_no = i; ref_deltas[nr_ref_deltas].obj_no = i;
nr_ref_deltas++; nr_ref_deltas++;
} else if (!data) { } else if (!data) {
@@ -1374,14 +1374,15 @@ static void fix_unresolved_deltas(struct hashfile *f)
if (objects[d->obj_no].real_type != OBJ_REF_DELTA) if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
continue; continue;
base_obj->data = read_sha1_file(d->sha1, &type, &base_obj->size); base_obj->data = read_object_file(&d->oid, &type,
&base_obj->size);
if (!base_obj->data) if (!base_obj->data)
continue; continue;
if (check_sha1_signature(d->sha1, base_obj->data, if (check_object_signature(&d->oid, base_obj->data,
base_obj->size, type_name(type))) base_obj->size, type_name(type)))
die(_("local object %s is corrupt"), sha1_to_hex(d->sha1)); die(_("local object %s is corrupt"), oid_to_hex(&d->oid));
base_obj->obj = append_obj_to_pack(f, d->sha1, base_obj->obj = append_obj_to_pack(f, d->oid.hash,
base_obj->data, base_obj->size, type); base_obj->data, base_obj->size, type);
find_unresolved_deltas(base_obj); find_unresolved_deltas(base_obj);
display_progress(progress, nr_resolved_deltas); display_progress(progress, nr_resolved_deltas);

View File

@@ -518,7 +518,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
{ {
unsigned long size; unsigned long size;
enum object_type type; enum object_type type;
char *buf = read_sha1_file(oid->hash, &type, &size); char *buf = read_object_file(oid, &type, &size);
int offset = 0; int offset = 0;
if (!buf) if (!buf)
@@ -541,7 +541,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
return 0; return 0;
} }
static int show_tree_object(const unsigned char *sha1, static int show_tree_object(const struct object_id *oid,
struct strbuf *base, struct strbuf *base,
const char *pathname, unsigned mode, int stage, void *context) const char *pathname, unsigned mode, int stage, void *context)
{ {
@@ -1873,12 +1873,12 @@ static void print_commit(char sign, struct commit *commit, int verbose,
{ {
if (!verbose) { if (!verbose) {
fprintf(file, "%c %s\n", sign, fprintf(file, "%c %s\n", sign,
find_unique_abbrev(commit->object.oid.hash, abbrev)); find_unique_abbrev(&commit->object.oid, abbrev));
} else { } else {
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf); pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
fprintf(file, "%c %s %s\n", sign, fprintf(file, "%c %s %s\n", sign,
find_unique_abbrev(commit->object.oid.hash, abbrev), find_unique_abbrev(&commit->object.oid, abbrev),
buf.buf); buf.buf);
strbuf_release(&buf); strbuf_release(&buf);
} }

View File

@@ -240,7 +240,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,
printf("%s%06o %s %d\t", printf("%s%06o %s %d\t",
tag, tag,
ce->ce_mode, ce->ce_mode,
find_unique_abbrev(ce->oid.hash, abbrev), find_unique_abbrev(&ce->oid, abbrev),
ce_stage(ce)); ce_stage(ce));
} }
write_eolinfo(repo->index, ce, fullname); write_eolinfo(repo->index, ce, fullname);
@@ -271,7 +271,7 @@ static void show_ru_info(const struct index_state *istate)
if (!ui->mode[i]) if (!ui->mode[i])
continue; continue;
printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i], printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i],
find_unique_abbrev(ui->sha1[i], abbrev), find_unique_abbrev(&ui->oid[i], abbrev),
i + 1); i + 1);
write_name(path); write_name(path);
} }

View File

@@ -60,7 +60,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
return 0; return 0;
} }
static int show_tree(const unsigned char *sha1, struct strbuf *base, static int show_tree(const struct object_id *oid, struct strbuf *base,
const char *pathname, unsigned mode, int stage, void *context) const char *pathname, unsigned mode, int stage, void *context)
{ {
int retval = 0; int retval = 0;
@@ -94,7 +94,7 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
char size_text[24]; char size_text[24];
if (!strcmp(type, blob_type)) { if (!strcmp(type, blob_type)) {
unsigned long size; unsigned long size;
if (sha1_object_info(sha1, &size) == OBJ_BAD) if (oid_object_info(oid, &size) == OBJ_BAD)
xsnprintf(size_text, sizeof(size_text), xsnprintf(size_text, sizeof(size_text),
"BAD"); "BAD");
else else
@@ -103,11 +103,11 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
} else } else
xsnprintf(size_text, sizeof(size_text), "-"); xsnprintf(size_text, sizeof(size_text), "-");
printf("%06o %s %s %7s\t", mode, type, printf("%06o %s %s %7s\t", mode, type,
find_unique_abbrev(sha1, abbrev), find_unique_abbrev(oid, abbrev),
size_text); size_text);
} else } else
printf("%06o %s %s\t", mode, type, printf("%06o %s %s\t", mode, type,
find_unique_abbrev(sha1, abbrev)); find_unique_abbrev(oid, abbrev));
} }
baselen = base->len; baselen = base->len;
strbuf_addstr(base, pathname); strbuf_addstr(base, pathname);

View File

@@ -60,7 +60,7 @@ static void *result(struct merge_list *entry, unsigned long *size)
const char *path = entry->path; const char *path = entry->path;
if (!entry->stage) if (!entry->stage)
return read_sha1_file(entry->blob->object.oid.hash, &type, size); return read_object_file(&entry->blob->object.oid, &type, size);
base = NULL; base = NULL;
if (entry->stage == 1) { if (entry->stage == 1) {
base = entry->blob; base = entry->blob;
@@ -82,7 +82,8 @@ static void *origin(struct merge_list *entry, unsigned long *size)
enum object_type type; enum object_type type;
while (entry) { while (entry) {
if (entry->stage == 2) if (entry->stage == 2)
return read_sha1_file(entry->blob->object.oid.hash, &type, size); return read_object_file(&entry->blob->object.oid,
&type, size);
entry = entry->link; entry = entry->link;
} }
return NULL; return NULL;

View File

@@ -639,7 +639,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
static void write_tree_trivial(struct object_id *oid) static void write_tree_trivial(struct object_id *oid)
{ {
if (write_cache_as_tree(oid->hash, 0, NULL)) if (write_cache_as_tree(oid, 0, NULL))
die(_("git write-tree failed to write a tree")); die(_("git write-tree failed to write a tree"));
} }
@@ -1324,7 +1324,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
check_commit_signature(commit, &signature_check); check_commit_signature(commit, &signature_check);
find_unique_abbrev_r(hex, commit->object.oid.hash, DEFAULT_ABBREV); find_unique_abbrev_r(hex, &commit->object.oid, DEFAULT_ABBREV);
switch (signature_check.result) { switch (signature_check.result) {
case 'G': case 'G':
break; break;
@@ -1417,9 +1417,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (verbosity >= 0) { if (verbosity >= 0) {
printf(_("Updating %s..%s\n"), printf(_("Updating %s..%s\n"),
find_unique_abbrev(head_commit->object.oid.hash, find_unique_abbrev(&head_commit->object.oid,
DEFAULT_ABBREV), DEFAULT_ABBREV),
find_unique_abbrev(remoteheads->item->object.oid.hash, find_unique_abbrev(&remoteheads->item->object.oid,
DEFAULT_ABBREV)); DEFAULT_ABBREV));
} }
strbuf_addstr(&msg, "Fast-forward"); strbuf_addstr(&msg, "Fast-forward");

View File

@@ -18,17 +18,17 @@
/* /*
* We refuse to tag something we can't verify. Just because. * We refuse to tag something we can't verify. Just because.
*/ */
static int verify_object(const unsigned char *sha1, const char *expected_type) static int verify_object(const struct object_id *oid, const char *expected_type)
{ {
int ret = -1; int ret = -1;
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
void *buffer = read_sha1_file(sha1, &type, &size); void *buffer = read_object_file(oid, &type, &size);
const unsigned char *repl = lookup_replace_object(sha1); const struct object_id *repl = lookup_replace_object(oid);
if (buffer) { if (buffer) {
if (type == type_from_string(expected_type)) if (type == type_from_string(expected_type))
ret = check_sha1_signature(repl, buffer, size, expected_type); ret = check_object_signature(repl, buffer, size, expected_type);
free(buffer); free(buffer);
} }
return ret; return ret;
@@ -38,8 +38,8 @@ static int verify_tag(char *buffer, unsigned long size)
{ {
int typelen; int typelen;
char type[20]; char type[20];
unsigned char sha1[20]; struct object_id oid;
const char *object, *type_line, *tag_line, *tagger_line, *lb, *rb; const char *object, *type_line, *tag_line, *tagger_line, *lb, *rb, *p;
size_t len; size_t len;
if (size < 84) if (size < 84)
@@ -52,11 +52,11 @@ static int verify_tag(char *buffer, unsigned long size)
if (memcmp(object, "object ", 7)) if (memcmp(object, "object ", 7))
return error("char%d: does not start with \"object \"", 0); return error("char%d: does not start with \"object \"", 0);
if (get_sha1_hex(object + 7, sha1)) if (parse_oid_hex(object + 7, &oid, &p))
return error("char%d: could not get SHA1 hash", 7); return error("char%d: could not get SHA1 hash", 7);
/* Verify type line */ /* Verify type line */
type_line = object + 48; type_line = p + 1;
if (memcmp(type_line - 1, "\ntype ", 6)) if (memcmp(type_line - 1, "\ntype ", 6))
return error("char%d: could not find \"\\ntype \"", 47); return error("char%d: could not find \"\\ntype \"", 47);
@@ -80,8 +80,8 @@ static int verify_tag(char *buffer, unsigned long size)
type[typelen] = 0; type[typelen] = 0;
/* Verify that the object matches */ /* Verify that the object matches */
if (verify_object(sha1, type)) if (verify_object(&oid, type))
return error("char%d: could not verify object %s", 7, sha1_to_hex(sha1)); return error("char%d: could not verify object %s", 7, oid_to_hex(&oid));
/* Verify the tag-name: we don't allow control characters or spaces in it */ /* Verify the tag-name: we don't allow control characters or spaces in it */
tag_line += 4; tag_line += 4;

View File

@@ -10,13 +10,13 @@
static struct treeent { static struct treeent {
unsigned mode; unsigned mode;
unsigned char sha1[20]; struct object_id oid;
int len; int len;
char name[FLEX_ARRAY]; char name[FLEX_ARRAY];
} **entries; } **entries;
static int alloc, used; static int alloc, used;
static void append_to_tree(unsigned mode, unsigned char *sha1, char *path) static void append_to_tree(unsigned mode, struct object_id *oid, char *path)
{ {
struct treeent *ent; struct treeent *ent;
size_t len = strlen(path); size_t len = strlen(path);
@@ -26,7 +26,7 @@ static void append_to_tree(unsigned mode, unsigned char *sha1, char *path)
FLEX_ALLOC_MEM(ent, name, path, len); FLEX_ALLOC_MEM(ent, name, path, len);
ent->mode = mode; ent->mode = mode;
ent->len = len; ent->len = len;
hashcpy(ent->sha1, sha1); oidcpy(&ent->oid, oid);
ALLOC_GROW(entries, used + 1, alloc); ALLOC_GROW(entries, used + 1, alloc);
entries[used++] = ent; entries[used++] = ent;
@@ -54,7 +54,7 @@ static void write_tree(struct object_id *oid)
for (i = 0; i < used; i++) { for (i = 0; i < used; i++) {
struct treeent *ent = entries[i]; struct treeent *ent = entries[i];
strbuf_addf(&buf, "%o %s%c", ent->mode, ent->name, '\0'); strbuf_addf(&buf, "%o %s%c", ent->mode, ent->name, '\0');
strbuf_add(&buf, ent->sha1, 20); strbuf_add(&buf, ent->oid.hash, the_hash_algo->rawsz);
} }
write_object_file(buf.buf, buf.len, tree_type, oid); write_object_file(buf.buf, buf.len, tree_type, oid);
@@ -69,11 +69,12 @@ static const char *mktree_usage[] = {
static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_missing) static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_missing)
{ {
char *ptr, *ntr; char *ptr, *ntr;
const char *p;
unsigned mode; unsigned mode;
enum object_type mode_type; /* object type derived from mode */ enum object_type mode_type; /* object type derived from mode */
enum object_type obj_type; /* object type derived from sha */ enum object_type obj_type; /* object type derived from sha */
char *path, *to_free = NULL; char *path, *to_free = NULL;
unsigned char sha1[20]; struct object_id oid;
ptr = buf; ptr = buf;
/* /*
@@ -85,9 +86,8 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
die("input format error: %s", buf); die("input format error: %s", buf);
ptr = ntr + 1; /* type */ ptr = ntr + 1; /* type */
ntr = strchr(ptr, ' '); ntr = strchr(ptr, ' ');
if (!ntr || buf + len <= ntr + 40 || if (!ntr || parse_oid_hex(ntr + 1, &oid, &p) ||
ntr[41] != '\t' || *p != '\t')
get_sha1_hex(ntr + 1, sha1))
die("input format error: %s", buf); die("input format error: %s", buf);
/* It is perfectly normal if we do not have a commit from a submodule */ /* It is perfectly normal if we do not have a commit from a submodule */
@@ -116,12 +116,12 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
} }
/* Check the type of object identified by sha1 */ /* Check the type of object identified by sha1 */
obj_type = sha1_object_info(sha1, NULL); obj_type = oid_object_info(&oid, NULL);
if (obj_type < 0) { if (obj_type < 0) {
if (allow_missing) { if (allow_missing) {
; /* no problem - missing objects are presumed to be of the right type */ ; /* no problem - missing objects are presumed to be of the right type */
} else { } else {
die("entry '%s' object %s is unavailable", path, sha1_to_hex(sha1)); die("entry '%s' object %s is unavailable", path, oid_to_hex(&oid));
} }
} else { } else {
if (obj_type != mode_type) { if (obj_type != mode_type) {
@@ -131,11 +131,11 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
* because the new tree entry will never be correct. * because the new tree entry will never be correct.
*/ */
die("entry '%s' object %s is a %s but specified type was (%s)", die("entry '%s' object %s is a %s but specified type was (%s)",
path, sha1_to_hex(sha1), type_name(obj_type), type_name(mode_type)); path, oid_to_hex(&oid), type_name(obj_type), type_name(mode_type));
} }
} }
append_to_tree(mode, sha1, path); append_to_tree(mode, &oid, path);
free(to_free); free(to_free);
} }

View File

@@ -328,7 +328,7 @@ static void show_name(const struct object *obj,
else if (allow_undefined) else if (allow_undefined)
printf("undefined\n"); printf("undefined\n");
else if (always) else if (always)
printf("%s\n", find_unique_abbrev(oid->hash, DEFAULT_ABBREV)); printf("%s\n", find_unique_abbrev(oid, DEFAULT_ABBREV));
else else
die("cannot describe '%s'", oid_to_hex(oid)); die("cannot describe '%s'", oid_to_hex(oid));
strbuf_release(&buf); strbuf_release(&buf);

View File

@@ -118,11 +118,11 @@ static int list_each_note(const struct object_id *object_oid,
return 0; return 0;
} }
static void copy_obj_to_fd(int fd, const unsigned char *sha1) static void copy_obj_to_fd(int fd, const struct object_id *oid)
{ {
unsigned long size; unsigned long size;
enum object_type type; enum object_type type;
char *buf = read_sha1_file(sha1, &type, &size); char *buf = read_object_file(oid, &type, &size);
if (buf) { if (buf) {
if (size) if (size)
write_or_die(fd, buf, size); write_or_die(fd, buf, size);
@@ -162,7 +162,7 @@ static void write_commented_object(int fd, const struct object_id *object)
} }
static void prepare_note_data(const struct object_id *object, struct note_data *d, static void prepare_note_data(const struct object_id *object, struct note_data *d,
const unsigned char *old_note) const struct object_id *old_note)
{ {
if (d->use_editor || !d->given) { if (d->use_editor || !d->given) {
int fd; int fd;
@@ -253,7 +253,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
if (get_oid(arg, &object)) if (get_oid(arg, &object))
die(_("failed to resolve '%s' as a valid ref."), arg); die(_("failed to resolve '%s' as a valid ref."), arg);
if (!(buf = read_sha1_file(object.hash, &type, &len))) { if (!(buf = read_object_file(&object, &type, &len))) {
free(buf); free(buf);
die(_("failed to read object '%s'."), arg); die(_("failed to read object '%s'."), arg);
} }
@@ -457,7 +457,7 @@ static int add(int argc, const char **argv, const char *prefix)
oid_to_hex(&object)); oid_to_hex(&object));
} }
prepare_note_data(&object, &d, note ? note->hash : NULL); prepare_note_data(&object, &d, note);
if (d.buf.len || allow_empty) { if (d.buf.len || allow_empty) {
write_note_data(&d, &new_note); write_note_data(&d, &new_note);
if (add_note(t, &object, &new_note, combine_notes_overwrite)) if (add_note(t, &object, &new_note, combine_notes_overwrite))
@@ -602,13 +602,13 @@ static int append_edit(int argc, const char **argv, const char *prefix)
t = init_notes_check(argv[0], NOTES_INIT_WRITABLE); t = init_notes_check(argv[0], NOTES_INIT_WRITABLE);
note = get_note(t, &object); note = get_note(t, &object);
prepare_note_data(&object, &d, edit && note ? note->hash : NULL); prepare_note_data(&object, &d, edit && note ? note : NULL);
if (note && !edit) { if (note && !edit) {
/* Append buf to previous note contents */ /* Append buf to previous note contents */
unsigned long size; unsigned long size;
enum object_type type; enum object_type type;
char *prev_buf = read_sha1_file(note->hash, &type, &size); char *prev_buf = read_object_file(note, &type, &size);
strbuf_grow(&d.buf, size + 1); strbuf_grow(&d.buf, size + 1);
if (d.buf.len && prev_buf && size) if (d.buf.len && prev_buf && size)

View File

@@ -122,11 +122,10 @@ static void *get_delta(struct object_entry *entry)
void *buf, *base_buf, *delta_buf; void *buf, *base_buf, *delta_buf;
enum object_type type; enum object_type type;
buf = read_sha1_file(entry->idx.oid.hash, &type, &size); buf = read_object_file(&entry->idx.oid, &type, &size);
if (!buf) if (!buf)
die("unable to read %s", oid_to_hex(&entry->idx.oid)); die("unable to read %s", oid_to_hex(&entry->idx.oid));
base_buf = read_sha1_file(entry->delta->idx.oid.hash, &type, base_buf = read_object_file(&entry->delta->idx.oid, &type, &base_size);
&base_size);
if (!base_buf) if (!base_buf)
die("unable to read %s", die("unable to read %s",
oid_to_hex(&entry->delta->idx.oid)); oid_to_hex(&entry->delta->idx.oid));
@@ -267,11 +266,10 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
if (!usable_delta) { if (!usable_delta) {
if (entry->type == OBJ_BLOB && if (entry->type == OBJ_BLOB &&
entry->size > big_file_threshold && entry->size > big_file_threshold &&
(st = open_istream(entry->idx.oid.hash, &type, &size, NULL)) != NULL) (st = open_istream(&entry->idx.oid, &type, &size, NULL)) != NULL)
buf = NULL; buf = NULL;
else { else {
buf = read_sha1_file(entry->idx.oid.hash, &type, buf = read_object_file(&entry->idx.oid, &type, &size);
&size);
if (!buf) if (!buf)
die(_("unable to read %s"), die(_("unable to read %s"),
oid_to_hex(&entry->idx.oid)); oid_to_hex(&entry->idx.oid));
@@ -1190,7 +1188,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
/* Did not find one. Either we got a bogus request or /* Did not find one. Either we got a bogus request or
* we need to read and perhaps cache. * we need to read and perhaps cache.
*/ */
data = read_sha1_file(oid->hash, &type, &size); data = read_object_file(oid, &type, &size);
if (!data) if (!data)
return NULL; return NULL;
if (type != OBJ_TREE) { if (type != OBJ_TREE) {
@@ -1351,7 +1349,7 @@ static void add_preferred_base(struct object_id *oid)
if (window <= num_preferred_base++) if (window <= num_preferred_base++)
return; return;
data = read_object_with_reference(oid->hash, tree_type, &size, tree_oid.hash); data = read_object_with_reference(oid, tree_type, &size, &tree_oid);
if (!data) if (!data)
return; return;
@@ -1516,7 +1514,7 @@ static void check_object(struct object_entry *entry)
unuse_pack(&w_curs); unuse_pack(&w_curs);
} }
entry->type = sha1_object_info(entry->idx.oid.hash, &entry->size); entry->type = oid_object_info(&entry->idx.oid, &entry->size);
/* /*
* The error condition is checked in prepare_pack(). This is * The error condition is checked in prepare_pack(). This is
* to permit a missing preferred base object to be ignored * to permit a missing preferred base object to be ignored
@@ -1578,8 +1576,7 @@ static void drop_reused_delta(struct object_entry *entry)
* And if that fails, the error will be recorded in entry->type * And if that fails, the error will be recorded in entry->type
* and dealt with in prepare_pack(). * and dealt with in prepare_pack().
*/ */
entry->type = sha1_object_info(entry->idx.oid.hash, entry->type = oid_object_info(&entry->idx.oid, &entry->size);
&entry->size);
} }
} }
@@ -1871,8 +1868,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
/* Load data if not already done */ /* Load data if not already done */
if (!trg->data) { if (!trg->data) {
read_lock(); read_lock();
trg->data = read_sha1_file(trg_entry->idx.oid.hash, &type, trg->data = read_object_file(&trg_entry->idx.oid, &type, &sz);
&sz);
read_unlock(); read_unlock();
if (!trg->data) if (!trg->data)
die("object %s cannot be read", die("object %s cannot be read",
@@ -1885,8 +1881,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
} }
if (!src->data) { if (!src->data) {
read_lock(); read_lock();
src->data = read_sha1_file(src_entry->idx.oid.hash, &type, src->data = read_object_file(&src_entry->idx.oid, &type, &sz);
&sz);
read_unlock(); read_unlock();
if (!src->data) { if (!src->data) {
if (src_entry->preferred_base) { if (src_entry->preferred_base) {
@@ -2709,7 +2704,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
static int add_loose_object(const struct object_id *oid, const char *path, static int add_loose_object(const struct object_id *oid, const char *path,
void *data) void *data)
{ {
enum object_type type = sha1_object_info(oid->hash, NULL); enum object_type type = oid_object_info(oid, NULL);
if (type < 0) { if (type < 0) {
warning("loose object at %s could not be examined", path); warning("loose object at %s could not be examined", path);

View File

@@ -50,7 +50,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
if (st.st_mtime > expire) if (st.st_mtime > expire)
return 0; return 0;
if (show_only || verbose) { if (show_only || verbose) {
enum object_type type = sha1_object_info(oid->hash, NULL); enum object_type type = oid_object_info(oid, NULL);
printf("%s %s\n", oid_to_hex(oid), printf("%s %s\n", oid_to_hex(oid),
(type > 0) ? type_name(type) : "unknown"); (type > 0) ? type_name(type) : "unknown");
} }

View File

@@ -1242,11 +1242,11 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
rp_error("refusing inconsistent update between symref '%s' (%s..%s) and" rp_error("refusing inconsistent update between symref '%s' (%s..%s) and"
" its target '%s' (%s..%s)", " its target '%s' (%s..%s)",
cmd->ref_name, cmd->ref_name,
find_unique_abbrev(cmd->old_oid.hash, DEFAULT_ABBREV), find_unique_abbrev(&cmd->old_oid, DEFAULT_ABBREV),
find_unique_abbrev(cmd->new_oid.hash, DEFAULT_ABBREV), find_unique_abbrev(&cmd->new_oid, DEFAULT_ABBREV),
dst_cmd->ref_name, dst_cmd->ref_name,
find_unique_abbrev(dst_cmd->old_oid.hash, DEFAULT_ABBREV), find_unique_abbrev(&dst_cmd->old_oid, DEFAULT_ABBREV),
find_unique_abbrev(dst_cmd->new_oid.hash, DEFAULT_ABBREV)); find_unique_abbrev(&dst_cmd->new_oid, DEFAULT_ABBREV));
cmd->error_string = dst_cmd->error_string = cmd->error_string = dst_cmd->error_string =
"inconsistent aliased update"; "inconsistent aliased update";

View File

@@ -75,7 +75,7 @@ static int tree_is_complete(const struct object_id *oid)
if (!tree->buffer) { if (!tree->buffer) {
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
void *data = read_sha1_file(oid->hash, &type, &size); void *data = read_object_file(oid, &type, &size);
if (!data) { if (!data) {
tree->object.flags |= INCOMPLETE; tree->object.flags |= INCOMPLETE;
return 0; return 0;

View File

@@ -53,8 +53,8 @@ static int show_reference(const char *refname, const struct object_id *oid,
if (get_oid(refname, &object)) if (get_oid(refname, &object))
return error("Failed to resolve '%s' as a valid ref.", refname); return error("Failed to resolve '%s' as a valid ref.", refname);
obj_type = sha1_object_info(object.hash, NULL); obj_type = oid_object_info(&object, NULL);
repl_type = sha1_object_info(oid->hash, NULL); repl_type = oid_object_info(oid, NULL);
printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type), printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type),
oid_to_hex(oid), type_name(repl_type)); oid_to_hex(oid), type_name(repl_type));
@@ -162,8 +162,8 @@ static int replace_object_oid(const char *object_ref,
struct ref_transaction *transaction; struct ref_transaction *transaction;
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
obj_type = sha1_object_info(object->hash, NULL); obj_type = oid_object_info(object, NULL);
repl_type = sha1_object_info(repl->hash, NULL); repl_type = oid_object_info(repl, NULL);
if (!force && obj_type != repl_type) if (!force && obj_type != repl_type)
die("Objects must be of the same type.\n" die("Objects must be of the same type.\n"
"'%s' points to a replaced object of type '%s'\n" "'%s' points to a replaced object of type '%s'\n"
@@ -290,7 +290,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
if (get_oid(object_ref, &old_oid) < 0) if (get_oid(object_ref, &old_oid) < 0)
die("Not a valid object name: '%s'", object_ref); die("Not a valid object name: '%s'", object_ref);
type = sha1_object_info(old_oid.hash, NULL); type = oid_object_info(&old_oid, NULL);
if (type < 0) if (type < 0)
die("unable to get object type for %s", oid_to_hex(&old_oid)); die("unable to get object type for %s", oid_to_hex(&old_oid));

View File

@@ -109,7 +109,7 @@ static void print_new_head_line(struct commit *commit)
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
printf(_("HEAD is now at %s"), printf(_("HEAD is now at %s"),
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV)); find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV));
pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf); pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
if (buf.len > 0) if (buf.len > 0)

View File

@@ -108,7 +108,7 @@ static void show_commit(struct commit *commit, void *data)
if (!revs->graph) if (!revs->graph)
fputs(get_revision_mark(revs, commit), stdout); fputs(get_revision_mark(revs, commit), stdout);
if (revs->abbrev_commit && revs->abbrev) if (revs->abbrev_commit && revs->abbrev)
fputs(find_unique_abbrev(commit->object.oid.hash, revs->abbrev), fputs(find_unique_abbrev(&commit->object.oid, revs->abbrev),
stdout); stdout);
else else
fputs(oid_to_hex(&commit->object.oid), stdout); fputs(oid_to_hex(&commit->object.oid), stdout);

View File

@@ -159,7 +159,7 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
} }
} }
else if (abbrev) else if (abbrev)
show_with_type(type, find_unique_abbrev(oid->hash, abbrev)); show_with_type(type, find_unique_abbrev(oid, abbrev));
else else
show_with_type(type, oid_to_hex(oid)); show_with_type(type, oid_to_hex(oid));
} }

View File

@@ -178,7 +178,7 @@ static int check_local_mod(struct object_id *head, int index_only)
* way as changed from the HEAD. * way as changed from the HEAD.
*/ */
if (no_head if (no_head
|| get_tree_entry(head->hash, name, oid.hash, &mode) || get_tree_entry(head, name, &oid, &mode)
|| ce->ce_mode != create_ce_mode(mode) || ce->ce_mode != create_ce_mode(mode)
|| oidcmp(&ce->oid, &oid)) || oidcmp(&ce->oid, &oid))
staged_changes = 1; staged_changes = 1;

View File

@@ -292,7 +292,7 @@ static void show_one_commit(struct commit *commit, int no_name)
} }
else else
printf("[%s] ", printf("[%s] ",
find_unique_abbrev(commit->object.oid.hash, find_unique_abbrev(&commit->object.oid,
DEFAULT_ABBREV)); DEFAULT_ABBREV));
} }
puts(pretty_str); puts(pretty_str);

View File

@@ -29,7 +29,7 @@ static void show_one(const char *refname, const struct object_id *oid)
if (quiet) if (quiet)
return; return;
hex = find_unique_abbrev(oid->hash, abbrev); hex = find_unique_abbrev(oid, abbrev);
if (hash_only) if (hash_only)
printf("%s\n", hex); printf("%s\n", hex);
else else
@@ -39,7 +39,7 @@ static void show_one(const char *refname, const struct object_id *oid)
return; return;
if (!peel_ref(refname, &peeled)) { if (!peel_ref(refname, &peeled)) {
hex = find_unique_abbrev(peeled.hash, abbrev); hex = find_unique_abbrev(&peeled, abbrev);
printf("%s %s^{}\n", hex, refname); printf("%s %s^{}\n", hex, refname);
} }
} }

View File

@@ -99,7 +99,8 @@ static int delete_tag(const char *name, const char *ref,
{ {
if (delete_ref(NULL, ref, oid, 0)) if (delete_ref(NULL, ref, oid, 0))
return 1; return 1;
printf(_("Deleted tag '%s' (was %s)\n"), name, find_unique_abbrev(oid->hash, DEFAULT_ABBREV)); printf(_("Deleted tag '%s' (was %s)\n"), name,
find_unique_abbrev(oid, DEFAULT_ABBREV));
return 0; return 0;
} }
@@ -167,7 +168,7 @@ static void write_tag_body(int fd, const struct object_id *oid)
enum object_type type; enum object_type type;
char *buf, *sp; char *buf, *sp;
buf = read_sha1_file(oid->hash, &type, &size); buf = read_object_file(oid, &type, &size);
if (!buf) if (!buf)
return; return;
/* skip header */ /* skip header */
@@ -211,7 +212,7 @@ static void create_tag(const struct object_id *object, const char *tag,
struct strbuf header = STRBUF_INIT; struct strbuf header = STRBUF_INIT;
char *path = NULL; char *path = NULL;
type = sha1_object_info(object->hash, NULL); type = oid_object_info(object, NULL);
if (type <= OBJ_NONE) if (type <= OBJ_NONE)
die(_("bad object type.")); die(_("bad object type."));
@@ -293,17 +294,17 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
strbuf_addstr(sb, rla); strbuf_addstr(sb, rla);
} else { } else {
strbuf_addstr(sb, "tag: tagging "); strbuf_addstr(sb, "tag: tagging ");
strbuf_add_unique_abbrev(sb, oid->hash, DEFAULT_ABBREV); strbuf_add_unique_abbrev(sb, oid, DEFAULT_ABBREV);
} }
strbuf_addstr(sb, " ("); strbuf_addstr(sb, " (");
type = sha1_object_info(oid->hash, NULL); type = oid_object_info(oid, NULL);
switch (type) { switch (type) {
default: default:
strbuf_addstr(sb, "object of unknown type"); strbuf_addstr(sb, "object of unknown type");
break; break;
case OBJ_COMMIT: case OBJ_COMMIT:
if ((buf = read_sha1_file(oid->hash, &type, &size)) != NULL) { if ((buf = read_object_file(oid, &type, &size)) != NULL) {
subject_len = find_commit_subject(buf, &subject_start); subject_len = find_commit_subject(buf, &subject_start);
strbuf_insert(sb, sb->len, subject_start, subject_len); strbuf_insert(sb, sb->len, subject_start, subject_len);
} else { } else {
@@ -558,7 +559,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
die("%s", err.buf); die("%s", err.buf);
ref_transaction_free(transaction); ref_transaction_free(transaction);
if (force && !is_null_oid(&prev) && oidcmp(&prev, &object)) if (force && !is_null_oid(&prev) && oidcmp(&prev, &object))
printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev.hash, DEFAULT_ABBREV)); printf(_("Updated tag '%s' (was %s)\n"), tag,
find_unique_abbrev(&prev, DEFAULT_ABBREV));
UNLEAK(buf); UNLEAK(buf);
UNLEAK(ref); UNLEAK(ref);

View File

@@ -9,7 +9,7 @@ static char *create_temp_file(struct object_id *oid)
unsigned long size; unsigned long size;
int fd; int fd;
buf = read_sha1_file(oid->hash, &type, &size); buf = read_object_file(oid, &type, &size);
if (!buf || type != OBJ_BLOB) if (!buf || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid)); die("unable to read blob object %s", oid_to_hex(oid));

View File

@@ -199,7 +199,7 @@ static int check_object(struct object *obj, int type, void *data, struct fsck_op
if (!(obj->flags & FLAG_OPEN)) { if (!(obj->flags & FLAG_OPEN)) {
unsigned long size; unsigned long size;
int type = sha1_object_info(obj->oid.hash, &size); int type = oid_object_info(&obj->oid, &size);
if (type != obj->type || type <= 0) if (type != obj->type || type <= 0)
die("object of unexpected type"); die("object of unexpected type");
obj->flags |= FLAG_WRITTEN; obj->flags |= FLAG_WRITTEN;
@@ -423,7 +423,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
if (resolve_against_held(nr, &base_oid, delta_data, delta_size)) if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
return; return;
base = read_sha1_file(base_oid.hash, &type, &base_size); base = read_object_file(&base_oid, &type, &base_size);
if (!base) { if (!base) {
error("failed to read delta-pack base object %s", error("failed to read delta-pack base object %s",
oid_to_hex(&base_oid)); oid_to_hex(&base_oid));

View File

@@ -592,7 +592,7 @@ static struct cache_entry *read_one_ent(const char *which,
int size; int size;
struct cache_entry *ce; struct cache_entry *ce;
if (get_tree_entry(ent->hash, path, oid.hash, &mode)) { if (get_tree_entry(ent, path, &oid, &mode)) {
if (which) if (which)
error("%s: not in %s branch.", path, which); error("%s: not in %s branch.", path, which);
return NULL; return NULL;

View File

@@ -44,7 +44,7 @@ static int verify_commit(const char *name, unsigned flags)
if (get_oid(name, &oid)) if (get_oid(name, &oid))
return error("commit '%s' not found.", name); return error("commit '%s' not found.", name);
buf = read_sha1_file(oid.hash, &type, &size); buf = read_object_file(&oid, &type, &size);
if (!buf) if (!buf)
return error("%s: unable to read file.", name); return error("%s: unable to read file.", name);
if (type != OBJ_COMMIT) if (type != OBJ_COMMIT)

View File

@@ -502,7 +502,7 @@ static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len)
strbuf_addstr(&sb, "(bare)"); strbuf_addstr(&sb, "(bare)");
else { else {
strbuf_addf(&sb, "%-*s ", abbrev_len, strbuf_addf(&sb, "%-*s ", abbrev_len,
find_unique_abbrev(wt->head_oid.hash, DEFAULT_ABBREV)); find_unique_abbrev(&wt->head_oid, DEFAULT_ABBREV));
if (wt->is_detached) if (wt->is_detached)
strbuf_addstr(&sb, "(detached HEAD)"); strbuf_addstr(&sb, "(detached HEAD)");
else if (wt->head_ref) { else if (wt->head_ref) {
@@ -527,7 +527,7 @@ static void measure_widths(struct worktree **wt, int *abbrev, int *maxlen)
if (path_len > *maxlen) if (path_len > *maxlen)
*maxlen = path_len; *maxlen = path_len;
sha1_len = strlen(find_unique_abbrev(wt[i]->head_oid.hash, *abbrev)); sha1_len = strlen(find_unique_abbrev(&wt[i]->head_oid, *abbrev));
if (sha1_len > *abbrev) if (sha1_len > *abbrev)
*abbrev = sha1_len; *abbrev = sha1_len;
} }

View File

@@ -19,7 +19,7 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
{ {
int flags = 0, ret; int flags = 0, ret;
const char *prefix = NULL; const char *prefix = NULL;
unsigned char sha1[20]; struct object_id oid;
const char *me = "git-write-tree"; const char *me = "git-write-tree";
struct option write_tree_options[] = { struct option write_tree_options[] = {
OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"), OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"),
@@ -38,10 +38,10 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
argc = parse_options(argc, argv, unused_prefix, write_tree_options, argc = parse_options(argc, argv, unused_prefix, write_tree_options,
write_tree_usage, 0); write_tree_usage, 0);
ret = write_cache_as_tree(sha1, flags, prefix); ret = write_cache_as_tree(&oid, flags, prefix);
switch (ret) { switch (ret) {
case 0: case 0:
printf("%s\n", sha1_to_hex(sha1)); printf("%s\n", oid_to_hex(&oid));
break; break;
case WRITE_TREE_UNREADABLE_INDEX: case WRITE_TREE_UNREADABLE_INDEX:
die("%s: error reading the index", me); die("%s: error reading the index", me);

View File

@@ -60,17 +60,17 @@ clear_exit:
reprepare_packed_git(); reprepare_packed_git();
} }
static int already_written(struct bulk_checkin_state *state, unsigned char sha1[]) static int already_written(struct bulk_checkin_state *state, struct object_id *oid)
{ {
int i; int i;
/* The object may already exist in the repository */ /* The object may already exist in the repository */
if (has_sha1_file(sha1)) if (has_sha1_file(oid->hash))
return 1; return 1;
/* Might want to keep the list sorted */ /* Might want to keep the list sorted */
for (i = 0; i < state->nr_written; i++) for (i = 0; i < state->nr_written; i++)
if (!hashcmp(state->written[i]->oid.hash, sha1)) if (!oidcmp(&state->written[i]->oid, oid))
return 1; return 1;
/* This is a new object we need to keep */ /* This is a new object we need to keep */
@@ -186,7 +186,7 @@ static void prepare_to_stream(struct bulk_checkin_state *state,
} }
static int deflate_to_pack(struct bulk_checkin_state *state, static int deflate_to_pack(struct bulk_checkin_state *state,
unsigned char result_sha1[], struct object_id *result_oid,
int fd, size_t size, int fd, size_t size,
enum object_type type, const char *path, enum object_type type, const char *path,
unsigned flags) unsigned flags)
@@ -236,17 +236,17 @@ static int deflate_to_pack(struct bulk_checkin_state *state,
if (lseek(fd, seekback, SEEK_SET) == (off_t) -1) if (lseek(fd, seekback, SEEK_SET) == (off_t) -1)
return error("cannot seek back"); return error("cannot seek back");
} }
the_hash_algo->final_fn(result_sha1, &ctx); the_hash_algo->final_fn(result_oid->hash, &ctx);
if (!idx) if (!idx)
return 0; return 0;
idx->crc32 = crc32_end(state->f); idx->crc32 = crc32_end(state->f);
if (already_written(state, result_sha1)) { if (already_written(state, result_oid)) {
hashfile_truncate(state->f, &checkpoint); hashfile_truncate(state->f, &checkpoint);
state->offset = checkpoint.offset; state->offset = checkpoint.offset;
free(idx); free(idx);
} else { } else {
hashcpy(idx->oid.hash, result_sha1); oidcpy(&idx->oid, result_oid);
ALLOC_GROW(state->written, ALLOC_GROW(state->written,
state->nr_written + 1, state->nr_written + 1,
state->alloc_written); state->alloc_written);
@@ -255,11 +255,11 @@ static int deflate_to_pack(struct bulk_checkin_state *state,
return 0; return 0;
} }
int index_bulk_checkin(unsigned char *sha1, int index_bulk_checkin(struct object_id *oid,
int fd, size_t size, enum object_type type, int fd, size_t size, enum object_type type,
const char *path, unsigned flags) const char *path, unsigned flags)
{ {
int status = deflate_to_pack(&state, sha1, fd, size, type, int status = deflate_to_pack(&state, oid, fd, size, type,
path, flags); path, flags);
if (!state.plugged) if (!state.plugged)
finish_bulk_checkin(&state); finish_bulk_checkin(&state);

View File

@@ -4,7 +4,7 @@
#ifndef BULK_CHECKIN_H #ifndef BULK_CHECKIN_H
#define BULK_CHECKIN_H #define BULK_CHECKIN_H
extern int index_bulk_checkin(unsigned char sha1[], extern int index_bulk_checkin(struct object_id *oid,
int fd, size_t size, enum object_type type, int fd, size_t size, enum object_type type,
const char *path, unsigned flags); const char *path, unsigned flags);

View File

@@ -222,7 +222,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
if (revs->max_age == -1 && revs->min_age == -1) if (revs->max_age == -1 && revs->min_age == -1)
goto out; goto out;
buf = read_sha1_file(tag->oid.hash, &type, &size); buf = read_object_file(&tag->oid, &type, &size);
if (!buf) if (!buf)
goto out; goto out;
line = memmem(buf, size, "\ntagger ", 8); line = memmem(buf, size, "\ntagger ", 8);

View File

@@ -320,7 +320,7 @@ static int update_one(struct cache_tree *it,
struct cache_tree_sub *sub = NULL; struct cache_tree_sub *sub = NULL;
const char *path, *slash; const char *path, *slash;
int pathlen, entlen; int pathlen, entlen;
const unsigned char *sha1; const struct object_id *oid;
unsigned mode; unsigned mode;
int expected_missing = 0; int expected_missing = 0;
int contains_ita = 0; int contains_ita = 0;
@@ -338,7 +338,7 @@ static int update_one(struct cache_tree *it,
die("cache-tree.c: '%.*s' in '%s' not found", die("cache-tree.c: '%.*s' in '%s' not found",
entlen, path + baselen, path); entlen, path + baselen, path);
i += sub->count; i += sub->count;
sha1 = sub->cache_tree->oid.hash; oid = &sub->cache_tree->oid;
mode = S_IFDIR; mode = S_IFDIR;
contains_ita = sub->cache_tree->entry_count < 0; contains_ita = sub->cache_tree->entry_count < 0;
if (contains_ita) { if (contains_ita) {
@@ -347,19 +347,19 @@ static int update_one(struct cache_tree *it,
} }
} }
else { else {
sha1 = ce->oid.hash; oid = &ce->oid;
mode = ce->ce_mode; mode = ce->ce_mode;
entlen = pathlen - baselen; entlen = pathlen - baselen;
i++; i++;
} }
if (is_null_sha1(sha1) || if (is_null_oid(oid) ||
(mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1))) { (mode != S_IFGITLINK && !missing_ok && !has_object_file(oid))) {
strbuf_release(&buffer); strbuf_release(&buffer);
if (expected_missing) if (expected_missing)
return -1; return -1;
return error("invalid object %06o %s for '%.*s'", return error("invalid object %06o %s for '%.*s'",
mode, sha1_to_hex(sha1), entlen+baselen, path); mode, oid_to_hex(oid), entlen+baselen, path);
} }
/* /*
@@ -385,12 +385,12 @@ static int update_one(struct cache_tree *it,
/* /*
* "sub" can be an empty tree if all subentries are i-t-a. * "sub" can be an empty tree if all subentries are i-t-a.
*/ */
if (contains_ita && !hashcmp(sha1, EMPTY_TREE_SHA1_BIN)) if (contains_ita && !oidcmp(oid, &empty_tree_oid))
continue; continue;
strbuf_grow(&buffer, entlen + 100); strbuf_grow(&buffer, entlen + 100);
strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0'); strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0');
strbuf_add(&buffer, sha1, 20); strbuf_add(&buffer, oid->hash, the_hash_algo->rawsz);
#if DEBUG #if DEBUG
fprintf(stderr, "cache-tree update-one %o %.*s\n", fprintf(stderr, "cache-tree update-one %o %.*s\n",
@@ -401,7 +401,7 @@ static int update_one(struct cache_tree *it,
if (repair) { if (repair) {
struct object_id oid; struct object_id oid;
hash_object_file(buffer.buf, buffer.len, tree_type, &oid); hash_object_file(buffer.buf, buffer.len, tree_type, &oid);
if (has_sha1_file(oid.hash)) if (has_object_file(&oid))
oidcpy(&it->oid, &oid); oidcpy(&it->oid, &oid);
else else
to_invalidate = 1; to_invalidate = 1;
@@ -465,7 +465,7 @@ static void write_one(struct strbuf *buffer, struct cache_tree *it,
#endif #endif
if (0 <= it->entry_count) { if (0 <= it->entry_count) {
strbuf_add(buffer, it->oid.hash, 20); strbuf_add(buffer, it->oid.hash, the_hash_algo->rawsz);
} }
for (i = 0; i < it->subtree_nr; i++) { for (i = 0; i < it->subtree_nr; i++) {
struct cache_tree_sub *down = it->down[i]; struct cache_tree_sub *down = it->down[i];
@@ -492,6 +492,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
char *ep; char *ep;
struct cache_tree *it; struct cache_tree *it;
int i, subtree_nr; int i, subtree_nr;
const unsigned rawsz = the_hash_algo->rawsz;
it = NULL; it = NULL;
/* skip name, but make sure name exists */ /* skip name, but make sure name exists */
@@ -520,11 +521,11 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
goto free_return; goto free_return;
buf++; size--; buf++; size--;
if (0 <= it->entry_count) { if (0 <= it->entry_count) {
if (size < 20) if (size < rawsz)
goto free_return; goto free_return;
hashcpy(it->oid.hash, (const unsigned char*)buf); memcpy(it->oid.hash, (const unsigned char*)buf, rawsz);
buf += 20; buf += rawsz;
size -= 20; size -= rawsz;
} }
#if DEBUG #if DEBUG
@@ -599,7 +600,7 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat
return it; return it;
} }
int write_index_as_tree(unsigned char *sha1, struct index_state *index_state, const char *index_path, int flags, const char *prefix) int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix)
{ {
int entries, was_valid; int entries, was_valid;
struct lock_file lock_file = LOCK_INIT; struct lock_file lock_file = LOCK_INIT;
@@ -640,19 +641,19 @@ int write_index_as_tree(unsigned char *sha1, struct index_state *index_state, co
ret = WRITE_TREE_PREFIX_ERROR; ret = WRITE_TREE_PREFIX_ERROR;
goto out; goto out;
} }
hashcpy(sha1, subtree->oid.hash); oidcpy(oid, &subtree->oid);
} }
else else
hashcpy(sha1, index_state->cache_tree->oid.hash); oidcpy(oid, &index_state->cache_tree->oid);
out: out:
rollback_lock_file(&lock_file); rollback_lock_file(&lock_file);
return ret; return ret;
} }
int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix) int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix)
{ {
return write_index_as_tree(sha1, &the_index, get_index_file(), flags, prefix); return write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix);
} }
static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree) static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)

View File

@@ -47,8 +47,8 @@ int update_main_cache_tree(int);
#define WRITE_TREE_UNMERGED_INDEX (-2) #define WRITE_TREE_UNMERGED_INDEX (-2)
#define WRITE_TREE_PREFIX_ERROR (-3) #define WRITE_TREE_PREFIX_ERROR (-3)
int write_index_as_tree(unsigned char *sha1, struct index_state *index_state, const char *index_path, int flags, const char *prefix); int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix);
int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix); int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix);
void prime_cache_tree(struct index_state *, struct tree *); void prime_cache_tree(struct index_state *, struct tree *);
extern int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info); extern int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);

38
cache.h
View File

@@ -955,14 +955,14 @@ extern void sha1_file_name(struct strbuf *buf, const unsigned char *sha1);
* more calls to find_unique_abbrev are made. * more calls to find_unique_abbrev are made.
* *
* The `_r` variant writes to a buffer supplied by the caller, which must be at * The `_r` variant writes to a buffer supplied by the caller, which must be at
* least `GIT_SHA1_HEXSZ + 1` bytes. The return value is the number of bytes * least `GIT_MAX_HEXSZ + 1` bytes. The return value is the number of bytes
* written (excluding the NUL terminator). * written (excluding the NUL terminator).
* *
* Note that while this version avoids the static buffer, it is not fully * Note that while this version avoids the static buffer, it is not fully
* reentrant, as it calls into other non-reentrant git code. * reentrant, as it calls into other non-reentrant git code.
*/ */
extern const char *find_unique_abbrev(const unsigned char *sha1, int len); extern const char *find_unique_abbrev(const struct object_id *oid, int len);
extern int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len); extern int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len);
extern const unsigned char null_sha1[GIT_MAX_RAWSZ]; extern const unsigned char null_sha1[GIT_MAX_RAWSZ];
extern const struct object_id null_oid; extern const struct object_id null_oid;
@@ -1189,19 +1189,19 @@ extern char *xdg_config_home(const char *filename);
*/ */
extern char *xdg_cache_home(const char *filename); extern char *xdg_cache_home(const char *filename);
extern void *read_sha1_file_extended(const unsigned char *sha1, extern void *read_object_file_extended(const struct object_id *oid,
enum object_type *type, enum object_type *type,
unsigned long *size, int lookup_replace); unsigned long *size, int lookup_replace);
static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size) static inline void *read_object_file(const struct object_id *oid, enum object_type *type, unsigned long *size)
{ {
return read_sha1_file_extended(sha1, type, size, 1); return read_object_file_extended(oid, type, size, 1);
} }
/* /*
* This internal function is only declared here for the benefit of * This internal function is only declared here for the benefit of
* lookup_replace_object(). Please do not call it directly. * lookup_replace_object(). Please do not call it directly.
*/ */
extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1); extern const struct object_id *do_lookup_replace_object(const struct object_id *oid);
/* /*
* If object sha1 should be replaced, return the replacement object's * If object sha1 should be replaced, return the replacement object's
@@ -1209,15 +1209,15 @@ extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
* either sha1 or a pointer to a permanently-allocated value. When * either sha1 or a pointer to a permanently-allocated value. When
* object replacement is suppressed, always return sha1. * 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) if (!check_replace_refs)
return sha1; return oid;
return do_lookup_replace_object(sha1); return do_lookup_replace_object(oid);
} }
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */ /* Read and unpack an object file into memory, write memory to an object file */
extern int sha1_object_info(const unsigned char *, unsigned long *); extern int oid_object_info(const struct object_id *, unsigned long *);
extern int hash_object_file(const void *buf, unsigned long len, extern int hash_object_file(const void *buf, unsigned long len,
const char *type, struct object_id *oid); const char *type, struct object_id *oid);
@@ -1240,19 +1240,19 @@ 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 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); extern int parse_sha1_header(const char *hdr, unsigned long *sizep);
extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type); extern int check_object_signature(const struct object_id *oid, void *buf, unsigned long size, const char *type);
extern int finalize_object_file(const char *tmpfile, const char *filename); extern int finalize_object_file(const char *tmpfile, const char *filename);
/* /*
* Open the loose object at path, check its sha1, and return the contents, * Open the loose object at path, check its hash, and return the contents,
* type, and size. If the object is a blob, then "contents" may return NULL, * type, and size. If the object is a blob, then "contents" may return NULL,
* to allow streaming of large blobs. * to allow streaming of large blobs.
* *
* Returns 0 on success, negative on error (details may be written to stderr). * Returns 0 on success, negative on error (details may be written to stderr).
*/ */
int read_loose_object(const char *path, int read_loose_object(const char *path,
const unsigned char *expected_sha1, const struct object_id *expected_oid,
enum object_type *type, enum object_type *type,
unsigned long *size, unsigned long *size,
void **contents); void **contents);
@@ -1279,7 +1279,7 @@ extern int has_object_file_with_flags(const struct object_id *oid, int flags);
*/ */
extern int has_loose_object_nonlocal(const unsigned char *sha1); extern int has_loose_object_nonlocal(const unsigned char *sha1);
extern void assert_sha1_type(const unsigned char *sha1, enum object_type expect); extern void assert_oid_type(const struct object_id *oid, enum object_type expect);
/* Helper to check and "touch" a file */ /* Helper to check and "touch" a file */
extern int check_and_freshen_file(const char *fn, int freshen); extern int check_and_freshen_file(const char *fn, int freshen);
@@ -1435,10 +1435,10 @@ extern int df_name_compare(const char *name1, int len1, int mode1, const char *n
extern int name_compare(const char *name1, size_t len1, const char *name2, size_t len2); extern int name_compare(const char *name1, size_t len1, const char *name2, size_t len2);
extern int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2); extern int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2);
extern void *read_object_with_reference(const unsigned char *sha1, extern void *read_object_with_reference(const struct object_id *oid,
const char *required_type, const char *required_type,
unsigned long *size, unsigned long *size,
unsigned char *sha1_ret); struct object_id *oid_ret);
extern struct object *peel_to_type(const char *name, int namelen, extern struct object *peel_to_type(const char *name, int namelen,
struct object *o, enum object_type); struct object *o, enum object_type);
@@ -1779,7 +1779,7 @@ struct object_info {
#define OBJECT_INFO_QUICK 8 #define OBJECT_INFO_QUICK 8
/* Do not check loose object */ /* Do not check loose object */
#define OBJECT_INFO_IGNORE_LOOSE 16 #define OBJECT_INFO_IGNORE_LOOSE 16
extern int sha1_object_info_extended(const unsigned char *, struct object_info *, unsigned flags); extern int oid_object_info_extended(const struct object_id *, struct object_info *, unsigned flags);
/* /*
* Set this to 0 to prevent sha1_object_info_extended() from fetching missing * Set this to 0 to prevent sha1_object_info_extended() from fetching missing

View File

@@ -306,7 +306,7 @@ static char *grab_blob(const struct object_id *oid, unsigned int mode,
*size = fill_textconv(textconv, df, &blob); *size = fill_textconv(textconv, df, &blob);
free_filespec(df); free_filespec(df);
} else { } else {
blob = read_sha1_file(oid->hash, &type, size); blob = read_object_file(oid, &type, size);
if (type != OBJ_BLOB) if (type != OBJ_BLOB)
die("object '%s' is not a blob!", oid_to_hex(oid)); die("object '%s' is not a blob!", oid_to_hex(oid));
} }
@@ -915,11 +915,11 @@ static void show_combined_header(struct combine_diff_path *elem,
"", elem->path, line_prefix, c_meta, c_reset); "", elem->path, line_prefix, c_meta, c_reset);
printf("%s%sindex ", line_prefix, c_meta); printf("%s%sindex ", line_prefix, c_meta);
for (i = 0; i < num_parent; i++) { for (i = 0; i < num_parent; i++) {
abb = find_unique_abbrev(elem->parent[i].oid.hash, abb = find_unique_abbrev(&elem->parent[i].oid,
abbrev); abbrev);
printf("%s%s", i ? "," : "", abb); printf("%s%s", i ? "," : "", abb);
} }
abb = find_unique_abbrev(elem->oid.hash, abbrev); abb = find_unique_abbrev(&elem->oid, abbrev);
printf("..%s%s\n", abb, c_reset); printf("..%s%s\n", abb, c_reset);
if (mode_differs) { if (mode_differs) {

View File

@@ -266,7 +266,7 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
if (!ret) { if (!ret) {
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
ret = read_sha1_file(commit->object.oid.hash, &type, &size); ret = read_object_file(&commit->object.oid, &type, &size);
if (!ret) if (!ret)
die("cannot read commit object %s", die("cannot read commit object %s",
oid_to_hex(&commit->object.oid)); oid_to_hex(&commit->object.oid));
@@ -383,7 +383,7 @@ int parse_commit_gently(struct commit *item, int quiet_on_missing)
return -1; return -1;
if (item->object.parsed) if (item->object.parsed)
return 0; return 0;
buffer = read_sha1_file(item->object.oid.hash, &type, &size); buffer = read_object_file(&item->object.oid, &type, &size);
if (!buffer) if (!buffer)
return quiet_on_missing ? -1 : return quiet_on_missing ? -1 :
error("Could not read %s", error("Could not read %s",
@@ -1206,7 +1206,7 @@ static void handle_signed_tag(struct commit *parent, struct commit_extra_header
desc = merge_remote_util(parent); desc = merge_remote_util(parent);
if (!desc || !desc->obj) if (!desc || !desc->obj)
return; return;
buf = read_sha1_file(desc->obj->oid.hash, &type, &size); buf = read_object_file(&desc->obj->oid, &type, &size);
if (!buf || type != OBJ_TAG) if (!buf || type != OBJ_TAG)
goto free_return; goto free_return;
len = parse_signature(buf, size); len = parse_signature(buf, size);
@@ -1517,7 +1517,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
int encoding_is_utf8; int encoding_is_utf8;
struct strbuf buffer; struct strbuf buffer;
assert_sha1_type(tree->hash, OBJ_TREE); assert_oid_type(tree, OBJ_TREE);
if (memchr(msg, '\0', msg_len)) if (memchr(msg, '\0', msg_len))
return error("a NUL byte in commit log message not allowed."); return error("a NUL byte in commit log message not allowed.");

View File

@@ -1488,7 +1488,7 @@ int git_config_from_blob_oid(config_fn_t fn,
unsigned long size; unsigned long size;
int ret; int ret;
buf = read_sha1_file(oid->hash, &type, &size); buf = read_object_file(oid, &type, &size);
if (!buf) if (!buf)
return error("unable to load config blob object '%s'", name); return error("unable to load config blob object '%s'", name);
if (type != OBJ_BLOB) { if (type != OBJ_BLOB) {

View File

@@ -914,7 +914,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
to_free = strbuf_detach(buf, NULL); to_free = strbuf_detach(buf, NULL);
hash_object_file(src, len, "blob", &oid); hash_object_file(src, len, "blob", &oid);
strbuf_grow(buf, len + cnt * 43); strbuf_grow(buf, len + cnt * (the_hash_algo->hexsz + 3));
for (;;) { for (;;) {
/* step 1: run to the next '$' */ /* step 1: run to the next '$' */
dollar = memchr(src, '$', len); dollar = memchr(src, '$', len);
@@ -1510,7 +1510,7 @@ struct ident_filter {
struct stream_filter filter; struct stream_filter filter;
struct strbuf left; struct strbuf left;
int state; int state;
char ident[45]; /* ": x40 $" */ char ident[GIT_MAX_HEXSZ + 5]; /* ": x40 $" */
}; };
static int is_foreign_ident(const char *str) static int is_foreign_ident(const char *str)
@@ -1635,12 +1635,12 @@ static struct stream_filter_vtbl ident_vtbl = {
ident_free_fn, ident_free_fn,
}; };
static struct stream_filter *ident_filter(const unsigned char *sha1) static struct stream_filter *ident_filter(const struct object_id *oid)
{ {
struct ident_filter *ident = xmalloc(sizeof(*ident)); struct ident_filter *ident = xmalloc(sizeof(*ident));
xsnprintf(ident->ident, sizeof(ident->ident), xsnprintf(ident->ident, sizeof(ident->ident),
": %s $", sha1_to_hex(sha1)); ": %s $", oid_to_hex(oid));
strbuf_init(&ident->left, 0); strbuf_init(&ident->left, 0);
ident->filter.vtbl = &ident_vtbl; ident->filter.vtbl = &ident_vtbl;
ident->state = 0; ident->state = 0;
@@ -1655,7 +1655,7 @@ static struct stream_filter *ident_filter(const unsigned char *sha1)
* Note that you would be crazy to set CRLF, smuge/clean or ident to a * Note that you would be crazy to set CRLF, smuge/clean or ident to a
* large binary blob you would want us not to slurp into the memory! * large binary blob you would want us not to slurp into the memory!
*/ */
struct stream_filter *get_stream_filter(const char *path, const unsigned char *sha1) struct stream_filter *get_stream_filter(const char *path, const struct object_id *oid)
{ {
struct conv_attrs ca; struct conv_attrs ca;
struct stream_filter *filter = NULL; struct stream_filter *filter = NULL;
@@ -1668,7 +1668,7 @@ struct stream_filter *get_stream_filter(const char *path, const unsigned char *s
return NULL; return NULL;
if (ca.ident) if (ca.ident)
filter = ident_filter(sha1); filter = ident_filter(oid);
if (output_eol(ca.crlf_action) == EOL_CRLF) if (output_eol(ca.crlf_action) == EOL_CRLF)
filter = cascade_filter(filter, lf_to_crlf_filter()); filter = cascade_filter(filter, lf_to_crlf_filter());

View File

@@ -93,7 +93,7 @@ extern int would_convert_to_git_filter_fd(const char *path);
struct stream_filter; /* opaque */ struct stream_filter; /* opaque */
extern struct stream_filter *get_stream_filter(const char *path, const unsigned char *); extern struct stream_filter *get_stream_filter(const char *path, const struct object_id *);
extern void free_stream_filter(struct stream_filter *); extern void free_stream_filter(struct stream_filter *);
extern int is_null_stream_filter(struct stream_filter *); extern int is_null_stream_filter(struct stream_filter *);

6
diff.c
View File

@@ -3638,7 +3638,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
else { else {
enum object_type type; enum object_type type;
if (size_only || (flags & CHECK_BINARY)) { if (size_only || (flags & CHECK_BINARY)) {
type = sha1_object_info(s->oid.hash, &s->size); type = oid_object_info(&s->oid, &s->size);
if (type < 0) if (type < 0)
die("unable to read %s", die("unable to read %s",
oid_to_hex(&s->oid)); oid_to_hex(&s->oid));
@@ -3649,7 +3649,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
return 0; return 0;
} }
} }
s->data = read_sha1_file(s->oid.hash, &type, &s->size); s->data = read_object_file(&s->oid, &type, &s->size);
if (!s->data) if (!s->data)
die("unable to read %s", oid_to_hex(&s->oid)); die("unable to read %s", oid_to_hex(&s->oid));
s->should_free = 1; s->should_free = 1;
@@ -3834,7 +3834,7 @@ static int similarity_index(struct diff_filepair *p)
static const char *diff_abbrev_oid(const struct object_id *oid, int abbrev) static const char *diff_abbrev_oid(const struct object_id *oid, int abbrev)
{ {
if (startup_info->have_repository) if (startup_info->have_repository)
return find_unique_abbrev(oid->hash, abbrev); return find_unique_abbrev(oid, abbrev);
else { else {
char *hex = oid_to_hex(oid); char *hex = oid_to_hex(oid);
if (abbrev < 0) if (abbrev < 0)

2
dir.c
View File

@@ -243,7 +243,7 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
*size_out = 0; *size_out = 0;
*data_out = NULL; *data_out = NULL;
data = read_sha1_file(oid->hash, &type, &sz); data = read_object_file(oid, &type, &sz);
if (!data || type != OBJ_BLOB) { if (!data || type != OBJ_BLOB) {
free(data); free(data);
return -1; return -1;

View File

@@ -85,7 +85,7 @@ static int create_file(const char *path, unsigned int mode)
static void *read_blob_entry(const struct cache_entry *ce, unsigned long *size) static void *read_blob_entry(const struct cache_entry *ce, unsigned long *size)
{ {
enum object_type type; enum object_type type;
void *blob_data = read_sha1_file(ce->oid.hash, &type, size); void *blob_data = read_object_file(&ce->oid, &type, size);
if (blob_data) { if (blob_data) {
if (type == OBJ_BLOB) if (type == OBJ_BLOB)
@@ -266,7 +266,7 @@ static int write_entry(struct cache_entry *ce,
if (ce_mode_s_ifmt == S_IFREG) { if (ce_mode_s_ifmt == S_IFREG) {
struct stream_filter *filter = get_stream_filter(ce->name, struct stream_filter *filter = get_stream_filter(ce->name,
ce->oid.hash); &ce->oid);
if (filter && if (filter &&
!streaming_write_entry(ce, path, filter, !streaming_write_entry(ce, path, filter,
state, to_tempfile, state, to_tempfile,

View File

@@ -1412,7 +1412,7 @@ static void load_tree(struct tree_entry *root)
die("Can't load tree %s", oid_to_hex(oid)); die("Can't load tree %s", oid_to_hex(oid));
} else { } else {
enum object_type type; enum object_type type;
buf = read_sha1_file(oid->hash, &type, &size); buf = read_object_file(oid, &type, &size);
if (!buf || type != OBJ_TREE) if (!buf || type != OBJ_TREE)
die("Can't load tree %s", oid_to_hex(oid)); die("Can't load tree %s", oid_to_hex(oid));
} }
@@ -1913,7 +1913,7 @@ static void read_marks(void)
die("corrupt mark line: %s", line); die("corrupt mark line: %s", line);
e = find_object(&oid); e = find_object(&oid);
if (!e) { if (!e) {
enum object_type type = sha1_object_info(oid.hash, NULL); enum object_type type = oid_object_info(&oid, NULL);
if (type < 0) if (type < 0)
die("object not found: %s", oid_to_hex(&oid)); die("object not found: %s", oid_to_hex(&oid));
e = insert_object(&oid); e = insert_object(&oid);
@@ -2443,7 +2443,7 @@ static void file_change_m(const char *p, struct branch *b)
enum object_type expected = S_ISDIR(mode) ? enum object_type expected = S_ISDIR(mode) ?
OBJ_TREE: OBJ_BLOB; OBJ_TREE: OBJ_BLOB;
enum object_type type = oe ? oe->type : enum object_type type = oe ? oe->type :
sha1_object_info(oid.hash, NULL); oid_object_info(&oid, NULL);
if (type < 0) if (type < 0)
die("%s not found: %s", die("%s not found: %s",
S_ISDIR(mode) ? "Tree" : "Blob", S_ISDIR(mode) ? "Tree" : "Blob",
@@ -2583,8 +2583,9 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
oidcpy(&commit_oid, &commit_oe->idx.oid); oidcpy(&commit_oid, &commit_oe->idx.oid);
} else if (!get_oid(p, &commit_oid)) { } else if (!get_oid(p, &commit_oid)) {
unsigned long size; unsigned long size;
char *buf = read_object_with_reference(commit_oid.hash, char *buf = read_object_with_reference(&commit_oid,
commit_type, &size, commit_oid.hash); commit_type, &size,
&commit_oid);
if (!buf || size < 46) if (!buf || size < 46)
die("Not a valid commit: %s", p); die("Not a valid commit: %s", p);
free(buf); free(buf);
@@ -2603,7 +2604,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
die("Not a blob (actually a %s): %s", die("Not a blob (actually a %s): %s",
type_name(oe->type), command_buf.buf); type_name(oe->type), command_buf.buf);
} else if (!is_null_oid(&oid)) { } else if (!is_null_oid(&oid)) {
enum object_type type = sha1_object_info(oid.hash, NULL); enum object_type type = oid_object_info(&oid, NULL);
if (type < 0) if (type < 0)
die("Blob not found: %s", command_buf.buf); die("Blob not found: %s", command_buf.buf);
if (type != OBJ_BLOB) if (type != OBJ_BLOB)
@@ -2653,9 +2654,8 @@ static void parse_from_existing(struct branch *b)
unsigned long size; unsigned long size;
char *buf; char *buf;
buf = read_object_with_reference(b->oid.hash, buf = read_object_with_reference(&b->oid, commit_type, &size,
commit_type, &size, &b->oid);
b->oid.hash);
parse_from_commit(b, buf, size); parse_from_commit(b, buf, size);
free(buf); free(buf);
} }
@@ -2732,8 +2732,9 @@ static struct hash_list *parse_merge(unsigned int *count)
oidcpy(&n->oid, &oe->idx.oid); oidcpy(&n->oid, &oe->idx.oid);
} else if (!get_oid(from, &n->oid)) { } else if (!get_oid(from, &n->oid)) {
unsigned long size; unsigned long size;
char *buf = read_object_with_reference(n->oid.hash, char *buf = read_object_with_reference(&n->oid,
commit_type, &size, n->oid.hash); commit_type,
&size, &n->oid);
if (!buf || size < 46) if (!buf || size < 46)
die("Not a valid commit: %s", from); die("Not a valid commit: %s", from);
free(buf); free(buf);
@@ -2890,7 +2891,7 @@ static void parse_new_tag(const char *arg)
} else if (!get_oid(from, &oid)) { } else if (!get_oid(from, &oid)) {
struct object_entry *oe = find_object(&oid); struct object_entry *oe = find_object(&oid);
if (!oe) { if (!oe) {
type = sha1_object_info(oid.hash, NULL); type = oid_object_info(&oid, NULL);
if (type < 0) if (type < 0)
die("Not a valid object: %s", from); die("Not a valid object: %s", from);
} else } else
@@ -2966,7 +2967,7 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
char *buf; char *buf;
if (!oe || oe->pack_id == MAX_PACK_ID) { if (!oe || oe->pack_id == MAX_PACK_ID) {
buf = read_sha1_file(oid->hash, &type, &size); buf = read_object_file(oid, &type, &size);
} else { } else {
type = oe->type; type = oe->type;
buf = gfi_unpack_entry(oe, &size); buf = gfi_unpack_entry(oe, &size);
@@ -3048,7 +3049,7 @@ static struct object_entry *dereference(struct object_entry *oe,
unsigned long size; unsigned long size;
char *buf = NULL; char *buf = NULL;
if (!oe) { if (!oe) {
enum object_type type = sha1_object_info(oid->hash, NULL); enum object_type type = oid_object_info(oid, NULL);
if (type < 0) if (type < 0)
die("object not found: %s", oid_to_hex(oid)); die("object not found: %s", oid_to_hex(oid));
/* cache it! */ /* cache it! */
@@ -3071,7 +3072,7 @@ static struct object_entry *dereference(struct object_entry *oe,
buf = gfi_unpack_entry(oe, &size); buf = gfi_unpack_entry(oe, &size);
} else { } else {
enum object_type unused; enum object_type unused;
buf = read_sha1_file(oid->hash, &unused, &size); buf = read_object_file(oid, &unused, &size);
} }
if (!buf) if (!buf)
die("Can't load object %s", oid_to_hex(oid)); die("Can't load object %s", oid_to_hex(oid));

2
fsck.c
View File

@@ -811,7 +811,7 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
enum object_type type; enum object_type type;
buffer = to_free = buffer = to_free =
read_sha1_file(tag->object.oid.hash, &type, &size); read_object_file(&tag->object.oid, &type, &size);
if (!buffer) if (!buffer)
return report(options, &tag->object, return report(options, &tag->object,
FSCK_MSG_MISSING_TAG_OBJECT, FSCK_MSG_MISSING_TAG_OBJECT,

2
grep.c
View File

@@ -2015,7 +2015,7 @@ static int grep_source_load_oid(struct grep_source *gs)
enum object_type type; enum object_type type;
grep_read_lock(); grep_read_lock();
gs->buf = read_sha1_file(gs->identifier, &type, &gs->size); gs->buf = read_object_file(gs->identifier, &type, &gs->size);
grep_read_unlock(); grep_read_unlock();
if (!gs->buf) if (!gs->buf)

View File

@@ -361,7 +361,7 @@ static void start_put(struct transfer_request *request)
ssize_t size; ssize_t size;
git_zstream stream; git_zstream stream;
unpacked = read_sha1_file(request->obj->oid.hash, &type, &len); unpacked = read_object_file(&request->obj->oid, &type, &len);
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), len) + 1; hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), len) + 1;
/* Set it up */ /* Set it up */

View File

@@ -22,7 +22,7 @@ enum object_request_state {
struct object_request { struct object_request {
struct walker *walker; struct walker *walker;
unsigned char sha1[20]; struct object_id oid;
struct alt_base *repo; struct alt_base *repo;
enum object_request_state state; enum object_request_state state;
struct http_object_request *req; struct http_object_request *req;
@@ -56,7 +56,7 @@ static void start_object_request(struct walker *walker,
struct active_request_slot *slot; struct active_request_slot *slot;
struct http_object_request *req; struct http_object_request *req;
req = new_http_object_request(obj_req->repo->base, obj_req->sha1); req = new_http_object_request(obj_req->repo->base, obj_req->oid.hash);
if (req == NULL) { if (req == NULL) {
obj_req->state = ABORTED; obj_req->state = ABORTED;
return; return;
@@ -82,7 +82,7 @@ static void finish_object_request(struct object_request *obj_req)
return; return;
if (obj_req->req->rename == 0) if (obj_req->req->rename == 0)
walker_say(obj_req->walker, "got %s\n", sha1_to_hex(obj_req->sha1)); walker_say(obj_req->walker, "got %s\n", oid_to_hex(&obj_req->oid));
} }
static void process_object_response(void *callback_data) static void process_object_response(void *callback_data)
@@ -129,7 +129,7 @@ static int fill_active_slot(struct walker *walker)
list_for_each_safe(pos, tmp, head) { list_for_each_safe(pos, tmp, head) {
obj_req = list_entry(pos, struct object_request, node); obj_req = list_entry(pos, struct object_request, node);
if (obj_req->state == WAITING) { if (obj_req->state == WAITING) {
if (has_sha1_file(obj_req->sha1)) if (has_sha1_file(obj_req->oid.hash))
obj_req->state = COMPLETE; obj_req->state = COMPLETE;
else { else {
start_object_request(walker, obj_req); start_object_request(walker, obj_req);
@@ -148,7 +148,7 @@ static void prefetch(struct walker *walker, unsigned char *sha1)
newreq = xmalloc(sizeof(*newreq)); newreq = xmalloc(sizeof(*newreq));
newreq->walker = walker; newreq->walker = walker;
hashcpy(newreq->sha1, sha1); hashcpy(newreq->oid.hash, sha1);
newreq->repo = data->alt; newreq->repo = data->alt;
newreq->state = WAITING; newreq->state = WAITING;
newreq->req = NULL; newreq->req = NULL;
@@ -481,13 +481,13 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
list_for_each(pos, head) { list_for_each(pos, head) {
obj_req = list_entry(pos, struct object_request, node); obj_req = list_entry(pos, struct object_request, node);
if (!hashcmp(obj_req->sha1, sha1)) if (!hashcmp(obj_req->oid.hash, sha1))
break; break;
} }
if (obj_req == NULL) if (obj_req == NULL)
return error("Couldn't find request for %s in the queue", hex); return error("Couldn't find request for %s in the queue", hex);
if (has_sha1_file(obj_req->sha1)) { if (has_sha1_file(obj_req->oid.hash)) {
if (obj_req->req != NULL) if (obj_req->req != NULL)
abort_http_object_request(obj_req->req); abort_http_object_request(obj_req->req);
abort_object_request(obj_req); abort_object_request(obj_req);
@@ -541,7 +541,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
} else if (req->zret != Z_STREAM_END) { } else if (req->zret != Z_STREAM_END) {
walker->corrupt_object_found++; walker->corrupt_object_found++;
ret = error("File %s (%s) corrupt", hex, req->url); ret = error("File %s (%s) corrupt", hex, req->url);
} else if (hashcmp(obj_req->sha1, req->real_sha1)) { } else if (hashcmp(obj_req->oid.hash, req->real_sha1)) {
ret = error("File %s has bad hash", hex); ret = error("File %s has bad hash", hex);
} else if (req->rename < 0) { } else if (req->rename < 0) {
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;

View File

@@ -501,8 +501,7 @@ static void fill_blob_sha1(struct commit *commit, struct diff_filespec *spec)
unsigned mode; unsigned mode;
struct object_id oid; struct object_id oid;
if (get_tree_entry(commit->object.oid.hash, spec->path, if (get_tree_entry(&commit->object.oid, spec->path, &oid, &mode))
oid.hash, &mode))
die("There is no path %s in the commit", spec->path); die("There is no path %s in the commit", spec->path);
fill_filespec(spec, &oid, 1, mode); fill_filespec(spec, &oid, 1, mode);

View File

@@ -117,7 +117,7 @@ static enum list_objects_filter_result filter_blobs_limit(
assert(obj->type == OBJ_BLOB); assert(obj->type == OBJ_BLOB);
assert((obj->flags & SEEN) == 0); assert((obj->flags & SEEN) == 0);
t = sha1_object_info(obj->oid.hash, &object_length); t = oid_object_info(&obj->oid, &object_length);
if (t != OBJ_BLOB) { /* probably OBJ_NONE */ if (t != OBJ_BLOB) { /* probably OBJ_NONE */
/* /*
* We DO NOT have the blob locally, so we cannot * We DO NOT have the blob locally, so we cannot

View File

@@ -177,7 +177,7 @@ static void show_parents(struct commit *commit, int abbrev, FILE *file)
struct commit_list *p; struct commit_list *p;
for (p = commit->parents; p ; p = p->next) { for (p = commit->parents; p ; p = p->next) {
struct commit *parent = p->item; struct commit *parent = p->item;
fprintf(file, " %s", find_unique_abbrev(parent->object.oid.hash, abbrev)); fprintf(file, " %s", find_unique_abbrev(&parent->object.oid, abbrev));
} }
} }
@@ -185,7 +185,7 @@ static void show_children(struct rev_info *opt, struct commit *commit, int abbre
{ {
struct commit_list *p = lookup_decoration(&opt->children, &commit->object); struct commit_list *p = lookup_decoration(&opt->children, &commit->object);
for ( ; p; p = p->next) { for ( ; p; p = p->next) {
fprintf(opt->diffopt.file, " %s", find_unique_abbrev(p->item->object.oid.hash, abbrev)); fprintf(opt->diffopt.file, " %s", find_unique_abbrev(&p->item->object.oid, abbrev));
} }
} }
@@ -558,7 +558,7 @@ void show_log(struct rev_info *opt)
if (!opt->graph) if (!opt->graph)
put_revision_mark(opt, commit); put_revision_mark(opt, commit);
fputs(find_unique_abbrev(commit->object.oid.hash, abbrev_commit), opt->diffopt.file); fputs(find_unique_abbrev(&commit->object.oid, abbrev_commit), opt->diffopt.file);
if (opt->print_parents) if (opt->print_parents)
show_parents(commit, abbrev_commit, opt->diffopt.file); show_parents(commit, abbrev_commit, opt->diffopt.file);
if (opt->children.name) if (opt->children.name)
@@ -620,7 +620,8 @@ void show_log(struct rev_info *opt)
if (!opt->graph) if (!opt->graph)
put_revision_mark(opt, commit); put_revision_mark(opt, commit);
fputs(find_unique_abbrev(commit->object.oid.hash, abbrev_commit), fputs(find_unique_abbrev(&commit->object.oid,
abbrev_commit),
opt->diffopt.file); opt->diffopt.file);
if (opt->print_parents) if (opt->print_parents)
show_parents(commit, abbrev_commit, opt->diffopt.file); show_parents(commit, abbrev_commit, opt->diffopt.file);
@@ -628,8 +629,7 @@ void show_log(struct rev_info *opt)
show_children(opt, commit, abbrev_commit); show_children(opt, commit, abbrev_commit);
if (parent) if (parent)
fprintf(opt->diffopt.file, " (from %s)", fprintf(opt->diffopt.file, " (from %s)",
find_unique_abbrev(parent->object.oid.hash, find_unique_abbrev(&parent->object.oid, abbrev_commit));
abbrev_commit));
fputs(diff_get_color_opt(&opt->diffopt, DIFF_RESET), opt->diffopt.file); fputs(diff_get_color_opt(&opt->diffopt, DIFF_RESET), opt->diffopt.file);
show_decorations(opt, commit); show_decorations(opt, commit);
if (opt->commit_format == CMIT_FMT_ONELINE) { if (opt->commit_format == CMIT_FMT_ONELINE) {

View File

@@ -224,7 +224,7 @@ static int read_mailmap_blob(struct string_list *map,
if (get_oid(name, &oid) < 0) if (get_oid(name, &oid) < 0)
return 0; return 0;
buf = read_sha1_file(oid.hash, &type, &size); buf = read_object_file(&oid, &type, &size);
if (!buf) if (!buf)
return error("unable to read mailmap object at %s", name); return error("unable to read mailmap object at %s", name);
if (type != OBJ_BLOB) if (type != OBJ_BLOB)

View File

@@ -54,7 +54,7 @@ static void *fill_tree_desc_strict(struct tree_desc *desc,
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
buffer = read_sha1_file(hash->hash, &type, &size); buffer = read_object_file(hash, &type, &size);
if (!buffer) if (!buffer)
die("unable to read tree (%s)", oid_to_hex(hash)); die("unable to read tree (%s)", oid_to_hex(hash));
if (type != OBJ_TREE) if (type != OBJ_TREE)
@@ -180,7 +180,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
if (*subpath) if (*subpath)
subpath++; subpath++;
buf = read_sha1_file(oid1->hash, &type, &sz); buf = read_object_file(oid1, &type, &sz);
if (!buf) if (!buf)
die("cannot read tree %s", oid_to_hex(oid1)); die("cannot read tree %s", oid_to_hex(oid1));
init_tree_desc(&desc, buf, sz); init_tree_desc(&desc, buf, sz);
@@ -269,7 +269,7 @@ void shift_tree(const struct object_id *hash1,
if (!*del_prefix) if (!*del_prefix)
return; return;
if (get_tree_entry(hash2->hash, del_prefix, shifted->hash, &mode)) if (get_tree_entry(hash2, del_prefix, shifted, &mode))
die("cannot find path %s in tree %s", die("cannot find path %s in tree %s",
del_prefix, oid_to_hex(hash2)); del_prefix, oid_to_hex(hash2));
return; return;
@@ -296,12 +296,12 @@ void shift_tree_by(const struct object_id *hash1,
unsigned candidate = 0; unsigned candidate = 0;
/* Can hash2 be a tree at shift_prefix in tree hash1? */ /* Can hash2 be a tree at shift_prefix in tree hash1? */
if (!get_tree_entry(hash1->hash, shift_prefix, sub1.hash, &mode1) && if (!get_tree_entry(hash1, shift_prefix, &sub1, &mode1) &&
S_ISDIR(mode1)) S_ISDIR(mode1))
candidate |= 1; candidate |= 1;
/* Can hash1 be a tree at shift_prefix in tree hash2? */ /* Can hash1 be a tree at shift_prefix in tree hash2? */
if (!get_tree_entry(hash2->hash, shift_prefix, sub2.hash, &mode2) && if (!get_tree_entry(hash2, shift_prefix, &sub2, &mode2) &&
S_ISDIR(mode2)) S_ISDIR(mode2))
candidate |= 2; candidate |= 2;

View File

@@ -11,7 +11,7 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
unsigned long size; unsigned long size;
enum object_type type; enum object_type type;
buf = read_sha1_file(obj->object.oid.hash, &type, &size); buf = read_object_file(&obj->object.oid, &type, &size);
if (!buf) if (!buf)
return -1; return -1;
if (type != OBJ_BLOB) { if (type != OBJ_BLOB) {
@@ -66,7 +66,7 @@ void *merge_blobs(const char *path, struct blob *base, struct blob *our, struct
return NULL; return NULL;
if (!our) if (!our)
our = their; our = their;
return read_sha1_file(our->object.oid.hash, &type, size); return read_object_file(&our->object.oid, &type, size);
} }
if (fill_mmfile_blob(&f1, our) < 0) if (fill_mmfile_blob(&f1, our) < 0)

View File

@@ -290,7 +290,7 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)
strbuf_addf(&o->obuf, "virtual %s\n", strbuf_addf(&o->obuf, "virtual %s\n",
merge_remote_util(commit)->name); merge_remote_util(commit)->name);
else { else {
strbuf_add_unique_abbrev(&o->obuf, commit->object.oid.hash, strbuf_add_unique_abbrev(&o->obuf, &commit->object.oid,
DEFAULT_ABBREV); DEFAULT_ABBREV);
strbuf_addch(&o->obuf, ' '); strbuf_addch(&o->obuf, ' ');
if (parse_commit(commit) != 0) if (parse_commit(commit) != 0)
@@ -402,7 +402,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
return result; return result;
} }
static int save_files_dirs(const unsigned char *sha1, static int save_files_dirs(const struct object_id *oid,
struct strbuf *base, const char *path, struct strbuf *base, const char *path,
unsigned int mode, int stage, void *context) unsigned int mode, int stage, void *context)
{ {
@@ -427,16 +427,16 @@ static void get_files_dirs(struct merge_options *o, struct tree *tree)
read_tree_recursive(tree, "", 0, 0, &match_all, save_files_dirs, o); read_tree_recursive(tree, "", 0, 0, &match_all, save_files_dirs, o);
} }
static int get_tree_entry_if_blob(const unsigned char *tree, static int get_tree_entry_if_blob(struct tree *tree,
const char *path, const char *path,
unsigned char *hashy, struct object_id *hashy,
unsigned int *mode_o) unsigned int *mode_o)
{ {
int ret; int ret;
ret = get_tree_entry(tree, path, hashy, mode_o); ret = get_tree_entry(&tree->object.oid, path, hashy, mode_o);
if (S_ISDIR(*mode_o)) { if (S_ISDIR(*mode_o)) {
hashcpy(hashy, null_sha1); oidcpy(hashy, &null_oid);
*mode_o = 0; *mode_o = 0;
} }
return ret; return ret;
@@ -452,12 +452,12 @@ static struct stage_data *insert_stage_data(const char *path,
{ {
struct string_list_item *item; struct string_list_item *item;
struct stage_data *e = xcalloc(1, sizeof(struct stage_data)); struct stage_data *e = xcalloc(1, sizeof(struct stage_data));
get_tree_entry_if_blob(o->object.oid.hash, path, get_tree_entry_if_blob(o, path,
e->stages[1].oid.hash, &e->stages[1].mode); &e->stages[1].oid, &e->stages[1].mode);
get_tree_entry_if_blob(a->object.oid.hash, path, get_tree_entry_if_blob(a, path,
e->stages[2].oid.hash, &e->stages[2].mode); &e->stages[2].oid, &e->stages[2].mode);
get_tree_entry_if_blob(b->object.oid.hash, path, get_tree_entry_if_blob(b, path,
e->stages[3].oid.hash, &e->stages[3].mode); &e->stages[3].oid, &e->stages[3].mode);
item = string_list_insert(entries, path); item = string_list_insert(entries, path);
item->util = e; item->util = e;
return e; return e;
@@ -891,7 +891,7 @@ static int update_file_flags(struct merge_options *o,
goto update_index; goto update_index;
} }
buf = read_sha1_file(oid->hash, &type, &size); buf = read_object_file(oid, &type, &size);
if (!buf) if (!buf)
return err(o, _("cannot read object %s '%s'"), oid_to_hex(oid), path); return err(o, _("cannot read object %s '%s'"), oid_to_hex(oid), path);
if (type != OBJ_BLOB) { if (type != OBJ_BLOB) {
@@ -1559,11 +1559,11 @@ static struct diff_queue_struct *get_diffpairs(struct merge_options *o,
static int tree_has_path(struct tree *tree, const char *path) static int tree_has_path(struct tree *tree, const char *path)
{ {
unsigned char hashy[GIT_MAX_RAWSZ]; struct object_id hashy;
unsigned int mode_o; unsigned int mode_o;
return !get_tree_entry(tree->object.oid.hash, path, return !get_tree_entry(&tree->object.oid, path,
hashy, &mode_o); &hashy, &mode_o);
} }
/* /*
@@ -2159,9 +2159,9 @@ static void apply_directory_rename_modifications(struct merge_options *o,
* the various conflict_rename_*() functions update the index * the various conflict_rename_*() functions update the index
* explicitly rather than relying on unpack_trees() to have done it. * explicitly rather than relying on unpack_trees() to have done it.
*/ */
get_tree_entry(tree->object.oid.hash, get_tree_entry(&tree->object.oid,
pair->two->path, pair->two->path,
re->dst_entry->stages[stage].oid.hash, &re->dst_entry->stages[stage].oid,
&re->dst_entry->stages[stage].mode); &re->dst_entry->stages[stage].mode);
/* Update pair status */ /* Update pair status */
@@ -2646,7 +2646,7 @@ static int read_oid_strbuf(struct merge_options *o,
void *buf; void *buf;
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
buf = read_sha1_file(oid->hash, &type, &size); buf = read_object_file(oid, &type, &size);
if (!buf) if (!buf)
return err(o, _("cannot read object %s"), oid_to_hex(oid)); return err(o, _("cannot read object %s"), oid_to_hex(oid));
if (type != OBJ_BLOB) { if (type != OBJ_BLOB) {

View File

@@ -77,7 +77,7 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
value_oid = get_note(&c->tree, key_oid); value_oid = get_note(&c->tree, key_oid);
if (!value_oid) if (!value_oid)
return NULL; return NULL;
value = read_sha1_file(value_oid->hash, &type, &size); value = read_object_file(value_oid, &type, &size);
*outsize = size; *outsize = size;
return value; return value;

View File

@@ -322,7 +322,7 @@ static void write_note_to_worktree(const struct object_id *obj,
{ {
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
void *buf = read_sha1_file(note->hash, &type, &size); void *buf = read_object_file(note, &type, &size);
if (!buf) if (!buf)
die("cannot read note %s for object %s", die("cannot read note %s for object %s",

10
notes.c
View File

@@ -796,13 +796,13 @@ int combine_notes_concatenate(struct object_id *cur_oid,
/* read in both note blob objects */ /* read in both note blob objects */
if (!is_null_oid(new_oid)) if (!is_null_oid(new_oid))
new_msg = read_sha1_file(new_oid->hash, &new_type, &new_len); new_msg = read_object_file(new_oid, &new_type, &new_len);
if (!new_msg || !new_len || new_type != OBJ_BLOB) { if (!new_msg || !new_len || new_type != OBJ_BLOB) {
free(new_msg); free(new_msg);
return 0; return 0;
} }
if (!is_null_oid(cur_oid)) if (!is_null_oid(cur_oid))
cur_msg = read_sha1_file(cur_oid->hash, &cur_type, &cur_len); cur_msg = read_object_file(cur_oid, &cur_type, &cur_len);
if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) { if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
free(cur_msg); free(cur_msg);
free(new_msg); free(new_msg);
@@ -858,7 +858,7 @@ static int string_list_add_note_lines(struct string_list *list,
return 0; return 0;
/* read_sha1_file NUL-terminates */ /* read_sha1_file NUL-terminates */
data = read_sha1_file(oid->hash, &t, &len); data = read_object_file(oid, &t, &len);
if (t != OBJ_BLOB || !data || !len) { if (t != OBJ_BLOB || !data || !len) {
free(data); free(data);
return t != OBJ_BLOB || !data; return t != OBJ_BLOB || !data;
@@ -1012,7 +1012,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
return; return;
if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid)) if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))
die("Cannot use notes ref %s", notes_ref); die("Cannot use notes ref %s", notes_ref);
if (get_tree_entry(object_oid.hash, "", oid.hash, &mode)) if (get_tree_entry(&object_oid, "", &oid, &mode))
die("Failed to read notes tree referenced by %s (%s)", die("Failed to read notes tree referenced by %s (%s)",
notes_ref, oid_to_hex(&object_oid)); notes_ref, oid_to_hex(&object_oid));
@@ -1217,7 +1217,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
if (!oid) if (!oid)
return; return;
if (!(msg = read_sha1_file(oid->hash, &type, &msglen)) || type != OBJ_BLOB) { if (!(msg = read_object_file(oid, &type, &msglen)) || type != OBJ_BLOB) {
free(msg); free(msg);
return; return;
} }

View File

@@ -244,7 +244,7 @@ struct object *parse_object(const struct object_id *oid)
unsigned long size; unsigned long size;
enum object_type type; enum object_type type;
int eaten; int eaten;
const unsigned char *repl = lookup_replace_object(oid->hash); const struct object_id *repl = lookup_replace_object(oid);
void *buffer; void *buffer;
struct object *obj; struct object *obj;
@@ -254,8 +254,8 @@ struct object *parse_object(const struct object_id *oid)
if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) || if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) ||
(!obj && has_object_file(oid) && (!obj && has_object_file(oid) &&
sha1_object_info(oid->hash, NULL) == OBJ_BLOB)) { oid_object_info(oid, NULL) == OBJ_BLOB)) {
if (check_sha1_signature(repl, NULL, 0, NULL) < 0) { if (check_object_signature(repl, NULL, 0, NULL) < 0) {
error("sha1 mismatch %s", oid_to_hex(oid)); error("sha1 mismatch %s", oid_to_hex(oid));
return NULL; return NULL;
} }
@@ -263,11 +263,11 @@ struct object *parse_object(const struct object_id *oid)
return lookup_object(oid->hash); return lookup_object(oid->hash);
} }
buffer = read_sha1_file(oid->hash, &type, &size); buffer = read_object_file(oid, &type, &size);
if (buffer) { if (buffer) {
if (check_sha1_signature(repl, buffer, size, type_name(type)) < 0) { if (check_object_signature(repl, buffer, size, type_name(type)) < 0) {
free(buffer); free(buffer);
error("sha1 mismatch %s", sha1_to_hex(repl)); error("sha1 mismatch %s", oid_to_hex(repl));
return NULL; return NULL;
} }

View File

@@ -73,8 +73,7 @@ void bitmap_writer_build_type_index(struct pack_idx_entry **index,
break; break;
default: default:
real_type = sha1_object_info(entry->idx.oid.hash, real_type = oid_object_info(&entry->idx.oid, NULL);
NULL);
break; break;
} }

View File

@@ -126,7 +126,7 @@ static int verify_packfile(struct packed_git *p,
if (type == OBJ_BLOB && big_file_threshold <= size) { if (type == OBJ_BLOB && big_file_threshold <= size) {
/* /*
* Let check_sha1_signature() check it with * Let check_object_signature() check it with
* the streaming interface; no point slurping * the streaming interface; no point slurping
* the data in-core only to discard. * the data in-core only to discard.
*/ */
@@ -141,7 +141,7 @@ static int verify_packfile(struct packed_git *p,
err = error("cannot unpack %s from %s at offset %"PRIuMAX"", err = error("cannot unpack %s from %s at offset %"PRIuMAX"",
oid_to_hex(entries[i].oid.oid), p->pack_name, oid_to_hex(entries[i].oid.oid), p->pack_name,
(uintmax_t)entries[i].offset); (uintmax_t)entries[i].offset);
else if (check_sha1_signature(entries[i].oid.hash, data, size, type_name(type))) else if (check_object_signature(entries[i].oid.oid, data, size, type_name(type)))
err = error("packed %s from %s is corrupt", err = error("packed %s from %s is corrupt",
oid_to_hex(entries[i].oid.oid), p->pack_name); oid_to_hex(entries[i].oid.oid), p->pack_name);
else if (fn) { else if (fn) {

View File

@@ -1095,13 +1095,13 @@ static int retry_bad_packed_offset(struct packed_git *p, off_t obj_offset)
{ {
int type; int type;
struct revindex_entry *revidx; struct revindex_entry *revidx;
const unsigned char *sha1; struct object_id oid;
revidx = find_pack_revindex(p, obj_offset); revidx = find_pack_revindex(p, obj_offset);
if (!revidx) if (!revidx)
return OBJ_BAD; return OBJ_BAD;
sha1 = nth_packed_object_sha1(p, revidx->nr); nth_packed_object_oid(&oid, p, revidx->nr);
mark_bad_packed_object(p, sha1); mark_bad_packed_object(p, oid.hash);
type = sha1_object_info(sha1, NULL); type = oid_object_info(&oid, NULL);
if (type <= OBJ_NONE) if (type <= OBJ_NONE)
return OBJ_BAD; return OBJ_BAD;
return type; return type;
@@ -1452,7 +1452,7 @@ struct unpack_entry_stack_ent {
unsigned long size; unsigned long size;
}; };
static void *read_object(const unsigned char *sha1, enum object_type *type, static void *read_object(const struct object_id *oid, enum object_type *type,
unsigned long *size) unsigned long *size)
{ {
struct object_info oi = OBJECT_INFO_INIT; struct object_info oi = OBJECT_INFO_INIT;
@@ -1461,7 +1461,7 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,
oi.sizep = size; oi.sizep = size;
oi.contentp = &content; oi.contentp = &content;
if (sha1_object_info_extended(sha1, &oi, 0) < 0) if (oid_object_info_extended(oid, &oi, 0) < 0)
return NULL; return NULL;
return content; return content;
} }
@@ -1501,11 +1501,11 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
struct revindex_entry *revidx = find_pack_revindex(p, obj_offset); struct revindex_entry *revidx = find_pack_revindex(p, obj_offset);
off_t len = revidx[1].offset - obj_offset; off_t len = revidx[1].offset - obj_offset;
if (check_pack_crc(p, &w_curs, obj_offset, len, revidx->nr)) { if (check_pack_crc(p, &w_curs, obj_offset, len, revidx->nr)) {
const unsigned char *sha1 = struct object_id oid;
nth_packed_object_sha1(p, revidx->nr); nth_packed_object_oid(&oid, p, revidx->nr);
error("bad packed object CRC for %s", error("bad packed object CRC for %s",
sha1_to_hex(sha1)); oid_to_hex(&oid));
mark_bad_packed_object(p, sha1); mark_bad_packed_object(p, oid.hash);
data = NULL; data = NULL;
goto out; goto out;
} }
@@ -1588,16 +1588,16 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
* of a corrupted pack, and is better than failing outright. * of a corrupted pack, and is better than failing outright.
*/ */
struct revindex_entry *revidx; struct revindex_entry *revidx;
const unsigned char *base_sha1; struct object_id base_oid;
revidx = find_pack_revindex(p, obj_offset); revidx = find_pack_revindex(p, obj_offset);
if (revidx) { if (revidx) {
base_sha1 = nth_packed_object_sha1(p, revidx->nr); nth_packed_object_oid(&base_oid, p, revidx->nr);
error("failed to read delta base object %s" error("failed to read delta base object %s"
" at offset %"PRIuMAX" from %s", " at offset %"PRIuMAX" from %s",
sha1_to_hex(base_sha1), (uintmax_t)obj_offset, oid_to_hex(&base_oid), (uintmax_t)obj_offset,
p->pack_name); p->pack_name);
mark_bad_packed_object(p, base_sha1); mark_bad_packed_object(p, base_oid.hash);
base = read_object(base_sha1, &type, &base_size); base = read_object(&base_oid, &type, &base_size);
external_base = base; external_base = base;
} }
} }

View File

@@ -549,7 +549,7 @@ static void add_merge_info(const struct pretty_print_context *pp,
struct object_id *oidp = &parent->item->object.oid; struct object_id *oidp = &parent->item->object.oid;
strbuf_addch(sb, ' '); strbuf_addch(sb, ' ');
if (pp->abbrev) if (pp->abbrev)
strbuf_add_unique_abbrev(sb, oidp->hash, pp->abbrev); strbuf_add_unique_abbrev(sb, oidp, pp->abbrev);
else else
strbuf_addstr(sb, oid_to_hex(oidp)); strbuf_addstr(sb, oid_to_hex(oidp));
parent = parent->next; parent = parent->next;
@@ -1156,7 +1156,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
return 1; return 1;
case 'h': /* abbreviated commit hash */ case 'h': /* abbreviated commit hash */
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_COMMIT)); strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_COMMIT));
strbuf_add_unique_abbrev(sb, commit->object.oid.hash, strbuf_add_unique_abbrev(sb, &commit->object.oid,
c->pretty_ctx->abbrev); c->pretty_ctx->abbrev);
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET)); strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
return 1; return 1;
@@ -1164,7 +1164,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
strbuf_addstr(sb, oid_to_hex(&commit->tree->object.oid)); strbuf_addstr(sb, oid_to_hex(&commit->tree->object.oid));
return 1; return 1;
case 't': /* abbreviated tree hash */ case 't': /* abbreviated tree hash */
strbuf_add_unique_abbrev(sb, commit->tree->object.oid.hash, strbuf_add_unique_abbrev(sb, &commit->tree->object.oid,
c->pretty_ctx->abbrev); c->pretty_ctx->abbrev);
return 1; return 1;
case 'P': /* parent hashes */ case 'P': /* parent hashes */
@@ -1178,7 +1178,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
for (p = commit->parents; p; p = p->next) { for (p = commit->parents; p; p = p->next) {
if (p != commit->parents) if (p != commit->parents)
strbuf_addch(sb, ' '); strbuf_addch(sb, ' ');
strbuf_add_unique_abbrev(sb, p->item->object.oid.hash, strbuf_add_unique_abbrev(sb, &p->item->object.oid,
c->pretty_ctx->abbrev); c->pretty_ctx->abbrev);
} }
return 1; return 1;

View File

@@ -77,7 +77,7 @@ static void add_recent_object(const struct object_id *oid,
* later processing, and the revision machinery expects * later processing, and the revision machinery expects
* commits and tags to have been parsed. * commits and tags to have been parsed.
*/ */
type = sha1_object_info(oid->hash, NULL); type = oid_object_info(oid, NULL);
if (type < 0) if (type < 0)
die("unable to get object info for %s", oid_to_hex(oid)); die("unable to get object info for %s", oid_to_hex(oid));

View File

@@ -185,7 +185,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
if (strbuf_readlink(&sb, ce->name, expected_size)) if (strbuf_readlink(&sb, ce->name, expected_size))
return -1; return -1;
buffer = read_sha1_file(ce->oid.hash, &type, &size); buffer = read_object_file(&ce->oid, &type, &size);
if (buffer) { if (buffer) {
if (size == sb.len) if (size == sb.len)
match = memcmp(buffer, sb.buf, size); match = memcmp(buffer, sb.buf, size);
@@ -2693,7 +2693,7 @@ void *read_blob_data_from_index(const struct index_state *istate,
} }
if (pos < 0) if (pos < 0)
return NULL; return NULL;
data = read_sha1_file(istate->cache[pos]->oid.hash, &type, &sz); data = read_object_file(&istate->cache[pos]->oid, &type, &sz);
if (!data || type != OBJ_BLOB) { if (!data || type != OBJ_BLOB) {
free(data); free(data);
return NULL; return NULL;

View File

@@ -728,7 +728,7 @@ int verify_ref_format(struct ref_format *format)
static void *get_obj(const struct object_id *oid, struct object **obj, unsigned long *sz, int *eaten) static void *get_obj(const struct object_id *oid, struct object **obj, unsigned long *sz, int *eaten)
{ {
enum object_type type; enum object_type type;
void *buf = read_sha1_file(oid->hash, &type, sz); void *buf = read_object_file(oid, &type, sz);
if (buf) if (buf)
*obj = parse_object_buffer(oid, type, *sz, buf, eaten); *obj = parse_object_buffer(oid, type, *sz, buf, eaten);
@@ -737,18 +737,18 @@ static void *get_obj(const struct object_id *oid, struct object **obj, unsigned
return buf; return buf;
} }
static int grab_objectname(const char *name, const unsigned char *sha1, static int grab_objectname(const char *name, const struct object_id *oid,
struct atom_value *v, struct used_atom *atom) struct atom_value *v, struct used_atom *atom)
{ {
if (starts_with(name, "objectname")) { if (starts_with(name, "objectname")) {
if (atom->u.objectname.option == O_SHORT) { if (atom->u.objectname.option == O_SHORT) {
v->s = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); v->s = xstrdup(find_unique_abbrev(oid, DEFAULT_ABBREV));
return 1; return 1;
} else if (atom->u.objectname.option == O_FULL) { } else if (atom->u.objectname.option == O_FULL) {
v->s = xstrdup(sha1_to_hex(sha1)); v->s = xstrdup(oid_to_hex(oid));
return 1; return 1;
} else if (atom->u.objectname.option == O_LENGTH) { } else if (atom->u.objectname.option == O_LENGTH) {
v->s = xstrdup(find_unique_abbrev(sha1, atom->u.objectname.length)); v->s = xstrdup(find_unique_abbrev(oid, atom->u.objectname.length));
return 1; return 1;
} else } else
die("BUG: unknown %%(objectname) option"); die("BUG: unknown %%(objectname) option");
@@ -775,7 +775,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
v->s = xstrfmt("%lu", sz); v->s = xstrfmt("%lu", sz);
} }
else if (deref) else if (deref)
grab_objectname(name, obj->oid.hash, v, &used_atom[i]); grab_objectname(name, &obj->oid, v, &used_atom[i]);
} }
} }
@@ -1455,7 +1455,7 @@ static void populate_value(struct ref_array_item *ref)
v->s = xstrdup(buf + 1); v->s = xstrdup(buf + 1);
} }
continue; continue;
} else if (!deref && grab_objectname(name, ref->objectname.hash, v, atom)) { } else if (!deref && grab_objectname(name, &ref->objectname, v, atom)) {
continue; continue;
} else if (!strcmp(name, "HEAD")) { } else if (!strcmp(name, "HEAD")) {
if (atom->u.head && !strcmp(ref->refname, atom->u.head)) if (atom->u.head && !strcmp(ref->refname, atom->u.head))

2
refs.c
View File

@@ -301,7 +301,7 @@ enum peel_status peel_object(const struct object_id *name, struct object_id *oid
struct object *o = lookup_unknown_object(name->hash); struct object *o = lookup_unknown_object(name->hash);
if (o->type == OBJ_NONE) { if (o->type == OBJ_NONE) {
int type = sha1_object_info(name->hash, NULL); int type = oid_object_info(name, NULL);
if (type < 0 || !object_as_type(o, type, 0)) if (type < 0 || !object_as_type(o, type, 0))
return PEEL_INVALID; return PEEL_INVALID;
} }

View File

@@ -61,7 +61,7 @@ static char *read_ref_note(const struct object_id *oid)
init_notes(NULL, notes_ref, NULL, 0); init_notes(NULL, notes_ref, NULL, 0);
if (!(note_oid = get_note(NULL, oid))) if (!(note_oid = get_note(NULL, oid)))
return NULL; /* note tree not found */ return NULL; /* note tree not found */
if (!(msg = read_sha1_file(note_oid->hash, &type, &msglen))) if (!(msg = read_object_file(note_oid, &type, &msglen)))
error("Empty notes tree. %s", notes_ref); error("Empty notes tree. %s", notes_ref);
else if (!msglen || type != OBJ_BLOB) { else if (!msglen || type != OBJ_BLOB) {
error("Note contains unusable content. " error("Note contains unusable content. "
@@ -108,7 +108,7 @@ static int note2mark_cb(const struct object_id *object_oid,
enum object_type type; enum object_type type;
struct rev_note note; struct rev_note note;
if (!(msg = read_sha1_file(note_oid->hash, &type, &msglen)) || if (!(msg = read_object_file(note_oid, &type, &msglen)) ||
!msglen || type != OBJ_BLOB) { !msglen || type != OBJ_BLOB) {
free(msg); free(msg);
return 1; return 1;

View File

@@ -1376,7 +1376,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
continue; /* not a tag */ continue; /* not a tag */
if (string_list_has_string(&dst_tag, ref->name)) if (string_list_has_string(&dst_tag, ref->name))
continue; /* they already have it */ continue; /* they already have it */
if (sha1_object_info(ref->new_oid.hash, NULL) != OBJ_TAG) if (oid_object_info(&ref->new_oid, NULL) != OBJ_TAG)
continue; /* be conservative */ continue; /* be conservative */
item = string_list_append(&src_tag, ref->name); item = string_list_append(&src_tag, ref->name);
item->util = ref; item->util = ref;

View File

@@ -8,8 +8,8 @@
* sha1. * sha1.
*/ */
static struct replace_object { static struct replace_object {
unsigned char original[20]; struct object_id original;
unsigned char replacement[20]; struct object_id replacement;
} **replace_object; } **replace_object;
static int replace_object_alloc, replace_object_nr; static int replace_object_alloc, replace_object_nr;
@@ -17,7 +17,7 @@ static int replace_object_alloc, replace_object_nr;
static const unsigned char *replace_sha1_access(size_t index, void *table) static const unsigned char *replace_sha1_access(size_t index, void *table)
{ {
struct replace_object **replace = table; struct replace_object **replace = table;
return replace[index]->original; return replace[index]->original.hash;
} }
static int replace_object_pos(const unsigned char *sha1) static int replace_object_pos(const unsigned char *sha1)
@@ -29,7 +29,7 @@ static int replace_object_pos(const unsigned char *sha1)
static int register_replace_object(struct replace_object *replace, static int register_replace_object(struct replace_object *replace,
int ignore_dups) int ignore_dups)
{ {
int pos = replace_object_pos(replace->original); int pos = replace_object_pos(replace->original.hash);
if (0 <= pos) { if (0 <= pos) {
if (ignore_dups) if (ignore_dups)
@@ -59,14 +59,14 @@ static int register_replace_ref(const char *refname,
const char *hash = slash ? slash + 1 : refname; const char *hash = slash ? slash + 1 : refname;
struct replace_object *repl_obj = xmalloc(sizeof(*repl_obj)); struct replace_object *repl_obj = xmalloc(sizeof(*repl_obj));
if (strlen(hash) != 40 || get_sha1_hex(hash, repl_obj->original)) { if (get_oid_hex(hash, &repl_obj->original)) {
free(repl_obj); free(repl_obj);
warning("bad replace ref name: %s", refname); warning("bad replace ref name: %s", refname);
return 0; return 0;
} }
/* Copy sha1 from the read ref */ /* Copy sha1 from the read ref */
hashcpy(repl_obj->replacement, oid->hash); oidcpy(&repl_obj->replacement, oid);
/* Register new object */ /* Register new object */
if (register_replace_object(repl_obj, 1)) if (register_replace_object(repl_obj, 1))
@@ -92,16 +92,16 @@ static void prepare_replace_object(void)
#define MAXREPLACEDEPTH 5 #define MAXREPLACEDEPTH 5
/* /*
* If a replacement for object sha1 has been set up, return the * If a replacement for object oid has been set up, return the
* replacement object's name (replaced recursively, if necessary). * replacement object's name (replaced recursively, if necessary).
* The return value is either sha1 or a pointer to a * The return value is either oid or a pointer to a
* permanently-allocated value. This function always respects replace * permanently-allocated value. This function always respects replace
* references, regardless of the value of check_replace_refs. * references, regardless of the value of check_replace_refs.
*/ */
const unsigned char *do_lookup_replace_object(const unsigned char *sha1) const struct object_id *do_lookup_replace_object(const struct object_id *oid)
{ {
int pos, depth = MAXREPLACEDEPTH; int pos, depth = MAXREPLACEDEPTH;
const unsigned char *cur = sha1; const struct object_id *cur = oid;
prepare_replace_object(); prepare_replace_object();
@@ -109,11 +109,11 @@ const unsigned char *do_lookup_replace_object(const unsigned char *sha1)
do { do {
if (--depth < 0) if (--depth < 0)
die("replace depth too high for object %s", die("replace depth too high for object %s",
sha1_to_hex(sha1)); oid_to_hex(oid));
pos = replace_object_pos(cur); pos = replace_object_pos(cur->hash);
if (0 <= pos) if (0 <= pos)
cur = replace_object[pos]->replacement; cur = &replace_object[pos]->replacement;
} while (0 <= pos); } while (0 <= pos);
return cur; return cur;

View File

@@ -979,7 +979,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
break; break;
i = ce_stage(ce) - 1; i = ce_stage(ce) - 1;
if (!mmfile[i].ptr) { if (!mmfile[i].ptr) {
mmfile[i].ptr = read_sha1_file(ce->oid.hash, &type, mmfile[i].ptr = read_object_file(&ce->oid, &type,
&size); &size);
mmfile[i].size = size; mmfile[i].size = size;
} }

View File

@@ -24,7 +24,7 @@ void record_resolve_undo(struct index_state *istate, struct cache_entry *ce)
if (!lost->util) if (!lost->util)
lost->util = xcalloc(1, sizeof(*ui)); lost->util = xcalloc(1, sizeof(*ui));
ui = lost->util; ui = lost->util;
hashcpy(ui->sha1[stage - 1], ce->oid.hash); oidcpy(&ui->oid[stage - 1], &ce->oid);
ui->mode[stage - 1] = ce->ce_mode; ui->mode[stage - 1] = ce->ce_mode;
} }
@@ -44,7 +44,7 @@ void resolve_undo_write(struct strbuf *sb, struct string_list *resolve_undo)
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
if (!ui->mode[i]) if (!ui->mode[i])
continue; continue;
strbuf_add(sb, ui->sha1[i], 20); strbuf_add(sb, ui->oid[i].hash, the_hash_algo->rawsz);
} }
} }
} }
@@ -55,6 +55,7 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
size_t len; size_t len;
char *endptr; char *endptr;
int i; int i;
const unsigned rawsz = the_hash_algo->rawsz;
resolve_undo = xcalloc(1, sizeof(*resolve_undo)); resolve_undo = xcalloc(1, sizeof(*resolve_undo));
resolve_undo->strdup_strings = 1; resolve_undo->strdup_strings = 1;
@@ -87,11 +88,11 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
if (!ui->mode[i]) if (!ui->mode[i])
continue; continue;
if (size < 20) if (size < rawsz)
goto error; goto error;
hashcpy(ui->sha1[i], (const unsigned char *)data); memcpy(ui->oid[i].hash, (const unsigned char *)data, rawsz);
size -= 20; size -= rawsz;
data += 20; data += rawsz;
} }
} }
return resolve_undo; return resolve_undo;
@@ -145,7 +146,7 @@ int unmerge_index_entry_at(struct index_state *istate, int pos)
struct cache_entry *nce; struct cache_entry *nce;
if (!ru->mode[i]) if (!ru->mode[i])
continue; continue;
nce = make_cache_entry(ru->mode[i], ru->sha1[i], nce = make_cache_entry(ru->mode[i], ru->oid[i].hash,
name, i + 1, 0); name, i + 1, 0);
if (matched) if (matched)
nce->ce_flags |= CE_MATCHED; nce->ce_flags |= CE_MATCHED;

View File

@@ -3,7 +3,7 @@
struct resolve_undo_info { struct resolve_undo_info {
unsigned int mode[3]; unsigned int mode[3];
unsigned char sha1[3][20]; struct object_id oid[3];
}; };
extern void record_resolve_undo(struct index_state *, struct cache_entry *); extern void record_resolve_undo(struct index_state *, struct cache_entry *);

View File

@@ -37,14 +37,14 @@ int option_parse_push_signed(const struct option *opt,
die("bad %s argument: %s", opt->long_name, arg); die("bad %s argument: %s", opt->long_name, arg);
} }
static void feed_object(const unsigned char *sha1, FILE *fh, int negative) static void feed_object(const struct object_id *oid, FILE *fh, int negative)
{ {
if (negative && !has_sha1_file(sha1)) if (negative && !has_sha1_file(oid->hash))
return; return;
if (negative) if (negative)
putc('^', fh); putc('^', fh);
fputs(sha1_to_hex(sha1), fh); fputs(oid_to_hex(oid), fh);
putc('\n', fh); putc('\n', fh);
} }
@@ -89,13 +89,13 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc
*/ */
po_in = xfdopen(po.in, "w"); po_in = xfdopen(po.in, "w");
for (i = 0; i < extra->nr; i++) for (i = 0; i < extra->nr; i++)
feed_object(extra->oid[i].hash, po_in, 1); feed_object(&extra->oid[i], po_in, 1);
while (refs) { while (refs) {
if (!is_null_oid(&refs->old_oid)) if (!is_null_oid(&refs->old_oid))
feed_object(refs->old_oid.hash, po_in, 1); feed_object(&refs->old_oid, po_in, 1);
if (!is_null_oid(&refs->new_oid)) if (!is_null_oid(&refs->new_oid))
feed_object(refs->new_oid.hash, po_in, 0); feed_object(&refs->new_oid, po_in, 0);
refs = refs->next; refs = refs->next;
} }

View File

@@ -282,7 +282,7 @@ struct commit_message {
static const char *short_commit_name(struct commit *commit) static const char *short_commit_name(struct commit *commit)
{ {
return find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV); return find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV);
} }
static int get_message(struct commit *commit, struct commit_message *out) static int get_message(struct commit *commit, struct commit_message *out)
@@ -1112,7 +1112,7 @@ static int try_to_commit(struct strbuf *msg, const char *author,
commit_list_insert(current_head, &parents); commit_list_insert(current_head, &parents);
} }
if (write_cache_as_tree(tree.hash, 0, NULL)) { if (write_cache_as_tree(&tree, 0, NULL)) {
res = error(_("git write-tree failed to write a tree")); res = error(_("git write-tree failed to write a tree"));
goto out; goto out;
} }
@@ -1474,7 +1474,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
* that represents the "current" state for merge-recursive * that represents the "current" state for merge-recursive
* to work on. * to work on.
*/ */
if (write_cache_as_tree(head.hash, 0, NULL)) if (write_cache_as_tree(&head, 0, NULL))
return error(_("your index file is unmerged.")); return error(_("your index file is unmerged."));
} else { } else {
unborn = get_oid("HEAD", &head); unborn = get_oid("HEAD", &head);
@@ -2876,7 +2876,8 @@ int sequencer_pick_revisions(struct replay_opts *opts)
if (!get_oid(name, &oid)) { if (!get_oid(name, &oid)) {
if (!lookup_commit_reference_gently(&oid, 1)) { if (!lookup_commit_reference_gently(&oid, 1)) {
enum object_type type = sha1_object_info(oid.hash, NULL); enum object_type type = oid_object_info(&oid,
NULL);
return error(_("%s: can't cherry-pick a %s"), return error(_("%s: can't cherry-pick a %s"),
name, type_name(type)); name, type_name(type));
} }

View File

@@ -30,6 +30,9 @@
#include "packfile.h" #include "packfile.h"
#include "fetch-object.h" #include "fetch-object.h"
/* The maximum size for an object header. */
#define MAX_HEADER_LEN 32
const unsigned char null_sha1[GIT_MAX_RAWSZ]; const unsigned char null_sha1[GIT_MAX_RAWSZ];
const struct object_id null_oid; const struct object_id null_oid;
const struct object_id empty_tree_oid = { const struct object_id empty_tree_oid = {
@@ -784,22 +787,22 @@ void *xmmap(void *start, size_t length,
* With "map" == NULL, try reading the object named with "sha1" using * With "map" == NULL, try reading the object named with "sha1" using
* the streaming interface and rehash it to do the same. * the streaming interface and rehash it to do the same.
*/ */
int check_sha1_signature(const unsigned char *sha1, void *map, int check_object_signature(const struct object_id *oid, void *map,
unsigned long size, const char *type) unsigned long size, const char *type)
{ {
struct object_id real_oid; struct object_id real_oid;
enum object_type obj_type; enum object_type obj_type;
struct git_istream *st; struct git_istream *st;
git_hash_ctx c; git_hash_ctx c;
char hdr[32]; char hdr[MAX_HEADER_LEN];
int hdrlen; int hdrlen;
if (map) { if (map) {
hash_object_file(map, size, type, &real_oid); hash_object_file(map, size, type, &real_oid);
return hashcmp(sha1, real_oid.hash) ? -1 : 0; return oidcmp(oid, &real_oid) ? -1 : 0;
} }
st = open_istream(sha1, &obj_type, &size, NULL); st = open_istream(oid, &obj_type, &size, NULL);
if (!st) if (!st)
return -1; return -1;
@@ -823,7 +826,7 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
} }
the_hash_algo->final_fn(real_oid.hash, &c); the_hash_algo->final_fn(real_oid.hash, &c);
close_istream(st); close_istream(st);
return hashcmp(sha1, real_oid.hash) ? -1 : 0; return oidcmp(oid, &real_oid) ? -1 : 0;
} }
int git_open_cloexec(const char *name, int flags) int git_open_cloexec(const char *name, int flags)
@@ -1150,7 +1153,7 @@ static int sha1_loose_object_info(const unsigned char *sha1,
unsigned long mapsize; unsigned long mapsize;
void *map; void *map;
git_zstream stream; git_zstream stream;
char hdr[32]; char hdr[MAX_HEADER_LEN];
struct strbuf hdrbuf = STRBUF_INIT; struct strbuf hdrbuf = STRBUF_INIT;
unsigned long size_scratch; unsigned long size_scratch;
@@ -1222,24 +1225,25 @@ static int sha1_loose_object_info(const unsigned char *sha1,
int fetch_if_missing = 1; int fetch_if_missing = 1;
int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, unsigned flags) int oid_object_info_extended(const struct object_id *oid, struct object_info *oi, unsigned flags)
{ {
static struct object_info blank_oi = OBJECT_INFO_INIT; static struct object_info blank_oi = OBJECT_INFO_INIT;
struct pack_entry e; struct pack_entry e;
int rtype; int rtype;
const unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ? const struct object_id *real = oid;
lookup_replace_object(sha1) :
sha1;
int already_retried = 0; int already_retried = 0;
if (is_null_sha1(real)) if (flags & OBJECT_INFO_LOOKUP_REPLACE)
real = lookup_replace_object(oid);
if (is_null_oid(real))
return -1; return -1;
if (!oi) if (!oi)
oi = &blank_oi; oi = &blank_oi;
if (!(flags & OBJECT_INFO_SKIP_CACHED)) { if (!(flags & OBJECT_INFO_SKIP_CACHED)) {
struct cached_object *co = find_cached_object(real); struct cached_object *co = find_cached_object(real->hash);
if (co) { if (co) {
if (oi->typep) if (oi->typep)
*(oi->typep) = co->type; *(oi->typep) = co->type;
@@ -1259,20 +1263,20 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
} }
while (1) { while (1) {
if (find_pack_entry(real, &e)) if (find_pack_entry(real->hash, &e))
break; break;
if (flags & OBJECT_INFO_IGNORE_LOOSE) if (flags & OBJECT_INFO_IGNORE_LOOSE)
return -1; return -1;
/* Most likely it's a loose object. */ /* Most likely it's a loose object. */
if (!sha1_loose_object_info(real, oi, flags)) if (!sha1_loose_object_info(real->hash, oi, flags))
return 0; return 0;
/* Not a loose object; someone else may have just packed it. */ /* Not a loose object; someone else may have just packed it. */
if (!(flags & OBJECT_INFO_QUICK)) { if (!(flags & OBJECT_INFO_QUICK)) {
reprepare_packed_git(); reprepare_packed_git();
if (find_pack_entry(real, &e)) if (find_pack_entry(real->hash, &e))
break; break;
} }
@@ -1283,7 +1287,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
* TODO Investigate haveing fetch_object() return * TODO Investigate haveing fetch_object() return
* TODO error/success and stopping the music here. * TODO error/success and stopping the music here.
*/ */
fetch_object(repository_format_partial_clone, real); fetch_object(repository_format_partial_clone, real->hash);
already_retried = 1; already_retried = 1;
continue; continue;
} }
@@ -1299,8 +1303,8 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
return 0; return 0;
rtype = packed_object_info(e.p, e.offset, oi); rtype = packed_object_info(e.p, e.offset, oi);
if (rtype < 0) { if (rtype < 0) {
mark_bad_packed_object(e.p, real); mark_bad_packed_object(e.p, real->hash);
return sha1_object_info_extended(real, oi, 0); return oid_object_info_extended(real, oi, 0);
} else if (oi->whence == OI_PACKED) { } else if (oi->whence == OI_PACKED) {
oi->u.packed.offset = e.offset; oi->u.packed.offset = e.offset;
oi->u.packed.pack = e.p; oi->u.packed.pack = e.p;
@@ -1312,14 +1316,14 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
} }
/* returns enum object_type or negative */ /* returns enum object_type or negative */
int sha1_object_info(const unsigned char *sha1, unsigned long *sizep) int oid_object_info(const struct object_id *oid, unsigned long *sizep)
{ {
enum object_type type; enum object_type type;
struct object_info oi = OBJECT_INFO_INIT; struct object_info oi = OBJECT_INFO_INIT;
oi.typep = &type; oi.typep = &type;
oi.sizep = sizep; oi.sizep = sizep;
if (sha1_object_info_extended(sha1, &oi, if (oid_object_info_extended(oid, &oi,
OBJECT_INFO_LOOKUP_REPLACE) < 0) OBJECT_INFO_LOOKUP_REPLACE) < 0)
return -1; return -1;
return type; return type;
@@ -1328,13 +1332,16 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
static void *read_object(const unsigned char *sha1, enum object_type *type, static void *read_object(const unsigned char *sha1, enum object_type *type,
unsigned long *size) unsigned long *size)
{ {
struct object_id oid;
struct object_info oi = OBJECT_INFO_INIT; struct object_info oi = OBJECT_INFO_INIT;
void *content; void *content;
oi.typep = type; oi.typep = type;
oi.sizep = size; oi.sizep = size;
oi.contentp = &content; oi.contentp = &content;
if (sha1_object_info_extended(sha1, &oi, 0) < 0) hashcpy(oid.hash, sha1);
if (oid_object_info_extended(&oid, &oi, 0) < 0)
return NULL; return NULL;
return content; return content;
} }
@@ -1362,7 +1369,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
* deal with them should arrange to call read_object() and give error * deal with them should arrange to call read_object() and give error
* messages themselves. * messages themselves.
*/ */
void *read_sha1_file_extended(const unsigned char *sha1, void *read_object_file_extended(const struct object_id *oid,
enum object_type *type, enum object_type *type,
unsigned long *size, unsigned long *size,
int lookup_replace) int lookup_replace)
@@ -1371,56 +1378,56 @@ void *read_sha1_file_extended(const unsigned char *sha1,
const struct packed_git *p; const struct packed_git *p;
const char *path; const char *path;
struct stat st; struct stat st;
const unsigned char *repl = lookup_replace ? lookup_replace_object(sha1) const struct object_id *repl = lookup_replace ? lookup_replace_object(oid)
: sha1; : oid;
errno = 0; errno = 0;
data = read_object(repl, type, size); data = read_object(repl->hash, type, size);
if (data) if (data)
return data; return data;
if (errno && errno != ENOENT) 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 */ /* 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", 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, &st, &path)) if (!stat_sha1_file(repl->hash, &st, &path))
die("loose object %s (stored in %s) is corrupt", 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", 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; return NULL;
} }
void *read_object_with_reference(const unsigned char *sha1, void *read_object_with_reference(const struct object_id *oid,
const char *required_type_name, const char *required_type_name,
unsigned long *size, unsigned long *size,
unsigned char *actual_sha1_return) struct object_id *actual_oid_return)
{ {
enum object_type type, required_type; enum object_type type, required_type;
void *buffer; void *buffer;
unsigned long isize; unsigned long isize;
unsigned char actual_sha1[20]; struct object_id actual_oid;
required_type = type_from_string(required_type_name); required_type = type_from_string(required_type_name);
hashcpy(actual_sha1, sha1); oidcpy(&actual_oid, oid);
while (1) { while (1) {
int ref_length = -1; int ref_length = -1;
const char *ref_type = NULL; const char *ref_type = NULL;
buffer = read_sha1_file(actual_sha1, &type, &isize); buffer = read_object_file(&actual_oid, &type, &isize);
if (!buffer) if (!buffer)
return NULL; return NULL;
if (type == required_type) { if (type == required_type) {
*size = isize; *size = isize;
if (actual_sha1_return) if (actual_oid_return)
hashcpy(actual_sha1_return, actual_sha1); oidcpy(actual_oid_return, &actual_oid);
return buffer; return buffer;
} }
/* Handle references */ /* Handle references */
@@ -1434,15 +1441,15 @@ void *read_object_with_reference(const unsigned char *sha1,
} }
ref_length = strlen(ref_type); ref_length = strlen(ref_type);
if (ref_length + 40 > isize || if (ref_length + GIT_SHA1_HEXSZ > isize ||
memcmp(buffer, ref_type, ref_length) || memcmp(buffer, ref_type, ref_length) ||
get_sha1_hex((char *) buffer + ref_length, actual_sha1)) { get_oid_hex((char *) buffer + ref_length, &actual_oid)) {
free(buffer); free(buffer);
return NULL; return NULL;
} }
free(buffer); free(buffer);
/* Now we have the ID of the referred-to object in /* Now we have the ID of the referred-to object in
* actual_sha1. Check again. */ * actual_oid. Check again. */
} }
} }
@@ -1515,7 +1522,7 @@ static int write_buffer(int fd, const void *buf, size_t len)
int hash_object_file(const void *buf, unsigned long len, const char *type, int hash_object_file(const void *buf, unsigned long len, const char *type,
struct object_id *oid) struct object_id *oid)
{ {
char hdr[32]; char hdr[MAX_HEADER_LEN];
int hdrlen = sizeof(hdr); int hdrlen = sizeof(hdr);
write_object_file_prepare(buf, len, type, oid, hdr, &hdrlen); write_object_file_prepare(buf, len, type, oid, hdr, &hdrlen);
return 0; return 0;
@@ -1670,7 +1677,7 @@ static int freshen_packed_object(const unsigned char *sha1)
int write_object_file(const void *buf, unsigned long len, const char *type, int write_object_file(const void *buf, unsigned long len, const char *type,
struct object_id *oid) struct object_id *oid)
{ {
char hdr[32]; char hdr[MAX_HEADER_LEN];
int hdrlen = sizeof(hdr); int hdrlen = sizeof(hdr);
/* Normally if we have it in the pack then we do not bother writing /* Normally if we have it in the pack then we do not bother writing
@@ -1690,7 +1697,7 @@ int hash_object_file_literally(const void *buf, unsigned long len,
int hdrlen, status = 0; int hdrlen, status = 0;
/* type string, SP, %lu of the length plus NUL must fit this */ /* type string, SP, %lu of the length plus NUL must fit this */
hdrlen = strlen(type) + 32; hdrlen = strlen(type) + MAX_HEADER_LEN;
header = xmalloc(hdrlen); header = xmalloc(hdrlen);
write_object_file_prepare(buf, len, type, oid, header, &hdrlen); write_object_file_prepare(buf, len, type, oid, header, &hdrlen);
@@ -1710,7 +1717,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
void *buf; void *buf;
unsigned long len; unsigned long len;
enum object_type type; enum object_type type;
char hdr[32]; char hdr[MAX_HEADER_LEN];
int hdrlen; int hdrlen;
int ret; int ret;
@@ -1728,9 +1735,11 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
int has_sha1_file_with_flags(const unsigned char *sha1, int flags) int has_sha1_file_with_flags(const unsigned char *sha1, int flags)
{ {
struct object_id oid;
if (!startup_info->have_repository) if (!startup_info->have_repository)
return 0; return 0;
return sha1_object_info_extended(sha1, NULL, hashcpy(oid.hash, sha1);
return oid_object_info_extended(&oid, NULL,
flags | OBJECT_INFO_SKIP_CACHED) >= 0; flags | OBJECT_INFO_SKIP_CACHED) >= 0;
} }
@@ -1897,7 +1906,7 @@ static int index_stream(struct object_id *oid, int fd, size_t size,
enum object_type type, const char *path, enum object_type type, const char *path,
unsigned flags) unsigned flags)
{ {
return index_bulk_checkin(oid->hash, fd, size, type, path, flags); return index_bulk_checkin(oid, fd, size, type, path, flags);
} }
int index_fd(struct object_id *oid, int fd, struct stat *st, int index_fd(struct object_id *oid, int fd, struct stat *st,
@@ -1971,13 +1980,13 @@ int read_pack_header(int fd, struct pack_header *header)
return 0; return 0;
} }
void assert_sha1_type(const unsigned char *sha1, enum object_type expect) void assert_oid_type(const struct object_id *oid, enum object_type expect)
{ {
enum object_type type = sha1_object_info(sha1, NULL); enum object_type type = oid_object_info(oid, NULL);
if (type < 0) if (type < 0)
die("%s is not a valid object", sha1_to_hex(sha1)); die("%s is not a valid object", oid_to_hex(oid));
if (type != expect) if (type != expect)
die("%s is not a valid '%s' object", sha1_to_hex(sha1), die("%s is not a valid '%s' object", oid_to_hex(oid),
type_name(expect)); type_name(expect));
} }
@@ -2181,7 +2190,7 @@ static int check_stream_sha1(git_zstream *stream,
} }
int read_loose_object(const char *path, int read_loose_object(const char *path,
const unsigned char *expected_sha1, const struct object_id *expected_oid,
enum object_type *type, enum object_type *type,
unsigned long *size, unsigned long *size,
void **contents) void **contents)
@@ -2190,7 +2199,7 @@ int read_loose_object(const char *path,
void *map = NULL; void *map = NULL;
unsigned long mapsize; unsigned long mapsize;
git_zstream stream; git_zstream stream;
char hdr[32]; char hdr[MAX_HEADER_LEN];
*contents = NULL; *contents = NULL;
@@ -2213,19 +2222,19 @@ int read_loose_object(const char *path,
} }
if (*type == OBJ_BLOB) { if (*type == OBJ_BLOB) {
if (check_stream_sha1(&stream, hdr, *size, path, expected_sha1) < 0) if (check_stream_sha1(&stream, hdr, *size, path, expected_oid->hash) < 0)
goto out; goto out;
} else { } else {
*contents = unpack_sha1_rest(&stream, hdr, *size, expected_sha1); *contents = unpack_sha1_rest(&stream, hdr, *size, expected_oid->hash);
if (!*contents) { if (!*contents) {
error("unable to unpack contents of %s", path); error("unable to unpack contents of %s", path);
git_inflate_end(&stream); git_inflate_end(&stream);
goto out; goto out;
} }
if (check_sha1_signature(expected_sha1, *contents, if (check_object_signature(expected_oid, *contents,
*size, type_name(*type))) { *size, type_name(*type))) {
error("sha1 mismatch for %s (expected %s)", path, error("sha1 mismatch for %s (expected %s)", path,
sha1_to_hex(expected_sha1)); oid_to_hex(expected_oid));
free(*contents); free(*contents);
goto out; goto out;
} }

View File

@@ -238,7 +238,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused) static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused)
{ {
int kind = sha1_object_info(oid->hash, NULL); int kind = oid_object_info(oid, NULL);
return kind == OBJ_COMMIT; return kind == OBJ_COMMIT;
} }
@@ -247,7 +247,7 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da
struct object *obj; struct object *obj;
int kind; int kind;
kind = sha1_object_info(oid->hash, NULL); kind = oid_object_info(oid, NULL);
if (kind == OBJ_COMMIT) if (kind == OBJ_COMMIT)
return 1; return 1;
if (kind != OBJ_TAG) if (kind != OBJ_TAG)
@@ -262,7 +262,7 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da
static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused) static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused)
{ {
int kind = sha1_object_info(oid->hash, NULL); int kind = oid_object_info(oid, NULL);
return kind == OBJ_TREE; return kind == OBJ_TREE;
} }
@@ -271,7 +271,7 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_
struct object *obj; struct object *obj;
int kind; int kind;
kind = sha1_object_info(oid->hash, NULL); kind = oid_object_info(oid, NULL);
if (kind == OBJ_TREE || kind == OBJ_COMMIT) if (kind == OBJ_TREE || kind == OBJ_COMMIT)
return 1; return 1;
if (kind != OBJ_TAG) if (kind != OBJ_TAG)
@@ -286,7 +286,7 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_
static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused) static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused)
{ {
int kind = sha1_object_info(oid->hash, NULL); int kind = oid_object_info(oid, NULL);
return kind == OBJ_BLOB; return kind == OBJ_BLOB;
} }
@@ -365,7 +365,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
if (ds->fn && !ds->fn(oid, ds->cb_data)) if (ds->fn && !ds->fn(oid, ds->cb_data))
return 0; return 0;
type = sha1_object_info(oid->hash, NULL); type = oid_object_info(oid, NULL);
if (type == OBJ_COMMIT) { if (type == OBJ_COMMIT) {
struct commit *commit = lookup_commit(oid); struct commit *commit = lookup_commit(oid);
if (commit) { if (commit) {
@@ -380,7 +380,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
} }
advise(" %s %s%s", advise(" %s %s%s",
find_unique_abbrev(oid->hash, DEFAULT_ABBREV), find_unique_abbrev(oid, DEFAULT_ABBREV),
type_name(type) ? type_name(type) : "unknown type", type_name(type) ? type_name(type) : "unknown type",
desc.buf); desc.buf);
@@ -569,7 +569,7 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
find_abbrev_len_for_pack(p, mad); find_abbrev_len_for_pack(p, mad);
} }
int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len) int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
{ {
struct disambiguate_state ds; struct disambiguate_state ds;
struct min_abbrev_data mad; struct min_abbrev_data mad;
@@ -596,14 +596,14 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
len = FALLBACK_DEFAULT_ABBREV; len = FALLBACK_DEFAULT_ABBREV;
} }
sha1_to_hex_r(hex, sha1); oid_to_hex_r(hex, oid);
if (len == GIT_SHA1_HEXSZ || !len) if (len == GIT_SHA1_HEXSZ || !len)
return GIT_SHA1_HEXSZ; return GIT_SHA1_HEXSZ;
mad.init_len = len; mad.init_len = len;
mad.cur_len = len; mad.cur_len = len;
mad.hex = hex; mad.hex = hex;
mad.hash = sha1; mad.hash = oid->hash;
find_abbrev_len_packed(&mad); find_abbrev_len_packed(&mad);
@@ -621,13 +621,13 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
return mad.cur_len; return mad.cur_len;
} }
const char *find_unique_abbrev(const unsigned char *sha1, int len) const char *find_unique_abbrev(const struct object_id *oid, int len)
{ {
static int bufno; static int bufno;
static char hexbuffer[4][GIT_MAX_HEXSZ + 1]; static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
char *hex = hexbuffer[bufno]; char *hex = hexbuffer[bufno];
bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer); bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
find_unique_abbrev_r(hex, sha1, len); find_unique_abbrev_r(hex, oid, len);
return hex; return hex;
} }
@@ -1529,8 +1529,7 @@ static void diagnose_invalid_oid_path(const char *prefix,
if (is_missing_file_error(errno)) { if (is_missing_file_error(errno)) {
char *fullname = xstrfmt("%s%s", prefix, filename); char *fullname = xstrfmt("%s%s", prefix, filename);
if (!get_tree_entry(tree_oid->hash, fullname, if (!get_tree_entry(tree_oid, fullname, &oid, &mode)) {
oid.hash, &mode)) {
die("Path '%s' exists, but not '%s'.\n" die("Path '%s' exists, but not '%s'.\n"
"Did you mean '%.*s:%s' aka '%.*s:./%s'?", "Did you mean '%.*s:%s' aka '%.*s:./%s'?",
fullname, fullname,
@@ -1722,8 +1721,8 @@ static int get_oid_with_context_1(const char *name,
filename, oid->hash, &oc->symlink_path, filename, oid->hash, &oc->symlink_path,
&oc->mode); &oc->mode);
} else { } else {
ret = get_tree_entry(tree_oid.hash, filename, ret = get_tree_entry(&tree_oid, filename, oid,
oid->hash, &oc->mode); &oc->mode);
if (ret && only_to_die) { if (ret && only_to_die) {
diagnose_invalid_oid_path(prefix, diagnose_invalid_oid_path(prefix,
filename, filename,

View File

@@ -897,12 +897,12 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
strbuf_setlen(sb, sb->len + len); strbuf_setlen(sb, sb->len + len);
} }
void strbuf_add_unique_abbrev(struct strbuf *sb, const unsigned char *sha1, void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
int abbrev_len) int abbrev_len)
{ {
int r; int r;
strbuf_grow(sb, GIT_SHA1_HEXSZ + 1); strbuf_grow(sb, GIT_SHA1_HEXSZ + 1);
r = find_unique_abbrev_r(sb->buf + sb->len, sha1, abbrev_len); r = find_unique_abbrev_r(sb->buf + sb->len, oid, abbrev_len);
strbuf_setlen(sb, sb->len + r); strbuf_setlen(sb, sb->len + r);
} }

View File

@@ -72,6 +72,12 @@ struct strbuf {
extern char strbuf_slopbuf[]; extern char strbuf_slopbuf[];
#define STRBUF_INIT { .alloc = 0, .len = 0, .buf = strbuf_slopbuf } #define STRBUF_INIT { .alloc = 0, .len = 0, .buf = strbuf_slopbuf }
/*
* Predeclare this here, since cache.h includes this file before it defines the
* struct.
*/
struct object_id;
/** /**
* Life Cycle Functions * Life Cycle Functions
* -------------------- * --------------------
@@ -558,7 +564,7 @@ extern void strbuf_list_free(struct strbuf **);
* the strbuf `sb`. * the strbuf `sb`.
*/ */
extern void strbuf_add_unique_abbrev(struct strbuf *sb, extern void strbuf_add_unique_abbrev(struct strbuf *sb,
const unsigned char *sha1, const struct object_id *oid,
int abbrev_len); int abbrev_len);
/** /**

View File

@@ -14,7 +14,7 @@ enum input_source {
typedef int (*open_istream_fn)(struct git_istream *, typedef int (*open_istream_fn)(struct git_istream *,
struct object_info *, struct object_info *,
const unsigned char *, const struct object_id *,
enum object_type *); enum object_type *);
typedef int (*close_istream_fn)(struct git_istream *); typedef int (*close_istream_fn)(struct git_istream *);
typedef ssize_t (*read_istream_fn)(struct git_istream *, char *, size_t); typedef ssize_t (*read_istream_fn)(struct git_istream *, char *, size_t);
@@ -27,7 +27,7 @@ struct stream_vtbl {
#define open_method_decl(name) \ #define open_method_decl(name) \
int open_istream_ ##name \ int open_istream_ ##name \
(struct git_istream *st, struct object_info *oi, \ (struct git_istream *st, struct object_info *oi, \
const unsigned char *sha1, \ const struct object_id *oid, \
enum object_type *type) enum object_type *type)
#define close_method_decl(name) \ #define close_method_decl(name) \
@@ -105,7 +105,7 @@ ssize_t read_istream(struct git_istream *st, void *buf, size_t sz)
return st->vtbl->read(st, buf, sz); return st->vtbl->read(st, buf, sz);
} }
static enum input_source istream_source(const unsigned char *sha1, static enum input_source istream_source(const struct object_id *oid,
enum object_type *type, enum object_type *type,
struct object_info *oi) struct object_info *oi)
{ {
@@ -114,7 +114,7 @@ static enum input_source istream_source(const unsigned char *sha1,
oi->typep = type; oi->typep = type;
oi->sizep = &size; oi->sizep = &size;
status = sha1_object_info_extended(sha1, oi, 0); status = oid_object_info_extended(oid, oi, 0);
if (status < 0) if (status < 0)
return stream_error; return stream_error;
@@ -130,14 +130,14 @@ static enum input_source istream_source(const unsigned char *sha1,
} }
} }
struct git_istream *open_istream(const unsigned char *sha1, struct git_istream *open_istream(const struct object_id *oid,
enum object_type *type, enum object_type *type,
unsigned long *size, unsigned long *size,
struct stream_filter *filter) struct stream_filter *filter)
{ {
struct git_istream *st; struct git_istream *st;
struct object_info oi = OBJECT_INFO_INIT; struct object_info oi = OBJECT_INFO_INIT;
const unsigned char *real = lookup_replace_object(sha1); const struct object_id *real = lookup_replace_object(oid);
enum input_source src = istream_source(real, type, &oi); enum input_source src = istream_source(real, type, &oi);
if (src < 0) if (src < 0)
@@ -335,7 +335,7 @@ static struct stream_vtbl loose_vtbl = {
static open_method_decl(loose) static open_method_decl(loose)
{ {
st->u.loose.mapped = map_sha1_file(sha1, &st->u.loose.mapsize); st->u.loose.mapped = map_sha1_file(oid->hash, &st->u.loose.mapsize);
if (!st->u.loose.mapped) if (!st->u.loose.mapped)
return -1; return -1;
if ((unpack_sha1_header(&st->z, if ((unpack_sha1_header(&st->z,
@@ -486,7 +486,7 @@ static struct stream_vtbl incore_vtbl = {
static open_method_decl(incore) static open_method_decl(incore)
{ {
st->u.incore.buf = read_sha1_file_extended(sha1, type, &st->size, 0); st->u.incore.buf = read_object_file_extended(oid, type, &st->size, 0);
st->u.incore.read_ptr = 0; st->u.incore.read_ptr = 0;
st->vtbl = &incore_vtbl; st->vtbl = &incore_vtbl;
@@ -507,7 +507,7 @@ int stream_blob_to_fd(int fd, const struct object_id *oid, struct stream_filter
ssize_t kept = 0; ssize_t kept = 0;
int result = -1; int result = -1;
st = open_istream(oid->hash, &type, &sz, filter); st = open_istream(oid, &type, &sz, filter);
if (!st) { if (!st) {
if (filter) if (filter)
free_stream_filter(filter); free_stream_filter(filter);

View File

@@ -8,7 +8,7 @@
/* opaque */ /* opaque */
struct git_istream; struct git_istream;
extern struct git_istream *open_istream(const unsigned char *, enum object_type *, unsigned long *, struct stream_filter *); extern struct git_istream *open_istream(const struct object_id *, enum object_type *, unsigned long *, struct stream_filter *);
extern int close_istream(struct git_istream *); extern int close_istream(struct git_istream *);
extern ssize_t read_istream(struct git_istream *, void *, size_t); extern ssize_t read_istream(struct git_istream *, void *, size_t);

Some files were not shown because too many files have changed in this diff Show More