1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-18 04:16:10 +02:00

refs: convert read_ref and read_ref_full to object_id

All but two of the call sites already have parameters using the hash
parameter of struct object_id, so convert them to take a pointer to the
struct directly.  Also convert refs_read_refs_full, the underlying
implementation.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
brian m. carlson 2017-10-15 22:06:56 +00:00 committed by Junio C Hamano
parent 0f2dc722dd
commit 34c290a6fc
19 changed files with 46 additions and 47 deletions

View File

@ -379,7 +379,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);
@ -1038,7 +1038,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 */
@ -1136,7 +1136,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);
}

View File

@ -690,7 +690,7 @@ static int mv(int argc, const char **argv)
int flag = 0;
struct object_id oid;
read_ref_full(item->string, RESOLVE_REF_READING, oid.hash, &flag);
read_ref_full(item->string, RESOLVE_REF_READING, &oid, &flag);
if (!(flag & REF_ISSYMREF))
continue;
if (delete_ref(NULL, item->string, NULL, REF_NODEREF))

View File

@ -113,7 +113,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
strbuf_addstr(&ref, oid_to_hex(&oid));
full_hex = ref.buf + base_len;
if (read_ref(ref.buf, oid.hash)) {
if (read_ref(ref.buf, &oid)) {
error("replace ref '%s' not found.", full_hex);
had_error = 1;
continue;
@ -144,7 +144,7 @@ static void check_ref_valid(struct object_id *object,
if (check_refname_format(ref->buf, 0))
die("'%s' is not a valid ref name.", ref->buf);
if (read_ref(ref->buf, prev->hash))
if (read_ref(ref->buf, prev))
oidclr(prev);
else if (!force)
die("replace ref '%s' already exists", ref->buf);

View File

@ -197,7 +197,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
struct object_id oid;
if ((starts_with(*pattern, "refs/") || !strcmp(*pattern, "HEAD")) &&
!read_ref(*pattern, oid.hash)) {
!read_ref(*pattern, &oid)) {
show_one(*pattern, &oid);
}
else if (!quiet)

View File

@ -82,7 +82,7 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
for (p = argv; *p; p++) {
strbuf_reset(&ref);
strbuf_addf(&ref, "refs/tags/%s", *p);
if (read_ref(ref.buf, oid.hash)) {
if (read_ref(ref.buf, &oid)) {
error(_("tag '%s' not found."), *p);
had_error = 1;
continue;
@ -518,7 +518,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
if (strbuf_check_tag_ref(&ref, tag))
die(_("'%s' is not a valid tag name."), tag);
if (read_ref(ref.buf, prev.hash))
if (read_ref(ref.buf, &prev))
oidclr(&prev);
else if (!force)
die(_("tag '%s' already exists"), tag);

View File

@ -679,9 +679,9 @@ static int unresolve_one(const char *path)
static void read_head_pointers(void)
{
if (read_ref("HEAD", head_oid.hash))
if (read_ref("HEAD", &head_oid))
die("No HEAD -- no initial commit yet?");
if (read_ref("MERGE_HEAD", merge_head_oid.hash)) {
if (read_ref("MERGE_HEAD", &merge_head_oid)) {
fprintf(stderr, "Not in the middle of a merge.\n");
exit(0);
}
@ -721,7 +721,7 @@ static int do_reupdate(int ac, const char **av,
PATHSPEC_PREFER_CWD,
prefix, av + 1);
if (read_ref("HEAD", head_oid.hash))
if (read_ref("HEAD", &head_oid))
/* If there is no HEAD, that means it is an initial
* commit. Update everything in the index.
*/

View File

@ -340,7 +340,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
continue;
if (dwim_ref(e->name, strlen(e->name), oid.hash, &ref) != 1)
goto skip_write_ref;
if (read_ref_full(e->name, RESOLVE_REF_READING, oid.hash, &flag))
if (read_ref_full(e->name, RESOLVE_REF_READING, &oid, &flag))
flag = 0;
display_ref = (flag & REF_ISSYMREF) ? e->name : ref;

View File

@ -1758,7 +1758,7 @@ static int update_branch(struct branch *b)
delete_ref(NULL, b->name, NULL, 0);
return 0;
}
if (read_ref(b->name, old_oid.hash))
if (read_ref(b->name, &old_oid))
oidclr(&old_oid);
if (!force_update && !is_null_oid(&old_oid)) {
struct commit *old_cmit, *new_cmit;

View File

@ -11,7 +11,7 @@ static int notes_cache_match_validity(const char *ref, const char *validity)
struct strbuf msg = STRBUF_INIT;
int ret;
if (read_ref(ref, oid.hash) < 0)
if (read_ref(ref, &oid) < 0)
return 0;
commit = lookup_commit_reference_gently(&oid, 1);

View File

@ -547,7 +547,7 @@ int notes_merge(struct notes_merge_options *o,
o->local_ref, o->remote_ref);
/* Dereference o->local_ref into local_sha1 */
if (read_ref_full(o->local_ref, 0, local_oid.hash, NULL))
if (read_ref_full(o->local_ref, 0, &local_oid, NULL))
die("Failed to resolve local notes ref '%s'", o->local_ref);
else if (!check_refname_format(o->local_ref, 0) &&
is_null_oid(&local_oid))

View File

@ -18,7 +18,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
if (!parents) {
/* Deduce parent commit from t->ref */
struct object_id parent_oid;
if (!read_ref(t->ref, parent_oid.hash)) {
if (!read_ref(t->ref, &parent_oid)) {
struct commit *parent = lookup_commit(&parent_oid);
if (parse_commit(parent))
die("Failed to find/parse commit %s", t->ref);

View File

@ -1027,7 +1027,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
if (flags & NOTES_INIT_EMPTY || !notes_ref ||
get_oid_treeish(notes_ref, &object_oid))
return;
if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, object_oid.hash))
if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))
die("Cannot use notes ref %s", notes_ref);
if (get_tree_entry(object_oid.hash, "", oid.hash, &mode))
die("Failed to read notes tree referenced by %s (%s)",

26
refs.c
View File

@ -219,22 +219,22 @@ struct ref_filter {
};
int refs_read_ref_full(struct ref_store *refs, const char *refname,
int resolve_flags, unsigned char *sha1, int *flags)
int resolve_flags, struct object_id *oid, int *flags)
{
if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, sha1, flags))
if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, oid->hash, flags))
return 0;
return -1;
}
int read_ref_full(const char *refname, int resolve_flags, unsigned char *sha1, int *flags)
int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags)
{
return refs_read_ref_full(get_main_ref_store(), refname,
resolve_flags, sha1, flags);
resolve_flags, oid, flags);
}
int read_ref(const char *refname, unsigned char *sha1)
int read_ref(const char *refname, struct object_id *oid)
{
return read_ref_full(refname, RESOLVE_REF_READING, sha1, NULL);
return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);
}
int ref_exists(const char *refname)
@ -362,7 +362,7 @@ int head_ref_namespaced(each_ref_fn fn, void *cb_data)
int flag;
strbuf_addf(&buf, "%sHEAD", get_git_namespace());
if (!read_ref_full(buf.buf, RESOLVE_REF_READING, oid.hash, &flag))
if (!read_ref_full(buf.buf, RESOLVE_REF_READING, &oid, &flag))
ret = fn(buf.buf, &oid, flag, cb_data);
strbuf_release(&buf);
@ -601,7 +601,7 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid,
if (old_oid) {
struct object_id actual_old_oid;
if (read_ref(pseudoref, actual_old_oid.hash))
if (read_ref(pseudoref, &actual_old_oid))
die("could not read ref '%s'", pseudoref);
if (oidcmp(&actual_old_oid, old_oid)) {
strbuf_addf(err, "unexpected sha1 when writing '%s'", pseudoref);
@ -639,7 +639,7 @@ static int delete_pseudoref(const char *pseudoref, const struct object_id *old_o
get_files_ref_lock_timeout_ms());
if (fd < 0)
die_errno(_("Could not open '%s' for writing"), filename);
if (read_ref(pseudoref, actual_old_oid.hash))
if (read_ref(pseudoref, &actual_old_oid))
die("could not read ref '%s'", pseudoref);
if (oidcmp(&actual_old_oid, old_oid)) {
warning("Unexpected sha1 when deleting %s", pseudoref);
@ -1249,7 +1249,7 @@ int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
int flag;
if (!refs_read_ref_full(refs, "HEAD", RESOLVE_REF_READING,
oid.hash, &flag))
&oid, &flag))
return fn("HEAD", &oid, flag, cb_data);
return 0;
@ -1699,7 +1699,7 @@ int refs_peel_ref(struct ref_store *refs, const char *refname,
unsigned char *sha1)
{
int flag;
unsigned char base[20];
struct object_id base;
if (current_ref_iter && current_ref_iter->refname == refname) {
struct object_id peeled;
@ -1711,10 +1711,10 @@ int refs_peel_ref(struct ref_store *refs, const char *refname,
}
if (refs_read_ref_full(refs, refname,
RESOLVE_REF_READING, base, &flag))
RESOLVE_REF_READING, &base, &flag))
return -1;
return peel_object(base, sha1);
return peel_object(base.hash, sha1);
}
int peel_ref(const char *refname, unsigned char *sha1)

