Convert add_note, get_note, and copy_note to take 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>
if (rewrite_cmd)
err = copy_note_for_rewrite(c, &from_obj, &to_obj);
else
- err = copy_note(t, from_obj.hash, to_obj.hash, force,
+ err = copy_note(t, &from_obj, &to_obj, force,
combine_notes_overwrite);
if (err) {
if (argc) {
if (get_oid(argv[0], &object))
die(_("failed to resolve '%s' as a valid ref."), argv[0]);
- note = get_note(t, object.hash);
+ note = get_note(t, &object);
if (note) {
puts(oid_to_hex(note));
retval = 0;
die(_("failed to resolve '%s' as a valid ref."), object_ref);
t = init_notes_check("add", NOTES_INIT_WRITABLE);
- note = get_note(t, object.hash);
+ note = get_note(t, &object);
if (note) {
if (!force) {
prepare_note_data(&object, &d, note->hash);
if (d.buf.len || allow_empty) {
write_note_data(&d, new_note.hash);
- if (add_note(t, object.hash, new_note.hash, combine_notes_overwrite))
+ if (add_note(t, &object, &new_note, combine_notes_overwrite))
die("BUG: combine_notes_overwrite failed");
commit_notes(t, "Notes added by 'git notes add'");
} else {
die(_("failed to resolve '%s' as a valid ref."), object_ref);
t = init_notes_check("copy", NOTES_INIT_WRITABLE);
- note = get_note(t, object.hash);
+ note = get_note(t, &object);
if (note) {
if (!force) {
oid_to_hex(&object));
}
- from_note = get_note(t, from_obj.hash);
+ from_note = get_note(t, &from_obj);
if (!from_note) {
retval = error(_("missing notes on source object %s. Cannot "
"copy."), oid_to_hex(&from_obj));
goto out;
}
- if (add_note(t, object.hash, from_note->hash, combine_notes_overwrite))
+ if (add_note(t, &object, from_note, combine_notes_overwrite))
die("BUG: combine_notes_overwrite failed");
commit_notes(t, "Notes added by 'git notes copy'");
out:
die(_("failed to resolve '%s' as a valid ref."), object_ref);
t = init_notes_check(argv[0], NOTES_INIT_WRITABLE);
- note = get_note(t, object.hash);
+ note = get_note(t, &object);
prepare_note_data(&object, &d, edit && note ? note->hash : NULL);
if (d.buf.len || allow_empty) {
write_note_data(&d, new_note.hash);
- if (add_note(t, object.hash, new_note.hash, combine_notes_overwrite))
+ if (add_note(t, &object, &new_note, combine_notes_overwrite))
die("BUG: combine_notes_overwrite failed");
logmsg = xstrfmt("Notes added by 'git notes %s'", argv[0]);
} else {
die(_("failed to resolve '%s' as a valid ref."), object_ref);
t = init_notes_check("show", 0);
- note = get_note(t, object.hash);
+ note = get_note(t, &object);
if (!note)
retval = error(_("no note found for object %s."),
char *value;
unsigned long size;
- value_oid = get_note(&c->tree, key_oid->hash);
+ value_oid = get_note(&c->tree, key_oid);
if (!value_oid)
return NULL;
value = read_sha1_file(value_oid->hash, &type, &size);
if (write_sha1_file(data, size, "blob", value_oid.hash) < 0)
return -1;
- return add_note(&c->tree, key_oid->hash, value_oid.hash, NULL);
+ return add_note(&c->tree, key_oid, &value_oid, NULL);
}
if (o->verbosity >= 2)
printf("Using remote notes for %s\n",
oid_to_hex(&p->obj));
- if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_overwrite))
+ if (add_note(t, &p->obj, &p->remote, combine_notes_overwrite))
die("BUG: combine_notes_overwrite failed");
return 0;
case NOTES_MERGE_RESOLVE_UNION:
if (o->verbosity >= 2)
printf("Concatenating local and remote notes for %s\n",
oid_to_hex(&p->obj));
- if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_concatenate))
+ if (add_note(t, &p->obj, &p->remote, combine_notes_concatenate))
die("failed to concatenate notes "
"(combine_notes_concatenate)");
return 0;
if (o->verbosity >= 2)
printf("Concatenating unique lines in local and remote "
"notes for %s\n", oid_to_hex(&p->obj));
- if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_cat_sort_uniq))
+ if (add_note(t, &p->obj, &p->remote, combine_notes_cat_sort_uniq))
die("failed to concatenate notes "
"(combine_notes_cat_sort_uniq)");
return 0;
!oidcmp(&p->local, &p->base)) {
/* no local change; adopt remote change */
trace_printf("\t\t\tno local change, adopted remote\n");
- if (add_note(t, p->obj.hash, p->remote.hash,
+ if (add_note(t, &p->obj, &p->remote,
combine_notes_overwrite))
die("BUG: combine_notes_overwrite failed");
} else {
baselen = path.len;
while ((e = readdir(dir)) != NULL) {
struct stat st;
- unsigned char obj_sha1[20], blob_sha1[20];
+ struct object_id obj_oid, blob_oid;
if (is_dot_or_dotdot(e->d_name))
continue;
- if (strlen(e->d_name) != 40 || get_sha1_hex(e->d_name, obj_sha1)) {
+ if (get_oid_hex(e->d_name, &obj_oid)) {
if (o->verbosity >= 3)
printf("Skipping non-SHA1 entry '%s%s'\n",
path.buf, e->d_name);
/* write file as blob, and add to partial_tree */
if (stat(path.buf, &st))
die_errno("Failed to stat '%s'", path.buf);
- if (index_path(blob_sha1, path.buf, &st, HASH_WRITE_OBJECT))
+ if (index_path(blob_oid.hash, path.buf, &st, HASH_WRITE_OBJECT))
die("Failed to write blob object from '%s'", path.buf);
- if (add_note(partial_tree, obj_sha1, blob_sha1, NULL))
+ if (add_note(partial_tree, &obj_oid, &blob_oid, NULL))
die("Failed to add resolved note '%s' to notes tree",
path.buf);
if (o->verbosity >= 4)
printf("Added resolved note for object %s: %s\n",
- sha1_to_hex(obj_sha1), sha1_to_hex(blob_sha1));
+ oid_to_hex(&obj_oid), oid_to_hex(&blob_oid));
strbuf_setlen(&path, baselen);
}
int ret = 0;
int i;
for (i = 0; c->trees[i]; i++)
- ret = copy_note(c->trees[i], from_obj->hash, to_obj->hash, 1, c->combine) || ret;
+ ret = copy_note(c->trees[i], from_obj, to_obj, 1, c->combine) || ret;
return ret;
}
string_list_clear(&display_notes_refs, 0);
}
-int add_note(struct notes_tree *t, const unsigned char *object_sha1,
- const unsigned char *note_sha1, combine_notes_fn combine_notes)
+int add_note(struct notes_tree *t, const struct object_id *object_oid,
+ const struct object_id *note_oid, combine_notes_fn combine_notes)
{
struct leaf_node *l;
if (!combine_notes)
combine_notes = t->combine_notes;
l = (struct leaf_node *) xmalloc(sizeof(struct leaf_node));
- hashcpy(l->key_oid.hash, object_sha1);
- hashcpy(l->val_oid.hash, note_sha1);
+ oidcpy(&l->key_oid, object_oid);
+ oidcpy(&l->val_oid, note_oid);
return note_tree_insert(t, t->root, 0, l, PTR_TYPE_NOTE, combine_notes);
}
}
const struct object_id *get_note(struct notes_tree *t,
- const unsigned char *object_sha1)
+ const struct object_id *oid)
{
struct leaf_node *found;
if (!t)
t = &default_notes_tree;
assert(t->initialized);
- found = note_tree_find(t, t->root, 0, object_sha1);
+ found = note_tree_find(t, t->root, 0, oid->hash);
return found ? &found->val_oid : NULL;
}
if (!t->initialized)
init_notes(t, NULL, NULL, 0);
- oid = get_note(t, object_oid->hash);
+ oid = get_note(t, object_oid);
if (!oid)
return;
}
int copy_note(struct notes_tree *t,
- const unsigned char *from_obj, const unsigned char *to_obj,
+ const struct object_id *from_obj, const struct object_id *to_obj,
int force, combine_notes_fn combine_notes)
{
const struct object_id *note = get_note(t, from_obj);
return 1;
if (note)
- return add_note(t, to_obj, note->hash, combine_notes);
+ return add_note(t, to_obj, note, combine_notes);
else if (existing_note)
- return add_note(t, to_obj, null_sha1, combine_notes);
+ return add_note(t, to_obj, &null_oid, combine_notes);
return 0;
}
* are not persistent until a subsequent call to write_notes_tree() returns
* zero.
*/
-int add_note(struct notes_tree *t, const unsigned char *object_sha1,
- const unsigned char *note_sha1, combine_notes_fn combine_notes);
+int add_note(struct notes_tree *t, const struct object_id *object_oid,
+ const struct object_id *note_oid, combine_notes_fn combine_notes);
/*
* Remove the given note object from the given notes_tree structure
* Return NULL if the given object has no notes.
*/
const struct object_id *get_note(struct notes_tree *t,
- const unsigned char *object_sha1);
+ const struct object_id *object_oid);
/*
* Copy a note from one object to another in the given notes_tree.
* zero.
*/
int copy_note(struct notes_tree *t,
- const unsigned char *from_obj, const unsigned char *to_obj,
+ const struct object_id *from_obj, const struct object_id *to_obj,
int force, combine_notes_fn combine_notes);
/*
}
/* NOTE: 'ref' refers to a git reference, while 'rev' refers to a svn revision. */
-static char *read_ref_note(const unsigned char sha1[20])
+static char *read_ref_note(const struct object_id *oid)
{
const struct object_id *note_oid;
char *msg = NULL;
enum object_type type;
init_notes(NULL, notes_ref, NULL, 0);
- if (!(note_oid = get_note(NULL, sha1)))
+ if (!(note_oid = get_note(NULL, oid)))
return NULL; /* note tree not found */
if (!(msg = read_sha1_file(note_oid->hash, &type, &msglen)))
error("Empty notes tree. %s", notes_ref);
int code;
int dumpin_fd;
char *note_msg;
- unsigned char head_sha1[20];
+ struct object_id head_oid;
unsigned int startrev;
struct child_process svndump_proc = CHILD_PROCESS_INIT;
const char *command = "svnrdump";
- if (read_ref(private_ref, head_sha1))
+ if (read_ref(private_ref, head_oid.hash))
startrev = 0;
else {
- note_msg = read_ref_note(head_sha1);
+ note_msg = read_ref_note(&head_oid);
if(note_msg == NULL) {
warning("No note found for %s.", private_ref);
startrev = 0;