From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 3/8] index-pack: add --append-pack=<path>
Date: Fri, 5 Feb 2016 15:57:52 +0700 [thread overview]
Message-ID: <1454662677-15137-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1454662677-15137-1-git-send-email-pclouds@gmail.com>
In this mode (--append-pack --stdin), index-pack consumes current
content in <path> first without producing anything else, then
continues to read from stdin and append to <path>. This is the
consumer end of "pack-objects --skip".
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/index-pack.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 48 insertions(+), 2 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 6a01509..f099ac2 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -73,6 +73,7 @@ static int nr_resolved_deltas;
static int nr_threads;
static int from_stdin;
+static int skip_mode;
static int strict;
static int do_fsck_object;
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
@@ -272,7 +273,29 @@ static void *fill(int min)
do {
ssize_t ret = xread(input_fd, input_buffer + input_len,
sizeof(input_buffer) - input_len);
- if (ret <= 0) {
+
+ if (ret == 0 && skip_mode) {
+ output_fd = input_fd;
+ input_fd = 0;
+ skip_mode = 0;
+ /*
+ * At this point we have 'input_len' bytes in
+ * input_buffer, which is from the existing pack.
+ * Assuming that we still need to read more, the
+ * next loop will read from stdin instead.
+ *
+ * What's read from stdin must be written down. The
+ * next flush() will write from &input_buffer[0],
+ * which appends the 'input_len' bytes from existing
+ * pack to the pack again.
+ *
+ * Seek back to make this an overwrite (of same
+ * content) instead of an append.
+ */
+ if (input_len && lseek(output_fd, -input_len, SEEK_CUR))
+ die_errno(_("cannot seek back %d bytes"), input_len);
+ }
+ else if (ret <= 0) {
if (!ret)
die(_("early EOF"));
die_errno(_("read error on input"));
@@ -323,6 +346,26 @@ static const char *open_pack_file(const char *pack_name)
return pack_name;
}
+static const char *open_pack_for_append(const char *path)
+{
+ if (!from_stdin)
+ die(_("--append-pack must be used with --stdin"));
+
+ input_fd = open(path, O_CREAT|O_RDWR, 0600);
+ if (input_fd < 0)
+ die_errno(_("cannot open packfile '%s'"), path);
+ output_fd = -1;
+ nothread_data.pack_fd = input_fd;
+ git_SHA1_Init(&input_ctx);
+
+ /*
+ * fill() will eventually turn this flag off and set output_fd
+ * after reading everything
+ */
+ skip_mode = 1;
+ return xstrdup(path);
+}
+
static void parse_pack_header(void)
{
struct pack_header *hdr = fill(sizeof(struct pack_header));
@@ -1692,6 +1735,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
opts.off32_limit = strtoul(c+1, &c, 0);
if (*c || opts.off32_limit & 0x80000000)
die(_("bad %s"), arg);
+ } else if (skip_prefix(arg, "--append-pack=", &arg)) {
+ curr_pack = open_pack_for_append(arg);
} else
usage(index_pack_usage);
continue;
@@ -1742,7 +1787,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
}
#endif
- curr_pack = open_pack_file(pack_name);
+ if (!curr_pack)
+ curr_pack = open_pack_file(pack_name);
parse_pack_header();
objects = xcalloc(nr_objects + 1, sizeof(struct object_entry));
if (show_stat)
--
2.7.0.377.g4cd97dd
next prev parent reply other threads:[~2016-02-05 8:58 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-05 8:57 [PATCH 0/8] Resumable clone revisited, proof of concept Nguyễn Thái Ngọc Duy
2016-02-05 8:57 ` [PATCH 1/8] pack-objects: add --skip and --skip-hash Nguyễn Thái Ngọc Duy
2016-02-05 9:20 ` Johannes Schindelin
2016-02-05 8:57 ` [PATCH 2/8] pack-objects: produce a stable pack when --skip is given Nguyễn Thái Ngọc Duy
2016-02-05 18:43 ` Junio C Hamano
2016-02-05 23:25 ` Duy Nguyen
2016-02-06 0:48 ` Junio C Hamano
2016-02-08 5:23 ` Duy Nguyen
2016-02-05 8:57 ` Nguyễn Thái Ngọc Duy [this message]
2016-02-05 8:57 ` [PATCH 4/8] upload-pack: new capability to pass --skip* to pack-objects Nguyễn Thái Ngọc Duy
2016-02-05 9:18 ` Johannes Schindelin
2016-02-05 8:57 ` [PATCH 5/8] fetch-pack.c: send "skip" line " Nguyễn Thái Ngọc Duy
2016-02-07 8:57 ` Eric Sunshine
2016-02-05 8:57 ` [PATCH 6/8] fetch: add --resume-pack=<path> Nguyễn Thái Ngọc Duy
2016-02-05 8:57 ` [PATCH 7/8] index-pack: --append-pack implies --strict Nguyễn Thái Ngọc Duy
2016-02-07 9:02 ` Eric Sunshine
2016-02-05 8:57 ` [PATCH 8/8] one ugly test to verify basic functionality Nguyễn Thái Ngọc Duy
2016-02-05 11:57 ` Elia Pinto
2016-02-05 13:02 ` Duy Nguyen
2016-02-05 13:33 ` Elia Pinto
2016-02-05 13:20 ` Johannes Schindelin
2016-02-05 13:38 ` Elia Pinto
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1454662677-15137-4-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).