From 490bc83a01acfefa11e98f8852b1f4a9dd962331 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Tue, 30 May 2017 10:30:39 -0700 Subject: 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 Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- remote-testsvn.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'remote-testsvn.c') diff --git a/remote-testsvn.c b/remote-testsvn.c index f87bf851b..793c4ad1d 100644 --- a/remote-testsvn.c +++ b/remote-testsvn.c @@ -99,8 +99,8 @@ static int parse_rev_note(const char *msg, struct rev_note *res) return -1; } -static int note2mark_cb(const unsigned char *object_sha1, - const unsigned char *note_sha1, char *note_path, +static int note2mark_cb(const struct object_id *object_oid, + const struct object_id *note_oid, char *note_path, void *cb_data) { FILE *file = (FILE *)cb_data; @@ -109,14 +109,14 @@ static int note2mark_cb(const unsigned char *object_sha1, enum object_type type; 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) { free(msg); return 1; } if (parse_rev_note(msg, ¬e)) 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 0; } -- cgit v1.2.1 From 9ef7223058a44990dc4650ecb1209c97ceb636b3 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Tue, 30 May 2017 10:30:40 -0700 Subject: notes: make get_note return pointer to struct object_id Make get_note return a pointer to a const struct object_id. Add a defensive check to ensure we don't accidentally dereference a NULL pointer. Signed-off-by: brian m. carlson Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- remote-testsvn.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'remote-testsvn.c') diff --git a/remote-testsvn.c b/remote-testsvn.c index 793c4ad1d..017af1bd5 100644 --- a/remote-testsvn.c +++ b/remote-testsvn.c @@ -53,15 +53,15 @@ static void terminate_batch(void) /* NOTE: 'ref' refers to a git reference, while 'rev' refers to a svn revision. */ static char *read_ref_note(const unsigned char sha1[20]) { - const unsigned char *note_sha1; + const struct object_id *note_oid; char *msg = NULL; unsigned long msglen; enum object_type type; init_notes(NULL, notes_ref, NULL, 0); - if (!(note_sha1 = get_note(NULL, sha1))) + if (!(note_oid = get_note(NULL, sha1))) return NULL; /* note tree not found */ - if (!(msg = read_sha1_file(note_sha1, &type, &msglen))) + if (!(msg = read_sha1_file(note_oid->hash, &type, &msglen))) error("Empty notes tree. %s", notes_ref); else if (!msglen || type != OBJ_BLOB) { error("Note contains unusable content. " -- cgit v1.2.1 From 5ee8a954e0191be2a144afdda6e37ef776730246 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Tue, 30 May 2017 10:30:43 -0700 Subject: notes: convert some accessor functions to struct object_id Convert add_note, get_note, and copy_note to take struct object_id. Signed-off-by: brian m. carlson Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- remote-testsvn.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'remote-testsvn.c') diff --git a/remote-testsvn.c b/remote-testsvn.c index 017af1bd5..8e8d5c794 100644 --- a/remote-testsvn.c +++ b/remote-testsvn.c @@ -51,7 +51,7 @@ static void terminate_batch(void) } /* 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; @@ -59,7 +59,7 @@ static char *read_ref_note(const unsigned char sha1[20]) 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); @@ -174,15 +174,15 @@ static int cmd_import(const char *line) 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; -- cgit v1.2.1