{"thread":{"id":"1153","subject":"[PATCH] Simplification - remove unnecessary list reversal from epoch.c","startedAt":"2005-07-07T02:27:14Z","lastAt":"2005-07-07T02:27:14Z","messageCount":1,"participants":["Jon Seymour"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"5748","messageId":"20050707022714.31167.qmail@blackcubes.dyndns.org","threadId":"1153","inReplyTo":null,"subject":"[PATCH] Simplification - remove unnecessary list reversal from epoch.c","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2005-07-07T02:27:14Z","receivedAt":"2005-07-07T02:27:14Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"\nSince --merge-order is the only thing that cares about the rev-list\nparse order, change the rev-list list to match the parse order\nand remove the corresponding compensating reversal from epoch.c.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n[PATCH] Move SEEN flag into epoch.h, replace use of VISITED flag with SEEN flag\n---\n\n epoch.c    |   26 ++++++++++++--------------\n rev-list.c |    3 ++-\n 2 files changed, 14 insertions(+), 15 deletions(-)\n\n198b131890a2c6fc98ce4c151dc20bd4f548acf0\ndiff --git a/epoch.c b/epoch.c\n--- a/epoch.c\n+++ b/epoch.c\n@@ -580,37 +580,35 @@ int sort_list_in_merge_order(struct comm\n \tstruct commit *base;\n \tint ret = 0;\n \tint action = CONTINUE;\n-\tstruct commit_list *reversed = NULL;\n+\tstruct commit_list *next = NULL;\n \n-\tfor (; list; list = list->next) {\n-\t\tlist->item->object.flags &= ~(SEEN|BOUNDARY|DISCONTINUITY);\n-\t\tcommit_list_insert(list->item, &reversed);\n-\t}\n+\tfor (next=list; next; next = next->next)\n+\t\tnext->item->object.flags &= ~(SEEN|BOUNDARY|DISCONTINUITY);\n \n-\tif (!reversed)\n+\tif (!list)\n \t\treturn ret;\n-\telse if (!reversed->next) {\n+\telse if (!list->next) {\n \t\t/*\n \t\t * If there is only one element in the list, we can sort it\n \t\t * using sort_in_merge_order.\n \t\t */\n-\t\tbase = reversed->item;\n+\t\tbase = list->item;\n \t} else {\n \t\t/*\n \t\t * Otherwise, we search for the base of the list.\n \t\t */\n-\t\tret = find_base_for_list(reversed, &base);\n+\t\tret = find_base_for_list(list, &base);\n \t\tif (ret)\n \t\t\treturn ret;\n \t\tif (base)\n \t\t\tbase->object.flags |= BOUNDARY;\n \n-\t\twhile (reversed) {\n-\t\t\tstruct commit * next = pop_commit(&reversed);\n+\t\tfor (next=list; next; next=next->next) {\n+\t\t\tstruct commit * next_item = next->item;\n \n-\t\t\tif (!(next->object.flags & SEEN) && next!=base) {\n-\t\t\t\tsort_first_epoch(next, &stack);\n-\t\t\t\tif (reversed) {\n+\t\t\tif (!(next_item->object.flags & SEEN) && next_item!=base) {\n+\t\t\t\tsort_first_epoch(next_item, &stack);\n+\t\t\t\tif (next) {\n \t\t\t\t\t/*\n \t\t\t\t\t * If we have more commits \n \t\t\t\t\t * to push, then the first\ndiff --git a/rev-list.c b/rev-list.c\n--- a/rev-list.c\n+++ b/rev-list.c\n@@ -407,6 +407,7 @@ static struct commit *get_commit_referen\n int main(int argc, char **argv)\n {\n \tstruct commit_list *list = NULL;\n+\tstruct commit_list **list_tail = &list;\n \tint i, limited = 0;\n \n \tfor (i = 1 ; i < argc; i++) {\n@@ -484,7 +485,7 @@ int main(int argc, char **argv)\n \t\tif (commit->object.flags & SEEN)\n \t\t\tcontinue;\n \t\tcommit->object.flags |= SEEN;\n-\t\tcommit_list_insert(commit, &list);\n+\t\tlist_tail = &commit_list_insert(commit, list_tail)->next;\n \t}\n \n \tif (!merge_order) {\t\t\n------------\n"}]}