6
refs.h
View File

@ -74,10 +74,10 @@ char *resolve_refdup(const char *refname, int resolve_flags,
struct object_id *oid, int *flags);
int refs_read_ref_full(struct ref_store *refs, const char *refname,
int resolve_flags, unsigned char *sha1, int *flags);
int resolve_flags, struct object_id *oid, int *flags);
int read_ref_full(const char *refname, int resolve_flags,
unsigned char *sha1, int *flags);
int read_ref(const char *refname, unsigned char *sha1);
struct object_id *oid, int *flags);
int read_ref(const char *refname, struct object_id *oid);
/*
* Return 0 if a reference named refname could be created without

View File

@ -782,7 +782,7 @@ static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
if (refs_read_ref_full(ref_store, lock->ref_name,
mustexist ? RESOLVE_REF_READING : 0,
lock->old_oid.hash, NULL)) {
&lock->old_oid, NULL)) {
if (old_sha1) {
int save_errno = errno;
strbuf_addf(err, "can't verify ref '%s'", lock->ref_name);
@ -1297,7 +1297,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
*/
if (!copy && !refs_read_ref_full(&refs->base, newrefname,
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
oid.hash, NULL) &&
&oid, NULL) &&
refs_delete_ref(&refs->base, NULL, newrefname,
NULL, REF_NODEREF)) {
if (errno == EISDIR) {
@ -1721,7 +1721,7 @@ static void update_symref_reflog(struct files_ref_store *refs,
struct object_id new_oid;
if (logmsg &&
!refs_read_ref_full(&refs->base, target,
RESOLVE_REF_READING, new_oid.hash, NULL) &&
RESOLVE_REF_READING, &new_oid, NULL) &&
files_log_ref_write(refs, refname, &lock->old_oid,
&new_oid, logmsg, 0, &err)) {
error("%s", err.buf);
@ -2010,7 +2010,7 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
if (refs_read_ref_full(iter->ref_store,
diter->relative_path, 0,
iter->oid.hash, &flags)) {
&iter->oid, &flags)) {
error("bad ref for %s", diter->path.buf);
continue;
}
@ -2347,7 +2347,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
*/
if (refs_read_ref_full(&refs->base,
referent.buf, 0,
lock->old_oid.hash, NULL)) {
&lock->old_oid, NULL)) {
if (update->flags & REF_HAVE_OLD) {
strbuf_addf(err, "cannot lock ref '%s': "
"error reading reference",

View File

@ -174,7 +174,7 @@ static int cmd_import(const char *line)
struct child_process svndump_proc = CHILD_PROCESS_INIT;
const char *command = "svnrdump";
if (read_ref(private_ref, head_oid.hash))
if (read_ref(private_ref, &head_oid))
startrev = 0;
else {
note_msg = read_ref_note(&head_oid);

View File

@ -2002,13 +2002,13 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
return -1;
/* Cannot stat if what we used to build on no longer exists */
if (read_ref(base, oid.hash))
if (read_ref(base, &oid))
return -1;
theirs = lookup_commit_reference(&oid);
if (!theirs)
return -1;
if (read_ref(branch->refname, oid.hash))
if (read_ref(branch->refname, &oid))
return -1;
ours = lookup_commit_reference(&oid);
if (!ours)
@ -2327,7 +2327,7 @@ static int remote_tracking(struct remote *remote, const char *refname,
dst = apply_refspecs(remote->fetch, remote->fetch_refspec_nr, refname);
if (!dst)
return -1; /* no tracking ref for refname at remote */
if (read_ref(dst, oid->hash))
if (read_ref(dst, oid))
return -1; /* we know what the tracking ref is but we cannot read it */
return 0;
}

View File

@ -1630,7 +1630,7 @@ static int rollback_single_pick(void)
if (!file_exists(git_path_cherry_pick_head()) &&
!file_exists(git_path_revert_head()))
return error(_("no cherry-pick or revert in progress"));
if (read_ref_full("HEAD", 0, head_oid.hash, NULL))
if (read_ref_full("HEAD", 0, &head_oid, NULL))
return error(_("cannot resolve HEAD"));
if (is_null_oid(&head_oid))
return error(_("cannot abort from a branch yet to be born"));

View File

@ -535,7 +535,7 @@ static int fetch_with_import(struct transport *transport,
else
private = xstrdup(name);
if (private) {
if (read_ref(private, posn->old_oid.hash) < 0)
if (read_ref(private, &posn->old_oid) < 0)
die("Could not read ref %s", private);
free(private);
}
@ -1067,8 +1067,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
if (eon) {
if (has_attribute(eon + 1, "unchanged")) {
(*tail)->status |= REF_STATUS_UPTODATE;
if (read_ref((*tail)->name,
(*tail)->old_oid.hash) < 0)
if (read_ref((*tail)->name, &(*tail)->old_oid) < 0)
die(_("Could not read ref %s"),
(*tail)->name);
}