From: Stephan Beyer <s-beyer@gmx.net>
To: Dmitry Potapov <dpotapov@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] shrink git-shell by avoiding redundant dependencies
Date: Fri, 18 Jul 2008 02:26:20 +0200 [thread overview]
Message-ID: <20080718002620.GE8421@leksak.fem-net> (raw)
In-Reply-To: <20080627223107.GH5737@dpotapov.dyndns.org>
Hi,
Dmitry Potapov wrote:
> diff --git a/shell.c b/shell.c
> index b27d01c..91ca7de 100644
> --- a/shell.c
> +++ b/shell.c
> @@ -3,6 +3,14 @@
> #include "exec_cmd.h"
> #include "strbuf.h"
>
> +/* Stubs for functions that make no sense for git-shell. These stubs
> + * are provided here to avoid linking in external redundant modules.
> + */
> +void release_pack_memory(size_t need, int fd){}
> +void trace_argv_printf(const char **argv, const char *fmt, ...){}
> +void trace_printf(const char *fmt, ...){}
> +
> +
I don't really understand why this works.
You redefine libgit.a functions here
So the linker should complain like that:
libgit.a(sha1_file.o): In function `release_pack_memory':
/home/sbeyer/src/git/sha1_file.c:624: multiple definition of `release_pack_memory'
shell.o:/home/sbeyer/src/git/shell.c:9: first defined here
collect2: ld returned 1 exit status
And, in fact, it does when I move a function from a builtin to a lib
source file, for example launch_editor() from builtin-tag.c to strbuf.c,
like the following one:
---
builtin-tag.c | 53 -----------------------------------------------------
strbuf.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+), 53 deletions(-)
diff --git a/builtin-tag.c b/builtin-tag.c
index c2cca6c..219f51d 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -23,59 +23,6 @@ static const char * const git_tag_usage[] = {
static char signingkey[1000];
-void launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
-{
- const char *editor, *terminal;
-
- editor = getenv("GIT_EDITOR");
- if (!editor && editor_program)
- editor = editor_program;
- if (!editor)
- editor = getenv("VISUAL");
- if (!editor)
- editor = getenv("EDITOR");
-
- terminal = getenv("TERM");
- if (!editor && (!terminal || !strcmp(terminal, "dumb"))) {
- fprintf(stderr,
- "Terminal is dumb but no VISUAL nor EDITOR defined.\n"
- "Please supply the message using either -m or -F option.\n");
- exit(1);
- }
-
- if (!editor)
- editor = "vi";
-
- if (strcmp(editor, ":")) {
- size_t len = strlen(editor);
- int i = 0;
- const char *args[6];
- struct strbuf arg0;
-
- strbuf_init(&arg0, 0);
- if (strcspn(editor, "$ \t'") != len) {
- /* there are specials */
- strbuf_addf(&arg0, "%s \"$@\"", editor);
- args[i++] = "sh";
- args[i++] = "-c";
- args[i++] = arg0.buf;
- }
- args[i++] = editor;
- args[i++] = path;
- args[i] = NULL;
-
- if (run_command_v_opt_cd_env(args, 0, NULL, env))
- die("There was a problem with the editor %s.", editor);
- strbuf_release(&arg0);
- }
-
- if (!buffer)
- return;
- if (strbuf_read_file(buffer, path, 0) < 0)
- die("could not read message file '%s': %s",
- path, strerror(errno));
-}
-
struct tag_filter {
const char *pattern;
int lines;
diff --git a/strbuf.c b/strbuf.c
index 720737d..6419e02 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "run-command.h"
int prefixcmp(const char *str, const char *prefix)
{
@@ -308,3 +309,56 @@ int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
return len;
}
+
+void launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
+{
+ const char *editor, *terminal;
+
+ editor = getenv("GIT_EDITOR");
+ if (!editor && editor_program)
+ editor = editor_program;
+ if (!editor)
+ editor = getenv("VISUAL");
+ if (!editor)
+ editor = getenv("EDITOR");
+
+ terminal = getenv("TERM");
+ if (!editor && (!terminal || !strcmp(terminal, "dumb"))) {
+ fprintf(stderr,
+ "Terminal is dumb but no VISUAL nor EDITOR defined.\n"
+ "Please supply the message using either -m or -F option.\n");
+ exit(1);
+ }
+
+ if (!editor)
+ editor = "vi";
+
+ if (strcmp(editor, ":")) {
+ size_t len = strlen(editor);
+ int i = 0;
+ const char *args[6];
+ struct strbuf arg0;
+
+ strbuf_init(&arg0, 0);
+ if (strcspn(editor, "$ \t'") != len) {
+ /* there are specials */
+ strbuf_addf(&arg0, "%s \"$@\"", editor);
+ args[i++] = "sh";
+ args[i++] = "-c";
+ args[i++] = arg0.buf;
+ }
+ args[i++] = editor;
+ args[i++] = path;
+ args[i] = NULL;
+
+ if (run_command_v_opt_cd_env(args, 0, NULL, env))
+ die("There was a problem with the editor %s.", editor);
+ strbuf_release(&arg0);
+ }
+
+ if (!buffer)
+ return;
+ if (strbuf_read_file(buffer, path, 0) < 0)
+ die("could not read message file '%s': %s",
+ path, strerror(errno));
+}
--
Stephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F
next prev parent reply other threads:[~2008-07-18 0:27 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-27 21:35 [PATCH] shrink git-shell by avoiding redundant dependencies Dmitry Potapov
2008-06-27 21:55 ` Junio C Hamano
2008-06-27 22:31 ` Dmitry Potapov
2008-06-27 22:34 ` Junio C Hamano
2008-07-18 0:26 ` Stephan Beyer [this message]
2008-07-18 0:58 ` Shawn O. Pearce
2008-07-18 1:04 ` [PATCH] Link git-shell only to a subset of libgit.a Stephan Beyer
2008-07-18 1:06 ` Shawn O. Pearce
2008-07-18 6:03 ` Dmitry Potapov
2008-07-18 10:55 ` Johannes Schindelin
2008-07-18 1:06 ` [PATCH] Remove function stubs in shell.c Stephan Beyer
2008-07-18 6:06 ` Dmitry Potapov
2008-07-18 5:59 ` [PATCH] shrink git-shell by avoiding redundant dependencies Dmitry Potapov
2008-06-28 14:51 ` Johannes Schindelin
2008-06-28 16:48 ` Dmitry Potapov
2008-06-28 17:31 ` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080718002620.GE8421@leksak.fem-net \
--to=s-beyer@gmx.net \
--cc=dpotapov@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).