Skip to content

Commit b5dd96b

Browse files
peffgitster
authored andcommitted
make credential helpers builtins
There's no real reason for credential helpers to be separate binaries. I did them this way originally under the notion that helper don't _need_ to be part of Git, and so can be built totally separately (and indeed, the ones in contrib/credential are). But the ones in our main Makefile build on libgit.a, and the resulting binaries are reasonably large. We can slim down our total disk footprint by just making them builtins. This reduces the size of: make strip install from 29MB to 24MB on my Debian system. Note that credential-cache can't operate without support for Unix sockets. Currently we just don't build it at all when NO_UNIX_SOCKETS is set. We could continue that with conditionals in the Makefile and our list of builtins. But instead, let's build a dummy implementation that dies with an informative message. That has two advantages: - it's simpler, because the conditional bits are all kept inside the credential-cache source - a user who is expecting it to exist will be told _why_ they can't use it, rather than getting the "credential-cache is not a git command" error which makes it look like the Git install is broken. Note that our dummy implementation does still respond to "-h" in order to appease t0012 (and this may be a little friendlier for users, as well). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a04f653 commit b5dd96b

File tree

7 files changed

+63
-35
lines changed

7 files changed

+63
-35
lines changed

Makefile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,6 @@ EXTRA_PROGRAMS =
672672
PROGRAMS += $(EXTRA_PROGRAMS)
673673

674674
PROGRAM_OBJS += bugreport.o
675-
PROGRAM_OBJS += credential-store.o
676675
PROGRAM_OBJS += daemon.o
677676
PROGRAM_OBJS += fast-import.o
678677
PROGRAM_OBJS += http-backend.o
@@ -1052,6 +1051,9 @@ BUILTIN_OBJS += builtin/checkout-index.o
10521051
BUILTIN_OBJS += builtin/checkout.o
10531052
BUILTIN_OBJS += builtin/clean.o
10541053
BUILTIN_OBJS += builtin/clone.o
1054+
BUILTIN_OBJS += builtin/credential-cache.o
1055+
BUILTIN_OBJS += builtin/credential-cache--daemon.o
1056+
BUILTIN_OBJS += builtin/credential-store.o
10551057
BUILTIN_OBJS += builtin/column.o
10561058
BUILTIN_OBJS += builtin/commit-graph.o
10571059
BUILTIN_OBJS += builtin/commit-tree.o
@@ -1634,11 +1636,8 @@ ifdef NO_INET_PTON
16341636
endif
16351637
ifdef NO_UNIX_SOCKETS
16361638
BASIC_CFLAGS += -DNO_UNIX_SOCKETS
1637-
EXCLUDED_PROGRAMS += git-credential-cache git-credential-cache--daemon
16381639
else
16391640
LIB_OBJS += unix-socket.o
1640-
PROGRAM_OBJS += credential-cache.o
1641-
PROGRAM_OBJS += credential-cache--daemon.o
16421641
endif
16431642

16441643
ifdef NO_ICONV
@@ -2901,7 +2900,6 @@ ifdef MSVC
29012900
# because it is just a copy/hardlink of git.exe, rather than a unique binary.
29022901
$(INSTALL) git.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
29032902
$(INSTALL) git-shell.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2904-
$(INSTALL) git-credential-store.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
29052903
$(INSTALL) git-daemon.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
29062904
$(INSTALL) git-fast-import.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
29072905
$(INSTALL) git-http-backend.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'

builtin.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix);
138138
int cmd_config(int argc, const char **argv, const char *prefix);
139139
int cmd_count_objects(int argc, const char **argv, const char *prefix);
140140
int cmd_credential(int argc, const char **argv, const char *prefix);
141+
int cmd_credential_cache(int argc, const char **argv, const char *prefix);
142+
int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix);
143+
int cmd_credential_store(int argc, const char **argv, const char *prefix);
141144
int cmd_describe(int argc, const char **argv, const char *prefix);
142145
int cmd_diff_files(int argc, const char **argv, const char *prefix);
143146
int cmd_diff_index(int argc, const char **argv, const char *prefix);

