Skip to content

Commit

Permalink
Merge branch 'bc/object-id'
Browse files Browse the repository at this point in the history
More transition from "unsigned char[40]" to "struct object_id".

This needed a few merge fixups, but is mostly disentangled from other
topics.

* bc/object-id:
  remote: convert functions to struct object_id
  Remove get_object_hash.
  Convert struct object to object_id
  Add several uses of get_object_hash.
  object: introduce get_object_hash macro.
  ref_newer: convert to use struct object_id
  push_refs_with_export: convert to struct object_id
  get_remote_heads: convert to struct object_id
  parse_fetch: convert to use struct object_id
  add_sought_entry_mem: convert to struct object_id
  Convert struct ref to use object_id.
  sha1_file: introduce has_object_file helper.
  • Loading branch information
Junio C Hamano committed Dec 10, 2015
2 parents b12a966 + fcd30b1 commit 844a9ce
Show file tree
Hide file tree
Showing 88 changed files with 716 additions and 704 deletions.
6 changes: 3 additions & 3 deletions archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ int write_archive_entries(struct archiver_args *args,
len--;
if (args->verbose)
fprintf(stderr, "%.*s\n", (int)len, args->base);
err = write_entry(args, args->tree->object.sha1, args->base,
err = write_entry(args, args->tree->object.oid.hash, args->base,
len, 040777);
if (err)
return err;
Expand Down Expand Up @@ -374,7 +374,7 @@ static void parse_treeish_arg(const char **argv,

commit = lookup_commit_reference_gently(oid.hash, 1);
if (commit) {
commit_sha1 = commit->object.sha1;
commit_sha1 = commit->object.oid.hash;
archive_time = commit->date;
} else {
commit_sha1 = NULL;
Expand All @@ -390,7 +390,7 @@ static void parse_treeish_arg(const char **argv,
unsigned int mode;
int err;

err = get_tree_entry(tree->object.sha1, prefix,
err = get_tree_entry(tree->object.oid.hash, prefix,
tree_oid.hash, &mode);
if (err || !S_ISDIR(mode))
die("current working directory is untracked");
Expand Down
10 changes: 5 additions & 5 deletions bisect.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static int compare_commit_dist(const void *a_, const void *b_)
b = (struct commit_dist *)b_;
if (a->distance != b->distance)
return b->distance - a->distance; /* desc sort */
return hashcmp(a->commit->object.sha1, b->commit->object.sha1);
return oidcmp(&a->commit->object.oid, &b->commit->object.oid);
}

static struct commit_list *best_bisection_sorted(struct commit_list *list, int nr)
Expand Down Expand Up @@ -500,7 +500,7 @@ struct commit_list *filter_skipped(struct commit_list *list,
struct commit_list *next = list->next;
list->next = NULL;
if (0 <= sha1_array_lookup(&skipped_revs,
list->item->object.sha1)) {
list->item->object.oid.hash)) {
if (skipped_first && !*skipped_first)
*skipped_first = 1;
/* Move current to tried list */
Expand Down Expand Up @@ -575,7 +575,7 @@ static struct commit_list *skip_away(struct commit_list *list, int count)

for (i = 0; cur; cur = cur->next, i++) {
if (i == index) {
if (hashcmp(cur->item->object.sha1, current_bad_oid->hash))
if (oidcmp(&cur->item->object.oid, current_bad_oid))
return cur;
if (previous)
return previous;
Expand Down Expand Up @@ -784,7 +784,7 @@ static void check_merge_bases(int no_checkout)
result = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1);

for (; result; result = result->next) {
const unsigned char *mb = result->item->object.sha1;
const unsigned char *mb = result->item->object.oid.hash;
if (!hashcmp(mb, current_bad_oid->hash)) {
handle_bad_merge_base();
} else if (0 <= sha1_array_lookup(&good_revs, mb)) {
Expand Down Expand Up @@ -973,7 +973,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
exit(4);
}

bisect_rev = revs.commits->item->object.sha1;
bisect_rev = revs.commits->item->object.oid.hash;

if (!hashcmp(bisect_rev, current_bad_oid->hash)) {
exit_if_skipped_commits(tried, current_bad_oid);
Expand Down
2 changes: 1 addition & 1 deletion branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ void create_branch(const char *head,

if ((commit = lookup_commit_reference(sha1)) == NULL)
die(_("Not a valid branch point: '%s'."), start_name);
hashcpy(sha1, commit->object.sha1);
hashcpy(sha1, commit->object.oid.hash);

if (forcing)
snprintf(msg, sizeof msg, "branch: Reset to %s",
Expand Down
2 changes: 1 addition & 1 deletion builtin/am.c
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ static void get_commit_info(struct am_state *state, struct commit *commit)
assert(!state->msg);
msg = strstr(buffer, "\n\n");
if (!msg)
die(_("unable to parse commit %s"), sha1_to_hex(commit->object.sha1));
die(_("unable to parse commit %s"), oid_to_hex(&commit->object.oid));
state->msg = xstrdup(msg + 2);
state->msg_len = strlen(state->msg);
}
Expand Down
56 changes: 28 additions & 28 deletions builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ static int fill_blob_sha1_and_mode(struct origin *origin)
{
if (!is_null_sha1(origin->blob_sha1))
return 0;
if (get_tree_entry(origin->commit->object.sha1,
if (get_tree_entry(origin->commit->object.oid.hash,
origin->path,
origin->blob_sha1, &origin->mode))
goto error_out;
Expand Down Expand Up @@ -557,11 +557,11 @@ static struct origin *find_origin(struct scoreboard *sb,
PATHSPEC_LITERAL_PATH, "", paths);
diff_setup_done(&diff_opts);

if (is_null_sha1(origin->commit->object.sha1))
do_diff_cache(parent->tree->object.sha1, &diff_opts);
if (is_null_oid(&origin->commit->object.oid))
do_diff_cache(parent->tree->object.oid.hash, &diff_opts);
else
diff_tree_sha1(parent->tree->object.sha1,
origin->commit->tree->object.sha1,
diff_tree_sha1(parent->tree->object.oid.hash,
origin->commit->tree->object.oid.hash,
"", &diff_opts);
diffcore_std(&diff_opts);

Expand Down Expand Up @@ -627,11 +627,11 @@ static struct origin *find_rename(struct scoreboard *sb,
diff_opts.single_follow = origin->path;
diff_setup_done(&diff_opts);

if (is_null_sha1(origin->commit->object.sha1))
do_diff_cache(parent->tree->object.sha1, &diff_opts);
if (is_null_oid(&origin->commit->object.oid))
do_diff_cache(parent->tree->object.oid.hash, &diff_opts);
else
diff_tree_sha1(parent->tree->object.sha1,
origin->commit->tree->object.sha1,
diff_tree_sha1(parent->tree->object.oid.hash,
origin->commit->tree->object.oid.hash,
"", &diff_opts);
diffcore_std(&diff_opts);

Expand Down Expand Up @@ -977,8 +977,8 @@ static void pass_blame_to_parent(struct scoreboard *sb,

if (diff_hunks(&file_p, &file_o, 0, blame_chunk_cb, &d))
die("unable to generate diff (%s -> %s)",
sha1_to_hex(parent->commit->object.sha1),
sha1_to_hex(target->commit->object.sha1));
oid_to_hex(&parent->commit->object.oid),
oid_to_hex(&target->commit->object.oid));
/* The rest are the same as the parent */
blame_chunk(&d.dstq, &d.srcq, INT_MAX, d.offset, INT_MAX, parent);
*d.dstq = NULL;
Expand Down Expand Up @@ -1126,7 +1126,7 @@ static void find_copy_in_blob(struct scoreboard *sb,
memset(split, 0, sizeof(struct blame_entry [3]));
if (diff_hunks(file_p, &file_o, 1, handle_split_cb, &d))
die("unable to generate diff (%s)",
sha1_to_hex(parent->commit->object.sha1));
oid_to_hex(&parent->commit->object.oid));
/* remainder, if any, all match the preimage */
handle_split(sb, ent, d.tlno, d.plno, ent->num_lines, parent, split);
}
Expand Down Expand Up @@ -1275,11 +1275,11 @@ static void find_copy_in_parent(struct scoreboard *sb,
&& (!porigin || strcmp(target->path, porigin->path))))
DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);

if (is_null_sha1(target->commit->object.sha1))
do_diff_cache(parent->tree->object.sha1, &diff_opts);
if (is_null_oid(&target->commit->object.oid))
do_diff_cache(parent->tree->object.oid.hash, &diff_opts);
else
diff_tree_sha1(parent->tree->object.sha1,
target->commit->tree->object.sha1,
diff_tree_sha1(parent->tree->object.oid.hash,
target->commit->tree->object.oid.hash,
"", &diff_opts);

if (!DIFF_OPT_TST(&diff_opts, FIND_COPIES_HARDER))
Expand Down Expand Up @@ -1690,7 +1690,7 @@ static void get_commit_info(struct commit *commit,
if (len)
strbuf_add(&ret->summary, subject, len);
else
strbuf_addf(&ret->summary, "(%s)", sha1_to_hex(commit->object.sha1));
strbuf_addf(&ret->summary, "(%s)", oid_to_hex(&commit->object.oid));

unuse_commit_buffer(commit, message);
}
Expand Down Expand Up @@ -1733,7 +1733,7 @@ static int emit_one_suspect_detail(struct origin *suspect, int repeat)
printf("boundary\n");
if (suspect->previous) {
struct origin *prev = suspect->previous;
printf("previous %s ", sha1_to_hex(prev->commit->object.sha1));
printf("previous %s ", oid_to_hex(&prev->commit->object.oid));
write_name_quoted(prev->path, stdout, '\n');
}

Expand All @@ -1752,7 +1752,7 @@ static void found_guilty_entry(struct blame_entry *ent)
struct origin *suspect = ent->suspect;

printf("%s %d %d %d\n",
sha1_to_hex(suspect->commit->object.sha1),
oid_to_hex(&suspect->commit->object.oid),
ent->s_lno + 1, ent->lno + 1, ent->num_lines);
emit_one_suspect_detail(suspect, 0);
write_filename_info(suspect->path);
Expand Down Expand Up @@ -1882,7 +1882,7 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent,
struct origin *suspect = ent->suspect;
char hex[GIT_SHA1_HEXSZ + 1];

sha1_to_hex_r(hex, suspect->commit->object.sha1);
sha1_to_hex_r(hex, suspect->commit->object.oid.hash);
printf("%s %d %d %d\n",
hex,
ent->s_lno + 1,
Expand Down Expand Up @@ -1922,7 +1922,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP);

get_commit_info(suspect->commit, &ci, 1);
sha1_to_hex_r(hex, suspect->commit->object.sha1);
sha1_to_hex_r(hex, suspect->commit->object.oid.hash);

cp = nth_line(sb, ent->lno);
for (cnt = 0; cnt < ent->num_lines; cnt++) {
Expand Down Expand Up @@ -2077,7 +2077,7 @@ static int read_ancestry(const char *graft_file)

static int update_auto_abbrev(int auto_abbrev, struct origin *suspect)
{
const char *uniq = find_unique_abbrev(suspect->commit->object.sha1,
const char *uniq = find_unique_abbrev(suspect->commit->object.oid.hash,
auto_abbrev);
int len = strlen(uniq);
if (auto_abbrev < len)
Expand Down Expand Up @@ -2153,7 +2153,7 @@ static void sanity_check_refcnt(struct scoreboard *sb)
if (ent->suspect->refcnt <= 0) {
fprintf(stderr, "%s in %s has negative refcnt %d\n",
ent->suspect->path,
sha1_to_hex(ent->suspect->commit->object.sha1),
oid_to_hex(&ent->suspect->commit->object.oid),
ent->suspect->refcnt);
baa = 1;
}
Expand Down Expand Up @@ -2216,7 +2216,7 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
struct commit_list *parents;

for (parents = work_tree->parents; parents; parents = parents->next) {
const unsigned char *commit_sha1 = parents->item->object.sha1;
const unsigned char *commit_sha1 = parents->item->object.oid.hash;
unsigned char blob_sha1[20];
unsigned mode;

Expand Down Expand Up @@ -2310,7 +2310,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
strbuf_addstr(&msg, "tree 0000000000000000000000000000000000000000\n");
for (parent = commit->parents; parent; parent = parent->next)
strbuf_addf(&msg, "parent %s\n",
sha1_to_hex(parent->item->object.sha1));
oid_to_hex(&parent->item->object.oid));
strbuf_addf(&msg,
"author %s\n"
"committer %s\n\n"
Expand Down Expand Up @@ -2738,7 +2738,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)

sb.revs->children.name = "children";
while (c->parents &&
hashcmp(c->object.sha1, sb.final->object.sha1)) {
oidcmp(&c->object.oid, &sb.final->object.oid)) {
struct commit_list *l = xcalloc(1, sizeof(*l));

l->item = c;
Expand All @@ -2748,11 +2748,11 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
c = c->parents->item;
}

if (hashcmp(c->object.sha1, sb.final->object.sha1))
if (oidcmp(&c->object.oid, &sb.final->object.oid))
die("--reverse --first-parent together require range along first-parent chain");
}

if (is_null_sha1(sb.final->object.sha1)) {
if (is_null_oid(&sb.final->object.oid)) {
o = sb.final->util;
sb.final_buf = xmemdupz(o->file.ptr, o->file.size);
sb.final_buf_size = o->file.size;
Expand Down
2 changes: 1 addition & 1 deletion builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ static void add_verbose_info(struct strbuf *out, struct ref_array_item *item,
fill_tracking_info(&stat, refname, filter->verbose > 1);

strbuf_addf(out, " %s %s%s",
find_unique_abbrev(item->commit->object.sha1, filter->abbrev),
find_unique_abbrev(item->commit->object.oid.hash, filter->abbrev),
stat.buf, sub);
strbuf_release(&stat);
strbuf_release(&subject);
Expand Down
22 changes: 11 additions & 11 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ static int post_checkout_hook(struct commit *old, struct commit *new,
int changed)
{
return run_hook_le(NULL, "post-checkout",
sha1_to_hex(old ? old->object.sha1 : null_sha1),
sha1_to_hex(new ? new->object.sha1 : null_sha1),
sha1_to_hex(old ? old->object.oid.hash : null_sha1),
sha1_to_hex(new ? new->object.oid.hash : null_sha1),
changed ? "1" : "0", NULL);
/* "new" can be NULL when checking out from the index before
a commit exists. */
Expand Down Expand Up @@ -401,7 +401,7 @@ static void describe_detached_head(const char *msg, struct commit *commit)
if (!parse_commit(commit))
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
fprintf(stderr, "%s %s... %s\n", msg,
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf);
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf);
strbuf_release(&sb);
}

Expand Down Expand Up @@ -510,10 +510,10 @@ static int merge_working_tree(const struct checkout_opts *opts,
setup_standard_excludes(topts.dir);
}
tree = parse_tree_indirect(old->commit ?
old->commit->object.sha1 :
old->commit->object.oid.hash :
EMPTY_TREE_SHA1_BIN);
init_tree_desc(&trees[0], tree->buffer, tree->size);
tree = parse_tree_indirect(new->commit->object.sha1);
tree = parse_tree_indirect(new->commit->object.oid.hash);
init_tree_desc(&trees[1], tree->buffer, tree->size);

ret = unpack_trees(2, trees, &topts);
Expand Down Expand Up @@ -641,7 +641,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,

old_desc = old->name;
if (!old_desc && old->commit)
old_desc = sha1_to_hex(old->commit->object.sha1);
old_desc = oid_to_hex(&old->commit->object.oid);

reflog_msg = getenv("GIT_REFLOG_ACTION");
if (!reflog_msg)
Expand All @@ -653,7 +653,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) {
/* Nothing to do. */
} else if (opts->force_detach || !new->path) { /* No longer on any branch. */
update_ref(msg.buf, "HEAD", new->commit->object.sha1, NULL,
update_ref(msg.buf, "HEAD", new->commit->object.oid.hash, NULL,
REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
if (!opts->quiet) {
if (old->path && advice_detached_head)
Expand Down Expand Up @@ -704,7 +704,7 @@ static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
{
strbuf_addstr(sb, " ");
strbuf_addstr(sb,
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));
strbuf_addch(sb, ' ');
if (!parse_commit(commit))
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
Expand Down Expand Up @@ -762,7 +762,7 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
" git branch <new-branch-name> %s\n\n",
/* Give ngettext() the count */
lost),
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));
}

/*
Expand All @@ -780,10 +780,10 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new)
setup_revisions(0, NULL, &revs, NULL);

object->flags &= ~UNINTERESTING;
add_pending_object(&revs, object, sha1_to_hex(object->sha1));
add_pending_object(&revs, object, oid_to_hex(&object->oid));

for_each_ref(add_pending_uninteresting_ref, &revs);
add_pending_sha1(&revs, "HEAD", new->object.sha1, UNINTERESTING);
add_pending_sha1(&revs, "HEAD", new->object.oid.hash, UNINTERESTING);

refs = revs.pending;
revs.leak_pending = 1;
Expand Down
Loading

0 comments on commit 844a9ce

Please sign in to comment.