Skip to content

Commit

Permalink
Merge branch 'bc/object-id'
Browse files Browse the repository at this point in the history
Conversion from uchar[20] to struct object_id continues.

* bc/object-id: (25 commits)
  refs/files-backend: convert static functions to object_id
  refs: convert read_raw_ref backends to struct object_id
  refs: convert peel_object to struct object_id
  refs: convert resolve_ref_unsafe to struct object_id
  worktree: convert struct worktree to object_id
  refs: convert resolve_gitlink_ref to struct object_id
  Convert remaining callers of resolve_gitlink_ref to object_id
  sha1_file: convert index_path and index_fd to struct object_id
  refs: convert reflog_expire parameter to struct object_id
  refs: convert read_ref_at to struct object_id
  refs: convert peel_ref to struct object_id
  builtin/pack-objects: convert to struct object_id
  pack-bitmap: convert traverse_bitmap_commit_list to object_id
  refs: convert dwim_log to struct object_id
  builtin/reflog: convert remaining unsigned char uses to object_id
  refs: convert dwim_ref and expand_ref to struct object_id
  refs: convert read_ref and read_ref_full to object_id
  refs: convert resolve_refdup and refs_resolve_refdup to struct object_id
  Convert check_connected to use struct object_id
  refs: update ref transactions to use struct object_id
  ...
  • Loading branch information
gitster committed Nov 6, 2017
2 parents f4c214b + 4f01e50 commit e7e456f
Show file tree
Hide file tree
Showing 70 changed files with 544 additions and 554 deletions.
2 changes: 1 addition & 1 deletion archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static void parse_treeish_arg(const char **argv,
const char *colon = strchrnul(name, ':');
int refnamelen = colon - name;

if (!dwim_ref(name, refnamelen, oid.hash, &ref))
if (!dwim_ref(name, refnamelen, &oid, &ref))
die("no such ref: %.*s", refnamelen, name);
free(ref);
}
Expand Down
5 changes: 3 additions & 2 deletions bisect.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,11 +690,12 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
char bisect_rev_hex[GIT_MAX_HEXSZ + 1];

memcpy(bisect_rev_hex, oid_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev->hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);