credential-cache--daemon.c renamed to builtin/credential-cache--daemon.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
#include "cache.h"
1+
#include "builtin.h"
2+
#include "parse-options.h"
3+
4+
#ifndef NO_UNIX_SOCKETS
5+
26
#include "config.h"
37
#include "tempfile.h"
48
#include "credential.h"
59
#include "unix-socket.h"
6-
#include "parse-options.h"
710

811
struct credential_cache_entry {
912
struct credential item;
@@ -257,7 +260,7 @@ static void init_socket_directory(const char *path)
257260
free(path_copy);
258261
}
259262

260-
int cmd_main(int argc, const char **argv)
263+
int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
261264
{
262265
struct tempfile *socket_file;
263266
const char *socket_path;
@@ -275,7 +278,7 @@ int cmd_main(int argc, const char **argv)
275278

276279
git_config_get_bool("credentialcache.ignoresighup", &ignore_sighup);
277280

278-
argc = parse_options(argc, argv, NULL, options, usage, 0);
281+
argc = parse_options(argc, argv, prefix, options, usage, 0);
279282
socket_path = argv[0];
280283

281284
if (!socket_path)
@@ -295,3 +298,21 @@ int cmd_main(int argc, const char **argv)
295298

296299
return 0;
297300
}
301+
302+
#else
303+
304+
int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
305+
{
306+
const char * const usage[] = {
307+
"git credential-cache--daemon [options] <action>",
308+
"",
309+
"credential-cache--daemon is disabled in this build of Git",
310+
NULL
311+
};
312+
struct option options[] = { OPT_END() };
313+
314+
argc = parse_options(argc, argv, prefix, options, usage, 0);
315+
die(_("credential-cache--daemon unavailable; no unix socket support"));
316+
}
317+
318+
#endif /* NO_UNIX_SOCKET */

credential-cache.c renamed to builtin/credential-cache.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
#include "cache.h"
1+
#include "builtin.h"
2+
#include "parse-options.h"
3+
4+
#ifndef NO_UNIX_SOCKETS
5+
26
#include "credential.h"
37
#include "string-list.h"
4-
#include "parse-options.h"
58
#include "unix-socket.h"
69
#include "run-command.h"
710

@@ -96,7 +99,7 @@ static char *get_socket_path(void)
9699
return socket;
97100
}
98101

99-
int cmd_main(int argc, const char **argv)
102+
int cmd_credential_cache(int argc, const char **argv, const char *prefix)
100103
{
101104
char *socket_path = NULL;
102105
int timeout = 900;
@@ -113,7 +116,7 @@ int cmd_main(int argc, const char **argv)
113116
OPT_END()
114117
};
115118

116-
argc = parse_options(argc, argv, NULL, options, usage, 0);
119+
argc = parse_options(argc, argv, prefix, options, usage, 0);
117120
if (!argc)
118121
usage_with_options(usage, options);
119122
op = argv[0];
@@ -134,3 +137,21 @@ int cmd_main(int argc, const char **argv)
134137

135138
return 0;
136139
}
140+
141+
#else
142+
143+
int cmd_credential_cache(int argc, const char **argv, const char *prefix)
144+
{
145+
const char * const usage[] = {
146+
"git credential-cache [options] <action>",
147+
"",
148+
"credential-cache is disabled in this build of Git",
149+
NULL
150+
};
151+
struct option options[] = { OPT_END() };
152+
153+
argc = parse_options(argc, argv, prefix, options, usage, 0);
154+
die(_("credential-cache unavailable; no unix socket support"));
155+
}
156+
157+
#endif /* NO_UNIX_SOCKETS */

