From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, Elijah Newren <newren@gmail.com>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 06/17] {fetch,upload}-pack: support narrow repository
Date: Sun, 5 Sep 2010 16:47:33 +1000 [thread overview]
Message-ID: <1283669264-15759-7-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1283669264-15759-1-git-send-email-pclouds@gmail.com>
If $GIT_DIR/narrow is set, fetch-pack will send "narrow-tree" lines to
upload-pack, where the prefixes are passed to rev-list mechanism to
produce a narrow pack.
"narrow-tree" capability is required for this to work.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
Documentation/git-fetch-pack.txt | 3 ++
Documentation/technical/pack-protocol.txt | 3 ++
builtin/fetch-pack.c | 9 +++++++
upload-pack.c | 38 +++++++++++++++++++++++++++-
4 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-fetch-pack.txt b/Documentation/git-fetch-pack.txt
index 4a8487c..19b0d92 100644
--- a/Documentation/git-fetch-pack.txt
+++ b/Documentation/git-fetch-pack.txt
@@ -25,6 +25,9 @@ This command degenerates to download everything to complete the
asked refs from the remote side when the local side does not
have a common ancestor commit.
+In narrow repositories, it asks 'git-upload-pack' to send only objects
+within narrow area defined in $GIT_DIR/narrow.
+
OPTIONS
-------
diff --git a/Documentation/technical/pack-protocol.txt b/Documentation/technical/pack-protocol.txt
index 369f91d..39474d2 100644
--- a/Documentation/technical/pack-protocol.txt
+++ b/Documentation/technical/pack-protocol.txt
@@ -215,6 +215,9 @@ discovery phase as 'want' lines. Clients MUST send at least one
obj-id in a 'want' command which did not appear in the response
obtained through ref discovery.
+If client is requesting narrow clone, it must send 'narrow-tree'
+lines before 'want' lines.
+
If client is requesting a shallow clone, it will now send a 'deepen'
line with the depth it is requesting.
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index dbd8b7b..591e0e4 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -37,6 +37,7 @@ static int marked;
static struct commit_list *rev_list;
static int non_common_revs, multi_ack, use_sideband;
+const char **narrow_prefix;
static void rev_list_push(struct commit *commit, int mark)
{
@@ -237,6 +238,12 @@ static int find_common(int fd[2], unsigned char *result_sha1,
for_each_ref(rev_list_insert_ref, NULL);
fetching = 0;
+ narrow_prefix = get_narrow_prefix();
+ if (narrow_prefix) {
+ const char **p = narrow_prefix;
+ while (*p)
+ packet_buf_write(&req_buf, "narrow-tree %s\n", *p++);
+ }
for ( ; refs ; refs = refs->next) {
unsigned char *remote = refs->old_sha1;
const char *remote_hex;
@@ -692,6 +699,8 @@ static struct ref *do_fetch_pack(int fd[2],
if (is_repository_shallow() && !server_supports("shallow"))
die("Server does not support shallow clients");
+ if (narrow_prefix && !server_supports("narrow-tree"))
+ die("Server does not support narrow-tree");
if (server_supports("multi_ack_detailed")) {
if (args.verbose)
fprintf(stderr, "Server supports multi_ack_detailed\n");
diff --git a/upload-pack.c b/upload-pack.c
index cc1983f..f3747e5 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -41,6 +41,8 @@ static int use_sideband;
static int debug_fd;
static int advertise_refs;
static int stateless_rpc;
+const char **narrow_prefix;
+int narrow_prefix_nr;
static void reset_timeout(void)
{
@@ -118,6 +120,10 @@ static int do_rev_list(int in, int out, void *user_data)
revs.simplify_history = 0;
if (use_thin_pack)
revs.edge_hint = 1;
+ if (narrow_prefix) {
+ revs.prune_data = narrow_prefix;
+ narrow_prefix[narrow_prefix_nr] = NULL;
+ }
for (i = 0; i < want_obj.nr; i++) {
struct object *o = want_obj.objects[i].item;
@@ -154,9 +160,10 @@ static void create_pack_file(void)
"corruption on the remote side.";
int buffered = -1;
ssize_t sz;
- const char *argv[10];
+ const char **argv;
int arg = 0;
+ argv = xmalloc(sizeof(*argv)*(11+narrow_prefix_nr));
if (shallow_nr) {
memset(&rev_list, 0, sizeof(rev_list));
rev_list.proc = do_rev_list;
@@ -180,6 +187,11 @@ static void create_pack_file(void)
argv[arg++] = "--delta-base-offset";
if (use_include_tag)
argv[arg++] = "--include-tag";
+ if (narrow_prefix) {
+ argv[arg++] = "--";
+ memcpy(argv+arg, narrow_prefix, narrow_prefix_nr*sizeof(*argv));
+ arg += narrow_prefix_nr;
+ }
argv[arg++] = NULL;
memset(&pack_objects, 0, sizeof(pack_objects));
@@ -307,6 +319,7 @@ static void create_pack_file(void)
error("git upload-pack: git-pack-objects died with error.");
goto fail;
}
+ free(argv);
if (shallow_nr && finish_async(&rev_list))
goto fail; /* error was already reported */
@@ -500,6 +513,22 @@ static void receive_needs(void)
if (debug_fd)
write_in_full(debug_fd, line, len);
+ if (!prefixcmp(line, "narrow-tree ")) {
+ char *s;
+ int len;
+ len = strlen(line+12);
+ s = malloc(len+1);
+ memcpy(s, line+12, len-1);
+ s[len-1] = '\0'; /* \n */
+ if (s[len-2] == '/')
+ die("trailing slash in narrow prefix not allowed, %s", line);
+
+ narrow_prefix_nr++;
+ narrow_prefix = xrealloc(narrow_prefix,
+ sizeof(*narrow_prefix)*(narrow_prefix_nr+1));
+ narrow_prefix[narrow_prefix_nr-1] = s;
+ continue;
+ }
if (!prefixcmp(line, "shallow ")) {
unsigned char sha1[20];
struct object *object;
@@ -563,6 +592,9 @@ static void receive_needs(void)
if (!use_sideband && daemon_mode)
no_progress = 1;
+ if (narrow_prefix)
+ use_thin_pack = 0;
+
if (depth == 0 && shallows.nr == 0)
return;
if (depth > 0) {
@@ -620,7 +652,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
{
static const char *capabilities = "multi_ack thin-pack side-band"
" side-band-64k ofs-delta shallow no-progress"
- " include-tag multi_ack_detailed";
+ " include-tag multi_ack_detailed narrow-tree";
struct object *o = parse_object(sha1);
if (!o)
@@ -725,6 +757,8 @@ int main(int argc, char **argv)
die("'%s' does not appear to be a git repository", dir);
if (is_repository_shallow())
die("attempt to fetch/clone from a shallow repository");
+ if (get_narrow_prefix())
+ die("attempt to fetch/clone from a narrow repository");
if (getenv("GIT_DEBUG_SEND_PACK"))
debug_fd = atoi(getenv("GIT_DEBUG_SEND_PACK"));
upload_pack();
--
1.7.1.rc1.69.g24c2f7
next prev parent reply other threads:[~2010-09-05 6:49 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-05 6:47 [PATCH 00/17] Narrow clone v3 (was subtree clone) Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 01/17] rev-list: do not do commit simplification if simplify_history = 0 Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 02/17] tree.c: add path_to_sha1() Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 03/17] Introduce $GIT_DIR/narrow Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 04/17] index: make narrow index incompatible with older git Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 05/17] pack-objects: support narrow packs with pathspecs Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` Nguyễn Thái Ngọc Duy [this message]
2010-09-05 6:47 ` [PATCH 07/17] unpack-trees: split traverse_trees() code into a separate function Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 08/17] unpack-trees: support unpack trees in narrow repository Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 09/17] cache-tree: only cache tree within narrow area Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 10/17] get_pathspec(): support narrow pathspec rewriting Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 11/17] pathspec retrieval fix Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 12/17] clone: support --narrow option Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 13/17] commit: add narrow's commit_tree version Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 14/17] commit: use commit_narrow_tree() to support narrow repo Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 15/17] write-tree: requires --narrow-base in narrow repository Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 16/17] merge: try to do local merge if possible in narrow repo Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 17/17] Add narrow clone demonstration test Nguyễn Thái Ngọc Duy
2010-09-05 6:55 ` [PATCH 00/17] Narrow clone v3 (was subtree clone) Sverre Rabbelier
2010-09-05 7:13 ` Nguyen Thai Ngoc Duy
2010-09-05 21:05 ` Elijah Newren
2010-09-06 5:17 ` Elijah Newren
2010-09-06 5:24 ` Nguyen Thai Ngoc Duy
2010-09-06 20:29 ` Sverre Rabbelier
2010-09-06 20:40 ` Elijah Newren
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=1283669264-15759-7-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=newren@gmail.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.