Skip to content

Commit d7a5649

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b5dd96b commit d7a5649

File tree

5 files changed

+7
-16
lines changed

5 files changed

+7
-16
lines changed

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,6 @@ EXTRA_PROGRAMS =
671671
# ... and all the rest that could be moved out of bindir to gitexecdir
672672
PROGRAMS += $(EXTRA_PROGRAMS)
673673

674-
PROGRAM_OBJS += bugreport.o
675674
PROGRAM_OBJS += daemon.o
676675
PROGRAM_OBJS += fast-import.o
677676
PROGRAM_OBJS += http-backend.o
@@ -1041,6 +1040,7 @@ BUILTIN_OBJS += builtin/archive.o
10411040
BUILTIN_OBJS += builtin/bisect--helper.o
10421041
BUILTIN_OBJS += builtin/blame.o
10431042
BUILTIN_OBJS += builtin/branch.o
1043+
BUILTIN_OBJS += builtin/bugreport.o
10441044
BUILTIN_OBJS += builtin/bundle.o
10451045
BUILTIN_OBJS += builtin/cat-file.o
10461046
BUILTIN_OBJS += builtin/check-attr.o
@@ -2458,10 +2458,6 @@ endif
24582458
git-%$X: %.o GIT-LDFLAGS $(GITLIBS)
24592459
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
24602460

2461-
git-bugreport$X: bugreport.o GIT-LDFLAGS $(GITLIBS)
2462-
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
2463-
$(LIBS)
2464-
24652461
git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
24662462
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
24672463
$(IMAP_SEND_LDFLAGS) $(LIBS)

builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ int cmd_archive(int argc, const char **argv, const char *prefix);
119119
int cmd_bisect__helper(int argc, const char **argv, const char *prefix);
120120
int cmd_blame(int argc, const char **argv, const char *prefix);
121121
int cmd_branch(int argc, const char **argv, const char *prefix);
122+
int cmd_bugreport(int argc, const char **argv, const char *prefix);
122123
int cmd_bundle(int argc, const char **argv, const char *prefix);
123124
int cmd_cat_file(int argc, const char **argv, const char *prefix);
124125
int cmd_checkout(int argc, const char **argv, const char *prefix);

bugreport.c renamed to builtin/bugreport.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cache.h"
1+
#include "builtin.h"
22
#include "parse-options.h"
33
#include "strbuf.h"
44
#include "help.h"
@@ -119,16 +119,14 @@ static void get_header(struct strbuf *buf, const char *title)
119119
strbuf_addf(buf, "\n\n[%s]\n", title);
120120
}
121121

122-
int cmd_main(int argc, const char **argv)
122+
int cmd_bugreport(int argc, const char **argv, const char *prefix)
123123
{
124124
struct strbuf buffer = STRBUF_INIT;
125125
struct strbuf report_path = STRBUF_INIT;
126126
int report = -1;
127127
time_t now = time(NULL);
128128
char *option_output = NULL;
129129
char *option_suffix = "%Y-%m-%d-%H%M";
130-
int nongit_ok = 0;
131-
const char *prefix = NULL;
132130
const char *user_relative_path = NULL;
133131

134132
const struct option bugreport_options[] = {
@@ -139,8 +137,6 @@ int cmd_main(int argc, const char **argv)
139137
OPT_END()
140138
};
141139

142-
prefix = setup_git_directory_gently(&nongit_ok);
143-
144140
argc = parse_options(argc, argv, prefix, bugreport_options,
145141
bugreport_usage, 0);
146142

@@ -170,7 +166,7 @@ int cmd_main(int argc, const char **argv)
170166
get_system_info(&buffer);
171167

172168
get_header(&buffer, _("Enabled Hooks"));
173-
get_populated_hooks(&buffer, nongit_ok);
169+
get_populated_hooks(&buffer, !startup_info->have_repository);
174170

175171
/* fopen doesn't offer us an O_EXCL alternative, except with glibc. */
176172
report = open(report_path.buf, O_CREAT | O_EXCL | O_WRONLY, 0666);

contrib/buildsystems/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ unset(CMAKE_REQUIRED_INCLUDES)
501501

502502
#programs
503503
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
505505
git-shell git-remote-testsvn)
506506

507507
if(NOT CURL_FOUND)
@@ -624,9 +624,6 @@ list(TRANSFORM git_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
624624
add_executable(git ${CMAKE_SOURCE_DIR}/git.c ${git_SOURCES})
625625
target_link_libraries(git common-main)
626626

627-
add_executable(git-bugreport ${CMAKE_SOURCE_DIR}/bugreport.c)
628-
target_link_libraries(git-bugreport common-main)
629-
630627
add_executable(git-daemon ${CMAKE_SOURCE_DIR}/daemon.c)
631628
target_link_libraries(git-daemon common-main)
632629

git.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ static struct cmd_struct commands[] = {
479479
{ "bisect--helper", cmd_bisect__helper, RUN_SETUP },
480480
{ "blame", cmd_blame, RUN_SETUP },
481481
{ "branch", cmd_branch, RUN_SETUP | DELAY_PAGER_CONFIG },
482+
{ "bugreport", cmd_bugreport, RUN_SETUP_GENTLY },
482483
{ "bundle", cmd_bundle, RUN_SETUP_GENTLY | NO_PARSEOPT },
483484
{ "cat-file", cmd_cat_file, RUN_SETUP },
484485
{ "check-attr", cmd_check_attr, RUN_SETUP },

0 commit comments

Comments
 (0)