Skip to content

Commit

Permalink
Merge branch 'bc/object-id'
Browse files Browse the repository at this point in the history
for_each_ref() callback functions were taught to name the objects
not with "unsigned char sha1[20]" but with "struct object_id".

* bc/object-id: (56 commits)
  struct ref_lock: convert old_sha1 member to object_id
  warn_if_dangling_symref(): convert local variable "junk" to object_id
  each_ref_fn_adapter(): remove adapter
  rev_list_insert_ref(): remove unneeded arguments
  rev_list_insert_ref_oid(): new function, taking an object_oid
  mark_complete(): remove unneeded arguments
  mark_complete_oid(): new function, taking an object_oid
  clear_marks(): rewrite to take an object_id argument
  mark_complete(): rewrite to take an object_id argument
  send_ref(): convert local variable "peeled" to object_id
  upload-pack: rewrite functions to take object_id arguments
  find_symref(): convert local variable "unused" to object_id
  find_symref(): rewrite to take an object_id argument
  write_one_ref(): rewrite to take an object_id argument
  write_refs_to_temp_dir(): convert local variable sha1 to object_id
  submodule: rewrite to take an object_id argument
  shallow: rewrite functions to take object_id arguments
  handle_one_ref(): rewrite to take an object_id argument
  add_info_ref(): rewrite to take an object_id argument
  handle_one_reflog(): rewrite to take an object_id argument
  ...
  • Loading branch information
Junio C Hamano committed Jun 5, 2015
2 parents c4a8354 + 5cb901a commit 5455ee0
Show file tree
Hide file tree
Showing 36 changed files with 300 additions and 255 deletions.
2 changes: 1 addition & 1 deletion Documentation/technical/api-ref-iteration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Iteration of refs is done by using an iterate function which will call a
callback function for every ref. The callback function has this
signature:

