From: Andreas Ericsson <ae@op5.se>
To: git@vger.kernel.org
Subject: Re: git binary directory?
Date: Wed, 09 Nov 2005 14:32:36 +0100 [thread overview]
Message-ID: <4371FA74.5070504@op5.se> (raw)
In-Reply-To: <20051107004346.GR1431@pasky.or.cz>
[-- Attachment #1: Type: text/plain, Size: 854 bytes --]
Petr Baudis wrote:
>
> I want to avoid extra fork()s and exec()s. They seem to routinely matter
> in orders of magnitude of speed in tight loops.
>
Give this a whirl. It's still slower than using the git-<something>
form, but it's quite an improvement anyways.
#############
$ time for i in `seq 1 10000`; do git send-pack --help >/dev/null 2>&1; done
real 0m28.921s
user 0m12.626s
sys 0m14.219s
$ time for i in `seq 1 10000`; do ./git send-pack --help >/dev/null
2>&1; done
real 0m12.129s
user 0m4.444s
sys 0m7.615s
$ time for i in `seq 1 10000`; do git-send-pack --help >/dev/null 2>&1; done
real 0m9.069s
user 0m3.481s
sys 0m5.558s
##############
--
Andreas Ericsson andreas.ericsson@op5.se
OP5 AB www.op5.se
Tel: +46 8-230225 Fax: +46 8-230231
[-- Attachment #2: git.c --]
[-- Type: text/x-csrc, Size: 3703 bytes --]
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <glob.h>
#ifndef PATH_MAX
# define PATH_MAX 4096
#endif
static const char git_usage[] =
"Usage: git [ --version ] [ --lib=<GIT_LIB> ] COMMAND [ OPTIONS ] [ TARGET ]";
struct string_list {
size_t len;
char *str;
struct string_list *next;
};
/* most gui terms set COLUMNS (although some don't export it) */
static int columns(void)
{
char *col_string = getenv("COLUMNS");
int n_cols = 0;
if (col_string && (n_cols = atoi(col_string)) > 0)
return n_cols;
return 80;
}
static inline void mput_char(char c, unsigned int num)
{
unsigned int i;
for(i = 0; i < num; i++)
putchar(c);
}
static void fmt_print_string_list(struct string_list *list, int longest)
{
int cols;
int space = longest + 1; /* space between start of string1 and string2 */
int max_cols = columns() - 1;
cols = max_cols / space;
if(cols < 1) {
cols = 1;
space = 0;
}
while (list) {
int c = cols;
printf(" ");
for(c = cols; c; c--) {
if (!list)
break;
printf("%s", list->str);
if (space && c != 1)
mput_char(' ', space - list->len);
list = list->next;
}
putchar('\n');
}
}
static void usage(char *path, const char *fmt, ...)
__attribute__((__format__(__printf__, 2, 3)));
static void usage(char *path, const char *fmt, ...)
{
struct string_list *list, *tail;
unsigned int longest = 0, i;
glob_t gl;
list = tail = NULL;
if (!fmt)
puts(git_usage);
else {
printf("git: ");
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
}
putchar('\n');
if (!path)
exit(1);
if (chdir(path) < 0) {
printf("git: '%s': %s\n", path, strerror(errno));
exit(1);
}
printf("\ngit commands available in '%s'\n", path);
printf("----------------------------");
mput_char('-', strlen(path));
putchar('\n');
glob("git-*", 0, NULL, &gl);
for (i = 0; i < gl.gl_pathc; i++) {
int len = strlen(gl.gl_pathv[i] + 4);
if(access(gl.gl_pathv[i], X_OK))
continue;
if (longest < len)
longest = len;
if (!tail)
tail = list = malloc(sizeof(struct string_list));
else {
tail->next = malloc(sizeof(struct string_list));
tail = tail->next;
}
tail->len = len;
tail->str = gl.gl_pathv[i] + 4;
tail->next = NULL;
}
fmt_print_string_list(list, longest);
puts("\nman-pages can be reached through 'man git-<COMMAND>'\n");
exit(1);
}
#define DEFAULT_GIT_LIB "/usr/bin"
#define GIT_VERSION "0.99.9.GIT"
int main(int argc, char **argv, char **envp)
{
char git_command[PATH_MAX + 1];
char *git_lib = getenv("GIT_LIB");
char wd[PATH_MAX + 1], libdir[PATH_MAX + 1];
getcwd(wd, PATH_MAX);
if(argc == 1) {
if (git_lib)
usage(git_lib, NULL);
usage(DEFAULT_GIT_LIB, NULL);
}
argv++;
/* always *argv since we inc it if we hit an option */
while (argc-- && !strncmp(*argv, "--", 2)) {
char *arg = (*argv++) + 2;
if (!strncmp(arg, "lib=", 3))
git_lib = arg + 4;
else if (!strncmp(arg, "version", 7)) {
printf("git version %s\n", GIT_VERSION);
exit(0);
}
else
usage (NULL, NULL);
}
if (!git_lib)
git_lib = DEFAULT_GIT_LIB;
/* allow relative paths, but run with exact */
if (chdir(git_lib)) {
printf("git: '%s': %s\n", git_lib, strerror(errno));
exit (1);
}
getcwd(libdir, sizeof(libdir));
chdir(wd);
snprintf(git_command, sizeof(git_command), "%s/git-%s", libdir, *argv);
if (access(git_command, X_OK))
usage(git_lib, "'%s' is not a git-command", *argv);
if (execve(git_command, argv, envp)) {
printf("Failed to run command '%s': %s\n", git_command, strerror(errno));
return 1;
}
/* not reached */
return 0;
}
next prev parent reply other threads:[~2005-11-09 13:33 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-05 21:02 git binary directory? Linus Torvalds
2005-11-05 23:52 ` Linus Torvalds
2005-11-06 0:27 ` Linus Torvalds
2005-11-06 7:25 ` Junio C Hamano
2005-11-06 2:49 ` Junio C Hamano
2005-11-06 3:12 ` Horst von Brand
2005-11-06 5:00 ` Kay Sievers
2005-11-06 5:36 ` Junio C Hamano
2005-11-06 8:23 ` Petr Baudis
2005-11-06 8:33 ` Junio C Hamano
2005-11-06 8:28 ` Petr Baudis
2005-11-06 4:25 ` Linus Torvalds
2005-11-06 5:37 ` Junio C Hamano
2005-11-06 16:20 ` Linus Torvalds
2005-11-06 20:15 ` Junio C Hamano
2005-11-06 22:19 ` Petr Baudis
2005-11-07 0:08 ` Junio C Hamano
2005-11-07 0:43 ` Petr Baudis
2005-11-07 0:54 ` Linus Torvalds
2005-11-07 9:45 ` Petr Baudis
2005-11-07 17:27 ` Junio C Hamano
2005-11-10 9:49 ` Petr Baudis
2005-11-09 13:32 ` Andreas Ericsson [this message]
[not found] <436D2269.6090605@slamail.org>
2005-11-05 21:43 ` Yaacov Akiba Slama
2005-11-06 8:56 ` Ben Clifford
2005-11-06 13:13 ` Nikolai Weibull
2005-11-06 14:05 ` Johannes Schindelin
2005-11-06 15:03 ` Nikolai Weibull
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=4371FA74.5070504@op5.se \
--to=ae@op5.se \
--cc=git@vger.kernel.org \
/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).