{"thread":{"id":"9883","subject":"[PATCH 1/3] rev-list --bisect: Move finding bisection into do_find_bisection.","startedAt":"2007-09-17T03:28:20Z","lastAt":"2007-09-17T03:28:20Z","messageCount":1,"participants":["Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"53249","messageId":"20070917052820.e83f31d5.chriscool@tuxfamily.org","threadId":"9883","inReplyTo":null,"subject":"[PATCH 1/3] rev-list --bisect: Move finding bisection into do_find_bisection.","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2007-09-17T03:28:20Z","receivedAt":"2007-09-17T03:28:20Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This factorises some code and make a big function smaller.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin-rev-list.c |   90 +++++++++++++++++++++++++++------------------------\n 1 files changed, 48 insertions(+), 42 deletions(-)\n\n\tThis patch series is a resend with the changes Junio asked for. \n\ndiff --git a/builtin-rev-list.c b/builtin-rev-list.c\nindex ac551d5..2dae287 100644\n--- a/builtin-rev-list.c\n+++ b/builtin-rev-list.c\n@@ -268,39 +268,12 @@ static void show_list(const char *debug, int counted, int nr,\n  * unknown.  After running count_distance() first, they will get zero\n  * or positive distance.\n  */\n-\n-static struct commit_list *find_bisection(struct commit_list *list,\n-\t\t\t\t\t  int *reaches, int *all)\n+static struct commit_list *do_find_bisection(struct commit_list *list,\n+\t\t\t\t\t     int nr, int *weights)\n {\n-\tint n, nr, on_list, counted, distance;\n-\tstruct commit_list *p, *best, *next, *last;\n-\tint *weights;\n-\n-\tshow_list(\"bisection 2 entry\", 0, 0, list);\n-\n-\t/*\n-\t * Count the number of total and tree-changing items on the\n-\t * list, while reversing the list.\n-\t */\n-\tfor (nr = on_list = 0, last = NULL, p = list;\n-\t     p;\n-\t     p = next) {\n-\t\tunsigned flags = p->item->object.flags;\n+\tint n, counted, distance;\n+\tstruct commit_list *p, *best;\n \n-\t\tnext = p->next;\n-\t\tif (flags & UNINTERESTING)\n-\t\t\tcontinue;\n-\t\tp->next = last;\n-\t\tlast = p;\n-\t\tif (!revs.prune_fn || (flags & TREECHANGE))\n-\t\t\tnr++;\n-\t\ton_list++;\n-\t}\n-\tlist = last;\n-\tshow_list(\"bisection 2 sorted\", 0, nr, list);\n-\n-\t*all = nr;\n-\tweights = xcalloc(on_list, sizeof(*weights));\n \tcounted = 0;\n \n \tfor (n = 0, p = list; p; p = p->next) {\n@@ -357,12 +330,8 @@ static struct commit_list *find_bisection(struct commit_list *list,\n \t\tweight_set(p, distance);\n \n \t\t/* Does it happen to be at exactly half-way? */\n-\t\tif (halfway(p, distance, nr)) {\n-\t\t\tp->next = NULL;\n-\t\t\t*reaches = distance;\n-\t\t\tfree(weights);\n+\t\tif (halfway(p, distance, nr))\n \t\t\treturn p;\n-\t\t}\n \t\tcounted++;\n \t}\n \n@@ -400,12 +369,8 @@ static struct commit_list *find_bisection(struct commit_list *list,\n \n \t\t\t/* Does it happen to be at exactly half-way? */\n \t\t\tdistance = weight(p);\n-\t\t\tif (halfway(p, distance, nr)) {\n-\t\t\t\tp->next = NULL;\n-\t\t\t\t*reaches = distance;\n-\t\t\t\tfree(weights);\n+\t\t\tif (halfway(p, distance, nr))\n \t\t\t\treturn p;\n-\t\t\t}\n \t\t}\n \t}\n \n@@ -425,12 +390,53 @@ static struct commit_list *find_bisection(struct commit_list *list,\n \t\tif (distance > counted) {\n \t\t\tbest = p;\n \t\t\tcounted = distance;\n-\t\t\t*reaches = weight(p);\n \t\t}\n \t}\n+\treturn best;\n+}\n+\n+static struct commit_list *find_bisection(struct commit_list *list,\n+\t\t\t\t\t  int *reaches, int *all)\n+{\n+\tint nr, on_list;\n+\tstruct commit_list *p, *best, *next, *last;\n+\tint *weights;\n+\n+\tshow_list(\"bisection 2 entry\", 0, 0, list);\n+\n+\t/*\n+\t * Count the number of total and tree-changing items on the\n+\t * list, while reversing the list.\n+\t */\n+\tfor (nr = on_list = 0, last = NULL, p = list;\n+\t     p;\n+\t     p = next) {\n+\t\tunsigned flags = p->item->object.flags;\n+\n+\t\tnext = p->next;\n+\t\tif (flags & UNINTERESTING)\n+\t\t\tcontinue;\n+\t\tp->next = last;\n+\t\tlast = p;\n+\t\tif (!revs.prune_fn || (flags & TREECHANGE))\n+\t\t\tnr++;\n+\t\ton_list++;\n+\t}\n+\tlist = last;\n+\tshow_list(\"bisection 2 sorted\", 0, nr, list);\n+\n+\t*all = nr;\n+\tweights = xcalloc(on_list, sizeof(*weights));\n+\n+\t/* Do the real work of finding bisection commit. */\n+\tbest = do_find_bisection(list, nr, weights);\n+\n \tif (best)\n \t\tbest->next = NULL;\n+\n+\t*reaches = weight(best);\n \tfree(weights);\n+\n \treturn best;\n }\n \n-- \n1.5.3.1.59.g93705\n"}]}