All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liu Yubao <yubao.liu@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git list <git@vger.kernel.org>
Subject: [PATCH 5/5] support writing uncompressed loose object
Date: Tue, 02 Dec 2008 10:03:10 +0800	[thread overview]
Message-ID: <4934975E.2010601@gmail.com> (raw)
In-Reply-To: <7voczws3np.fsf@gitster.siamese.dyndns.org>



Signed-off-by: Liu Yubao <yubao.liu@gmail.com>
---
 sha1_file.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 05a9fa3..053b564 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2328,7 +2328,7 @@ static int create_tmpfile(char *buffer, size_t bufsiz, const char *filename)
 }
 
 static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
-			      void *buf, unsigned long len, time_t mtime)
+			      void *buf, unsigned long len, time_t mtime, int dont_deflate)
 {
 	int fd, size, ret;
 	unsigned char *compressed;
@@ -2345,6 +2345,12 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
 			return error("unable to create temporary sha1 filename %s: %s\n", tmpfile, strerror(errno));
 	}
 
+	if (dont_deflate) {
+		if (write_buffer(fd, hdr, hdrlen) < 0 || write_buffer(fd, buf, len) < 0)
+			die("unable to write sha1 file");
+		goto L_close_file;
+	}
+
 	/* Set it up */
 	memset(&stream, 0, sizeof(stream));
 	deflateInit(&stream, zlib_compression_level);
@@ -2376,9 +2382,11 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
 
 	if (write_buffer(fd, compressed, size) < 0)
 		die("unable to write sha1 file");
-	close_sha1_file(fd);
 	free(compressed);
 
+L_close_file:
+	close_sha1_file(fd);
+
 	if (mtime) {
 		struct utimbuf utb;
 		utb.actime = mtime;
@@ -2405,7 +2413,7 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha
 		hashcpy(returnsha1, sha1);
 	if (has_sha1_file(sha1))
 		return 0;
-	return write_loose_object(sha1, hdr, hdrlen, buf, len, 0);
+	return write_loose_object(sha1, hdr, hdrlen, buf, len, 0, 1);
 }
 
 int force_object_loose(const unsigned char *sha1, time_t mtime)
@@ -2423,7 +2431,7 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)
 	if (!buf)
 		return error("cannot read sha1_file for %s", sha1_to_hex(sha1));
 	hdrlen = sprintf(hdr, "%s %lu", typename(type), len) + 1;
-	ret = write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);
+	ret = write_loose_object(sha1, hdr, hdrlen, buf, len, mtime, 1);
 	free(buf);
 
 	return ret;
-- 
1.6.1.rc1.5.gde86c

  parent reply	other threads:[~2008-12-02  2:05 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-01  8:00 two questions about the format of loose object Liu Yubao
2008-12-01  8:25 ` Junio C Hamano
2008-12-01  9:28   ` Liu Yubao
2008-12-01 11:32     ` Jakub Narebski
2008-12-02  2:19       ` Liu Yubao
2008-12-01 15:21     ` Shawn O. Pearce
2008-12-02  2:43       ` Liu Yubao
2008-12-02  1:48   ` [PATCH 0/5] support reading and writing uncompressed " Liu Yubao
2008-12-02  1:51   ` [PATCH 1/5] avoid parse_sha1_header() accessing memory out of bound Liu Yubao
2008-12-02 15:42     ` Shawn O. Pearce
2008-12-03  3:49       ` Liu Yubao
2008-12-02  1:53   ` [PATCH 2/5] don't die immediately when convert an invalid type name Liu Yubao
2008-12-02  1:55   ` [PATCH 3/5] optimize parse_sha1_header() a little by detecting object type Liu Yubao
2008-12-02 15:53     ` Shawn O. Pearce
2008-12-03  4:06       ` Liu Yubao
2008-12-02  1:56   ` [PATCH 4/5] support reading uncompressed loose object Liu Yubao
2008-12-02 15:58     ` Shawn O. Pearce
2008-12-03  4:09       ` Liu Yubao
2008-12-02  2:03   ` Liu Yubao [this message]
2008-12-02 16:07     ` [PATCH 5/5] support writing " Shawn O. Pearce
2008-12-03  4:22       ` Liu Yubao
2008-12-02  3:11   ` [PATCH 0/5] support reading and " Liu Yubao
2008-12-01 12:16 ` two questions about the format of " Nick Andrew
2008-12-02  2:26   ` Liu Yubao
2008-12-01 15:32 ` Shawn O. Pearce
2008-12-02  3:05   ` Liu Yubao
2008-12-04  0:54     ` Nicolas Pitre

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=4934975E.2010601@gmail.com \
    --to=yubao.liu@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.