Hi all,
why is the git package in backfire so big? (45 MB, installed around 90 MB)
I found the answer: the original git makefile creates hard links for all the builtin programs (around 100 of them, 850KB each), the openwrt git makefile then just puts everyone of them in its own file (because it does not recognize the hard links).
I made a small patch for the original git makefile that creates symlinks instead of hardlinks, that reduces the package size to around 10% of the original.
There are more non built in programs in the package, that have a lot of code in common with each other and the main executable. So I decided to convert them all to builtins. Et volia: the main executable is now 90KB bigger, but the whole ipk is now 516KB, around 1% of the original. Now I can install it on my router, and it works, without disabling any git feature that wasn't disabled before.
I'm quite happy with the result. I would contribute the patch to openwrt, but since I am not so used to the open source working model, tools, etc, I think the patch has low quility. For example I think it breaks the makefile when having non default install directories, and maybe some possible error conditions in the make process won't be reported properly anymore.. not sure. But for anyone who thinks he can use the patch for himself, or wants to improve its quality to add it to openwrt, here it is:
From bff60e1b8acac7b049f778c8ad7e93541a3d2a8a Mon Sep 17 00:00:00 2001
From: I <wont@tell.com>
Date: Mon, 15 Nov 2010 09:50:40 +0100
Subject: [PATCH 1/9] changed makefile
---
Makefile | 27 ++++++++++++++-------------
1 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/Makefile b/Makefile
index 9b94e96..01ce8ab 100644
--- a/Makefile
+++ b/Makefile
@@ -356,19 +356,6 @@ EXTRA_PROGRAMS =
# ... and all the rest that could be moved out of bindir to gitexecdir
PROGRAMS += $(EXTRA_PROGRAMS)
-PROGRAMS += git-fast-import$X
-PROGRAMS += git-hash-object$X
-PROGRAMS += git-index-pack$X
-PROGRAMS += git-merge-index$X
-PROGRAMS += git-merge-tree$X
-PROGRAMS += git-mktag$X
-PROGRAMS += git-pack-redundant$X
-PROGRAMS += git-patch-id$X
-PROGRAMS += git-shell$X
-PROGRAMS += git-show-index$X
-PROGRAMS += git-unpack-file$X
-PROGRAMS += git-upload-pack$X
-PROGRAMS += git-var$X
# List built-in command $C whose implementation cmd_$C() is not in
# builtin-$C.o but is linked in as part of some other command.
@@ -388,6 +375,20 @@ BUILT_INS += git-stage$X
BUILT_INS += git-status$X
BUILT_INS += git-whatchanged$X
+BUILT_INS += git-fast-import$X
+BUILT_INS += git-hash-object$X
+BUILT_INS += git-index-pack$X
+BUILT_INS += git-merge-index$X
+BUILT_INS += git-merge-tree$X
+BUILT_INS += git-mktag$X
+BUILT_INS += git-pack-redundant$X
+BUILT_INS += git-patch-id$X
+BUILT_INS += git-shell$X
+BUILT_INS += git-show-index$X
+BUILT_INS += git-unpack-file$X
+BUILT_INS += git-upload-pack$X
+BUILT_INS += git-var$X
+
# what 'all' will build and 'install' will install in gitexecdir,
# excluding programs for built-in commands
ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS)
--
1.7.1
From 83253a310edafae5d1170459e7ecb11f8e07da76 Mon Sep 17 00:00:00 2001
From: I <wont@tell.com>
Date: Mon, 15 Nov 2010 10:07:38 +0100
Subject: [PATCH 2/9] renames
---
fast-import.c => builtin-fast-import.c | 0
hash-object.c => builtin-hash-object.c | 0
index-pack.c => builtin-index-pack.c | 0
merge-index.c => builtin-merge-index.c | 0
merge-tree.c => builtin-merge-tree.c | 0
mktag.c => builtin-mktag.c | 0
pack-redundant.c => builtin-pack-redundant.c | 0
patch-id.c => builtin-patch-id.c | 0
shell.c => builtin-shell.c | 0
show-index.c => builtin-show-index.c | 0
unpack-file.c => builtin-unpack-file.c | 0
upload-pack.c => builtin-upload-pack.c | 0
var.c => builtin-var.c | 0
builtin.h | 14 ++++++++++++++
git.c | 13 +++++++++++++
15 files changed, 27 insertions(+), 0 deletions(-)
rename fast-import.c => builtin-fast-import.c (100%)
rename hash-object.c => builtin-hash-object.c (100%)
rename index-pack.c => builtin-index-pack.c (100%)
rename merge-index.c => builtin-merge-index.c (100%)
rename merge-tree.c => builtin-merge-tree.c (100%)
rename mktag.c => builtin-mktag.c (100%)
rename pack-redundant.c => builtin-pack-redundant.c (100%)
rename patch-id.c => builtin-patch-id.c (100%)
rename shell.c => builtin-shell.c (100%)
rename show-index.c => builtin-show-index.c (100%)
rename unpack-file.c => builtin-unpack-file.c (100%)
rename upload-pack.c => builtin-upload-pack.c (100%)
rename var.c => builtin-var.c (100%)
diff --git a/fast-import.c b/builtin-fast-import.c
similarity index 100%
rename from fast-import.c
rename to builtin-fast-import.c
diff --git a/hash-object.c b/builtin-hash-object.c
similarity index 100%
rename from hash-object.c
rename to builtin-hash-object.c
diff --git a/index-pack.c b/builtin-index-pack.c
similarity index 100%
rename from index-pack.c
rename to builtin-index-pack.c
diff --git a/merge-index.c b/builtin-merge-index.c
similarity index 100%
rename from merge-index.c
rename to builtin-merge-index.c
diff --git a/merge-tree.c b/builtin-merge-tree.c
similarity index 100%
rename from merge-tree.c
rename to builtin-merge-tree.c
diff --git a/mktag.c b/builtin-mktag.c
similarity index 100%
rename from mktag.c
rename to builtin-mktag.c
diff --git a/pack-redundant.c b/builtin-pack-redundant.c
similarity index 100%
rename from pack-redundant.c
rename to builtin-pack-redundant.c
diff --git a/patch-id.c b/builtin-patch-id.c
similarity index 100%
rename from patch-id.c
rename to builtin-patch-id.c
diff --git a/shell.c b/builtin-shell.c
similarity index 100%
rename from shell.c
rename to builtin-shell.c
diff --git a/show-index.c b/builtin-show-index.c
similarity index 100%
rename from show-index.c
rename to builtin-show-index.c
diff --git a/unpack-file.c b/builtin-unpack-file.c
similarity index 100%
rename from unpack-file.c
rename to builtin-unpack-file.c
diff --git a/upload-pack.c b/builtin-upload-pack.c
similarity index 100%
rename from upload-pack.c
rename to builtin-upload-pack.c
diff --git a/var.c b/builtin-var.c
similarity index 100%
rename from var.c
rename to builtin-var.c
diff --git a/builtin.h b/builtin.h
index a2174dc..dde6ec7 100644
--- a/builtin.h
+++ b/builtin.h
@@ -114,4 +114,18 @@ extern int cmd_show_ref(int argc, const char **argv, const char *prefix);
extern int cmd_pack_refs(int argc, const char **argv, const char *prefix);
extern int cmd_replace(int argc, const char **argv, const char *prefix);
+extern int cmd_fast_import(int argc, const char **argv, const char *prefix);
+extern int cmd_hash_object(int argc, const char **argv, const char *prefix);
+extern int cmd_index_pack(int argc, const char **argv, const char *prefix);
+extern int cmd_merge_index(int argc, const char **argv, const char *prefix);
+extern int cmd_merge_tree(int argc, const char **argv, const char *prefix);
+extern int cmd_mktag(int argc, const char **argv, const char *prefix);
+extern int cmd_pack_redundant(int argc, const char **argv, const char *prefix);
+extern int cmd_patch_id(int argc, const char **argv, const char *prefix);
+extern int cmd_shell(int argc, const char **argv, const char *prefix);
+extern int cmd_show_index(int argc, const char **argv, const char *prefix);
+extern int cmd_unpack_file(int argc, const char **argv, const char *prefix);
+extern int cmd_upload_pack(int argc, const char **argv, const char *prefix);
+extern int cmd_var(int argc, const char **argv, const char *prefix);
+
#endif
diff --git a/git.c b/git.c
index 9883009..abf0ee0 100644
--- a/git.c
+++ b/git.c
@@ -368,6 +368,19 @@ static void handle_internal_command(int argc, const char **argv)
{ "verify-pack", cmd_verify_pack },
{ "show-ref", cmd_show_ref, RUN_SETUP },
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
+ { "fast-import", cmd_fast_import },
+ { "hash-object", cmd_hash_object },
+ { "index-pack", cmd_index_pack },
+ { "merge-index", cmd_merge_index },
+ { "merge-tree", cmd_merge_tree },
+ { "mktag", cmd_mktag },
+ { "pack-redundant", cmd_pack_redundant },
+ { "patch-id", cmd_patch_id },
+ { "shell", cmd_shell },
+ { "show-index", cmd_show_index },
+ { "unpack-file", cmd_unpack_file },
+ { "upload-pack", cmd_upload_pack },
+ { "var", cmd_var },
};
int i;
static const char ext[] = STRIP_EXTENSION;
--
1.7.1
From 54fbeb12b98e8c47727afc34b652af61381a2e45 Mon Sep 17 00:00:00 2001
From: I <wont@tell.com>
Date: Mon, 15 Nov 2010 10:16:59 +0100
Subject: [PATCH 3/9] func ren
---
builtin-fast-import.c | 2 +-
builtin-hash-object.c | 2 +-
builtin-index-pack.c | 2 +-
builtin-merge-index.c | 2 +-
builtin-merge-tree.c | 2 +-
builtin-mktag.c | 2 +-
builtin-pack-redundant.c | 2 +-
builtin-patch-id.c | 2 +-
builtin-shell.c | 2 +-
builtin-show-index.c | 2 +-
builtin-unpack-file.c | 2 +-
builtin-upload-pack.c | 2 +-
builtin-var.c | 2 +-
13 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/builtin-fast-import.c b/builtin-fast-import.c
index 6faaaac..86fdb43 100644
--- a/builtin-fast-import.c
+++ b/builtin-fast-import.c
@@ -2399,7 +2399,7 @@ static int git_pack_config(const char *k, const char *v, void *cb)
static const char fast_import_usage[] =
"git fast-import [--date-format=f] [--max-pack-size=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file]";
-int main(int argc, const char **argv)
+int cmd_fast_import(int argc, const char **argv, const char *prefix)
{
unsigned int i, show_stats = 1;
diff --git a/builtin-hash-object.c b/builtin-hash-object.c
index 9455dd0..1f6270b 100644
--- a/builtin-hash-object.c
+++ b/builtin-hash-object.c
@@ -73,7 +73,7 @@ static const struct option hash_object_options[] = {
OPT_END()
};
-int main(int argc, const char **argv)
+int cmd_hash_object(int argc, const char **argv, const char *prefix)
{
int i;
const char *prefix = NULL;
diff --git a/builtin-index-pack.c b/builtin-index-pack.c
index b4f8278..5677f17 100644
--- a/builtin-index-pack.c
+++ b/builtin-index-pack.c
@@ -870,7 +870,7 @@ static int git_index_pack_config(const char *k, const char *v, void *cb)
return git_default_config(k, v, cb);
}
-int main(int argc, char **argv)
+int cmd_index_pack(int argc, const char **argv, const char *prefix)
{
int i, fix_thin_pack = 0;
char *curr_pack, *pack_name = NULL;
diff --git a/builtin-merge-index.c b/builtin-merge-index.c
index 19ddd03..090153e 100644
--- a/builtin-merge-index.c
+++ b/builtin-merge-index.c
@@ -66,7 +66,7 @@ static void merge_all(void)
}
}
-int main(int argc, char **argv)
+int cmd_merge_index(int argc, const char **argv, const char *prefix)
{
int i, force_file = 0;
diff --git a/builtin-merge-tree.c b/builtin-merge-tree.c
index f01e7c8..3ebf33d 100644
--- a/builtin-merge-tree.c
+++ b/builtin-merge-tree.c
@@ -337,7 +337,7 @@ static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)
return buf;
}
-int main(int argc, char **argv)
+int cmd_merge_tree(int argc, const char **argv, const char *prefix)
{
struct tree_desc t[3];
void *buf1, *buf2, *buf3;
diff --git a/builtin-mktag.c b/builtin-mktag.c
index a3b4270..f260a65 100644
--- a/builtin-mktag.c
+++ b/builtin-mktag.c
@@ -153,7 +153,7 @@ static int verify_tag(char *buffer, unsigned long size)
#undef PD_FMT
-int main(int argc, char **argv)
+int cmd_mktag(int argc, const char **argv, const char *prefix)
{
struct strbuf buf = STRBUF_INIT;
unsigned char result_sha1[20];
diff --git a/builtin-pack-redundant.c b/builtin-pack-redundant.c
index 69a7ab2..c7341e0 100644
--- a/builtin-pack-redundant.c
+++ b/builtin-pack-redundant.c
@@ -593,7 +593,7 @@ static void load_all(void)
}
}
-int main(int argc, char **argv)
+int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
{
int i;
struct pack_list *min, *red, *pl;
diff --git a/builtin-patch-id.c b/builtin-patch-id.c
index 0df4cb0..52fc5c7 100644
--- a/builtin-patch-id.c
+++ b/builtin-patch-id.c
@@ -75,7 +75,7 @@ static void generate_id_list(void)
static const char patch_id_usage[] = "git patch-id < patch";
-int main(int argc, char **argv)
+int cmd_patch_id(int argc, const char **argv, const char *prefix)
{
if (argc != 1)
usage(patch_id_usage);
diff --git a/builtin-shell.c b/builtin-shell.c
index e4864e0..c032c0b 100644
--- a/builtin-shell.c
+++ b/builtin-shell.c
@@ -45,7 +45,7 @@ static struct commands {
{ NULL },
};
-int main(int argc, char **argv)
+int cmd_shell(int argc, const char **argv, const char *prefix)
{
char *prog;
struct commands *cmd;
diff --git a/builtin-show-index.c b/builtin-show-index.c
index 45bb535..e19ef53 100644
--- a/builtin-show-index.c
+++ b/builtin-show-index.c
@@ -1,7 +1,7 @@
#include "cache.h"
#include "pack.h"
-int main(int argc, char **argv)
+int cmd_show_index(int argc, const char **argv, const char *prefix)
{
int i;
unsigned nr;
diff --git a/builtin-unpack-file.c b/builtin-unpack-file.c
index ac9cbf7..97b9146 100644
--- a/builtin-unpack-file.c
+++ b/builtin-unpack-file.c
@@ -22,7 +22,7 @@ static char *create_temp_file(unsigned char *sha1)
return path;
}
-int main(int argc, char **argv)
+int cmd_unpack_file(int argc, const char **argv, const char *prefix)
{
unsigned char sha1[20];
diff --git a/builtin-upload-pack.c b/builtin-upload-pack.c
index 0ea8516..08005b0 100644
--- a/builtin-upload-pack.c
+++ b/builtin-upload-pack.c
@@ -650,7 +650,7 @@ static void upload_pack(void)
}
}
-int main(int argc, char **argv)
+int cmd_upload_pack(int argc, const char **argv, const char *prefix)
{
char *dir;
int i;
diff --git a/builtin-var.c b/builtin-var.c
index 125c0d1..2bd5187 100644
--- a/builtin-var.c
+++ b/builtin-var.c
@@ -48,7 +48,7 @@ static int show_config(const char *var, const char *value, void *cb)
return git_default_config(var, value, cb);
}
-int main(int argc, char **argv)
+int cmd_var(int argc, const char **argv, const char *prefix)
{
const char *val;
int nongit;
--
1.7.1
From e0a991f0f6aa4f9697c195b4582d2a6859f25383 Mon Sep 17 00:00:00 2001
From: I <wont@tell.com>
Date: Mon, 15 Nov 2010 10:23:29 +0100
Subject: [PATCH 4/9] makefile objs
---
Makefile | 14 +++++++++++++-
builtin.h | 1 -
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 01ce8ab..436e7d2 100644
--- a/Makefile
+++ b/Makefile
@@ -374,7 +374,6 @@ BUILT_INS += git-show$X
BUILT_INS += git-stage$X
BUILT_INS += git-status$X
BUILT_INS += git-whatchanged$X
-
BUILT_INS += git-fast-import$X
BUILT_INS += git-hash-object$X
BUILT_INS += git-index-pack$X
@@ -656,6 +655,19 @@ BUILTIN_OBJS += builtin-upload-archive.o
BUILTIN_OBJS += builtin-verify-pack.o
BUILTIN_OBJS += builtin-verify-tag.o
BUILTIN_OBJS += builtin-write-tree.o
+BUILTIN_OBJS += builtin-fast-import.o
+BUILTIN_OBJS += builtin-hash-object.o
+BUILTIN_OBJS += builtin-index-pack.o
+BUILTIN_OBJS += builtin-merge-index.o
+BUILTIN_OBJS += builtin-merge-tree.o
+BUILTIN_OBJS += builtin-mktag.o
+BUILTIN_OBJS += builtin-pack-redundant.o
+BUILTIN_OBJS += builtin-patch-id.o
+BUILTIN_OBJS += builtin-shell.o
+BUILTIN_OBJS += builtin-show-index.o
+BUILTIN_OBJS += builtin-unpack-file.o
+BUILTIN_OBJS += builtin-upload-pack.o
+BUILTIN_OBJS += builtin-var.o
GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
EXTLIBS =
diff --git a/builtin.h b/builtin.h
index dde6ec7..9ba53b0 100644
--- a/builtin.h
+++ b/builtin.h
@@ -113,7 +113,6 @@ extern int cmd_verify_pack(int argc, const char **argv, const char *prefix);
extern int cmd_show_ref(int argc, const char **argv, const char *prefix);
extern int cmd_pack_refs(int argc, const char **argv, const char *prefix);
extern int cmd_replace(int argc, const char **argv, const char *prefix);
-
extern int cmd_fast_import(int argc, const char **argv, const char *prefix);
extern int cmd_hash_object(int argc, const char **argv, const char *prefix);
extern int cmd_index_pack(int argc, const char **argv, const char *prefix);
--
1.7.1
From 6fc6af49ecb77d68fb01e25c8f675d15bc8a4519 Mon Sep 17 00:00:00 2001
From: I <wont@tell.com>
Date: Mon, 15 Nov 2010 10:27:40 +0100
Subject: [PATCH 5/9] bug fixes
---
Makefile | 13 -------------
builtin-hash-object.c | 1 -
2 files changed, 0 insertions(+), 14 deletions(-)
diff --git a/Makefile b/Makefile
index 436e7d2..5ee1054 100644
--- a/Makefile
+++ b/Makefile
@@ -374,19 +374,6 @@ BUILT_INS += git-show$X
BUILT_INS += git-stage$X
BUILT_INS += git-status$X
BUILT_INS += git-whatchanged$X
-BUILT_INS += git-fast-import$X
-BUILT_INS += git-hash-object$X
-BUILT_INS += git-index-pack$X
-BUILT_INS += git-merge-index$X
-BUILT_INS += git-merge-tree$X
-BUILT_INS += git-mktag$X
-BUILT_INS += git-pack-redundant$X
-BUILT_INS += git-patch-id$X
-BUILT_INS += git-shell$X
-BUILT_INS += git-show-index$X
-BUILT_INS += git-unpack-file$X
-BUILT_INS += git-upload-pack$X
-BUILT_INS += git-var$X
# what 'all' will build and 'install' will install in gitexecdir,
# excluding programs for built-in commands
diff --git a/builtin-hash-object.c b/builtin-hash-object.c
index 1f6270b..40fd6d3 100644
--- a/builtin-hash-object.c
+++ b/builtin-hash-object.c
@@ -76,7 +76,6 @@ static const struct option hash_object_options[] = {
int cmd_hash_object(int argc, const char **argv, const char *prefix)
{
int i;
- const char *prefix = NULL;
int prefix_length = -1;
const char *errstr = NULL;
--
1.7.1
From bf7e673a0576a721ca7939bdf7687d1e1a35ee80 Mon Sep 17 00:00:00 2001
From: I <wont@tell.com>
Date: Mon, 15 Nov 2010 11:01:31 +0100
Subject: [PATCH 6/9] compile warnings/errors
---
builtin-index-pack.c | 30 +++++++++++++++++-------------
builtin-merge-index.c | 2 +-
builtin-pack-redundant.c | 2 +-
builtin-shell.c | 3 ++-
builtin-upload-pack.c | 5 +++--
5 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/builtin-index-pack.c b/builtin-index-pack.c
index 5677f17..dfb1efd 100644
--- a/builtin-index-pack.c
+++ b/builtin-index-pack.c
@@ -166,29 +166,32 @@ static void use(int bytes)
consumed_bytes += bytes;
}
-static char *open_pack_file(char *pack_name)
+static char *open_pack_file(const char *pack_name)
{
+ char *new_pack_name;
+ new_pack_name = xstrdup(pack_name);
if (from_stdin) {
input_fd = 0;
if (!pack_name) {
static char tmpfile[PATH_MAX];
output_fd = odb_mkstemp(tmpfile, sizeof(tmpfile),
"pack/tmp_pack_XXXXXX");
- pack_name = xstrdup(tmpfile);
+ free(new_pack_name);
+ new_pack_name = xstrdup(tmpfile);
} else
- output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);
+ output_fd = open(new_pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);
if (output_fd < 0)
- die_errno("unable to create '%s'", pack_name);
+ die_errno("unable to create '%s'", new_pack_name);
pack_fd = output_fd;
} else {
- input_fd = open(pack_name, O_RDONLY);
+ input_fd = open(new_pack_name, O_RDONLY);
if (input_fd < 0)
- die_errno("cannot open packfile '%s'", pack_name);
+ die_errno("cannot open packfile '%s'", new_pack_name);
output_fd = -1;
pack_fd = input_fd;
}
git_SHA1_Init(&input_ctx);
- return pack_name;
+ return new_pack_name;
}
static void parse_pack_header(void)
@@ -873,8 +876,10 @@ static int git_index_pack_config(const char *k, const char *v, void *cb)
int cmd_index_pack(int argc, const char **argv, const char *prefix)
{
int i, fix_thin_pack = 0;
- char *curr_pack, *pack_name = NULL;
- char *curr_index, *index_name = NULL;
+ char *curr_pack;
+ const char *pack_name = NULL;
+ char *curr_index;
+ char *index_name = NULL;
const char *keep_name = NULL, *keep_msg = NULL;
char *index_name_buf = NULL, *keep_name_buf = NULL;
struct pack_idx_entry **idx_objects;
@@ -903,7 +908,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
}
for (i = 1; i < argc; i++) {
- char *arg = argv[i];
+ const char *arg = argv[i];
if (*arg == '-') {
if (!strcmp(arg, "--stdin")) {
@@ -934,7 +939,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
} else if (!strcmp(arg, "-o")) {
if (index_name || (i+1) >= argc)
usage(index_pack_usage);
- index_name = argv[++i];
+ index_name = xstrdup(argv[++i]);
} else if (!prefixcmp(arg, "--index-version=")) {
char *c;
pack_idx_default_version = strtoul(arg + 16, &c, 10);
@@ -1035,8 +1040,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
free(objects);
free(index_name_buf);
free(keep_name_buf);
- if (pack_name == NULL)
- free(curr_pack);
+ free(curr_pack);
if (index_name == NULL)
free(curr_index);
diff --git a/builtin-merge-index.c b/builtin-merge-index.c
index 090153e..f3899d7 100644
--- a/builtin-merge-index.c
+++ b/builtin-merge-index.c
@@ -94,7 +94,7 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix)
}
pgm = argv[i++];
for (; i < argc; i++) {
- char *arg = argv[i];
+ const char *arg = argv[i];
if (!force_file && *arg == '-') {
if (!strcmp(arg, "--")) {
force_file = 1;
diff --git a/builtin-pack-redundant.c b/builtin-pack-redundant.c
index c7341e0..568aa64 100644
--- a/builtin-pack-redundant.c
+++ b/builtin-pack-redundant.c
@@ -568,7 +568,7 @@ static struct pack_list * add_pack(struct packed_git *p)
return pack_list_insert(&altodb_packs, &l);
}
-static struct pack_list * add_pack_file(char *filename)
+static struct pack_list * add_pack_file(const char *filename)
{
struct packed_git *p = packed_git;
diff --git a/builtin-shell.c b/builtin-shell.c
index c032c0b..fc47dc0 100644
--- a/builtin-shell.c
+++ b/builtin-shell.c
@@ -76,7 +76,7 @@ int cmd_shell(int argc, const char **argv, const char *prefix)
else if (argc != 3 || strcmp(argv[1], "-c"))
die("What do you think I am? A shell?");
- prog = argv[2];
+ prog = xstrdup(argv[2]);
if (!strncmp(prog, "git", 3) && isspace(prog[3]))
/* Accept "git foo" as if the caller said "git-foo". */
prog[3] = '-';
@@ -97,6 +97,7 @@ int cmd_shell(int argc, const char **argv, const char *prefix)
default:
continue;
}
+ free(prog);
exit(cmd->exec(cmd->name, arg));
}
die("unrecognized command '%s'", prog);
diff --git a/builtin-upload-pack.c b/builtin-upload-pack.c
index 08005b0..aee6d1f 100644
--- a/builtin-upload-pack.c
+++ b/builtin-upload-pack.c
@@ -660,7 +660,7 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
read_replace_refs = 0;
for (i = 1; i < argc; i++) {
- char *arg = argv[i];
+ const char *arg = argv[i];
if (arg[0] != '-')
break;
@@ -684,7 +684,7 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
setup_path();
- dir = argv[i];
+ dir = xstrdup(argv[i]);
if (!enter_repo(dir, strict))
die("'%s' does not appear to be a git repository", dir);
@@ -693,5 +693,6 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
if (getenv("GIT_DEBUG_SEND_PACK"))
debug_fd = atoi(getenv("GIT_DEBUG_SEND_PACK"));
upload_pack();
+ free(dir);
return 0;
}
--
1.7.1
From ff2fe4d6017587d73e2a0c5541d8db1dd2963269 Mon Sep 17 00:00:00 2001
From: I <wont@tell.com>
Date: Mon, 15 Nov 2010 11:20:53 +0100
Subject: [PATCH 7/9] daemon and imap-send as builtins
---
Makefile | 4 ++--
daemon.c => builtin-daemon.c | 0
imap-send.c => builtin-imap-send.c | 0
builtin.h | 2 ++
git.c | 2 ++
5 files changed, 6 insertions(+), 2 deletions(-)
rename daemon.c => builtin-daemon.c (100%)
rename imap-send.c => builtin-imap-send.c (100%)
diff --git a/Makefile b/Makefile
index 5ee1054..545042d 100644
--- a/Makefile
+++ b/Makefile
@@ -1078,8 +1078,8 @@ endif
EXTLIBS += -lz
ifndef NO_POSIX_ONLY_PROGRAMS
- PROGRAMS += git-daemon$X
- PROGRAMS += git-imap-send$X
+ BUILTIN_OBJS += builtin-git-daemon.o
+ BUILTIN_OBJS += builtin-imap-send.o
endif
ifndef NO_OPENSSL
OPENSSL_LIBSSL = -lssl
diff --git a/daemon.c b/builtin-daemon.c
similarity index 100%
rename from daemon.c
rename to builtin-daemon.c
diff --git a/imap-send.c b/builtin-imap-send.c
similarity index 100%
rename from imap-send.c
rename to builtin-imap-send.c
diff --git a/builtin.h b/builtin.h
index 9ba53b0..b6299da 100644
--- a/builtin.h
+++ b/builtin.h
@@ -126,5 +126,7 @@ extern int cmd_show_index(int argc, const char **argv, const char *prefix);
extern int cmd_unpack_file(int argc, const char **argv, const char *prefix);
extern int cmd_upload_pack(int argc, const char **argv, const char *prefix);
extern int cmd_var(int argc, const char **argv, const char *prefix);
+extern int cmd_daemon(int argc, const char **argv, const char *prefix);
+extern int cmd_imap_send(int argc, const char **argv, const char *prefix);
#endif
diff --git a/git.c b/git.c
index abf0ee0..7605199 100644
--- a/git.c
+++ b/git.c
@@ -381,6 +381,8 @@ static void handle_internal_command(int argc, const char **argv)
{ "unpack-file", cmd_unpack_file },
{ "upload-pack", cmd_upload_pack },
{ "var", cmd_var },
+ { "daemon", cmd_daemon },
+ { "imap-send", cmd_imap_send },
};
int i;
static const char ext[] = STRIP_EXTENSION;
--
1.7.1
From 42ee94b41f5c103cd4c7d04862fbd569cab21266 Mon Sep 17 00:00:00 2001
From: I <wont@tell.com>
Date: Mon, 15 Nov 2010 11:28:19 +0100
Subject: [PATCH 8/9] compile warnings
---
Makefile | 6 +-----
builtin-daemon.c | 12 ++++++------
builtin-imap-send.c | 2 +-
3 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/Makefile b/Makefile
index 545042d..0d07814 100644
--- a/Makefile
+++ b/Makefile
@@ -1078,7 +1078,7 @@ endif
EXTLIBS += -lz
ifndef NO_POSIX_ONLY_PROGRAMS
- BUILTIN_OBJS += builtin-git-daemon.o
+ BUILTIN_OBJS += builtin-daemon.o
BUILTIN_OBJS += builtin-imap-send.o
endif
ifndef NO_OPENSSL
@@ -1552,10 +1552,6 @@ endif
git-%$X: %.o $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
-git-imap-send$X: imap-send.o $(GITLIBS)
- $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
- $(LIBS) $(OPENSSL_LINK) $(OPENSSL_LIBSSL)
-
http.o http-walker.o http-push.o: http.h
http.o http-walker.o: $(LIB_H)
diff --git a/builtin-daemon.c b/builtin-daemon.c
index 1b5ada6..350eeec 100644
--- a/builtin-daemon.c
+++ b/builtin-daemon.c
@@ -31,15 +31,15 @@ static const char daemon_usage[] =
" [directory...]";
/* List of acceptable pathname prefixes */
-static char **ok_paths;
+static const char **ok_paths;
static int strict_paths;
/* If this is set, git-daemon-export-ok is not required */
static int export_all_trees;
/* Take all paths relative to this one if non-NULL */
-static char *base_path;
-static char *interpolated_path;
+static const char *base_path;
+static const char *interpolated_path;
static int base_path_relaxed;
/* Flag indicating client sent extra args. */
@@ -236,7 +236,7 @@ static char *path_ok(char *directory)
}
if ( ok_paths && *ok_paths ) {
- char **pp;
+ const char **pp;
int pathlen = strlen(path);
/* The validation is done on the paths after enter_repo
@@ -967,7 +967,7 @@ static int serve(char *listen_addr, int listen_port, struct passwd *pass, gid_t
return service_loop(socknum, socklist);
}
-int main(int argc, char **argv)
+int cmd_daemon(int argc, const char **argv, const char *prefix)
{
int listen_port = 0;
char *listen_addr = NULL;
@@ -982,7 +982,7 @@ int main(int argc, char **argv)
git_extract_argv0_path(argv[0]);
for (i = 1; i < argc; i++) {
- char *arg = argv[i];
+ const char *arg = argv[i];
if (!prefixcmp(arg, "--listen=")) {
listen_addr = xstrdup_tolower(arg + 9);
diff --git a/builtin-imap-send.c b/builtin-imap-send.c
index f805c6e..b93cbc2 100644
--- a/builtin-imap-send.c
+++ b/builtin-imap-send.c
@@ -1483,7 +1483,7 @@ static int git_imap_config(const char *key, const char *val, void *cb)
return 0;
}
-int main(int argc, char **argv)
+int cmd_imap_send(int argc, const char **argv, const char *prefix)
{
struct msg_data all_msgs, msg;
struct store *ctx = NULL;
--
1.7.1
From df1e0bff8149c0e66ca80cc370a7b32d4c2d60ed Mon Sep 17 00:00:00 2001
From: I <wont@tell.com>
Date: Mon, 15 Nov 2010 11:40:04 +0100
Subject: [PATCH 9/9] create symlinks instead of cp/hardlinks
---
Makefile | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index 0d07814..e49f37f 100644
--- a/Makefile
+++ b/Makefile
@@ -1724,7 +1724,11 @@ install: all
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
- $(INSTALL) git$X git-upload-pack$X git-receive-pack$X git-upload-archive$X git-shell$X git-cvsserver '$(DESTDIR_SQ)$(bindir_SQ)'
+ $(INSTALL) git git-cvsserver '$(DESTDIR_SQ)$(bindir_SQ)'
+ ln -s git $(DESTDIR_SQ)$(bindir_SQ)/git-upload-pack 2>/dev/null
+ ln -s git $(DESTDIR_SQ)$(bindir_SQ)/git-receive-pack 2>/dev/null
+ ln -s git $(DESTDIR_SQ)$(bindir_SQ)/git-upload-archive 2>/dev/null
+ ln -s git $(DESTDIR_SQ)$(bindir_SQ)/git-shell 2>/dev/null
$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
ifndef NO_PERL
$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
@@ -1741,11 +1745,10 @@ endif
{ test "$$bindir/" = "$$execdir/" || \
{ $(RM) "$$execdir/git$X" && \
test -z "$(NO_CROSS_DIRECTORY_HARDLINKS)" && \
- ln "$$bindir/git$X" "$$execdir/git$X" 2>/dev/null || \
+ ln -s ../../bin/git "$$execdir/git$X" 2>/dev/null || \
cp "$$bindir/git$X" "$$execdir/git$X"; } ; } && \
{ for p in $(BUILT_INS); do \
$(RM) "$$execdir/$$p" && \
- ln "$$execdir/git$X" "$$execdir/$$p" 2>/dev/null || \
ln -s "git$X" "$$execdir/$$p" 2>/dev/null || \
cp "$$execdir/git$X" "$$execdir/$$p" || exit; \
done; } && \
--
1.7.1