{"thread":{"id":"58766","subject":"[PATCH] revisions API: extend the nascent REV_INFO_INIT macro","startedAt":"2022-11-08T14:03:08Z","lastAt":"2022-11-08T14:03:08Z","messageCount":1,"participants":["Ævar Arnfjörð Bjarmason"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"466822","messageId":"patch-1.1-c3afcd69ddb-20221108T140134Z-avarab@gmail.com","threadId":"58766","inReplyTo":null,"subject":"[PATCH] revisions API: extend the nascent REV_INFO_INIT macro","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-08T14:02:57Z","receivedAt":"2022-11-08T14:03:08Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Have the REV_INFO_INIT macro added in [1] declare more members of\n\"struct rev_info\" that we can initialize statically, and have\nrepo_init_revisions() do so with the memcpy(..., &blank) idiom\nintroduced in [2].\n\nAs the comment for the \"REV_INFO_INIT\" macro notes this still isn't\nsufficient to initialize a \"struct rev_info\" for use yet. But we are\ngetting closer to that eventual goal.\n\nEven though we can't fully initialize a \"struct rev_info\" with\nREV_INFO_INIT it's useful for readability to clearly separate those\nthings that we can statically initialize, and those that we can't.\n\nThis change could replace the:\n\n\tlist_objects_filter_init(&revs->filter);\n\nIn the repo_init_revisions() with this line, at the end of the\nREV_INFO_INIT deceleration in revisions.h:\n\n\t.filter = LIST_OBJECTS_FILTER_INIT, \\\n\nBut doing so would produce a minor conflict with an outstanding\ntopic[3]. Let's skip that for now. I have follow-ups to initialize\nmore of this statically, e.g. changes to get rid of grep_init(). We\ncan initialize more members with the macro in a future series.\n\n1. f196c1e908d (revisions API users: use release_revisions() needing\n   REV_INFO_INIT, 2022-04-13)\n2. 5726a6b4012 (*.c *_init(): define in terms of corresponding *_INIT\n   macro, 2021-07-01)\n3. https://lore.kernel.org/git/265b292ed5c2de19b7118dfe046d3d9d932e2e89.1667901510.git.ps@pks.im/\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n\nA small follow-up to what I mentioned in[1]. As noted above there's a\nvery small part of Patrick's series that *could* use this[2] (getting\nrid of the trivial \"init_ref_exclusions\"), but let's not hold that up\nfor this minor cleanup, and have these proceed concurrently without\nconflicts.\n\n1. https://lore.kernel.org/git/221107.86tu3ax5b6.gmgdl@evledraar.gmail.com/\n2. https://lore.kernel.org/git/265b292ed5c2de19b7118dfe046d3d9d932e2e89.1667901510.git.ps@pks.im/\n\n revision.c | 19 ++-----------------\n revision.h | 18 +++++++++++++++++-\n 2 files changed, 19 insertions(+), 18 deletions(-)\n\ndiff --git a/revision.c b/revision.c\nindex 0760e78936e..c6b39965834 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1865,30 +1865,15 @@ void repo_init_revisions(struct repository *r,\n \t\t\t struct rev_info *revs,\n \t\t\t const char *prefix)\n {\n-\tmemset(revs, 0, sizeof(*revs));\n+\tstruct rev_info blank = REV_INFO_INIT;\n+\tmemcpy(revs, &blank, sizeof(*revs));\n \n \trevs->repo = r;\n-\trevs->abbrev = DEFAULT_ABBREV;\n-\trevs->simplify_history = 1;\n \trevs->pruning.repo = r;\n-\trevs->pruning.flags.recursive = 1;\n-\trevs->pruning.flags.quick = 1;\n \trevs->pruning.add_remove = file_add_remove;\n \trevs->pruning.change = file_change;\n \trevs->pruning.change_fn_data = revs;\n-\trevs->sort_order = REV_SORT_IN_GRAPH_ORDER;\n-\trevs->dense = 1;\n \trevs->prefix = prefix;\n-\trevs->max_age = -1;\n-\trevs->max_age_as_filter = -1;\n-\trevs->min_age = -1;\n-\trevs->skip_count = -1;\n-\trevs->max_count = -1;\n-\trevs->max_parents = -1;\n-\trevs->expand_tabs_in_log = -1;\n-\n-\trevs->commit_format = CMIT_FMT_DEFAULT;\n-\trevs->expand_tabs_in_log_default = 8;\n \n \tgrep_init(&revs->grep_filter, revs->repo);\n \trevs->grep_filter.status_only = 1;\ndiff --git a/revision.h b/revision.h\nindex afe1b77985f..8493a3f3b93 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -357,7 +357,23 @@ struct rev_info {\n  * called before release_revisions() the \"struct rev_info\" can be left\n  * uninitialized.\n  */\n-#define REV_INFO_INIT { 0 }\n+#define REV_INFO_INIT { \\\n+\t.abbrev = DEFAULT_ABBREV, \\\n+\t.simplify_history = 1, \\\n+\t.pruning.flags.recursive = 1, \\\n+\t.pruning.flags.quick = 1, \\\n+\t.sort_order = REV_SORT_IN_GRAPH_ORDER, \\\n+\t.dense = 1, \\\n+\t.max_age = -1, \\\n+\t.max_age_as_filter = -1, \\\n+\t.min_age = -1, \\\n+\t.skip_count = -1, \\\n+\t.max_count = -1, \\\n+\t.max_parents = -1, \\\n+\t.expand_tabs_in_log = -1, \\\n+\t.commit_format = CMIT_FMT_DEFAULT, \\\n+\t.expand_tabs_in_log_default = 8, \\\n+}\n \n /**\n  * Initialize a rev_info structure with default values. The third parameter may\n-- \n2.38.0.1464.gea6794aacbc\n\n"}]}