argv_checkout[2] = bisect_rev_hex;
if (no_checkout) {
update_ref(NULL, "BISECT_HEAD", bisect_rev->hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
} else {
int res;
res = run_command_v_opt(argv_checkout, RUN_GIT_CMD);
Expand Down
4 changes: 2 additions & 2 deletions blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
commit->date = now;
parent_tail = &commit->parents;

if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
die("no such ref: HEAD");

parent_tail = append_parent(parent_tail, &head_oid);
Expand Down Expand Up @@ -1689,7 +1689,7 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
return NULL;

/* Do we have HEAD? */
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
return NULL;
head_commit = lookup_commit_reference_gently(&head_oid, 1);
if (!head_commit)
Expand Down
4 changes: 2 additions & 2 deletions branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void create_branch(const char *name, const char *start_name,
die(_("Not a valid object name: '%s'."), start_name);
}

switch (dwim_ref(start_name, strlen(start_name), oid.hash, &real_ref)) {
switch (dwim_ref(start_name, strlen(start_name), &oid, &real_ref)) {
case 0:
/* Not branching from any existing branch */
if (explicit_tracking)
Expand Down Expand Up @@ -305,7 +305,7 @@ void create_branch(const char *name, const char *start_name,
transaction = ref_transaction_begin(&err);
if (!transaction ||
ref_transaction_update(transaction, ref.buf,
oid.hash, forcing ? NULL : null_sha1,
&oid, forcing ? NULL : &null_oid,
0, msg, &err) ||
ref_transaction_commit(transaction, &err))
die("%s", err.buf);
Expand Down
16 changes: 8 additions & 8 deletions builtin/am.c
Original file line number Diff line number Diff line change
Expand Up @@ -1068,8 +1068,8 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
if (!get_oid("HEAD", &curr_head)) {
write_state_text(state, "abort-safety", oid_to_hex(&curr_head));
if (!state->rebasing)
update_ref_oid("am", "ORIG_HEAD", &curr_head, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
update_ref("am", "ORIG_HEAD", &curr_head, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
} else {
write_state_text(state, "abort-safety", "");
if (!state->rebasing)
Expand Down Expand Up @@ -1685,8 +1685,8 @@ static void do_commit(const struct am_state *state)
strbuf_addf(&sb, "%s: %.*s", reflog_msg, linelen(state->msg),
state->msg);

update_ref_oid(sb.buf, "HEAD", &commit, old_oid, 0,
UPDATE_REFS_DIE_ON_ERR);
update_ref(sb.buf, "HEAD", &commit, old_oid, 0,
UPDATE_REFS_DIE_ON_ERR);

if (state->rebasing) {
FILE *fp = xfopen(am_path(state, "rewritten"), "a");
Expand Down Expand Up @@ -2132,7 +2132,7 @@ static void am_abort(struct am_state *state)

am_rerere_clear();

curr_branch = resolve_refdup("HEAD", 0, curr_head.hash, NULL);
curr_branch = resolve_refdup("HEAD", 0, &curr_head, NULL);
has_curr_head = curr_branch && !is_null_oid(&curr_head);
if (!has_curr_head)
hashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);
Expand All @@ -2144,9 +2144,9 @@ static void am_abort(struct am_state *state)
clean_index(&curr_head, &orig_head);

if (has_orig_head)
update_ref_oid("am --abort", "HEAD", &orig_head,
has_curr_head ? &curr_head : NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
update_ref("am --abort", "HEAD", &orig_head,
has_curr_head ? &curr_head : NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
else if (curr_branch)
delete_ref(NULL, curr_branch, NULL, REF_NODEREF);

Expand Down
8 changes: 4 additions & 4 deletions builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static int branch_merged(int kind, const char *name,
if (upstream &&
(reference_name = reference_name_to_free =
resolve_refdup(upstream, RESOLVE_REF_READING,
oid.hash, NULL)) != NULL)
&oid, NULL)) != NULL)
reference_rev = lookup_commit_reference(&oid);
}
if (!reference_rev)
Expand Down Expand Up @@ -241,7 +241,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
RESOLVE_REF_READING
| RESOLVE_REF_NO_RECURSE
| RESOLVE_REF_ALLOW_BAD_NAME,
oid.hash, &flags);
&oid, &flags);
if (!target) {
error(remote_branch
? _("remote-tracking branch '%s' not found.")
Expand All @@ -257,7 +257,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
goto next;
}

if (delete_ref(NULL, name, is_null_oid(&oid) ? NULL : oid.hash,
if (delete_ref(NULL, name, is_null_oid(&oid) ? NULL : &oid,
REF_NODEREF)) {
error(remote_branch
? _("Error deleting remote-tracking branch '%s'")
Expand Down Expand Up @@ -636,7 +636,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)

track = git_branch_track;

head = resolve_refdup("HEAD", 0, head_oid.hash, NULL);
head = resolve_refdup("HEAD", 0, &head_oid, NULL);
if (!head)
die(_("Failed to resolve HEAD as a valid ref."));
if (!strcmp(head, "HEAD"))
Expand Down
10 changes: 5 additions & 5 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ static int checkout_paths(const struct checkout_opts *opts,
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
die(_("unable to write new index file"));

read_ref_full("HEAD", 0, rev.hash, NULL);
read_ref_full("HEAD", 0, &rev, NULL);
head = lookup_commit_reference_gently(&rev, 1);

errs |= post_checkout_hook(head, head, 0);
Expand Down Expand Up @@ -662,7 +662,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.oid.hash, NULL,
update_ref(msg.buf, "HEAD", &new->commit->object.oid, NULL,
REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
if (!opts->quiet) {
if (old->path &&
Expand Down Expand Up @@ -825,7 +825,7 @@ static int switch_branches(const struct checkout_opts *opts,
struct object_id rev;
int flag, writeout_error = 0;
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, &flag);
if (old.path)
old.commit = lookup_commit_reference_gently(&rev, 1);
if (!(flag & REF_ISSYMREF))
Expand Down Expand Up @@ -1036,7 +1036,7 @@ static int parse_branchname_arg(int argc, const char **argv,
setup_branch_path(new);

if (!check_refname_format(new->path, 0) &&
!read_ref(new->path, branch_rev.hash))
!read_ref(new->path, &branch_rev))
oidcpy(rev, &branch_rev);
else
new->path = NULL; /* not an existing branch */
Expand Down Expand Up @@ -1134,7 +1134,7 @@ static int checkout_branch(struct checkout_opts *opts,
struct object_id rev;
int flag;

if (!read_ref_full("HEAD", 0, rev.hash, &flag) &&
if (!read_ref_full("HEAD", 0, &rev, &flag) &&
(flag & REF_ISSYMREF) && is_null_oid(&rev))
return switch_unborn_to_new_branch(opts);
}
Expand Down
22 changes: 11 additions & 11 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ static void write_remote_refs(const struct ref *local_refs)
for (r = local_refs; r; r = r->next) {
if (!r->peer_ref)
continue;
if (ref_transaction_create(t, r->peer_ref->name, r->old_oid.hash,
if (ref_transaction_create(t, r->peer_ref->name, &r->old_oid,
0, NULL, &err))
die("%s", err.buf);
}
Expand All @@ -610,12 +610,12 @@ static void write_followtags(const struct ref *refs, const char *msg)
continue;
if (!has_object_file(&ref->old_oid))
continue;
update_ref(msg, ref->name, ref->old_oid.hash,
NULL, 0, UPDATE_REFS_DIE_ON_ERR);
update_ref(msg, ref->name, &ref->old_oid, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
}
}

static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
static int iterate_ref_map(void *cb_data, struct object_id *oid)
{
struct ref **rm = cb_data;
struct ref *ref = *rm;
Expand All @@ -630,7 +630,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
if (!ref)
return -1;

hashcpy(sha1, ref->old_oid.hash);
oidcpy(oid, &ref->old_oid);
*rm = ref->next;
return 0;
}
Expand Down Expand Up @@ -682,23 +682,23 @@ static void update_head(const struct ref *our, const struct ref *remote,
if (create_symref("HEAD", our->name, NULL) < 0)
die(_("unable to update HEAD"));
if (!option_bare) {
update_ref(msg, "HEAD", our->old_oid.hash, NULL, 0,
update_ref(msg, "HEAD", &our->old_oid, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
install_branch_config(0, head, option_origin, our->name);
}
} else if (our) {
struct commit *c = lookup_commit_reference(&our->old_oid);
/* --branch specifies a non-branch (i.e. tags), detach HEAD */
update_ref(msg, "HEAD", c->object.oid.hash,
NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
update_ref(msg, "HEAD", &c->object.oid, NULL, REF_NODEREF,
UPDATE_REFS_DIE_ON_ERR);
} else if (remote) {
/*
* We know remote HEAD points to a non-branch, or
* HEAD points to a branch but we don't know which one.
* Detach HEAD in all these cases.
*/
update_ref(msg, "HEAD", remote->old_oid.hash,
NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
update_ref(msg, "HEAD", &remote->old_oid, NULL, REF_NODEREF,
UPDATE_REFS_DIE_ON_ERR);
}
}

Expand All @@ -715,7 +715,7 @@ static int checkout(int submodule_progress)
if (option_no_checkout)
return 0;

head = resolve_refdup("HEAD", RESOLVE_REF_READING, oid.hash, NULL);
head = resolve_refdup("HEAD", RESOLVE_REF_READING, &oid, NULL);
if (!head) {
warning(_("remote HEAD refers to nonexistent ref, "
"unable to checkout.\n"));
Expand Down
4 changes: 2 additions & 2 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1790,9 +1790,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)

transaction = ref_transaction_begin(&err);
if (!transaction ||
ref_transaction_update(transaction, "HEAD", oid.hash,
ref_transaction_update(transaction, "HEAD", &oid,
current_head
? current_head->object.oid.hash : null_sha1,
? &current_head->object.oid : &null_oid,
0, sb.buf, &err) ||
ref_transaction_commit(transaction, &err)) {
rollback_index_files();
Expand Down
2 changes: 1 addition & 1 deletion builtin/describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
}

/* Is it annotated? */
if (!peel_ref(path, peeled.hash)) {
if (!peel_ref(path, &peeled)) {
is_annotated = !!oidcmp(oid, &peeled);
} else {
oidcpy(&peeled, oid);
Expand Down
2 changes: 1 addition & 1 deletion builtin/fast-export.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
if (e->flags & UNINTERESTING)
continue;

if (dwim_ref(e->name, strlen(e->name), oid.hash, &full_name) != 1)
if (dwim_ref(e->name, strlen(e->name), &oid, &full_name) != 1)
continue;

if (refspecs) {
Expand Down
8 changes: 4 additions & 4 deletions builtin/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ static int s_update_ref(const char *action,
transaction = ref_transaction_begin(&err);
if (!transaction ||
ref_transaction_update(transaction, ref->name,
ref->new_oid.hash,
check_old ? ref->old_oid.hash : NULL,
&ref->new_oid,
check_old ? &ref->old_oid : NULL,
0, msg, &err))
goto fail;

Expand Down Expand Up @@ -727,7 +727,7 @@ static int update_local_ref(struct ref *ref,
}
}

static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
static int iterate_ref_map(void *cb_data, struct object_id *oid)
{
struct ref **rm = cb_data;
struct ref *ref = *rm;
Expand All @@ -737,7 +737,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
if (!ref)
return -1; /* end of the list */
*rm = ref->next;
hashcpy(sha1, ref->old_oid.hash);
oidcpy(oid, &ref->old_oid);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion builtin/fmt-merge-msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,

/* get current branch */
current_branch = current_branch_to_free =
resolve_refdup("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL);
resolve_refdup("HEAD", RESOLVE_REF_READING, &head_oid, NULL);
if (!current_branch)
die("No current branch");
if (starts_with(current_branch, "refs/heads/"))
Expand Down
2 changes: 1 addition & 1 deletion builtin/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ static int fsck_head_link(void)
if (verbose)
fprintf(stderr, "Checking HEAD link\n");

head_points_at = resolve_ref_unsafe("HEAD", 0, head_oid.hash, NULL);
head_points_at = resolve_ref_unsafe("HEAD", 0, &head_oid, NULL);
if (!head_points_at) {
errors_found |= ERROR_REFS;
return error("Invalid HEAD");
Expand Down
2 changes: 1 addition & 1 deletion builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ static char *find_branch_name(struct rev_info *rev)
return NULL;
ref = rev->cmdline.rev[positive].name;
tip_oid = &rev->cmdline.rev[positive].item->oid;
if (dwim_ref(ref, strlen(ref), branch_oid.hash, &full_ref) &&
if (dwim_ref(ref, strlen(ref), &branch_oid, &full_ref) &&
skip_prefix(full_ref, "refs/heads/", &v) &&
!oidcmp(tip_oid, &branch_oid))
branch = xstrdup(v);
Expand Down
2 changes: 1 addition & 1 deletion builtin/merge-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static int handle_fork_point(int argc, const char **argv)
struct commit_list *bases;
int i, ret = 0;

switch (dwim_ref(argv[0], strlen(argv[0]), oid.hash, &refname)) {
switch (dwim_ref(argv[0], strlen(argv[0]), &oid, &refname)) {
case 0:
die("No such ref: '%s'", argv[0]);
case 1:
Expand Down
Loading

0 comments on commit e7e456f

Please sign in to comment.