Git development
 help / color / mirror / Atom feed
* [PATCH 0] A few improvements to Emacs interface to Git
From: Jakub Narebski @ 2006-07-13 20:15 UTC (permalink / raw)
  To: git

This series of patches introduces a few minor improvements to
Emacs interface to Git.

-- 
Jakub Narebski

^ permalink raw reply

* As long as you're hacking on git-daemon...
From: linux @ 2006-07-13 20:12 UTC (permalink / raw)
  To: matled; +Cc: git

Is it possible to make it capable of running from /etc/inetd.conf?
That's nicer for little-used personal servers, and also nicer if you
want to use tcp wrappers or one of the inetd replacements that
offers sophisticated load control.  (Refuse connections if
load average is too high, different nice level for internal vs.
external clients, etc. etc.)

Thanks.

^ permalink raw reply

* Re: [PATCH] format-patch: Generate a newline between the subject header and the message body.
From: Robert Shearman @ 2006-07-13 20:03 UTC (permalink / raw)
  To: git
In-Reply-To: <e967en$bi6$1@sea.gmane.org>

Jakub Narebski wrote:

>Robert Shearman wrote:
>  
>
>>format-patch previously didn't generate a newline after a subject. This 
>>caused the diffstat to not be displayed in messages without a blank line 
>>and the first blank line to be eaten in messages with a blank line.
>>    
>>
>
>Does this _enforce_ separating commit message into subject+empty
>line+description? What about commit messages without this structire (e.g.
>legacy commit messages from import from other SCM, e.g. GNU ChangeLog
>style)?
>

It only affects commits exported into email style. It has nothing to do
with the structure of GIT commit messages or those of any other SCM.

-- 
Rob Shearman

^ permalink raw reply

* Re: [PATCH] format-patch: Generate a newline between the subject header and the message body.
From: Jakub Narebski @ 2006-07-13 19:38 UTC (permalink / raw)
  To: git
In-Reply-To: <44B6369D.6070602@codeweavers.com>

Robert Shearman wrote:

> 
> format-patch previously didn't generate a newline after a subject. This 
> caused the diffstat to not be displayed in messages without a blank line 
> and the first blank line to be eaten in messages with a blank line.

Does this _enforce_ separating commit message into subject+empty
line+description? What about commit messages without this structire (e.g.
legacy commit messages from import from other SCM, e.g. GNU ChangeLog
style)?

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git

^ permalink raw reply

* Re: [PATCH 5.1/5] daemon: new option --detach to run git-daemon in background
From: Matthias Lederhofer @ 2006-07-13 16:47 UTC (permalink / raw)
  To: Edgar Toernig; +Cc: git
In-Reply-To: <20060713153703.05f862ee.froese@gmx.de>

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
Edgar Toernig <froese@gmx.de> wrote:
> Hmm... leaks devnull.  Why not simply close(0/1/2) and
> let sanitize_stdfds take care of the rest?
---
 daemon.c |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/daemon.c b/daemon.c
index cdc4266..e4ec676 100644
--- a/daemon.c
+++ b/daemon.c
@@ -674,6 +674,24 @@ static void sanitize_stdfds(void)
 		close(fd);
 }
 
+static void daemonize(void)
+{
+	switch (fork()) {
+		case 0:
+			break;
+		case -1:
+			die("fork failed: %s", strerror(errno));
+		default:
+			exit(0);
+	}
+	if (setsid() == -1)
+		die("setsid failed: %s", strerror(errno));
+	close(0);
+	close(1);
+	close(2);
+	sanitize_stdfds();
+}
+
 static void store_pid(const char *path)
 {
 	FILE *f = fopen(path, "w");
@@ -699,6 +717,7 @@ int main(int argc, char **argv)
 	int port = DEFAULT_GIT_PORT;
 	int inetd_mode = 0;
 	const char *pid_file = NULL;
+	int detach = 0;
 	int i;
 
 	/* Without this we cannot rely on waitpid() to tell
@@ -767,6 +786,11 @@ int main(int argc, char **argv)
 			pid_file = arg + 11;
 			continue;
 		}
+		if (!strcmp(arg, "--detach")) {
+			detach = 1;
+			log_syslog = 1;
+			continue;
+		}
 		if (!strcmp(arg, "--")) {
 			ok_paths = &argv[i+1];
 			break;
@@ -799,7 +823,10 @@ int main(int argc, char **argv)
 		return execute(peer);
 	}
 
-	sanitize_stdfds();
+	if (detach)
+		daemonize();
+	else
+		sanitize_stdfds();
 
 	if (pid_file)
 		store_pid(pid_file);
-- 
1.4.1.g8b4b

^ permalink raw reply related

* [PATCH 2.1/5] daemon: if one of the standard fds is missing open it to /dev/null
From: Matthias Lederhofer @ 2006-07-13 16:32 UTC (permalink / raw)
  To: git
In-Reply-To: <E1G0znB-0002IO-61@moooo.ath.cx>

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
fixed sanitize_stdfds
---
 daemon.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/daemon.c b/daemon.c
index a7636bc..01ccda3 100644
--- a/daemon.c
+++ b/daemon.c
@@ -662,6 +662,18 @@ static int service_loop(int socknum, int
 	}
 }
 
+/* if any standard file descriptor is missing open it to /dev/null */
+static void sanitize_stdfds(void)
+{
+	int fd = open("/dev/null", O_RDWR, 0);
+	while (fd != -1 && fd < 2)
+		fd = dup(fd);
+	if (fd == -1)
+		die("open /dev/null or dup failed: %s", strerror(errno));
+	if (fd > 2)
+		close(fd);
+}
+
 static int serve(int port)
 {
 	int socknum, *socklist;
@@ -773,5 +785,7 @@ int main(int argc, char **argv)
 		return execute(peer);
 	}
 
+	sanitize_stdfds();
+
 	return serve(port);
 }
