notes: convert for_each_note to struct object_id
Convert for_each_note and each of the callbacks to use struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
89c149f55b
commit
490bc83a01
|
@ -109,11 +109,11 @@ static void free_note_data(struct note_data *d)
|
||||||
strbuf_release(&d->buf);
|
strbuf_release(&d->buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int list_each_note(const unsigned char *object_sha1,
|
static int list_each_note(const struct object_id *object_oid,
|
||||||
const unsigned char *note_sha1, char *note_path,
|
const struct object_id *note_oid, char *note_path,
|
||||||
void *cb_data)
|
void *cb_data)
|
||||||
{
|
{
|
||||||
printf("%s %s\n", sha1_to_hex(note_sha1), sha1_to_hex(object_sha1));
|
printf("%s %s\n", oid_to_hex(note_oid), oid_to_hex(object_oid));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
24
notes.c
24
notes.c
|
@ -610,7 +610,7 @@ redo:
|
||||||
if (path[path_len - 1] != '/')
|
if (path[path_len - 1] != '/')
|
||||||
path[path_len++] = '/';
|
path[path_len++] = '/';
|
||||||
path[path_len] = '\0';
|
path[path_len] = '\0';
|
||||||
ret = fn(l->key_oid.hash, l->val_oid.hash,
|
ret = fn(&l->key_oid, &l->val_oid,
|
||||||
path,
|
path,
|
||||||
cb_data);
|
cb_data);
|
||||||
}
|
}
|
||||||
|
@ -627,7 +627,7 @@ redo:
|
||||||
l = (struct leaf_node *) CLR_PTR_TYPE(p);
|
l = (struct leaf_node *) CLR_PTR_TYPE(p);
|
||||||
construct_path_with_fanout(l->key_oid.hash, fanout,
|
construct_path_with_fanout(l->key_oid.hash, fanout,
|
||||||
path);
|
path);
|
||||||
ret = fn(l->key_oid.hash, l->val_oid.hash, path,
|
ret = fn(&l->key_oid, &l->val_oid, path,
|
||||||
cb_data);
|
cb_data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -698,7 +698,7 @@ static int tree_write_stack_finish_subtree(struct tree_write_stack *tws)
|
||||||
|
|
||||||
static int write_each_note_helper(struct tree_write_stack *tws,
|
static int write_each_note_helper(struct tree_write_stack *tws,
|
||||||
const char *path, unsigned int mode,
|
const char *path, unsigned int mode,
|
||||||
const unsigned char *sha1)
|
const struct object_id *oid)
|
||||||
{
|
{
|
||||||
size_t path_len = strlen(path);
|
size_t path_len = strlen(path);
|
||||||
unsigned int n = 0;
|
unsigned int n = 0;
|
||||||
|
@ -728,7 +728,7 @@ static int write_each_note_helper(struct tree_write_stack *tws,
|
||||||
|
|
||||||
/* Finally add given entry to the current tree object */
|
/* Finally add given entry to the current tree object */
|
||||||
write_tree_entry(&tws->buf, mode, path + 3 * n, path_len - (3 * n),
|
write_tree_entry(&tws->buf, mode, path + 3 * n, path_len - (3 * n),
|
||||||
sha1);
|
oid->hash);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -748,7 +748,7 @@ static int write_each_non_note_until(const char *note_path,
|
||||||
; /* do nothing, prefer note to non-note */
|
; /* do nothing, prefer note to non-note */
|
||||||
else {
|
else {
|
||||||
ret = write_each_note_helper(d->root, n->path, n->mode,
|
ret = write_each_note_helper(d->root, n->path, n->mode,
|
||||||
n->oid.hash);
|
&n->oid);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -758,8 +758,8 @@ static int write_each_non_note_until(const char *note_path,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write_each_note(const unsigned char *object_sha1,
|
static int write_each_note(const struct object_id *object_oid,
|
||||||
const unsigned char *note_sha1, char *note_path,
|
const struct object_id *note_oid, char *note_path,
|
||||||
void *cb_data)
|
void *cb_data)
|
||||||
{
|
{
|
||||||
struct write_each_note_data *d =
|
struct write_each_note_data *d =
|
||||||
|
@ -777,7 +777,7 @@ static int write_each_note(const unsigned char *object_sha1,
|
||||||
|
|
||||||
/* Weave non-note entries into note entries */
|
/* Weave non-note entries into note entries */
|
||||||
return write_each_non_note_until(note_path, d) ||
|
return write_each_non_note_until(note_path, d) ||
|
||||||
write_each_note_helper(d->root, note_path, mode, note_sha1);
|
write_each_note_helper(d->root, note_path, mode, note_oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct note_delete_list {
|
struct note_delete_list {
|
||||||
|
@ -785,20 +785,20 @@ struct note_delete_list {
|
||||||
const unsigned char *sha1;
|
const unsigned char *sha1;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int prune_notes_helper(const unsigned char *object_sha1,
|
static int prune_notes_helper(const struct object_id *object_oid,
|
||||||
const unsigned char *note_sha1, char *note_path,
|
const struct object_id *note_oid, char *note_path,
|
||||||
void *cb_data)
|
void *cb_data)
|
||||||
{
|
{
|
||||||
struct note_delete_list **l = (struct note_delete_list **) cb_data;
|
struct note_delete_list **l = (struct note_delete_list **) cb_data;
|
||||||
struct note_delete_list *n;
|
struct note_delete_list *n;
|
||||||
|
|
||||||
if (has_sha1_file(object_sha1))
|
if (has_object_file(object_oid))
|
||||||
return 0; /* nothing to do for this note */
|
return 0; /* nothing to do for this note */
|
||||||
|
|
||||||
/* failed to find object => prune this note */
|
/* failed to find object => prune this note */
|
||||||
n = (struct note_delete_list *) xmalloc(sizeof(*n));
|
n = (struct note_delete_list *) xmalloc(sizeof(*n));
|
||||||
n->next = *l;
|
n->next = *l;
|
||||||
n->sha1 = object_sha1;
|
n->sha1 = object_oid->hash;
|
||||||
*l = n;
|
*l = n;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
4
notes.h
4
notes.h
|
@ -202,8 +202,8 @@ int copy_note(struct notes_tree *t,
|
||||||
* - copy_note()
|
* - copy_note()
|
||||||
* - free_notes()
|
* - free_notes()
|
||||||
*/
|
*/
|
||||||
typedef int each_note_fn(const unsigned char *object_sha1,
|
typedef int each_note_fn(const struct object_id *object_oid,
|
||||||
const unsigned char *note_sha1, char *note_path,
|
const struct object_id *note_oid, char *note_path,
|
||||||
void *cb_data);
|
void *cb_data);
|
||||||
int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
|
int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
|
||||||
void *cb_data);
|
void *cb_data);
|
||||||
|
|
|
@ -99,8 +99,8 @@ static int parse_rev_note(const char *msg, struct rev_note *res)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int note2mark_cb(const unsigned char *object_sha1,
|
static int note2mark_cb(const struct object_id *object_oid,
|
||||||
const unsigned char *note_sha1, char *note_path,
|
const struct object_id *note_oid, char *note_path,
|
||||||
void *cb_data)
|
void *cb_data)
|
||||||
{
|
{
|
||||||
FILE *file = (FILE *)cb_data;
|
FILE *file = (FILE *)cb_data;
|
||||||
|
@ -109,14 +109,14 @@ static int note2mark_cb(const unsigned char *object_sha1,
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
struct rev_note note;
|
struct rev_note note;
|
||||||
|
|
||||||
if (!(msg = read_sha1_file(note_sha1, &type, &msglen)) ||
|
if (!(msg = read_sha1_file(note_oid->hash, &type, &msglen)) ||
|
||||||
!msglen || type != OBJ_BLOB) {
|
!msglen || type != OBJ_BLOB) {
|
||||||
free(msg);
|
free(msg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (parse_rev_note(msg, ¬e))
|
if (parse_rev_note(msg, ¬e))
|
||||||
return 2;
|
return 2;
|
||||||
if (fprintf(file, ":%d %s\n", note.rev_nr, sha1_to_hex(object_sha1)) < 1)
|
if (fprintf(file, ":%d %s\n", note.rev_nr, oid_to_hex(object_oid)) < 1)
|
||||||
return 3;
|
return 3;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue