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 7/7] send-pack: support pushing to a shallow clone
Date: Wed, 17 Jul 2013 19:47:14 +0700 [thread overview]
Message-ID: <1374065234-870-8-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1374065234-870-1-git-send-email-pclouds@gmail.com>
When send-pack receives "shallow" lines from receive-pack, it knows
the other end does not have a complete commit chains. It restrict
itself to the commits that are not cut out by either end to make sure
the result pack is usuable by receive-pack.
The same technique here, using setup_alternate_shallow() and
--shallow-file, might simplify similar code in upload-pack.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/send-pack.c | 7 +++++--
send-pack.c | 38 +++++++++++++++++++++++++++++++++-----
send-pack.h | 4 +++-
t/t5537-push-shallow.sh | 18 ++++++++++++++++++
transport.c | 5 +++--
5 files changed, 62 insertions(+), 10 deletions(-)
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index f0ad0ce..b177120 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -94,6 +94,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
int fd[2];
struct child_process *conn;
struct extra_have_objects extra_have;
+ struct extra_have_objects shallow;
struct ref *remote_refs, *local_refs;
int ret;
int helper_status = 0;
@@ -206,8 +207,10 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
}
memset(&extra_have, 0, sizeof(extra_have));
+ memset(&shallow, 0, sizeof(shallow));
- get_remote_heads(fd[0], NULL, 0, &remote_refs, REF_NORMAL, &extra_have, NULL);
+ get_remote_heads(fd[0], NULL, 0, &remote_refs, REF_NORMAL,
+ &extra_have, &shallow);
transport_verify_remote_names(nr_refspecs, refspecs);
@@ -227,7 +230,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
set_ref_status_for_push(remote_refs, args.send_mirror,
args.force_update);
- ret = send_pack(&args, fd, conn, remote_refs, &extra_have);
+ ret = send_pack(&args, fd, conn, remote_refs, &extra_have, &shallow);
if (helper_status)
print_helper_status(remote_refs);
diff --git a/send-pack.c b/send-pack.c
index 81d4b1c..08de681 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -27,14 +27,19 @@ static int feed_object(const unsigned char *sha1, int fd, int negative)
/*
* Make a pack stream and spit it out into file descriptor fd
*/
-static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *extra, struct send_pack_args *args)
+static int pack_objects(int fd, struct ref *refs,
+ struct extra_have_objects *extra,
+ struct extra_have_objects *extra_shallow,
+ struct send_pack_args *args)
{
/*
* The child becomes pack-objects --revs; we feed
* the revision parameters to it via its stdin and
* let its stdout go back to the other end.
*/
- const char *argv[] = {
+ const char *av[] = {
+ "--shallow-file",
+ NULL,
"pack-objects",
"--all-progress-implied",
"--revs",
@@ -45,10 +50,27 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
NULL,
NULL,
};
+ const char **argv;
struct child_process po;
+ static struct lock_file shallow_lock;
+ const char *alternate_shallow_file = NULL;
int i;
- i = 4;
+ if (extra_shallow->nr) {
+ memset(&shallow_lock, 0, sizeof(shallow_lock));
+ /* just to load up .git/shallow if exists */
+ is_repository_shallow();
+ setup_alternate_shallow(&shallow_lock,
+ &alternate_shallow_file,
+ extra_shallow,
+ 0);
+ av[1] = alternate_shallow_file;
+ argv = av;
+ i = 6;
+ } else {
+ argv = &av[2];
+ i = 4;
+ }
if (args->use_thin_pack)
argv[i++] = "--thin";
if (args->use_ofs_delta)
@@ -100,6 +122,10 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
if (finish_command(&po))
return -1;
+
+ if (extra_shallow->nr)
+ rollback_lock_file(&shallow_lock);
+
return 0;
}
@@ -176,7 +202,8 @@ static int sideband_demux(int in, int out, void *data)
int send_pack(struct send_pack_args *args,
int fd[], struct child_process *conn,
struct ref *remote_refs,
- struct extra_have_objects *extra_have)
+ struct extra_have_objects *extra_have,
+ struct extra_have_objects *extra_shallow)
{
int in = fd[0];
int out = fd[1];
@@ -294,7 +321,8 @@ int send_pack(struct send_pack_args *args,
}
if (new_refs && cmds_sent) {
- if (pack_objects(out, remote_refs, extra_have, args) < 0) {
+ if (pack_objects(out, remote_refs, extra_have, extra_shallow,
+ args) < 0) {
for (ref = remote_refs; ref; ref = ref->next)
ref->status = REF_STATUS_NONE;
if (args->stateless_rpc)
diff --git a/send-pack.h b/send-pack.h
index 05d7ab1..1c8a343 100644
--- a/send-pack.h
+++ b/send-pack.h
@@ -16,6 +16,8 @@ struct send_pack_args {
int send_pack(struct send_pack_args *args,
int fd[], struct child_process *conn,
- struct ref *remote_refs, struct extra_have_objects *extra_have);
+ struct ref *remote_refs,
+ struct extra_have_objects *extra_have,
+ struct extra_have_objects *extra_shallow);
#endif
diff --git a/t/t5537-push-shallow.sh b/t/t5537-push-shallow.sh
index 30fdbc8..76d3d51 100755
--- a/t/t5537-push-shallow.sh
+++ b/t/t5537-push-shallow.sh
@@ -64,4 +64,22 @@ EOF
test_cmp expect actual
'
+test_expect_success 'push from shallow to shallow' '
+ (
+ cd shallow &&
+ git push ../shallow2/.git +master:refs/remotes/shallow/master
+ ) &&
+ (
+ cd shallow2 &&
+ git log --format=%s shallow/master >actual &&
+ git fsck &&
+ cat <<EOF >expect &&
+5
+4
+3
+EOF
+ test_cmp expect actual
+ )
+'
+
test_done
diff --git a/transport.c b/transport.c
index 17fef16..d592e8d 100644
--- a/transport.c
+++ b/transport.c
@@ -802,7 +802,8 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
struct ref *tmp_refs;
connect_setup(transport, 1, 0);
- get_remote_heads(data->fd[0], NULL, 0, &tmp_refs, REF_NORMAL, NULL, NULL);
+ get_remote_heads(data->fd[0], NULL, 0, &tmp_refs, REF_NORMAL,
+ NULL, &data->shallow);
data->got_remote_heads = 1;
}
@@ -817,7 +818,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
args.porcelain = !!(flags & TRANSPORT_PUSH_PORCELAIN);
ret = send_pack(&args, data->fd, data->conn, remote_refs,
- &data->extra_have);
+ &data->extra_have, &data->shallow);
close(data->fd[1]);
close(data->fd[0]);
--
1.8.2.83.gc99314b
next prev parent reply other threads:[~2013-07-17 12:47 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-17 12:47 [PATCH 0/7] First class shallow clone Nguyễn Thái Ngọc Duy
2013-07-17 12:47 ` [PATCH 1/7] transport.h: remove send_pack prototype, already defined in send-pack.h Nguyễn Thái Ngọc Duy
2013-07-17 12:47 ` [PATCH 2/7] {receive,upload}-pack: advertise shallow graft information Nguyễn Thái Ngọc Duy
2013-07-17 12:47 ` [PATCH 3/7] connect.c: teach get_remote_heads to parse "shallow" lines Nguyễn Thái Ngọc Duy
2013-07-20 3:27 ` Junio C Hamano
2013-07-17 12:47 ` [PATCH 4/7] Move setup_alternate_shallow and write_shallow_commits to shallow.c Nguyễn Thái Ngọc Duy
2013-07-17 12:47 ` [PATCH 5/7] fetch-pack: support fetching from a shallow repository Nguyễn Thái Ngọc Duy
2013-07-20 3:17 ` Junio C Hamano
2013-07-17 12:47 ` [PATCH 6/7] {send,receive}-pack: support pushing from a shallow clone Nguyễn Thái Ngọc Duy
2013-07-17 12:47 ` Nguyễn Thái Ngọc Duy [this message]
2013-07-20 9:57 ` [PATCH v2 00/16] First class " Nguyễn Thái Ngọc Duy
2013-07-20 9:57 ` [PATCH v2 01/16] send-pack: forbid pushing from a shallow repository Nguyễn Thái Ngọc Duy
2013-07-20 9:57 ` [PATCH v2 02/16] {receive,upload}-pack: advertise shallow graft information Nguyễn Thái Ngọc Duy
2013-07-20 9:57 ` [PATCH v2 03/16] connect.c: teach get_remote_heads to parse "shallow" lines Nguyễn Thái Ngọc Duy
2013-07-20 9:57 ` [PATCH v2 04/16] Move setup_alternate_shallow and write_shallow_commits to shallow.c Nguyễn Thái Ngọc Duy
2013-07-20 9:57 ` [PATCH v2 05/16] fetch-pack: support fetching from a shallow repository Nguyễn Thái Ngọc Duy
2013-07-22 19:10 ` Philip Oakley
2013-07-23 2:06 ` Duy Nguyen
2013-07-23 14:39 ` Duy Nguyen
2013-07-20 9:58 ` [PATCH v2 06/16] {send,receive}-pack: support pushing from a shallow clone Nguyễn Thái Ngọc Duy
2013-07-20 9:58 ` [PATCH v2 07/16] send-pack: support pushing to " Nguyễn Thái Ngọc Duy
2013-07-20 9:58 ` [PATCH v2 08/16] upload-pack: let pack-objects do the object counting in shallow case Nguyễn Thái Ngọc Duy
2013-07-20 9:58 ` [PATCH v2 09/16] pack-protocol.txt: a bit about smart http Nguyễn Thái Ngọc Duy
2013-07-20 9:58 ` [PATCH v2 10/16] Add document for command arguments for supporting " Nguyễn Thái Ngọc Duy
2013-07-20 9:58 ` [PATCH v2 11/16] {fetch,upload}-pack: support fetching from a shallow clone via " Nguyễn Thái Ngọc Duy
2013-07-20 9:58 ` [PATCH v2 12/16] receive-pack: support pushing to a shallow clone via http Nguyễn Thái Ngọc Duy
2013-07-20 9:58 ` [PATCH v2 13/16] send-pack: support pushing from " Nguyễn Thái Ngọc Duy
2013-07-20 9:58 ` [PATCH v2 14/16] git-clone.txt: remove shallow clone limitations Nguyễn Thái Ngọc Duy
2013-07-20 9:58 ` [PATCH v2 15/16] config: add core.noshallow to prevent turning a repo into a shallow one Nguyễn Thái Ngọc Duy
2013-07-22 19:23 ` Philip Oakley
2013-07-23 1:28 ` Duy Nguyen
2013-07-23 4:06 ` Junio C Hamano
2013-07-23 19:44 ` Philip Oakley
2013-07-20 9:58 ` [PATCH v2 16/16] clone: use git protocol for cloning shallow repo locally Nguyễn Thái Ngọc Duy
2013-07-22 23:41 ` [PATCH v2 00/16] First class shallow clone Philip Oakley
2013-07-23 1:20 ` Duy Nguyen
2013-07-23 4:08 ` Junio C Hamano
2013-07-23 5:01 ` Duy Nguyen
2013-07-23 22:33 ` Philip Oakley
2013-07-24 1:57 ` Duy Nguyen
2013-07-24 7:38 ` Philip Oakley
2013-07-24 8:30 ` Piotr Krukowiecki
2013-07-24 10:35 ` Duy Nguyen
2013-07-24 16:50 ` Piotr Krukowiecki
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=1374065234-870-8-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).