int handle_one_ref(const char *refname, const unsigned char *sha1,
int handle_one_ref(const char *refname, const struct object_id *oid,
int flags, void *cb_data);

There are different kinds of iterate functions which all take a
Expand Down
8 changes: 4 additions & 4 deletions bisect.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,16 +400,16 @@ struct commit_list *find_bisection(struct commit_list *list,
return best;
}

static int register_ref(const char *refname, const unsigned char *sha1,
static int register_ref(const char *refname, const struct object_id *oid,
int flags, void *cb_data)
{
if (!strcmp(refname, "bad")) {
current_bad_oid = xmalloc(sizeof(*current_bad_oid));
hashcpy(current_bad_oid->hash, sha1);
oidcpy(current_bad_oid, oid);
} else if (starts_with(refname, "good-")) {
sha1_array_append(&good_revs, sha1);
sha1_array_append(&good_revs, oid->hash);
} else if (starts_with(refname, "skip-")) {
sha1_array_append(&skipped_revs, sha1);
sha1_array_append(&skipped_revs, oid->hash);
}

return 0;
Expand Down
4 changes: 2 additions & 2 deletions builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ static int match_patterns(const char **pattern, const char *refname)
return 0;
}

static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
static int append_ref(const char *refname, const struct object_id *oid, int flags, void *cb_data)
{
struct append_ref_cb *cb = (struct append_ref_cb *)(cb_data);
struct ref_list *ref_list = cb->ref_list;
Expand Down Expand Up @@ -363,7 +363,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,

commit = NULL;
if (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) {
commit = lookup_commit_reference_gently(sha1, 1);
commit = lookup_commit_reference_gently(oid->hash, 1);
if (!commit) {
cb->ret = error(_("branch '%s' does not point at a commit"), refname);
return 0;
Expand Down
4 changes: 2 additions & 2 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,10 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
}

static int add_pending_uninteresting_ref(const char *refname,
const unsigned char *sha1,
const struct object_id *oid,
int flags, void *cb_data)
{
add_pending_sha1(cb_data, refname, sha1, UNINTERESTING);
add_pending_sha1(cb_data, refname, oid->hash, UNINTERESTING);
return 0;
}

Expand Down
12 changes: 6 additions & 6 deletions builtin/describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ static void add_to_known_names(const char *path,
}
}

static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)
static int get_name(const char *path, const struct object_id *oid, int flag, void *cb_data)
{
int is_tag = starts_with(path, "refs/tags/");
unsigned char peeled[20];
struct object_id peeled;
int is_annotated, prio;

/* Reject anything outside refs/tags/ unless --all */
Expand All @@ -134,10 +134,10 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void
return 0;

/* Is it annotated? */
if (!peel_ref(path, peeled)) {
is_annotated = !!hashcmp(sha1, peeled);
if (!peel_ref(path, peeled.hash)) {
is_annotated = !!oidcmp(oid, &peeled);
} else {
hashcpy(peeled, sha1);
oidcpy(&peeled, oid);
is_annotated = 0;
}

Expand All @@ -154,7 +154,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void
else
prio = 0;

add_to_known_names(all ? path + 5 : path + 10, peeled, prio, sha1);
add_to_known_names(all ? path + 5 : path + 10, peeled.hash, prio, oid->hash);
return 0;
}

Expand Down
15 changes: 9 additions & 6 deletions builtin/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,15 @@ static void add_merge_config(struct ref **head,
}
}

static int add_existing(const char *refname, const unsigned char *sha1,
static int add_existing(const char *refname, const struct object_id *oid,
int flag, void *cbdata)
{
struct string_list *list = (struct string_list *)cbdata;
struct string_list_item *item = string_list_insert(list, refname);
item->util = xmalloc(20);
hashcpy(item->util, sha1);
struct object_id *old_oid = xmalloc(sizeof(*old_oid));

oidcpy(old_oid, oid);
item->util = old_oid;
return 0;
}

Expand Down Expand Up @@ -913,9 +915,10 @@ static int do_fetch(struct transport *transport,
struct string_list_item *peer_item =
string_list_lookup(&existing_refs,
rm->peer_ref->name);
if (peer_item)
hashcpy(rm->peer_ref->old_sha1,
peer_item->util);
if (peer_item) {
struct object_id *old_oid = peer_item->util;
hashcpy(rm->peer_ref->old_sha1, old_oid->hash);
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions builtin/for-each-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,8 @@ struct grab_ref_cbdata {
* A call-back given to for_each_ref(). Filter refs and keep them for
* later object processing.
*/
static int grab_single_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
static int grab_single_ref(const char *refname, const struct object_id *oid,
int flag, void *cb_data)
{
struct grab_ref_cbdata *cb = cb_data;
struct refinfo *ref;
Expand Down Expand Up @@ -892,7 +893,7 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f
*/
ref = xcalloc(1, sizeof(*ref));
ref->refname = xstrdup(refname);
hashcpy(ref->objectname, sha1);
hashcpy(ref->objectname, oid->hash);
ref->flag = flag;

cnt = cb->grab_cnt;
Expand Down
20 changes: 11 additions & 9 deletions builtin/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static int include_reflogs = 1;
static int check_full = 1;
static int check_strict;
static int keep_cache_objects;
static unsigned char head_sha1[20];
static struct object_id head_oid;
static const char *head_points_at;
static int errors_found;
static int write_lost_and_found;
Expand Down Expand Up @@ -476,19 +476,21 @@ static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
return 0;
}

static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, int flag, void *cb_data)
static int fsck_handle_reflog(const char *logname, const struct object_id *oid,
int flag, void *cb_data)
{
for_each_reflog_ent(logname, fsck_handle_reflog_ent, NULL);
return 0;
}

static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
static int fsck_handle_ref(const char *refname, const struct object_id *oid,
int flag, void *cb_data)
{
struct object *obj;

obj = parse_object(sha1);
obj = parse_object(oid->hash);
if (!obj) {
error("%s: invalid sha1 pointer %s", refname, sha1_to_hex(sha1));
error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid));
errors_found |= ERROR_REACHABLE;
/* We'll continue with the rest despite the error.. */
return 0;
Expand All @@ -504,8 +506,8 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f

static void get_default_heads(void)
{
if (head_points_at && !is_null_sha1(head_sha1))
fsck_handle_ref("HEAD", head_sha1, 0, NULL);
if (head_points_at && !is_null_oid(&head_oid))
fsck_handle_ref("HEAD", &head_oid, 0, NULL);
for_each_rawref(fsck_handle_ref, NULL);
if (include_reflogs)
for_each_reflog(fsck_handle_reflog, NULL);
Expand Down Expand Up @@ -556,7 +558,7 @@ static int fsck_head_link(void)
if (verbose)
fprintf(stderr, "Checking HEAD link\n");

head_points_at = resolve_ref_unsafe("HEAD", 0, head_sha1, &flag);
head_points_at = resolve_ref_unsafe("HEAD", 0, head_oid.hash, &flag);
if (!head_points_at)
return error("Invalid HEAD");
if (!strcmp(head_points_at, "HEAD"))
Expand All @@ -565,7 +567,7 @@ static int fsck_head_link(void)
else if (!starts_with(head_points_at, "refs/heads/"))
return error("HEAD points to something strange (%s)",
head_points_at);
if (is_null_sha1(head_sha1)) {
if (is_null_oid(&head_oid)) {
if (null_is_error)
return error("HEAD: detached HEAD points at nothing");
fprintf(stderr, "notice: HEAD points to an unborn branch (%s)\n",
Expand Down
6 changes: 3 additions & 3 deletions builtin/name-rev.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ static int tipcmp(const void *a_, const void *b_)
return hashcmp(a->sha1, b->sha1);
}

static int name_ref(const char *path, const unsigned char *sha1, 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(sha1);
struct object *o = parse_object(oid->hash);
struct name_ref_data *data = cb_data;
int can_abbreviate_output = data->tags_only && data->name_only;
int deref = 0;
Expand All @@ -160,7 +160,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void
}
}

add_to_tip_table(sha1, path, can_abbreviate_output);
add_to_tip_table(oid->hash, path, can_abbreviate_output);

while (o && o->type == OBJ_TAG) {
struct tag *t = (struct tag *) o;
Expand Down
14 changes: 7 additions & 7 deletions builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,11 @@ static enum write_one_status write_one(struct sha1file *f,
return WRITE_ONE_WRITTEN;
}

static int mark_tagged(const char *path, const unsigned char *sha1, int flag,
static int mark_tagged(const char *path, const struct object_id *oid, int flag,
void *cb_data)
{
unsigned char peeled[20];
struct object_entry *entry = packlist_find(&to_pack, sha1, NULL);
struct object_entry *entry = packlist_find(&to_pack, oid->hash, NULL);

if (entry)
entry->tagged = 1;
Expand Down Expand Up @@ -2097,14 +2097,14 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
#define ll_find_deltas(l, s, w, d, p) find_deltas(l, &s, w, d, p)
#endif

static int add_ref_tag(const char *path, const unsigned char *sha1, int flag, void *cb_data)
static int add_ref_tag(const char *path, const struct object_id *oid, int flag, void *cb_data)
{
unsigned char peeled[20];
struct object_id peeled;

if (starts_with(path, "refs/tags/") && /* is a tag? */
!peel_ref(path, peeled) && /* peelable? */
packlist_find(&to_pack, peeled, NULL)) /* object packed? */
add_object_entry(sha1, OBJ_TAG, NULL, 0);
!peel_ref(path, peeled.hash) && /* peelable? */
packlist_find(&to_pack, peeled.hash, NULL)) /* object packed? */
add_object_entry(oid->hash, OBJ_TAG, NULL, 0);
return 0;
}

Expand Down
5 changes: 3 additions & 2 deletions builtin/receive-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static void show_ref(const char *path, const unsigned char *sha1)
}
}

static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, void *unused)
static int show_ref_cb(const char *path, const struct object_id *oid, int flag, void *unused)
{
path = strip_namespace(path);
/*
Expand All @@ -210,7 +210,7 @@ static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, vo
*/
if (!path)
path = ".have";
show_ref(path, sha1);
show_ref(path, oid->hash);
return 0;
}

Expand All @@ -228,6 +228,7 @@ static void collect_one_alternate_ref(const struct ref *ref, void *data)
static void write_head_info(void)
{
struct sha1_array sa = SHA1_ARRAY_INIT;

for_each_alternate_ref(collect_one_alternate_ref, &sa);
sha1_array_for_each_unique(&sa, show_one_alternate_sha1, NULL);
sha1_array_clear(&sa);
Expand Down
9 changes: 5 additions & 4 deletions builtin/reflog.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,14 @@ static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
return 0;
}

static int push_tip_to_list(const char *refname, const unsigned char *sha1,
static int push_tip_to_list(const char *refname, const struct object_id *oid,
int flags, void *cb_data)
{
struct commit_list **list = cb_data;
struct commit *tip_commit;
if (flags & REF_ISSYMREF)
return 0;
tip_commit = lookup_commit_reference_gently(sha1, 1);
tip_commit = lookup_commit_reference_gently(oid->hash, 1);
if (!tip_commit)
return 0;
commit_list_insert(tip_commit, list);
Expand Down Expand Up @@ -352,6 +352,7 @@ static void reflog_expiry_prepare(const char *refname,
if (cb->unreachable_expire_kind != UE_ALWAYS) {
if (cb->unreachable_expire_kind == UE_HEAD) {
struct commit_list *elem;

for_each_ref(push_tip_to_list, &cb->tips);
for (elem = cb->tips; elem; elem = elem->next)
commit_list_insert(elem->item, &cb->mark_list);
Expand Down Expand Up @@ -379,14 +380,14 @@ static void reflog_expiry_cleanup(void *cb_data)
}
}

static int collect_reflog(const char *ref, const unsigned char *sha1, int unused, void *cb_data)
static int collect_reflog(const char *ref, const struct object_id *oid, int unused, void *cb_data)
{
struct collected_reflog *e;
struct collect_reflog_cb *cb = cb_data;
size_t namelen = strlen(ref);

e = xmalloc(sizeof(*e) + namelen + 1);
hashcpy(e->sha1, sha1);
hashcpy(e->sha1, oid->hash);
memcpy(e->reflog, ref, namelen + 1);
ALLOC_GROW(cb->e, cb->nr + 1, cb->alloc);
cb->e[cb->nr++] = e;
Expand Down
Loading

0 comments on commit 5455ee0

Please sign in to comment.