git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sun He <sunheehnus@gmail.com>
To: git@vger.kernel.org
Cc: mhagger@alum.mit.edu, Sun He <sunheehnus@gmail.com>
Subject: [PATCH] Rewrite bulk-checkin.c:finish_bulk_checkin() to use a strbuf for handling packname
Date: Thu, 27 Feb 2014 22:00:01 +0800	[thread overview]
Message-ID: <1393509601-31312-1-git-send-email-sunheehnus@gmail.com> (raw)


Signed-off-by: Sun He <sunheehnus@gmail.com>
---
 bulk-checkin.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/bulk-checkin.c b/bulk-checkin.c
index 118c625..8c47d71 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -23,7 +23,8 @@ static struct bulk_checkin_state {
 static void finish_bulk_checkin(struct bulk_checkin_state *state)
 {
 	unsigned char sha1[20];
-	char packname[PATH_MAX];
+	char *packname;
+    struct strbuf sb;
 	int i;
 
 	if (!state->f)
@@ -43,6 +44,10 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
 		close(fd);
 	}
 
+    /* 64-1 is more than the sum of len(sha1_to_hex(sha1)) and len(".pack") */
+    strbuf_init(&sb,strlen(get_object_directory())+64);
+    packname = sb.buf;
+
 	sprintf(packname, "%s/pack/pack-", get_object_directory());
 	finish_tmp_packfile(packname, state->pack_tmp_name,
 			    state->written, state->nr_written,
@@ -54,6 +59,9 @@ clear_exit:
 	free(state->written);
 	memset(state, 0, sizeof(*state));
 
+    /* release sb space */
+    strbuf_release(&sb);
+
 	/* Make objects we just wrote available to ourselves */
 	reprepare_packed_git();
 }
-- 
1.7.1

             reply	other threads:[~2014-02-27 14:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-27 14:00 Sun He [this message]
2014-02-27 19:39 ` [PATCH] Rewrite bulk-checkin.c:finish_bulk_checkin() to use a strbuf for handling packname Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2014-02-28  8:28 Sun He
2014-02-28  9:46 ` Eric Sunshine
2014-02-28 13:10   ` Eric Sunshine
2014-02-28 14:17     ` 孙赫
2014-02-28 20:42       ` Eric Sunshine
2014-03-01  0:13         ` He Sun
     [not found]   ` <CAJr59C2Uw+tnRSuHbMnyJjGSE+XNpepPdode5MvcHb4X31e+qQ@mail.gmail.com>
2014-02-28 15:54     ` Fwd: " 孙赫
2014-02-28 20:47       ` Eric Sunshine

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=1393509601-31312-1-git-send-email-sunheehnus@gmail.com \
    --to=sunheehnus@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=mhagger@alum.mit.edu \
    /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).