From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Jeff King" <peff@peff.net>, "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 3/3] receive-pack: use index-pack --unpack-limit instead of unpack-objects
Date: Fri, 6 Sep 2013 07:46:03 +0700 [thread overview]
Message-ID: <1378428363-14086-3-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1378428363-14086-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/receive-pack.c | 122 ++++++++++++++-----------------------------------
1 file changed, 34 insertions(+), 88 deletions(-)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index e3eb5fc..0a84a61 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -792,105 +792,51 @@ static struct command *read_head_info(void)
return commands;
}
-static const char *parse_pack_header(struct pack_header *hdr)
-{
- switch (read_pack_header(0, hdr)) {
- case PH_ERROR_EOF:
- return "eof before pack header was fully read";
-
- case PH_ERROR_PACK_SIGNATURE:
- return "protocol error (pack signature mismatch detected)";
-
- case PH_ERROR_PROTOCOL:
- return "protocol error (pack version unsupported)";
-
- default:
- return "unknown error in parse_pack_header";
-
- case 0:
- return NULL;
- }
-}
-
static const char *pack_lockfile;
static const char *unpack(int err_fd)
{
- struct pack_header hdr;
- const char *hdr_err;
- char hdr_arg[38];
int fsck_objects = (receive_fsck_objects >= 0
? receive_fsck_objects
: transfer_fsck_objects >= 0
? transfer_fsck_objects
: 0);
- hdr_err = parse_pack_header(&hdr);
- if (hdr_err) {
- if (err_fd > 0)
- close(err_fd);
- return hdr_err;
- }
- snprintf(hdr_arg, sizeof(hdr_arg),
- "--pack_header=%"PRIu32",%"PRIu32,
- ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries));
-
- if (ntohl(hdr.hdr_entries) < unpack_limit) {
- int code, i = 0;
- struct child_process child;
- const char *unpacker[5];
- unpacker[i++] = "unpack-objects";
- if (quiet)
- unpacker[i++] = "-q";
- if (fsck_objects)
- unpacker[i++] = "--strict";
- unpacker[i++] = hdr_arg;
- unpacker[i++] = NULL;
- memset(&child, 0, sizeof(child));
- child.argv = unpacker;
- child.no_stdout = 1;
- child.err = err_fd;
- child.git_cmd = 1;
- code = run_command(&child);
- if (!code)
- return NULL;
- return "unpack-objects abnormal exit";
- } else {
- const char *keeper[7];
- int s, status, i = 0;
- char keep_arg[256];
- struct child_process ip;
-
- s = sprintf(keep_arg, "--keep=receive-pack %"PRIuMAX" on ", (uintmax_t) getpid());
- if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
- strcpy(keep_arg + s, "localhost");
-
- keeper[i++] = "index-pack";
- keeper[i++] = "--stdin";
- if (fsck_objects)
- keeper[i++] = "--strict";
- keeper[i++] = "--fix-thin";
- keeper[i++] = hdr_arg;
- keeper[i++] = keep_arg;
- keeper[i++] = NULL;
- memset(&ip, 0, sizeof(ip));
- ip.argv = keeper;
- ip.out = -1;
- ip.err = err_fd;
- ip.git_cmd = 1;
- status = start_command(&ip);
- if (status) {
- return "index-pack fork failed";
- }
- pack_lockfile = index_pack_lockfile(ip.out);
- close(ip.out);
- status = finish_command(&ip);
- if (!status) {
- reprepare_packed_git();
- return NULL;
- }
+ const char *keeper[7];
+ int s, status, i = 0;
+ char keep_arg[256];
+ char unpack_limit_arg[256];
+ struct child_process ip;
+
+ s = sprintf(keep_arg, "--keep=receive-pack %"PRIuMAX" on ", (uintmax_t) getpid());
+ if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
+ strcpy(keep_arg + s, "localhost");
+ sprintf(unpack_limit_arg, "--unpack-limit=%u", unpack_limit);
+
+ keeper[i++] = "index-pack";
+ keeper[i++] = "--stdin";
+ if (fsck_objects)
+ keeper[i++] = "--strict";
+ keeper[i++] = "--fix-thin";
+ keeper[i++] = keep_arg;
+ keeper[i++] = unpack_limit_arg;
+ keeper[i++] = NULL;
+ memset(&ip, 0, sizeof(ip));
+ ip.argv = keeper;
+ ip.out = -1;
+ ip.err = err_fd;
+ ip.git_cmd = 1;
+ status = start_command(&ip);
+ if (status)
+ return "index-pack fork failed";
+ pack_lockfile = index_pack_lockfile(ip.out);
+ close(ip.out);
+ status = finish_command(&ip);
+ if (status)
return "index-pack abnormal exit";
- }
+ if (pack_lockfile)
+ reprepare_packed_git();
+ return NULL;
}
static const char *unpack_with_sideband(void)
--
1.8.2.83.gc99314b
next prev parent reply other threads:[~2013-09-06 0:43 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-02 3:05 [PATCH] {fetch,receive}-pack: drop unpack-objects, delay loosing objects until the end Nguyễn Thái Ngọc Duy
2013-09-02 4:38 ` Eric Sunshine
2013-09-03 6:49 ` Jeff King
2013-09-03 11:56 ` Duy Nguyen
2013-09-03 17:25 ` Jeff King
2013-09-06 0:46 ` [PATCH v2 1/3] index-pack: add --unpack-limit to unpack objects Nguyễn Thái Ngọc Duy
2013-09-06 0:46 ` [PATCH v2 2/3] fetch-pack: use index-pack --unpack-limit instead of unpack-objects Nguyễn Thái Ngọc Duy
2013-09-08 4:45 ` Jeff King
2013-09-06 0:46 ` Nguyễn Thái Ngọc Duy [this message]
2013-09-08 4:44 ` [PATCH v2 1/3] index-pack: add --unpack-limit to unpack objects Jeff King
2013-09-08 6:28 ` Duy Nguyen
2013-09-08 6:35 ` Jeff King
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=1378428363-14086-3-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/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).