@matheusbsbs / matheus-bagliano / commits / d7a5649c82
Fork 0

make git-bugreport a builtin

There's no reason that bugreport has to be a separate binary. And since it links against libgit.a, it has a rather large disk footprint. Let's make it a builtin, which reduces the size of a stripped installation from 24MB to 22MB. This also simplifies our Makefile a bit. And we can take advantage of builtin niceties like RUN_SETUP_GENTLY. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 13, 2020 at 10:59 UTC d7a5649c82dfa83ba8d0253e4140f242dca859a7
5 files changed +7 -16
Makefile
+1 -5
@@ -671,7 +671,6 @@ EXTRA_PROGRAMS =
671 # ... and all the rest that could be moved out of bindir to gitexecdir
672 PROGRAMS += $(EXTRA_PROGRAMS)
673
674 -PROGRAM_OBJS += bugreport.o
674 PROGRAM_OBJS += daemon.o
675 PROGRAM_OBJS += fast-import.o
676 PROGRAM_OBJS += http-backend.o
@@ -1041,6 +1040,7 @@ BUILTIN_OBJS += builtin/archive.o
1040 BUILTIN_OBJS += builtin/bisect--helper.o
1041 BUILTIN_OBJS += builtin/blame.o
1042 BUILTIN_OBJS += builtin/branch.o
1043 +BUILTIN_OBJS += builtin/bugreport.o
1044 BUILTIN_OBJS += builtin/bundle.o
1045 BUILTIN_OBJS += builtin/cat-file.o
1046 BUILTIN_OBJS += builtin/check-attr.o
@@ -2458,10 +2458,6 @@ endif
2458 git-%$X: %.o GIT-LDFLAGS $(GITLIBS)
2459 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
2460
2461 -git-bugreport$X: bugreport.o GIT-LDFLAGS $(GITLIBS)
2462 - $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
2463 - $(LIBS)
2464 -
2461 git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
2462 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
2463 $(IMAP_SEND_LDFLAGS) $(LIBS)
builtin.h
+1
@@ -119,6 +119,7 @@ int cmd_archive(int argc, const char **argv, const char *prefix);
119 int cmd_bisect__helper(int argc, const char **argv, const char *prefix);
120 int cmd_blame(int argc, const char **argv, const char *prefix);
121 int cmd_branch(int argc, const char **argv, const char *prefix);
122 +int cmd_bugreport(int argc, const char **argv, const char *prefix);
123 int cmd_bundle(int argc, const char **argv, const char *prefix);
124 int cmd_cat_file(int argc, const char **argv, const char *prefix);
125 int cmd_checkout(int argc, const char **argv, const char *prefix);
builtin/bugreport.c renamed
+3 -7
@@ -1,4 +1,4 @@
1 -#include "cache.h"
1 +#include "builtin.h"
2 #include "parse-options.h"
3 #include "strbuf.h"
4 #include "help.h"
@@ -119,7 +119,7 @@ static void get_header(struct strbuf *buf, const char *title)
119 strbuf_addf(buf, "\n\n[%s]\n", title);
120 }
121
122 -int cmd_main(int argc, const char **argv)
122 +int cmd_bugreport(int argc, const char **argv, const char *prefix)
123 {
124 struct strbuf buffer = STRBUF_INIT;
125 struct strbuf report_path = STRBUF_INIT;
@@ -127,8 +127,6 @@ int cmd_main(int argc, const char **argv)
127 time_t now = time(NULL);
128 char *option_output = NULL;
129 char *option_suffix = "%Y-%m-%d-%H%M";
130 - int nongit_ok = 0;
131 - const char *prefix = NULL;
130 const char *user_relative_path = NULL;
131
132 const struct option bugreport_options[] = {
@@ -139,8 +137,6 @@ int cmd_main(int argc, const char **argv)
137 OPT_END()
138 };
139
142 - prefix = setup_git_directory_gently(&nongit_ok);
143 -
140 argc = parse_options(argc, argv, prefix, bugreport_options,
141 bugreport_usage, 0);
142
@@ -170,7 +166,7 @@ int cmd_main(int argc, const char **argv)
166 get_system_info(&buffer);
167
168 get_header(&buffer, _("Enabled Hooks"));
173 - get_populated_hooks(&buffer, nongit_ok);
169 + get_populated_hooks(&buffer, !startup_info->have_repository);
170
171 /* fopen doesn't offer us an O_EXCL alternative, except with glibc. */
172 report = open(report_path.buf, O_CREAT | O_EXCL | O_WRONLY, 0666);
contrib/buildsystems/CMakeLists.txt
+1 -4
@@ -501,7 +501,7 @@ unset(CMAKE_REQUIRED_INCLUDES)
501
502 #programs
503 set(PROGRAMS_BUILT
504 - git git-bugreport git-daemon git-fast-import git-http-backend git-sh-i18n--envsubst
504 + git git-daemon git-fast-import git-http-backend git-sh-i18n--envsubst
505 git-shell git-remote-testsvn)
506
507 if(NOT CURL_FOUND)
@@ -624,9 +624,6 @@ list(TRANSFORM git_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
624 add_executable(git ${CMAKE_SOURCE_DIR}/git.c ${git_SOURCES})
625 target_link_libraries(git common-main)
626
627 -add_executable(git-bugreport ${CMAKE_SOURCE_DIR}/bugreport.c)
628 -target_link_libraries(git-bugreport common-main)
629 -
627 add_executable(git-daemon ${CMAKE_SOURCE_DIR}/daemon.c)
628 target_link_libraries(git-daemon common-main)
629
git.c
+1
@@ -479,6 +479,7 @@ static struct cmd_struct commands[] = {
479 { "bisect--helper", cmd_bisect__helper, RUN_SETUP },
480 { "blame", cmd_blame, RUN_SETUP },
481 { "branch", cmd_branch, RUN_SETUP | DELAY_PAGER_CONFIG },
482 + { "bugreport", cmd_bugreport, RUN_SETUP_GENTLY },
483 { "bundle", cmd_bundle, RUN_SETUP_GENTLY | NO_PARSEOPT },
484 { "cat-file", cmd_cat_file, RUN_SETUP },
485 { "check-attr", cmd_check_attr, RUN_SETUP },