credential-store.c renamed to builtin/credential-store.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cache.h"
1+
#include "builtin.h"
22
#include "lockfile.h"
33
#include "credential.h"
44
#include "string-list.h"
@@ -143,7 +143,7 @@ static void lookup_credential(const struct string_list *fns, struct credential *
143143
return; /* Found credential */
144144
}
145145

146-
int cmd_main(int argc, const char **argv)
146+
int cmd_credential_store(int argc, const char **argv, const char *prefix)
147147
{
148148
const char * const usage[] = {
149149
"git credential-store [<options>] <action>",
@@ -161,7 +161,7 @@ int cmd_main(int argc, const char **argv)
161161

162162
umask(077);
163163

164-
argc = parse_options(argc, (const char **)argv, NULL, options, usage, 0);
164+
argc = parse_options(argc, (const char **)argv, prefix, options, usage, 0);
165165
if (argc != 1)
166166
usage_with_options(usage, options);
167167
op = argv[0];

contrib/buildsystems/CMakeLists.txt

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

502502
#programs
503503
set(PROGRAMS_BUILT
504-
git git-bugreport git-credential-store git-daemon git-fast-import git-http-backend git-sh-i18n--envsubst
504+
git git-bugreport git-daemon git-fast-import git-http-backend git-sh-i18n--envsubst
505505
git-shell git-remote-testsvn)
506506

507-
if(NO_UNIX_SOCKETS)
508-
list(APPEND excluded_progs git-credential-cache git-credential-cache--daemon)
509-
else()
510-
list(APPEND PROGRAMS_BUILT git-credential-cache git-credential-cache--daemon)
511-
endif()
512-
513507
if(NOT CURL_FOUND)
514508
list(APPEND excluded_progs git-http-fetch git-http-push)
515509
add_compile_definitions(NO_CURL)
@@ -633,9 +627,6 @@ target_link_libraries(git common-main)
633627
add_executable(git-bugreport ${CMAKE_SOURCE_DIR}/bugreport.c)
634628
target_link_libraries(git-bugreport common-main)
635629

636-
add_executable(git-credential-store ${CMAKE_SOURCE_DIR}/credential-store.c)
637-
target_link_libraries(git-credential-store common-main)
638-
639630
add_executable(git-daemon ${CMAKE_SOURCE_DIR}/daemon.c)
640631
target_link_libraries(git-daemon common-main)
641632

@@ -672,15 +663,6 @@ endif()
672663
add_executable(git-remote-testsvn ${CMAKE_SOURCE_DIR}/remote-testsvn.c)
673664
target_link_libraries(git-remote-testsvn common-main vcs-svn)
674665

675-
if(NOT NO_UNIX_SOCKETS)
676-
add_executable(git-credential-cache ${CMAKE_SOURCE_DIR}/credential-cache.c)
677-
target_link_libraries(git-credential-cache common-main)
678-
679-
add_executable(git-credential-cache--daemon ${CMAKE_SOURCE_DIR}/credential-cache--daemon.c)
680-
target_link_libraries(git-credential-cache--daemon common-main)
681-
endif()
682-
683-
684666
set(git_builtin_extra
685667
cherry cherry-pick format-patch fsck-objects
686668
init merge-subtree restore show

git.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ static struct cmd_struct commands[] = {
499499
{ "config", cmd_config, RUN_SETUP_GENTLY | DELAY_PAGER_CONFIG },
500500
{ "count-objects", cmd_count_objects, RUN_SETUP },
501501
{ "credential", cmd_credential, RUN_SETUP_GENTLY | NO_PARSEOPT },
502+
{ "credential-cache", cmd_credential_cache },
503+
{ "credential-cache--daemon", cmd_credential_cache_daemon },
504+
{ "credential-store", cmd_credential_store },
502505
{ "describe", cmd_describe, RUN_SETUP },
503506
{ "diff", cmd_diff, NO_PARSEOPT },
504507
{ "diff-files", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT },

0 commit comments

Comments
 (0)