{"thread":{"id":"1435","subject":"[PATCH] Fix ref_newer() in send-pack.","startedAt":"2005-08-06T06:18:38Z","lastAt":"2005-08-06T06:18:38Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"6872","messageId":"7v7jezbnb5.fsf@assigned-by-dhcp.cox.net","threadId":"1435","inReplyTo":null,"subject":"[PATCH] Fix ref_newer() in send-pack.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-08-06T06:18:38Z","receivedAt":"2005-08-06T06:18:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When more than two references need to be checked with\nref_newer() function, the second and later calls did not work\ncorrectly.  This was because the later calls found commits\nretained by the \"struct object\" layer that still had smudges\nmade by earlier calls.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n send-pack.c |   27 ++++++++++++++++++++++-----\n 1 files changed, 22 insertions(+), 5 deletions(-)\n\n51b0fca012310910783de76f2eacfd10b0f2f9fc\ndiff --git a/send-pack.c b/send-pack.c\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -105,12 +105,23 @@ static int pack_objects(int fd, struct r\n \treturn 0;\n }\n \n+static void unmark_and_free(struct commit_list *list, unsigned int mark)\n+{\n+\twhile (list) {\n+\t\tstruct commit_list *temp = list;\n+\t\ttemp->item->object.flags &= ~mark;\n+\t\tlist = temp->next;\n+\t\tfree(temp);\n+\t}\n+}\n+\n static int ref_newer(const unsigned char *new_sha1,\n \t\t     const unsigned char *old_sha1)\n {\n \tstruct object *o;\n \tstruct commit *old, *new;\n-\tstruct commit_list *list;\n+\tstruct commit_list *list, *used;\n+\tint found = 0;\n \n \t/* Both new and old must be commit-ish and new is descendant of\n \t * old.  Otherwise we require --force.\n@@ -127,14 +138,20 @@ static int ref_newer(const unsigned char\n \n \tif (parse_commit(new) < 0)\n \t\treturn 0;\n-\tlist = NULL;\n+\n+\tused = list = NULL;\n \tcommit_list_insert(new, &list);\n \twhile (list) {\n \t\tnew = pop_most_recent_commit(&list, 1);\n-\t\tif (new == old)\n-\t\t\treturn 1;\n+\t\tcommit_list_insert(new, &used);\n+\t\tif (new == old) {\n+\t\t\tfound = 1;\n+\t\t\tbreak;\n+\t\t}\n \t}\n-\treturn 0;\n+\tunmark_and_free(list, 1);\n+\tunmark_and_free(used, 1);\n+\treturn found;\n }\n \n static struct ref *local_refs, **local_tail;\n"}]}