{"thread":{"id":"59417","subject":"[PATCH 2/2] treewide: remove unnecessary inclusions of parse-options.h from headers","startedAt":"2023-03-19T16:29:36Z","lastAt":"2023-03-20T16:49:37Z","messageCount":4,"participants":["SZEDER Gábor","Elijah Newren"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"473733","messageId":"20230319162712.654137-2-szeder.dev@gmail.com","threadId":"59417","inReplyTo":"20230319162712.654137-1-szeder.dev@gmail.com","subject":"[PATCH 1/2] treewide: include parse-options.h in source files","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2023-03-19T16:27:11Z","receivedAt":"2023-03-19T16:29:36Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"The builtins 'ls-remote', 'pack-objects', 'receive-pack', 'reflog' and\n'send-pack' use parse_options(), but their source files don't directly\ninclude 'parse-options.h'.  Furthermore, the source files\n'diagnose.c', 'list-objects-filter-options.c', 'remote.c' and\n'send-pack.c' define option parsing callback functions, while\n'revision.c' defines an option parsing helper function, and thus need\naccess to various fields in 'struct option' and 'struct\nparse_opt_ctx_t', but they don't directly include 'parse-options.h'\neither.  They all can still be built, of course, because they include\none of the header files that does include 'parse-options.h' (though\nunnecessarily, see the next commit).\n\nAdd those missing includes to these files, as our general rule is that\n\"a C file must directly include the header files that declare the\nfunctions and the types it uses\".\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n builtin/ls-remote.c           | 1 +\n builtin/pack-objects.c        | 1 +\n builtin/receive-pack.c        | 1 +\n builtin/reflog.c              | 1 +\n builtin/send-pack.c           | 1 +\n diagnose.c                    | 1 +\n list-objects-filter-options.c | 1 +\n remote.c                      | 1 +\n revision.c                    | 1 +\n send-pack.c                   | 1 +\n 10 files changed, 10 insertions(+)\n\ndiff --git a/builtin/ls-remote.c b/builtin/ls-remote.c\nindex 2dfbd8ed9b..a9de0575ce 100644\n--- a/builtin/ls-remote.c\n+++ b/builtin/ls-remote.c\n@@ -5,6 +5,7 @@\n #include \"ref-filter.h\"\n #include \"remote.h\"\n #include \"refs.h\"\n+#include \"parse-options.h\"\n \n static const char * const ls_remote_usage[] = {\n \tN_(\"git ls-remote [--heads] [--tags] [--refs] [--upload-pack=<exec>]\\n\"\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 545b8bddc8..7e9e20172a 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -39,6 +39,7 @@\n #include \"shallow.h\"\n #include \"promisor-remote.h\"\n #include \"pack-mtimes.h\"\n+#include \"parse-options.h\"\n \n /*\n  * Objects we are going to pack are collected in the `to_pack` structure.\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex fe68c79ee3..fcc87595ac 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -31,6 +31,7 @@\n #include \"commit-reach.h\"\n #include \"worktree.h\"\n #include \"shallow.h\"\n+#include \"parse-options.h\"\n \n static const char * const receive_pack_usage[] = {\n \tN_(\"git receive-pack <git-dir>\"),\ndiff --git a/builtin/reflog.c b/builtin/reflog.c\nindex 270681dcdf..9b000bb6bc 100644\n--- a/builtin/reflog.c\n+++ b/builtin/reflog.c\n@@ -4,6 +4,7 @@\n #include \"reachable.h\"\n #include \"worktree.h\"\n #include \"reflog.h\"\n+#include \"parse-options.h\"\n \n #define BUILTIN_REFLOG_SHOW_USAGE \\\n \tN_(\"git reflog [show] [<log-options>] [<ref>]\")\ndiff --git a/builtin/send-pack.c b/builtin/send-pack.c\nindex fb5b2bad2c..42a04ed6fc 100644\n--- a/builtin/send-pack.c\n+++ b/builtin/send-pack.c\n@@ -16,6 +16,7 @@\n #include \"gpg-interface.h\"\n #include \"gettext.h\"\n #include \"protocol.h\"\n+#include \"parse-options.h\"\n \n static const char * const send_pack_usage[] = {\n \tN_(\"git send-pack [--mirror] [--dry-run] [--force]\\n\"\ndiff --git a/diagnose.c b/diagnose.c\nindex 5b398f0cff..998f517c48 100644\n--- a/diagnose.c\n+++ b/diagnose.c\n@@ -8,6 +8,7 @@\n #include \"strvec.h\"\n #include \"object-store.h\"\n #include \"packfile.h\"\n+#include \"parse-options.h\"\n \n struct archive_dir {\n \tconst char *path;\ndiff --git a/list-objects-filter-options.c b/list-objects-filter-options.c\nindex 1d25a5737d..72aeb089cc 100644\n--- a/list-objects-filter-options.c\n+++ b/list-objects-filter-options.c\n@@ -11,6 +11,7 @@\n #include \"promisor-remote.h\"\n #include \"trace.h\"\n #include \"url.h\"\n+#include \"parse-options.h\"\n \n static int parse_combine_filter(\n \tstruct list_objects_filter_options *filter_options,\ndiff --git a/remote.c b/remote.c\nindex b04e5da338..641b083d90 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -17,6 +17,7 @@\n #include \"commit-reach.h\"\n #include \"advice.h\"\n #include \"connect.h\"\n+#include \"parse-options.h\"\n \n enum map_direction { FROM_SRC, FROM_DST };\n \ndiff --git a/revision.c b/revision.c\nindex e4c066e90b..8b1ecf07fc 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -37,6 +37,7 @@\n #include \"json-writer.h\"\n #include \"list-objects-filter-options.h\"\n #include \"resolve-undo.h\"\n+#include \"parse-options.h\"\n \n volatile show_early_output_fn_t show_early_output;\n \ndiff --git a/send-pack.c b/send-pack.c\nindex 423a5cfe22..0d05191162 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -17,6 +17,7 @@\n #include \"gpg-interface.h\"\n #include \"cache.h\"\n #include \"shallow.h\"\n+#include \"parse-options.h\"\n \n int option_parse_push_signed(const struct option *opt,\n \t\t\t     const char *arg, int unset)\n-- \n2.40.0.499.g88fa0b00d2\n\n"},{"id":"473732","messageId":"20230319162712.654137-3-szeder.dev@gmail.com","threadId":"59417","inReplyTo":"20230319162712.654137-1-szeder.dev@gmail.com","subject":"[PATCH 2/2] treewide: remove unnecessary inclusions of parse-options.h from headers","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2023-03-19T16:27:12Z","receivedAt":"2023-03-19T16:29:37Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"The headers 'diagnose.h', 'list-objects-filter-options.h',\n'ref-filter.h' and 'remote.h' declare option parsing callback\nfunctions with a 'struct option*' parameter, and 'revision.h' declares\nan option parsing helper function taking 'struct parse_opt_ctx_t*' and\n'struct option*' parameters.  These headers all include\n'parse-options.h', although they don't need any of the type\ndefinitions from that header file.  Furthermore,\n'list-objects-filter-options.h' and 'ref-filter.h' also define some\nOPT_* macros to initialize a 'struct option', but these don't\nnecessitate the inclusion of parse-options.h in these headers either,\nbecause these macros are only expanded in source files.\n\nRemove these unnecessary inclusions of parse-options.h and use forward\ndeclarations to declare the necessary types.\n\nAfter this patch none of the header files include parse-options.h\nanymore.\n\nWith these changes, the build time after modifying only\nparse-options.h is reduced by about 30%, and the number of targets\nbuilt is almost 20% less:\n\n  Before:\n\n    $ touch parse-options.h && time make -j4 |wc -l\n    353\n\n    real    1m1.527s\n    user    3m32.205s\n    sys\t    0m15.903s\n\n  After:\n\n    289\n\n    real    0m39.285s\n    user    2m12.540s\n    sys     0m11.164s\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n diagnose.h                    | 3 ++-\n list-objects-filter-options.h | 3 ++-\n ref-filter.h                  | 2 +-\n remote.h                      | 2 +-\n revision.h                    | 3 ++-\n 5 files changed, 8 insertions(+), 5 deletions(-)\n\ndiff --git a/diagnose.h b/diagnose.h\nindex 7a4951a786..f525219ab0 100644\n--- a/diagnose.h\n+++ b/diagnose.h\n@@ -2,7 +2,8 @@\n #define DIAGNOSE_H\n \n #include \"strbuf.h\"\n-#include \"parse-options.h\"\n+\n+struct option;\n \n enum diagnose_mode {\n \tDIAGNOSE_NONE,\ndiff --git a/list-objects-filter-options.h b/list-objects-filter-options.h\nindex ef03b45132..727c986122 100644\n--- a/list-objects-filter-options.h\n+++ b/list-objects-filter-options.h\n@@ -2,10 +2,11 @@\n #define LIST_OBJECTS_FILTER_OPTIONS_H\n \n #include \"object.h\"\n-#include \"parse-options.h\"\n #include \"string-list.h\"\n #include \"strbuf.h\"\n \n+struct option;\n+\n /*\n  * The list of defined filters for list-objects.\n  */\ndiff --git a/ref-filter.h b/ref-filter.h\nindex aa0eea4ecf..daa6d02017 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -4,7 +4,6 @@\n #include \"oid-array.h\"\n #include \"refs.h\"\n #include \"commit.h\"\n-#include \"parse-options.h\"\n \n /* Quoting styles */\n #define QUOTE_NONE 0\n@@ -24,6 +23,7 @@\n \n struct atom_value;\n struct ref_sorting;\n+struct option;\n \n enum ref_sorting_order {\n \tREF_SORTING_REVERSE = 1<<0,\ndiff --git a/remote.h b/remote.h\nindex 5b38ee20b8..73638cefeb 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -1,10 +1,10 @@\n #ifndef REMOTE_H\n #define REMOTE_H\n \n-#include \"parse-options.h\"\n #include \"hashmap.h\"\n #include \"refspec.h\"\n \n+struct option;\n struct transport_ls_refs_options;\n \n /**\ndiff --git a/revision.h b/revision.h\nindex ab71443696..649f817f39 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -2,7 +2,6 @@\n #define REVISION_H\n \n #include \"commit.h\"\n-#include \"parse-options.h\"\n #include \"grep.h\"\n #include \"notes.h\"\n #include \"pretty.h\"\n@@ -62,6 +61,8 @@ struct string_list;\n struct saved_parents;\n struct bloom_key;\n struct bloom_filter_settings;\n+struct option;\n+struct parse_opt_ctx_t;\n define_shared_commit_slab(revision_sources, char *);\n \n struct rev_cmdline_info {\n-- \n2.40.0.499.g88fa0b00d2\n\n"},{"id":"473734","messageId":"20230319162712.654137-1-szeder.dev@gmail.com","threadId":"59417","inReplyTo":null,"subject":"[PATCH 0/2] Remove unnecessary inclusions of parse-options.h from headers","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2023-03-19T16:27:10Z","receivedAt":"2023-03-19T16:29:37Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Some source files use parse_options(), but don't include\nparse-options.h, while some headers do include parse-options.h, though\ndon't really need it.  These patches fix these issues.\n\nThis series has a small and simple conflict with the 'ds/ahead-behind'\ntopic, and it will have small conflicts with Elijah's header cleanup\nseries as well:\n\n  https://public-inbox.org/git/pull.1493.git.1679207282.gitgitgadget@gmail.com/T/#t\n\n\nSZEDER Gábor (2):\n  treewide: include parse-options.h in source files\n  treewide: remove unnecessary inclusions of parse-options.h from\n    headers\n\n builtin/ls-remote.c           | 1 +\n builtin/pack-objects.c        | 1 +\n builtin/receive-pack.c        | 1 +\n builtin/reflog.c              | 1 +\n builtin/send-pack.c           | 1 +\n diagnose.c                    | 1 +\n diagnose.h                    | 3 ++-\n list-objects-filter-options.c | 1 +\n list-objects-filter-options.h | 3 ++-\n ref-filter.h                  | 2 +-\n remote.c                      | 1 +\n remote.h                      | 2 +-\n revision.c                    | 1 +\n revision.h                    | 3 ++-\n send-pack.c                   | 1 +\n 15 files changed, 18 insertions(+), 5 deletions(-)\n\n-- \n2.40.0.499.g88fa0b00d2\n\n"},{"id":"473783","messageId":"CABPp-BHVsxVQJrar3qc1xGCSwFXKtBmma1V4xo__8YMOi0Xc2w@mail.gmail.com","threadId":"59417","inReplyTo":"20230319162712.654137-1-szeder.dev@gmail.com","subject":"Re: [PATCH 0/2] Remove unnecessary inclusions of parse-options.h from headers","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2023-03-20T16:41:03Z","receivedAt":"2023-03-20T16:49:37Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Sun, Mar 19, 2023 at 10:13 AM SZEDER Gábor <szeder.dev@gmail.com> wrote:\n>\n> Some source files use parse_options(), but don't include\n> parse-options.h, while some headers do include parse-options.h, though\n> don't really need it.  These patches fix these issues.\n\nNice!\n\nReviewed-by: Elijah Newren <newren@gmail.com>\n\n> This series has a small and simple conflict with the 'ds/ahead-behind'\n> topic, and it will have small conflicts with Elijah's header cleanup\n> series as well:\n>\n>   https://public-inbox.org/git/pull.1493.git.1679207282.gitgitgadget@gmail.com/T/#t\n\nPerhaps it makes sense to rebase your series on that one?  (And/or add\nthe headers earlier in the list instead of at the end to reduce the\nodds of patch collisions?  I really wish we had our #include's in\nalphabetical order instead of always appending to the end, because it\nboth reduces the odds of conflicts and is so much easier for humans to\ncheck.)\n"}]}