Merge branch 'bc/object-id'

* bc/object-id: (53 commits)
  object: convert parse_object* to take struct object_id
  tree: convert parse_tree_indirect to struct object_id
  sequencer: convert do_recursive_merge to struct object_id
  diff-lib: convert do_diff_cache to struct object_id
  builtin/ls-tree: convert to struct object_id
  merge: convert checkout_fast_forward to struct object_id
  sequencer: convert fast_forward_to to struct object_id
  builtin/ls-files: convert overlay_tree_on_cache to object_id
  builtin/read-tree: convert to struct object_id
  sha1_name: convert internals of peel_onion to object_id
  upload-pack: convert remaining parse_object callers to object_id
  revision: convert remaining parse_object callers to object_id
  revision: rename add_pending_sha1 to add_pending_oid
  http-push: convert process_ls_object and descendants to object_id
  refs/files-backend: convert many internals to struct object_id
  refs: convert struct ref_update to use struct object_id
  ref-filter: convert some static functions to struct object_id
  Convert struct ref_array_item to struct object_id
  Convert the verify_pack callback to struct object_id
  Convert lookup_tag to struct object_id
  ...
This commit is contained in:
Junio C Hamano 2017-05-23 14:29:19 +09:00
commit ca7b2ab07d
106 changed files with 1174 additions and 1135 deletions

View File

@ -360,7 +360,7 @@ static void parse_treeish_arg(const char **argv,
if (get_sha1(name, oid.hash)) if (get_sha1(name, oid.hash))
die("Not a valid object name"); die("Not a valid object name");
commit = lookup_commit_reference_gently(oid.hash, 1); commit = lookup_commit_reference_gently(&oid, 1);
if (commit) { if (commit) {
commit_sha1 = commit->object.oid.hash; commit_sha1 = commit->object.oid.hash;
archive_time = commit->date; archive_time = commit->date;
@ -369,7 +369,7 @@ static void parse_treeish_arg(const char **argv,
archive_time = time(NULL); archive_time = time(NULL);
} }
tree = parse_tree_indirect(oid.hash); tree = parse_tree_indirect(&oid);
if (tree == NULL) if (tree == NULL)
die("not a tree object"); die("not a tree object");
@ -383,7 +383,7 @@ static void parse_treeish_arg(const char **argv,
if (err || !S_ISDIR(mode)) if (err || !S_ISDIR(mode))
die("current working directory is untracked"); die("current working directory is untracked");
tree = parse_tree_indirect(tree_oid.hash); tree = parse_tree_indirect(&tree_oid);
} }
ar_args->tree = tree; ar_args->tree = tree;
ar_args->commit_sha1 = commit_sha1; ar_args->commit_sha1 = commit_sha1;

View File

@ -705,7 +705,7 @@ static int bisect_checkout(const unsigned char *bisect_rev, int no_checkout)
static struct commit *get_commit_reference(const struct object_id *oid) static struct commit *get_commit_reference(const struct object_id *oid)
{ {
struct commit *r = lookup_commit_reference(oid->hash); struct commit *r = lookup_commit_reference(oid);
if (!r) if (!r)
die(_("Not a valid commit name %s"), oid_to_hex(oid)); die(_("Not a valid commit name %s"), oid_to_hex(oid));
return r; return r;

6
blob.c
View File

@ -3,11 +3,11 @@
const char *blob_type = "blob"; const char *blob_type = "blob";
struct blob *lookup_blob(const unsigned char *sha1) struct blob *lookup_blob(const struct object_id *oid)
{ {
struct object *obj = lookup_object(sha1); struct object *obj = lookup_object(oid->hash);
if (!obj) if (!obj)
return create_object(sha1, alloc_blob_node()); return create_object(oid->hash, alloc_blob_node());
return object_as_type(obj, OBJ_BLOB, 0); return object_as_type(obj, OBJ_BLOB, 0);
} }

2
blob.h
View File

@ -9,7 +9,7 @@ struct blob {
struct object object; struct object object;
}; };
struct blob *lookup_blob(const unsigned char *sha1); struct blob *lookup_blob(const struct object_id *oid);
int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size); int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size);

View File