-- 
1.4.1.g8b4b

^ permalink raw reply related

* [PATCH] diff: Support both attributes and colors
From: Timo Hirvonen @ 2006-07-13 16:06 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Make it possible to set both colors and a attribute for diff colors.
Background colors are supported too.

Syntax is now:

	[attr] [fg [bg]]
	[fg [bg]] [attr]

Empty value is same as "normal normal", ie use default colors.  The new
syntax is backwards compatible.

Signed-off-by: Timo Hirvonen <tihirvon@gmail.com>
---
 diff.c |  164 ++++++++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 107 insertions(+), 57 deletions(-)

diff --git a/diff.c b/diff.c
index a007019..a9118a9 100644
--- a/diff.c
+++ b/diff.c
@@ -26,30 +26,14 @@ enum color_diff {
 	DIFF_FILE_NEW = 5,
 };
 
-#define COLOR_NORMAL  ""
-#define COLOR_BOLD    "\033[1m"
-#define COLOR_DIM     "\033[2m"
-#define COLOR_UL      "\033[4m"
-#define COLOR_BLINK   "\033[5m"
-#define COLOR_REVERSE "\033[7m"
-#define COLOR_RESET   "\033[m"
-
-#define COLOR_BLACK   "\033[30m"
-#define COLOR_RED     "\033[31m"
-#define COLOR_GREEN   "\033[32m"
-#define COLOR_YELLOW  "\033[33m"
-#define COLOR_BLUE    "\033[34m"
-#define COLOR_MAGENTA "\033[35m"
-#define COLOR_CYAN    "\033[36m"
-#define COLOR_WHITE   "\033[37m"
-
-static const char *diff_colors[] = {
-	COLOR_RESET,
-	COLOR_NORMAL,
-	COLOR_BOLD,
-	COLOR_CYAN,
-	COLOR_RED,
-	COLOR_GREEN
+/* "\033[1;30;47m\0" is 11 bytes */
+static char diff_colors[][16] = {
+	"\033[m",	/* reset */
+	"",		/* normal */
+	"\033[1m",	/* bold */
+	"\033[36m",	/* cyan */
+	"\033[31m",	/* red */
+	"\033[32m"	/* green */
 };
 
 static int parse_diff_color_slot(const char *var, int ofs)
@@ -67,38 +51,104 @@ static int parse_diff_color_slot(const c
 	die("bad config variable '%s'", var);
 }
 
-static const char *parse_diff_color_value(const char *value, const char *var)
-{
-	if (!strcasecmp(value, "normal"))
-		return COLOR_NORMAL;
-	if (!strcasecmp(value, "bold"))
-		return COLOR_BOLD;
-	if (!strcasecmp(value, "dim"))
-		return COLOR_DIM;
-	if (!strcasecmp(value, "ul"))
-		return COLOR_UL;
-	if (!strcasecmp(value, "blink"))
-		return COLOR_BLINK;
-	if (!strcasecmp(value, "reverse"))
-		return COLOR_REVERSE;
-	if (!strcasecmp(value, "reset"))
-		return COLOR_RESET;
-	if (!strcasecmp(value, "black"))
-		return COLOR_BLACK;
-	if (!strcasecmp(value, "red"))
-		return COLOR_RED;
-	if (!strcasecmp(value, "green"))
-		return COLOR_GREEN;
-	if (!strcasecmp(value, "yellow"))
-		return COLOR_YELLOW;
-	if (!strcasecmp(value, "blue"))
-		return COLOR_BLUE;
-	if (!strcasecmp(value, "magenta"))
-		return COLOR_MAGENTA;
-	if (!strcasecmp(value, "cyan"))
-		return COLOR_CYAN;
-	if (!strcasecmp(value, "white"))
-		return COLOR_WHITE;
+static int parse_color(const char *name, int len)
+{
+	static const char * const color_names[] = {
+		"normal", "black", "red", "green", "yellow",
+		"blue", "magenta", "cyan", "white"
+	};
+	int i;
+	for (i = 0; i < ARRAY_SIZE(color_names); i++) {
+		const char *str = color_names[i];
+		if (!strncasecmp(name, str, len) && !str[len])
+			return i - 1;
+	}
+	return -2;
+}
+
+static int parse_attr(const char *name, int len)
+{
+	static const int attr_values[] = { 1, 2, 4, 5, 7 };
+	static const char * const attr_names[] = {
+		"bold", "dim", "ul", "blink", "reverse"
+	};
+	int i;
+	for (i = 0; i < ARRAY_SIZE(attr_names); i++) {
+		const char *str = attr_names[i];
+		if (!strncasecmp(name, str, len) && !str[len])
+			return attr_values[i];
+	}
+	return -1;
+}
+
+static void parse_diff_color_value(const char *value, const char *var, char *dst)
+{
+	const char *ptr = value;
+	int attr = -1;
+	int fg = -2;
+	int bg = -2;
+
+	if (!strcasecmp(value, "reset")) {
+		strcpy(dst, "\033[m");
+		return;
+	}
+
+	/* [fg [bg]] [attr] */
+	while (*ptr) {
+		const char *word = ptr;
+		int val, len = 0;
+
+		while (word[len] && !isspace(word[len]))
+			len++;
+
+		ptr = word + len;
+		while (*ptr && isspace(*ptr))
+			ptr++;
+
+		val = parse_color(word, len);
+		if (val >= -1) {
+			if (fg == -2) {
+				fg = val;
+				continue;
+			}
+			if (bg == -2) {
+				bg = val;
+				continue;
+			}
+			goto bad;
+		}
+		val = parse_attr(word, len);
+		if (val < 0 || attr != -1)
+			goto bad;
+		attr = val;
+	}
+
+	if (attr >= 0 || fg >= 0 || bg >= 0) {
+		int sep = 0;
+
+		*dst++ = '\033';
+		*dst++ = '[';
+		if (attr >= 0) {
+			*dst++ = '0' + attr;
+			sep++;
+		}
+		if (fg >= 0) {
+			if (sep++)
+				*dst++ = ';';
+			*dst++ = '3';
+			*dst++ = '0' + fg;
+		}
+		if (bg >= 0) {
+			if (sep++)
+				*dst++ = ';';
+			*dst++ = '4';
+			*dst++ = '0' + bg;
+		}
+		*dst++ = 'm';
+	}
+	*dst = 0;
+	return;
+bad:
 	die("bad config value '%s' for variable '%s'", value, var);
 }
 
@@ -145,7 +195,7 @@ int git_diff_ui_config(const char *var, 
 	}
 	if (!strncmp(var, "diff.color.", 11)) {
 		int slot = parse_diff_color_slot(var, 11);
-		diff_colors[slot] = parse_diff_color_value(value, var);
+		parse_diff_color_value(value, var, diff_colors[slot]);
 		return 0;
 	}
 	return git_default_config(var, value);
-- 
1.4.1.gd0c9d-dirty

^ permalink raw reply related

* [PATCH] diff: Support 256 colors
From: Timo Hirvonen @ 2006-07-13 16:08 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Add support for more than 8 colors.  Colors can be specified as numbers
-1..255.  -1 is same as "normal".

Signed-off-by: Timo Hirvonen <tihirvon@gmail.com>
---
 diff.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/diff.c b/diff.c
index a9118a9..351cd07 100644
--- a/diff.c
+++ b/diff.c
@@ -26,8 +26,8 @@ enum color_diff {
 	DIFF_FILE_NEW = 5,
 };
 
-/* "\033[1;30;47m\0" is 11 bytes */
-static char diff_colors[][16] = {
+/* "\033[1;38;5;2xx;48;5;2xxm\0" is 23 bytes */
+static char diff_colors[][24] = {
 	"\033[m",	/* reset */
 	"",		/* normal */
 	"\033[1m",	/* bold */
@@ -57,12 +57,16 @@ static int parse_color(const char *name,
 		"normal", "black", "red", "green", "yellow",
 		"blue", "magenta", "cyan", "white"
 	};
+	char *end;
 	int i;
 	for (i = 0; i < ARRAY_SIZE(color_names); i++) {
 		const char *str = color_names[i];
 		if (!strncasecmp(name, str, len) && !str[len])
 			return i - 1;
 	}
+	i = strtol(name, &end, 10);
+	if (*name && !*end && i >= -1 && i <= 255)
+		return i;
 	return -2;
 }
 
@@ -135,14 +139,22 @@ static void parse_diff_color_value(const
 		if (fg >= 0) {
 			if (sep++)
 				*dst++ = ';';
-			*dst++ = '3';
-			*dst++ = '0' + fg;
+			if (fg < 8) {
+				*dst++ = '3';
+				*dst++ = '0' + fg;
+			} else {
+				dst += sprintf(dst, "38;5;%d", fg);
+			}
 		}
 		if (bg >= 0) {
 			if (sep++)
 				*dst++ = ';';
-			*dst++ = '4';
-			*dst++ = '0' + bg;
+			if (bg < 8) {
+				*dst++ = '4';
+				*dst++ = '0' + bg;
+			} else {
+				dst += sprintf(dst, "48;5;%d", bg);
+			}
 		}
 		*dst++ = 'm';
 	}
-- 
1.4.1.gd0c9d-dirty

^ permalink raw reply related

* Re: [PATCH 2/5] daemon: if one of the standard fds is missing open it to /dev/null
From: Matthias Lederhofer @ 2006-07-13 16:03 UTC (permalink / raw)
  To: Morten Welinder; +Cc: git
In-Reply-To: <118833cc0607130837u30c58d53lc785f56d45ef970c@mail.gmail.com>

Morten Welinder <mwelinder@gmail.com> wrote:
> >+               if (devnull == -1 &&
> >+                       (devnull = open("/dev/null", O_RDWR, 0)) == -1)
> >+                       die("open /dev/null failed: %s", strerror(errno));
> >+               if (dup2(devnull, i) != i)
> >+                       die("dup2 failed: %s", strerror(errno));
> 
> "die" probably won't work well at this point.
At least with --syslog there will be an error message in the logs.
If the user does not use --syslog and closes fd 2 it is just his own
fault imho.

> Should git (and most other programs) do something like this in general?
> fprintf will happily write to fd=2 regardless of whether that is some critical
> file you opened.
I thought of that too.  It might be not that important because I
cannot think of anyway that this could happen accidentally or could be
exploited.

^ permalink raw reply

* Re: [PATCH 2/5] daemon: if one of the standard fds is missing open it to /dev/null
From: Morten Welinder @ 2006-07-13 15:37 UTC (permalink / raw)
  To: Matthias Lederhofer; +Cc: git
In-Reply-To: <E1G0znB-0002IO-61@moooo.ath.cx>

> +               if (devnull == -1 &&
> +                       (devnull = open("/dev/null", O_RDWR, 0)) == -1)
> +                       die("open /dev/null failed: %s", strerror(errno));
> +               if (dup2(devnull, i) != i)
> +                       die("dup2 failed: %s", strerror(errno));

"die" probably won't work well at this point.

Should git (and most other programs) do something like this in general?
fprintf will happily write to fd=2 regardless of whether that is some critical
file you opened.

Morten

^ permalink raw reply

* Re: [PATCH 2/5] daemon: if one of the standard fds is missing open it to /dev/null
From: Uwe Zeisberger @ 2006-07-13 14:36 UTC (permalink / raw)
  To: Edgar Toernig, git, Matthias Lederhofer
In-Reply-To: <E1G11nq-00076g-Aa@moooo.ath.cx>

Hello Matthias,

(Do you know you set the Mail-Followup-To Header?  That is annoying.)

>     devnull = open("/dev/null", O_RDWR, 0);
>     while (devnull != -1 && devnull < 2)
>         dup(devnull);
You mean

	  devnull = dup(devnull);

, don't you?

>     if (devnull == -1)
>         die("..");
>     close(devnull);

Best regards
Uwe

-- 
Uwe Zeisberger

primes where sieve (p:xs) = [ x | x<-xs, x `rem` p /= 0 ]; \
primes = map head (iterate sieve [2..])

^ permalink raw reply

* Re: [PATCH 2/5] daemon: if one of the standard fds is missing open it to /dev/null
From: Matthias Lederhofer @ 2006-07-13 14:04 UTC (permalink / raw)
  To: Edgar Toernig; +Cc: git
In-Reply-To: <20060713152725.7a5081df.froese@gmx.de>

Edgar Toernig <froese@gmx.de> wrote:
> Matthias Lederhofer wrote:
> >
> > +/* if any standard file descriptor is missing open it to /dev/null */
> > +static void sanitize_stdfds(void)
> > +{
> > +	int devnull = -1, i;
> > +	struct stat buf;
> > +	for (i = 0; i < 3; ++i) {
> > +		if (fstat(i, &buf) != -1)
> > +			continue;
> > +		if (devnull == -1 &&
> > +			(devnull = open("/dev/null", O_RDWR, 0)) == -1)
> > +			die("open /dev/null failed: %s", strerror(errno));
> > +		if (dup2(devnull, i) != i)
> > +			die("dup2 failed: %s", strerror(errno));
> > +	}
> > +	if (devnull != -1)
> > +		close(devnull);
> > +}
> 
> This looks broken.  The open will return i as this is
> the lowest free fd.  I don't know what POSIX says
> about dup2(i,i) but anyway, you close it at the end
> which completely defeats the intent of the function.
> 
> How's this?
> 
> 	devnull = open("/dev/null", O_RDWR, 0);
> 	if (devnull == 0)
> 		devnull = dup(devnull);
> 	if (devnull == 1)
> 		devnull = dup(devnull);
> 	if (devnull == -1)
> 		die("open/dup /dev/null failed: %s", strerror(errno));
> 	if (devnull > 2)
> 		close(devnull);

You're right (also for the daemonize function to use sanitize_stdfds).
The code looks good to me, this could also be done using a while-loop
(making it a little bit shorter, I don't know what is easier to read):

    devnull = open("/dev/null", O_RDWR, 0);
    while (devnull != -1 && devnull < 2)
        dup(devnull);
    if (devnull == -1)
        die("..");
    close(devnull);

(This is similar to what Andre Noll posted.)

I'll correct and resend those patches later.

^ permalink raw reply

* Re: [PATCH 5/5] daemon: new option --detach to run git-daemon in background
From: Edgar Toernig @ 2006-07-13 13:37 UTC (permalink / raw)
  To: Matthias Lederhofer; +Cc: git
In-Reply-To: <E1G0znB-0002If-8A@moooo.ath.cx>

Matthias Lederhofer wrote:
>
> [daemonize]
> +	if ((devnull = open("/dev/null", O_RDWR, 0)) == -1)
> +		die("open /dev/null failed: %s", strerror(errno));
> +	if (dup2(devnull, 0) != 0 ||
> +		dup2(devnull, 1) != 1 ||
> +		dup2(devnull, 2) != 2)
> +		die("dup2 failed: %s", strerror(errno));
> +}

Hmm... leaks devnull.  Why not simply close(0/1/2) and
let sanitize_stdfds take care of the rest?

Ciao, ET.

^ permalink raw reply

* Re: [PATCH 2/5] daemon: if one of the standard fds is missing open it to /dev/null
From: Edgar Toernig @ 2006-07-13 13:27 UTC (permalink / raw)
  To: Matthias Lederhofer; +Cc: git
In-Reply-To: <E1G0znB-0002IO-61@moooo.ath.cx>

Matthias Lederhofer wrote:
>
> +/* if any standard file descriptor is missing open it to /dev/null */
> +static void sanitize_stdfds(void)
> +{
> +	int devnull = -1, i;
> +	struct stat buf;
> +	for (i = 0; i < 3; ++i) {
> +		if (fstat(i, &buf) != -1)
> +			continue;
> +		if (devnull == -1 &&
> +			(devnull = open("/dev/null", O_RDWR, 0)) == -1)
> +			die("open /dev/null failed: %s", strerror(errno));
> +		if (dup2(devnull, i) != i)
> +			die("dup2 failed: %s", strerror(errno));
> +	}
> +	if (devnull != -1)
> +		close(devnull);
> +}

This looks broken.  The open will return i as this is
the lowest free fd.  I don't know what POSIX says
about dup2(i,i) but anyway, you close it at the end
which completely defeats the intent of the function.

How's this?

	devnull = open("/dev/null", O_RDWR, 0);
	if (devnull == 0)
		devnull = dup(devnull);
	if (devnull == 1)
		devnull = dup(devnull);
	if (devnull == -1)
		die("open/dup /dev/null failed: %s", strerror(errno));
	if (devnull > 2)
		close(devnull);

Ciao, ET.

^ permalink raw reply

* [PATCH] format-patch: Generate a newline between the subject header and the message body.
From: Robert Shearman @ 2006-07-13 12:03 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 556 bytes --]


format-patch previously didn't generate a newline after a subject. This 
caused the diffstat to not be displayed in messages without a blank line 
and the first blank line to be eaten in messages with a blank line.

This patch inserts a newline in two places - once in the loop to 
separate the subject part of the commit message from the body part of 
the commit message and another after the loop to counteract the eating 
of whitespace at the end of the message.
---
  commit.c |   14 ++++++++++++--
  1 files changed, 12 insertions(+), 2 deletions(-)

[-- Attachment #2: 278bfe08daa6888b9dd7c0e5ca74ad4b3c10e4a4.diff --]
[-- Type: text/x-patch, Size: 1187 bytes --]

diff --git a/commit.c b/commit.c
index 522a6f3..8869b0d 100644
--- a/commit.c
+++ b/commit.c
@@ -655,6 +655,9 @@ unsigned long pretty_print_commit(enum c
 			continue;
 		}
 
+		if (!subject)
+			body = 1;
+
 		if (is_empty_line(line, &linelen)) {
 			if (!body)
 				continue;
@@ -662,8 +665,6 @@ unsigned long pretty_print_commit(enum c
 				continue;
 			if (fmt == CMIT_FMT_SHORT)
 				break;
-		} else {
-			body = 1;
 		}
 
 		if (subject) {
@@ -694,6 +695,9 @@ unsigned long pretty_print_commit(enum c
 			memcpy(buf + offset, after_subject, slen);
 			offset += slen;
 			after_subject = NULL;
+		} else if (fmt == CMIT_FMT_EMAIL && subject) {
+			/* separate the headers from the body */
+			buf[offset++] = '\n';
 		}
 		subject = NULL;
 	}
@@ -702,6 +706,12 @@ unsigned long pretty_print_commit(enum c
 	/* Make sure there is an EOLN for the non-oneline case */
 	if (fmt != CMIT_FMT_ONELINE)
 		buf[offset++] = '\n';
+	/*
+	 * make sure there is another EOLN to separate the headers from whatever
+	 * body the caller appends if we haven't already written a body
+	 */
+	if (fmt == CMIT_FMT_EMAIL && !body)
+		buf[offset++] = '\n';
 	buf[offset] = '\0';
 	return offset;
 }


^ permalink raw reply related

* [PATCH 3/5] upload-pack: ignore write errors to stderr
From: Matthias Lederhofer @ 2006-07-13 11:07 UTC (permalink / raw)
  To: git
In-Reply-To: <E1G0zj7-0001c1-8q@moooo.ath.cx>

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
 upload-pack.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index b18eb9b..94aa0da 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -51,6 +51,10 @@ static ssize_t send_client_data(int fd, 
 		if (fd == 3)
 			/* emergency quit */
 			fd = 2;
+		if (fd == 2) {
+			xwrite(fd, data, sz);
+			return sz;
+		}
 		return safe_write(fd, data, sz);
 	}
 	p = data;
-- 
1.4.1.gb16f

^ permalink raw reply related

* [PATCH 1/5] daemon: use a custom die routine with syslog
From: Matthias Lederhofer @ 2006-07-13 10:02 UTC (permalink / raw)
  To: git
In-Reply-To: <E1G0zj7-0001c1-8q@moooo.ath.cx>

Removed the git-daemon prefix from die() because no other call to die
does this.

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
 daemon.c |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/daemon.c b/daemon.c
index e096bd7..a7636bc 100644
--- a/daemon.c
+++ b/daemon.c
@@ -95,6 +95,12 @@ static void loginfo(const char *err, ...
 	va_end(params);
 }
 
+static void NORETURN daemon_die(const char *err, va_list params)
+{
+	logreport(LOG_ERR, err, params);
+	exit(1);
+}
+
 static int avoid_alias(char *p)
 {
 	int sl, ndot;
@@ -746,17 +752,14 @@ int main(int argc, char **argv)
 		usage(daemon_usage);
 	}
 
-	if (log_syslog)
+	if (log_syslog) {
 		openlog("git-daemon", 0, LOG_DAEMON);
-
-	if (strict_paths && (!ok_paths || !*ok_paths)) {
-		if (!inetd_mode)
-			die("git-daemon: option --strict-paths requires a whitelist");
-
-		logerror("option --strict-paths requires a whitelist");
-		exit (1);
+		set_die_routine(daemon_die);
 	}
 
+	if (strict_paths && (!ok_paths || !*ok_paths))
+		die("option --strict-paths requires a whitelist");
+
 	if (inetd_mode) {
 		struct sockaddr_storage ss;
 		struct sockaddr *peer = (struct sockaddr *)&ss;
-- 
1.4.1.gb16f

^ permalink raw reply related

* [PATCH 5/5] daemon: new option --detach to run git-daemon in background
From: Matthias Lederhofer @ 2006-07-13 10:32 UTC (permalink / raw)
  To: git
In-Reply-To: <E1G0zj7-0001c1-8q@moooo.ath.cx>

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
 daemon.c |   32 +++++++++++++++++++++++++++++++-
 1 files changed, 31 insertions(+), 1 deletions(-)

diff --git a/daemon.c b/daemon.c
index 4b85930..9f4bc20 100644
--- a/daemon.c
+++ b/daemon.c
@@ -662,6 +662,27 @@ static int service_loop(int socknum, int
 	}
 }
 
+static void daemonize(void)
+{
+	int devnull = -1;
+	switch (fork()) {
+		case 0:
+			break;
+		case -1:
+			die("fork failed: %s", strerror(errno));
+		default:
+			exit(0);
+	}
+	if (setsid() == -1)
+		die("setsid failed: %s", strerror(errno));
+	if ((devnull = open("/dev/null", O_RDWR, 0)) == -1)
+		die("open /dev/null failed: %s", strerror(errno));
+	if (dup2(devnull, 0) != 0 ||
+		dup2(devnull, 1) != 1 ||
+		dup2(devnull, 2) != 2)
+		die("dup2 failed: %s", strerror(errno));
+}
+
 /* if any standard file descriptor is missing open it to /dev/null */
 static void sanitize_stdfds(void)
 {
@@ -705,6 +726,7 @@ int main(int argc, char **argv)
 	int port = DEFAULT_GIT_PORT;
 	int inetd_mode = 0;
 	const char *pid_file = NULL;
+	int detach = 0;
 	int i;
 
 	/* Without this we cannot rely on waitpid() to tell
@@ -773,6 +795,11 @@ int main(int argc, char **argv)
 			pid_file = arg + 11;
 			continue;
 		}
+		if (!strcmp(arg, "--detach")) {
+			detach = 1;
+			log_syslog = 1;
+			continue;
+		}
 		if (!strcmp(arg, "--")) {
 			ok_paths = &argv[i+1];
 			break;
@@ -805,7 +832,10 @@ int main(int argc, char **argv)
 		return execute(peer);
 	}
 
-	sanitize_stdfds();
+	if (detach)
+		daemonize();
+	else
+		sanitize_stdfds();
 
 	if (pid_file)
 		store_pid(pid_file);
-- 
1.4.1.gb16f

^ permalink raw reply related

* [PATCH 4/5] daemon: new option --pid-file=<path> to store the pid
From: Matthias Lederhofer @ 2006-07-13 10:18 UTC (permalink / raw)
  To: git
In-Reply-To: <E1G0zj7-0001c1-8q@moooo.ath.cx>

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
 daemon.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/daemon.c b/daemon.c
index e6b1730..4b85930 100644
--- a/daemon.c
+++ b/daemon.c
@@ -680,6 +680,15 @@ static void sanitize_stdfds(void)
 		close(devnull);
 }
 
+static void store_pid(const char *path)
+{
+	FILE *f = fopen(path, "w");
+	if (!f)
+		die("cannot open pid file %s: %s", path, strerror(errno));
+	fprintf(f, "%d\n", getpid());
+	fclose(f);
+}
+
 static int serve(int port)
 {
 	int socknum, *socklist;
@@ -695,6 +704,7 @@ int main(int argc, char **argv)
 {
 	int port = DEFAULT_GIT_PORT;
 	int inetd_mode = 0;
+	const char *pid_file = NULL;
 	int i;
 
 	/* Without this we cannot rely on waitpid() to tell
@@ -759,6 +769,10 @@ int main(int argc, char **argv)
 			user_path = arg + 12;
 			continue;
 		}
+		if (!strncmp(arg, "--pid-file=", 11)) {
+			pid_file = arg + 11;
+			continue;
+		}
 		if (!strcmp(arg, "--")) {
 			ok_paths = &argv[i+1];
 			break;
@@ -793,5 +807,8 @@ int main(int argc, char **argv)
 
 	sanitize_stdfds();
 
+	if (pid_file)
+		store_pid(pid_file);
+
 	return serve(port);
 }
-- 
1.4.1.gb16f

^ permalink raw reply related

* [PATCH 2/5] daemon: if one of the standard fds is missing open it to /dev/null
From: Matthias Lederhofer @ 2006-07-13 10:10 UTC (permalink / raw)
  To: git
In-Reply-To: <E1G0zj7-0001c1-8q@moooo.ath.cx>

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
 daemon.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/daemon.c b/daemon.c
index a7636bc..e6b1730 100644
--- a/daemon.c
+++ b/daemon.c
@@ -662,6 +662,24 @@ static int service_loop(int socknum, int
 	}
 }
 
+/* if any standard file descriptor is missing open it to /dev/null */
+static void sanitize_stdfds(void)
+{
+	int devnull = -1, i;
+	struct stat buf;
+	for (i = 0; i < 3; ++i) {
+		if (fstat(i, &buf) != -1)
+			continue;
+		if (devnull == -1 &&
+			(devnull = open("/dev/null", O_RDWR, 0)) == -1)
+			die("open /dev/null failed: %s", strerror(errno));
+		if (dup2(devnull, i) != i)
+			die("dup2 failed: %s", strerror(errno));
+	}
+	if (devnull != -1)
+		close(devnull);
+}
+
 static int serve(int port)
 {
 	int socknum, *socklist;
@@ -773,5 +791,7 @@ int main(int argc, char **argv)
 		return execute(peer);
 	}
 
+	sanitize_stdfds();
+
 	return serve(port);
 }
-- 
1.4.1.gb16f

^ permalink raw reply related

* Re: git-daemon problem
From: Matthias Lederhofer @ 2006-07-13 11:51 UTC (permalink / raw)
  To: git
In-Reply-To: <E1G0QeX-0003hG-0I@moooo.ath.cx>

Here are some patches that should solve this.
Note: The first patch is not really related to this problem but I
think the die error message should go to syslog when --syslog was
used. (And I did not have to add more if-clauses.)

Documentation will follow if the changes are ok.

^ permalink raw reply

* Re: git-daemon problem
From: Andre Noll @ 2006-07-13 11:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Matthias Lederhofer, git
In-Reply-To: <7vveq2ukho.fsf@assigned-by-dhcp.cox.net>

[-- Attachment #1: Type: text/plain, Size: 917 bytes --]

On 22:44, Junio C Hamano wrote:

> The only "right" solution I could think of is to properly
> daemonize git-daemon when not running under --inetd mode.  Close
> and open /dev/null the low three fds, and dissociate the process
> from the controlling terminal (did I forget anything else --
> perhaps chdir("/") at the top?).  And we keep the current
> behaviour of assuming the sane set of low three fds when a new
> option --debug is given to help people look at its stderr.  The
> tentative patch to upload-pack would become moot at that point.
> 
> Hmm?

A common solution for this problem is 

	while (1) {
		int     fd;

		fd = open("/dev/null", O_RDWR);
		if (fd < 0)
			exit(EX_OSERR);
		if (fd > 2) {
			close(fd);
			break;
		}
	}

See

	http://rechner.lst.de/~okir/blackhats/node41.html

Andre
-- 
The only person who always got his work done by Friday was Robinson Crusoe

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply

* remove perl from git-commit.sh
From: Alex Riesen @ 2006-07-13  8:30 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git
In-Reply-To: <7v3bd6xgnz.fsf@assigned-by-dhcp.cox.net>

[-- Attachment #1: Type: text/plain, Size: 1394 bytes --]

git-commit.sh has the only one place where perl is used
and there it can quite trivially be done in sh.

git-ls-files without "-z" produces quoted output, even if
is different from that produced by perl code it could be
enough. Otherwise I'd better suggest to add another
quoting style (replacing only \t, \n and backslash).

This system is an ugly combination of cygwin and
activestate perl. The combination has some quirks
(like the perl producing \r\n by default, expecting
windows pathnames instead of cygwin fakes, or
ignoring environment variables under some hard to
reproduce circumstances), so reducing number of
this interactions reduces number of hacks one has
to put in core code to make things work. I used to
patch git-commit.sh to put binmode in perl output,
and git-clone.sh still has these calls to cygpath.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>

---

It is really annoying when the essentials do not work.
I think we could improve at  least them, by minimizing
their dependencies to external tools.

Junio C Hamano wrote:
> (1) Sign-off?

done

> (2) I think the cover letter comment talks more apporpirate
>    things than your proposed commit message.  The commit log is
>    not a place to vent your frustration.  It's where you
>    justify why that change was needed for people who will want
>    to figure out why your patch broke their workflow later.

done.

[-- Attachment #2: 0001-remove-perl-from-git-commit.sh.txt --]
[-- Type: text/plain, Size: 1501 bytes --]

From 69bf41df4ef69d0f1e4ab52942c59bb3fd568cb8 Mon Sep 17 00:00:00 2001
From: Alex Riesen <raa.lkml@gmail.com>
Date: Wed, 12 Jul 2006 13:02:23 +0200
Subject: remove perl from git-commit.sh
---
 git-commit.sh |   32 +++++++++++++-------------------
 1 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/git-commit.sh b/git-commit.sh
index 802dd72..4cf3fab 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -138,32 +138,26 @@ #'
         if test -z "$untracked_files"; then
             option="--directory --no-empty-directory"
         fi
+	hdr_shown=
 	if test -f "$GIT_DIR/info/exclude"
 	then
-	    git-ls-files -z --others $option \
+	    git-ls-files --others $option \
 		--exclude-from="$GIT_DIR/info/exclude" \
 		--exclude-per-directory=.gitignore
 	else
-	    git-ls-files -z --others $option \
+	    git-ls-files --others $option \
 		--exclude-per-directory=.gitignore
 	fi |
-	@@PERL@@ -e '$/ = "\0";
-	    my $shown = 0;
-	    while (<>) {
-		chomp;
-		s|\\|\\\\|g;
-		s|\t|\\t|g;
-		s|\n|\\n|g;
-		s/^/#	/;
-		if (!$shown) {
-		    print "#\n# Untracked files:\n";
-		    print "#   (use \"git add\" to add to commit)\n";
-		    print "#\n";
-		    $shown = 1;
-		}
-		print "$_\n";
-	    }
-	'
+	while read line; do
+	    if [ -z "$hdr_shown" ]; then
+		echo '#'
+		echo '# Untracked files:'
+		echo '#   (use "git add" to add to commit)'
+		echo '#'
+		hdr_shown=1
+	    fi
+	    echo "#	$line"
+	done
 
 	if test -n "$verbose" -a -z "$IS_INITIAL"
 	then
-- 
1.4.1.gb4adf


^ permalink raw reply related

* Re: git-fmt-merge-message problem..
From: Johannes Schindelin @ 2006-07-13  8:03 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Junio C Hamano, Git Mailing List
In-Reply-To: <Pine.LNX.4.64.0607122133250.5623@g5.osdl.org>

Hi,

On Wed, 12 Jul 2006, Linus Torvalds wrote:

> Dscho? Can you please make git fmt-merge-message print out something 
> sensible again?

Sorry for the breakage. I saw Junio already patched and pushed.

Ciao,
Dscho

^ permalink raw reply

* Re: [PATCH] gitweb.css: Courer fonts for commits and tree-diff
From: Matthias Lederhofer @ 2006-07-13  7:57 UTC (permalink / raw)
  To: Luben Tuikov; +Cc: git
In-Reply-To: <20060712174610.71046.qmail@web31810.mail.mud.yahoo.com>

Luben Tuikov <ltuikov@yahoo.com> wrote:
> --- Junio C Hamano <junkio@cox.net> wrote:
> > But if I really have to, I would say this makes things uglier
> > and less readable.  Maybe asking for monospace is less yucky but
> > naming Courier explicitly?
> 
> Sometimes people would put ASCII art in their commit messages,
> things like a simple table, compiler output, log output, etc,
> and I wanted to _preserve_ the intent of such output.  This is why
> I changed it to Courier. (sorry for the misspelling of Courier)
monospace should do this too, see[1].  I think it should be added as
fallback[2] at least but I see no reason not to use font-family:
monospace.

[1] http://www.w3.org/TR/REC-CSS2/fonts.html#monospace-def
[2] http://www.w3.org/TR/REC-CSS2/fonts.html#generic-font-families

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox