{"thread":{"id":"61212","subject":"[GSoC] [PATCH] builtin/gc: Replace run_command with C function refs_pack_refs","startedAt":"2024-03-28T04:09:57Z","lastAt":"2024-03-28T04:31:48Z","messageCount":3,"participants":["vk","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"491720","messageId":"20240328040010.40230-1-g@vkabc.me","threadId":"61212","inReplyTo":null,"subject":"[GSoC] [PATCH] builtin/gc: Replace run_command with C function refs_pack_refs","fromName":"vk","fromEmail":"g@vkabc.me","sentAt":"2024-03-28T04:00:10Z","receivedAt":"2024-03-28T04:09:57Z","isPatch":true,"sender":{"key":"g@vkabc.me","avatar":null},"body":"Replace \"git pack-refs\" with C function refs_pack_refs\nfor maintenance_task_pack_refs(). C function refs_pack_refs\ncan be called directly, hence saving an external process.\n---\n builtin/gc.c | 29 +++++++++++++++++++++++------\n 1 file changed, 23 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex 3c874b248b..b55c5f5225 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -42,6 +42,8 @@\n #include \"setup.h\"\n #include \"trace2.h\"\n \n+#include <revision.h>\n+\n #define FAILED_RUN \"failed to run %s\"\n \n static const char * const builtin_gc_usage[] = {\n@@ -218,14 +220,29 @@ static int pack_refs_condition(void)\n \n static int maintenance_task_pack_refs(MAYBE_UNUSED struct maintenance_run_opts *opts)\n {\n-\tstruct child_process cmd = CHILD_PROCESS_INIT;\n \n-\tcmd.git_cmd = 1;\n-\tstrvec_pushl(&cmd.args, \"pack-refs\", \"--all\", \"--prune\", NULL);\n-\tif (opts->auto_flag)\n-\t\tstrvec_push(&cmd.args, \"--auto\");\n+\t//following coding convention in pack-refs.c\n+\tint ret;\n+\n+\tstruct ref_exclusions excludes = REF_EXCLUSIONS_INIT;\n+\tstruct string_list included_refs = STRING_LIST_INIT_NODUP;\n+\n+\t//default flag is to prune\n+\tstruct pack_refs_opts pack_refs_opts = {\n+\t\t.exclusions = &excludes,\n+\t\t.includes = &included_refs,\n+\t\t.flags = PACK_REFS_PRUNE,\n+\t};\n+\n+\n+\t//--all flag\n+\tstring_list_append(pack_refs_opts.includes, \"*\");\n+\n+\tret = refs_pack_refs(get_main_ref_store(the_repository), &pack_refs_opts);\n+\n+\t//same as run_command return since ret is directly returned in cmd_pack_refs\n+\treturn ret;\n \n-\treturn run_command(&cmd);\n }\n \n static int too_many_loose_objects(void)\n-- \n2.39.3 (Apple Git-145)\n\n"},{"id":"491721","messageId":"0a149be978e68271c251e80f8eb571f4@vkabc.me","threadId":"61212","inReplyTo":"20240328040010.40230-1-g@vkabc.me","subject":"Re: [GSoC] [PATCH] builtin/gc: Replace run_command with C function refs_pack_refs","fromName":"vk","fromEmail":"g@vkabc.me","sentAt":"2024-03-28T04:12:06Z","receivedAt":"2024-03-28T04:17:19Z","isPatch":true,"sender":{"key":"g@vkabc.me","avatar":null},"body":"On 2024-03-28 12:00, vk wrote:\n> Replace \"git pack-refs\" with C function refs_pack_refs\n> for maintenance_task_pack_refs(). C function refs_pack_refs\n> can be called directly, hence saving an external process.\n> ---\n>  builtin/gc.c | 29 +++++++++++++++++++++++------\n>  1 file changed, 23 insertions(+), 6 deletions(-)\n> \n> diff --git a/builtin/gc.c b/builtin/gc.c\n> index 3c874b248b..b55c5f5225 100644\n> --- a/builtin/gc.c\n> +++ b/builtin/gc.c\n> @@ -42,6 +42,8 @@\n>  #include \"setup.h\"\n>  #include \"trace2.h\"\n> \n> +#include <revision.h>\n> +\n>  #define FAILED_RUN \"failed to run %s\"\n> \n>  static const char * const builtin_gc_usage[] = {\n> @@ -218,14 +220,29 @@ static int pack_refs_condition(void)\n> \n>  static int maintenance_task_pack_refs(MAYBE_UNUSED struct \n> maintenance_run_opts *opts)\n>  {\n> -\tstruct child_process cmd = CHILD_PROCESS_INIT;\n> \n> -\tcmd.git_cmd = 1;\n> -\tstrvec_pushl(&cmd.args, \"pack-refs\", \"--all\", \"--prune\", NULL);\n> -\tif (opts->auto_flag)\n> -\t\tstrvec_push(&cmd.args, \"--auto\");\n\nI forgot to add this --auto optional logic. Will add it in the following \npatch.\n\nThanks\n\n"},{"id":"491722","messageId":"xmqqedbvyo28.fsf@gitster.g","threadId":"61212","inReplyTo":"0a149be978e68271c251e80f8eb571f4@vkabc.me","subject":"Re: [GSoC] [PATCH] builtin/gc: Replace run_command with C function refs_pack_refs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-03-28T04:31:43Z","receivedAt":"2024-03-28T04:31:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"vk <g@vkabc.me> writes:\n\n> I forgot to add this --auto optional logic. Will add it in the\n> following patch.\n\nPlease slow down a bit.  If you notice a problem in the patch you\njust posted within 7 minutes after posting it, there is a good\nchance that you are rushing it without carefully proofreading.\n\nYou'd be better off if you give yourself some time to think about\nwhat you wrote, after drafting your patch.  Sleep on it, if needed.\n\nThere are issues in the patch.  Trying to spot them yourself would\ngive you a good exercise.  Documentation/SubmittingPatches and\nDocumentation/CodingGuidelines would be useful.\n\nThanks for your interest in Git development.\n"}]}