@ -191,9 +191,9 @@ int validate_new_branchname(const char *name, struct strbuf *ref,
if (!attr_only) { if (!attr_only) {
const char *head; const char *head;
unsigned char sha1[20]; struct object_id oid;
head = resolve_ref_unsafe("HEAD", 0, sha1, NULL); head = resolve_ref_unsafe("HEAD", 0, oid.hash, NULL);
if (!is_bare_repository() && head && !strcmp(head, ref->buf)) if (!is_bare_repository() && head && !strcmp(head, ref->buf))
die(_("Cannot force update the current branch.")); die(_("Cannot force update the current branch."));
} }
@ -233,7 +233,7 @@ void create_branch(const char *name, const char *start_name,
int quiet, enum branch_track track) int quiet, enum branch_track track)
{ {
struct commit *commit; struct commit *commit;
unsigned char sha1[20]; struct object_id oid;
char *real_ref; char *real_ref;
struct strbuf ref = STRBUF_INIT; struct strbuf ref = STRBUF_INIT;
int forcing = 0; int forcing = 0;
@ -253,7 +253,7 @@ void create_branch(const char *name, const char *start_name,
} }
real_ref = NULL; real_ref = NULL;
if (get_sha1(start_name, sha1)) { if (get_oid(start_name, &oid)) {
if (explicit_tracking) { if (explicit_tracking) {
if (advice_set_upstream_failure) { if (advice_set_upstream_failure) {
error(_(upstream_missing), start_name); error(_(upstream_missing), start_name);
@ -265,7 +265,7 @@ void create_branch(const char *name, const char *start_name,
die(_("Not a valid object name: '%s'."), start_name); die(_("Not a valid object name: '%s'."), start_name);
} }
switch (dwim_ref(start_name, strlen(start_name), sha1, &real_ref)) { switch (dwim_ref(start_name, strlen(start_name), oid.hash, &real_ref)) {
case 0: case 0:
/* Not branching from any existing branch */ /* Not branching from any existing branch */
if (explicit_tracking) if (explicit_tracking)
@ -286,9 +286,9 @@ void create_branch(const char *name, const char *start_name,
break; break;
} }
if ((commit = lookup_commit_reference(sha1)) == NULL) if ((commit = lookup_commit_reference(&oid)) == NULL)
die(_("Not a valid branch point: '%s'."), start_name); die(_("Not a valid branch point: '%s'."), start_name);
hashcpy(sha1, commit->object.oid.hash); oidcpy(&oid, &commit->object.oid);
if (reflog) if (reflog)
log_all_ref_updates = LOG_REFS_NORMAL; log_all_ref_updates = LOG_REFS_NORMAL;
@ -306,7 +306,7 @@ void create_branch(const char *name, const char *start_name,
transaction = ref_transaction_begin(&err); transaction = ref_transaction_begin(&err);
if (!transaction || if (!transaction ||
ref_transaction_update(transaction, ref.buf, ref_transaction_update(transaction, ref.buf,
sha1, forcing ? NULL : null_sha1, oid.hash, forcing ? NULL : null_sha1,
0, msg, &err) || 0, msg, &err) ||
ref_transaction_commit(transaction, &err)) ref_transaction_commit(transaction, &err))
die("%s", err.buf); die("%s", err.buf);

View File

@ -1145,7 +1145,7 @@ static int index_has_changes(struct strbuf *sb)
DIFF_OPT_SET(&opt, EXIT_WITH_STATUS); DIFF_OPT_SET(&opt, EXIT_WITH_STATUS);
if (!sb) if (!sb)
DIFF_OPT_SET(&opt, QUICK); DIFF_OPT_SET(&opt, QUICK);
do_diff_cache(head.hash, &opt); do_diff_cache(&head, &opt);
diffcore_std(&opt); diffcore_std(&opt);
for (i = 0; sb && i < diff_queued_diff.nr; i++) { for (i = 0; sb && i < diff_queued_diff.nr; i++) {
if (i) if (i)
@ -1447,9 +1447,9 @@ static void write_index_patch(const struct am_state *state)
FILE *fp; FILE *fp;
if (!get_sha1_tree("HEAD", head.hash)) if (!get_sha1_tree("HEAD", head.hash))
tree = lookup_tree(head.hash); tree = lookup_tree(&head);
else else
tree = lookup_tree(EMPTY_TREE_SHA1_BIN); tree = lookup_tree(&empty_tree_oid);
fp = xfopen(am_path(state, "patch"), "w"); fp = xfopen(am_path(state, "patch"), "w");
init_revisions(&rev_info, NULL); init_revisions(&rev_info, NULL);
@ -1482,7 +1482,7 @@ static int parse_mail_rebase(struct am_state *state, const char *mail)
if (get_mail_commit_oid(&commit_oid, mail) < 0) if (get_mail_commit_oid(&commit_oid, mail) < 0)
die(_("could not parse %s"), mail); die(_("could not parse %s"), mail);
commit = lookup_commit_or_die(commit_oid.hash, mail); commit = lookup_commit_or_die(&commit_oid, mail);
get_commit_info(state, commit); get_commit_info(state, commit);
@ -1612,7 +1612,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
init_revisions(&rev_info, NULL); init_revisions(&rev_info, NULL);
rev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS; rev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
diff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1, rev_info.prefix); diff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1, rev_info.prefix);
add_pending_sha1(&rev_info, "HEAD", our_tree.hash, 0); add_pending_oid(&rev_info, "HEAD", &our_tree, 0);
diff_setup_done(&rev_info.diffopt); diff_setup_done(&rev_info.diffopt);
run_diff_index(&rev_info, 1); run_diff_index(&rev_info, 1);
} }
@ -1677,7 +1677,7 @@ static void do_commit(const struct am_state *state)
if (!get_sha1_commit("HEAD", parent.hash)) { if (!get_sha1_commit("HEAD", parent.hash)) {
old_oid = &parent; old_oid = &parent;
commit_list_insert(lookup_commit(parent.hash), &parents); commit_list_insert(lookup_commit(&parent), &parents);
} else { } else {
old_oid = NULL; old_oid = NULL;
say(state, stderr, _("applying to an empty history")); say(state, stderr, _("applying to an empty history"));
@ -2039,11 +2039,11 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
struct tree *head_tree, *remote_tree, *index_tree; struct tree *head_tree, *remote_tree, *index_tree;
struct object_id index; struct object_id index;
head_tree = parse_tree_indirect(head->hash); head_tree = parse_tree_indirect(head);
if (!head_tree) if (!head_tree)
return error(_("Could not parse object '%s'."), oid_to_hex(head)); return error(_("Could not parse object '%s'."), oid_to_hex(head));
remote_tree = parse_tree_indirect(remote->hash); remote_tree = parse_tree_indirect(remote);
if (!remote_tree) if (!remote_tree)
return error(_("Could not parse object '%s'."), oid_to_hex(remote)); return error(_("Could not parse object '%s'."), oid_to_hex(remote));
@ -2055,7 +2055,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
if (write_cache_as_tree(index.hash, 0, NULL)) if (write_cache_as_tree(index.hash, 0, NULL))
return -1; return -1;
index_tree = parse_tree_indirect(index.hash); index_tree = parse_tree_indirect(&index);
if (!index_tree) if (!index_tree)
return error(_("Could not parse object '%s'."), oid_to_hex(&index)); return error(_("Could not parse object '%s'."), oid_to_hex(&index));

View File

@ -563,7 +563,7 @@ static struct origin *find_origin(struct scoreboard *sb,
diff_setup_done(&diff_opts); diff_setup_done(&diff_opts);
if (is_null_oid(&origin->commit->object.oid)) if (is_null_oid(&origin->commit->object.oid))
do_diff_cache(parent->tree->object.oid.hash, &diff_opts); do_diff_cache(&parent->tree->object.oid, &diff_opts);
else else
diff_tree_sha1(parent->tree->object.oid.hash, diff_tree_sha1(parent->tree->object.oid.hash,
origin->commit->tree->object.oid.hash, origin->commit->tree->object.oid.hash,
@ -633,7 +633,7 @@ static struct origin *find_rename(struct scoreboard *sb,
diff_setup_done(&diff_opts); diff_setup_done(&diff_opts);
if (is_null_oid(&origin->commit->object.oid)) if (is_null_oid(&origin->commit->object.oid))
do_diff_cache(parent->tree->object.oid.hash, &diff_opts); do_diff_cache(&parent->tree->object.oid, &diff_opts);
else else
diff_tree_sha1(parent->tree->object.oid.hash, diff_tree_sha1(parent->tree->object.oid.hash,
origin->commit->tree->object.oid.hash, origin->commit->tree->object.oid.hash,
@ -1272,7 +1272,7 @@ static void find_copy_in_parent(struct scoreboard *sb,
DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER); DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);
if (is_null_oid(&target->commit->object.oid)) if (is_null_oid(&target->commit->object.oid))
do_diff_cache(parent->tree->object.oid.hash, &diff_opts); do_diff_cache(&parent->tree->object.oid, &diff_opts);
else else
diff_tree_sha1(parent->tree->object.oid.hash, diff_tree_sha1(parent->tree->object.oid.hash,
target->commit->tree->object.oid.hash, target->commit->tree->object.oid.hash,
@ -2253,7 +2253,7 @@ static struct commit_list **append_parent(struct commit_list **tail, const struc
{ {
struct commit *parent; struct commit *parent;
parent = lookup_commit_reference(oid->hash); parent = lookup_commit_reference(oid);
if (!parent) if (!parent)
die("no such commit %s", oid_to_hex(oid)); die("no such commit %s", oid_to_hex(oid));
return &commit_list_insert(parent, tail)->next; return &commit_list_insert(parent, tail)->next;
@ -2461,7 +2461,7 @@ static const char *dwim_reverse_initial(struct scoreboard *sb)
*/ */
struct object *obj; struct object *obj;
struct commit *head_commit; struct commit *head_commit;
unsigned char head_sha1[20]; struct object_id head_oid;
if (sb->revs->pending.nr != 1) if (sb->revs->pending.nr != 1)
return NULL; return NULL;
@ -2473,9 +2473,9 @@ static const char *dwim_reverse_initial(struct scoreboard *sb)
return NULL; return NULL;
/* Do we have HEAD? */ /* Do we have HEAD? */
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_sha1, NULL)) if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
return NULL; return NULL;
head_commit = lookup_commit_reference_gently(head_sha1, 1); head_commit = lookup_commit_reference_gently(&head_oid, 1);
if (!head_commit) if (!head_commit)
return NULL; return NULL;

View File

@ -124,7 +124,7 @@ static int branch_merged(int kind, const char *name,
(reference_name = reference_name_to_free = (reference_name = reference_name_to_free =
resolve_refdup(upstream, RESOLVE_REF_READING, resolve_refdup(upstream, RESOLVE_REF_READING,
oid.hash, NULL)) != NULL) oid.hash, NULL)) != NULL)
reference_rev = lookup_commit_reference(oid.hash); reference_rev = lookup_commit_reference(&oid);
} }
if (!reference_rev) if (!reference_rev)
reference_rev = head_rev; reference_rev = head_rev;
@ -157,7 +157,7 @@ static int check_branch_commit(const char *branchname, const char *refname,
const struct object_id *oid, struct commit *head_rev, const struct object_id *oid, struct commit *head_rev,
int kinds, int force) int kinds, int force)
{ {
struct commit *rev = lookup_commit_reference(oid->hash); struct commit *rev = lookup_commit_reference(oid);
if (!rev) { if (!rev) {
error(_("Couldn't look up commit object for '%s'"), refname); error(_("Couldn't look up commit object for '%s'"), refname);
return -1; return -1;
@ -211,7 +211,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
} }
if (!force) { if (!force) {
head_rev = lookup_commit_reference(head_oid.hash); head_rev = lookup_commit_reference(&head_oid);
if (!head_rev) if (!head_rev)
die(_("Couldn't look up commit object for HEAD")); die(_("Couldn't look up commit object for HEAD"));
} }

View File

@ -393,7 +393,7 @@ static int checkout_paths(const struct checkout_opts *opts,
die(_("unable to write new index file")); die(_("unable to write new index file"));
read_ref_full("HEAD", 0, rev.hash, NULL); read_ref_full("HEAD", 0, rev.hash, NULL);
head = lookup_commit_reference_gently(rev.hash, 1); head = lookup_commit_reference_gently(&rev, 1);
errs |= post_checkout_hook(head, head, 0); errs |= post_checkout_hook(head, head, 0);
return errs; return errs;
@ -527,10 +527,10 @@ static int merge_working_tree(const struct checkout_opts *opts,
setup_standard_excludes(topts.dir); setup_standard_excludes(topts.dir);
} }
tree = parse_tree_indirect(old->commit ? tree = parse_tree_indirect(old->commit ?
old->commit->object.oid.hash : &old->commit->object.oid :
EMPTY_TREE_SHA1_BIN); &empty_tree_oid);
init_tree_desc(&trees[0], tree->buffer, tree->size); init_tree_desc(&trees[0], tree->buffer, tree->size);
tree = parse_tree_indirect(new->commit->object.oid.hash); tree = parse_tree_indirect(&new->commit->object.oid);
init_tree_desc(&trees[1], tree->buffer, tree->size); init_tree_desc(&trees[1], tree->buffer, tree->size);
ret = unpack_trees(2, trees, &topts); ret = unpack_trees(2, trees, &topts);
@ -721,7 +721,7 @@ static int add_pending_uninteresting_ref(const char *refname,
const struct object_id *oid, const struct object_id *oid,
int flags, void *cb_data) int flags, void *cb_data)
{ {
add_pending_sha1(cb_data, refname, oid->hash, UNINTERESTING); add_pending_oid(cb_data, refname, oid, UNINTERESTING);
return 0; return 0;
} }
@ -807,7 +807,7 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new)
add_pending_object(&revs, object, oid_to_hex(&object->oid)); add_pending_object(&revs, object, oid_to_hex(&object->oid));
for_each_ref(add_pending_uninteresting_ref, &revs); for_each_ref(add_pending_uninteresting_ref, &revs);
add_pending_sha1(&revs, "HEAD", new->object.oid.hash, UNINTERESTING); add_pending_oid(&revs, "HEAD", &new->object.oid, UNINTERESTING);
refs = revs.pending; refs = revs.pending;
revs.leak_pending = 1; revs.leak_pending = 1;
@ -834,7 +834,7 @@ static int switch_branches(const struct checkout_opts *opts,
memset(&old, 0, sizeof(old)); memset(&old, 0, sizeof(old));
old.path = path_to_free = resolve_refdup("HEAD", 0, rev.hash, &flag); old.path = path_to_free = resolve_refdup("HEAD", 0, rev.hash, &flag);
if (old.path) if (old.path)
old.commit = lookup_commit_reference_gently(rev.hash, 1); old.commit = lookup_commit_reference_gently(&rev, 1);
if (!(flag & REF_ISSYMREF)) if (!(flag & REF_ISSYMREF))
old.path = NULL; old.path = NULL;
@ -1048,10 +1048,10 @@ static int parse_branchname_arg(int argc, const char **argv,
else else
new->path = NULL; /* not an existing branch */ new->path = NULL; /* not an existing branch */
new->commit = lookup_commit_reference_gently(rev->hash, 1); new->commit = lookup_commit_reference_gently(rev, 1);
if (!new->commit) { if (!new->commit) {
/* not a commit */ /* not a commit */
*source_tree = parse_tree_indirect(rev->hash); *source_tree = parse_tree_indirect(rev);
} else { } else {
parse_commit_or_die(new->commit); parse_commit_or_die(new->commit);
*source_tree = new->commit->tree; *source_tree = new->commit->tree;

View File

@ -685,7 +685,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
install_branch_config(0, head, option_origin, our->name); install_branch_config(0, head, option_origin, our->name);
} }
} else if (our) { } else if (our) {
struct commit *c = lookup_commit_reference(our->old_oid.hash); struct commit *c = lookup_commit_reference(&our->old_oid);
/* --branch specifies a non-branch (i.e. tags), detach HEAD */ /* --branch specifies a non-branch (i.e. tags), detach HEAD */
update_ref(msg, "HEAD", c->object.oid.hash, update_ref(msg, "HEAD", c->object.oid.hash,
NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR); NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
@ -742,7 +742,7 @@ static int checkout(int submodule_progress)
opts.src_index = &the_index; opts.src_index = &the_index;
opts.dst_index = &the_index; opts.dst_index = &the_index;
tree = parse_tree_indirect(oid.hash); tree = parse_tree_indirect(&oid);
parse_tree(tree); parse_tree(tree);
init_tree_desc(&t, tree->buffer, tree->size); init_tree_desc(&t, tree->buffer, tree->size);
if (unpack_trees(1, &t, &opts) < 0) if (unpack_trees(1, &t, &opts) < 0)

View File

@ -58,7 +58,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
if (get_sha1_commit(argv[i], oid.hash)) if (get_sha1_commit(argv[i], oid.hash))
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_sha1_type(oid.hash, OBJ_COMMIT);
new_parent(lookup_commit(oid.hash), &parents); new_parent(lookup_commit(&oid), &parents);
continue; continue;
} }

View File

@ -313,7 +313,7 @@ static void create_base_index(const struct commit *current_head)
opts.dst_index = &the_index; opts.dst_index = &the_index;
opts.fn = oneway_merge; opts.fn = oneway_merge;
tree = parse_tree_indirect(current_head->object.oid.hash); tree = parse_tree_indirect(&current_head->object.oid);
if (!tree) if (!tree)
die(_("failed to unpack HEAD tree object")); die(_("failed to unpack HEAD tree object"));
parse_tree(tree); parse_tree(tree);
@ -1434,7 +1434,7 @@ static void print_summary(const char *prefix, const struct object_id *oid,
struct strbuf author_ident = STRBUF_INIT; struct strbuf author_ident = STRBUF_INIT;
struct strbuf committer_ident = STRBUF_INIT; struct strbuf committer_ident = STRBUF_INIT;
commit = lookup_commit(oid->hash); commit = lookup_commit(oid);
if (!commit) if (!commit)
die(_("couldn't look up newly created commit")); die(_("couldn't look up newly created commit"));
if (parse_commit(commit)) if (parse_commit(commit))
@ -1658,7 +1658,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
if (get_sha1("HEAD", oid.hash)) if (get_sha1("HEAD", oid.hash))
current_head = NULL; current_head = NULL;
else { else {
current_head = lookup_commit_or_die(oid.hash, "HEAD"); current_head = lookup_commit_or_die(&oid, "HEAD");
if (parse_commit(current_head)) if (parse_commit(current_head))
die(_("could not parse HEAD commit")); die(_("could not parse HEAD commit"));
} }
@ -1762,7 +1762,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
append_merge_tag_headers(parents, &tail); append_merge_tag_headers(parents, &tail);
} }
if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->sha1, if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->oid.hash,
parents, oid.hash, author_ident.buf, sign_commit, extra)) { parents, oid.hash, author_ident.buf, sign_commit, extra)) {
rollback_index_files(); rollback_index_files();
die(_("failed to write commit object")); die(_("failed to write commit object"));

View File

@ -79,13 +79,13 @@ static int replace_name(struct commit_name *e,
struct tag *t; struct tag *t;
if (!e->tag) { if (!e->tag) {
t = lookup_tag(e->oid.hash); t = lookup_tag(&e->oid);
if (!t || parse_tag(t)) if (!t || parse_tag(t))
return 1; return 1;
e->tag = t; e->tag = t;
} }
t = lookup_tag(oid->hash); t = lookup_tag(oid);
if (!t || parse_tag(t)) if (!t || parse_tag(t))
return 0; return 0;
*tag = t; *tag = t;
@ -245,7 +245,7 @@ static unsigned long finish_depth_computation(
static void display_name(struct commit_name *n) static void display_name(struct commit_name *n)
{ {
if (n->prio == 2 && !n->tag) { if (n->prio == 2 && !n->tag) {
n->tag = lookup_tag(n->oid.hash); n->tag = lookup_tag(&n->oid);
if (!n->tag || parse_tag(n->tag)) if (!n->tag || parse_tag(n->tag))
die(_("annotated tag %s not available"), n->path); die(_("annotated tag %s not available"), n->path);
} }
@ -281,7 +281,7 @@ static void describe(const char *arg, int last_one)
if (get_oid(arg, &oid)) if (get_oid(arg, &oid))
die(_("Not a valid object name %s"), arg); die(_("Not a valid object name %s"), arg);
cmit = lookup_commit_reference(oid.hash); cmit = lookup_commit_reference(&oid);
if (!cmit) if (!cmit)
die(_("%s is not a valid '%s' object"), arg, commit_type); die(_("%s is not a valid '%s' object"), arg, commit_type);
@ -309,7 +309,7 @@ static void describe(const char *arg, int last_one)
struct commit *c; struct commit *c;
struct commit_name *n = hashmap_iter_first(&names, &iter); struct commit_name *n = hashmap_iter_first(&names, &iter);
for (; n; n = hashmap_iter_next(&iter)) { for (; n; n = hashmap_iter_next(&iter)) {
c = lookup_commit_reference_gently(n->peeled.hash, 1); c = lookup_commit_reference_gently(&n->peeled, 1);
if (c) if (c)
c->util = n; c->util = n;
} }

View File

@ -9,7 +9,7 @@ static struct rev_info log_tree_opt;
static int diff_tree_commit_sha1(const struct object_id *oid) static int diff_tree_commit_sha1(const struct object_id *oid)
{ {
struct commit *commit = lookup_commit_reference(oid->hash); struct commit *commit = lookup_commit_reference(oid);
if (!commit) if (!commit)
return -1; return -1;
return log_tree_commit(&log_tree_opt, commit); return log_tree_commit(&log_tree_opt, commit);
@ -23,7 +23,7 @@ static int stdin_diff_commit(struct commit *commit, const char *p)
/* Graft the fake parents locally to the commit */ /* Graft the fake parents locally to the commit */
while (isspace(*p++) && !parse_oid_hex(p, &oid, &p)) { while (isspace(*p++) && !parse_oid_hex(p, &oid, &p)) {
struct commit *parent = lookup_commit(oid.hash); struct commit *parent = lookup_commit(&oid);
if (!pptr) { if (!pptr) {
/* Free the real parent list */ /* Free the real parent list */
free_commit_list(commit->parents); free_commit_list(commit->parents);
@ -44,7 +44,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)
struct tree *tree2; struct tree *tree2;
if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p) if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p)
return error("Need exactly two trees, separated by a space"); return error("Need exactly two trees, separated by a space");
tree2 = lookup_tree(oid.hash); tree2 = lookup_tree(&oid);
if (!tree2 || parse_tree(tree2)) if (!tree2 || parse_tree(tree2))
return -1; return -1;
printf("%s %s\n", oid_to_hex(&tree1->object.oid), printf("%s %s\n", oid_to_hex(&tree1->object.oid),
@ -67,7 +67,7 @@ static int diff_tree_stdin(char *line)
line[len-1] = 0; line[len-1] = 0;
if (parse_oid_hex(line, &oid, &p)) if (parse_oid_hex(line, &oid, &p))
return -1; return -1;
obj = parse_object(oid.hash); obj = parse_object(&oid);
if (!obj) if (!obj)
return -1; return -1;
if (obj->type == OBJ_COMMIT) if (obj->type == OBJ_COMMIT)

View File

@ -381,7 +381,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
add_head_to_pending(&rev); add_head_to_pending(&rev);
if (!rev.pending.nr) { if (!rev.pending.nr) {
struct tree *tree; struct tree *tree;
tree = lookup_tree(EMPTY_TREE_SHA1_BIN); tree = lookup_tree(&empty_tree_oid);
add_pending_object(&rev, &tree->object, "HEAD"); add_pending_object(&rev, &tree->object, "HEAD");
} }
break; break;
@ -395,7 +395,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
const char *name = entry->name; const char *name = entry->name;
int flags = (obj->flags & UNINTERESTING); int flags = (obj->flags & UNINTERESTING);
if (!obj->parsed) if (!obj->parsed)
obj = parse_object(obj->oid.hash); obj = parse_object(&obj->oid);
obj = deref_tag(obj, NULL, 0); obj = deref_tag(obj, NULL, 0);
if (!obj) if (!obj)
die(_("invalid object '%s' given."), name); die(_("invalid object '%s' given."), name);
@ -408,7 +408,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
} else if (obj->type == OBJ_BLOB) { } else if (obj->type == OBJ_BLOB) {
if (2 <= blobs) if (2 <= blobs)
die(_("more than two blobs given: '%s'"), name); die(_("more than two blobs given: '%s'"), name);
hashcpy(blob[blobs].oid.hash, obj->oid.hash); oidcpy(&blob[blobs].oid, &obj->oid);
blob[blobs].name = name; blob[blobs].name = name;
blob[blobs].mode = entry->mode; blob[blobs].mode = entry->mode;
blobs++; blobs++;

View File

@ -232,7 +232,7 @@ static void export_blob(const struct object_id *oid)
if (anonymize) { if (anonymize) {
buf = anonymize_blob(&size); buf = anonymize_blob(&size);
object = (struct object *)lookup_blob(oid->hash); object = (struct object *)lookup_blob(oid);
eaten = 0; eaten = 0;
} else { } else {
buf = read_sha1_file(oid->hash, &type, &size); buf = read_sha1_file(oid->hash, &type, &size);
@ -240,7 +240,7 @@ static void export_blob(const struct object_id *oid)
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, typename(type)) < 0) if (check_sha1_signature(oid->hash, buf, size, typename(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->hash, type, size, buf, &eaten); object = parse_object_buffer(oid, type, size, buf, &eaten);
} }
if (!object) if (!object)
@ -777,7 +777,7 @@ static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name)
/* handle nested tags */ /* handle nested tags */
while (tag && tag->object.type == OBJ_TAG) { while (tag && tag->object.type == OBJ_TAG) {
parse_object(tag->object.oid.hash); parse_object(&tag->object.oid);
string_list_append(&extra_refs, full_name)->util = tag; string_list_append(&extra_refs, full_name)->util = tag;
tag = (struct tag *)tag->tagged; tag = (struct tag *)tag->tagged;
} }
@ -938,7 +938,7 @@ static void import_marks(char *input_file)
/* only commits */ /* only commits */
continue; continue;
commit = lookup_commit(oid.hash); commit = lookup_commit(&oid);
if (!commit) if (!commit)
die("not a commit? can't happen: %s", oid_to_hex(&oid)); die("not a commit? can't happen: %s", oid_to_hex(&oid));

View File

@ -636,8 +636,8 @@ static int update_local_ref(struct ref *ref,
return r; return r;
} }
current = lookup_commit_reference_gently(ref->old_oid.hash, 1); current = lookup_commit_reference_gently(&ref->old_oid, 1);
updated = lookup_commit_reference_gently(ref->new_oid.hash, 1); updated = lookup_commit_reference_gently(&ref->new_oid, 1);
if (!current || !updated) { if (!current || !updated) {
const char *msg; const char *msg;
const char *what; const char *what;
@ -770,7 +770,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
continue; continue;
} }
commit = lookup_commit_reference_gently(rm->old_oid.hash, 1); commit = lookup_commit_reference_gently(&rm->old_oid,
1);
if (!commit) if (!commit)
rm->fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE; rm->fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE;

View File

@ -341,7 +341,7 @@ static void shortlog(const char *name,
const struct object_id *oid = &origin_data->oid; const struct object_id *oid = &origin_data->oid;
int limit = opts->shortlog_len; int limit = opts->shortlog_len;
branch = deref_tag(parse_object(oid->hash), oid_to_hex(oid), GIT_SHA1_HEXSZ); branch = deref_tag(parse_object(oid), oid_to_hex(oid), GIT_SHA1_HEXSZ);
if (!branch || branch->type != OBJ_COMMIT) if (!branch || branch->type != OBJ_COMMIT)
return; return;
@ -559,14 +559,14 @@ static void find_merge_parents(struct merge_parents *result,
* "name" here and we do not want to contaminate its * "name" here and we do not want to contaminate its
* util field yet. * util field yet.
*/ */
obj = parse_object(oid.hash); obj = parse_object(&oid);
parent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT); parent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT);
if (!parent) if (!parent)
continue; continue;
commit_list_insert(parent, &parents); commit_list_insert(parent, &parents);
add_merge_parent(result, &obj->oid, &parent->object.oid); add_merge_parent(result, &obj->oid, &parent->object.oid);
} }
head_commit = lookup_commit(head->hash); head_commit = lookup_commit(head);
if (head_commit) if (head_commit)
commit_list_insert(head_commit, &parents); commit_list_insert(head_commit, &parents);
parents = reduce_heads(parents); parents = reduce_heads(parents);
@ -633,7 +633,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
struct commit *head; struct commit *head;
struct rev_info rev; struct rev_info rev;
head = lookup_commit_or_die(head_oid.hash, "HEAD"); head = lookup_commit_or_die(&head_oid, "HEAD");
init_revisions(&rev, NULL); init_revisions(&rev, NULL);
rev.commit_format = CMIT_FMT_ONELINE; rev.commit_format = CMIT_FMT_ONELINE;
rev.ignore_merges = 1; rev.ignore_merges = 1;

View File

@ -377,7 +377,7 @@ static int fsck_obj(struct object *obj)
return 0; return 0;
} }
static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type, static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
unsigned long size, void *buffer, int *eaten) unsigned long size, void *buffer, int *eaten)
{ {
/* /*
@ -385,10 +385,10 @@ static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,
* verify_packfile(), data_valid variable for details. * verify_packfile(), data_valid variable for details.
*/ */
struct object *obj; struct object *obj;
obj = parse_object_buffer(sha1, type, size, buffer, eaten); obj = parse_object_buffer(oid, type, size, buffer, eaten);
if (!obj) { if (!obj) {
errors_found |= ERROR_OBJECT; errors_found |= ERROR_OBJECT;
return error("%s: object corrupt or missing", sha1_to_hex(sha1)); return error("%s: object corrupt or missing", oid_to_hex(oid));
} }
obj->flags = HAS_OBJ; obj->flags = HAS_OBJ;
return fsck_obj(obj); return fsck_obj(obj);
@ -444,7 +444,7 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
{ {
struct object *obj; struct object *obj;
obj = parse_object(oid->hash); obj = parse_object(oid);
if (!obj) { if (!obj) {
error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid)); error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid));
errors_found |= ERROR_REACHABLE; errors_found |= ERROR_REACHABLE;
@ -506,7 +506,7 @@ static struct object *parse_loose_object(const struct object_id *oid,
if (!contents && type != OBJ_BLOB) if (!contents && type != OBJ_BLOB)
die("BUG: read_loose_object streamed a non-blob"); die("BUG: read_loose_object streamed a non-blob");
obj = parse_object_buffer(oid->hash, type, size, contents, &eaten); obj = parse_object_buffer(oid, type, size, contents, &eaten);
if (!eaten) if (!eaten)
free(contents); free(contents);
@ -599,10 +599,10 @@ static int fsck_cache_tree(struct cache_tree *it)
fprintf(stderr, "Checking cache tree\n"); fprintf(stderr, "Checking cache tree\n");
if (0 <= it->entry_count) { if (0 <= it->entry_count) {
struct object *obj = parse_object(it->sha1); struct object *obj = parse_object(&it->oid);
if (!obj) { if (!obj) {
error("%s: invalid sha1 pointer in cache-tree", error("%s: invalid sha1 pointer in cache-tree",
sha1_to_hex(it->sha1)); oid_to_hex(&it->oid));
errors_found |= ERROR_REFS; errors_found |= ERROR_REFS;
return 1; return 1;
} }
@ -781,7 +781,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
mode = active_cache[i]->ce_mode; mode = active_cache[i]->ce_mode;
if (S_ISGITLINK(mode)) if (S_ISGITLINK(mode))
continue; continue;
blob = lookup_blob(active_cache[i]->oid.hash); blob = lookup_blob(&active_cache[i]->oid);
if (!blob) if (!blob)
continue; continue;
obj = &blob->object; obj = &blob->object;

View File

@ -1196,7 +1196,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
break; break;
} }
object = parse_object_or_die(oid.hash, arg); object = parse_object_or_die(&oid, arg);
if (!seen_dashdash) if (!seen_dashdash)
verify_non_filename(prefix, arg); verify_non_filename(prefix, arg);
add_object_array_with_path(object, arg, &list, oc.mode, oc.path); add_object_array_with_path(object, arg, &list, oc.mode, oc.path);

View File

@ -747,13 +747,13 @@ static int compare_objects(const unsigned char *buf, unsigned long size,
ssize_t len = read_istream(data->st, data->buf, size); ssize_t len = read_istream(data->st, data->buf, size);
if (len == 0) if (len == 0)
die(_("SHA1 COLLISION FOUND WITH %s !"), die(_("SHA1 COLLISION FOUND WITH %s !"),
sha1_to_hex(data->entry->idx.sha1)); oid_to_hex(&data->entry->idx.oid));
if (len < 0) if (len < 0)
die(_("unable to read %s"), die(_("unable to read %s"),
sha1_to_hex(data->entry->idx.sha1)); oid_to_hex(&data->entry->idx.oid));
if (memcmp(buf, data->buf, len)) if (memcmp(buf, data->buf, len))
die(_("SHA1 COLLISION FOUND WITH %s !"), die(_("SHA1 COLLISION FOUND WITH %s !"),
sha1_to_hex(data->entry->idx.sha1)); oid_to_hex(&data->entry->idx.oid));
size -= len; size -= len;
buf += len; buf += len;
} }
@ -771,12 +771,12 @@ 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.sha1, &type, &size, NULL); data.st = open_istream(entry->idx.oid.hash, &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)
die(_("SHA1 COLLISION FOUND WITH %s !"), die(_("SHA1 COLLISION FOUND WITH %s !"),
sha1_to_hex(entry->idx.sha1)); oid_to_hex(&entry->idx.oid));
unpack_data(entry, compare_objects, &data); unpack_data(entry, compare_objects, &data);
close_istream(data.st); close_istream(data.st);
free(data.buf); free(data.buf);
@ -785,7 +785,7 @@ static int check_collison(struct object_entry *entry)
static void sha1_object(const void *data, struct object_entry *obj_entry, static void sha1_object(const void *data, struct object_entry *obj_entry,
unsigned long size, enum object_type type, unsigned long size, enum object_type type,
const unsigned char *sha1) const struct object_id *oid)
{ {
void *new_data = NULL; void *new_data = NULL;
int collision_test_needed = 0; int collision_test_needed = 0;
@ -794,7 +794,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
if (startup_info->have_repository) { if (startup_info->have_repository) {
read_lock(); read_lock();
collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK); collision_test_needed = has_sha1_file_with_flags(oid->hash, HAS_SHA1_QUICK);
read_unlock(); read_unlock();
} }
@ -809,31 +809,31 @@ 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(sha1, &has_size); has_type = sha1_object_info(oid->hash, &has_size);
if (has_type < 0) if (has_type < 0)
die(_("cannot read existing object info %s"), sha1_to_hex(sha1)); 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 !"), sha1_to_hex(sha1)); die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
has_data = read_sha1_file(sha1, &has_type, &has_size); has_data = read_sha1_file(oid->hash, &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);
if (!has_data) if (!has_data)
die(_("cannot read existing object %s"), sha1_to_hex(sha1)); die(_("cannot read existing object %s"), oid_to_hex(oid));
if (size != has_size || type != has_type || if (size != has_size || type != has_type ||
memcmp(data, has_data, size) != 0) memcmp(data, has_data, size) != 0)
die(_("SHA1 COLLISION FOUND WITH %s !"), sha1_to_hex(sha1)); die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
free(has_data); free(has_data);
} }
if (strict) { if (strict) {
read_lock(); read_lock();
if (type == OBJ_BLOB) { if (type == OBJ_BLOB) {
struct blob *blob = lookup_blob(sha1); struct blob *blob = lookup_blob(oid);
if (blob) if (blob)
blob->object.flags |= FLAG_CHECKED; blob->object.flags |= FLAG_CHECKED;
else else
die(_("invalid blob object %s"), sha1_to_hex(sha1)); die(_("invalid blob object %s"), oid_to_hex(oid));
} else { } else {
struct object *obj; struct object *obj;
int eaten; int eaten;
@ -845,7 +845,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
* we do not need to free the memory here, as the * we do not need to free the memory here, as the
* buf is deleted by the caller. * buf is deleted by the caller.
*/ */
obj = parse_object_buffer(sha1, type, size, buf, &eaten); obj = parse_object_buffer(oid, type, size, buf,
&eaten);
if (!obj) if (!obj)
die(_("invalid %s"), typename(type)); die(_("invalid %s"), typename(type));
if (do_fsck_object && if (do_fsck_object &&
@ -957,9 +958,10 @@ static void resolve_delta(struct object_entry *delta_obj,
if (!result->data) if (!result->data)
bad_object(delta_obj->idx.offset, _("failed to apply delta")); bad_object(delta_obj->idx.offset, _("failed to apply delta"));
hash_sha1_file(result->data, result->size, hash_sha1_file(result->data, result->size,
typename(delta_obj->real_type), delta_obj->idx.sha1); typename(delta_obj->real_type),
delta_obj->idx.oid.hash);
sha1_object(result->data, NULL, result->size, delta_obj->real_type, sha1_object(result->data, NULL, result->size, delta_obj->real_type,
delta_obj->idx.sha1); &delta_obj->idx.oid);
counter_lock(); counter_lock();
nr_resolved_deltas++; nr_resolved_deltas++;
counter_unlock(); counter_unlock();
@ -989,7 +991,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.sha1, find_ref_delta_children(base->obj->idx.oid.hash,
&base->ref_first, &base->ref_last, &base->ref_first, &base->ref_last,
OBJ_REF_DELTA); OBJ_REF_DELTA);
@ -1130,7 +1132,8 @@ static void parse_pack_objects(unsigned char *sha1)
for (i = 0; i < nr_objects; i++) { for (i = 0; i < nr_objects; i++) {
struct object_entry *obj = &objects[i]; struct object_entry *obj = &objects[i];
void *data = unpack_raw_entry(obj, &ofs_delta->offset, void *data = unpack_raw_entry(obj, &ofs_delta->offset,
ref_delta_sha1, obj->idx.sha1); ref_delta_sha1,
obj->idx.oid.hash);
obj->real_type = obj->type; obj->real_type = obj->type;
if (obj->type == OBJ_OFS_DELTA) { if (obj->type == OBJ_OFS_DELTA) {
nr_ofs_deltas++; nr_ofs_deltas++;
@ -1146,7 +1149,8 @@ static void parse_pack_objects(unsigned char *sha1)
obj->real_type = OBJ_BAD; obj->real_type = OBJ_BAD;
nr_delays++; nr_delays++;
} else } else
sha1_object(data, NULL, obj->size, obj->type, obj->idx.sha1); sha1_object(data, NULL, obj->size, obj->type,
&obj->idx.oid);
free(data); free(data);
display_progress(progress, i+1); display_progress(progress, i+1);
} }
@ -1172,7 +1176,8 @@ static void parse_pack_objects(unsigned char *sha1)
if (obj->real_type != OBJ_BAD) if (obj->real_type != OBJ_BAD)
continue; continue;
obj->real_type = obj->type; obj->real_type = obj->type;
sha1_object(NULL, obj, obj->size, obj->type, obj->idx.sha1); sha1_object(NULL, obj, obj->size, obj->type,
&obj->idx.oid);
nr_delays--; nr_delays--;
} }
if (nr_delays) if (nr_delays)
@ -1330,7 +1335,7 @@ static struct object_entry *append_obj_to_pack(struct sha1file *f,
obj[1].idx.offset += write_compressed(f, buf, size); obj[1].idx.offset += write_compressed(f, buf, size);
obj[0].idx.crc32 = crc32_end(f); obj[0].idx.crc32 = crc32_end(f);
sha1flush(f); sha1flush(f);
hashcpy(obj->idx.sha1, sha1); hashcpy(obj->idx.oid.hash, sha1);
return obj; return obj;
} }
@ -1581,13 +1586,14 @@ static void show_pack_info(int stat_only)
if (stat_only) if (stat_only)
continue; continue;
printf("%s %-6s %lu %lu %"PRIuMAX, printf("%s %-6s %lu %lu %"PRIuMAX,
sha1_to_hex(obj->idx.sha1), oid_to_hex(&obj->idx.oid),
typename(obj->real_type), obj->size, typename(obj->real_type), obj->size,
(unsigned long)(obj[1].idx.offset - obj->idx.offset), (unsigned long)(obj[1].idx.offset - obj->idx.offset),
(uintmax_t)obj->idx.offset); (uintmax_t)obj->idx.offset);
if (is_delta_type(obj->type)) { if (is_delta_type(obj->type)) {
struct object_entry *bobj = &objects[obj_stat[i].base_object_no]; struct object_entry *bobj = &objects[obj_stat[i].base_object_no];
printf(" %u %s", obj_stat[i].delta_depth, sha1_to_hex(bobj->idx.sha1)); printf(" %u %s", obj_stat[i].delta_depth,
oid_to_hex(&bobj->idx.oid));
} }
putchar('\n'); putchar('\n');
} }

View File

@ -596,7 +596,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
rev.shown_one = 1; rev.shown_one = 1;
if (ret) if (ret)
break; break;
o = parse_object(t->tagged->oid.hash); o = parse_object(&t->tagged->oid);
if (!o) if (!o)
ret = error(_("Could not read object %s"), ret = error(_("Could not read object %s"),
oid_to_hex(&t->tagged->oid)); oid_to_hex(&t->tagged->oid));
@ -878,8 +878,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
o2 = rev->pending.objects[1].item; o2 = rev->pending.objects[1].item;
flags1 = o1->flags; flags1 = o1->flags;
flags2 = o2->flags; flags2 = o2->flags;
c1 = lookup_commit_reference(o1->oid.hash); c1 = lookup_commit_reference(&o1->oid);
c2 = lookup_commit_reference(o2->oid.hash); c2 = lookup_commit_reference(&o2->oid);
if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING)) if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING))
die(_("Not a range.")); die(_("Not a range."));
@ -1263,7 +1263,7 @@ static struct commit *get_base_commit(const char *base_commit,
if (get_oid(upstream, &oid)) if (get_oid(upstream, &oid))
die(_("Failed to resolve '%s' as a valid ref."), upstream); die(_("Failed to resolve '%s' as a valid ref."), upstream);
commit = lookup_commit_or_die(oid.hash, "upstream base"); commit = lookup_commit_or_die(&oid, "upstream base");
base_list = get_merge_bases_many(commit, total, list); base_list = get_merge_bases_many(commit, total, list);
/* There should be one and only one merge base. */ /* There should be one and only one merge base. */
if (!base_list || base_list->next) if (!base_list || base_list->next)
@ -1819,7 +1819,7 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
{ {
struct object_id oid; struct object_id oid;
if (get_oid(arg, &oid) == 0) { if (get_oid(arg, &oid) == 0) {
struct commit *commit = lookup_commit_reference(oid.hash); struct commit *commit = lookup_commit_reference(&oid);
if (commit) { if (commit) {
commit->object.flags |= flags; commit->object.flags |= flags;
add_pending_object(revs, &commit->object, arg); add_pending_object(revs, &commit->object, arg);

View File

@ -414,14 +414,14 @@ static void prune_cache(const char *prefix, size_t prefixlen)
void overlay_tree_on_cache(const char *tree_name, const char *prefix) void overlay_tree_on_cache(const char *tree_name, const char *prefix)
{ {
struct tree *tree; struct tree *tree;
unsigned char sha1[20]; struct object_id oid;
struct pathspec pathspec; struct pathspec pathspec;
struct cache_entry *last_stage0 = NULL; struct cache_entry *last_stage0 = NULL;
int i; int i;
if (get_sha1(tree_name, sha1)) if (get_oid(tree_name, &oid))
die("tree-ish %s not found.", tree_name); die("tree-ish %s not found.", tree_name);
tree = parse_tree_indirect(sha1); tree = parse_tree_indirect(&oid);
if (!tree) if (!tree)
die("bad tree-ish %s", tree_name); die("bad tree-ish %s", tree_name);

View File

@ -119,7 +119,7 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
int cmd_ls_tree(int argc, const char **argv, const char *prefix) int cmd_ls_tree(int argc, const char **argv, const char *prefix)
{ {
unsigned char sha1[20]; struct object_id oid;
struct tree *tree; struct tree *tree;
int i, full_tree = 0; int i, full_tree = 0;
const struct option ls_tree_options[] = { const struct option ls_tree_options[] = {
@ -164,7 +164,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
if (argc < 1) if (argc < 1)
usage_with_options(ls_tree_usage, ls_tree_options); usage_with_options(ls_tree_usage, ls_tree_options);
if (get_sha1(argv[0], sha1)) if (get_oid(argv[0], &oid))
die("Not a valid object name %s", argv[0]); die("Not a valid object name %s", argv[0]);
/* /*
@ -180,7 +180,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
for (i = 0; i < pathspec.nr; i++) for (i = 0; i < pathspec.nr; i++)
pathspec.items[i].nowildcard_len = pathspec.items[i].len; pathspec.items[i].nowildcard_len = pathspec.items[i].len;
pathspec.has_wildcard = 0; pathspec.has_wildcard = 0;
tree = parse_tree_indirect(sha1); tree = parse_tree_indirect(&oid);
if (!tree) if (!tree)
die("not a tree object"); die("not a tree object");
return !!read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL); return !!read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);

View File

@ -41,7 +41,7 @@ static struct commit *get_commit_reference(const char *arg)
if (get_oid(arg, &revkey)) if (get_oid(arg, &revkey))
die("Not a valid object name %s", arg); die("Not a valid object name %s", arg);
r = lookup_commit_reference(revkey.hash); r = lookup_commit_reference(&revkey);
if (!r) if (!r)
die("Not a valid commit name %s", arg); die("Not a valid commit name %s", arg);
@ -120,7 +120,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs)
if (is_null_oid(oid)) if (is_null_oid(oid))
return; return;
commit = lookup_commit(oid->hash); commit = lookup_commit(oid);
if (!commit || if (!commit ||
(commit->object.flags & TMP_MARK) || (commit->object.flags & TMP_MARK) ||
parse_commit(commit)) parse_commit(commit))
@ -168,7 +168,7 @@ static int handle_fork_point(int argc, const char **argv)
if (get_oid(commitname, &oid)) if (get_oid(commitname, &oid))
die("Not a valid object name: '%s'", commitname); die("Not a valid object name: '%s'", commitname);
derived = lookup_commit_reference(oid.hash); derived = lookup_commit_reference(&oid);
memset(&revs, 0, sizeof(revs)); memset(&revs, 0, sizeof(revs));
revs.initial = 1; revs.initial = 1;
for_each_reflog_ent(refname, collect_one_reflog_ent, &revs); for_each_reflog_ent(refname, collect_one_reflog_ent, &revs);

View File

@ -161,14 +161,14 @@ static int both_empty(struct name_entry *a, struct name_entry *b)
return !(a->oid || b->oid); return !(a->oid || b->oid);
} }
static struct merge_list *create_entry(unsigned stage, unsigned mode, const unsigned char *sha1, const char *path) static struct merge_list *create_entry(unsigned stage, unsigned mode, const struct object_id *oid, const char *path)
{ {
struct merge_list *res = xcalloc(1, sizeof(*res)); struct merge_list *res = xcalloc(1, sizeof(*res));
res->stage = stage; res->stage = stage;
res->path = path; res->path = path;
res->mode = mode; res->mode = mode;
res->blob = lookup_blob(sha1); res->blob = lookup_blob(oid);
return res; return res;
} }
@ -188,8 +188,8 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s
return; return;
path = traverse_path(info, result); path = traverse_path(info, result);
orig = create_entry(2, ours->mode, ours->oid->hash, path); orig = create_entry(2, ours->mode, ours->oid, path);
final = create_entry(0, result->mode, result->oid->hash, path); final = create_entry(0, result->mode, result->oid, path);
final->link = orig; final->link = orig;
@ -239,7 +239,7 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info
path = entry->path; path = entry->path;
else else
path = traverse_path(info, n); path = traverse_path(info, n);
link = create_entry(stage, n->mode, n->oid->hash, path); link = create_entry(stage, n->mode, n->oid, path);
link->link = entry; link->link = entry;
return link; return link;
} }

View File

@ -605,13 +605,13 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
opts.verbose_update = 1; opts.verbose_update = 1;
opts.trivial_merges_only = 1; opts.trivial_merges_only = 1;
opts.merge = 1; opts.merge = 1;
trees[nr_trees] = parse_tree_indirect(common->hash); trees[nr_trees] = parse_tree_indirect(common);
if (!trees[nr_trees++]) if (!trees[nr_trees++])
return -1; return -1;
trees[nr_trees] = parse_tree_indirect(head->hash); trees[nr_trees] = parse_tree_indirect(head);
if (!trees[nr_trees++]) if (!trees[nr_trees++])
return -1; return -1;
trees[nr_trees] = parse_tree_indirect(one->hash); trees[nr_trees] = parse_tree_indirect(one);
if (!trees[nr_trees++]) if (!trees[nr_trees++])
return -1; return -1;
opts.fn = threeway_merge; opts.fn = threeway_merge;
@ -1123,7 +1123,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (!branch || is_null_oid(&head_oid)) if (!branch || is_null_oid(&head_oid))
head_commit = NULL; head_commit = NULL;
else else
head_commit = lookup_commit_or_die(head_oid.hash, "HEAD"); head_commit = lookup_commit_or_die(&head_oid, "HEAD");
init_diff_ui_defaults(); init_diff_ui_defaults();
git_config(git_merge_config, NULL); git_config(git_merge_config, NULL);
@ -1372,8 +1372,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
goto done; goto done;
} }
if (checkout_fast_forward(head_commit->object.oid.hash, if (checkout_fast_forward(&head_commit->object.oid,
commit->object.oid.hash, &commit->object.oid,
overwrite_ignore)) { overwrite_ignore)) {
ret = 1; ret = 1;
goto done; goto done;

View File

@ -114,7 +114,7 @@ struct name_ref_data {
static struct tip_table { static struct tip_table {
struct tip_table_entry { struct tip_table_entry {
unsigned char sha1[20]; struct object_id oid;
const char *refname; const char *refname;
} *table; } *table;
int nr; int nr;
@ -122,13 +122,13 @@ static struct tip_table {
int sorted; int sorted;
} tip_table; } tip_table;
static void add_to_tip_table(const unsigned char *sha1, const char *refname, static void add_to_tip_table(const struct object_id *oid, const char *refname,
int shorten_unambiguous) int shorten_unambiguous)
{ {
refname = name_ref_abbrev(refname, shorten_unambiguous); refname = name_ref_abbrev(refname, shorten_unambiguous);
ALLOC_GROW(tip_table.table, tip_table.nr + 1, tip_table.alloc); ALLOC_GROW(tip_table.table, tip_table.nr + 1, tip_table.alloc);
hashcpy(tip_table.table[tip_table.nr].sha1, sha1); oidcpy(&tip_table.table[tip_table.nr].oid, oid);
tip_table.table[tip_table.nr].refname = xstrdup(refname); tip_table.table[tip_table.nr].refname = xstrdup(refname);
tip_table.nr++; tip_table.nr++;
tip_table.sorted = 0; tip_table.sorted = 0;
@ -137,12 +137,12 @@ static void add_to_tip_table(const unsigned char *sha1, const char *refname,
static int tipcmp(const void *a_, const void *b_) static int tipcmp(const void *a_, const void *b_)
{ {
const struct tip_table_entry *a = a_, *b = b_; const struct tip_table_entry *a = a_, *b = b_;
return hashcmp(a->sha1, b->sha1); return oidcmp(&a->oid, &b->oid);
} }
static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data) static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data)
{ {
struct object *o = parse_object(oid->hash); struct object *o = parse_object(oid);
struct name_ref_data *data = cb_data; struct name_ref_data *data = cb_data;
int can_abbreviate_output = data->tags_only && data->name_only; int can_abbreviate_output = data->tags_only && data->name_only;
int deref = 0; int deref = 0;
@ -194,13 +194,13 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
return 0; return 0;
} }
add_to_tip_table(oid->hash, path, can_abbreviate_output); add_to_tip_table(oid, path, can_abbreviate_output);
while (o && o->type == OBJ_TAG) { while (o && o->type == OBJ_TAG) {
struct tag *t = (struct tag *) o; struct tag *t = (struct tag *) o;
if (!t->tagged) if (!t->tagged)
break; /* broken repository */ break; /* broken repository */
o = parse_object(t->tagged->oid.hash); o = parse_object(&t->tagged->oid);
deref = 1; deref = 1;
taggerdate = t->date; taggerdate = t->date;
} }
@ -216,7 +216,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
static const unsigned char *nth_tip_table_ent(size_t ix, void *table_) static const unsigned char *nth_tip_table_ent(size_t ix, void *table_)
{ {
struct tip_table_entry *table = table_; struct tip_table_entry *table = table_;
return table[ix].sha1; return table[ix].oid.hash;
} }
static const char *get_exact_ref_match(const struct object *o) static const char *get_exact_ref_match(const struct object *o)
@ -301,9 +301,9 @@ static void name_rev_line(char *p, struct name_ref_data *data)
#define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f')) #define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f'))
if (!ishex(*p)) if (!ishex(*p))
forty = 0; forty = 0;
else if (++forty == 40 && else if (++forty == GIT_SHA1_HEXSZ &&
!ishex(*(p+1))) { !ishex(*(p+1))) {
unsigned char sha1[40]; struct object_id oid;
const char *name = NULL; const char *name = NULL;
char c = *(p+1); char c = *(p+1);
int p_len = p - p_start + 1; int p_len = p - p_start + 1;
@ -311,9 +311,9 @@ static void name_rev_line(char *p, struct name_ref_data *data)
forty = 0; forty = 0;
*(p+1) = 0; *(p+1) = 0;
if (!get_sha1(p - 39, sha1)) { if (!get_oid(p - (GIT_SHA1_HEXSZ - 1), &oid)) {
struct object *o = struct object *o =
lookup_object(sha1); lookup_object(oid.hash);
if (o) if (o)
name = get_rev_name(o, &buf); name = get_rev_name(o, &buf);
} }
@ -323,7 +323,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
continue; continue;
if (data->name_only) if (data->name_only)
printf("%.*s%s", p_len - 40, p_start, name); printf("%.*s%s", p_len - GIT_SHA1_HEXSZ, p_start, name);
else else
printf("%.*s (%s)", p_len, p_start, name); printf("%.*s (%s)", p_len, p_start, name);
p_start = p + 1; p_start = p + 1;
@ -374,18 +374,18 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
cutoff = 0; cutoff = 0;
for (; argc; argc--, argv++) { for (; argc; argc--, argv++) {
unsigned char sha1[20]; struct object_id oid;
struct object *object; struct object *object;
struct commit *commit; struct commit *commit;
if (get_sha1(*argv, sha1)) { if (get_oid(*argv, &oid)) {
fprintf(stderr, "Could not get sha1 for %s. Skipping.\n", fprintf(stderr, "Could not get sha1 for %s. Skipping.\n",
*argv); *argv);
continue; continue;
} }
commit = NULL; commit = NULL;
object = parse_object(sha1); object = parse_object(&oid);
if (object) { if (object) {
struct object *peeled = deref_tag(object, *argv, 0); struct object *peeled = deref_tag(object, *argv, 0);
if (peeled && peeled->type == OBJ_COMMIT) if (peeled && peeled->type == OBJ_COMMIT)

View File

@ -706,7 +706,7 @@ static int merge_commit(struct notes_merge_options *o)
if (get_oid("NOTES_MERGE_PARTIAL", &oid)) if (get_oid("NOTES_MERGE_PARTIAL", &oid))
die(_("failed to read ref NOTES_MERGE_PARTIAL")); die(_("failed to read ref NOTES_MERGE_PARTIAL"));
else if (!(partial = lookup_commit_reference(oid.hash))) else if (!(partial = lookup_commit_reference(&oid)))
die(_("could not find commit from NOTES_MERGE_PARTIAL.")); die(_("could not find commit from NOTES_MERGE_PARTIAL."));
else if (parse_commit(partial)) else if (parse_commit(partial))
die(_("could not parse commit from NOTES_MERGE_PARTIAL.")); die(_("could not parse commit from NOTES_MERGE_PARTIAL."));

View File

@ -106,12 +106,14 @@ 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.sha1, &type, &size); buf = read_sha1_file(entry->idx.oid.hash, &type, &size);
if (!buf) if (!buf)
die("unable to read %s", sha1_to_hex(entry->idx.sha1)); die("unable to read %s", oid_to_hex(&entry->idx.oid));
base_buf = read_sha1_file(entry->delta->idx.sha1, &type, &base_size); base_buf = read_sha1_file(entry->delta->idx.oid.hash, &type,
&base_size);
if (!base_buf) if (!base_buf)
die("unable to read %s", sha1_to_hex(entry->delta->idx.sha1)); die("unable to read %s",
oid_to_hex(&entry->delta->idx.oid));
delta_buf = diff_delta(base_buf, base_size, delta_buf = diff_delta(base_buf, base_size,
buf, size, &delta_size, 0); buf, size, &delta_size, 0);
if (!delta_buf || delta_size != entry->delta_size) if (!delta_buf || delta_size != entry->delta_size)
@ -249,12 +251,14 @@ static unsigned long write_no_reuse_object(struct sha1file *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.sha1, &type, &size, NULL)) != NULL) (st = open_istream(entry->idx.oid.hash, &type, &size, NULL)) != NULL)
buf = NULL; buf = NULL;
else { else {
buf = read_sha1_file(entry->idx.sha1, &type, &size); buf = read_sha1_file(entry->idx.oid.hash, &type,
&size);
if (!buf) if (!buf)
die(_("unable to read %s"), sha1_to_hex(entry->idx.sha1)); die(_("unable to read %s"),
oid_to_hex(&entry->idx.oid));
} }
/* /*
* make sure no cached delta data remains from a * make sure no cached delta data remains from a
@ -322,7 +326,7 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
return 0; return 0;
} }
sha1write(f, header, hdrlen); sha1write(f, header, hdrlen);
sha1write(f, entry->delta->idx.sha1, 20); sha1write(f, entry->delta->idx.oid.hash, 20);
hdrlen += 20; hdrlen += 20;
} else { } else {
if (limit && hdrlen + datalen + 20 >= limit) { if (limit && hdrlen + datalen + 20 >= limit) {
@ -334,7 +338,7 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
sha1write(f, header, hdrlen); sha1write(f, header, hdrlen);
} }
if (st) { if (st) {
datalen = write_large_blob_data(st, f, entry->idx.sha1); datalen = write_large_blob_data(st, f, entry->idx.oid.hash);
close_istream(st); close_istream(st);
} else { } else {
sha1write(f, buf, datalen); sha1write(f, buf, datalen);
@ -369,7 +373,8 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,
datalen = revidx[1].offset - offset; datalen = revidx[1].offset - offset;
if (!pack_to_stdout && p->index_version > 1 && if (!pack_to_stdout && p->index_version > 1 &&
check_pack_crc(p, &w_curs, offset, datalen, revidx->nr)) { check_pack_crc(p, &w_curs, offset, datalen, revidx->nr)) {
error("bad packed object CRC for %s", sha1_to_hex(entry->idx.sha1)); error("bad packed object CRC for %s",
oid_to_hex(&entry->idx.oid));
unuse_pack(&w_curs); unuse_pack(&w_curs);
return write_no_reuse_object(f, entry, limit, usable_delta); return write_no_reuse_object(f, entry, limit, usable_delta);
} }
@ -379,7 +384,8 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,
if (!pack_to_stdout && p->index_version == 1 && if (!pack_to_stdout && p->index_version == 1 &&
check_pack_inflate(p, &w_curs, offset, datalen, entry->size)) { check_pack_inflate(p, &w_curs, offset, datalen, entry->size)) {
error("corrupt packed object for %s", sha1_to_hex(entry->idx.sha1)); error("corrupt packed object for %s",
oid_to_hex(&entry->idx.oid));
unuse_pack(&w_curs); unuse_pack(&w_curs);
return write_no_reuse_object(f, entry, limit, usable_delta); return write_no_reuse_object(f, entry, limit, usable_delta);
} }
@ -404,7 +410,7 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,
return 0; return 0;
} }
sha1write(f, header, hdrlen); sha1write(f, header, hdrlen);
sha1write(f, entry->delta->idx.sha1, 20); sha1write(f, entry->delta->idx.oid.hash, 20);
hdrlen += 20; hdrlen += 20;
reused_delta++; reused_delta++;
} else { } else {
@ -509,7 +515,7 @@ static enum write_one_status write_one(struct sha1file *f,
recursing = (e->idx.offset == 1); recursing = (e->idx.offset == 1);
if (recursing) { if (recursing) {
warning("recursive delta detected for object %s", warning("recursive delta detected for object %s",
sha1_to_hex(e->idx.sha1)); oid_to_hex(&e->idx.oid));
return WRITE_ONE_RECURSIVE; return WRITE_ONE_RECURSIVE;
} else if (e->idx.offset || e->preferred_base) { } else if (e->idx.offset || e->preferred_base) {
/* offset is non zero if object is written already. */ /* offset is non zero if object is written already. */
@ -1432,7 +1438,7 @@ static void check_object(struct object_entry *entry)
ofs += 1; ofs += 1;
if (!ofs || MSB(ofs, 7)) { if (!ofs || MSB(ofs, 7)) {
error("delta base offset overflow in pack for %s", error("delta base offset overflow in pack for %s",
sha1_to_hex(entry->idx.sha1)); oid_to_hex(&entry->idx.oid));
goto give_up; goto give_up;
} }
c = buf[used_0++]; c = buf[used_0++];
@ -1441,7 +1447,7 @@ static void check_object(struct object_entry *entry)
ofs = entry->in_pack_offset - ofs; ofs = entry->in_pack_offset - ofs;
if (ofs <= 0 || ofs >= entry->in_pack_offset) { if (ofs <= 0 || ofs >= entry->in_pack_offset) {
error("delta base offset out of bound for %s", error("delta base offset out of bound for %s",
sha1_to_hex(entry->idx.sha1)); oid_to_hex(&entry->idx.oid));
goto give_up; goto give_up;
} }
if (reuse_delta && !entry->preferred_base) { if (reuse_delta && !entry->preferred_base) {
@ -1498,7 +1504,7 @@ static void check_object(struct object_entry *entry)
unuse_pack(&w_curs); unuse_pack(&w_curs);
} }
entry->type = sha1_object_info(entry->idx.sha1, &entry->size); entry->type = sha1_object_info(entry->idx.oid.hash, &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
@ -1514,7 +1520,7 @@ static int pack_offset_sort(const void *_a, const void *_b)
/* avoid filesystem trashing with loose objects */ /* avoid filesystem trashing with loose objects */
if (!a->in_pack && !b->in_pack) if (!a->in_pack && !b->in_pack)
return hashcmp(a->idx.sha1, b->idx.sha1); return oidcmp(&a->idx.oid, &b->idx.oid);
if (a->in_pack < b->in_pack) if (a->in_pack < b->in_pack)
return -1; return -1;
@ -1560,7 +1566,8 @@ 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.sha1, &entry->size); entry->type = sha1_object_info(entry->idx.oid.hash,
&entry->size);
} }
} }
@ -1852,26 +1859,29 @@ 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.sha1, &type, &sz); trg->data = read_sha1_file(trg_entry->idx.oid.hash, &type,
&sz);
read_unlock(); read_unlock();
if (!trg->data) if (!trg->data)
die("object %s cannot be read", die("object %s cannot be read",
sha1_to_hex(trg_entry->idx.sha1)); oid_to_hex(&trg_entry->idx.oid));
if (sz != trg_size) if (sz != trg_size)
die("object %s inconsistent object length (%lu vs %lu)", die("object %s inconsistent object length (%lu vs %lu)",
sha1_to_hex(trg_entry->idx.sha1), sz, trg_size); oid_to_hex(&trg_entry->idx.oid), sz,
trg_size);
*mem_usage += sz; *mem_usage += sz;
} }
if (!src->data) { if (!src->data) {
read_lock(); read_lock();
src->data = read_sha1_file(src_entry->idx.sha1, &type, &sz); src->data = read_sha1_file(src_entry->idx.oid.hash, &type,
&sz);
read_unlock(); read_unlock();
if (!src->data) { if (!src->data) {
if (src_entry->preferred_base) { if (src_entry->preferred_base) {
static int warned = 0; static int warned = 0;
if (!warned++) if (!warned++)
warning("object %s cannot be read", warning("object %s cannot be read",
sha1_to_hex(src_entry->idx.sha1)); oid_to_hex(&src_entry->idx.oid));
/* /*
* Those objects are not included in the * Those objects are not included in the
* resulting pack. Be resilient and ignore * resulting pack. Be resilient and ignore
@ -1881,11 +1891,12 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
return 0; return 0;
} }
die("object %s cannot be read", die("object %s cannot be read",
sha1_to_hex(src_entry->idx.sha1)); oid_to_hex(&src_entry->idx.oid));
} }
if (sz != src_size) if (sz != src_size)
die("object %s inconsistent object length (%lu vs %lu)", die("object %s inconsistent object length (%lu vs %lu)",
sha1_to_hex(src_entry->idx.sha1), sz, src_size); oid_to_hex(&src_entry->idx.oid), sz,
src_size);
*mem_usage += sz; *mem_usage += sz;
} }
if (!src->index) { if (!src->index) {
@ -2337,7 +2348,7 @@ static void add_tag_chain(const struct object_id *oid)
if (packlist_find(&to_pack, oid->hash, NULL)) if (packlist_find(&to_pack, oid->hash, NULL))
return; return;
tag = lookup_tag(oid->hash); tag = lookup_tag(oid);
while (1) { while (1) {
if (!tag || parse_tag(tag) || !tag->tagged) if (!tag || parse_tag(tag) || !tag->tagged)
die("unable to pack objects reachable from tag %s", die("unable to pack objects reachable from tag %s",
@ -2406,7 +2417,7 @@ static void prepare_pack(int window, int depth)
nr_deltas++; nr_deltas++;
if (entry->type < 0) if (entry->type < 0)
die("unable to get type of object %s", die("unable to get type of object %s",
sha1_to_hex(entry->idx.sha1)); oid_to_hex(&entry->idx.oid));
} else { } else {
if (entry->type < 0) { if (entry->type < 0) {
/* /*
@ -2777,10 +2788,10 @@ static void get_object_list(int ac, const char **av)
continue; continue;
} }
if (starts_with(line, "--shallow ")) { if (starts_with(line, "--shallow ")) {
unsigned char sha1[20]; struct object_id oid;
if (get_sha1_hex(line + 10, sha1)) if (get_oid_hex(line + 10, &oid))
die("not an SHA-1 '%s'", line + 10); die("not an SHA-1 '%s'", line + 10);
register_shallow(sha1); register_shallow(&oid);
use_bitmap_index = 0; use_bitmap_index = 0;
continue; continue;
} }

View File

@ -123,11 +123,12 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
die(_("cannot prune in a precious-objects repo")); die(_("cannot prune in a precious-objects repo"));
while (argc--) { while (argc--) {
unsigned char sha1[20]; struct object_id oid;
const char *name = *argv++; const char *name = *argv++;
if (!get_sha1(name, sha1)) { if (!get_oid(name, &oid)) {
struct object *object = parse_object_or_die(sha1, name); struct object *object = parse_object_or_die(&oid,
name);
add_pending_object(&revs, object, ""); add_pending_object(&revs, object, "");
} }
else else

View File

@ -523,7 +523,7 @@ static int pull_into_void(const struct object_id *merge_head,
* index/worktree changes that the user already made on the unborn * index/worktree changes that the user already made on the unborn
* branch. * branch.
*/ */
if (checkout_fast_forward(EMPTY_TREE_SHA1_BIN, merge_head->hash, 0)) if (checkout_fast_forward(&empty_tree_oid, merge_head, 0))
return 1; return 1;
if (update_ref("initial pull", "HEAD", merge_head->hash, curr_head->hash, 0, UPDATE_REFS_DIE_ON_ERR)) if (update_ref("initial pull", "HEAD", merge_head->hash, curr_head->hash, 0, UPDATE_REFS_DIE_ON_ERR))
@ -698,10 +698,10 @@ static int get_octopus_merge_base(struct object_id *merge_base,
{ {
struct commit_list *revs = NULL, *result; struct commit_list *revs = NULL, *result;
commit_list_insert(lookup_commit_reference(curr_head->hash), &revs); commit_list_insert(lookup_commit_reference(curr_head), &revs);
commit_list_insert(lookup_commit_reference(merge_head->hash), &revs); commit_list_insert(lookup_commit_reference(merge_head), &revs);
if (!is_null_oid(fork_point)) if (!is_null_oid(fork_point))
commit_list_insert(lookup_commit_reference(fork_point->hash), &revs); commit_list_insert(lookup_commit_reference(fork_point), &revs);
result = reduce_heads(get_octopus_merge_bases(revs)); result = reduce_heads(get_octopus_merge_bases(revs));
free_commit_list(revs); free_commit_list(revs);
@ -839,7 +839,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
"fast-forwarding your working tree from\n" "fast-forwarding your working tree from\n"
"commit %s."), oid_to_hex(&orig_head)); "commit %s."), oid_to_hex(&orig_head));
if (checkout_fast_forward(orig_head.hash, curr_head.hash, 0)) if (checkout_fast_forward(&orig_head, &curr_head, 0))
die(_("Cannot fast-forward your working tree.\n" die(_("Cannot fast-forward your working tree.\n"
"After making sure that you saved anything precious from\n" "After making sure that you saved anything precious from\n"
"$ git diff %s\n" "$ git diff %s\n"
@ -865,9 +865,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
struct commit_list *list = NULL; struct commit_list *list = NULL;
struct commit *merge_head, *head; struct commit *merge_head, *head;
head = lookup_commit_reference(orig_head.hash); head = lookup_commit_reference(&orig_head);
commit_list_insert(head, &list); commit_list_insert(head, &list);
merge_head = lookup_commit_reference(merge_heads.oid[0].hash); merge_head = lookup_commit_reference(&merge_heads.oid[0]);
if (is_descendant_of(merge_head, list)) { if (is_descendant_of(merge_head, list)) {
/* we can fast-forward this without invoking rebase */ /* we can fast-forward this without invoking rebase */
opt_ff = "--ff-only"; opt_ff = "--ff-only";

View File

@ -23,13 +23,13 @@ static int read_empty;
static struct tree *trees[MAX_UNPACK_TREES]; static struct tree *trees[MAX_UNPACK_TREES];
static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT; static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
static int list_tree(unsigned char *sha1) static int list_tree(struct object_id *oid)
{ {
struct tree *tree; struct tree *tree;
if (nr_trees >= MAX_UNPACK_TREES) if (nr_trees >= MAX_UNPACK_TREES)
die("I cannot read more than %d trees", MAX_UNPACK_TREES); die("I cannot read more than %d trees", MAX_UNPACK_TREES);
tree = parse_tree_indirect(sha1); tree = parse_tree_indirect(oid);
if (!tree) if (!tree)
return -1; return -1;
trees[nr_trees++] = tree; trees[nr_trees++] = tree;
@ -121,7 +121,7 @@ static struct lock_file lock_file;
int cmd_read_tree(int argc, const char **argv, const char *unused_prefix) int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
{ {
int i, stage = 0; int i, stage = 0;
unsigned char sha1[20]; struct object_id oid;
struct tree_desc t[MAX_UNPACK_TREES]; struct tree_desc t[MAX_UNPACK_TREES];
struct unpack_trees_options opts; struct unpack_trees_options opts;
int prefix_set = 0; int prefix_set = 0;
@ -204,9 +204,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
const char *arg = argv[i]; const char *arg = argv[i];
if (get_sha1(arg, sha1)) if (get_oid(arg, &oid))
die("Not a valid object name %s", arg); die("Not a valid object name %s", arg);
if (list_tree(sha1) < 0) if (list_tree(&oid) < 0)
die("failed to unpack tree object %s", arg); die("failed to unpack tree object %s", arg);
stage++; stage++;
} }

View File

@ -900,7 +900,7 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
* not lose these new roots.. * not lose these new roots..
*/ */
for (i = 0; i < extra.nr; i++) for (i = 0; i < extra.nr; i++)
register_shallow(extra.oid[i].hash); register_shallow(&extra.oid[i]);
si->shallow_ref[cmd->index] = 0; si->shallow_ref[cmd->index] = 0;
oid_array_clear(&extra); oid_array_clear(&extra);
@ -1100,8 +1100,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
struct object *old_object, *new_object; struct object *old_object, *new_object;
struct commit *old_commit, *new_commit; struct commit *old_commit, *new_commit;
old_object = parse_object(old_oid->hash); old_object = parse_object(old_oid);
new_object = parse_object(new_oid->hash); new_object = parse_object(new_oid);
if (!old_object || !new_object || if (!old_object || !new_object ||
old_object->type != OBJ_COMMIT || old_object->type != OBJ_COMMIT ||
@ -1124,7 +1124,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
if (is_null_oid(new_oid)) { if (is_null_oid(new_oid)) {
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
if (!parse_object(old_oid->hash)) { if (!parse_object(old_oid)) {
old_oid = NULL; old_oid = NULL;
if (ref_exists(name)) { if (ref_exists(name)) {
rp_warning("Allowing deletion of corrupt ref."); rp_warning("Allowing deletion of corrupt ref.");

View File

@ -55,14 +55,14 @@ struct collect_reflog_cb {
#define STUDYING (1u<<11) #define STUDYING (1u<<11)
#define REACHABLE (1u<<12) #define REACHABLE (1u<<12)
static int tree_is_complete(const unsigned char *sha1) static int tree_is_complete(const struct object_id *oid)
{ {
struct tree_desc desc; struct tree_desc desc;
struct name_entry entry; struct name_entry entry;
int complete; int complete;
struct tree *tree; struct tree *tree;
tree = lookup_tree(sha1); tree = lookup_tree(oid);
if (!tree) if (!tree)
return 0; return 0;
if (tree->object.flags & SEEN) if (tree->object.flags & SEEN)
@ -73,7 +73,7 @@ static int tree_is_complete(const unsigned char *sha1)
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(sha1, &type, &size); void *data = read_sha1_file(oid->hash, &type, &size);
if (!data) { if (!data) {
tree->object.flags |= INCOMPLETE; tree->object.flags |= INCOMPLETE;
return 0; return 0;
@ -85,7 +85,7 @@ static int tree_is_complete(const unsigned char *sha1)
complete = 1; complete = 1;
while (tree_entry(&desc, &entry)) { while (tree_entry(&desc, &entry)) {
if (!has_sha1_file(entry.oid->hash) || if (!has_sha1_file(entry.oid->hash) ||
(S_ISDIR(entry.mode) && !tree_is_complete(entry.oid->hash))) { (S_ISDIR(entry.mode) && !tree_is_complete(entry.oid))) {
tree->object.flags |= INCOMPLETE; tree->object.flags |= INCOMPLETE;
complete = 0; complete = 0;
} }
@ -126,7 +126,7 @@ static int commit_is_complete(struct commit *commit)
struct commit_list *parent; struct commit_list *parent;
c = (struct commit *)study.objects[--study.nr].item; c = (struct commit *)study.objects[--study.nr].item;
if (!c->object.parsed && !parse_object(c->object.oid.hash)) if (!c->object.parsed && !parse_object(&c->object.oid))
c->object.flags |= INCOMPLETE; c->object.flags |= INCOMPLETE;
if (c->object.flags & INCOMPLETE) { if (c->object.flags & INCOMPLETE) {
@ -152,7 +152,7 @@ static int commit_is_complete(struct commit *commit)
for (i = 0; i < found.nr; i++) { for (i = 0; i < found.nr; i++) {
struct commit *c = struct commit *c =
(struct commit *)found.objects[i].item; (struct commit *)found.objects[i].item;
if (!tree_is_complete(c->tree->object.oid.hash)) { if (!tree_is_complete(&c->tree->object.oid)) {
is_incomplete = 1; is_incomplete = 1;
c->object.flags |= INCOMPLETE; c->object.flags |= INCOMPLETE;
} }
@ -186,13 +186,13 @@ static int commit_is_complete(struct commit *commit)
return !is_incomplete; return !is_incomplete;
} }
static int keep_entry(struct commit **it, unsigned char *sha1) static int keep_entry(struct commit **it, struct object_id *oid)
{ {
struct commit *commit; struct commit *commit;
if (is_null_sha1(sha1)) if (is_null_oid(oid))
return 1; return 1;
commit = lookup_commit_reference_gently(sha1, 1); commit = lookup_commit_reference_gently(oid, 1);
if (!commit) if (!commit)
return 0; return 0;
@ -251,17 +251,17 @@ static void mark_reachable(struct expire_reflog_policy_cb *cb)
cb->mark_list = leftover; cb->mark_list = leftover;
} }
static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit, unsigned char *sha1) static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit, struct object_id *oid)
{ {
/* /*
* We may or may not have the commit yet - if not, look it * We may or may not have the commit yet - if not, look it
* up using the supplied sha1. * up using the supplied sha1.
*/ */
if (!commit) { if (!commit) {
if (is_null_sha1(sha1)) if (is_null_oid(oid))
return 0; return 0;
commit = lookup_commit_reference_gently(sha1, 1); commit = lookup_commit_reference_gently(oid, 1);
/* Not a commit -- keep it */ /* Not a commit -- keep it */
if (!commit) if (!commit)
@ -283,7 +283,7 @@ static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit
/* /*
* Return true iff the specified reflog entry should be expired. * Return true iff the specified reflog entry should be expired.
*/ */
static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1, static int should_expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
const char *email, timestamp_t timestamp, int tz, const char *email, timestamp_t timestamp, int tz,
const char *message, void *cb_data) const char *message, void *cb_data)
{ {
@ -295,13 +295,13 @@ static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
old = new = NULL; old = new = NULL;
if (cb->cmd.stalefix && if (cb->cmd.stalefix &&
(!keep_entry(&old, osha1) || !keep_entry(&new, nsha1))) (!keep_entry(&old, ooid) || !keep_entry(&new, noid)))
return 1; return 1;
if (timestamp < cb->cmd.expire_unreachable) { if (timestamp < cb->cmd.expire_unreachable) {
if (cb->unreachable_expire_kind == UE_ALWAYS) if (cb->unreachable_expire_kind == UE_ALWAYS)
return 1; return 1;
if (unreachable(cb, old, osha1) || unreachable(cb, new, nsha1)) if (unreachable(cb, old, ooid) || unreachable(cb, new, noid))
return 1; return 1;
} }
@ -318,7 +318,7 @@ static int push_tip_to_list(const char *refname, const struct object_id *oid,
struct commit *tip_commit; struct commit *tip_commit;
if (flags & REF_ISSYMREF) if (flags & REF_ISSYMREF)
return 0; return 0;
tip_commit = lookup_commit_reference_gently(oid->hash, 1); tip_commit = lookup_commit_reference_gently(oid, 1);
if (!tip_commit) if (!tip_commit)
return 0; return 0;
commit_list_insert(tip_commit, list); commit_list_insert(tip_commit, list);
@ -326,7 +326,7 @@ static int push_tip_to_list(const char *refname, const struct object_id *oid,
} }
static void reflog_expiry_prepare(const char *refname, static void reflog_expiry_prepare(const char *refname,
const unsigned char *sha1, const struct object_id *oid,
void *cb_data) void *cb_data)
{ {
struct expire_reflog_policy_cb *cb = cb_data; struct expire_reflog_policy_cb *cb = cb_data;
@ -335,7 +335,7 @@ static void reflog_expiry_prepare(const char *refname,
cb->tip_commit = NULL; cb->tip_commit = NULL;
cb->unreachable_expire_kind = UE_HEAD; cb->unreachable_expire_kind = UE_HEAD;
} else { } else {
cb->tip_commit = lookup_commit_reference_gently(sha1, 1); cb->tip_commit = lookup_commit_reference_gently(oid, 1);
if (!cb->tip_commit) if (!cb->tip_commit)
cb->unreachable_expire_kind = UE_ALWAYS; cb->unreachable_expire_kind = UE_ALWAYS;
else else

View File

@ -328,7 +328,7 @@ static void replace_parents(struct strbuf *buf, int argc, const char **argv)
struct object_id oid; struct object_id oid;
if (get_oid(argv[i], &oid) < 0) if (get_oid(argv[i], &oid) < 0)
die(_("Not a valid object name: '%s'"), argv[i]); die(_("Not a valid object name: '%s'"), argv[i]);
lookup_commit_or_die(oid.hash, argv[i]); lookup_commit_or_die(&oid, argv[i]);
strbuf_addf(&new_parents, "parent %s\n", oid_to_hex(&oid)); strbuf_addf(&new_parents, "parent %s\n", oid_to_hex(&oid));
} }
@ -355,7 +355,7 @@ static void check_one_mergetag(struct commit *commit,
int i; int i;
hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), tag_oid.hash); hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), tag_oid.hash);
tag = lookup_tag(tag_oid.hash); tag = lookup_tag(&tag_oid);
if (!tag) if (!tag)
die(_("bad mergetag in commit '%s'"), ref); die(_("bad mergetag in commit '%s'"), ref);
if (parse_tag_buffer(tag, extra->value, extra->len)) if (parse_tag_buffer(tag, extra->value, extra->len))
@ -394,7 +394,7 @@ static int create_graft(int argc, const char **argv, int force)
if (get_oid(old_ref, &old) < 0) if (get_oid(old_ref, &old) < 0)
die(_("Not a valid object name: '%s'"), old_ref); die(_("Not a valid object name: '%s'"), old_ref);
commit = lookup_commit_or_die(old.hash, old_ref); commit = lookup_commit_or_die(&old, old_ref);
buffer = get_commit_buffer(commit, &size); buffer = get_commit_buffer(commit, &size);
strbuf_add(&buf, buffer, size); strbuf_add(&buf, buffer, size);

View File

@ -84,7 +84,7 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
return -1; return -1;
if (reset_type == MIXED || reset_type == HARD) { if (reset_type == MIXED || reset_type == HARD) {
tree = parse_tree_indirect(oid->hash); tree = parse_tree_indirect(oid);
prime_cache_tree(&the_index, tree); prime_cache_tree(&the_index, tree);
} }
@ -154,7 +154,7 @@ static int read_from_tree(const struct pathspec *pathspec,
opt.format_callback = update_index_from_diff; opt.format_callback = update_index_from_diff;
opt.format_callback_data = &intent_to_add; opt.format_callback_data = &intent_to_add;
if (do_diff_cache(tree_oid->hash, &opt)) if (do_diff_cache(tree_oid, &opt))
return 1; return 1;
diffcore_std(&opt); diffcore_std(&opt);
diff_flush(&opt); diff_flush(&opt);
@ -303,7 +303,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
struct commit *commit; struct commit *commit;
if (get_sha1_committish(rev, oid.hash)) if (get_sha1_committish(rev, oid.hash))
die(_("Failed to resolve '%s' as a valid revision."), rev); die(_("Failed to resolve '%s' as a valid revision."), rev);
commit = lookup_commit_reference(oid.hash); commit = lookup_commit_reference(&oid);
if (!commit) if (!commit)
die(_("Could not parse object '%s'."), rev); die(_("Could not parse object '%s'."), rev);
oidcpy(&oid, &commit->object.oid); oidcpy(&oid, &commit->object.oid);
@ -311,7 +311,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
struct tree *tree; struct tree *tree;
if (get_sha1_treeish(rev, oid.hash)) if (get_sha1_treeish(rev, oid.hash))
die(_("Failed to resolve '%s' as a valid tree."), rev); die(_("Failed to resolve '%s' as a valid tree."), rev);
tree = parse_tree_indirect(oid.hash); tree = parse_tree_indirect(&oid);
if (!tree) if (!tree)
die(_("Could not parse object '%s'."), rev); die(_("Could not parse object '%s'."), rev);
oidcpy(&oid, &tree->object.oid); oidcpy(&oid, &tree->object.oid);
@ -380,7 +380,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
update_ref_status = reset_refs(rev, &oid); update_ref_status = reset_refs(rev, &oid);
if (reset_type == HARD && !update_ref_status && !quiet) if (reset_type == HARD && !update_ref_status && !quiet)
print_new_head_line(lookup_commit_reference(oid.hash)); print_new_head_line(lookup_commit_reference(&oid));
} }
if (!pathspec.nr) if (!pathspec.nr)
remove_branch_state(); remove_branch_state();

View File

@ -181,7 +181,7 @@ static void finish_object(struct object *obj, const char *name, void *cb_data)
if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid)) if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid))
die("missing blob object '%s'", oid_to_hex(&obj->oid)); die("missing blob object '%s'", oid_to_hex(&obj->oid));
if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT) if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
parse_object(obj->oid.hash); parse_object(&obj->oid);
} }
static void show_object(struct object *obj, const char *name, void *cb_data) static void show_object(struct object *obj, const char *name, void *cb_data)

View File

@ -121,7 +121,7 @@ static void show_with_type(int type, const char *arg)
} }
/* Output a revision, only if filter allows it */ /* Output a revision, only if filter allows it */
static void show_rev(int type, const unsigned char *sha1, const char *name) static void show_rev(int type, const struct object_id *oid, const char *name)
{ {
if (!(filter & DO_REVS)) if (!(filter & DO_REVS))
return; return;
@ -129,10 +129,10 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
if ((symbolic || abbrev_ref) && name) { if ((symbolic || abbrev_ref) && name) {
if (symbolic == SHOW_SYMBOLIC_FULL || abbrev_ref) { if (symbolic == SHOW_SYMBOLIC_FULL || abbrev_ref) {
unsigned char discard[20]; struct object_id discard;
char *full; char *full;
switch (dwim_ref(name, strlen(name), discard, &full)) { switch (dwim_ref(name, strlen(name), discard.hash, &full)) {
case 0: case 0:
/* /*
* Not found -- not a ref. We could * Not found -- not a ref. We could
@ -158,9 +158,9 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
} }
} }
else if (abbrev) else if (abbrev)
show_with_type(type, find_unique_abbrev(sha1, abbrev)); show_with_type(type, find_unique_abbrev(oid->hash, abbrev));
else else
show_with_type(type, sha1_to_hex(sha1)); show_with_type(type, oid_to_hex(oid));
} }
/* Output a flag, only if filter allows it. */ /* Output a flag, only if filter allows it. */
@ -180,11 +180,11 @@ static int show_default(void)
const char *s = def; const char *s = def;
if (s) { if (s) {
unsigned char sha1[20]; struct object_id oid;
def = NULL; def = NULL;
if (!get_sha1(s, sha1)) { if (!get_oid(s, &oid)) {
show_rev(NORMAL, sha1, s); show_rev(NORMAL, &oid, s);
return 1; return 1;
} }
} }
@ -195,19 +195,19 @@ static int show_reference(const char *refname, const struct object_id *oid, int
{ {
if (ref_excluded(ref_excludes, refname)) if (ref_excluded(ref_excludes, refname))
return 0; return 0;
show_rev(NORMAL, oid->hash, refname); show_rev(NORMAL, oid, refname);
return 0; return 0;
} }
static int anti_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data) static int anti_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data)
{ {
show_rev(REVERSED, oid->hash, refname); show_rev(REVERSED, oid, refname);
return 0; return 0;
} }
static int show_abbrev(const struct object_id *oid, void *cb_data) static int show_abbrev(const struct object_id *oid, void *cb_data)
{ {
show_rev(NORMAL, oid->hash, NULL); show_rev(NORMAL, oid, NULL);
return 0; return 0;
} }
@ -242,8 +242,8 @@ static int show_file(const char *arg, int output_prefix)
static int try_difference(const char *arg) static int try_difference(const char *arg)
{ {
char *dotdot; char *dotdot;
unsigned char sha1[20]; struct object_id oid;
unsigned char end[20]; struct object_id end;
const char *next; const char *next;
const char *this; const char *this;
int symmetric; int symmetric;
@ -273,18 +273,18 @@ static int try_difference(const char *arg)
return 0; return 0;
} }
if (!get_sha1_committish(this, sha1) && !get_sha1_committish(next, end)) { if (!get_sha1_committish(this, oid.hash) && !get_sha1_committish(next, end.hash)) {
show_rev(NORMAL, end, next); show_rev(NORMAL, &end, next);
show_rev(symmetric ? NORMAL : REVERSED, sha1, this); show_rev(symmetric ? NORMAL : REVERSED, &oid, this);
if (symmetric) { if (symmetric) {
struct commit_list *exclude; struct commit_list *exclude;
struct commit *a, *b; struct commit *a, *b;
a = lookup_commit_reference(sha1); a = lookup_commit_reference(&oid);
b = lookup_commit_reference(end); b = lookup_commit_reference(&end);
exclude = get_merge_bases(a, b); exclude = get_merge_bases(a, b);
while (exclude) { while (exclude) {
struct commit *commit = pop_commit(&exclude); struct commit *commit = pop_commit(&exclude);
show_rev(REVERSED, commit->object.oid.hash, NULL); show_rev(REVERSED, &commit->object.oid, NULL);
} }
} }
*dotdot = '.'; *dotdot = '.';
@ -297,7 +297,7 @@ static int try_difference(const char *arg)
static int try_parent_shorthands(const char *arg) static int try_parent_shorthands(const char *arg)
{ {
char *dotdot; char *dotdot;
unsigned char sha1[20]; struct object_id oid;
struct commit *commit; struct commit *commit;
struct commit_list *parents; struct commit_list *parents;
int parent_number; int parent_number;
@ -327,12 +327,12 @@ static int try_parent_shorthands(const char *arg)
return 0; return 0;
*dotdot = 0; *dotdot = 0;
if (get_sha1_committish(arg, sha1)) { if (get_sha1_committish(arg, oid.hash)) {
*dotdot = '^'; *dotdot = '^';
return 0; return 0;
} }
commit = lookup_commit_reference(sha1); commit = lookup_commit_reference(&oid);
if (exclude_parent && if (exclude_parent &&
exclude_parent > commit_list_count(commit->parents)) { exclude_parent > commit_list_count(commit->parents)) {
*dotdot = '^'; *dotdot = '^';
@ -340,7 +340,7 @@ static int try_parent_shorthands(const char *arg)
} }
if (include_rev) if (include_rev)
show_rev(NORMAL, sha1, arg); show_rev(NORMAL, &oid, arg);
for (parents = commit->parents, parent_number = 1; for (parents = commit->parents, parent_number = 1;
parents; parents;
parents = parents->next, parent_number++) { parents = parents->next, parent_number++) {
@ -352,7 +352,7 @@ static int try_parent_shorthands(const char *arg)
if (symbolic) if (symbolic)
name = xstrfmt("%s^%d", arg, parent_number); name = xstrfmt("%s^%d", arg, parent_number);
show_rev(include_parents ? NORMAL : REVERSED, show_rev(include_parents ? NORMAL : REVERSED,
parents->item->object.oid.hash, name); &parents->item->object.oid, name);
free(name); free(name);
} }
@ -571,7 +571,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
int did_repo_setup = 0; int did_repo_setup = 0;
int has_dashdash = 0; int has_dashdash = 0;
int output_prefix = 0; int output_prefix = 0;
unsigned char sha1[20]; struct object_id oid;
unsigned int flags = 0; unsigned int flags = 0;
const char *name = NULL; const char *name = NULL;
struct object_context unused; struct object_context unused;
@ -910,11 +910,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
name++; name++;
type = REVERSED; type = REVERSED;
} }
if (!get_sha1_with_context(name, flags, sha1, &unused)) { if (!get_sha1_with_context(name, flags, oid.hash, &unused)) {
if (verify) if (verify)
revs_count++; revs_count++;
else else
show_rev(type, sha1, name); show_rev(type, &oid, name);
continue; continue;
} }
if (verify) if (verify)
@ -929,7 +929,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
strbuf_release(&buf); strbuf_release(&buf);
if (verify) { if (verify) {
if (revs_count == 1) { if (revs_count == 1) {
show_rev(type, sha1, name); show_rev(type, &oid, name);
return 0; return 0;
} else if (revs_count == 0 && show_default()) } else if (revs_count == 0 && show_default())
return 0; return 0;

View File

@ -358,7 +358,7 @@ static void sort_ref_range(int bottom, int top)
static int append_ref(const char *refname, const struct object_id *oid, static int append_ref(const char *refname, const struct object_id *oid,
int allow_dups) int allow_dups)
{ {
struct commit *commit = lookup_commit_reference_gently(oid->hash, 1); struct commit *commit = lookup_commit_reference_gently(oid, 1);
int i; int i;
if (!commit) if (!commit)
@ -816,7 +816,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
MAX_REVS), MAX_REVS); MAX_REVS), MAX_REVS);
if (get_sha1(ref_name[num_rev], revkey.hash)) if (get_sha1(ref_name[num_rev], revkey.hash))
die(_("'%s' is not a valid ref."), ref_name[num_rev]); die(_("'%s' is not a valid ref."), ref_name[num_rev]);
commit = lookup_commit_reference(revkey.hash); commit = lookup_commit_reference(&revkey);
if (!commit) if (!commit)
die(_("cannot find commit %s (%s)"), die(_("cannot find commit %s (%s)"),
ref_name[num_rev], oid_to_hex(&revkey)); ref_name[num_rev], oid_to_hex(&revkey));

View File

@ -66,7 +66,7 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, con
} }
typedef int (*each_tag_name_fn)(const char *name, const char *ref, typedef int (*each_tag_name_fn)(const char *name, const char *ref,
const unsigned char *sha1, const void *cb_data); const struct object_id *oid, const void *cb_data);
static int for_each_tag_name(const char **argv, each_tag_name_fn fn, static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
const void *cb_data) const void *cb_data)
@ -74,17 +74,17 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
const char **p; const char **p;
struct strbuf ref = STRBUF_INIT; struct strbuf ref = STRBUF_INIT;
int had_error = 0; int had_error = 0;
unsigned char sha1[20]; struct object_id oid;
for (p = argv; *p; p++) { for (p = argv; *p; p++) {
strbuf_reset(&ref); strbuf_reset(&ref);
strbuf_addf(&ref, "refs/tags/%s", *p); strbuf_addf(&ref, "refs/tags/%s", *p);
if (read_ref(ref.buf, sha1)) { if (read_ref(ref.buf, oid.hash)) {
error(_("tag '%s' not found."), *p); error(_("tag '%s' not found."), *p);
had_error = 1; had_error = 1;
continue; continue;
} }
if (fn(*p, ref.buf, sha1, cb_data)) if (fn(*p, ref.buf, &oid, cb_data))
had_error = 1; had_error = 1;
} }
strbuf_release(&ref); strbuf_release(&ref);
@ -92,16 +92,16 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
} }
static int delete_tag(const char *name, const char *ref, static int delete_tag(const char *name, const char *ref,
const unsigned char *sha1, const void *cb_data) const struct object_id *oid, const void *cb_data)
{ {
if (delete_ref(NULL, ref, sha1, 0)) if (delete_ref(NULL, ref, oid->hash, 0))
return 1; return 1;
printf(_("Deleted tag '%s' (was %s)\n"), name, find_unique_abbrev(sha1, DEFAULT_ABBREV)); printf(_("Deleted tag '%s' (was %s)\n"), name, find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
return 0; return 0;
} }
static int verify_tag(const char *name, const char *ref, static int verify_tag(const char *name, const char *ref,
const unsigned char *sha1, const void *cb_data) const struct object_id *oid, const void *cb_data)
{ {
int flags; int flags;
const char *fmt_pretty = cb_data; const char *fmt_pretty = cb_data;
@ -110,11 +110,11 @@ static int verify_tag(const char *name, const char *ref,
if (fmt_pretty) if (fmt_pretty)
flags = GPG_VERIFY_OMIT_STATUS; flags = GPG_VERIFY_OMIT_STATUS;
if (gpg_verify_tag(sha1, name, flags)) if (gpg_verify_tag(oid->hash, name, flags))
return -1; return -1;
if (fmt_pretty) if (fmt_pretty)
pretty_print_ref(name, sha1, fmt_pretty); pretty_print_ref(name, oid->hash, fmt_pretty);
return 0; return 0;
} }
@ -182,13 +182,13 @@ static int git_tag_config(const char *var, const char *value, void *cb)
return git_default_config(var, value, cb); return git_default_config(var, value, cb);
} }
static void write_tag_body(int fd, const unsigned char *sha1) static void write_tag_body(int fd, const struct object_id *oid)
{ {
unsigned long size; unsigned long size;
enum object_type type; enum object_type type;
char *buf, *sp; char *buf, *sp;
buf = read_sha1_file(sha1, &type, &size); buf = read_sha1_file(oid->hash, &type, &size);
if (!buf) if (!buf)
return; return;
/* skip header */ /* skip header */
@ -204,11 +204,11 @@ static void write_tag_body(int fd, const unsigned char *sha1)
free(buf); free(buf);
} }
static int build_tag_object(struct strbuf *buf, int sign, unsigned char *result) static int build_tag_object(struct strbuf *buf, int sign, struct object_id *result)
{ {
if (sign && do_sign(buf) < 0) if (sign && do_sign(buf) < 0)
return error(_("unable to sign the tag")); return error(_("unable to sign the tag"));
if (write_sha1_file(buf->buf, buf->len, tag_type, result) < 0) if (write_sha1_file(buf->buf, buf->len, tag_type, result->hash) < 0)
return error(_("unable to write tag file")); return error(_("unable to write tag file"));
return 0; return 0;
} }
@ -223,15 +223,15 @@ struct create_tag_options {
} cleanup_mode; } cleanup_mode;
}; };
static void create_tag(const unsigned char *object, const char *tag, static void create_tag(const struct object_id *object, const char *tag,
struct strbuf *buf, struct create_tag_options *opt, struct strbuf *buf, struct create_tag_options *opt,
unsigned char *prev, unsigned char *result) struct object_id *prev, struct object_id *result)
{ {
enum object_type type; enum object_type type;
struct strbuf header = STRBUF_INIT; struct strbuf header = STRBUF_INIT;
char *path = NULL; char *path = NULL;
type = sha1_object_info(object, NULL); type = sha1_object_info(object->hash, NULL);
if (type <= OBJ_NONE) if (type <= OBJ_NONE)
die(_("bad object type.")); die(_("bad object type."));
@ -240,7 +240,7 @@ static void create_tag(const unsigned char *object, const char *tag,
"type %s\n" "type %s\n"
"tag %s\n" "tag %s\n"
"tagger %s\n\n", "tagger %s\n\n",
sha1_to_hex(object), oid_to_hex(object),
typename(type), typename(type),
tag, tag,
git_committer_info(IDENT_STRICT)); git_committer_info(IDENT_STRICT));
@ -254,7 +254,7 @@ static void create_tag(const unsigned char *object, const char *tag,
if (fd < 0) if (fd < 0)
die_errno(_("could not create file '%s'"), path); die_errno(_("could not create file '%s'"), path);
if (!is_null_sha1(prev)) { if (!is_null_oid(prev)) {
write_tag_body(fd, prev); write_tag_body(fd, prev);
} else { } else {
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
@ -296,7 +296,7 @@ static void create_tag(const unsigned char *object, const char *tag,
} }
} }
static void create_reflog_msg(const unsigned char *sha1, struct strbuf *sb) static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
{ {
enum object_type type; enum object_type type;
struct commit *c; struct commit *c;
@ -310,17 +310,17 @@ static void create_reflog_msg(const unsigned char *sha1, 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, sha1, DEFAULT_ABBREV); strbuf_add_unique_abbrev(sb, oid->hash, DEFAULT_ABBREV);
} }
strbuf_addstr(sb, " ("); strbuf_addstr(sb, " (");
type = sha1_object_info(sha1, NULL); type = sha1_object_info(oid->hash, 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(sha1, &type, &size)) != NULL) { if ((buf = read_sha1_file(oid->hash, &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 {
@ -328,7 +328,7 @@ static void create_reflog_msg(const unsigned char *sha1, struct strbuf *sb)
} }
free(buf); free(buf);
if ((c = lookup_commit_reference(sha1)) != NULL) if ((c = lookup_commit_reference(oid)) != NULL)
strbuf_addf(sb, ", %s", show_date(c->date, 0, DATE_MODE(SHORT))); strbuf_addf(sb, ", %s", show_date(c->date, 0, DATE_MODE(SHORT)));
break; break;
case OBJ_TREE: case OBJ_TREE:
@ -378,7 +378,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
struct strbuf ref = STRBUF_INIT; struct strbuf ref = STRBUF_INIT;
struct strbuf reflog_msg = STRBUF_INIT; struct strbuf reflog_msg = STRBUF_INIT;
unsigned char object[20], prev[20]; struct object_id object, prev;
const char *object_ref, *tag; const char *object_ref, *tag;
struct create_tag_options opt; struct create_tag_options opt;
char *cleanup_arg = NULL; char *cleanup_arg = NULL;
@ -528,14 +528,14 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
if (argc > 2) if (argc > 2)
die(_("too many params")); die(_("too many params"));
if (get_sha1(object_ref, object)) if (get_oid(object_ref, &object))
die(_("Failed to resolve '%s' as a valid ref."), object_ref); die(_("Failed to resolve '%s' as a valid ref."), object_ref);
if (strbuf_check_tag_ref(&ref, tag)) if (strbuf_check_tag_ref(&ref, tag))
die(_("'%s' is not a valid tag name."), tag); die(_("'%s' is not a valid tag name."), tag);
if (read_ref(ref.buf, prev)) if (read_ref(ref.buf, prev.hash))
hashclr(prev); oidclr(&prev);
else if (!force) else if (!force)
die(_("tag '%s' already exists"), tag); die(_("tag '%s' already exists"), tag);
@ -550,24 +550,24 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
else else
die(_("Invalid cleanup mode %s"), cleanup_arg); die(_("Invalid cleanup mode %s"), cleanup_arg);
create_reflog_msg(object, &reflog_msg); create_reflog_msg(&object, &reflog_msg);
if (create_tag_object) { if (create_tag_object) {
if (force_sign_annotate && !annotate) if (force_sign_annotate && !annotate)
opt.sign = 1; opt.sign = 1;
create_tag(object, tag, &buf, &opt, prev, object); create_tag(&object, tag, &buf, &opt, &prev, &object);
} }
transaction = ref_transaction_begin(&err); transaction = ref_transaction_begin(&err);
if (!transaction || if (!transaction ||
ref_transaction_update(transaction, ref.buf, object, prev, ref_transaction_update(transaction, ref.buf, object.hash, prev.hash,
create_reflog ? REF_FORCE_CREATE_REFLOG : 0, create_reflog ? REF_FORCE_CREATE_REFLOG : 0,
reflog_msg.buf, &err) || reflog_msg.buf, &err) ||
ref_transaction_commit(transaction, &err)) ref_transaction_commit(transaction, &err))
die("%s", err.buf); die("%s", err.buf);
ref_transaction_free(transaction); ref_transaction_free(transaction);
if (force && !is_null_sha1(prev) && hashcmp(prev, object)) if (force && !is_null_oid(&prev) && oidcmp(&prev, &object))
printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev, DEFAULT_ABBREV)); printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev.hash, DEFAULT_ABBREV));
strbuf_release(&err); strbuf_release(&err);
strbuf_release(&buf); strbuf_release(&buf);

View File

@ -127,7 +127,7 @@ static void *get_data(unsigned long size)
} }
struct delta_info { struct delta_info {
unsigned char base_sha1[20]; struct object_id base_oid;
unsigned nr; unsigned nr;
off_t base_offset; off_t base_offset;
unsigned long size; unsigned long size;
@ -137,13 +137,13 @@ struct delta_info {
static struct delta_info *delta_list; static struct delta_info *delta_list;
static void add_delta_to_list(unsigned nr, unsigned const char *base_sha1, static void add_delta_to_list(unsigned nr, const struct object_id *base_oid,
off_t base_offset, off_t base_offset,
void *delta, unsigned long size) void *delta, unsigned long size)
{ {
struct delta_info *info = xmalloc(sizeof(*info)); struct delta_info *info = xmalloc(sizeof(*info));
hashcpy(info->base_sha1, base_sha1); oidcpy(&info->base_oid, base_oid);
info->base_offset = base_offset; info->base_offset = base_offset;
info->size = size; info->size = size;
info->delta = delta; info->delta = delta;
@ -154,7 +154,7 @@ static void add_delta_to_list(unsigned nr, unsigned const char *base_sha1,
struct obj_info { struct obj_info {
off_t offset; off_t offset;
unsigned char sha1[20]; struct object_id oid;
struct object *obj; struct object *obj;
}; };
@ -170,9 +170,9 @@ static unsigned nr_objects;
*/ */
static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf) static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
{ {
unsigned char sha1[20]; struct object_id oid;
if (write_sha1_file(obj_buf->buffer, obj_buf->size, typename(obj->type), sha1) < 0) if (write_sha1_file(obj_buf->buffer, obj_buf->size, typename(obj->type), oid.hash) < 0)
die("failed to write object %s", oid_to_hex(&obj->oid)); die("failed to write object %s", oid_to_hex(&obj->oid));
obj->flags |= FLAG_WRITTEN; obj->flags |= FLAG_WRITTEN;
} }
@ -237,19 +237,19 @@ static void write_object(unsigned nr, enum object_type type,
void *buf, unsigned long size) void *buf, unsigned long size)
{ {
if (!strict) { if (!strict) {
if (write_sha1_file(buf, size, typename(type), obj_list[nr].sha1) < 0) if (write_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash) < 0)
die("failed to write object"); die("failed to write object");
added_object(nr, type, buf, size); added_object(nr, type, buf, size);
free(buf); free(buf);
obj_list[nr].obj = NULL; obj_list[nr].obj = NULL;
} else if (type == OBJ_BLOB) { } else if (type == OBJ_BLOB) {
struct blob *blob; struct blob *blob;
if (write_sha1_file(buf, size, typename(type), obj_list[nr].sha1) < 0) if (write_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash) < 0)
die("failed to write object"); die("failed to write object");
added_object(nr, type, buf, size); added_object(nr, type, buf, size);
free(buf); free(buf);
blob = lookup_blob(obj_list[nr].sha1); blob = lookup_blob(&obj_list[nr].oid);
if (blob) if (blob)
blob->object.flags |= FLAG_WRITTEN; blob->object.flags |= FLAG_WRITTEN;
else else
@ -258,9 +258,10 @@ static void write_object(unsigned nr, enum object_type type,
} else { } else {
struct object *obj; struct object *obj;
int eaten; int eaten;
hash_sha1_file(buf, size, typename(type), obj_list[nr].sha1); hash_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash);
added_object(nr, type, buf, size); added_object(nr, type, buf, size);
obj = parse_object_buffer(obj_list[nr].sha1, type, size, buf, &eaten); obj = parse_object_buffer(&obj_list[nr].oid, type, size, buf,
&eaten);
if (!obj) if (!obj)
die("invalid %s", typename(type)); die("invalid %s", typename(type));
add_object_buffer(obj, buf, size); add_object_buffer(obj, buf, size);
@ -296,7 +297,7 @@ static void added_object(unsigned nr, enum object_type type,
struct delta_info *info; struct delta_info *info;
while ((info = *p) != NULL) { while ((info = *p) != NULL) {
if (!hashcmp(info->base_sha1, obj_list[nr].sha1) || if (!oidcmp(&info->base_oid, &obj_list[nr].oid) ||
info->base_offset == obj_list[nr].offset) { info->base_offset == obj_list[nr].offset) {
*p = info->next; *p = info->next;
p = &delta_list; p = &delta_list;
@ -320,12 +321,12 @@ static void unpack_non_delta_entry(enum object_type type, unsigned long size,
free(buf); free(buf);
} }
static int resolve_against_held(unsigned nr, const unsigned char *base, static int resolve_against_held(unsigned nr, const struct object_id *base,
void *delta_data, unsigned long delta_size) void *delta_data, unsigned long delta_size)
{ {
struct object *obj; struct object *obj;
struct obj_buffer *obj_buffer; struct obj_buffer *obj_buffer;
obj = lookup_object(base); obj = lookup_object(base->hash);
if (!obj) if (!obj)
return 0; return 0;
obj_buffer = lookup_object_buffer(obj); obj_buffer = lookup_object_buffer(obj);
@ -341,25 +342,25 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
{ {
void *delta_data, *base; void *delta_data, *base;
unsigned long base_size; unsigned long base_size;
unsigned char base_sha1[20]; struct object_id base_oid;
if (type == OBJ_REF_DELTA) { if (type == OBJ_REF_DELTA) {
hashcpy(base_sha1, fill(20)); hashcpy(base_oid.hash, fill(GIT_SHA1_RAWSZ));
use(20); use(GIT_SHA1_RAWSZ);
delta_data = get_data(delta_size); delta_data = get_data(delta_size);
if (dry_run || !delta_data) { if (dry_run || !delta_data) {
free(delta_data); free(delta_data);
return; return;
} }
if (has_sha1_file(base_sha1)) if (has_object_file(&base_oid))
; /* Ok we have this one */ ; /* Ok we have this one */
else if (resolve_against_held(nr, base_sha1, else if (resolve_against_held(nr, &base_oid,
delta_data, delta_size)) delta_data, delta_size))
return; /* we are done */ return; /* we are done */
else { else {
/* cannot resolve yet --- queue it */ /* cannot resolve yet --- queue it */
hashclr(obj_list[nr].sha1); oidclr(&obj_list[nr].oid);
add_delta_to_list(nr, base_sha1, 0, delta_data, delta_size); add_delta_to_list(nr, &base_oid, 0, delta_data, delta_size);
return; return;
} }
} else { } else {
@ -399,8 +400,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
} else if (base_offset > obj_list[mid].offset) { } else if (base_offset > obj_list[mid].offset) {
lo = mid + 1; lo = mid + 1;
} else { } else {
hashcpy(base_sha1, obj_list[mid].sha1); oidcpy(&base_oid, &obj_list[mid].oid);
base_found = !is_null_sha1(base_sha1); base_found = !is_null_oid(&base_oid);
break; break;
} }
} }
@ -409,19 +410,19 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
* The delta base object is itself a delta that * The delta base object is itself a delta that
* has not been resolved yet. * has not been resolved yet.
*/ */
hashclr(obj_list[nr].sha1); oidclr(&obj_list[nr].oid);
add_delta_to_list(nr, null_sha1, base_offset, delta_data, delta_size); add_delta_to_list(nr, &null_oid, base_offset, delta_data, delta_size);
return; return;
} }
} }
if (resolve_against_held(nr, base_sha1, delta_data, delta_size)) if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
return; return;
base = read_sha1_file(base_sha1, &type, &base_size); base = read_sha1_file(base_oid.hash, &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",
sha1_to_hex(base_sha1)); oid_to_hex(&base_oid));
if (!recover) if (!recover)
exit(1); exit(1);
has_errors = 1; has_errors = 1;
@ -505,7 +506,7 @@ static void unpack_all(void)
int cmd_unpack_objects(int argc, const char **argv, const char *prefix) int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
{ {
int i; int i;
unsigned char sha1[20]; struct object_id oid;
check_replace_refs = 0; check_replace_refs = 0;
@ -566,12 +567,12 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
git_SHA1_Init(&ctx); git_SHA1_Init(&ctx);
unpack_all(); unpack_all();
git_SHA1_Update(&ctx, buffer, offset); git_SHA1_Update(&ctx, buffer, offset);
git_SHA1_Final(sha1, &ctx); git_SHA1_Final(oid.hash, &ctx);
if (strict) if (strict)
write_rest(); write_rest();
if (hashcmp(fill(20), sha1)) if (hashcmp(fill(GIT_SHA1_RAWSZ), oid.hash))
die("final sha1 did not match"); die("final sha1 did not match");
use(20); use(GIT_SHA1_RAWSZ);
/* Write the last part of the buffer to stdout */ /* Write the last part of the buffer to stdout */
while (len) { while (len) {

View File

@ -18,14 +18,14 @@ static const char * const verify_commit_usage[] = {
NULL NULL
}; };
static int run_gpg_verify(const unsigned char *sha1, const char *buf, unsigned long size, unsigned flags) static int run_gpg_verify(const struct object_id *oid, const char *buf, unsigned long size, unsigned flags)
{ {
struct signature_check signature_check; struct signature_check signature_check;
int ret; int ret;
memset(&signature_check, 0, sizeof(signature_check)); memset(&signature_check, 0, sizeof(signature_check));
ret = check_commit_signature(lookup_commit(sha1), &signature_check); ret = check_commit_signature(lookup_commit(oid), &signature_check);
print_signature_buffer(&signature_check, flags); print_signature_buffer(&signature_check, flags);
signature_check_clear(&signature_check); signature_check_clear(&signature_check);
@ -35,22 +35,22 @@ static int run_gpg_verify(const unsigned char *sha1, const char *buf, unsigned l
static int verify_commit(const char *name, unsigned flags) static int verify_commit(const char *name, unsigned flags)
{ {
enum object_type type; enum object_type type;
unsigned char sha1[20]; struct object_id oid;
char *buf; char *buf;
unsigned long size; unsigned long size;
int ret; int ret;
if (get_sha1(name, sha1)) if (get_oid(name, &oid))
return error("commit '%s' not found.", name); return error("commit '%s' not found.", name);
buf = read_sha1_file(sha1, &type, &size); buf = read_sha1_file(oid.hash, &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)
return error("%s: cannot verify a non-commit object of type %s.", return error("%s: cannot verify a non-commit object of type %s.",
name, typename(type)); name, typename(type));
ret = run_gpg_verify(sha1, buf, size, flags); ret = run_gpg_verify(&oid, buf, size, flags);
free(buf); free(buf);
return ret; return ret;

View File

@ -69,7 +69,7 @@ static int already_written(struct bulk_checkin_state *state, unsigned char sha1[
/* 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]->sha1, sha1)) if (!hashcmp(state->written[i]->oid.hash, sha1))
return 1; return 1;
/* This is a new object we need to keep */ /* This is a new object we need to keep */
@ -242,7 +242,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,
state->offset = checkpoint.offset; state->offset = checkpoint.offset;
free(idx); free(idx);
} else { } else {
hashcpy(idx->sha1, result_sha1); hashcpy(idx->oid.hash, result_sha1);
ALLOC_GROW(state->written, ALLOC_GROW(state->written,
state->nr_written + 1, state->nr_written + 1,
state->alloc_written); state->alloc_written);

View File

@ -12,11 +12,11 @@
static const char bundle_signature[] = "# v2 git bundle\n"; static const char bundle_signature[] = "# v2 git bundle\n";
static void add_to_ref_list(const unsigned char *sha1, const char *name, static void add_to_ref_list(const struct object_id *oid, const char *name,
struct ref_list *list) struct ref_list *list)
{ {
ALLOC_GROW(list->list, list->nr + 1, list->alloc); ALLOC_GROW(list->list, list->nr + 1, list->alloc);
hashcpy(list->list[list->nr].sha1, sha1); oidcpy(&list->list[list->nr].oid, oid);
list->list[list->nr].name = xstrdup(name); list->list[list->nr].name = xstrdup(name);
list->nr++; list->nr++;
} }
@ -40,8 +40,9 @@ static int parse_bundle_header(int fd, struct bundle_header *header,
/* The bundle header ends with an empty line */ /* The bundle header ends with an empty line */
while (!strbuf_getwholeline_fd(&buf, fd, '\n') && while (!strbuf_getwholeline_fd(&buf, fd, '\n') &&
buf.len && buf.buf[0] != '\n') { buf.len && buf.buf[0] != '\n') {
unsigned char sha1[20]; struct object_id oid;
int is_prereq = 0; int is_prereq = 0;
const char *p;
if (*buf.buf == '-') { if (*buf.buf == '-') {
is_prereq = 1; is_prereq = 1;
@ -54,9 +55,9 @@ static int parse_bundle_header(int fd, struct bundle_header *header,
* Prerequisites have object name that is optionally * Prerequisites have object name that is optionally
* followed by SP and subject line. * followed by SP and subject line.
*/ */
if (get_sha1_hex(buf.buf, sha1) || if (parse_oid_hex(buf.buf, &oid, &p) ||
(buf.len > 40 && !isspace(buf.buf[40])) || (*p && !isspace(*p)) ||
(!is_prereq && buf.len <= 40)) { (!is_prereq && !*p)) {
if (report_path) if (report_path)
error(_("unrecognized header: %s%s (%d)"), error(_("unrecognized header: %s%s (%d)"),
(is_prereq ? "-" : ""), buf.buf, (int)buf.len); (is_prereq ? "-" : ""), buf.buf, (int)buf.len);
@ -64,9 +65,9 @@ static int parse_bundle_header(int fd, struct bundle_header *header,
break; break;
} else { } else {
if (is_prereq) if (is_prereq)
add_to_ref_list(sha1, "", &header->prerequisites); add_to_ref_list(&oid, "", &header->prerequisites);
else else
add_to_ref_list(sha1, buf.buf + 41, &header->references); add_to_ref_list(&oid, p + 1, &header->references);
} }
} }
@ -115,7 +116,7 @@ static int list_refs(struct ref_list *r, int argc, const char **argv)
if (j == argc) if (j == argc)
continue; continue;
} }
printf("%s %s\n", sha1_to_hex(r->list[i].sha1), printf("%s %s\n", oid_to_hex(&r->list[i].oid),
r->list[i].name); r->list[i].name);
} }
return 0; return 0;
@ -141,7 +142,7 @@ int verify_bundle(struct bundle_header *header, int verbose)
init_revisions(&revs, NULL); init_revisions(&revs, NULL);
for (i = 0; i < p->nr; i++) { for (i = 0; i < p->nr; i++) {
struct ref_list_entry *e = p->list + i; struct ref_list_entry *e = p->list + i;
struct object *o = parse_object(e->sha1); struct object *o = parse_object(&e->oid);
if (o) { if (o) {
o->flags |= PREREQ_MARK; o->flags |= PREREQ_MARK;
add_pending_object(&revs, o, e->name); add_pending_object(&revs, o, e->name);
@ -149,7 +150,7 @@ int verify_bundle(struct bundle_header *header, int verbose)
} }
if (++ret == 1) if (++ret == 1)
error("%s", message); error("%s", message);
error("%s %s", sha1_to_hex(e->sha1), e->name); error("%s %s", oid_to_hex(&e->oid), e->name);
} }
if (revs.pending.nr != p->nr) if (revs.pending.nr != p->nr)
return ret; return ret;
@ -285,16 +286,18 @@ static int compute_and_write_prerequisites(int bundle_fd,
return -1; return -1;
rls_fout = xfdopen(rls.out, "r"); rls_fout = xfdopen(rls.out, "r");
while (strbuf_getwholeline(&buf, rls_fout, '\n') != EOF) { while (strbuf_getwholeline(&buf, rls_fout, '\n') != EOF) {
unsigned char sha1[20]; struct object_id oid;
if (buf.len > 0 && buf.buf[0] == '-') { if (buf.len > 0 && buf.buf[0] == '-') {
write_or_die(bundle_fd, buf.buf, buf.len); write_or_die(bundle_fd, buf.buf, buf.len);
if (!get_sha1_hex(buf.buf + 1, sha1)) { if (!get_oid_hex(buf.buf + 1, &oid)) {
struct object *object = parse_object_or_die(sha1, buf.buf); struct object *object = parse_object_or_die(&oid,
buf.buf);
object->flags |= UNINTERESTING; object->flags |= UNINTERESTING;
add_pending_object(revs, object, buf.buf); add_pending_object(revs, object, buf.buf);
} }
} else if (!get_sha1_hex(buf.buf, sha1)) { } else if (!get_oid_hex(buf.buf, &oid)) {
struct object *object = parse_object_or_die(sha1, buf.buf); struct object *object = parse_object_or_die(&oid,
buf.buf);
object->flags |= SHOWN; object->flags |= SHOWN;
} }
} }
@ -366,7 +369,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
* in terms of a tag (e.g. v2.0 from the range * in terms of a tag (e.g. v2.0 from the range
* "v1.0..v2.0")? * "v1.0..v2.0")?
*/ */
struct commit *one = lookup_commit_reference(oid.hash); struct commit *one = lookup_commit_reference(&oid);
struct object *obj; struct object *obj;
if (e->item == &(one->object)) { if (e->item == &(one->object)) {
@ -378,7 +381,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
* end up triggering "empty bundle" * end up triggering "empty bundle"
* error. * error.
*/ */
obj = parse_object_or_die(oid.hash, e->name); obj = parse_object_or_die(&oid, e->name);
obj->flags |= SHOWN; obj->flags |= SHOWN;
add_pending_object(revs, obj, e->name); add_pending_object(revs, obj, e->name);
} }

View File

@ -1,10 +1,12 @@
#ifndef BUNDLE_H #ifndef BUNDLE_H
#define BUNDLE_H #define BUNDLE_H
#include "cache.h"
struct ref_list { struct ref_list {
unsigned int nr, alloc; unsigned int nr, alloc;
struct ref_list_entry { struct ref_list_entry {
unsigned char sha1[20]; struct object_id oid;
char *name; char *name;
} *list; } *list;
}; };

View File

@ -225,7 +225,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
int i; int i;
if (!it) if (!it)
return 0; return 0;
if (it->entry_count < 0 || !has_sha1_file(it->sha1)) if (it->entry_count < 0 || !has_sha1_file(it->oid.hash))
return 0; return 0;
for (i = 0; i < it->subtree_nr; i++) { for (i = 0; i < it->subtree_nr; i++) {
if (!cache_tree_fully_valid(it->down[i]->cache_tree)) if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@ -253,7 +253,7 @@ static int update_one(struct cache_tree *it,
*skip_count = 0; *skip_count = 0;
if (0 <= it->entry_count && has_sha1_file(it->sha1)) if (0 <= it->entry_count && has_sha1_file(it->oid.hash))
return it->entry_count; return it->entry_count;
/* /*
@ -340,7 +340,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->sha1; sha1 = sub->cache_tree->oid.hash;
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) {
@ -404,12 +404,13 @@ static int update_one(struct cache_tree *it,
unsigned char sha1[20]; unsigned char sha1[20];
hash_sha1_file(buffer.buf, buffer.len, tree_type, sha1); hash_sha1_file(buffer.buf, buffer.len, tree_type, sha1);
if (has_sha1_file(sha1)) if (has_sha1_file(sha1))
hashcpy(it->sha1, sha1); hashcpy(it->oid.hash, sha1);
else else
to_invalidate = 1; to_invalidate = 1;
} else if (dryrun) } else if (dryrun)
hash_sha1_file(buffer.buf, buffer.len, tree_type, it->sha1); hash_sha1_file(buffer.buf, buffer.len, tree_type,
else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->sha1)) { it->oid.hash);
else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->oid.hash)) {
strbuf_release(&buffer); strbuf_release(&buffer);
return -1; return -1;
} }
@ -419,7 +420,7 @@ static int update_one(struct cache_tree *it,
#if DEBUG #if DEBUG
fprintf(stderr, "cache-tree update-one (%d ent, %d subtree) %s\n", fprintf(stderr, "cache-tree update-one (%d ent, %d subtree) %s\n",
it->entry_count, it->subtree_nr, it->entry_count, it->subtree_nr,
sha1_to_hex(it->sha1)); oid_to_hex(&it->oid));
#endif #endif
return i; return i;
} }
@ -459,14 +460,14 @@ static void write_one(struct strbuf *buffer, struct cache_tree *it,
if (0 <= it->entry_count) if (0 <= it->entry_count)
fprintf(stderr, "cache-tree <%.*s> (%d ent, %d subtree) %s\n", fprintf(stderr, "cache-tree <%.*s> (%d ent, %d subtree) %s\n",
pathlen, path, it->entry_count, it->subtree_nr, pathlen, path, it->entry_count, it->subtree_nr,
sha1_to_hex(it->sha1)); oid_to_hex(&it->oid));
else else
fprintf(stderr, "cache-tree <%.*s> (%d subtree) invalid\n", fprintf(stderr, "cache-tree <%.*s> (%d subtree) invalid\n",
pathlen, path, it->subtree_nr); pathlen, path, it->subtree_nr);
#endif #endif
if (0 <= it->entry_count) { if (0 <= it->entry_count) {
strbuf_add(buffer, it->sha1, 20); strbuf_add(buffer, it->oid.hash, 20);
} }
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];
@ -523,7 +524,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
if (0 <= it->entry_count) { if (0 <= it->entry_count) {
if (size < 20) if (size < 20)
goto free_return; goto free_return;
hashcpy(it->sha1, (const unsigned char*)buf); hashcpy(it->oid.hash, (const unsigned char*)buf);
buf += 20; buf += 20;
size -= 20; size -= 20;
} }
@ -532,7 +533,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
if (0 <= it->entry_count) if (0 <= it->entry_count)
fprintf(stderr, "cache-tree <%s> (%d ent, %d subtree) %s\n", fprintf(stderr, "cache-tree <%s> (%d ent, %d subtree) %s\n",
*buffer, it->entry_count, subtree_nr, *buffer, it->entry_count, subtree_nr,
sha1_to_hex(it->sha1)); oid_to_hex(&it->oid));
else else
fprintf(stderr, "cache-tree <%s> (%d subtrees) invalid\n", fprintf(stderr, "cache-tree <%s> (%d subtrees) invalid\n",
*buffer, subtree_nr); *buffer, subtree_nr);
@ -643,10 +644,10 @@ int write_index_as_tree(unsigned char *sha1, struct index_state *index_state, co
subtree = cache_tree_find(index_state->cache_tree, prefix); subtree = cache_tree_find(index_state->cache_tree, prefix);
if (!subtree) if (!subtree)
return WRITE_TREE_PREFIX_ERROR; return WRITE_TREE_PREFIX_ERROR;
hashcpy(sha1, subtree->sha1); hashcpy(sha1, subtree->oid.hash);
} }
else else
hashcpy(sha1, index_state->cache_tree->sha1); hashcpy(sha1, index_state->cache_tree->oid.hash);
if (0 <= newfd) if (0 <= newfd)
rollback_lock_file(lock_file); rollback_lock_file(lock_file);
@ -665,7 +666,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
struct name_entry entry; struct name_entry entry;
int cnt; int cnt;
hashcpy(it->sha1, tree->object.oid.hash); oidcpy(&it->oid, &tree->object.oid);
init_tree_desc(&desc, tree->buffer, tree->size); init_tree_desc(&desc, tree->buffer, tree->size);
cnt = 0; cnt = 0;
while (tree_entry(&desc, &entry)) { while (tree_entry(&desc, &entry)) {
@ -673,7 +674,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
cnt++; cnt++;
else { else {
struct cache_tree_sub *sub; struct cache_tree_sub *sub;
struct tree *subtree = lookup_tree(entry.oid->hash); struct tree *subtree = lookup_tree(entry.oid);
if (!subtree->object.parsed) if (!subtree->object.parsed)
parse_tree(subtree); parse_tree(subtree);
sub = cache_tree_sub(it, entry.path); sub = cache_tree_sub(it, entry.path);
@ -720,7 +721,7 @@ int cache_tree_matches_traversal(struct cache_tree *root,
it = find_cache_tree_from_traversal(root, info); it = find_cache_tree_from_traversal(root, info);
it = cache_tree_find(it, ent->path); it = cache_tree_find(it, ent->path);
if (it && it->entry_count > 0 && !hashcmp(ent->oid->hash, it->sha1)) if (it && it->entry_count > 0 && !oidcmp(ent->oid, &it->oid))
return it->entry_count; return it->entry_count;
return 0; return 0;
} }

View File

@ -1,6 +1,7 @@
#ifndef CACHE_TREE_H #ifndef CACHE_TREE_H
#define CACHE_TREE_H #define CACHE_TREE_H
#include "cache.h"
#include "tree.h" #include "tree.h"
#include "tree-walk.h" #include "tree-walk.h"
@ -15,7 +16,7 @@ struct cache_tree_sub {
struct cache_tree { struct cache_tree {
int entry_count; /* negative means "invalid" */ int entry_count; /* negative means "invalid" */
unsigned char sha1[20]; struct object_id oid;
int subtree_nr; int subtree_nr;
int subtree_alloc; int subtree_alloc;
struct cache_tree_sub **down; struct cache_tree_sub **down;

View File

@ -2198,8 +2198,8 @@ struct commit_list;
int try_merge_command(const char *strategy, size_t xopts_nr, int try_merge_command(const char *strategy, size_t xopts_nr,
const char **xopts, struct commit_list *common, const char **xopts, struct commit_list *common,
const char *head_arg, struct commit_list *remotes); const char *head_arg, struct commit_list *remotes);
int checkout_fast_forward(const unsigned char *from, int checkout_fast_forward(const struct object_id *from,
const unsigned char *to, const struct object_id *to,
int overwrite_ignore); int overwrite_ignore);

View File

@ -18,38 +18,38 @@ int save_commit_buffer = 1;
const char *commit_type = "commit"; const char *commit_type = "commit";
struct commit *lookup_commit_reference_gently(const unsigned char *sha1, struct commit *lookup_commit_reference_gently(const struct object_id *oid,
int quiet) int quiet)
{ {
struct object *obj = deref_tag(parse_object(sha1), NULL, 0); struct object *obj = deref_tag(parse_object(oid), NULL, 0);
if (!obj) if (!obj)
return NULL; return NULL;
return object_as_type(obj, OBJ_COMMIT, quiet); return object_as_type(obj, OBJ_COMMIT, quiet);
} }
struct commit *lookup_commit_reference(const unsigned char *sha1) struct commit *lookup_commit_reference(const struct object_id *oid)
{ {
return lookup_commit_reference_gently(sha1, 0); return lookup_commit_reference_gently(oid, 0);
} }
struct commit *lookup_commit_or_die(const unsigned char *sha1, const char *ref_name) struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name)
{ {
struct commit *c = lookup_commit_reference(sha1); struct commit *c = lookup_commit_reference(oid);
if (!c) if (!c)
die(_("could not parse %s"), ref_name); die(_("could not parse %s"), ref_name);
if (hashcmp(sha1, c->object.oid.hash)) { if (oidcmp(oid, &c->object.oid)) {
warning(_("%s %s is not a commit!"), warning(_("%s %s is not a commit!"),
ref_name, sha1_to_hex(sha1)); ref_name, oid_to_hex(oid));
} }
return c; return c;
} }
struct commit *lookup_commit(const unsigned char *sha1) struct commit *lookup_commit(const struct object_id *oid)
{ {
struct object *obj = lookup_object(sha1); struct object *obj = lookup_object(oid->hash);
if (!obj) if (!obj)
return create_object(sha1, alloc_commit_node()); return create_object(oid->hash, alloc_commit_node());
return object_as_type(obj, OBJ_COMMIT, 0); return object_as_type(obj, OBJ_COMMIT, 0);
} }
@ -60,7 +60,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)
if (get_sha1_committish(name, oid.hash)) if (get_sha1_committish(name, oid.hash))
return NULL; return NULL;
commit = lookup_commit_reference(oid.hash); commit = lookup_commit_reference(&oid);
if (parse_commit(commit)) if (parse_commit(commit))
return NULL; return NULL;
return commit; return commit;
@ -216,9 +216,9 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
return ret; return ret;
} }
int unregister_shallow(const unsigned char *sha1) int unregister_shallow(const struct object_id *oid)
{ {
int pos = commit_graft_pos(sha1); int pos = commit_graft_pos(oid->hash);
if (pos < 0) if (pos < 0)
return -1; return -1;
if (pos + 1 < commit_graft_nr) if (pos + 1 < commit_graft_nr)
@ -331,7 +331,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
if (get_sha1_hex(bufptr + 5, parent.hash) < 0) if (get_sha1_hex(bufptr + 5, parent.hash) < 0)
return error("bad tree pointer in commit %s", return error("bad tree pointer in commit %s",
oid_to_hex(&item->object.oid)); oid_to_hex(&item->object.oid));
item->tree = lookup_tree(parent.hash); item->tree = lookup_tree(&parent);
bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */ bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
pptr = &item->parents; pptr = &item->parents;
@ -350,7 +350,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
*/ */
if (graft && (graft->nr_parent < 0 || grafts_replace_parents)) if (graft && (graft->nr_parent < 0 || grafts_replace_parents))
continue; continue;
new_parent = lookup_commit(parent.hash); new_parent = lookup_commit(&parent);
if (new_parent) if (new_parent)
pptr = &commit_list_insert(new_parent, pptr)->next; pptr = &commit_list_insert(new_parent, pptr)->next;
} }
@ -358,7 +358,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
int i; int i;
struct commit *new_parent; struct commit *new_parent;
for (i = 0; i < graft->nr_parent; i++) { for (i = 0; i < graft->nr_parent; i++) {
new_parent = lookup_commit(graft->parent[i].hash); new_parent = lookup_commit(&graft->parent[i]);
if (!new_parent) if (!new_parent)
continue; continue;
pptr = &commit_list_insert(new_parent, pptr)->next; pptr = &commit_list_insert(new_parent, pptr)->next;
@ -562,7 +562,7 @@ void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark)
for (i = 0; i < a->nr; i++) { for (i = 0; i < a->nr; i++) {
object = a->objects[i].item; object = a->objects[i].item;
commit = lookup_commit_reference_gently(object->oid.hash, 1); commit = lookup_commit_reference_gently(&object->oid, 1);
if (commit) if (commit)
clear_commit_marks(commit, mark); clear_commit_marks(commit, mark);
} }
@ -1589,7 +1589,7 @@ struct commit *get_merge_parent(const char *name)
struct object_id oid; struct object_id oid;
if (get_sha1(name, oid.hash)) if (get_sha1(name, oid.hash))
return NULL; return NULL;
obj = parse_object(oid.hash); obj = parse_object(&oid);
commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT); commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);
if (commit && !commit->util) if (commit && !commit->util)
set_merge_remote_desc(commit, name, obj); set_merge_remote_desc(commit, name, obj);

View File

@ -45,18 +45,18 @@ enum decoration_type {
void add_name_decoration(enum decoration_type type, const char *name, struct object *obj); void add_name_decoration(enum decoration_type type, const char *name, struct object *obj);
const struct name_decoration *get_name_decoration(const struct object *obj); const struct name_decoration *get_name_decoration(const struct object *obj);
struct commit *lookup_commit(const unsigned char *sha1); struct commit *lookup_commit(const struct object_id *oid);
struct commit *lookup_commit_reference(const unsigned char *sha1); struct commit *lookup_commit_reference(const struct object_id *oid);
struct commit *lookup_commit_reference_gently(const unsigned char *sha1, struct commit *lookup_commit_reference_gently(const struct object_id *oid,
int quiet); int quiet);
struct commit *lookup_commit_reference_by_name(const char *name); struct commit *lookup_commit_reference_by_name(const char *name);
/* /*
* Look up object named by "sha1", dereference tag as necessary, * Look up object named by "oid", dereference tag as necessary,
* get a commit and return it. If "sha1" does not dereference to * get a commit and return it. If "oid" does not dereference to
* a commit, use ref_name to report an error and die. * a commit, use ref_name to report an error and die.
*/ */
struct commit *lookup_commit_or_die(const unsigned char *sha1, const char *ref_name); struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name);
int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size); int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size);
int parse_commit_gently(struct commit *item, int quiet_on_missing); int parse_commit_gently(struct commit *item, int quiet_on_missing);
@ -263,8 +263,8 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n,
struct oid_array; struct oid_array;
struct ref; struct ref;
extern int register_shallow(const unsigned char *sha1); extern int register_shallow(const struct object_id *oid);
extern int unregister_shallow(const unsigned char *sha1); extern int unregister_shallow(const struct object_id *oid);
extern int for_each_commit_graft(each_commit_graft_fn, void *); extern int for_each_commit_graft(each_commit_graft_fn, void *);
extern int is_repository_shallow(void); extern int is_repository_shallow(void);
extern struct commit_list *get_shallow_commits(struct object_array *heads, extern struct commit_list *get_shallow_commits(struct object_array *heads,

View File

@ -478,7 +478,7 @@ static int oneway_diff(const struct cache_entry * const *src,
} }
static int diff_cache(struct rev_info *revs, static int diff_cache(struct rev_info *revs,
const unsigned char *tree_sha1, const struct object_id *tree_oid,
const char *tree_name, const char *tree_name,
int cached) int cached)
{ {
@ -486,10 +486,10 @@ static int diff_cache(struct rev_info *revs,
struct tree_desc t; struct tree_desc t;
struct unpack_trees_options opts; struct unpack_trees_options opts;
tree = parse_tree_indirect(tree_sha1); tree = parse_tree_indirect(tree_oid);
if (!tree) if (!tree)
return error("bad tree object %s", return error("bad tree object %s",
tree_name ? tree_name : sha1_to_hex(tree_sha1)); tree_name ? tree_name : oid_to_hex(tree_oid));
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
opts.head_idx = 1; opts.head_idx = 1;
opts.index_only = cached; opts.index_only = cached;
@ -512,7 +512,7 @@ int run_diff_index(struct rev_info *revs, int cached)
struct object_array_entry *ent; struct object_array_entry *ent;
ent = revs->pending.objects; ent = revs->pending.objects;
if (diff_cache(revs, ent->item->oid.hash, ent->name, cached)) if (diff_cache(revs, &ent->item->oid, ent->name, cached))
exit(128); exit(128);
diff_set_mnemonic_prefix(&revs->diffopt, "c/", cached ? "i/" : "w/"); diff_set_mnemonic_prefix(&revs->diffopt, "c/", cached ? "i/" : "w/");
@ -522,7 +522,7 @@ int run_diff_index(struct rev_info *revs, int cached)
return 0; return 0;
} }
int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt) int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt)
{ {
struct rev_info revs; struct rev_info revs;
@ -530,7 +530,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
copy_pathspec(&revs.prune_data, &opt->pathspec); copy_pathspec(&revs.prune_data, &opt->pathspec);
revs.diffopt = *opt; revs.diffopt = *opt;
if (diff_cache(&revs, tree_sha1, NULL, 1)) if (diff_cache(&revs, tree_oid, NULL, 1))
exit(128); exit(128);
return 0; return 0;
} }

4
diff.c
View File

@ -5244,7 +5244,7 @@ size_t fill_textconv(struct userdiff_driver *driver,
if (driver->textconv_cache && df->oid_valid) { if (driver->textconv_cache && df->oid_valid) {
*outbuf = notes_cache_get(driver->textconv_cache, *outbuf = notes_cache_get(driver->textconv_cache,
df->oid.hash, &df->oid,
&size); &size);
if (*outbuf) if (*outbuf)
return size; return size;
@ -5256,7 +5256,7 @@ size_t fill_textconv(struct userdiff_driver *driver,
if (driver->textconv_cache && df->oid_valid) { if (driver->textconv_cache && df->oid_valid) {
/* ignore errors, as we might be in a readonly repository */ /* ignore errors, as we might be in a readonly repository */
notes_cache_put(driver->textconv_cache, df->oid.hash, *outbuf, notes_cache_put(driver->textconv_cache, &df->oid, *outbuf,
size); size);
/* /*
* we could save up changes and flush them all at the end, * we could save up changes and flush them all at the end,

2
diff.h
View File

@ -354,7 +354,7 @@ extern const char *diff_aligned_abbrev(const struct object_id *sha1, int);
extern int run_diff_files(struct rev_info *revs, unsigned int option); extern int run_diff_files(struct rev_info *revs, unsigned int option);
extern int run_diff_index(struct rev_info *revs, int cached); extern int run_diff_index(struct rev_info *revs, int cached);
extern int do_diff_cache(const unsigned char *, struct diff_options *); extern int do_diff_cache(const struct object_id *, struct diff_options *);
extern int diff_flush_patch_id(struct diff_options *, unsigned char *, int); extern int diff_flush_patch_id(struct diff_options *, unsigned char *, int);
extern int diff_result_code(struct diff_options *, int); extern int diff_result_code(struct diff_options *, int);

File diff suppressed because it is too large Load Diff

View File

@ -78,7 +78,7 @@ static void cache_one_alternate(const char *refname,
void *vcache) void *vcache)
{ {
struct alternate_object_cache *cache = vcache; struct alternate_object_cache *cache = vcache;
struct object *obj = parse_object(oid->hash); struct object *obj = parse_object(oid);
if (!obj || (obj->flags & ALTERNATE)) if (!obj || (obj->flags & ALTERNATE))
return; return;
@ -118,9 +118,9 @@ static void rev_list_push(struct commit *commit, int mark)
} }
} }
static int rev_list_insert_ref(const char *refname, const unsigned char *sha1) static int rev_list_insert_ref(const char *refname, const struct object_id *oid)
{ {
struct object *o = deref_tag(parse_object(sha1), refname, 0); struct object *o = deref_tag(parse_object(oid), refname, 0);
if (o && o->type == OBJ_COMMIT) if (o && o->type == OBJ_COMMIT)
rev_list_push((struct commit *)o, SEEN); rev_list_push((struct commit *)o, SEEN);
@ -131,13 +131,13 @@ static int rev_list_insert_ref(const char *refname, const unsigned char *sha1)
static int rev_list_insert_ref_oid(const char *refname, const struct object_id *oid, static int rev_list_insert_ref_oid(const char *refname, const struct object_id *oid,
int flag, void *cb_data) int flag, void *cb_data)
{ {
return rev_list_insert_ref(refname, oid->hash); return rev_list_insert_ref(refname, oid);
} }
static int clear_marks(const char *refname, const struct object_id *oid, static int clear_marks(const char *refname, const struct object_id *oid,
int flag, void *cb_data) int flag, void *cb_data)
{ {
struct object *o = deref_tag(parse_object(oid->hash), refname, 0); struct object *o = deref_tag(parse_object(oid), refname, 0);
if (o && o->type == OBJ_COMMIT) if (o && o->type == OBJ_COMMIT)
clear_commit_marks((struct commit *)o, clear_commit_marks((struct commit *)o,
@ -183,7 +183,7 @@ static void mark_common(struct commit *commit,
Get the next rev to send, ignoring the common. Get the next rev to send, ignoring the common.
*/ */
static const unsigned char *get_rev(void) static const struct object_id *get_rev(void)
{ {
struct commit *commit = NULL; struct commit *commit = NULL;
@ -222,7 +222,7 @@ static const unsigned char *get_rev(void)
} }
} }
return commit->object.oid.hash; return &commit->object.oid;
} }
enum ack_type { enum ack_type {
@ -251,7 +251,7 @@ static void consume_shallow_list(struct fetch_pack_args *args, int fd)
} }
} }
static enum ack_type get_ack(int fd, unsigned char *result_sha1) static enum ack_type get_ack(int fd, struct object_id *result_oid)
{ {
int len; int len;
char *line = packet_read_line(fd, &len); char *line = packet_read_line(fd, &len);
@ -262,7 +262,7 @@ static enum ack_type get_ack(int fd, unsigned char *result_sha1)
if (!strcmp(line, "NAK")) if (!strcmp(line, "NAK"))
return NAK; return NAK;
if (skip_prefix(line, "ACK ", &arg)) { if (skip_prefix(line, "ACK ", &arg)) {
if (!get_sha1_hex(arg, result_sha1)) { if (!get_oid_hex(arg, result_oid)) {
arg += 40; arg += 40;
len -= arg - line; len -= arg - line;
if (len < 1) if (len < 1)
@ -293,7 +293,7 @@ static void send_request(struct fetch_pack_args *args,
static void insert_one_alternate_object(struct object *obj) static void insert_one_alternate_object(struct object *obj)
{ {
rev_list_insert_ref(NULL, obj->oid.hash); rev_list_insert_ref(NULL, &obj->oid);
} }
#define INITIAL_FLUSH 16 #define INITIAL_FLUSH 16
@ -317,12 +317,12 @@ static int next_flush(struct fetch_pack_args *args, int count)
} }
static int find_common(struct fetch_pack_args *args, static int find_common(struct fetch_pack_args *args,
int fd[2], unsigned char *result_sha1, int fd[2], struct object_id *result_oid,
struct ref *refs) struct ref *refs)
{ {
int fetching; int fetching;
int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval; int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval;
const unsigned char *sha1; const struct object_id *oid;
unsigned in_vain = 0; unsigned in_vain = 0;
int got_continue = 0; int got_continue = 0;
int got_ready = 0; int got_ready = 0;
@ -340,7 +340,7 @@ static int find_common(struct fetch_pack_args *args,
fetching = 0; fetching = 0;
for ( ; refs ; refs = refs->next) { for ( ; refs ; refs = refs->next) {
unsigned char *remote = refs->old_oid.hash; struct object_id *remote = &refs->old_oid;
const char *remote_hex; const char *remote_hex;
struct object *o; struct object *o;
@ -354,12 +354,12 @@ static int find_common(struct fetch_pack_args *args,
* interested in the case we *know* the object is * interested in the case we *know* the object is
* reachable and we have already scanned it. * reachable and we have already scanned it.
*/ */
if (((o = lookup_object(remote)) != NULL) && if (((o = lookup_object(remote->hash)) != NULL) &&
(o->flags & COMPLETE)) { (o->flags & COMPLETE)) {
continue; continue;
} }
remote_hex = sha1_to_hex(remote); remote_hex = oid_to_hex(remote);
if (!fetching) { if (!fetching) {
struct strbuf c = STRBUF_INIT; struct strbuf c = STRBUF_INIT;
if (multi_ack == 2) strbuf_addstr(&c, " multi_ack_detailed"); if (multi_ack == 2) strbuf_addstr(&c, " multi_ack_detailed");
@ -410,25 +410,25 @@ static int find_common(struct fetch_pack_args *args,
if (args->deepen) { if (args->deepen) {
char *line; char *line;
const char *arg; const char *arg;
unsigned char sha1[20]; struct object_id oid;
send_request(args, fd[1], &req_buf); send_request(args, fd[1], &req_buf);
while ((line = packet_read_line(fd[0], NULL))) { while ((line = packet_read_line(fd[0], NULL))) {
if (skip_prefix(line, "shallow ", &arg)) { if (skip_prefix(line, "shallow ", &arg)) {
if (get_sha1_hex(arg, sha1)) if (get_oid_hex(arg, &oid))
die(_("invalid shallow line: %s"), line); die(_("invalid shallow line: %s"), line);
register_shallow(sha1); register_shallow(&oid);
continue; continue;
} }
if (skip_prefix(line, "unshallow ", &arg)) { if (skip_prefix(line, "unshallow ", &arg)) {
if (get_sha1_hex(arg, sha1)) if (get_oid_hex(arg, &oid))
die(_("invalid unshallow line: %s"), line); die(_("invalid unshallow line: %s"), line);
if (!lookup_object(sha1)) if (!lookup_object(oid.hash))
die(_("object not found: %s"), line); die(_("object not found: %s"), line);
/* make sure that it is parsed as shallow */ /* make sure that it is parsed as shallow */
if (!parse_object(sha1)) if (!parse_object(&oid))
die(_("error in object: %s"), line); die(_("error in object: %s"), line);
if (unregister_shallow(sha1)) if (unregister_shallow(&oid))
die(_("no shallow found: %s"), line); die(_("no shallow found: %s"), line);
continue; continue;
} }
@ -447,9 +447,9 @@ static int find_common(struct fetch_pack_args *args,
flushes = 0; flushes = 0;
retval = -1; retval = -1;
while ((sha1 = get_rev())) { while ((oid = get_rev())) {
packet_buf_write(&req_buf, "have %s\n", sha1_to_hex(sha1)); packet_buf_write(&req_buf, "have %s\n", oid_to_hex(oid));
print_verbose(args, "have %s", sha1_to_hex(sha1)); print_verbose(args, "have %s", oid_to_hex(oid));
in_vain++; in_vain++;
if (flush_at <= ++count) { if (flush_at <= ++count) {
int ack; int ack;
@ -469,10 +469,10 @@ static int find_common(struct fetch_pack_args *args,
consume_shallow_list(args, fd[0]); consume_shallow_list(args, fd[0]);
do { do {
ack = get_ack(fd[0], result_sha1); ack = get_ack(fd[0], result_oid);
if (ack) if (ack)
print_verbose(args, _("got %s %d %s"), "ack", print_verbose(args, _("got %s %d %s"), "ack",
ack, sha1_to_hex(result_sha1)); ack, oid_to_hex(result_oid));
switch (ack) { switch (ack) {
case ACK: case ACK:
flushes = 0; flushes = 0;
@ -483,9 +483,9 @@ static int find_common(struct fetch_pack_args *args,
case ACK_ready: case ACK_ready:
case ACK_continue: { case ACK_continue: {
struct commit *commit = struct commit *commit =
lookup_commit(result_sha1); lookup_commit(result_oid);
if (!commit) if (!commit)
die(_("invalid commit %s"), sha1_to_hex(result_sha1)); die(_("invalid commit %s"), oid_to_hex(result_oid));
if (args->stateless_rpc if (args->stateless_rpc
&& ack == ACK_common && ack == ACK_common
&& !(commit->object.flags & COMMON)) { && !(commit->object.flags & COMMON)) {
@ -493,7 +493,7 @@ static int find_common(struct fetch_pack_args *args,
* on the next RPC request so the peer knows * on the next RPC request so the peer knows
* it is in common with us. * it is in common with us.
*/ */
const char *hex = sha1_to_hex(result_sha1); const char *hex = oid_to_hex(result_oid);
packet_buf_write(&req_buf, "have %s\n", hex); packet_buf_write(&req_buf, "have %s\n", hex);
state_len = req_buf.len; state_len = req_buf.len;
/* /*
@ -538,10 +538,10 @@ done:
if (!got_ready || !no_done) if (!got_ready || !no_done)
consume_shallow_list(args, fd[0]); consume_shallow_list(args, fd[0]);
while (flushes || multi_ack) { while (flushes || multi_ack) {
int ack = get_ack(fd[0], result_sha1); int ack = get_ack(fd[0], result_oid);
if (ack) { if (ack) {
print_verbose(args, _("got %s (%d) %s"), "ack", print_verbose(args, _("got %s (%d) %s"), "ack",
ack, sha1_to_hex(result_sha1)); ack, oid_to_hex(result_oid));
if (ack == ACK) if (ack == ACK)
return 0; return 0;
multi_ack = 1; multi_ack = 1;
@ -555,16 +555,16 @@ done:
static struct commit_list *complete; static struct commit_list *complete;
static int mark_complete(const unsigned char *sha1) static int mark_complete(const struct object_id *oid)
{ {
struct object *o = parse_object(sha1); struct object *o = parse_object(oid);
while (o && o->type == OBJ_TAG) { while (o && o->type == OBJ_TAG) {
struct tag *t = (struct tag *) o; struct tag *t = (struct tag *) o;
if (!t->tagged) if (!t->tagged)
break; /* broken repository */ break; /* broken repository */
o->flags |= COMPLETE; o->flags |= COMPLETE;
o = parse_object(t->tagged->oid.hash); o = parse_object(&t->tagged->oid);
} }
if (o && o->type == OBJ_COMMIT) { if (o && o->type == OBJ_COMMIT) {
struct commit *commit = (struct commit *)o; struct commit *commit = (struct commit *)o;
@ -579,7 +579,7 @@ static int mark_complete(const unsigned char *sha1)
static int mark_complete_oid(const char *refname, const struct object_id *oid, static int mark_complete_oid(const char *refname, const struct object_id *oid,
int flag, void *cb_data) int flag, void *cb_data)
{ {
return mark_complete(oid->hash); return mark_complete(oid);
} }
static void mark_recent_complete_commits(struct fetch_pack_args *args, static void mark_recent_complete_commits(struct fetch_pack_args *args,
@ -637,14 +637,15 @@ static void filter_refs(struct fetch_pack_args *args,
/* Append unmatched requests to the list */ /* Append unmatched requests to the list */
for (i = 0; i < nr_sought; i++) { for (i = 0; i < nr_sought; i++) {
unsigned char sha1[20]; struct object_id oid;
const char *p;
ref = sought[i]; ref = sought[i];
if (ref->match_status != REF_NOT_MATCHED) if (ref->match_status != REF_NOT_MATCHED)
continue; continue;
if (get_sha1_hex(ref->name, sha1) || if (parse_oid_hex(ref->name, &oid, &p) ||
ref->name[40] != '\0' || *p != '\0' ||
hashcmp(sha1, ref->old_oid.hash)) oidcmp(&oid, &ref->old_oid))
continue; continue;
if ((allow_unadvertised_object_request & if ((allow_unadvertised_object_request &
@ -661,7 +662,7 @@ static void filter_refs(struct fetch_pack_args *args,
static void mark_alternate_complete(struct object *obj) static void mark_alternate_complete(struct object *obj)
{ {
mark_complete(obj->oid.hash); mark_complete(&obj->oid);
} }
static int everything_local(struct fetch_pack_args *args, static int everything_local(struct fetch_pack_args *args,
@ -680,7 +681,7 @@ static int everything_local(struct fetch_pack_args *args,
if (!has_object_file(&ref->old_oid)) if (!has_object_file(&ref->old_oid))
continue; continue;
o = parse_object(ref->old_oid.hash); o = parse_object(&ref->old_oid);
if (!o) if (!o)
continue; continue;
@ -724,17 +725,17 @@ static int everything_local(struct fetch_pack_args *args,
filter_refs(args, refs, sought, nr_sought); filter_refs(args, refs, sought, nr_sought);
for (retval = 1, ref = *refs; ref ; ref = ref->next) { for (retval = 1, ref = *refs; ref ; ref = ref->next) {
const unsigned char *remote = ref->old_oid.hash; const struct object_id *remote = &ref->old_oid;
struct object *o; struct object *o;
o = lookup_object(remote); o = lookup_object(remote->hash);
if (!o || !(o->flags & COMPLETE)) { if (!o || !(o->flags & COMPLETE)) {
retval = 0; retval = 0;
print_verbose(args, "want %s (%s)", sha1_to_hex(remote), print_verbose(args, "want %s (%s)", oid_to_hex(remote),
ref->name); ref->name);
continue; continue;
} }
print_verbose(args, _("already have %s (%s)"), sha1_to_hex(remote), print_verbose(args, _("already have %s (%s)"), oid_to_hex(remote),
ref->name); ref->name);
} }
return retval; return retval;
@ -873,7 +874,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
char **pack_lockfile) char **pack_lockfile)
{ {
struct ref *ref = copy_ref_list(orig_ref); struct ref *ref = copy_ref_list(orig_ref);
unsigned char sha1[20]; struct object_id oid;
const char *agent_feature; const char *agent_feature;
int agent_len; int agent_len;
@ -945,7 +946,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
packet_flush(fd[1]); packet_flush(fd[1]);
goto all_done; goto all_done;
} }
if (find_common(args, fd, sha1, ref) < 0) if (find_common(args, fd, &oid, ref) < 0)
if (!args->keep_pack) if (!args->keep_pack)
/* When cloning, it is not unusual to have /* When cloning, it is not unusual to have
* no common commit. * no common commit.

6
fsck.c
View File

@ -358,14 +358,14 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
continue; continue;
if (S_ISDIR(entry.mode)) { if (S_ISDIR(entry.mode)) {
obj = &lookup_tree(entry.oid->hash)->object; obj = &lookup_tree(entry.oid)->object;
if (name) if (name)
put_object_name(options, obj, "%s%s/", name, put_object_name(options, obj, "%s%s/", name,
entry.path); entry.path);
result = options->walk(obj, OBJ_TREE, data, options); result = options->walk(obj, OBJ_TREE, data, options);
} }
else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) { else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) {
obj = &lookup_blob(entry.oid->hash)->object; obj = &lookup_blob(entry.oid)->object;
if (name) if (name)
put_object_name(options, obj, "%s%s", name, put_object_name(options, obj, "%s%s", name,
entry.path); entry.path);
@ -461,7 +461,7 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options)
return -1; return -1;
if (obj->type == OBJ_NONE) if (obj->type == OBJ_NONE)
parse_object(obj->oid.hash); parse_object(&obj->oid);
switch (obj->type) { switch (obj->type) {
case OBJ_BLOB: case OBJ_BLOB:

View File

@ -431,7 +431,7 @@ static int show_text_ref(const char *name, const struct object_id *oid,
{ {
const char *name_nons = strip_namespace(name); const char *name_nons = strip_namespace(name);
struct strbuf *buf = cb_data; struct strbuf *buf = cb_data;
struct object *o = parse_object(oid->hash); struct object *o = parse_object(oid);
if (!o) if (!o)
return 0; return 0;

View File

@ -718,13 +718,13 @@ static int fetch_indices(void)
return ret; return ret;
} }
static void one_remote_object(const unsigned char *sha1) static void one_remote_object(const struct object_id *oid)
{ {
struct object *obj; struct object *obj;
obj = lookup_object(sha1); obj = lookup_object(oid->hash);
if (!obj) if (!obj)
obj = parse_object(sha1); obj = parse_object(oid);
/* Ignore remote objects that don't exist locally */ /* Ignore remote objects that don't exist locally */
if (!obj) if (!obj)
@ -1013,26 +1013,26 @@ static void remote_ls(const char *path, int flags,
void *userData); void *userData);
/* extract hex from sharded "xx/x{40}" filename */ /* extract hex from sharded "xx/x{40}" filename */
static int get_sha1_hex_from_objpath(const char *path, unsigned char *sha1) static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
{ {
char hex[40]; char hex[GIT_MAX_HEXSZ];
if (strlen(path) != 41) if (strlen(path) != GIT_SHA1_HEXSZ + 1)
return -1; return -1;
memcpy(hex, path, 2); memcpy(hex, path, 2);
path += 2; path += 2;
path++; /* skip '/' */ path++; /* skip '/' */
memcpy(hex, path, 38); memcpy(hex, path, GIT_SHA1_HEXSZ - 2);
return get_sha1_hex(hex, sha1); return get_oid_hex(hex, oid);
} }
static void process_ls_object(struct remote_ls_ctx *ls) static void process_ls_object(struct remote_ls_ctx *ls)
{ {
unsigned int *parent = (unsigned int *)ls->userData; unsigned int *parent = (unsigned int *)ls->userData;
const char *path = ls->dentry_name; const char *path = ls->dentry_name;
unsigned char sha1[20]; struct object_id oid;
if (!strcmp(ls->path, ls->dentry_name) && (ls->flags & IS_DIR)) { if (!strcmp(ls->path, ls->dentry_name) && (ls->flags & IS_DIR)) {
remote_dir_exists[*parent] = 1; remote_dir_exists[*parent] = 1;
@ -1040,10 +1040,10 @@ static void process_ls_object(struct remote_ls_ctx *ls)
} }
if (!skip_prefix(path, "objects/", &path) || if (!skip_prefix(path, "objects/", &path) ||
get_sha1_hex_from_objpath(path, sha1)) get_oid_hex_from_objpath(path, &oid))
return; return;
one_remote_object(sha1); one_remote_object(&oid);
} }
static void process_ls_ref(struct remote_ls_ctx *ls) static void process_ls_ref(struct remote_ls_ctx *ls)
@ -1312,10 +1312,10 @@ static struct object_list **process_tree(struct tree *tree,
while (tree_entry(&desc, &entry)) while (tree_entry(&desc, &entry))
switch (object_type(entry.mode)) { switch (object_type(entry.mode)) {
case OBJ_TREE: case OBJ_TREE:
p = process_tree(lookup_tree(entry.oid->hash), p); p = process_tree(lookup_tree(entry.oid), p);
break; break;
case OBJ_BLOB: case OBJ_BLOB:
p = process_blob(lookup_blob(entry.oid->hash), p); p = process_blob(lookup_blob(entry.oid), p);
break; break;
default: default:
/* Subproject commit - not in this repository */ /* Subproject commit - not in this repository */
@ -1462,7 +1462,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
return; return;
} }
o = parse_object(ref->old_oid.hash); o = parse_object(&ref->old_oid);
if (!o) { if (!o) {
fprintf(stderr, fprintf(stderr,
"Unable to parse object %s for remote ref %s\n", "Unable to parse object %s for remote ref %s\n",
@ -1536,7 +1536,7 @@ static int remote_exists(const char *path)
return ret; return ret;
} }
static void fetch_symref(const char *path, char **symref, unsigned char *sha1) static void fetch_symref(const char *path, char **symref, struct object_id *oid)
{ {
char *url = xstrfmt("%s%s", repo->url, path); char *url = xstrfmt("%s%s", repo->url, path);
struct strbuf buffer = STRBUF_INIT; struct strbuf buffer = STRBUF_INIT;
@ -1549,7 +1549,7 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
free(*symref); free(*symref);
*symref = NULL; *symref = NULL;
hashclr(sha1); oidclr(oid);
if (buffer.len == 0) if (buffer.len == 0)
return; return;
@ -1561,16 +1561,17 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
if (skip_prefix(buffer.buf, "ref: ", &name)) { if (skip_prefix(buffer.buf, "ref: ", &name)) {
*symref = xmemdupz(name, buffer.len - (name - buffer.buf)); *symref = xmemdupz(name, buffer.len - (name - buffer.buf));
} else { } else {
get_sha1_hex(buffer.buf, sha1); get_oid_hex(buffer.buf, oid);
} }
strbuf_release(&buffer); strbuf_release(&buffer);
} }
static int verify_merge_base(unsigned char *head_sha1, struct ref *remote) static int verify_merge_base(struct object_id *head_oid, struct ref *remote)
{ {
struct commit *head = lookup_commit_or_die(head_sha1, "HEAD"); struct commit *head = lookup_commit_or_die(head_oid, "HEAD");
struct commit *branch = lookup_commit_or_die(remote->old_oid.hash, remote->name); struct commit *branch = lookup_commit_or_die(&remote->old_oid,
remote->name);
return in_merge_bases(branch, head); return in_merge_bases(branch, head);
} }
@ -1579,7 +1580,7 @@ static int delete_remote_branch(const char *pattern, int force)
{ {
struct ref *refs = remote_refs; struct ref *refs = remote_refs;
struct ref *remote_ref = NULL; struct ref *remote_ref = NULL;
unsigned char head_sha1[20]; struct object_id head_oid;
char *symref = NULL; char *symref = NULL;
int match; int match;
int patlen = strlen(pattern); int patlen = strlen(pattern);
@ -1610,7 +1611,7 @@ static int delete_remote_branch(const char *pattern, int force)
* Remote HEAD must be a symref (not exactly foolproof; a remote * Remote HEAD must be a symref (not exactly foolproof; a remote
* symlink to a symref will look like a symref) * symlink to a symref will look like a symref)
*/ */
fetch_symref("HEAD", &symref, head_sha1); fetch_symref("HEAD", &symref, &head_oid);
if (!symref) if (!symref)
return error("Remote HEAD is not a symref"); return error("Remote HEAD is not a symref");
@ -1619,7 +1620,7 @@ static int delete_remote_branch(const char *pattern, int force)
if (!strcmp(remote_ref->name, symref)) if (!strcmp(remote_ref->name, symref))
return error("Remote branch %s is the current HEAD", return error("Remote branch %s is the current HEAD",
remote_ref->name); remote_ref->name);
fetch_symref(symref, &symref, head_sha1); fetch_symref(symref, &symref, &head_oid);
} }
/* Run extra sanity checks if delete is not forced */ /* Run extra sanity checks if delete is not forced */
@ -1627,10 +1628,10 @@ static int delete_remote_branch(const char *pattern, int force)
/* Remote HEAD must resolve to a known object */ /* Remote HEAD must resolve to a known object */
if (symref) if (symref)
return error("Remote HEAD symrefs too deep"); return error("Remote HEAD symrefs too deep");
if (is_null_sha1(head_sha1)) if (is_null_oid(&head_oid))
return error("Unable to resolve remote HEAD"); return error("Unable to resolve remote HEAD");
if (!has_sha1_file(head_sha1)) if (!has_object_file(&head_oid))
return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", sha1_to_hex(head_sha1)); return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", oid_to_hex(&head_oid));
/* Remote branch must resolve to a known object */ /* Remote branch must resolve to a known object */
if (is_null_oid(&remote_ref->old_oid)) if (is_null_oid(&remote_ref->old_oid))
@ -1640,7 +1641,7 @@ static int delete_remote_branch(const char *pattern, int force)
return error("Remote branch %s resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", remote_ref->name, oid_to_hex(&remote_ref->old_oid)); return error("Remote branch %s resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", remote_ref->name, oid_to_hex(&remote_ref->old_oid));
/* Remote branch must be an ancestor of remote HEAD */ /* Remote branch must be an ancestor of remote HEAD */
if (!verify_merge_base(head_sha1, remote_ref)) { if (!verify_merge_base(&head_oid, remote_ref)) {
return error("The branch '%s' is not an ancestor " return error("The branch '%s' is not an ancestor "
"of your current HEAD.\n" "of your current HEAD.\n"
"If you are sure you want to delete it," "If you are sure you want to delete it,"

View File

@ -110,7 +110,7 @@ static void process_tree(struct rev_info *revs,
if (S_ISDIR(entry.mode)) if (S_ISDIR(entry.mode))
process_tree(revs, process_tree(revs,
lookup_tree(entry.oid->hash), lookup_tree(entry.oid),
show, base, entry.path, show, base, entry.path,
cb_data); cb_data);
else if (S_ISGITLINK(entry.mode)) else if (S_ISGITLINK(entry.mode))
@ -119,7 +119,7 @@ static void process_tree(struct rev_info *revs,
cb_data); cb_data);
else else
process_blob(revs, process_blob(revs,
lookup_blob(entry.oid->hash), lookup_blob(entry.oid),
show, base, entry.path, show, base, entry.path,
cb_data); cb_data);
} }

View File

@ -105,13 +105,13 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
warning("invalid replace ref %s", refname); warning("invalid replace ref %s", refname);
return 0; return 0;
} }
obj = parse_object(original_oid.hash); obj = parse_object(&original_oid);
if (obj) if (obj)
add_name_decoration(DECORATION_GRAFTED, "replaced", obj); add_name_decoration(DECORATION_GRAFTED, "replaced", obj);
return 0; return 0;
} }
obj = parse_object(oid->hash); obj = parse_object(oid);
if (!obj) if (!obj)
return 0; return 0;
@ -132,7 +132,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
if (!obj) if (!obj)
break; break;
if (!obj->parsed) if (!obj->parsed)
parse_object(obj->oid.hash); parse_object(&obj->oid);
add_name_decoration(DECORATION_REF_TAG, refname, obj); add_name_decoration(DECORATION_REF_TAG, refname, obj);
} }
return 0; return 0;
@ -140,7 +140,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
static int add_graft_decoration(const struct commit_graft *graft, void *cb_data) static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
{ {
struct commit *commit = lookup_commit(graft->oid.hash); struct commit *commit = lookup_commit(&graft->oid);
if (!commit) if (!commit)
return 0; return 0;
add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object); add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object);
@ -184,7 +184,7 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
{ {
const struct name_decoration *list, *head = NULL; const struct name_decoration *list, *head = NULL;
const char *branch_name = NULL; const char *branch_name = NULL;
unsigned char unused[20]; struct object_id unused;
int rru_flags; int rru_flags;
/* First find HEAD */ /* First find HEAD */
@ -197,7 +197,7 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
return NULL; return NULL;
/* Now resolve and find the matching current branch */ /* Now resolve and find the matching current branch */
branch_name = resolve_ref_unsafe("HEAD", 0, unused, &rru_flags); branch_name = resolve_ref_unsafe("HEAD", 0, unused.hash, &rru_flags);
if (!(rru_flags & REF_ISSYMREF)) if (!(rru_flags & REF_ISSYMREF))
return NULL; return NULL;
@ -456,13 +456,13 @@ static void show_signature(struct rev_info *opt, struct commit *commit)
strbuf_release(&signature); strbuf_release(&signature);
} }
static int which_parent(const unsigned char *sha1, const struct commit *commit) static int which_parent(const struct object_id *oid, const struct commit *commit)
{ {
int nth; int nth;
const struct commit_list *parent; const struct commit_list *parent;
for (nth = 0, parent = commit->parents; parent; parent = parent->next) { for (nth = 0, parent = commit->parents; parent; parent = parent->next) {
if (!hashcmp(parent->item->object.oid.hash, sha1)) if (!oidcmp(&parent->item->object.oid, oid))
return nth; return nth;
nth++; nth++;
} }
@ -481,14 +481,14 @@ static void show_one_mergetag(struct commit *commit,
void *data) void *data)
{ {
struct rev_info *opt = (struct rev_info *)data; struct rev_info *opt = (struct rev_info *)data;
unsigned char sha1[20]; struct object_id oid;
struct tag *tag; struct tag *tag;
struct strbuf verify_message; struct strbuf verify_message;
int status, nth; int status, nth;
size_t payload_size, gpg_message_offset; size_t payload_size, gpg_message_offset;
hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), sha1); hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), oid.hash);
tag = lookup_tag(sha1); tag = lookup_tag(&oid);
if (!tag) if (!tag)
return; /* error message already given */ return; /* error message already given */
@ -500,7 +500,7 @@ static void show_one_mergetag(struct commit *commit,
&commit->parents->next->item->object.oid)) &commit->parents->next->item->object.oid))
strbuf_addf(&verify_message, strbuf_addf(&verify_message,
"merged tag '%s'\n", tag->tag); "merged tag '%s'\n", tag->tag);
else if ((nth = which_parent(tag->tagged->oid.hash, commit)) < 0) else if ((nth = which_parent(&tag->tagged->oid, commit)) < 0)
strbuf_addf(&verify_message, "tag %s names a non-parent %s\n", strbuf_addf(&verify_message, "tag %s names a non-parent %s\n",
tag->tag, tag->tagged->oid.hash); tag->tag, tag->tagged->oid.hash);
else else
@ -536,7 +536,7 @@ void show_log(struct rev_info *opt)
struct strbuf msgbuf = STRBUF_INIT; struct strbuf msgbuf = STRBUF_INIT;
struct log_info *log = opt->loginfo; struct log_info *log = opt->loginfo;
struct commit *commit = log->commit, *parent = log->parent; struct commit *commit = log->commit, *parent = log->parent;
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40; int abbrev_commit = opt->abbrev_commit ? opt->abbrev : GIT_SHA1_HEXSZ;
const char *extra_headers = opt->extra_headers; const char *extra_headers = opt->extra_headers;
struct pretty_print_context ctx = {0}; struct pretty_print_context ctx = {0};

View File

@ -67,7 +67,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
} }
if (!oidcmp(&two->object.oid, &shifted)) if (!oidcmp(&two->object.oid, &shifted))
return two; return two;
return lookup_tree(shifted.hash); return lookup_tree(&shifted);
} }
static struct commit *make_virtual_commit(struct tree *tree, const char *comment) static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
@ -304,7 +304,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
return NULL; return NULL;
} }
result = lookup_tree(active_cache_tree->sha1); result = lookup_tree(&active_cache_tree->oid);
return result; return result;
} }
@ -994,11 +994,11 @@ static int merge_file_1(struct merge_options *o,
return ret; return ret;
result->clean = (merge_status == 0); result->clean = (merge_status == 0);
} else if (S_ISGITLINK(a->mode)) { } else if (S_ISGITLINK(a->mode)) {
result->clean = merge_submodule(result->oid.hash, result->clean = merge_submodule(&result->oid,
one->path, one->path,
one->oid.hash, &one->oid,
a->oid.hash, &a->oid,
b->oid.hash, &b->oid,
!o->call_depth); !o->call_depth);
} else if (S_ISLNK(a->mode)) { } else if (S_ISLNK(a->mode)) {
oidcpy(&result->oid, &a->oid); oidcpy(&result->oid, &a->oid);
@ -2042,7 +2042,7 @@ int merge_recursive(struct merge_options *o,
/* if there is no common ancestor, use an empty tree */ /* if there is no common ancestor, use an empty tree */
struct tree *tree; struct tree *tree;
tree = lookup_tree(EMPTY_TREE_SHA1_BIN); tree = lookup_tree(&empty_tree_oid);
merged_common_ancestors = make_virtual_commit(tree, "ancestor"); merged_common_ancestors = make_virtual_commit(tree, "ancestor");
} }
@ -2103,7 +2103,7 @@ static struct commit *get_ref(const struct object_id *oid, const char *name)
{ {
struct object *object; struct object *object;
object = deref_tag(parse_object(oid->hash), name, strlen(name)); object = deref_tag(parse_object(oid), name, strlen(name));
if (!object) if (!object)
return NULL; return NULL;
if (object->type == OBJ_TREE) if (object->type == OBJ_TREE)

View File

@ -44,8 +44,8 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
return ret; return ret;
} }
int checkout_fast_forward(const unsigned char *head, int checkout_fast_forward(const struct object_id *head,
const unsigned char *remote, const struct object_id *remote,
int overwrite_ignore) int overwrite_ignore)
{ {
struct tree *trees[MAX_UNPACK_TREES]; struct tree *trees[MAX_UNPACK_TREES];

View File

@ -5,16 +5,16 @@
static int notes_cache_match_validity(const char *ref, const char *validity) static int notes_cache_match_validity(const char *ref, const char *validity)
{ {
unsigned char sha1[20]; struct object_id oid;
struct commit *commit; struct commit *commit;
struct pretty_print_context pretty_ctx; struct pretty_print_context pretty_ctx;
struct strbuf msg = STRBUF_INIT; struct strbuf msg = STRBUF_INIT;
int ret; int ret;
if (read_ref(ref, sha1) < 0) if (read_ref(ref, oid.hash) < 0)
return 0; return 0;
commit = lookup_commit_reference_gently(sha1, 1); commit = lookup_commit_reference_gently(&oid, 1);
if (!commit) if (!commit)
return 0; return 0;
@ -46,8 +46,7 @@ void notes_cache_init(struct notes_cache *c, const char *name,
int notes_cache_write(struct notes_cache *c) int notes_cache_write(struct notes_cache *c)
{ {
unsigned char tree_sha1[20]; struct object_id tree_oid, commit_oid;
unsigned char commit_sha1[20];
if (!c || !c->tree.initialized || !c->tree.update_ref || if (!c || !c->tree.initialized || !c->tree.update_ref ||
!*c->tree.update_ref) !*c->tree.update_ref)
@ -55,19 +54,19 @@ int notes_cache_write(struct notes_cache *c)
if (!c->tree.dirty) if (!c->tree.dirty)
return 0; return 0;
if (write_notes_tree(&c->tree, tree_sha1)) if (write_notes_tree(&c->tree, tree_oid.hash))
return -1; return -1;
if (commit_tree(c->validity, strlen(c->validity), tree_sha1, NULL, if (commit_tree(c->validity, strlen(c->validity), tree_oid.hash, NULL,
commit_sha1, NULL, NULL) < 0) commit_oid.hash, NULL, NULL) < 0)
return -1; return -1;
if (update_ref("update notes cache", c->tree.update_ref, commit_sha1, if (update_ref("update notes cache", c->tree.update_ref, commit_oid.hash,
NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0) NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0)
return -1; return -1;
return 0; return 0;
} }
char *notes_cache_get(struct notes_cache *c, unsigned char key_sha1[20], char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
size_t *outsize) size_t *outsize)
{ {
const unsigned char *value_sha1; const unsigned char *value_sha1;
@ -75,7 +74,7 @@ char *notes_cache_get(struct notes_cache *c, unsigned char key_sha1[20],
char *value; char *value;
unsigned long size; unsigned long size;
value_sha1 = get_note(&c->tree, key_sha1); value_sha1 = get_note(&c->tree, key_oid->hash);
if (!value_sha1) if (!value_sha1)
return NULL; return NULL;
value = read_sha1_file(value_sha1, &type, &size); value = read_sha1_file(value_sha1, &type, &size);
@ -84,12 +83,12 @@ char *notes_cache_get(struct notes_cache *c, unsigned char key_sha1[20],
return value; return value;
} }
int notes_cache_put(struct notes_cache *c, unsigned char key_sha1[20], int notes_cache_put(struct notes_cache *c, struct object_id *key_oid,
const char *data, size_t size) const char *data, size_t size)
{ {
unsigned char value_sha1[20]; struct object_id value_oid;
if (write_sha1_file(data, size, "blob", value_sha1) < 0) if (write_sha1_file(data, size, "blob", value_oid.hash) < 0)
return -1; return -1;
return add_note(&c->tree, key_sha1, value_sha1, NULL); return add_note(&c->tree, key_oid->hash, value_oid.hash, NULL);
} }

View File

@ -12,9 +12,9 @@ void notes_cache_init(struct notes_cache *c, const char *name,
const char *validity); const char *validity);
int notes_cache_write(struct notes_cache *c); int notes_cache_write(struct notes_cache *c);
char *notes_cache_get(struct notes_cache *c, unsigned char sha1[20], size_t char *notes_cache_get(struct notes_cache *c, struct object_id *oid, size_t
*outsize); *outsize);
int notes_cache_put(struct notes_cache *c, unsigned char sha1[20], int notes_cache_put(struct notes_cache *c, struct object_id *oid,
const char *data, size_t size); const char *data, size_t size);
#endif /* NOTES_CACHE_H */ #endif /* NOTES_CACHE_H */

View File

@ -535,7 +535,7 @@ int notes_merge(struct notes_merge_options *o,
struct notes_tree *local_tree, struct notes_tree *local_tree,
unsigned char *result_sha1) unsigned char *result_sha1)
{ {
unsigned char local_sha1[20], remote_sha1[20]; struct object_id local_oid, remote_oid;
struct commit *local, *remote; struct commit *local, *remote;
struct commit_list *bases = NULL; struct commit_list *bases = NULL;
const unsigned char *base_sha1, *base_tree_sha1; const unsigned char *base_sha1, *base_tree_sha1;
@ -549,46 +549,46 @@ int notes_merge(struct notes_merge_options *o,
o->local_ref, o->remote_ref); o->local_ref, o->remote_ref);
/* Dereference o->local_ref into local_sha1 */ /* Dereference o->local_ref into local_sha1 */
if (read_ref_full(o->local_ref, 0, local_sha1, NULL)) if (read_ref_full(o->local_ref, 0, local_oid.hash, NULL))
die("Failed to resolve local notes ref '%s'", o->local_ref); die("Failed to resolve local notes ref '%s'", o->local_ref);
else if (!check_refname_format(o->local_ref, 0) && else if (!check_refname_format(o->local_ref, 0) &&
is_null_sha1(local_sha1)) is_null_oid(&local_oid))
local = NULL; /* local_sha1 == null_sha1 indicates unborn ref */ local = NULL; /* local_sha1 == null_sha1 indicates unborn ref */
else if (!(local = lookup_commit_reference(local_sha1))) else if (!(local = lookup_commit_reference(&local_oid)))
die("Could not parse local commit %s (%s)", die("Could not parse local commit %s (%s)",
sha1_to_hex(local_sha1), o->local_ref); oid_to_hex(&local_oid), o->local_ref);
trace_printf("\tlocal commit: %.7s\n", sha1_to_hex(local_sha1)); trace_printf("\tlocal commit: %.7s\n", oid_to_hex(&local_oid));
/* Dereference o->remote_ref into remote_sha1 */ /* Dereference o->remote_ref into remote_sha1 */
if (get_sha1(o->remote_ref, remote_sha1)) { if (get_oid(o->remote_ref, &remote_oid)) {
/* /*
* Failed to get remote_sha1. If o->remote_ref looks like an * Failed to get remote_sha1. If o->remote_ref looks like an
* unborn ref, perform the merge using an empty notes tree. * unborn ref, perform the merge using an empty notes tree.
*/ */
if (!check_refname_format(o->remote_ref, 0)) { if (!check_refname_format(o->remote_ref, 0)) {
hashclr(remote_sha1); oidclr(&remote_oid);
remote = NULL; remote = NULL;
} else { } else {
die("Failed to resolve remote notes ref '%s'", die("Failed to resolve remote notes ref '%s'",
o->remote_ref); o->remote_ref);
} }
} else if (!(remote = lookup_commit_reference(remote_sha1))) { } else if (!(remote = lookup_commit_reference(&remote_oid))) {
die("Could not parse remote commit %s (%s)", die("Could not parse remote commit %s (%s)",
sha1_to_hex(remote_sha1), o->remote_ref); oid_to_hex(&remote_oid), o->remote_ref);
} }
trace_printf("\tremote commit: %.7s\n", sha1_to_hex(remote_sha1)); trace_printf("\tremote commit: %.7s\n", oid_to_hex(&remote_oid));
if (!local && !remote) if (!local && !remote)
die("Cannot merge empty notes ref (%s) into empty notes ref " die("Cannot merge empty notes ref (%s) into empty notes ref "
"(%s)", o->remote_ref, o->local_ref); "(%s)", o->remote_ref, o->local_ref);
if (!local) { if (!local) {
/* result == remote commit */ /* result == remote commit */
hashcpy(result_sha1, remote_sha1); hashcpy(result_sha1, remote_oid.hash);
goto found_result; goto found_result;
} }
if (!remote) { if (!remote) {
/* result == local commit */ /* result == local commit */
hashcpy(result_sha1, local_sha1); hashcpy(result_sha1, local_oid.hash);
goto found_result; goto found_result;
} }
assert(local && remote); assert(local && remote);

View File

@ -7,18 +7,18 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
const char *msg, size_t msg_len, const char *msg, size_t msg_len,
unsigned char *result_sha1) unsigned char *result_sha1)
{ {
unsigned char tree_sha1[20]; struct object_id tree_oid;
assert(t->initialized); assert(t->initialized);
if (write_notes_tree(t, tree_sha1)) if (write_notes_tree(t, tree_oid.hash))
die("Failed to write notes tree to database"); die("Failed to write notes tree to database");
if (!parents) { if (!parents) {
/* Deduce parent commit from t->ref */ /* Deduce parent commit from t->ref */
unsigned char parent_sha1[20]; struct object_id parent_oid;
if (!read_ref(t->ref, parent_sha1)) { if (!read_ref(t->ref, parent_oid.hash)) {
struct commit *parent = lookup_commit(parent_sha1); struct commit *parent = lookup_commit(&parent_oid);
if (parse_commit(parent)) if (parse_commit(parent))
die("Failed to find/parse commit %s", t->ref); die("Failed to find/parse commit %s", t->ref);
commit_list_insert(parent, &parents); commit_list_insert(parent, &parents);
@ -26,14 +26,14 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
/* else: t->ref points to nothing, assume root/orphan commit */ /* else: t->ref points to nothing, assume root/orphan commit */
} }
if (commit_tree(msg, msg_len, tree_sha1, parents, result_sha1, NULL, NULL)) if (commit_tree(msg, msg_len, tree_oid.hash, parents, result_sha1, NULL, NULL))
die("Failed to commit notes tree to database"); die("Failed to commit notes tree to database");
} }
void commit_notes(struct notes_tree *t, const char *msg) void commit_notes(struct notes_tree *t, const char *msg)
{ {
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
unsigned char commit_sha1[20]; struct object_id commit_oid;
if (!t) if (!t)
t = &default_notes_tree; t = &default_notes_tree;
@ -46,9 +46,9 @@ void commit_notes(struct notes_tree *t, const char *msg)
strbuf_addstr(&buf, msg); strbuf_addstr(&buf, msg);
strbuf_complete_line(&buf); strbuf_complete_line(&buf);
create_notes_commit(t, NULL, buf.buf, buf.len, commit_sha1); create_notes_commit(t, NULL, buf.buf, buf.len, commit_oid.hash);
strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */ strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */
update_ref(buf.buf, t->update_ref, commit_sha1, NULL, 0, update_ref(buf.buf, t->update_ref, commit_oid.hash, NULL, 0,
UPDATE_REFS_DIE_ON_ERR); UPDATE_REFS_DIE_ON_ERR);
strbuf_release(&buf); strbuf_release(&buf);

View File

@ -180,21 +180,21 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
return obj; return obj;
} }
struct object *parse_object_buffer(const unsigned char *sha1, enum object_type type, unsigned long size, void *buffer, int *eaten_p) struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
{ {
struct object *obj; struct object *obj;
*eaten_p = 0; *eaten_p = 0;
obj = NULL; obj = NULL;
if (type == OBJ_BLOB) { if (type == OBJ_BLOB) {
struct blob *blob = lookup_blob(sha1); struct blob *blob = lookup_blob(oid);
if (blob) { if (blob) {
if (parse_blob_buffer(blob, buffer, size)) if (parse_blob_buffer(blob, buffer, size))
return NULL; return NULL;
obj = &blob->object; obj = &blob->object;
} }
} else if (type == OBJ_TREE) { } else if (type == OBJ_TREE) {
struct tree *tree = lookup_tree(sha1); struct tree *tree = lookup_tree(oid);
if (tree) { if (tree) {
obj = &tree->object; obj = &tree->object;
if (!tree->buffer) if (!tree->buffer)
@ -206,7 +206,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
} }
} }
} else if (type == OBJ_COMMIT) { } else if (type == OBJ_COMMIT) {
struct commit *commit = lookup_commit(sha1); struct commit *commit = lookup_commit(oid);
if (commit) { if (commit) {
if (parse_commit_buffer(commit, buffer, size)) if (parse_commit_buffer(commit, buffer, size))
return NULL; return NULL;
@ -217,54 +217,54 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
obj = &commit->object; obj = &commit->object;
} }
} else if (type == OBJ_TAG) { } else if (type == OBJ_TAG) {
struct tag *tag = lookup_tag(sha1); struct tag *tag = lookup_tag(oid);
if (tag) { if (tag) {
if (parse_tag_buffer(tag, buffer, size)) if (parse_tag_buffer(tag, buffer, size))
return NULL; return NULL;
obj = &tag->object; obj = &tag->object;
} }
} else { } else {
warning("object %s has unknown type id %d", sha1_to_hex(sha1), type); warning("object %s has unknown type id %d", oid_to_hex(oid), type);
obj = NULL; obj = NULL;
} }
return obj; return obj;
} }
struct object *parse_object_or_die(const unsigned char *sha1, struct object *parse_object_or_die(const struct object_id *oid,
const char *name) const char *name)
{ {
struct object *o = parse_object(sha1); struct object *o = parse_object(oid);
if (o) if (o)
return o; return o;
die(_("unable to parse object: %s"), name ? name : sha1_to_hex(sha1)); die(_("unable to parse object: %s"), name ? name : oid_to_hex(oid));
} }
struct object *parse_object(const unsigned char *sha1) 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(sha1); const unsigned char *repl = lookup_replace_object(oid->hash);
void *buffer; void *buffer;
struct object *obj; struct object *obj;
obj = lookup_object(sha1); obj = lookup_object(oid->hash);
if (obj && obj->parsed) if (obj && obj->parsed)
return obj; return obj;
if ((obj && obj->type == OBJ_BLOB) || if ((obj && obj->type == OBJ_BLOB) ||
(!obj && has_sha1_file(sha1) && (!obj && has_object_file(oid) &&
sha1_object_info(sha1, NULL) == OBJ_BLOB)) { sha1_object_info(oid->hash, NULL) == OBJ_BLOB)) {
if (check_sha1_signature(repl, NULL, 0, NULL) < 0) { if (check_sha1_signature(repl, NULL, 0, NULL) < 0) {
error("sha1 mismatch %s", sha1_to_hex(repl)); error("sha1 mismatch %s", oid_to_hex(oid));
return NULL; return NULL;
} }
parse_blob_buffer(lookup_blob(sha1), NULL, 0); parse_blob_buffer(lookup_blob(oid), NULL, 0);
return lookup_object(sha1); return lookup_object(oid->hash);
} }
buffer = read_sha1_file(sha1, &type, &size); buffer = read_sha1_file(oid->hash, &type, &size);
if (buffer) { if (buffer) {
if (check_sha1_signature(repl, buffer, size, typename(type)) < 0) { if (check_sha1_signature(repl, buffer, size, typename(type)) < 0) {
free(buffer); free(buffer);
@ -272,7 +272,7 @@ struct object *parse_object(const unsigned char *sha1)
return NULL; return NULL;
} }
obj = parse_object_buffer(sha1, type, size, buffer, &eaten); obj = parse_object_buffer(oid, type, size, buffer, &eaten);
if (!eaten) if (!eaten)
free(buffer); free(buffer);
return obj; return obj;

View File

@ -89,20 +89,20 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet);
* *
* Returns NULL if the object is missing or corrupt. * Returns NULL if the object is missing or corrupt.
*/ */
struct object *parse_object(const unsigned char *sha1); struct object *parse_object(const struct object_id *oid);
/* /*
* Like parse_object, but will die() instead of returning NULL. If the * Like parse_object, but will die() instead of returning NULL. If the
* "name" parameter is not NULL, it is included in the error message * "name" parameter is not NULL, it is included in the error message
* (otherwise, the sha1 hex is given). * (otherwise, the hex object ID is given).
*/ */
struct object *parse_object_or_die(const unsigned char *sha1, const char *name); struct object *parse_object_or_die(const struct object_id *oid, const char *name);
/* Given the result of read_sha1_file(), returns the object after /* Given the result of read_sha1_file(), returns the object after
* parsing it. eaten_p indicates if the object has a borrowed copy * parsing it. eaten_p indicates if the object has a borrowed copy
* of buffer and the caller should not free() it. * of buffer and the caller should not free() it.
*/ */
struct object *parse_object_buffer(const unsigned char *sha1, enum object_type type, unsigned long size, void *buffer, int *eaten_p); struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
/** Returns the object, with potentially excess memory allocated. **/ /** Returns the object, with potentially excess memory allocated. **/
struct object *lookup_unknown_object(const unsigned char *sha1); struct object *lookup_unknown_object(const unsigned char *sha1);

View File

@ -73,7 +73,8 @@ void bitmap_writer_build_type_index(struct pack_idx_entry **index,
break; break;
default: default:
real_type = sha1_object_info(entry->idx.sha1, NULL); real_type = sha1_object_info(entry->idx.oid.hash,
NULL);
break; break;
} }
@ -96,7 +97,8 @@ void bitmap_writer_build_type_index(struct pack_idx_entry **index,
default: default:
die("Missing type information for %s (%d/%d)", die("Missing type information for %s (%d/%d)",
sha1_to_hex(entry->idx.sha1), real_type, entry->type); oid_to_hex(&entry->idx.oid), real_type,
entry->type);
} }
} }
} }
@ -459,7 +461,7 @@ static inline void dump_bitmap(struct sha1file *f, struct ewah_bitmap *bitmap)
static const unsigned char *sha1_access(size_t pos, void *table) static const unsigned char *sha1_access(size_t pos, void *table)
{ {
struct pack_idx_entry **index = table; struct pack_idx_entry **index = table;
return index[pos]->sha1; return index[pos]->oid.hash;
} }
static void write_selected_commits_v1(struct sha1file *f, static void write_selected_commits_v1(struct sha1file *f,

View File

@ -673,7 +673,7 @@ int prepare_bitmap_walk(struct rev_info *revs)
struct object *object = pending_e[i].item; struct object *object = pending_e[i].item;
if (object->type == OBJ_NONE) if (object->type == OBJ_NONE)
parse_object_or_die(object->oid.hash, NULL); parse_object_or_die(&object->oid, NULL);
while (object->type == OBJ_TAG) { while (object->type == OBJ_TAG) {
struct tag *tag = (struct tag *) object; struct tag *tag = (struct tag *) object;
@ -685,7 +685,7 @@ int prepare_bitmap_walk(struct rev_info *revs)
if (!tag->tagged) if (!tag->tagged)
die("bad tag"); die("bad tag");
object = parse_object_or_die(tag->tagged->oid.hash, NULL); object = parse_object_or_die(&tag->tagged->oid, NULL);
} }
if (object->flags & UNINTERESTING) if (object->flags & UNINTERESTING)

View File

@ -5,7 +5,10 @@
struct idx_entry { struct idx_entry {
off_t offset; off_t offset;
const unsigned char *sha1; union idx_entry_object {
const unsigned char *hash;
struct object_id *oid;
} oid;
unsigned int nr; unsigned int nr;
}; };
@ -51,7 +54,7 @@ static int verify_packfile(struct packed_git *p,
off_t index_size = p->index_size; off_t index_size = p->index_size;
const unsigned char *index_base = p->index_data; const unsigned char *index_base = p->index_data;
git_SHA_CTX ctx; git_SHA_CTX ctx;
unsigned char sha1[20], *pack_sig; unsigned char hash[GIT_MAX_RAWSZ], *pack_sig;
off_t offset = 0, pack_sig_ofs = 0; off_t offset = 0, pack_sig_ofs = 0;
uint32_t nr_objects, i; uint32_t nr_objects, i;
int err = 0; int err = 0;
@ -71,9 +74,9 @@ static int verify_packfile(struct packed_git *p,
remaining -= (unsigned int)(offset - pack_sig_ofs); remaining -= (unsigned int)(offset - pack_sig_ofs);
git_SHA1_Update(&ctx, in, remaining); git_SHA1_Update(&ctx, in, remaining);
} while (offset < pack_sig_ofs); } while (offset < pack_sig_ofs);
git_SHA1_Final(sha1, &ctx); git_SHA1_Final(hash, &ctx);
pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL); pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
if (hashcmp(sha1, pack_sig)) if (hashcmp(hash, pack_sig))
err = error("%s SHA1 checksum mismatch", err = error("%s SHA1 checksum mismatch",
p->pack_name); p->pack_name);
if (hashcmp(index_base + index_size - 40, pack_sig)) if (hashcmp(index_base + index_size - 40, pack_sig))
@ -90,8 +93,8 @@ static int verify_packfile(struct packed_git *p,
entries[nr_objects].offset = pack_sig_ofs; entries[nr_objects].offset = pack_sig_ofs;
/* first sort entries by pack offset, since unpacking them is more efficient that way */ /* first sort entries by pack offset, since unpacking them is more efficient that way */
for (i = 0; i < nr_objects; i++) { for (i = 0; i < nr_objects; i++) {
entries[i].sha1 = nth_packed_object_sha1(p, i); entries[i].oid.hash = nth_packed_object_sha1(p, i);
if (!entries[i].sha1) if (!entries[i].oid.hash)
die("internal error pack-check nth-packed-object"); die("internal error pack-check nth-packed-object");
entries[i].offset = nth_packed_object_offset(p, i); entries[i].offset = nth_packed_object_offset(p, i);
entries[i].nr = i; entries[i].nr = i;
@ -112,7 +115,7 @@ static int verify_packfile(struct packed_git *p,
if (check_pack_crc(p, w_curs, offset, len, nr)) if (check_pack_crc(p, w_curs, offset, len, nr))
err = error("index CRC mismatch for object %s " err = error("index CRC mismatch for object %s "
"from %s at offset %"PRIuMAX"", "from %s at offset %"PRIuMAX"",
sha1_to_hex(entries[i].sha1), oid_to_hex(entries[i].oid.oid),
p->pack_name, (uintmax_t)offset); p->pack_name, (uintmax_t)offset);
} }
@ -135,14 +138,14 @@ static int verify_packfile(struct packed_git *p,
if (data_valid && !data) if (data_valid && !data)
err = error("cannot unpack %s from %s at offset %"PRIuMAX"", err = error("cannot unpack %s from %s at offset %"PRIuMAX"",
sha1_to_hex(entries[i].sha1), 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].sha1, data, size, typename(type))) else if (check_sha1_signature(entries[i].oid.hash, data, size, typename(type)))
err = error("packed %s from %s is corrupt", err = error("packed %s from %s is corrupt",
sha1_to_hex(entries[i].sha1), p->pack_name); oid_to_hex(entries[i].oid.oid), p->pack_name);
else if (fn) { else if (fn) {
int eaten = 0; int eaten = 0;
err |= fn(entries[i].sha1, type, size, data, &eaten); err |= fn(entries[i].oid.oid, type, size, data, &eaten);
if (eaten) if (eaten)
data = NULL; data = NULL;
} }

View File

@ -14,7 +14,7 @@ static uint32_t locate_object_entry_hash(struct packing_data *pdata,
while (pdata->index[i] > 0) { while (pdata->index[i] > 0) {
uint32_t pos = pdata->index[i] - 1; uint32_t pos = pdata->index[i] - 1;
if (!hashcmp(sha1, pdata->objects[pos].idx.sha1)) { if (!hashcmp(sha1, pdata->objects[pos].idx.oid.hash)) {
*found = 1; *found = 1;
return i; return i;
} }
@ -53,7 +53,9 @@ static void rehash_objects(struct packing_data *pdata)
for (i = 0; i < pdata->nr_objects; i++) { for (i = 0; i < pdata->nr_objects; i++) {
int found; int found;
uint32_t ix = locate_object_entry_hash(pdata, entry->idx.sha1, &found); uint32_t ix = locate_object_entry_hash(pdata,
entry->idx.oid.hash,
&found);
if (found) if (found)
die("BUG: Duplicate object in hash"); die("BUG: Duplicate object in hash");
@ -98,7 +100,7 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,
new_entry = pdata->objects + pdata->nr_objects++; new_entry = pdata->objects + pdata->nr_objects++;
memset(new_entry, 0, sizeof(*new_entry)); memset(new_entry, 0, sizeof(*new_entry));
hashcpy(new_entry->idx.sha1, sha1); hashcpy(new_entry->idx.oid.hash, sha1);
if (pdata->index_size * 3 <= pdata->nr_objects * 4) if (pdata->index_size * 3 <= pdata->nr_objects * 4)
rehash_objects(pdata); rehash_objects(pdata);

View File

@ -13,7 +13,7 @@ static int sha1_compare(const void *_a, const void *_b)
{ {
struct pack_idx_entry *a = *(struct pack_idx_entry **)_a; struct pack_idx_entry *a = *(struct pack_idx_entry **)_a;
struct pack_idx_entry *b = *(struct pack_idx_entry **)_b; struct pack_idx_entry *b = *(struct pack_idx_entry **)_b;
return hashcmp(a->sha1, b->sha1); return oidcmp(&a->oid, &b->oid);
} }
static int cmp_uint32(const void *a_, const void *b_) static int cmp_uint32(const void *a_, const void *b_)
@ -103,7 +103,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
struct pack_idx_entry **next = list; struct pack_idx_entry **next = list;
while (next < last) { while (next < last) {
struct pack_idx_entry *obj = *next; struct pack_idx_entry *obj = *next;
if (obj->sha1[0] != i) if (obj->oid.hash[0] != i)
break; break;
next++; next++;
} }
@ -122,11 +122,11 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
uint32_t offset = htonl(obj->offset); uint32_t offset = htonl(obj->offset);
sha1write(f, &offset, 4); sha1write(f, &offset, 4);
} }
sha1write(f, obj->sha1, 20); sha1write(f, obj->oid.hash, 20);
if ((opts->flags & WRITE_IDX_STRICT) && if ((opts->flags & WRITE_IDX_STRICT) &&
(i && !hashcmp(list[-2]->sha1, obj->sha1))) (i && !oidcmp(&list[-2]->oid, &obj->oid)))
die("The same object %s appears twice in the pack", die("The same object %s appears twice in the pack",
sha1_to_hex(obj->sha1)); oid_to_hex(&obj->oid));
} }
if (index_version >= 2) { if (index_version >= 2) {

4
pack.h
View File

@ -67,7 +67,7 @@ struct pack_idx_header {
* Common part of object structure used for write_idx_file * Common part of object structure used for write_idx_file
*/ */
struct pack_idx_entry { struct pack_idx_entry {
unsigned char sha1[20]; struct object_id oid;
uint32_t crc32; uint32_t crc32;
off_t offset; off_t offset;
}; };
@ -75,7 +75,7 @@ struct pack_idx_entry {
struct progress; struct progress;
/* Note, the data argument could be NULL if object type is blob */ /* Note, the data argument could be NULL if object type is blob */
typedef int (*verify_fn)(const unsigned char*, enum object_type, unsigned long, void*, int*); typedef int (*verify_fn)(const struct object_id *, enum object_type, unsigned long, void*, int*);
extern const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects, int nr_objects, const struct pack_idx_option *, const unsigned char *sha1); extern const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects, int nr_objects, const struct pack_idx_option *, const unsigned char *sha1);
extern int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr); extern int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr);

View File

@ -80,14 +80,14 @@ int parse_opt_verbosity_cb(const struct option *opt, const char *arg,
int parse_opt_commits(const struct option *opt, const char *arg, int unset) int parse_opt_commits(const struct option *opt, const char *arg, int unset)
{ {
unsigned char sha1[20]; struct object_id oid;
struct commit *commit; struct commit *commit;
if (!arg) if (!arg)
return -1; return -1;
if (get_sha1(arg, sha1)) if (get_oid(arg, &oid))
return error("malformed object name %s", arg); return error("malformed object name %s", arg);
commit = lookup_commit_reference(sha1); commit = lookup_commit_reference(&oid);
if (!commit) if (!commit)
return error("no such commit %s", arg); return error("no such commit %s", arg);
commit_list_insert(commit, opt->value); commit_list_insert(commit, opt->value);

View File

@ -1137,7 +1137,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
/* these depend on the commit */ /* these depend on the commit */
if (!commit->object.parsed) if (!commit->object.parsed)
parse_object(commit->object.oid.hash); parse_object(&commit->object.oid);
switch (placeholder[0]) { switch (placeholder[0]) {
case 'H': /* commit hash */ case 'H': /* commit hash */

View File

@ -33,7 +33,7 @@ static int add_one_ref(const char *path, const struct object_id *oid,
return 0; return 0;
} }
object = parse_object_or_die(oid->hash, path); object = parse_object_or_die(oid, path);
add_pending_object(revs, object, ""); add_pending_object(revs, object, "");
return 0; return 0;
@ -82,13 +82,13 @@ static void add_recent_object(const struct object_id *oid,
switch (type) { switch (type) {
case OBJ_TAG: case OBJ_TAG:
case OBJ_COMMIT: case OBJ_COMMIT:
obj = parse_object_or_die(oid->hash, NULL); obj = parse_object_or_die(oid, NULL);
break; break;
case OBJ_TREE: case OBJ_TREE:
obj = (struct object *)lookup_tree(oid->hash); obj = (struct object *)lookup_tree(oid);
break; break;
case OBJ_BLOB: case OBJ_BLOB:
obj = (struct object *)lookup_blob(oid->hash); obj = (struct object *)lookup_blob(oid);
break; break;
default: default:
die("unknown object type for %s: %s", die("unknown object type for %s: %s",

View File

@ -677,13 +677,13 @@ int verify_ref_format(const char *format)
* by the "struct object" representation, set *eaten as well---it is a * by the "struct object" representation, set *eaten as well---it is a
* signal from parse_object_buffer to us not to free the buffer. * signal from parse_object_buffer to us not to free the buffer.
*/ */
static void *get_obj(const unsigned char *sha1, 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(sha1, &type, sz); void *buf = read_sha1_file(oid->hash, &type, sz);
if (buf) if (buf)
*obj = parse_object_buffer(sha1, type, *sz, buf, eaten); *obj = parse_object_buffer(oid, type, *sz, buf, eaten);
else else
*obj = NULL; *obj = NULL;
return buf; return buf;
@ -1293,7 +1293,7 @@ static void populate_value(struct ref_array_item *ref)
struct object *obj; struct object *obj;
int eaten, i; int eaten, i;
unsigned long size; unsigned long size;
const unsigned char *tagged; const struct object_id *tagged;
ref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value)); ref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));
@ -1366,14 +1366,14 @@ 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, v, atom)) { } else if (!deref && grab_objectname(name, ref->objectname.hash, v, atom)) {
continue; continue;
} else if (!strcmp(name, "HEAD")) { } else if (!strcmp(name, "HEAD")) {
const char *head; const char *head;
unsigned char sha1[20]; struct object_id oid;
head = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
sha1, NULL); oid.hash, NULL);
if (head && !strcmp(ref->refname, head)) if (head && !strcmp(ref->refname, head))
v->s = "*"; v->s = "*";
else else
@ -1415,13 +1415,13 @@ static void populate_value(struct ref_array_item *ref)
return; return;
need_obj: need_obj:
buf = get_obj(ref->objectname, &obj, &size, &eaten); buf = get_obj(&ref->objectname, &obj, &size, &eaten);
if (!buf) if (!buf)
die(_("missing object %s for %s"), die(_("missing object %s for %s"),
sha1_to_hex(ref->objectname), ref->refname); oid_to_hex(&ref->objectname), ref->refname);
if (!obj) if (!obj)
die(_("parse_object_buffer failed on %s for %s"), die(_("parse_object_buffer failed on %s for %s"),
sha1_to_hex(ref->objectname), ref->refname); oid_to_hex(&ref->objectname), ref->refname);
grab_values(ref->value, 0, obj, buf, size); grab_values(ref->value, 0, obj, buf, size);
if (!eaten) if (!eaten)
@ -1438,7 +1438,7 @@ static void populate_value(struct ref_array_item *ref)
* If it is a tag object, see if we use a value that derefs * If it is a tag object, see if we use a value that derefs
* the object, and if we do grab the object it refers to. * the object, and if we do grab the object it refers to.
*/ */
tagged = ((struct tag *)obj)->tagged->oid.hash; tagged = &((struct tag *)obj)->tagged->oid;
/* /*
* NEEDSWORK: This derefs tag only once, which * NEEDSWORK: This derefs tag only once, which
@ -1449,10 +1449,10 @@ static void populate_value(struct ref_array_item *ref)
buf = get_obj(tagged, &obj, &size, &eaten); buf = get_obj(tagged, &obj, &size, &eaten);
if (!buf) if (!buf)
die(_("missing object %s for %s"), die(_("missing object %s for %s"),
sha1_to_hex(tagged), ref->refname); oid_to_hex(tagged), ref->refname);
if (!obj) if (!obj)
die(_("parse_object_buffer failed on %s for %s"), die(_("parse_object_buffer failed on %s for %s"),
sha1_to_hex(tagged), ref->refname); oid_to_hex(tagged), ref->refname);
grab_values(ref->value, 1, obj, buf, size); grab_values(ref->value, 1, obj, buf, size);
if (!eaten) if (!eaten)
free(buf); free(buf);
@ -1687,7 +1687,7 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
if (oid_array_lookup(points_at, oid) >= 0) if (oid_array_lookup(points_at, oid) >= 0)
return oid; return oid;
obj = parse_object(oid->hash); obj = parse_object(oid);
if (!obj) if (!obj)
die(_("malformed object at '%s'"), refname); die(_("malformed object at '%s'"), refname);
if (obj->type == OBJ_TAG) if (obj->type == OBJ_TAG)
@ -1704,7 +1704,7 @@ static struct ref_array_item *new_ref_array_item(const char *refname,
{ {
struct ref_array_item *ref; struct ref_array_item *ref;
FLEX_ALLOC_STR(ref, refname, refname); FLEX_ALLOC_STR(ref, refname, refname);
hashcpy(ref->objectname, objectname); hashcpy(ref->objectname.hash, objectname);
ref->flag = flag; ref->flag = flag;
return ref; return ref;
@ -1782,7 +1782,7 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
* non-commits early. The actual filtering is done later. * non-commits early. The actual filtering is done later.
*/ */
if (filter->merge_commit || filter->with_commit || filter->no_commit || filter->verbose) { if (filter->merge_commit || filter->with_commit || filter->no_commit || filter->verbose) {
commit = lookup_commit_reference_gently(oid->hash, 1); commit = lookup_commit_reference_gently(oid, 1);
if (!commit) if (!commit)
return 0; return 0;
/* We perform the filtering for the '--contains' option... */ /* We perform the filtering for the '--contains' option... */
@ -2090,7 +2090,7 @@ int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset) int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
{ {
struct ref_filter *rf = opt->value; struct ref_filter *rf = opt->value;
unsigned char sha1[20]; struct object_id oid;
int no_merged = starts_with(opt->long_name, "no"); int no_merged = starts_with(opt->long_name, "no");
if (rf->merge) { if (rf->merge) {
@ -2105,10 +2105,10 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
? REF_FILTER_MERGED_OMIT ? REF_FILTER_MERGED_OMIT
: REF_FILTER_MERGED_INCLUDE; : REF_FILTER_MERGED_INCLUDE;
if (get_sha1(arg, sha1)) if (get_oid(arg, &oid))
die(_("malformed object name %s"), arg); die(_("malformed object name %s"), arg);
rf->merge_commit = lookup_commit_reference_gently(sha1, 0); rf->merge_commit = lookup_commit_reference_gently(&oid, 0);
if (!rf->merge_commit) if (!rf->merge_commit)
return opterror(opt, "must point to a commit", 0); return opterror(opt, "must point to a commit", 0);

View File

@ -34,7 +34,7 @@ struct ref_sorting {
}; };
struct ref_array_item { struct ref_array_item {
unsigned char objectname[20]; struct object_id objectname;
int flag; int flag;
unsigned int kind; unsigned int kind;
const char *symref; const char *symref;

View File

@ -238,13 +238,13 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
do { do {
reflog = &commit_reflog->reflogs->items[commit_reflog->recno]; reflog = &commit_reflog->reflogs->items[commit_reflog->recno];
commit_reflog->recno--; commit_reflog->recno--;
logobj = parse_object(reflog->ooid.hash); logobj = parse_object(&reflog->ooid);
} while (commit_reflog->recno && (logobj && logobj->type != OBJ_COMMIT)); } while (commit_reflog->recno && (logobj && logobj->type != OBJ_COMMIT));
if (!logobj && commit_reflog->recno >= 0 && is_null_sha1(reflog->ooid.hash)) { if (!logobj && commit_reflog->recno >= 0 && is_null_oid(&reflog->ooid)) {
/* a root commit, but there are still more entries to show */ /* a root commit, but there are still more entries to show */
reflog = &commit_reflog->reflogs->items[commit_reflog->recno]; reflog = &commit_reflog->reflogs->items[commit_reflog->recno];
logobj = parse_object(reflog->noid.hash); logobj = parse_object(&reflog->noid);
} }
if (!logobj || logobj->type != OBJ_COMMIT) { if (!logobj || logobj->type != OBJ_COMMIT) {

4
refs.c
View File

@ -883,9 +883,9 @@ struct ref_update *ref_transaction_add_update(
update->flags = flags; update->flags = flags;
if (flags & REF_HAVE_NEW) if (flags & REF_HAVE_NEW)
hashcpy(update->new_sha1, new_sha1); hashcpy(update->new_oid.hash, new_sha1);
if (flags & REF_HAVE_OLD) if (flags & REF_HAVE_OLD)
hashcpy(update->old_sha1, old_sha1); hashcpy(update->old_oid.hash, old_sha1);
update->msg = xstrdup_or_null(msg); update->msg = xstrdup_or_null(msg);
return update; return update;
} }

6
refs.h
View File

@ -602,10 +602,10 @@ enum expire_reflog_flags {
* unlocked again. * unlocked again.
*/ */
typedef void reflog_expiry_prepare_fn(const char *refname, typedef void reflog_expiry_prepare_fn(const char *refname,
const unsigned char *sha1, const struct object_id *oid,
void *cb_data); void *cb_data);
typedef int reflog_expiry_should_prune_fn(unsigned char *osha1, typedef int reflog_expiry_should_prune_fn(struct object_id *ooid,
unsigned char *nsha1, struct object_id *noid,
const char *email, const char *email,
timestamp_t timestamp, int tz, timestamp_t timestamp, int tz,
const char *message, void *cb_data); const char *message, void *cb_data);

View File

@ -195,27 +195,15 @@ static const char PACKED_REFS_HEADER[] =
* Return a pointer to the refname within the line (null-terminated), * Return a pointer to the refname within the line (null-terminated),
* or NULL if there was a problem. * or NULL if there was a problem.
*/ */
static const char *parse_ref_line(struct strbuf *line, unsigned char *sha1) static const char *parse_ref_line(struct strbuf *line, struct object_id *oid)
{ {
const char *ref; const char *ref;
/* if (parse_oid_hex(line->buf, oid, &ref) < 0)
* 42: the answer to everything. return NULL;
* if (!isspace(*ref++))
* In this case, it happens to be the answer to
* 40 (length of sha1 hex representation)
* +1 (space in between hex and name)
* +1 (newline at the end of the line)
*/
if (line->len <= 42)
return NULL; return NULL;
if (get_sha1_hex(line->buf, sha1) < 0)
return NULL;
if (!isspace(line->buf[40]))
return NULL;
ref = line->buf + 41;
if (isspace(*ref)) if (isspace(*ref))
return NULL; return NULL;
@ -260,7 +248,7 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
enum { PEELED_NONE, PEELED_TAGS, PEELED_FULLY } peeled = PEELED_NONE; enum { PEELED_NONE, PEELED_TAGS, PEELED_FULLY } peeled = PEELED_NONE;
while (strbuf_getwholeline(&line, f, '\n') != EOF) { while (strbuf_getwholeline(&line, f, '\n') != EOF) {
unsigned char sha1[20]; struct object_id oid;
const char *refname; const char *refname;
const char *traits; const char *traits;
@ -273,17 +261,17 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
continue; continue;
} }
refname = parse_ref_line(&line, sha1); refname = parse_ref_line(&line, &oid);
if (refname) { if (refname) {
int flag = REF_ISPACKED; int flag = REF_ISPACKED;
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) { if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
if (!refname_is_safe(refname)) if (!refname_is_safe(refname))
die("packed refname is dangerous: %s", refname); die("packed refname is dangerous: %s", refname);
hashclr(sha1); oidclr(&oid);
flag |= REF_BAD_NAME | REF_ISBROKEN; flag |= REF_BAD_NAME | REF_ISBROKEN;
} }
last = create_ref_entry(refname, sha1, flag, 0); last = create_ref_entry(refname, &oid, flag, 0);
if (peeled == PEELED_FULLY || if (peeled == PEELED_FULLY ||
(peeled == PEELED_TAGS && starts_with(refname, "refs/tags/"))) (peeled == PEELED_TAGS && starts_with(refname, "refs/tags/")))
last->flag |= REF_KNOWS_PEELED; last->flag |= REF_KNOWS_PEELED;
@ -294,8 +282,8 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
line.buf[0] == '^' && line.buf[0] == '^' &&
line.len == PEELED_LINE_LENGTH && line.len == PEELED_LINE_LENGTH &&
line.buf[PEELED_LINE_LENGTH - 1] == '\n' && line.buf[PEELED_LINE_LENGTH - 1] == '\n' &&
!get_sha1_hex(line.buf + 1, sha1)) { !get_oid_hex(line.buf + 1, &oid)) {
hashcpy(last->u.value.peeled.hash, sha1); oidcpy(&last->u.value.peeled, &oid);
/* /*
* Regardless of what the file header said, * Regardless of what the file header said,
* we definitely know the value of *this* * we definitely know the value of *this*
@ -404,14 +392,14 @@ static struct ref_dir *get_packed_refs(struct files_ref_store *refs)
* commit_packed_refs(). * commit_packed_refs().
*/ */
static void add_packed_ref(struct files_ref_store *refs, static void add_packed_ref(struct files_ref_store *refs,
const char *refname, const unsigned char *sha1) const char *refname, const struct object_id *oid)
{ {
struct packed_ref_cache *packed_ref_cache = get_packed_ref_cache(refs); struct packed_ref_cache *packed_ref_cache = get_packed_ref_cache(refs);
if (!packed_ref_cache->lock) if (!packed_ref_cache->lock)
die("internal error: packed refs not locked"); die("internal error: packed refs not locked");
add_ref_entry(get_packed_ref_dir(packed_ref_cache), add_ref_entry(get_packed_ref_dir(packed_ref_cache),
create_ref_entry(refname, sha1, REF_ISPACKED, 1)); create_ref_entry(refname, oid, REF_ISPACKED, 1));
} }
/* /*
@ -444,7 +432,7 @@ static void loose_fill_ref_dir(struct ref_store *ref_store,
strbuf_add(&refname, dirname, dirnamelen); strbuf_add(&refname, dirname, dirnamelen);
while ((de = readdir(d)) != NULL) { while ((de = readdir(d)) != NULL) {
unsigned char sha1[20]; struct object_id oid;
struct stat st; struct stat st;
int flag; int flag;
@ -465,10 +453,10 @@ static void loose_fill_ref_dir(struct ref_store *ref_store,
if (!refs_resolve_ref_unsafe(&refs->base, if (!refs_resolve_ref_unsafe(&refs->base,
refname.buf, refname.buf,
RESOLVE_REF_READING, RESOLVE_REF_READING,
sha1, &flag)) { oid.hash, &flag)) {
hashclr(sha1); oidclr(&oid);
flag |= REF_ISBROKEN; flag |= REF_ISBROKEN;
} else if (is_null_sha1(sha1)) { } else if (is_null_oid(&oid)) {
/* /*
* It is so astronomically unlikely * It is so astronomically unlikely
* that NULL_SHA1 is the SHA-1 of an * that NULL_SHA1 is the SHA-1 of an
@ -484,11 +472,11 @@ static void loose_fill_ref_dir(struct ref_store *ref_store,
REFNAME_ALLOW_ONELEVEL)) { REFNAME_ALLOW_ONELEVEL)) {
if (!refname_is_safe(refname.buf)) if (!refname_is_safe(refname.buf))
die("loose refname is dangerous: %s", refname.buf); die("loose refname is dangerous: %s", refname.buf);
hashclr(sha1); oidclr(&oid);
flag |= REF_BAD_NAME | REF_ISBROKEN; flag |= REF_BAD_NAME | REF_ISBROKEN;
} }
add_entry_to_dir(dir, add_entry_to_dir(dir,
create_ref_entry(refname.buf, sha1, flag, 0)); create_ref_entry(refname.buf, &oid, flag, 0));
} }
strbuf_setlen(&refname, dirnamelen); strbuf_setlen(&refname, dirnamelen);
strbuf_setlen(&path, path_baselen); strbuf_setlen(&path, path_baselen);
@ -1526,7 +1514,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
packed_entry->flag = REF_ISPACKED; packed_entry->flag = REF_ISPACKED;
oidcpy(&packed_entry->u.value.oid, iter->oid); oidcpy(&packed_entry->u.value.oid, iter->oid);
} else { } else {
packed_entry = create_ref_entry(iter->refname, iter->oid->hash, packed_entry = create_ref_entry(iter->refname, iter->oid,
REF_ISPACKED, 0); REF_ISPACKED, 0);
add_ref_entry(packed_refs, packed_entry); add_ref_entry(packed_refs, packed_entry);
} }
@ -1709,10 +1697,10 @@ static int rename_tmp_log(struct files_ref_store *refs, const char *newrefname)
} }
static int write_ref_to_lockfile(struct ref_lock *lock, static int write_ref_to_lockfile(struct ref_lock *lock,
const unsigned char *sha1, struct strbuf *err); const struct object_id *oid, struct strbuf *err);
static int commit_ref_update(struct files_ref_store *refs, static int commit_ref_update(struct files_ref_store *refs,
struct ref_lock *lock, struct ref_lock *lock,
const unsigned char *sha1, const char *logmsg, const struct object_id *oid, const char *logmsg,
struct strbuf *err); struct strbuf *err);
static int files_rename_ref(struct ref_store *ref_store, static int files_rename_ref(struct ref_store *ref_store,
@ -1721,7 +1709,7 @@ static int files_rename_ref(struct ref_store *ref_store,
{ {
struct files_ref_store *refs = struct files_ref_store *refs =
files_downcast(ref_store, REF_STORE_WRITE, "rename_ref"); files_downcast(ref_store, REF_STORE_WRITE, "rename_ref");
unsigned char sha1[20], orig_sha1[20]; struct object_id oid, orig_oid;
int flag = 0, logmoved = 0; int flag = 0, logmoved = 0;
struct ref_lock *lock; struct ref_lock *lock;
struct stat loginfo; struct stat loginfo;
@ -1743,7 +1731,7 @@ static int files_rename_ref(struct ref_store *ref_store,
if (!refs_resolve_ref_unsafe(&refs->base, oldrefname, if (!refs_resolve_ref_unsafe(&refs->base, oldrefname,
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE, RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
orig_sha1, &flag)) { orig_oid.hash, &flag)) {
ret = error("refname %s not found", oldrefname); ret = error("refname %s not found", oldrefname);
goto out; goto out;
} }
@ -1765,21 +1753,21 @@ static int files_rename_ref(struct ref_store *ref_store,
} }
if (refs_delete_ref(&refs->base, logmsg, oldrefname, if (refs_delete_ref(&refs->base, logmsg, oldrefname,
orig_sha1, REF_NODEREF)) { orig_oid.hash, REF_NODEREF)) {
error("unable to delete old %s", oldrefname); error("unable to delete old %s", oldrefname);
goto rollback; goto rollback;
} }
/* /*
* Since we are doing a shallow lookup, sha1 is not the * Since we are doing a shallow lookup, oid is not the
* correct value to pass to delete_ref as old_sha1. But that * correct value to pass to delete_ref as old_oid. But that
* doesn't matter, because an old_sha1 check wouldn't add to * doesn't matter, because an old_oid check wouldn't add to
* the safety anyway; we want to delete the reference whatever * the safety anyway; we want to delete the reference whatever
* its current value. * its current value.
*/ */
if (!refs_read_ref_full(&refs->base, newrefname, if (!refs_read_ref_full(&refs->base, newrefname,
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE, RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
sha1, NULL) && oid.hash, NULL) &&
refs_delete_ref(&refs->base, NULL, newrefname, refs_delete_ref(&refs->base, NULL, newrefname,
NULL, REF_NODEREF)) { NULL, REF_NODEREF)) {
if (errno == EISDIR) { if (errno == EISDIR) {
@ -1812,10 +1800,10 @@ static int files_rename_ref(struct ref_store *ref_store,
strbuf_release(&err); strbuf_release(&err);
goto rollback; goto rollback;
} }
hashcpy(lock->old_oid.hash, orig_sha1); oidcpy(&lock->old_oid, &orig_oid);
if (write_ref_to_lockfile(lock, orig_sha1, &err) || if (write_ref_to_lockfile(lock, &orig_oid, &err) ||
commit_ref_update(refs, lock, orig_sha1, logmsg, &err)) { commit_ref_update(refs, lock, &orig_oid, logmsg, &err)) {
error("unable to write current sha1 into %s: %s", newrefname, err.buf); error("unable to write current sha1 into %s: %s", newrefname, err.buf);
strbuf_release(&err); strbuf_release(&err);
goto rollback; goto rollback;
@ -1835,8 +1823,8 @@ static int files_rename_ref(struct ref_store *ref_store,
flag = log_all_ref_updates; flag = log_all_ref_updates;
log_all_ref_updates = LOG_REFS_NONE; log_all_ref_updates = LOG_REFS_NONE;
if (write_ref_to_lockfile(lock, orig_sha1, &err) || if (write_ref_to_lockfile(lock, &orig_oid, &err) ||
commit_ref_update(refs, lock, orig_sha1, NULL, &err)) { commit_ref_update(refs, lock, &orig_oid, NULL, &err)) {
error("unable to write current sha1 into %s: %s", oldrefname, err.buf); error("unable to write current sha1 into %s: %s", oldrefname, err.buf);
strbuf_release(&err); strbuf_release(&err);
} }
@ -1986,8 +1974,8 @@ static int files_create_reflog(struct ref_store *ref_store,
return 0; return 0;
} }
static int log_ref_write_fd(int fd, const unsigned char *old_sha1, static int log_ref_write_fd(int fd, const struct object_id *old_oid,
const unsigned char *new_sha1, const struct object_id *new_oid,
const char *committer, const char *msg) const char *committer, const char *msg)
{ {
int msglen, written; int msglen, written;
@ -1998,8 +1986,8 @@ static int log_ref_write_fd(int fd, const unsigned char *old_sha1,
maxlen = strlen(committer) + msglen + 100; maxlen = strlen(committer) + msglen + 100;
logrec = xmalloc(maxlen); logrec = xmalloc(maxlen);
len = xsnprintf(logrec, maxlen, "%s %s %s\n", len = xsnprintf(logrec, maxlen, "%s %s %s\n",
sha1_to_hex(old_sha1), oid_to_hex(old_oid),
sha1_to_hex(new_sha1), oid_to_hex(new_oid),
committer); committer);
if (msglen) if (msglen)
len += copy_reflog_msg(logrec + len - 1, msg) - 1; len += copy_reflog_msg(logrec + len - 1, msg) - 1;
@ -2013,8 +2001,8 @@ static int log_ref_write_fd(int fd, const unsigned char *old_sha1,
} }
static int files_log_ref_write(struct files_ref_store *refs, static int files_log_ref_write(struct files_ref_store *refs,
const char *refname, const unsigned char *old_sha1, const char *refname, const struct object_id *old_oid,
const unsigned char *new_sha1, const char *msg, const struct object_id *new_oid, const char *msg,
int flags, struct strbuf *err) int flags, struct strbuf *err)
{ {
int logfd, result; int logfd, result;
@ -2031,7 +2019,7 @@ static int files_log_ref_write(struct files_ref_store *refs,
if (logfd < 0) if (logfd < 0)
return 0; return 0;
result = log_ref_write_fd(logfd, old_sha1, new_sha1, result = log_ref_write_fd(logfd, old_oid, new_oid,
git_committer_info(0), msg); git_committer_info(0), msg);
if (result) { if (result) {
struct strbuf sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT;
@ -2063,29 +2051,29 @@ static int files_log_ref_write(struct files_ref_store *refs,
* return -1. * return -1.
*/ */
static int write_ref_to_lockfile(struct ref_lock *lock, static int write_ref_to_lockfile(struct ref_lock *lock,
const unsigned char *sha1, struct strbuf *err) const struct object_id *oid, struct strbuf *err)
{ {
static char term = '\n'; static char term = '\n';
struct object *o; struct object *o;
int fd; int fd;
o = parse_object(sha1); o = parse_object(oid);
if (!o) { if (!o) {
strbuf_addf(err, strbuf_addf(err,
"trying to write ref '%s' with nonexistent object %s", "trying to write ref '%s' with nonexistent object %s",
lock->ref_name, sha1_to_hex(sha1)); lock->ref_name, oid_to_hex(oid));
unlock_ref(lock); unlock_ref(lock);
return -1; return -1;
} }
if (o->type != OBJ_COMMIT && is_branch(lock->ref_name)) { if (o->type != OBJ_COMMIT && is_branch(lock->ref_name)) {
strbuf_addf(err, strbuf_addf(err,
"trying to write non-commit object %s to branch '%s'", "trying to write non-commit object %s to branch '%s'",
sha1_to_hex(sha1), lock->ref_name); oid_to_hex(oid), lock->ref_name);
unlock_ref(lock); unlock_ref(lock);
return -1; return -1;
} }
fd = get_lock_file_fd(lock->lk); fd = get_lock_file_fd(lock->lk);
if (write_in_full(fd, sha1_to_hex(sha1), 40) != 40 || if (write_in_full(fd, oid_to_hex(oid), GIT_SHA1_HEXSZ) != GIT_SHA1_HEXSZ ||
write_in_full(fd, &term, 1) != 1 || write_in_full(fd, &term, 1) != 1 ||
close_ref(lock) < 0) { close_ref(lock) < 0) {
strbuf_addf(err, strbuf_addf(err,
@ -2103,14 +2091,14 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
*/ */
static int commit_ref_update(struct files_ref_store *refs, static int commit_ref_update(struct files_ref_store *refs,
struct ref_lock *lock, struct ref_lock *lock,
const unsigned char *sha1, const char *logmsg, const struct object_id *oid, const char *logmsg,
struct strbuf *err) struct strbuf *err)
{ {
files_assert_main_repository(refs, "commit_ref_update"); files_assert_main_repository(refs, "commit_ref_update");
clear_loose_ref_cache(refs); clear_loose_ref_cache(refs);
if (files_log_ref_write(refs, lock->ref_name, if (files_log_ref_write(refs, lock->ref_name,
lock->old_oid.hash, sha1, &lock->old_oid, oid,
logmsg, 0, err)) { logmsg, 0, err)) {
char *old_msg = strbuf_detach(err, NULL); char *old_msg = strbuf_detach(err, NULL);
strbuf_addf(err, "cannot update the ref '%s': %s", strbuf_addf(err, "cannot update the ref '%s': %s",
@ -2133,18 +2121,18 @@ static int commit_ref_update(struct files_ref_store *refs,
* check with HEAD only which should cover 99% of all usage * check with HEAD only which should cover 99% of all usage
* scenarios (even 100% of the default ones). * scenarios (even 100% of the default ones).
*/ */
unsigned char head_sha1[20]; struct object_id head_oid;
int head_flag; int head_flag;
const char *head_ref; const char *head_ref;
head_ref = refs_resolve_ref_unsafe(&refs->base, "HEAD", head_ref = refs_resolve_ref_unsafe(&refs->base, "HEAD",
RESOLVE_REF_READING, RESOLVE_REF_READING,
head_sha1, &head_flag); head_oid.hash, &head_flag);
if (head_ref && (head_flag & REF_ISSYMREF) && if (head_ref && (head_flag & REF_ISSYMREF) &&
!strcmp(head_ref, lock->ref_name)) { !strcmp(head_ref, lock->ref_name)) {
struct strbuf log_err = STRBUF_INIT; struct strbuf log_err = STRBUF_INIT;
if (files_log_ref_write(refs, "HEAD", if (files_log_ref_write(refs, "HEAD",
lock->old_oid.hash, sha1, &lock->old_oid, oid,
logmsg, 0, &log_err)) { logmsg, 0, &log_err)) {
error("%s", log_err.buf); error("%s", log_err.buf);
strbuf_release(&log_err); strbuf_release(&log_err);
@ -2182,12 +2170,12 @@ static void update_symref_reflog(struct files_ref_store *refs,
const char *target, const char *logmsg) const char *target, const char *logmsg)
{ {
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
unsigned char new_sha1[20]; struct object_id new_oid;
if (logmsg && if (logmsg &&
!refs_read_ref_full(&refs->base, target, !refs_read_ref_full(&refs->base, target,
RESOLVE_REF_READING, new_sha1, NULL) && RESOLVE_REF_READING, new_oid.hash, NULL) &&
files_log_ref_write(refs, refname, lock->old_oid.hash, files_log_ref_write(refs, refname, &lock->old_oid,
new_sha1, logmsg, 0, &err)) { &new_oid, logmsg, 0, &err)) {
error("%s", err.buf); error("%s", err.buf);
strbuf_release(&err); strbuf_release(&err);
} }
@ -2589,7 +2577,7 @@ static int split_head_update(struct ref_update *update,
new_update = ref_transaction_add_update( new_update = ref_transaction_add_update(
transaction, "HEAD", transaction, "HEAD",
update->flags | REF_LOG_ONLY | REF_NODEREF, update->flags | REF_LOG_ONLY | REF_NODEREF,
update->new_sha1, update->old_sha1, update->new_oid.hash, update->old_oid.hash,
update->msg); update->msg);
item->util = new_update; item->util = new_update;
@ -2646,7 +2634,7 @@ static int split_symref_update(struct files_ref_store *refs,
new_update = ref_transaction_add_update( new_update = ref_transaction_add_update(
transaction, referent, new_flags, transaction, referent, new_flags,
update->new_sha1, update->old_sha1, update->new_oid.hash, update->old_oid.hash,
update->msg); update->msg);
new_update->parent_update = update; new_update->parent_update = update;
@ -2685,10 +2673,10 @@ static int check_old_oid(struct ref_update *update, struct object_id *oid,
struct strbuf *err) struct strbuf *err)
{ {
if (!(update->flags & REF_HAVE_OLD) || if (!(update->flags & REF_HAVE_OLD) ||
!hashcmp(oid->hash, update->old_sha1)) !oidcmp(oid, &update->old_oid))
return 0; return 0;
if (is_null_sha1(update->old_sha1)) if (is_null_oid(&update->old_oid))
strbuf_addf(err, "cannot lock ref '%s': " strbuf_addf(err, "cannot lock ref '%s': "
"reference already exists", "reference already exists",
original_update_refname(update)); original_update_refname(update));
@ -2696,13 +2684,13 @@ static int check_old_oid(struct ref_update *update, struct object_id *oid,
strbuf_addf(err, "cannot lock ref '%s': " strbuf_addf(err, "cannot lock ref '%s': "
"reference is missing but expected %s", "reference is missing but expected %s",
original_update_refname(update), original_update_refname(update),
sha1_to_hex(update->old_sha1)); oid_to_hex(&update->old_oid));
else else
strbuf_addf(err, "cannot lock ref '%s': " strbuf_addf(err, "cannot lock ref '%s': "
"is at %s but expected %s", "is at %s but expected %s",
original_update_refname(update), original_update_refname(update),
oid_to_hex(oid), oid_to_hex(oid),
sha1_to_hex(update->old_sha1)); oid_to_hex(&update->old_oid));
return -1; return -1;
} }
@ -2729,13 +2717,13 @@ static int lock_ref_for_update(struct files_ref_store *refs,
{ {
struct strbuf referent = STRBUF_INIT; struct strbuf referent = STRBUF_INIT;
int mustexist = (update->flags & REF_HAVE_OLD) && int mustexist = (update->flags & REF_HAVE_OLD) &&
!is_null_sha1(update->old_sha1); !is_null_oid(&update->old_oid);
int ret; int ret;
struct ref_lock *lock; struct ref_lock *lock;
files_assert_main_repository(refs, "lock_ref_for_update"); files_assert_main_repository(refs, "lock_ref_for_update");
if ((update->flags & REF_HAVE_NEW) && is_null_sha1(update->new_sha1)) if ((update->flags & REF_HAVE_NEW) && is_null_oid(&update->new_oid))
update->flags |= REF_DELETING; update->flags |= REF_DELETING;
if (head_ref) { if (head_ref) {
@ -2817,12 +2805,12 @@ static int lock_ref_for_update(struct files_ref_store *refs,
!(update->flags & REF_DELETING) && !(update->flags & REF_DELETING) &&
!(update->flags & REF_LOG_ONLY)) { !(update->flags & REF_LOG_ONLY)) {
if (!(update->type & REF_ISSYMREF) && if (!(update->type & REF_ISSYMREF) &&
!hashcmp(lock->old_oid.hash, update->new_sha1)) { !oidcmp(&lock->old_oid, &update->new_oid)) {
/* /*
* The reference already has the desired * The reference already has the desired
* value, so we don't need to write it. * value, so we don't need to write it.
*/ */
} else if (write_ref_to_lockfile(lock, update->new_sha1, } else if (write_ref_to_lockfile(lock, &update->new_oid,
err)) { err)) {
char *write_err = strbuf_detach(err, NULL); char *write_err = strbuf_detach(err, NULL);
@ -2957,8 +2945,8 @@ static int files_transaction_commit(struct ref_store *ref_store,
update->flags & REF_LOG_ONLY) { update->flags & REF_LOG_ONLY) {
if (files_log_ref_write(refs, if (files_log_ref_write(refs,
lock->ref_name, lock->ref_name,
lock->old_oid.hash, &lock->old_oid,
update->new_sha1, &update->new_oid,
update->msg, update->flags, update->msg, update->flags,
err)) { err)) {
char *old_msg = strbuf_detach(err, NULL); char *old_msg = strbuf_detach(err, NULL);
@ -3107,7 +3095,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
struct ref_update *update = transaction->updates[i]; struct ref_update *update = transaction->updates[i];
if ((update->flags & REF_HAVE_OLD) && if ((update->flags & REF_HAVE_OLD) &&
!is_null_sha1(update->old_sha1)) !is_null_oid(&update->old_oid))
die("BUG: initial ref transaction with old_sha1 set"); die("BUG: initial ref transaction with old_sha1 set");
if (refs_verify_refname_available(&refs->base, update->refname, if (refs_verify_refname_available(&refs->base, update->refname,
&affected_refnames, NULL, &affected_refnames, NULL,
@ -3128,8 +3116,9 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
struct ref_update *update = transaction->updates[i]; struct ref_update *update = transaction->updates[i];
if ((update->flags & REF_HAVE_NEW) && if ((update->flags & REF_HAVE_NEW) &&
!is_null_sha1(update->new_sha1)) !is_null_oid(&update->new_oid))
add_packed_ref(refs, update->refname, update->new_sha1); add_packed_ref(refs, update->refname,
&update->new_oid);
} }
if (commit_packed_refs(refs)) { if (commit_packed_refs(refs)) {
@ -3163,7 +3152,7 @@ static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
if (cb->flags & EXPIRE_REFLOGS_REWRITE) if (cb->flags & EXPIRE_REFLOGS_REWRITE)
ooid = &cb->last_kept_oid; ooid = &cb->last_kept_oid;
if ((*cb->should_prune_fn)(ooid->hash, noid->hash, email, timestamp, tz, if ((*cb->should_prune_fn)(ooid, noid, email, timestamp, tz,
message, policy_cb)) { message, policy_cb)) {
if (!cb->newlog) if (!cb->newlog)
printf("would prune %s", message); printf("would prune %s", message);
@ -3200,6 +3189,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
int status = 0; int status = 0;
int type; int type;
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
struct object_id oid;
memset(&cb, 0, sizeof(cb)); memset(&cb, 0, sizeof(cb));
cb.flags = flags; cb.flags = flags;
@ -3249,7 +3239,9 @@ static int files_reflog_expire(struct ref_store *ref_store,
} }
} }
(*prepare_fn)(refname, sha1, cb.policy_cb); hashcpy(oid.hash, sha1);
(*prepare_fn)(refname, &oid, cb.policy_cb);
refs_for_each_reflog_ent(ref_store, refname, expire_reflog_ent, &cb); refs_for_each_reflog_ent(ref_store, refname, expire_reflog_ent, &cb);
(*cleanup_fn)(cb.policy_cb); (*cleanup_fn)(cb.policy_cb);

View File

@ -32,7 +32,7 @@ struct ref_dir *get_ref_dir(struct ref_entry *entry)
} }
struct ref_entry *create_ref_entry(const char *refname, struct ref_entry *create_ref_entry(const char *refname,
const unsigned char *sha1, int flag, const struct object_id *oid, int flag,
int check_name) int check_name)
{ {
struct ref_entry *ref; struct ref_entry *ref;
@ -41,7 +41,7 @@ struct ref_entry *create_ref_entry(const char *refname,
check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) check_refname_format(refname, REFNAME_ALLOW_ONELEVEL))
die("Reference has invalid format: '%s'", refname); die("Reference has invalid format: '%s'", refname);
FLEX_ALLOC_STR(ref, name, refname); FLEX_ALLOC_STR(ref, name, refname);
hashcpy(ref->u.value.oid.hash, sha1); oidcpy(&ref->u.value.oid, oid);
oidclr(&ref->u.value.peeled); oidclr(&ref->u.value.peeled);
ref->flag = flag; ref->flag = flag;
return ref; return ref;

View File

@ -185,7 +185,7 @@ struct ref_entry *create_dir_entry(struct ref_cache *cache,
int incomplete); int incomplete);
struct ref_entry *create_ref_entry(const char *refname, struct ref_entry *create_ref_entry(const char *refname,
const unsigned char *sha1, int flag, const struct object_id *oid, int flag,
int check_name); int check_name);
/* /*

View File

@ -130,13 +130,13 @@ struct ref_update {
/* /*
* If (flags & REF_HAVE_NEW), set the reference to this value: * If (flags & REF_HAVE_NEW), set the reference to this value:
*/ */
unsigned char new_sha1[20]; struct object_id new_oid;
/* /*
* If (flags & REF_HAVE_OLD), check that the reference * If (flags & REF_HAVE_OLD), check that the reference
* previously had this value: * previously had this value:
*/ */
unsigned char old_sha1[20]; struct object_id old_oid;
/* /*
* One or more of REF_HAVE_NEW, REF_HAVE_OLD, REF_NODEREF, * One or more of REF_HAVE_NEW, REF_HAVE_OLD, REF_NODEREF,

View File

@ -1296,7 +1296,7 @@ static void add_to_tips(struct tips *tips, const struct object_id *oid)
if (is_null_oid(oid)) if (is_null_oid(oid))
return; return;
commit = lookup_commit_reference_gently(oid->hash, 1); commit = lookup_commit_reference_gently(oid, 1);
if (!commit || (commit->object.flags & TMP_MARK)) if (!commit || (commit->object.flags & TMP_MARK))
return; return;
commit->object.flags |= TMP_MARK; commit->object.flags |= TMP_MARK;
@ -1358,7 +1358,8 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
if (is_null_oid(&ref->new_oid)) if (is_null_oid(&ref->new_oid))
continue; continue;
commit = lookup_commit_reference_gently(ref->new_oid.hash, 1); commit = lookup_commit_reference_gently(&ref->new_oid,
1);
if (!commit) if (!commit)
/* not pushing a commit, which is not an error */ /* not pushing a commit, which is not an error */
continue; continue;
@ -1585,8 +1586,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS; reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
else if (!has_object_file(&ref->old_oid)) else if (!has_object_file(&ref->old_oid))
reject_reason = REF_STATUS_REJECT_FETCH_FIRST; reject_reason = REF_STATUS_REJECT_FETCH_FIRST;
else if (!lookup_commit_reference_gently(ref->old_oid.hash, 1) || else if (!lookup_commit_reference_gently(&ref->old_oid, 1) ||
!lookup_commit_reference_gently(ref->new_oid.hash, 1)) !lookup_commit_reference_gently(&ref->new_oid, 1))
reject_reason = REF_STATUS_REJECT_NEEDS_FORCE; reject_reason = REF_STATUS_REJECT_NEEDS_FORCE;
else if (!ref_newer(&ref->new_oid, &ref->old_oid)) else if (!ref_newer(&ref->new_oid, &ref->old_oid))
reject_reason = REF_STATUS_REJECT_NONFASTFORWARD; reject_reason = REF_STATUS_REJECT_NONFASTFORWARD;
@ -1953,12 +1954,12 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
* Both new and old must be commit-ish and new is descendant of * Both new and old must be commit-ish and new is descendant of
* old. Otherwise we require --force. * old. Otherwise we require --force.
*/ */
o = deref_tag(parse_object(old_oid->hash), NULL, 0); o = deref_tag(parse_object(old_oid), NULL, 0);
if (!o || o->type != OBJ_COMMIT) if (!o || o->type != OBJ_COMMIT)
return 0; return 0;
old = (struct commit *) o; old = (struct commit *) o;
o = deref_tag(parse_object(new_oid->hash), NULL, 0); o = deref_tag(parse_object(new_oid), NULL, 0);
if (!o || o->type != OBJ_COMMIT) if (!o || o->type != OBJ_COMMIT)
return 0; return 0;
new = (struct commit *) o; new = (struct commit *) o;
@ -2009,13 +2010,13 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
/* Cannot stat if what we used to build on no longer exists */ /* Cannot stat if what we used to build on no longer exists */
if (read_ref(base, oid.hash)) if (read_ref(base, oid.hash))
return -1; return -1;
theirs = lookup_commit_reference(oid.hash); theirs = lookup_commit_reference(&oid);
if (!theirs) if (!theirs)
return -1; return -1;
if (read_ref(branch->refname, oid.hash)) if (read_ref(branch->refname, oid.hash))
return -1; return -1;
ours = lookup_commit_reference(oid.hash); ours = lookup_commit_reference(&oid);
if (!ours) if (!ours)
return -1; return -1;

View File

@ -59,10 +59,10 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
while (tree_entry(&desc, &entry)) { while (tree_entry(&desc, &entry)) {
switch (object_type(entry.mode)) { switch (object_type(entry.mode)) {
case OBJ_TREE: case OBJ_TREE:
mark_tree_uninteresting(lookup_tree(entry.oid->hash)); mark_tree_uninteresting(lookup_tree(entry.oid));
break; break;
case OBJ_BLOB: case OBJ_BLOB:
mark_blob_uninteresting(lookup_blob(entry.oid->hash)); mark_blob_uninteresting(lookup_blob(entry.oid));
break; break;
default: default:
/* Subproject commit - not in this repository */ /* Subproject commit - not in this repository */
@ -177,23 +177,23 @@ void add_pending_object(struct rev_info *revs,
void add_head_to_pending(struct rev_info *revs) void add_head_to_pending(struct rev_info *revs)
{ {
unsigned char sha1[20]; struct object_id oid;
struct object *obj; struct object *obj;
if (get_sha1("HEAD", sha1)) if (get_oid("HEAD", &oid))
return; return;
obj = parse_object(sha1); obj = parse_object(&oid);
if (!obj) if (!obj)
return; return;
add_pending_object(revs, obj, "HEAD"); add_pending_object(revs, obj, "HEAD");
} }
static struct object *get_reference(struct rev_info *revs, const char *name, static struct object *get_reference(struct rev_info *revs, const char *name,
const unsigned char *sha1, const struct object_id *oid,
unsigned int flags) unsigned int flags)
{ {
struct object *object; struct object *object;
object = parse_object(sha1); object = parse_object(oid);
if (!object) { if (!object) {
if (revs->ignore_missing) if (revs->ignore_missing)
return object; return object;
@ -203,10 +203,10 @@ static struct object *get_reference(struct rev_info *revs, const char *name,
return object; return object;
} }
void add_pending_sha1(struct rev_info *revs, const char *name, void add_pending_oid(struct rev_info *revs, const char *name,
const unsigned char *sha1, unsigned int flags) const struct object_id *oid, unsigned int flags)
{ {
struct object *object = get_reference(revs, name, sha1, flags); struct object *object = get_reference(revs, name, oid, flags);
add_pending_object(revs, object, name); add_pending_object(revs, object, name);
} }
@ -228,7 +228,7 @@ static struct commit *handle_commit(struct rev_info *revs,
add_pending_object(revs, object, tag->tag); add_pending_object(revs, object, tag->tag);
if (!tag->tagged) if (!tag->tagged)
die("bad tag"); die("bad tag");
object = parse_object(tag->tagged->oid.hash); object = parse_object(&tag->tagged->oid);
if (!object) { if (!object) {
if (flags & UNINTERESTING) if (flags & UNINTERESTING)
return NULL; return NULL;
@ -1157,9 +1157,9 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
if (ref_excluded(cb->all_revs->ref_excludes, path)) if (ref_excluded(cb->all_revs->ref_excludes, path))
return 0; return 0;
object = get_reference(cb->all_revs, path, oid->hash, cb->all_flags); object = get_reference(cb->all_revs, path, oid, cb->all_flags);
add_rev_cmdline(cb->all_revs, object, path, REV_CMD_REF, cb->all_flags); add_rev_cmdline(cb->all_revs, object, path, REV_CMD_REF, cb->all_flags);
add_pending_sha1(cb->all_revs, path, oid->hash, cb->all_flags); add_pending_oid(cb->all_revs, path, oid, cb->all_flags);
return 0; return 0;
} }
@ -1200,7 +1200,7 @@ static void handle_one_reflog_commit(struct object_id *oid, void *cb_data)
{ {
struct all_refs_cb *cb = cb_data; struct all_refs_cb *cb = cb_data;
if (!is_null_oid(oid)) { if (!is_null_oid(oid)) {
struct object *o = parse_object(oid->hash); struct object *o = parse_object(oid);
if (o) { if (o) {
o->flags |= cb->all_flags; o->flags |= cb->all_flags;
/* ??? CMDLINEFLAGS ??? */ /* ??? CMDLINEFLAGS ??? */
@ -1249,7 +1249,7 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
int i; int i;
if (it->entry_count >= 0) { if (it->entry_count >= 0) {
struct tree *tree = lookup_tree(it->sha1); struct tree *tree = lookup_tree(&it->oid);
add_pending_object_with_path(revs, &tree->object, "", add_pending_object_with_path(revs, &tree->object, "",
040000, path->buf); 040000, path->buf);
} }
@ -1275,7 +1275,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned flags)
if (S_ISGITLINK(ce->ce_mode)) if (S_ISGITLINK(ce->ce_mode))
continue; continue;
blob = lookup_blob(ce->oid.hash); blob = lookup_blob(&ce->oid);
if (!blob) if (!blob)
die("unable to add index blob to traversal"); die("unable to add index blob to traversal");
add_pending_object_with_path(revs, &blob->object, "", add_pending_object_with_path(revs, &blob->object, "",
@ -1292,7 +1292,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned flags)
static int add_parents_only(struct rev_info *revs, const char *arg_, int flags, static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
int exclude_parent) int exclude_parent)
{ {
unsigned char sha1[20]; struct object_id oid;
struct object *it; struct object *it;
struct commit *commit; struct commit *commit;
struct commit_list *parents; struct commit_list *parents;
@ -1303,17 +1303,17 @@ static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
flags ^= UNINTERESTING | BOTTOM; flags ^= UNINTERESTING | BOTTOM;
arg++; arg++;
} }
if (get_sha1_committish(arg, sha1)) if (get_sha1_committish(arg, oid.hash))
return 0; return 0;
while (1) { while (1) {
it = get_reference(revs, arg, sha1, 0); it = get_reference(revs, arg, &oid, 0);
if (!it && revs->ignore_missing) if (!it && revs->ignore_missing)
return 0; return 0;
if (it->type != OBJ_TAG) if (it->type != OBJ_TAG)
break; break;
if (!((struct tag*)it)->tagged) if (!((struct tag*)it)->tagged)
return 0; return 0;
hashcpy(sha1, ((struct tag*)it)->tagged->oid.hash); oidcpy(&oid, &((struct tag*)it)->tagged->oid);
} }
if (it->type != OBJ_COMMIT) if (it->type != OBJ_COMMIT)
return 0; return 0;
@ -1389,16 +1389,16 @@ static void prepare_show_merge(struct rev_info *revs)
{ {
struct commit_list *bases; struct commit_list *bases;
struct commit *head, *other; struct commit *head, *other;
unsigned char sha1[20]; struct object_id oid;
const char **prune = NULL; const char **prune = NULL;
int i, prune_num = 1; /* counting terminating NULL */ int i, prune_num = 1; /* counting terminating NULL */
if (get_sha1("HEAD", sha1)) if (get_oid("HEAD", &oid))
die("--merge without HEAD?"); die("--merge without HEAD?");
head = lookup_commit_or_die(sha1, "HEAD"); head = lookup_commit_or_die(&oid, "HEAD");
if (get_sha1("MERGE_HEAD", sha1)) if (get_oid("MERGE_HEAD", &oid))
die("--merge without MERGE_HEAD?"); die("--merge without MERGE_HEAD?");
other = lookup_commit_or_die(sha1, "MERGE_HEAD"); other = lookup_commit_or_die(&oid, "MERGE_HEAD");
add_pending_object(revs, &head->object, "HEAD"); add_pending_object(revs, &head->object, "HEAD");
add_pending_object(revs, &other->object, "MERGE_HEAD"); add_pending_object(revs, &other->object, "MERGE_HEAD");
bases = get_merge_bases(head, other); bases = get_merge_bases(head, other);
@ -1434,7 +1434,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
struct object_context oc; struct object_context oc;
char *dotdot; char *dotdot;
struct object *object; struct object *object;
unsigned char sha1[20]; struct object_id oid;
int local_flags; int local_flags;
const char *arg = arg_; const char *arg = arg_;
int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME; int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME;
@ -1444,7 +1444,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
dotdot = strstr(arg, ".."); dotdot = strstr(arg, "..");
if (dotdot) { if (dotdot) {
unsigned char from_sha1[20]; struct object_id from_oid;
const char *next = dotdot + 2; const char *next = dotdot + 2;
const char *this = arg; const char *this = arg;
int symmetric = *next == '.'; int symmetric = *next == '.';
@ -1470,8 +1470,8 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
return -1; return -1;
} }
} }
if (!get_sha1_committish(this, from_sha1) && if (!get_sha1_committish(this, from_oid.hash) &&
!get_sha1_committish(next, sha1)) { !get_sha1_committish(next, oid.hash)) {
struct object *a_obj, *b_obj; struct object *a_obj, *b_obj;
if (!cant_be_filename) { if (!cant_be_filename) {
@ -1479,8 +1479,8 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
verify_non_filename(revs->prefix, arg); verify_non_filename(revs->prefix, arg);
} }
a_obj = parse_object(from_sha1); a_obj = parse_object(&from_oid);
b_obj = parse_object(sha1); b_obj = parse_object(&oid);
if (!a_obj || !b_obj) { if (!a_obj || !b_obj) {
missing: missing:
if (revs->ignore_missing) if (revs->ignore_missing)
@ -1500,10 +1500,10 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
a = (a_obj->type == OBJ_COMMIT a = (a_obj->type == OBJ_COMMIT
? (struct commit *)a_obj ? (struct commit *)a_obj
: lookup_commit_reference(a_obj->oid.hash)); : lookup_commit_reference(&a_obj->oid));
b = (b_obj->type == OBJ_COMMIT b = (b_obj->type == OBJ_COMMIT
? (struct commit *)b_obj ? (struct commit *)b_obj
: lookup_commit_reference(b_obj->oid.hash)); : lookup_commit_reference(&b_obj->oid));
if (!a || !b) if (!a || !b)
goto missing; goto missing;
exclude = get_merge_bases(a, b); exclude = get_merge_bases(a, b);
@ -1568,11 +1568,11 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
if (revarg_opt & REVARG_COMMITTISH) if (revarg_opt & REVARG_COMMITTISH)
get_sha1_flags = GET_SHA1_COMMITTISH; get_sha1_flags = GET_SHA1_COMMITTISH;
if (get_sha1_with_context(arg, get_sha1_flags, sha1, &oc)) if (get_sha1_with_context(arg, get_sha1_flags, oid.hash, &oc))
return revs->ignore_missing ? 0 : -1; return revs->ignore_missing ? 0 : -1;
if (!cant_be_filename) if (!cant_be_filename)
verify_non_filename(revs->prefix, arg); verify_non_filename(revs->prefix, arg);
object = get_reference(revs, arg, sha1, flags ^ local_flags); object = get_reference(revs, arg, &oid, flags ^ local_flags);
add_rev_cmdline(revs, object, arg_, REV_CMD_REV, flags ^ local_flags); add_rev_cmdline(revs, object, arg_, REV_CMD_REV, flags ^ local_flags);
add_pending_object_with_mode(revs, object, arg, oc.mode); add_pending_object_with_mode(revs, object, arg, oc.mode);
return 0; return 0;
@ -2287,12 +2287,12 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
if (revs->show_merge) if (revs->show_merge)
prepare_show_merge(revs); prepare_show_merge(revs);
if (revs->def && !revs->pending.nr && !got_rev_arg) { if (revs->def && !revs->pending.nr && !got_rev_arg) {
unsigned char sha1[20]; struct object_id oid;
struct object *object; struct object *object;
struct object_context oc; struct object_context oc;
if (get_sha1_with_context(revs->def, 0, sha1, &oc)) if (get_sha1_with_context(revs->def, 0, oid.hash, &oc))
diagnose_missing_default(revs->def); diagnose_missing_default(revs->def);
object = get_reference(revs, revs->def, sha1, 0); object = get_reference(revs, revs->def, &oid, 0);
add_pending_object_with_mode(revs, object, revs->def, oc.mode); add_pending_object_with_mode(revs, object, revs->def, oc.mode);
} }

View File

@ -263,9 +263,9 @@ extern void show_object_with_name(FILE *, struct object *, const char *);
extern void add_pending_object(struct rev_info *revs, extern void add_pending_object(struct rev_info *revs,
struct object *obj, const char *name); struct object *obj, const char *name);
extern void add_pending_sha1(struct rev_info *revs, extern void add_pending_oid(struct rev_info *revs,
const char *name, const unsigned char *sha1, const char *name, const struct object_id *oid,
unsigned int flags); unsigned int flags);
extern void add_head_to_pending(struct rev_info *); extern void add_head_to_pending(struct rev_info *);
extern void add_reflogs_to_pending(struct rev_info *, unsigned int flags); extern void add_reflogs_to_pending(struct rev_info *, unsigned int flags);

View File

@ -344,7 +344,7 @@ static int read_oneliner(struct strbuf *buf,
static struct tree *empty_tree(void) static struct tree *empty_tree(void)
{ {
return lookup_tree(EMPTY_TREE_SHA1_BIN); return lookup_tree(&empty_tree_oid);
} }
static int error_dirty_index(struct replay_opts *opts) static int error_dirty_index(struct replay_opts *opts)
@ -374,7 +374,7 @@ static void update_abort_safety_file(void)
write_file(git_path_abort_safety_file(), "%s", ""); write_file(git_path_abort_safety_file(), "%s", "");
} }
static int fast_forward_to(const unsigned char *to, const unsigned char *from, static int fast_forward_to(const struct object_id *to, const struct object_id *from,
int unborn, struct replay_opts *opts) int unborn, struct replay_opts *opts)
{ {
struct ref_transaction *transaction; struct ref_transaction *transaction;
@ -390,7 +390,7 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from,
transaction = ref_transaction_begin(&err); transaction = ref_transaction_begin(&err);
if (!transaction || if (!transaction ||
ref_transaction_update(transaction, "HEAD", ref_transaction_update(transaction, "HEAD",
to, unborn ? null_sha1 : from, to->hash, unborn ? null_sha1 : from->hash,
0, sb.buf, &err) || 0, sb.buf, &err) ||
ref_transaction_commit(transaction, &err)) { ref_transaction_commit(transaction, &err)) {
ref_transaction_free(transaction); ref_transaction_free(transaction);
@ -426,7 +426,7 @@ void append_conflicts_hint(struct strbuf *msgbuf)
static int do_recursive_merge(struct commit *base, struct commit *next, static int do_recursive_merge(struct commit *base, struct commit *next,
const char *base_label, const char *next_label, const char *base_label, const char *next_label,
unsigned char *head, struct strbuf *msgbuf, struct object_id *head, struct strbuf *msgbuf,
struct replay_opts *opts) struct replay_opts *opts)
{ {
struct merge_options o; struct merge_options o;
@ -482,13 +482,13 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
static int is_index_unchanged(void) static int is_index_unchanged(void)
{ {
unsigned char head_sha1[20]; struct object_id head_oid;
struct commit *head_commit; struct commit *head_commit;
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_sha1, NULL)) if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
return error(_("could not resolve HEAD commit\n")); return error(_("could not resolve HEAD commit\n"));
head_commit = lookup_commit(head_sha1); head_commit = lookup_commit(&head_oid);
/* /*
* If head_commit is NULL, check_commit, called from * If head_commit is NULL, check_commit, called from
@ -508,7 +508,8 @@ static int is_index_unchanged(void)
if (cache_tree_update(&the_index, 0)) if (cache_tree_update(&the_index, 0))
return error(_("unable to update cache tree\n")); return error(_("unable to update cache tree\n"));
return !hashcmp(active_cache_tree->sha1, head_commit->tree->object.oid.hash); return !oidcmp(&active_cache_tree->oid,
&head_commit->tree->object.oid);
} }
static int write_author_script(const char *message) static int write_author_script(const char *message)
@ -834,13 +835,13 @@ static int update_squash_messages(enum todo_command command,
strbuf_splice(&buf, 0, eol - buf.buf, header.buf, header.len); strbuf_splice(&buf, 0, eol - buf.buf, header.buf, header.len);
strbuf_release(&header); strbuf_release(&header);
} else { } else {
unsigned char head[20]; struct object_id head;
struct commit *head_commit; struct commit *head_commit;
const char *head_message, *body; const char *head_message, *body;
if (get_sha1("HEAD", head)) if (get_oid("HEAD", &head))
return error(_("need a HEAD to fixup")); return error(_("need a HEAD to fixup"));
if (!(head_commit = lookup_commit_reference(head))) if (!(head_commit = lookup_commit_reference(&head)))
return error(_("could not read HEAD")); return error(_("could not read HEAD"));
if (!(head_message = get_commit_buffer(head_commit, NULL))) if (!(head_message = get_commit_buffer(head_commit, NULL)))
return error(_("could not read HEAD's commit message")); return error(_("could not read HEAD's commit message"));
@ -934,7 +935,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
{ {
unsigned int flags = opts->edit ? EDIT_MSG : 0; unsigned int flags = opts->edit ? EDIT_MSG : 0;
const char *msg_file = opts->edit ? NULL : git_path_merge_msg(); const char *msg_file = opts->edit ? NULL : git_path_merge_msg();
unsigned char head[20]; struct object_id head;
struct commit *base, *next, *parent; struct commit *base, *next, *parent;
const char *base_label, *next_label; const char *base_label, *next_label;
struct commit_message msg = { NULL, NULL, NULL, NULL }; struct commit_message msg = { NULL, NULL, NULL, NULL };
@ -948,12 +949,12 @@ 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, 0, NULL)) if (write_cache_as_tree(head.hash, 0, NULL))
return error(_("your index file is unmerged.")); return error(_("your index file is unmerged."));
} else { } else {
unborn = get_sha1("HEAD", head); unborn = get_oid("HEAD", &head);
if (unborn) if (unborn)
hashcpy(head, EMPTY_TREE_SHA1_BIN); oidcpy(&head, &empty_tree_oid);
if (index_differs_from(unborn ? EMPTY_TREE_SHA1_HEX : "HEAD", 0, 0)) if (index_differs_from(unborn ? EMPTY_TREE_SHA1_HEX : "HEAD", 0, 0))
return error_dirty_index(opts); return error_dirty_index(opts);
} }
@ -989,11 +990,11 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
oid_to_hex(&commit->object.oid)); oid_to_hex(&commit->object.oid));
if (opts->allow_ff && !is_fixup(command) && if (opts->allow_ff && !is_fixup(command) &&
((parent && !hashcmp(parent->object.oid.hash, head)) || ((parent && !oidcmp(&parent->object.oid, &head)) ||
(!parent && unborn))) { (!parent && unborn))) {
if (is_rebase_i(opts)) if (is_rebase_i(opts))
write_author_script(msg.message); write_author_script(msg.message);
res = fast_forward_to(commit->object.oid.hash, head, unborn, res = fast_forward_to(&commit->object.oid, &head, unborn,
opts); opts);
if (res || command != TODO_REWORD) if (res || command != TODO_REWORD)
goto leave; goto leave;
@ -1081,7 +1082,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
res = -1; res = -1;
else if (!opts->strategy || !strcmp(opts->strategy, "recursive") || command == TODO_REVERT) { else if (!opts->strategy || !strcmp(opts->strategy, "recursive") || command == TODO_REVERT) {
res = do_recursive_merge(base, next, base_label, next_label, res = do_recursive_merge(base, next, base_label, next_label,
head, &msgbuf, opts); &head, &msgbuf, opts);
if (res < 0) if (res < 0)
return res; return res;
res |= write_message(msgbuf.buf, msgbuf.len, res |= write_message(msgbuf.buf, msgbuf.len,
@ -1097,7 +1098,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
commit_list_insert(next, &remotes); commit_list_insert(next, &remotes);
res |= try_merge_command(opts->strategy, res |= try_merge_command(opts->strategy,
opts->xopts_nr, (const char **)opts->xopts, opts->xopts_nr, (const char **)opts->xopts,
common, sha1_to_hex(head), remotes); common, oid_to_hex(&head), remotes);
free_commit_list(common); free_commit_list(common);
free_commit_list(remotes); free_commit_list(remotes);
} }
@ -1222,7 +1223,7 @@ static struct todo_item *append_new_todo(struct todo_list *todo_list)
static int parse_insn_line(struct todo_item *item, const char *bol, char *eol) static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
{ {
unsigned char commit_sha1[20]; struct object_id commit_oid;
char *end_of_object_name; char *end_of_object_name;
int i, saved, status, padding; int i, saved, status, padding;
@ -1271,7 +1272,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
end_of_object_name = (char *) bol + strcspn(bol, " \t\n"); end_of_object_name = (char *) bol + strcspn(bol, " \t\n");
saved = *end_of_object_name; saved = *end_of_object_name;
*end_of_object_name = '\0'; *end_of_object_name = '\0';
status = get_sha1(bol, commit_sha1); status = get_oid(bol, &commit_oid);
*end_of_object_name = saved; *end_of_object_name = saved;
item->arg = end_of_object_name + strspn(end_of_object_name, " \t"); item->arg = end_of_object_name + strspn(end_of_object_name, " \t");
@ -1280,7 +1281,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
if (status < 0) if (status < 0)
return -1; return -1;
item->commit = lookup_commit_reference(commit_sha1); item->commit = lookup_commit_reference(&commit_oid);
return !item->commit; return !item->commit;
} }
@ -2281,7 +2282,7 @@ static int single_pick(struct commit *cmit, struct replay_opts *opts)
int sequencer_pick_revisions(struct replay_opts *opts) int sequencer_pick_revisions(struct replay_opts *opts)
{ {
struct todo_list todo_list = TODO_LIST_INIT; struct todo_list todo_list = TODO_LIST_INIT;
unsigned char sha1[20]; struct object_id oid;
int i, res; int i, res;
assert(opts->revs); assert(opts->revs);
@ -2289,16 +2290,16 @@ int sequencer_pick_revisions(struct replay_opts *opts)
return -1; return -1;
for (i = 0; i < opts->revs->pending.nr; i++) { for (i = 0; i < opts->revs->pending.nr; i++) {
unsigned char sha1[20]; struct object_id oid;
const char *name = opts->revs->pending.objects[i].name; const char *name = opts->revs->pending.objects[i].name;
/* This happens when using --stdin. */ /* This happens when using --stdin. */
if (!strlen(name)) if (!strlen(name))
continue; continue;
if (!get_sha1(name, sha1)) { if (!get_oid(name, &oid)) {
if (!lookup_commit_reference_gently(sha1, 1)) { if (!lookup_commit_reference_gently(&oid, 1)) {
enum object_type type = sha1_object_info(sha1, NULL); enum object_type type = sha1_object_info(oid.hash, NULL);
return error(_("%s: can't cherry-pick a %s"), return error(_("%s: can't cherry-pick a %s"),
name, typename(type)); name, typename(type));
} }
@ -2335,9 +2336,9 @@ int sequencer_pick_revisions(struct replay_opts *opts)
if (walk_revs_populate_todo(&todo_list, opts) || if (walk_revs_populate_todo(&todo_list, opts) ||
create_seq_dir() < 0) create_seq_dir() < 0)
return -1; return -1;
if (get_sha1("HEAD", sha1) && (opts->action == REPLAY_REVERT)) if (get_oid("HEAD", &oid) && (opts->action == REPLAY_REVERT))
return error(_("can't revert as initial commit")); return error(_("can't revert as initial commit"));
if (save_head(sha1_to_hex(sha1))) if (save_head(oid_to_hex(&oid)))
return -1; return -1;
if (save_opts(opts)) if (save_opts(opts))
return -1; return -1;

View File

@ -53,7 +53,7 @@ static int add_info_ref(const char *path, const struct object_id *oid,
int flag, void *cb_data) int flag, void *cb_data)
{ {
FILE *fp = cb_data; FILE *fp = cb_data;
struct object *o = parse_object(oid->hash); struct object *o = parse_object(oid);
if (!o) if (!o)
return -1; return -1;

View File

@ -241,7 +241,7 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da
return 0; return 0;
/* We need to do this the hard way... */ /* We need to do this the hard way... */
obj = deref_tag(parse_object(oid->hash), NULL, 0); obj = deref_tag(parse_object(oid), NULL, 0);
if (obj && obj->type == OBJ_COMMIT) if (obj && obj->type == OBJ_COMMIT)
return 1; return 1;
return 0; return 0;
@ -265,7 +265,7 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_
return 0; return 0;
/* We need to do this the hard way... */ /* We need to do this the hard way... */
obj = deref_tag(parse_object(oid->hash), NULL, 0); obj = deref_tag(parse_object(oid), NULL, 0);
if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT)) if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
return 1; return 1;
return 0; return 0;
@ -354,14 +354,14 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
type = sha1_object_info(oid->hash, NULL); type = sha1_object_info(oid->hash, NULL);
if (type == OBJ_COMMIT) { if (type == OBJ_COMMIT) {
struct commit *commit = lookup_commit(oid->hash); struct commit *commit = lookup_commit(oid);
if (commit) { if (commit) {
struct pretty_print_context pp = {0}; struct pretty_print_context pp = {0};
pp.date_mode.type = DATE_SHORT; pp.date_mode.type = DATE_SHORT;
format_commit_message(commit, " %ad - %s", &desc, &pp); format_commit_message(commit, " %ad - %s", &desc, &pp);
} }
} else if (type == OBJ_TAG) { } else if (type == OBJ_TAG) {
struct tag *tag = lookup_tag(oid->hash); struct tag *tag = lookup_tag(oid);
if (!parse_tag(tag) && tag->tag) if (!parse_tag(tag) && tag->tag)
strbuf_addf(&desc, " %s", tag->tag); strbuf_addf(&desc, " %s", tag->tag);
} }
@ -722,14 +722,14 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
static int get_parent(const char *name, int len, static int get_parent(const char *name, int len,
unsigned char *result, int idx) unsigned char *result, int idx)
{ {
unsigned char sha1[20]; struct object_id oid;
int ret = get_sha1_1(name, len, sha1, GET_SHA1_COMMITTISH); int ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH);
struct commit *commit; struct commit *commit;
struct commit_list *p; struct commit_list *p;
if (ret) if (ret)
return ret; return ret;
commit = lookup_commit_reference(sha1); commit = lookup_commit_reference(&oid);
if (parse_commit(commit)) if (parse_commit(commit))
return -1; return -1;
if (!idx) { if (!idx) {
@ -750,14 +750,14 @@ static int get_parent(const char *name, int len,
static int get_nth_ancestor(const char *name, int len, static int get_nth_ancestor(const char *name, int len,
unsigned char *result, int generation) unsigned char *result, int generation)
{ {
unsigned char sha1[20]; struct object_id oid;
struct commit *commit; struct commit *commit;
int ret; int ret;
ret = get_sha1_1(name, len, sha1, GET_SHA1_COMMITTISH); ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH);
if (ret) if (ret)
return ret; return ret;
commit = lookup_commit_reference(sha1); commit = lookup_commit_reference(&oid);
if (!commit) if (!commit)
return -1; return -1;
@ -776,7 +776,7 @@ struct object *peel_to_type(const char *name, int namelen,
if (name && !namelen) if (name && !namelen)
namelen = strlen(name); namelen = strlen(name);
while (1) { while (1) {
if (!o || (!o->parsed && !parse_object(o->oid.hash))) if (!o || (!o->parsed && !parse_object(&o->oid)))
return NULL; return NULL;
if (expected_type == OBJ_ANY || o->type == expected_type) if (expected_type == OBJ_ANY || o->type == expected_type)
return o; return o;
@ -798,7 +798,7 @@ struct object *peel_to_type(const char *name, int namelen,
static int peel_onion(const char *name, int len, unsigned char *sha1, static int peel_onion(const char *name, int len, unsigned char *sha1,
unsigned lookup_flags) unsigned lookup_flags)
{ {
unsigned char outer[20]; struct object_id outer;
const char *sp; const char *sp;
unsigned int expected_type = 0; unsigned int expected_type = 0;
struct object *o; struct object *o;
@ -846,15 +846,15 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
else if (expected_type == OBJ_TREE) else if (expected_type == OBJ_TREE)
lookup_flags |= GET_SHA1_TREEISH; lookup_flags |= GET_SHA1_TREEISH;
if (get_sha1_1(name, sp - name - 2, outer, lookup_flags)) if (get_sha1_1(name, sp - name - 2, outer.hash, lookup_flags))
return -1; return -1;
o = parse_object(outer); o = parse_object(&outer);
if (!o) if (!o)
return -1; return -1;
if (!expected_type) { if (!expected_type) {
o = deref_tag(o, name, sp - name - 2); o = deref_tag(o, name, sp - name - 2);
if (!o || (!o->parsed && !parse_object(o->oid.hash))) if (!o || (!o->parsed && !parse_object(&o->oid)))
return -1; return -1;
hashcpy(sha1, o->oid.hash); hashcpy(sha1, o->oid.hash);
return 0; return 0;
@ -981,7 +981,7 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
int flag, void *cb_data) int flag, void *cb_data)
{ {
struct commit_list **list = cb_data; struct commit_list **list = cb_data;
struct object *object = parse_object(oid->hash); struct object *object = parse_object(oid);
if (!object) if (!object)
return 0; return 0;
if (object->type == OBJ_TAG) { if (object->type == OBJ_TAG) {
@ -1027,7 +1027,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
int matches; int matches;
commit = pop_most_recent_commit(&list, ONELINE_SEEN); commit = pop_most_recent_commit(&list, ONELINE_SEEN);
if (!parse_object(commit->object.oid.hash)) if (!parse_object(&commit->object.oid))
continue; continue;
buf = get_commit_buffer(commit, NULL); buf = get_commit_buffer(commit, NULL);
p = strstr(buf, "\n\n"); p = strstr(buf, "\n\n");
@ -1136,13 +1136,13 @@ int get_oid_mb(const char *name, struct object_id *oid)
} }
if (st) if (st)
return st; return st;
one = lookup_commit_reference_gently(oid_tmp.hash, 0); one = lookup_commit_reference_gently(&oid_tmp, 0);
if (!one) if (!one)
return -1; return -1;
if (get_sha1_committish(dots[3] ? (dots + 3) : "HEAD", oid_tmp.hash)) if (get_sha1_committish(dots[3] ? (dots + 3) : "HEAD", oid_tmp.hash))
return -1; return -1;
two = lookup_commit_reference_gently(oid_tmp.hash, 0); two = lookup_commit_reference_gently(&oid_tmp, 0);
if (!two) if (!two)
return -1; return -1;
mbs = get_merge_bases(one, two); mbs = get_merge_bases(one, two);

View File

@ -27,13 +27,13 @@ void set_alternate_shallow_file(const char *path, int override)
alternate_shallow_file = xstrdup_or_null(path); alternate_shallow_file = xstrdup_or_null(path);
} }
int register_shallow(const unsigned char *sha1) int register_shallow(const struct object_id *oid)
{ {
struct commit_graft *graft = struct commit_graft *graft =
xmalloc(sizeof(struct commit_graft)); xmalloc(sizeof(struct commit_graft));
struct commit *commit = lookup_commit(sha1); struct commit *commit = lookup_commit(oid);
hashcpy(graft->oid.hash, sha1); oidcpy(&graft->oid, oid);
graft->nr_parent = -1; graft->nr_parent = -1;
if (commit && commit->object.parsed) if (commit && commit->object.parsed)
commit->parents = NULL; commit->parents = NULL;
@ -65,10 +65,10 @@ int is_repository_shallow(void)
is_shallow = 1; is_shallow = 1;
while (fgets(buf, sizeof(buf), fp)) { while (fgets(buf, sizeof(buf), fp)) {
unsigned char sha1[20]; struct object_id oid;
if (get_sha1_hex(buf, sha1)) if (get_oid_hex(buf, &oid))
die("bad shallow line: %s", buf); die("bad shallow line: %s", buf);
register_shallow(sha1); register_shallow(&oid);
} }
fclose(fp); fclose(fp);
return is_shallow; return is_shallow;
@ -241,7 +241,7 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
if (graft->nr_parent != -1) if (graft->nr_parent != -1)
return 0; return 0;
if (data->flags & SEEN_ONLY) { if (data->flags & SEEN_ONLY) {
struct commit *c = lookup_commit(graft->oid.hash); struct commit *c = lookup_commit(&graft->oid);
if (!c || !(c->object.flags & SEEN)) { if (!c || !(c->object.flags & SEEN)) {
if (data->flags & VERBOSE) if (data->flags & VERBOSE)
printf("Removing %s from .git/shallow\n", printf("Removing %s from .git/shallow\n",
@ -466,7 +466,7 @@ static uint32_t *paint_alloc(struct paint_info *info)
* UNINTERESTING or BOTTOM is hit. Set the id-th bit in ref_bitmap for * UNINTERESTING or BOTTOM is hit. Set the id-th bit in ref_bitmap for
* all walked commits. * all walked commits.
*/ */
static void paint_down(struct paint_info *info, const unsigned char *sha1, static void paint_down(struct paint_info *info, const struct object_id *oid,
unsigned int id) unsigned int id)
{ {
unsigned int i, nr; unsigned int i, nr;
@ -475,7 +475,7 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,
size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr); size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr);
uint32_t *tmp = xmalloc(bitmap_size); /* to be freed before return */ uint32_t *tmp = xmalloc(bitmap_size); /* to be freed before return */
uint32_t *bitmap = paint_alloc(info); uint32_t *bitmap = paint_alloc(info);
struct commit *c = lookup_commit_reference_gently(sha1, 1); struct commit *c = lookup_commit_reference_gently(oid, 1);
if (!c) if (!c)
return; return;
memset(bitmap, 0, bitmap_size); memset(bitmap, 0, bitmap_size);
@ -531,7 +531,7 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,
static int mark_uninteresting(const char *refname, const struct object_id *oid, static int mark_uninteresting(const char *refname, const struct object_id *oid,
int flags, void *cb_data) int flags, void *cb_data)
{ {
struct commit *commit = lookup_commit_reference_gently(oid->hash, 1); struct commit *commit = lookup_commit_reference_gently(oid, 1);
if (!commit) if (!commit)
return 0; return 0;
commit->object.flags |= UNINTERESTING; commit->object.flags |= UNINTERESTING;
@ -599,18 +599,18 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
/* Mark potential bottoms so we won't go out of bound */ /* Mark potential bottoms so we won't go out of bound */
for (i = 0; i < nr_shallow; i++) { for (i = 0; i < nr_shallow; i++) {
struct commit *c = lookup_commit(oid[shallow[i]].hash); struct commit *c = lookup_commit(&oid[shallow[i]]);
c->object.flags |= BOTTOM; c->object.flags |= BOTTOM;
} }
for (i = 0; i < ref->nr; i++) for (i = 0; i < ref->nr; i++)
paint_down(&pi, ref->oid[i].hash, i); paint_down(&pi, ref->oid + i, i);
if (used) { if (used) {
int bitmap_size = ((pi.nr_bits + 31) / 32) * sizeof(uint32_t); int bitmap_size = ((pi.nr_bits + 31) / 32) * sizeof(uint32_t);
memset(used, 0, sizeof(*used) * info->shallow->nr); memset(used, 0, sizeof(*used) * info->shallow->nr);
for (i = 0; i < nr_shallow; i++) { for (i = 0; i < nr_shallow; i++) {
const struct commit *c = lookup_commit(oid[shallow[i]].hash); const struct commit *c = lookup_commit(&oid[shallow[i]]);
uint32_t **map = ref_bitmap_at(&pi.ref_bitmap, c); uint32_t **map = ref_bitmap_at(&pi.ref_bitmap, c);
if (*map) if (*map)
used[shallow[i]] = xmemdupz(*map, bitmap_size); used[shallow[i]] = xmemdupz(*map, bitmap_size);
@ -641,7 +641,7 @@ static int add_ref(const char *refname, const struct object_id *oid,
{ {
struct commit_array *ca = cb_data; struct commit_array *ca = cb_data;
ALLOC_GROW(ca->commits, ca->nr + 1, ca->alloc); ALLOC_GROW(ca->commits, ca->nr + 1, ca->alloc);
ca->commits[ca->nr] = lookup_commit_reference_gently(oid->hash, 1); ca->commits[ca->nr] = lookup_commit_reference_gently(oid, 1);
if (ca->commits[ca->nr]) if (ca->commits[ca->nr])
ca->nr++; ca->nr++;
return 0; return 0;
@ -679,7 +679,7 @@ static void post_assign_shallow(struct shallow_info *info,
for (i = dst = 0; i < info->nr_theirs; i++) { for (i = dst = 0; i < info->nr_theirs; i++) {
if (i != dst) if (i != dst)
info->theirs[dst] = info->theirs[i]; info->theirs[dst] = info->theirs[i];
c = lookup_commit(oid[info->theirs[i]].hash); c = lookup_commit(&oid[info->theirs[i]]);
bitmap = ref_bitmap_at(ref_bitmap, c); bitmap = ref_bitmap_at(ref_bitmap, c);
if (!*bitmap) if (!*bitmap)
continue; continue;
@ -700,7 +700,7 @@ static void post_assign_shallow(struct shallow_info *info,
for (i = dst = 0; i < info->nr_ours; i++) { for (i = dst = 0; i < info->nr_ours; i++) {
if (i != dst) if (i != dst)
info->ours[dst] = info->ours[i]; info->ours[dst] = info->ours[i];
c = lookup_commit(oid[info->ours[i]].hash); c = lookup_commit(&oid[info->ours[i]]);
bitmap = ref_bitmap_at(ref_bitmap, c); bitmap = ref_bitmap_at(ref_bitmap, c);
if (!*bitmap) if (!*bitmap)
continue; continue;
@ -722,7 +722,7 @@ static void post_assign_shallow(struct shallow_info *info,
int delayed_reachability_test(struct shallow_info *si, int c) int delayed_reachability_test(struct shallow_info *si, int c)
{ {
if (si->need_reachability_test[c]) { if (si->need_reachability_test[c]) {
struct commit *commit = lookup_commit(si->shallow->oid[c].hash); struct commit *commit = lookup_commit(&si->shallow->oid[c]);
if (!si->commits) { if (!si->commits) {
struct commit_array ca; struct commit_array ca;

View File

@ -447,8 +447,8 @@ static void show_submodule_header(FILE *f, const char *path,
* Attempt to lookup the commit references, and determine if this is * Attempt to lookup the commit references, and determine if this is
* a fast forward or fast backwards update. * a fast forward or fast backwards update.
*/ */
*left = lookup_commit_reference(one->hash); *left = lookup_commit_reference(one);
*right = lookup_commit_reference(two->hash); *right = lookup_commit_reference(two);
/* /*
* Warn about missing commits in the submodule project, but only if * Warn about missing commits in the submodule project, but only if
@ -722,7 +722,7 @@ static int check_has_commit(const struct object_id *oid, void *data)
{ {
int *has_commit = data; int *has_commit = data;
if (!lookup_commit_reference(oid->hash)) if (!lookup_commit_reference(oid))
*has_commit = 0; *has_commit = 0;
return 0; return 0;
@ -1559,9 +1559,9 @@ static void print_commit(struct commit *commit)
#define MERGE_WARNING(path, msg) \ #define MERGE_WARNING(path, msg) \
warning("Failed to merge submodule %s (%s)", path, msg); warning("Failed to merge submodule %s (%s)", path, msg);
int merge_submodule(unsigned char result[20], const char *path, int merge_submodule(struct object_id *result, const char *path,
const unsigned char base[20], const unsigned char a[20], const struct object_id *base, const struct object_id *a,
const unsigned char b[20], int search) const struct object_id *b, int search)
{ {
struct commit *commit_base, *commit_a, *commit_b; struct commit *commit_base, *commit_a, *commit_b;
int parent_count; int parent_count;
@ -1570,14 +1570,14 @@ int merge_submodule(unsigned char result[20], const char *path,
int i; int i;
/* store a in result in case we fail */ /* store a in result in case we fail */
hashcpy(result, a); oidcpy(result, a);
/* we can not handle deletion conflicts */ /* we can not handle deletion conflicts */
if (is_null_sha1(base)) if (is_null_oid(base))
return 0; return 0;
if (is_null_sha1(a)) if (is_null_oid(a))
return 0; return 0;
if (is_null_sha1(b)) if (is_null_oid(b))
return 0; return 0;
if (add_submodule_odb(path)) { if (add_submodule_odb(path)) {
@ -1601,11 +1601,11 @@ int merge_submodule(unsigned char result[20], const char *path,
/* Case #1: a is contained in b or vice versa */ /* Case #1: a is contained in b or vice versa */
if (in_merge_bases(commit_a, commit_b)) { if (in_merge_bases(commit_a, commit_b)) {
hashcpy(result, b); oidcpy(result, b);
return 1; return 1;
} }
if (in_merge_bases(commit_b, commit_a)) { if (in_merge_bases(commit_b, commit_a)) {
hashcpy(result, a); oidcpy(result, a);
return 1; return 1;
} }

View File

@ -84,10 +84,10 @@ extern int submodule_uses_gitfile(const char *path);
#define SUBMODULE_REMOVAL_IGNORE_UNTRACKED (1<<1) #define SUBMODULE_REMOVAL_IGNORE_UNTRACKED (1<<1)
#define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<2) #define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<2)
extern int bad_to_remove_submodule(const char *path, unsigned flags); extern int bad_to_remove_submodule(const char *path, unsigned flags);
extern int merge_submodule(unsigned char result[20], const char *path, extern int merge_submodule(struct object_id *result, const char *path,
const unsigned char base[20], const struct object_id *base,
const unsigned char a[20], const struct object_id *a,
const unsigned char b[20], int search); const struct object_id *b, int search);
extern int find_unpushed_submodules(struct oid_array *commits, extern int find_unpushed_submodules(struct oid_array *commits,
const char *remotes_name, const char *remotes_name,
struct string_list *needs_pushing); struct string_list *needs_pushing);

View File

@ -10,7 +10,7 @@ static void dump_one(struct cache_tree *it, const char *pfx, const char *x)
"invalid", x, pfx, it->subtree_nr); "invalid", x, pfx, it->subtree_nr);
else else
printf("%s %s%s (%d entries, %d subtrees)\n", printf("%s %s%s (%d entries, %d subtrees)\n",
sha1_to_hex(it->sha1), x, pfx, oid_to_hex(&it->oid), x, pfx,
it->entry_count, it->subtree_nr); it->entry_count, it->subtree_nr);
} }
@ -32,7 +32,7 @@ static int dump_cache_tree(struct cache_tree *it,
} }
else { else {
dump_one(it, pfx, ""); dump_one(it, pfx, "");
if (hashcmp(it->sha1, ref->sha1) || if (oidcmp(&it->oid, &ref->oid) ||
ref->entry_count != it->entry_count || ref->entry_count != it->entry_count ||
ref->subtree_nr != it->subtree_nr) { ref->subtree_nr != it->subtree_nr) {
/* claims to be valid but is lying */ /* claims to be valid but is lying */

View File

@ -12,10 +12,10 @@ int cmd_main(int ac, const char **av)
die("cannot parse %s as an object name", av[1]); die("cannot parse %s as an object name", av[1]);
if (get_oid(av[2], &hash2)) if (get_oid(av[2], &hash2))
die("cannot parse %s as an object name", av[2]); die("cannot parse %s as an object name", av[2]);
one = parse_tree_indirect(hash1.hash); one = parse_tree_indirect(&hash1);
if (!one) if (!one)
die("not a tree-ish %s", av[1]); die("not a tree-ish %s", av[1]);
two = parse_tree_indirect(hash2.hash); two = parse_tree_indirect(&hash2);
if (!two) if (!two)
die("not a tree-ish %s", av[2]); die("not a tree-ish %s", av[2]);

25
tag.c
View File

@ -66,7 +66,7 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)
{ {
while (o && o->type == OBJ_TAG) while (o && o->type == OBJ_TAG)
if (((struct tag *)o)->tagged) if (((struct tag *)o)->tagged)
o = parse_object(((struct tag *)o)->tagged->oid.hash); o = parse_object(&((struct tag *)o)->tagged->oid);
else else
o = NULL; o = NULL;
if (!o && warn) { if (!o && warn) {
@ -80,7 +80,7 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)
struct object *deref_tag_noverify(struct object *o) struct object *deref_tag_noverify(struct object *o)
{ {
while (o && o->type == OBJ_TAG) { while (o && o->type == OBJ_TAG) {
o = parse_object(o->oid.hash); o = parse_object(&o->oid);
if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged) if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged)
o = ((struct tag *)o)->tagged; o = ((struct tag *)o)->tagged;
else else
@ -89,11 +89,11 @@ struct object *deref_tag_noverify(struct object *o)
return o; return o;
} }
struct tag *lookup_tag(const unsigned char *sha1) struct tag *lookup_tag(const struct object_id *oid)
{ {
struct object *obj = lookup_object(sha1); struct object *obj = lookup_object(oid->hash);
if (!obj) if (!obj)
return create_object(sha1, alloc_tag_node()); return create_object(oid->hash, alloc_tag_node());
return object_as_type(obj, OBJ_TAG, 0); return object_as_type(obj, OBJ_TAG, 0);
} }
@ -116,7 +116,7 @@ static timestamp_t parse_tag_date(const char *buf, const char *tail)
int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
{ {
unsigned char sha1[20]; struct object_id oid;
char type[20]; char type[20];
const char *bufptr = data; const char *bufptr = data;
const char *tail = bufptr + size; const char *tail = bufptr + size;
@ -126,11 +126,10 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
return 0; return 0;
item->object.parsed = 1; item->object.parsed = 1;
if (size < 64) if (size < GIT_SHA1_HEXSZ + 24)
return -1; return -1;
if (memcmp("object ", bufptr, 7) || get_sha1_hex(bufptr + 7, sha1) || bufptr[47] != '\n') if (memcmp("object ", bufptr, 7) || parse_oid_hex(bufptr + 7, &oid, &bufptr) || *bufptr++ != '\n')
return -1; return -1;
bufptr += 48; /* "object " + sha1 + "\n" */
if (!starts_with(bufptr, "type ")) if (!starts_with(bufptr, "type "))
return -1; return -1;
@ -143,13 +142,13 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
bufptr = nl + 1; bufptr = nl + 1;
if (!strcmp(type, blob_type)) { if (!strcmp(type, blob_type)) {
item->tagged = &lookup_blob(sha1)->object; item->tagged = &lookup_blob(&oid)->object;
} else if (!strcmp(type, tree_type)) { } else if (!strcmp(type, tree_type)) {
item->tagged = &lookup_tree(sha1)->object; item->tagged = &lookup_tree(&oid)->object;
} else if (!strcmp(type, commit_type)) { } else if (!strcmp(type, commit_type)) {
item->tagged = &lookup_commit(sha1)->object; item->tagged = &lookup_commit(&oid)->object;
} else if (!strcmp(type, tag_type)) { } else if (!strcmp(type, tag_type)) {
item->tagged = &lookup_tag(sha1)->object; item->tagged = &lookup_tag(&oid)->object;
} else { } else {
error("Unknown type %s", type); error("Unknown type %s", type);
item->tagged = NULL; item->tagged = NULL;

2
tag.h
View File

@ -12,7 +12,7 @@ struct tag {
timestamp_t date; timestamp_t date;
}; };
extern struct tag *lookup_tag(const unsigned char *sha1); extern struct tag *lookup_tag(const struct object_id *oid);
extern int parse_tag_buffer(struct tag *item, const void *data, unsigned long size); extern int parse_tag_buffer(struct tag *item, const void *data, unsigned long size);
extern int parse_tag(struct tag *item); extern int parse_tag(struct tag *item);
extern struct object *deref_tag(struct object *, const char *, int); extern struct object *deref_tag(struct object *, const char *, int);

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