From 21b1aced83195af50fd8bc9a88e7734c8ee77c0e Mon Sep 17 00:00:00 2001
From: Junio C Hamano <junkio@cox.net>
Date: Wed, 21 Dec 2005 12:09:17 -0800
Subject: [PATCH 1/6] objects/info/packs: work around bug in
 http-fetch.c::fetch_indices()

The code to fetch pack index files in deployed clients have a
bug that causes it to ignore the pack file on the last line of
objects/info/packs file, so append an empty line to work it
around.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 server-info.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/server-info.c b/server-info.c
index df19e49b5be..6089765941f 100644
--- a/server-info.c
+++ b/server-info.c
@@ -200,6 +200,7 @@ static void write_pack_info_file(FILE *fp)
 	int i;
 	for (i = 0; i < num_pack; i++)
 		fprintf(fp, "P %s\n", info[i]->p->pack_name + objdirlen + 6);
+	fputc('\n', fp);
 }
 
 static int update_info_packs(int force)

From 455c161c47542de7e67d2ba48bba637e5a645388 Mon Sep 17 00:00:00 2001
From: Junio C Hamano <junkio@cox.net>
Date: Wed, 21 Dec 2005 12:10:10 -0800
Subject: [PATCH 2/6] http-fetch.c: fix objects/info/pack parsing.

It failed to register the last pack in the objects/info/packs
file.  Also it had an independent overrun error.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 http-fetch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/http-fetch.c b/http-fetch.c
index ad59f1cce61..3cd6ef91af5 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -658,7 +658,7 @@ static int fetch_indices(struct alt_base *repo)
 		switch (data[i]) {
 		case 'P':
 			i++;
-			if (i + 52 < buffer.posn &&
+			if (i + 52 <= buffer.posn &&
 			    !strncmp(data + i, " pack-", 6) &&
 			    !strncmp(data + i + 46, ".pack\n", 6)) {
 				get_sha1_hex(data + i + 6, sha1);
@@ -667,7 +667,7 @@ static int fetch_indices(struct alt_base *repo)
 				break;
 			}
 		default:
-			while (data[i] != '\n')
+			while (i < buffer.posn && data[i] != '\n')
 				i++;
 		}
 		i++;

From 9470657ad0d0472e3e3c2e352334f60e7bd777c1 Mon Sep 17 00:00:00 2001
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Date: Wed, 21 Dec 2005 17:53:29 +0100
Subject: [PATCH 3/6] Avoid misleading success message on error

When a push fails (for example when the remote head does not fast forward
to the desired ref) it is not correct to print "Everything up-to-date".

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 send-pack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/send-pack.c b/send-pack.c
index a41bbe5ecfd..5bc2f017bca 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -272,7 +272,7 @@ static int send_pack(int in, int out, int nr_refspec, char **refspec)
 	packet_flush(out);
 	if (new_refs)
 		pack_objects(out, remote_refs);
-	else
+	else if (ret == 0)
 		fprintf(stderr, "Everything up-to-date\n");
 	close(out);
 	return ret;

From 6689f08735d08a057f8d6f91af98b04960afa517 Mon Sep 17 00:00:00 2001
From: Pavel Roskin <proski@gnu.org>
Date: Wed, 21 Dec 2005 15:35:48 -0500
Subject: [PATCH 4/6] An off-by-one bug found by valgrind

Insufficient memory is allocated in index-pack.c to hold the *.idx name.
One more byte should be allocated to hold the terminating 0.

Signed-off-by: Pavel Roskin <proski@gnu.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 index-pack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/index-pack.c b/index-pack.c
index 785fe71a6fb..d4ce3af5878 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -440,7 +440,7 @@ int main(int argc, char **argv)
 		if (len < 5 || strcmp(pack_name + len - 5, ".pack"))
 			die("packfile name '%s' does not end with '.pack'",
 			    pack_name);
-		index_name_buf = xmalloc(len - 1);
+		index_name_buf = xmalloc(len);
 		memcpy(index_name_buf, pack_name, len - 5);
 		strcpy(index_name_buf + len - 5, ".idx");
 		index_name = index_name_buf;

From 50e7b06730915dd7439e880fe84439a4483ccbb4 Mon Sep 17 00:00:00 2001
From: Pavel Roskin <proski@gnu.org>
Date: Wed, 21 Dec 2005 15:35:48 -0500
Subject: [PATCH 5/6] [PATCH] quote.c: Make loop control more readable.

quote_c_style_counted() in quote.c uses a hard-to-read  construct.
Convert this to a more traditional form of the for loop.

Signed-off-by: Pavel Roskin <proski@gnu.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 quote.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/quote.c b/quote.c
index 76eb1442658..7218a7080d9 100644
--- a/quote.c
+++ b/quote.c
@@ -126,8 +126,10 @@ static int quote_c_style_counted(const char *name, int namelen,
 
 	if (!no_dq)
 		EMIT('"');
-	for (sp = name; (ch = *sp++) && (sp - name) <= namelen; ) {
-
+	for (sp = name; sp < name + namelen; sp++) {
+		ch = *sp;
+		if (!ch)
+			break;
 		if ((ch < ' ') || (ch == '"') || (ch == '\\') ||
 		    (ch == 0177)) {
 			needquote = 1;

From 8ac4838af428a2a32498b3e8d13295eb714654b4 Mon Sep 17 00:00:00 2001
From: Junio C Hamano <junkio@cox.net>
Date: Wed, 21 Dec 2005 13:48:47 -0800
Subject: [PATCH 6/6] server-info: skip empty lines.

Now we allow an empty line in objects/info/packs file, recognize
that and stop complaining.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 server-info.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/server-info.c b/server-info.c
index 6089765941f..05bce7da3b4 100644
--- a/server-info.c
+++ b/server-info.c
@@ -99,7 +99,10 @@ static int read_pack_info_file(const char *infofile)
 	while (fgets(line, sizeof(line), fp)) {
 		int len = strlen(line);
 		if (line[len-1] == '\n')
-			line[len-1] = 0;
+			line[--len] = 0;
+
+		if (!len)
+			continue;
 
 		switch (line[0]) {
 		case 'P': /* P name */