{"thread":{"id":"48811","subject":"Feature request : \"git fsck\" should show the percentage of completeness in step \"Checking connectivity:\"","startedAt":"2018-07-01T16:21:49Z","lastAt":"2018-07-02T21:41:17Z","messageCount":3,"participants":["Toralf Förster","Stefan Beller","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"351477","messageId":"3d6b38a8-7dbe-0633-5c54-603161ee3fd4@gmx.de","threadId":"48811","inReplyTo":null,"subject":"Feature request : \"git fsck\" should show the percentage of completeness in step \"Checking connectivity:\"","fromName":"Toralf Förster","fromEmail":"toralf.foerster@gmx.de","sentAt":"2018-07-01T16:21:40Z","receivedAt":"2018-07-01T16:21:49Z","isPatch":false,"sender":{"key":"toralf.foerster@gmx.de","avatar":null},"body":"as \"git fsck\" does it already for \"Checking objects:\"\n\nIs this a valid feature request?\n\n-- \nToralf\nPGP C4EACDDE 0076E94E\n"},{"id":"351554","messageId":"CAGZ79kYoRziU12hsU4ST90JyxTvMqXSxq-eHnn6jGndzQ_fZ6g@mail.gmail.com","threadId":"48811","inReplyTo":"3d6b38a8-7dbe-0633-5c54-603161ee3fd4@gmx.de","subject":"Re: Feature request : \"git fsck\" should show the percentage of completeness in step \"Checking connectivity:\"","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-07-02T19:59:35Z","receivedAt":"2018-07-02T19:59:50Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Sun, Jul 1, 2018 at 9:22 AM Toralf Förster <toralf.foerster@gmx.de> wrote:\n>\n> as \"git fsck\" does it already for \"Checking objects:\"\n>\n> Is this a valid feature request?\n\nYes it is. However it is most likely to have the feature incorporated if\nit comes in form of a patch.\n\nSo clone one of the git.git repositories found at\nhttps://git-blame.blogspot.com/p/git-public-repositories.html\nand have a look builtin/fsck.c (Search for \"Checking connectivity\")\nas well as how the progress.{h, c} for its API if needed.\n\nI am not sure if this is an easy thing to add, as knowing the number\nof objects before the walk might be hard. How does \"Checking objects\"\nsolve that issue?\n\nSee Documentation/SubmittingPatches once you have some code\nthat can be a starter of a discussion. :)\n\nThanks,\nStefan\n"},{"id":"351569","messageId":"20180702214103.GA26121@sigill.intra.peff.net","threadId":"48811","inReplyTo":"3d6b38a8-7dbe-0633-5c54-603161ee3fd4@gmx.de","subject":"Re: Feature request : \"git fsck\" should show the percentage of completeness in step \"Checking connectivity:\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-07-02T21:41:03Z","receivedAt":"2018-07-02T21:41:17Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Jul 01, 2018 at 06:21:40PM +0200, Toralf Förster wrote:\n\n> as \"git fsck\" does it already for \"Checking objects:\"\n> \n> Is this a valid feature request?\n\nIt's actually hard to do accurately. We don't know how many objects are\nreachable until we traverse the graph...which is exactly what the\n\"checking connectivity\" operation is doing.\n\nThe operation is bounded by the total number of objects in the\nrepository. We may have duplicates (in multiple packs, or loose/packed),\nand objects which aren't reachable at all. But we could make that a\nguess, and just \"jump\" to 100% at the end.\n\nThe code might look something like the patch below. I'm not sure if it's\na good idea or not (I mostly copied the counting from\nbuiltin/count-objects.c; it might be nice to factor that out).\n\n-Peff\n\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 3ad4f160f9..52e79aed76 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -192,17 +192,49 @@ static int traverse_one_object(struct object *obj)\n \treturn result;\n }\n \n+static int count_loose(const struct object_id *oid, const char *path,\n+\t\t       void *data)\n+{\n+\tunsigned int *nr = data;\n+\tnr++;\n+\treturn 0;\n+}\n+\n+static unsigned object_max(void)\n+{\n+\tunsigned max = 0;\n+\tstruct packed_git *p;\n+\n+\tfor_each_loose_object(count_loose, &max, 0);\n+\n+\tfor (p = get_packed_git(the_repository); p; p = p->next) {\n+\t\tif (open_pack_index(p))\n+\t\t\tcontinue;\n+\t\tmax += p->num_objects;\n+\t}\n+\n+\treturn max;\n+}\n+\n static int traverse_reachable(void)\n {\n \tstruct progress *progress = NULL;\n \tunsigned int nr = 0;\n \tint result = 0;\n-\tif (show_progress)\n-\t\tprogress = start_delayed_progress(_(\"Checking connectivity\"), 0);\n+\tunsigned int max = 0;\n+\n+\tif (show_progress) {\n+\t\tmax = object_max();\n+\t\tprogress = start_delayed_progress(_(\"Checking connectivity\"),\n+\t\t\t\t\t\t  max);\n+\t}\n+\n \twhile (pending.nr) {\n \t\tresult |= traverse_one_object(object_array_pop(&pending));\n \t\tdisplay_progress(progress, ++nr);\n \t}\n+\n+\tdisplay_progress(progress, max);\n \tstop_progress(&progress);\n \treturn !!result;\n }\n"}]}