Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Convert struct ref to use object_id.
Use struct object_id in three fields in struct ref and convert all the
necessary places that use it.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Jeff King <peff@peff.net>
  • Loading branch information
brian m. carlson authored and Jeff King committed Nov 20, 2015
1 parent b419aa2 commit f4e54d0
Show file tree
Hide file tree
Showing 18 changed files with 151 additions and 151 deletions.
16 changes: 8 additions & 8 deletions builtin/clone.c
Expand Up @@ -559,7 +559,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_sha1,
if (ref_transaction_create(t, r->peer_ref->name, r->old_oid.hash,
0, NULL, &err))
die("%s", err.buf);
}
Expand All @@ -579,9 +579,9 @@ static void write_followtags(const struct ref *refs, const char *msg)
continue;
if (ends_with(ref->name, "^{}"))
continue;
if (!has_sha1_file(ref->old_sha1))
if (!has_object_file(&ref->old_oid))
continue;
update_ref(msg, ref->name, ref->old_sha1,
update_ref(msg, ref->name, ref->old_oid.hash,
NULL, 0, UPDATE_REFS_DIE_ON_ERR);
}
}
Expand All @@ -601,7 +601,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
if (!ref)
return -1;

hashcpy(sha1, ref->old_sha1);
hashcpy(sha1, ref->old_oid.hash);
*rm = ref->next;
return 0;
}
Expand Down Expand Up @@ -650,12 +650,12 @@ static void update_head(const struct ref *our, const struct ref *remote,
/* Local default branch link */
create_symref("HEAD", our->name, NULL);
if (!option_bare) {
update_ref(msg, "HEAD", our->old_sha1, NULL, 0,
update_ref(msg, "HEAD", our->old_oid.hash, 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_sha1);
struct commit *c = lookup_commit_reference(our->old_oid.hash);
/* --branch specifies a non-branch (i.e. tags), detach HEAD */
update_ref(msg, "HEAD", c->object.sha1,
NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
Expand All @@ -665,7 +665,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
* HEAD points to a branch but we don't know which one.
* Detach HEAD in all these cases.
*/
update_ref(msg, "HEAD", remote->old_sha1,
update_ref(msg, "HEAD", remote->old_oid.hash,
NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
}
}
Expand Down Expand Up @@ -1016,7 +1016,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
* remote HEAD check.
*/
for (ref = refs; ref; ref = ref->next)
if (is_null_sha1(ref->old_sha1)) {
if (is_null_oid(&ref->old_oid)) {
complete_refs_before_fetch = 0;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions builtin/fetch-pack.c
Expand Up @@ -17,7 +17,7 @@ static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,
unsigned char sha1[20];

if (namelen > 41 && name[40] == ' ' && !get_sha1_hex(name, sha1)) {
hashcpy(ref->old_sha1, sha1);
hashcpy(ref->old_oid.hash, sha1);
name += 41;
namelen -= 41;
}
Expand Down Expand Up @@ -210,7 +210,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)

while (ref) {
printf("%s %s\n",
sha1_to_hex(ref->old_sha1), ref->name);
oid_to_hex(&ref->old_oid), ref->name);
ref = ref->next;
}

Expand Down
50 changes: 25 additions & 25 deletions builtin/fetch.c
Expand Up @@ -196,7 +196,7 @@ static int will_fetch(struct ref **head, const unsigned char *sha1)
{
struct ref *rm = *head;
while (rm) {
if (!hashcmp(rm->old_sha1, sha1))
if (!hashcmp(rm->old_oid.hash, sha1))
return 1;
rm = rm->next;
}
Expand Down Expand Up @@ -224,8 +224,8 @@ static void find_non_local_tags(struct transport *transport,
* as one to ignore by setting util to NULL.
*/
if (ends_with(ref->name, "^{}")) {
if (item && !has_sha1_file(ref->old_sha1) &&
!will_fetch(head, ref->old_sha1) &&
if (item && !has_object_file(&ref->old_oid) &&
!will_fetch(head, ref->old_oid.hash) &&
!has_sha1_file(item->util) &&
!will_fetch(head, item->util))
item->util = NULL;
Expand All @@ -251,7 +251,7 @@ static void find_non_local_tags(struct transport *transport,
continue;

item = string_list_insert(&remote_refs, ref->name);
item->util = (void *)ref->old_sha1;
item->util = (void *)&ref->old_oid;
}
string_list_clear(&existing_refs, 1);

Expand All @@ -273,7 +273,7 @@ static void find_non_local_tags(struct transport *transport,
{
struct ref *rm = alloc_ref(item->string);
rm->peer_ref = alloc_ref(item->string);
hashcpy(rm->old_sha1, item->util);
oidcpy(&rm->old_oid, item->util);
**tail = rm;
*tail = &rm->next;
}
Expand Down Expand Up @@ -419,8 +419,8 @@ static int s_update_ref(const char *action,
transaction = ref_transaction_begin(&err);
if (!transaction ||
ref_transaction_update(transaction, ref->name,
ref->new_sha1,
check_old ? ref->old_sha1 : NULL,
ref->new_oid.hash,
check_old ? ref->old_oid.hash : NULL,
0, msg, &err))
goto fail;

Expand Down Expand Up @@ -453,11 +453,11 @@ static int update_local_ref(struct ref *ref,
struct branch *current_branch = branch_get(NULL);
const char *pretty_ref = prettify_refname(ref->name);

type = sha1_object_info(ref->new_sha1, NULL);
type = sha1_object_info(ref->new_oid.hash, NULL);
if (type < 0)
die(_("object %s not found"), sha1_to_hex(ref->new_sha1));
die(_("object %s not found"), oid_to_hex(&ref->new_oid));

if (!hashcmp(ref->old_sha1, ref->new_sha1)) {
if (!oidcmp(&ref->old_oid, &ref->new_oid)) {
if (verbosity > 0)
strbuf_addf(display, "= %-*s %-*s -> %s",
TRANSPORT_SUMMARY(_("[up to date]")),
Expand All @@ -468,7 +468,7 @@ static int update_local_ref(struct ref *ref,
if (current_branch &&
!strcmp(ref->name, current_branch->name) &&
!(update_head_ok || is_bare_repository()) &&
!is_null_sha1(ref->old_sha1)) {
!is_null_oid(&ref->old_oid)) {
/*
* If this is the head, and it's not okay to update
* the head, and the old value of the head isn't empty...
Expand All @@ -480,7 +480,7 @@ static int update_local_ref(struct ref *ref,
return 1;
}

if (!is_null_sha1(ref->old_sha1) &&
if (!is_null_oid(&ref->old_oid) &&
starts_with(ref->name, "refs/tags/")) {
int r;
r = s_update_ref("updating tag", ref, 0);
Expand All @@ -492,8 +492,8 @@ static int update_local_ref(struct ref *ref,
return r;
}

current = lookup_commit_reference_gently(ref->old_sha1, 1);
updated = lookup_commit_reference_gently(ref->new_sha1, 1);
current = lookup_commit_reference_gently(ref->old_oid.hash, 1);
updated = lookup_commit_reference_gently(ref->new_oid.hash, 1);
if (!current || !updated) {
const char *msg;
const char *what;
Expand All @@ -517,7 +517,7 @@ static int update_local_ref(struct ref *ref,

if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
(recurse_submodules != RECURSE_SUBMODULES_ON))
check_for_new_submodule_commits(ref->new_sha1);
check_for_new_submodule_commits(ref->new_oid.hash);
r = s_update_ref(msg, ref, 0);
strbuf_addf(display, "%c %-*s %-*s -> %s%s",
r ? '!' : '*',
Expand All @@ -532,10 +532,10 @@ static int update_local_ref(struct ref *ref,
int r;
strbuf_add_unique_abbrev(&quickref, current->object.sha1, DEFAULT_ABBREV);
strbuf_addstr(&quickref, "..");
strbuf_add_unique_abbrev(&quickref, ref->new_sha1, DEFAULT_ABBREV);
strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash, DEFAULT_ABBREV);
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
(recurse_submodules != RECURSE_SUBMODULES_ON))
check_for_new_submodule_commits(ref->new_sha1);
check_for_new_submodule_commits(ref->new_oid.hash);
r = s_update_ref("fast-forward", ref, 1);
strbuf_addf(display, "%c %-*s %-*s -> %s%s",
r ? '!' : ' ',
Expand All @@ -549,10 +549,10 @@ static int update_local_ref(struct ref *ref,
int r;
strbuf_add_unique_abbrev(&quickref, current->object.sha1, DEFAULT_ABBREV);
strbuf_addstr(&quickref, "...");
strbuf_add_unique_abbrev(&quickref, ref->new_sha1, DEFAULT_ABBREV);
strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash, DEFAULT_ABBREV);
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
(recurse_submodules != RECURSE_SUBMODULES_ON))
check_for_new_submodule_commits(ref->new_sha1);
check_for_new_submodule_commits(ref->new_oid.hash);
r = s_update_ref("forced-update", ref, 1);
strbuf_addf(display, "%c %-*s %-*s -> %s (%s)",
r ? '!' : '+',
Expand Down Expand Up @@ -580,7 +580,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_sha1);
hashcpy(sha1, ref->old_oid.hash);
return 0;
}

Expand Down Expand Up @@ -631,7 +631,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
continue;
}

commit = lookup_commit_reference_gently(rm->old_sha1, 1);
commit = lookup_commit_reference_gently(rm->old_oid.hash, 1);
if (!commit)
rm->fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE;

Expand All @@ -640,8 +640,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,

if (rm->peer_ref) {
ref = alloc_ref(rm->peer_ref->name);
hashcpy(ref->old_sha1, rm->peer_ref->old_sha1);
hashcpy(ref->new_sha1, rm->old_sha1);
oidcpy(&ref->old_oid, &rm->peer_ref->old_oid);
oidcpy(&ref->new_oid, &rm->old_oid);
ref->force = rm->peer_ref->force;
}

Expand Down Expand Up @@ -686,7 +686,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
/* fall-through */
case FETCH_HEAD_MERGE:
fprintf(fp, "%s\t%s\t%s",
sha1_to_hex(rm->old_sha1),
oid_to_hex(&rm->old_oid),
merge_status_marker,
note.buf);
for (i = 0; i < url_len; ++i)
Expand Down Expand Up @@ -928,7 +928,7 @@ static int do_fetch(struct transport *transport,
rm->peer_ref->name);
if (peer_item) {
struct object_id *old_oid = peer_item->util;
hashcpy(rm->peer_ref->old_sha1, old_oid->hash);
oidcpy(&rm->peer_ref->old_oid, old_oid);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion builtin/ls-remote.c
Expand Up @@ -125,7 +125,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
continue;
if (!tail_match(pattern, ref->name))
continue;
printf("%s %s\n", sha1_to_hex(ref->old_sha1), ref->name);
printf("%s %s\n", oid_to_hex(&ref->old_oid), ref->name);
status = 0; /* we found something */
}
return status;
Expand Down
2 changes: 1 addition & 1 deletion builtin/receive-pack.c
Expand Up @@ -246,7 +246,7 @@ static void show_one_alternate_sha1(const unsigned char sha1[20], void *unused)
static void collect_one_alternate_ref(const struct ref *ref, void *data)
{
struct sha1_array *sa = data;
sha1_array_append(sa, ref->old_sha1);
sha1_array_append(sa, ref->old_oid.hash);
}

static void write_head_info(void)
Expand Down
12 changes: 6 additions & 6 deletions builtin/remote.c
Expand Up @@ -401,7 +401,7 @@ static int get_push_ref_states(const struct ref *remote_refs,

if (!ref->peer_ref)
continue;
hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
oidcpy(&ref->new_oid, &ref->peer_ref->new_oid);

item = string_list_append(&states->push,
abbrev_branch(ref->peer_ref->name));
Expand All @@ -410,14 +410,14 @@ static int get_push_ref_states(const struct ref *remote_refs,
info->forced = ref->force;
info->dest = xstrdup(abbrev_branch(ref->name));

if (is_null_sha1(ref->new_sha1)) {
if (is_null_oid(&ref->new_oid)) {
info->status = PUSH_STATUS_DELETE;
} else if (!hashcmp(ref->old_sha1, ref->new_sha1))
} else if (!oidcmp(&ref->old_oid, &ref->new_oid))
info->status = PUSH_STATUS_UPTODATE;
else if (is_null_sha1(ref->old_sha1))
else if (is_null_oid(&ref->old_oid))
info->status = PUSH_STATUS_CREATE;
else if (has_sha1_file(ref->old_sha1) &&
ref_newer(ref->new_sha1, ref->old_sha1))
else if (has_object_file(&ref->old_oid) &&
ref_newer(ref->new_oid.hash, ref->old_oid.hash))
info->status = PUSH_STATUS_FASTFORWARD;
else
info->status = PUSH_STATUS_OUTOFDATE;
Expand Down
2 changes: 1 addition & 1 deletion connect.c
Expand Up @@ -166,7 +166,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
if (!check_ref(name, flags))
continue;
ref = alloc_ref(buffer + 41);
hashcpy(ref->old_sha1, old_sha1);
hashcpy(ref->old_oid.hash, old_sha1);
*list = ref;
list = &ref->next;
got_at_least_one_head = 1;
Expand Down
18 changes: 9 additions & 9 deletions fetch-pack.c
Expand Up @@ -238,7 +238,7 @@ static void send_request(struct fetch_pack_args *args,

static void insert_one_alternate_ref(const struct ref *ref, void *unused)
{
rev_list_insert_ref(NULL, ref->old_sha1);
rev_list_insert_ref(NULL, ref->old_oid.hash);
}

#define INITIAL_FLUSH 16
Expand Down Expand Up @@ -280,7 +280,7 @@ static int find_common(struct fetch_pack_args *args,

fetching = 0;
for ( ; refs ; refs = refs->next) {
unsigned char *remote = refs->old_sha1;
unsigned char *remote = refs->old_oid.hash;
const char *remote_hex;
struct object *o;

Expand Down Expand Up @@ -570,7 +570,7 @@ static void filter_refs(struct fetch_pack_args *args,
continue;
if (get_sha1_hex(ref->name, sha1) ||
ref->name[40] != '\0' ||
hashcmp(sha1, ref->old_sha1))
hashcmp(sha1, ref->old_oid.hash))
continue;

ref->matched = 1;
Expand All @@ -583,7 +583,7 @@ static void filter_refs(struct fetch_pack_args *args,

static void mark_alternate_complete(const struct ref *ref, void *unused)
{
mark_complete(ref->old_sha1);
mark_complete(ref->old_oid.hash);
}

static int everything_local(struct fetch_pack_args *args,
Expand All @@ -599,10 +599,10 @@ static int everything_local(struct fetch_pack_args *args,
for (ref = *refs; ref; ref = ref->next) {
struct object *o;

if (!has_sha1_file(ref->old_sha1))
if (!has_object_file(&ref->old_oid))
continue;

o = parse_object(ref->old_sha1);
o = parse_object(ref->old_oid.hash);
if (!o)
continue;

Expand Down Expand Up @@ -630,7 +630,7 @@ static int everything_local(struct fetch_pack_args *args,
* Don't mark them common yet; the server has to be told so first.
*/
for (ref = *refs; ref; ref = ref->next) {
struct object *o = deref_tag(lookup_object(ref->old_sha1),
struct object *o = deref_tag(lookup_object(ref->old_oid.hash),
NULL, 0);

if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
Expand All @@ -646,7 +646,7 @@ static int everything_local(struct fetch_pack_args *args,
filter_refs(args, refs, sought, nr_sought);

for (retval = 1, ref = *refs; ref ; ref = ref->next) {
const unsigned char *remote = ref->old_sha1;
const unsigned char *remote = ref->old_oid.hash;
struct object *o;

o = lookup_object(remote);
Expand Down Expand Up @@ -985,7 +985,7 @@ static void update_shallow(struct fetch_pack_args *args,
if (!si->nr_ours && !si->nr_theirs)
return;
for (i = 0; i < nr_sought; i++)
sha1_array_append(&ref, sought[i]->old_sha1);
sha1_array_append(&ref, sought[i]->old_oid.hash);
si->ref = &ref;

if (args->update_shallow) {
Expand Down

0 comments on commit f4e54d0

Please sign in to comment.